Issue #416: fix now hidden buttons at the very bottom

This commit is contained in:
Ansgar Becker
2018-12-02 14:12:59 +01:00
parent 7f555885d0
commit 7e84a3fb52

View File

@ -28,9 +28,9 @@ type
ColumnNames : TStringList; ColumnNames : TStringList;
OrderColumns : TOrderColArray; OrderColumns : TOrderColArray;
OldOrderClause : String; OldOrderClause : String;
procedure dropdownColsChange( Sender: TObject ); procedure comboColumnsChange( Sender: TObject );
procedure buttonOrderClick( Sender: TObject ); procedure btnOrderClick( Sender: TObject );
procedure buttonDeleteClick( Sender: TObject ); procedure btnDeleteClick( Sender: TObject );
procedure Modified; procedure Modified;
public public
{ Public declarations } { Public declarations }
@ -70,13 +70,14 @@ end;
} }
procedure TDataSortingForm.DisplaySortingControls(Sender: TObject); procedure TDataSortingForm.DisplaySortingControls(Sender: TObject);
var var
labelNumber: TLabel; lblNumber: TLabel;
buttonDelete: TButton; btnDelete: TButton;
dropdownCols: TComboBox; comboColumns: TComboBox;
buttonOrder: TSpeedButton; btnOrder: TSpeedButton;
i, xPosition, topPosition, btnWidth : Integer; i, TopPos,
Margin: Integer; // Space between controls Width1, Width2, Width3, Width4, // Width of controls per row
MarginBig: Integer; // Space above the very first and last controls, used to separate stuff Margin, // Space between controls
MarginBig: Integer; // Space above the very first and last controls, used to separate stuff
begin begin
// Remove previously created components, which all have a tag > 0 // Remove previously created components, which all have a tag > 0
for i := ComponentCount - 1 downto 0 do begin for i := ComponentCount - 1 downto 0 do begin
@ -84,107 +85,115 @@ begin
Components[i].Free; Components[i].Free;
end; end;
Margin := Round(2 * DpiScaleFactor(Self)); Margin := Round(3 * DpiScaleFactor(Self));
MarginBig := Round(6 * DpiScaleFactor(Self)); MarginBig := Margin * 2;
Width1 := Round(15 * DpiScaleFactor(Self));
Width2 := Round(130 * DpiScaleFactor(Self));
Width3 := Round(40 * DpiScaleFactor(Self));
Width4 := Round(30 * DpiScaleFactor(Self));
// Set initial width to avoid resizing form to 0 // Set initial width to avoid resizing form to 0
xPosition := pnlBevel.Width; TopPos := pnlBevel.BorderWidth + MarginBig;
topPosition := MarginBig;
// Create line with controls for each order column // Create line with controls for each order column
// TODO: disable repaint on every created control. Sending WM_SETREDRAW=0 message creates artefacts. // TODO: disable repaint on every created control. Sending WM_SETREDRAW=0 message creates artefacts.
for i:=0 to Length(OrderColumns)-1 do for i:=0 to Length(OrderColumns)-1 do begin
begin
xPosition := pnlBevel.BorderWidth;
// 1. Label with number // 1. Label with number
labelNumber := TLabel.Create(self); lblNumber := TLabel.Create(self);
labelNumber.Parent := pnlBevel; lblNumber.Parent := pnlBevel;
labelNumber.AutoSize := False; // Avoids automatic changes to width + height lblNumber.AutoSize := False; // Avoids automatic changes to width + height
labelNumber.Left := xPosition; lblNumber.Left := pnlBevel.BorderWidth + MarginBig;
labelNumber.Top := topPosition; lblNumber.Top := TopPos;
labelNumber.Width := Round(15 * DpiScaleFactor(Self)); lblNumber.Width := Width1;
labelNumber.Alignment := taRightJustify; lblNumber.Alignment := taRightJustify;
labelNumber.Layout := tlCenter; lblNumber.Layout := tlCenter;
labelNumber.Caption := IntToStr(i+1) + '.'; lblNumber.Caption := IntToStr(i+1) + '.';
labelNumber.Tag := i+1; lblNumber.Tag := i+1;
Inc( xPosition, labelNumber.Width + Margin );
// 2. Dropdown with columnnames // 2. Dropdown with columnnames
dropdownCols := TComboBox.Create(self); comboColumns := TComboBox.Create(self);
dropdownCols.Parent := pnlBevel; comboColumns.Parent := pnlBevel;
dropdownCols.Width := Round(130 * DpiScaleFactor(Self)); comboColumns.Width := Width2;
dropdownCols.Left := xPosition; comboColumns.Left := lblNumber.Left + lblNumber.Width + Margin;
dropdownCols.Top := topPosition; comboColumns.Top := TopPos;
dropdownCols.Items.Text := ColumnNames.Text; comboColumns.Items.Text := ColumnNames.Text;
dropdownCols.Style := csDropDownList; // Not editable comboColumns.Style := csDropDownList; // Not editable
dropdownCols.ItemIndex := ColumnNames.IndexOf(OrderColumns[i].ColumnName); comboColumns.ItemIndex := ColumnNames.IndexOf(OrderColumns[i].ColumnName);
dropdownCols.Tag := i+1; comboColumns.Tag := i+1;
dropdownCols.OnChange := dropdownColsChange; comboColumns.OnChange := comboColumnsChange;
labelNumber.Height := dropdownCols.Height; lblNumber.Height := comboColumns.Height;
Inc( xPosition, dropdownCols.Width + Margin );
// 3. A button for selecting ASC/DESC // 3. A button for selecting ASC/DESC
buttonOrder := TSpeedButton.Create(self); btnOrder := TSpeedButton.Create(self);
buttonOrder.Parent := pnlBevel; btnOrder.Parent := pnlBevel;
buttonOrder.Width := Round(40 * DpiScaleFactor(Self)); btnOrder.Width := Width3;
buttonOrder.Height := dropdownCols.Height; btnOrder.Height := comboColumns.Height;
buttonOrder.Left := xPosition; btnOrder.Left := comboColumns.Left + comboColumns.Width + Margin;
buttonOrder.Top := topPosition; btnOrder.Top := TopPos;
buttonOrder.AllowAllUp := True; // Enables Down = False btnOrder.AllowAllUp := True; // Enables Down = False
buttonOrder.GroupIndex := i+1; // if > 0 enables Down = True btnOrder.GroupIndex := i+1; // if > 0 enables Down = True
buttonOrder.Caption := TXT_ASC; btnOrder.Caption := TXT_ASC;
if OrderColumns[i].SortDirection = ORDER_DESC then if OrderColumns[i].SortDirection = ORDER_DESC then begin
begin btnOrder.Caption := TXT_DESC;
buttonOrder.Caption := TXT_DESC; btnOrder.Down := True;
buttonOrder.Down := True;
end; end;
buttonOrder.Hint := _('Toggle the sort direction for this column.'); btnOrder.Hint := _('Toggle the sort direction for this column.');
buttonOrder.Tag := i+1; btnOrder.Tag := i+1;
buttonOrder.OnClick := buttonOrderClick; btnOrder.OnClick := btnOrderClick;
Inc( xPosition, buttonOrder.Width + Margin );
// 4. Button for deleting // 4. Button for deleting
buttonDelete := TButton.Create(self); btnDelete := TButton.Create(self);
buttonDelete.Parent := pnlBevel; btnDelete.Parent := pnlBevel;
buttonDelete.Width := Round(30 * DpiScaleFactor(Self)); btnDelete.Width := Width4;
buttonDelete.Height := dropdownCols.Height; btnDelete.Height := comboColumns.Height;
buttonDelete.Left := xPosition; btnDelete.Left := btnOrder.Left + btnOrder.Width + Margin;
buttonDelete.Top := topPosition; btnDelete.Top := TopPos;
buttonDelete.Caption := 'X'; btnDelete.Caption := 'X';
buttonDelete.Hint := _('Drops sorting by this column.'); btnDelete.Hint := _('Drops sorting by this column.');
buttonDelete.Tag := i+1; btnDelete.Tag := i+1;
buttonDelete.OnClick := buttonDeleteClick; btnDelete.OnClick := btnDeleteClick;
Inc( xPosition, buttonDelete.Width + Margin );
topPosition := dropdownCols.Top + dropdownCols.Height + Margin; TopPos := comboColumns.Top + comboColumns.Height + Margin;
end; end;
Inc(TopPos, MarginBig);
// Auto-adjust size of form // Auto-adjust size of form
Height := topPosition + MarginBig + Height := TopPos +
btnreset.Height + Margin + btnReset.Height + Margin +
btnOK.Height + Margin + btnOK.Height + MarginBig +
pnlBevel.BorderWidth; pnlBevel.BorderWidth;
Width := xPosition + pnlBevel.BorderWidth; Width := pnlBevel.BorderWidth +
MarginBig + Width1 +
Margin + Width2 +
Margin + Width3 +
Margin + Width4 +
MarginBig + pnlBevel.BorderWidth;
// Auto-adjust width and position of main buttons at bottom // Auto-adjust width and position of main buttons at bottom
btnWidth := (pnlBevel.Width -pnlBevel.BorderWidth*2 - Margin) DIV 3 - Margin; btnReset.Left := pnlBevel.BorderWidth + MarginBig;
btnOK.Width := btnWidth; btnReset.Top := TopPos;
btnOK.Left := pnlBevel.BorderWidth + Margin; btnReset.Width := Width - 2 * pnlBevel.BorderWidth - 2 * MarginBig;
btnCancel.Width := btnWidth;
btnCancel.Left := btnOK.Left + btnWidth + Margin;
btnAddCol.Width := btnWidth;
btnAddCol.Left := btnCancel.Left + btnWidth + Margin;
btnReset.Left := btnOK.Left;
btnReset.Width := btnAddCol.Left + btnAddCol.Width - btnReset.Left;
btnReset.Enabled := Mainform.actDataResetSorting.Enabled; btnReset.Enabled := Mainform.actDataResetSorting.Enabled;
btnOK.Left := pnlBevel.BorderWidth + MarginBig;
btnOK.Top := btnReset.Top + btnReset.Height + Margin;
btnOK.Width := Round(btnReset.Width / 3) - Margin;
btnCancel.Left := btnOK.Left + btnOK.Width + Margin;
btnCancel.Top := btnReset.Top + btnReset.Height + Margin;
btnCancel.Width := btnOK.Width;
btnAddCol.Left := btnCancel.Left + btnCancel.Width + Margin;
btnAddCol.Top := btnReset.Top + btnReset.Height + Margin;
btnAddCol.Width := btnOK.Width;
end; end;
{** {**
Dropdown for column selection was changed Dropdown for column selection was changed
} }
procedure TDataSortingForm.dropdownColsChange( Sender: TObject ); procedure TDataSortingForm.comboColumnsChange( Sender: TObject );
var var
combo : TComboBox; combo : TComboBox;
begin begin
@ -199,7 +208,7 @@ end;
{** {**
Button for selecting sort-direction was clicked Button for selecting sort-direction was clicked
} }
procedure TDataSortingForm.buttonOrderClick( Sender: TObject ); procedure TDataSortingForm.btnOrderClick( Sender: TObject );
var var
btn : TSpeedButton; btn : TSpeedButton;
begin begin
@ -223,7 +232,7 @@ end;
{** {**
Delete order column Delete order column
} }
procedure TDataSortingForm.buttonDeleteClick( Sender: TObject ); procedure TDataSortingForm.btnDeleteClick( Sender: TObject );
var var
btn : TButton; btn : TButton;
i : Integer; i : Integer;