tvplanit: Improved and more stable layout of print preview related dialogs at higher dpi.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@5012 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2016-07-20 19:29:00 +00:00
parent 0fc938717d
commit 59719d29cb
6 changed files with 172 additions and 61 deletions

View File

@ -91,7 +91,7 @@ type
procedure PosEditEnter(Sender: TObject);
procedure UpDownClick(Sender: TObject; Button: TUDBtnType);
private
procedure RepositionControls;
procedure PositionControls;
procedure SetCaptions;
procedure SetMaxSpin(Spin: Integer);
protected
@ -141,6 +141,7 @@ end;
{=====}
procedure TfrmEditElement.FormShow(Sender: TObject);
begin
PositionControls;
edName.SetFocus;
end;
{=====}
@ -286,11 +287,9 @@ begin
btnShape.Caption := RSShapeBtn;
btnOK.Caption := RSOKBtn;
btnCancel.Caption := RSCancelBtn;
RepositionControls;
end;
procedure TfrmEditElement.RepositionControls;
procedure TfrmEditElement.PositionControls;
const
MARGIN = 16;
DELTA = 8;
@ -299,10 +298,44 @@ const
GROUPBOX_CORRECTION = 16;
GROUPBOX_DISTANCE = 16;
var
i, w, h: Integer;
i, w, h, hEd, hBtn: Integer;
cnv: TControlCanvas;
rb: TRadioButton;
begin
// Fix edit heights at higher dpi
with TEdit.Create(self) do
try
Parent := self;
hEd := Height;
finally
free;
end;
edName.Height := hEd;
edOffset.Height := hEd;
udOffset.Height := hEd;
edTop.Height := hEd;
edLeft.Height := hEd;
edHeight.Height := hEd;
edWidth.Height := hEd;
udTop.Height := hEd;
udLeft.Height := hEd;
udHeight.Height := hEd;
udWidth.Height := hEd;
edCaptionText.Height := hEd;
// Fix button heights a higher dpi
with TButton.Create(self) do
try
Parent := self;
hBtn := Height;
finally
Free;
end;
btnOK.Height := hBtn;
btnCancel.Height := hBtn;
btnShape.Height := hBtn;
btnCaptionFont.Height := hBtn;
cnv := TControlCanvas.Create;
try
cnv.Control := rgItemType;

View File

@ -88,6 +88,7 @@ uses
procedure TfrmEditFormat.FormShow(Sender: TObject);
begin
PositionControls;
edName.SetFocus;
end;
{=====}
@ -149,48 +150,70 @@ begin
rgDayIncrement.Items[3] := RSYears;
btnOK.Caption := RSOKBtn;
btnCancel.Caption := RSCancelBtn;
PositionControls;
end;
procedure TfrmEditFormat.PositionControls;
var
delta: integer = 8;
DELTA: integer = 8;
margin: Integer = 16;
vdist: Integer = 4;
var
w, h: Integer;
dummyRB: TRadioButton;
editHeight: Integer;
btnHeight: Integer;
begin
delta := Round(delta * Screen.PixelsPerInch / DesignTimeDPI);
margin := Round(margin * Screen.PixelsPerInch / DesignTimeDPI);
vdist := Round(vdist * Screen.PixelsPerInch / DesignTimeDPI);
// Fix edit and button heights at higher dpi
with TEdit.Create(self) do
try
Parent := self;
editHeight := Height;
finally
Free;
end;
with TButton.Create(self) do
try
Parent := self;
btnHeight := Height;
finally
Free;
end;
DELTA := Round(DELTA * Screen.PixelsPerInch / DesignTimeDPI);
MARGIN := Round(MARGIN * Screen.PixelsPerInch / DesignTimeDPI);
VDIST := Round(VDIST * Screen.PixelsPerInch / DesignTimeDPI);
w := MaxValue([GetLabelWidth(LblName), GetLabelWidth(LblDescription), GetLabelWidth(LblIncrement)]);
edName.Left := margin + w + delta;
edName.Left := margin + w + DELTA;
edDescription.Left := edName.Left;
edDescription.Width := edName.Width;
edIncrement.Left := edName.Left;
udIncrement.Left := edIncrement.Left + edIncrement.Width;
LblName.Left := edName.Left - GetLabelWidth(LblName) - delta;
LblDescription.Left := edDescription.Left - GetLabelWidth(lblDescription) - delta;
lblIncrement.Left := edIncrement.Left - GetLabelWidth(lblIncrement) - delta;
LblName.Left := edName.Left - GetLabelWidth(LblName) - DELTA;
LblDescription.Left := edDescription.Left - GetLabelWidth(lblDescription) - DELTA;
lblIncrement.Left := edIncrement.Left - GetLabelWidth(lblIncrement) - DELTA;
ClientWidth := MARGIN + w + delta + edName.Width + margin;
rgDayIncrement.Width := ClientWidth - 2*margin;
ClientWidth := MARGIN + w + DELTA + edName.Width + MARGIN;
rgDayIncrement.Width := ClientWidth - 2*MARGIN;
w := Max(GetButtonWidth(btnOK), GetButtonWidth(btnCancel));
btnOK.Width := w;
btnCancel.Width := w;
btnCancel.Left := RightOf(rgDayIncrement) - btnCancel.Width;
btnOK.Left := btnCancel.Left - delta - btnOK.Width;
btnOK.Left := btnCancel.Left - DELTA - btnOK.Width;
edDescription.Top := BottomOf(edName) + vDist;
edName.Height := editHeight;
edDescription.Height := editHeight;
edIncrement.Height := editHeight;
udIncrement.Height := editHeight;
edDescription.Top := BottomOf(edName) + VDIST;
lblDescription.Top := edDescription.Top + (edDescription.Height - lblDescription.Height) div 2;
edIncrement.Top := BottomOf(edDescription) + vDist;
edIncrement.Top := BottomOf(edDescription) + VDIST;
udIncrement.Top := edIncrement.Top;
lblIncrement.top := edIncrement.Top + (edIncrement.Height - lblIncrement.Height) div 2;
rgDayIncrement.Top := BottomOf(edIncrement) + vDist + vDist;
rgDayIncrement.Top := BottomOf(edIncrement) + VDISt + VDIST;
DummyRB := TRadioButton.Create(self);
DummyRB.Parent := self;
@ -198,10 +221,12 @@ begin
DummyRB.Free;
rgdayIncrement.Height := h + 2*LblName.Height;
btnOK.Top := Bottomof(rgDayIncrement) + vDist;
btnOK.Height := btnHeight;
btnCancel.Height := btnHeight;
btnOK.Top := Bottomof(rgDayIncrement) + VDIST;
btnCancel.Top := btnOK.Top;
ClientHeight := Bottomof(btnOK) + vDist*2;
ClientHeight := Bottomof(btnOK) + VDIST*2;
end;
procedure TfrmEditFormat.SetData(AFormat: TVpPrintFormatItem);

View File

@ -2,12 +2,12 @@ object frmPrnFormat: TfrmPrnFormat
Left = 250
Height = 480
Top = 165
Width = 693
Width = 694
HorzScrollBar.Page = 639
VertScrollBar.Page = 479
Caption = 'Print Format Designer'
ClientHeight = 480
ClientWidth = 693
ClientWidth = 694
OnCloseQuery = FormCloseQuery
OnCreate = FormCreate
OnShow = FormShow
@ -98,8 +98,8 @@ object frmPrnFormat: TfrmPrnFormat
Height = 439
Top = 0
Width = 320
Align = alRight
BorderSpacing.Right = 8
BorderSpacing.Top = 4
BorderSpacing.Right = 4
BevelOuter = bvNone
ClientHeight = 439
ClientWidth = 320
@ -145,7 +145,7 @@ object frmPrnFormat: TfrmPrnFormat
object btnEditFormat: TButton
Left = 280
Height = 25
Top = 61
Top = 56
Width = 75
Caption = '&Edit'
Enabled = False
@ -155,7 +155,7 @@ object frmPrnFormat: TfrmPrnFormat
object btnDeleteFormat: TButton
Left = 280
Height = 25
Top = 97
Top = 88
Width = 75
Caption = '&Delete'
Enabled = False
@ -175,7 +175,7 @@ object frmPrnFormat: TfrmPrnFormat
object btnEditElement: TButton
Left = 280
Height = 25
Top = 282
Top = 280
Width = 75
Caption = 'E&dit'
Enabled = False
@ -185,7 +185,7 @@ object frmPrnFormat: TfrmPrnFormat
object btnDeleteElement: TButton
Left = 280
Height = 25
Top = 318
Top = 312
Width = 75
Caption = 'De&lete'
Enabled = False
@ -196,11 +196,11 @@ object frmPrnFormat: TfrmPrnFormat
Left = 0
Height = 41
Top = 439
Width = 693
Width = 694
Align = alBottom
BevelOuter = bvNone
ClientHeight = 41
ClientWidth = 693
ClientWidth = 694
TabOrder = 9
object btnLoadFile: TButton
Left = 88
@ -230,7 +230,7 @@ object frmPrnFormat: TfrmPrnFormat
TabOrder = 0
end
object btnOk: TButton
Left = 609
Left = 610
Height = 25
Top = 8
Width = 75

View File

@ -173,6 +173,8 @@ end;
{=====}
procedure TfrmPrnFormat.FormShow(Sender: TObject);
begin
PositionControls;
PrintPreview.Parent := PrintPreviewPanel;
if ControlLink.Printer.PrintFormats.Count > 0 then begin
@ -663,28 +665,53 @@ begin
btnNewFile.Caption := RSNewFileBtn;
btnLoadFile.Caption := RSLoadFileBtn;
btnSaveFile.Caption := RSSaveFileBtn;
PositionControls;
end;
procedure TfrmPrnFormat.PositionControls;
var
w: Integer;
dist: Integer;
DIST: Integer = 8;
btndist: Integer;
hBtn: Integer;
begin
dist := round(8 * Screen.PixelsPerInch / DesignTimeDPI);
DIST := round(DIST * Screen.PixelsPerInch / DesignTimeDPI);
btnDist := btnEditFormat.Top - BottomOf(btnNewFormat);
// Fix button height at higher dpi
with TButton.Create(self) do
try
Parent := self;
hBtn := Height;
finally
Free;
end;
btnNewFormat.Height := hBtn;
btnEditFormat.Height := hBtn;
btnDeleteFormat.Height := hBtn;
btnNewElement.Height := hBtn;
btnEditElement.Height := hbtn;
btnDeleteElement.Height := hBtn;
btnNewFile.Height := hBtn;
btnLoadFile.Height := hBtn;
btnSaveFile.Height := hBtn;
btnOK.Height := hBtn;
w := MaxValue([GetButtonWidth(btnNewFile), GetButtonWidth(btnLoadFile), GetButtonWidth(btnSaveFile)]);
btnNewFile.Width := w;
btnLoadFile.Width := w;
btnSaveFile.Width := w;
btnLoadFile.Left := RightOf(btnNewFile) + dist;
btnSaveFile.Left := RightOf(btnLoadFile) + dist;
btnLoadFile.Left := RightOf(btnNewFile) + DIST;
btnSaveFile.Left := RightOf(btnLoadFile) + DIST;
w := MaxValue([GetButtonWidth(btnNewFormat), GetButtonWidth(btnEditFormat), GetButtonWidth(btnDeleteFormat)]);
btnNewFormat.Left := RightOf(lbFormats) + dist;
btnNewFormat.Width := w;
btnEditFormat.Width := w;
btnDeleteFormat.Width := w;
btnNewElement.Width := w;
btnEditElement.Width := w;
btnDeleteElement.Width := w;
w := Max(w, GetLabelWidth(LblPrintOrder));
btnNewFormat.Left := RightOf(lbFormats) + DIST + (w - btnNewFormat.Width) div 2;
btnEditFormat.Left := btnNewFormat.Left;
btnDeleteFormat.Left := btnNewFormat.Left;
btnNewElement.Left := btnNewFormat.Left;
@ -698,9 +725,11 @@ begin
btnMoveElementUp.Top := BottomOf(LblPrintOrder) + Round(8 * Screen.PixelsPerInch / DesignTimeDPI);
btnMoveElementDn.Top := BottomOf(BtnMoveElementUp) + Round(8 * Screen.PixelsPerInch / DesignTimeDPI);
PrintPreviewPanel.Left := BtnNewFormat.Left + BtnNewFormat.Width + dist;
PrintPreviewPanel.Left := Max(RightOf(btnNewFormat), RightOf(LblPrintOrder)) + DIST; //RightOf(lbFormats) + DIST + w + DIST;
PrintPreviewPanel.Width := round(PrintPreview.Height * 210 / 297); // size ratio of A4 paper
ClientWidth := PrintPreviewPanel.Left + PrintPreviewPanel.Width + 8;
ButtonPanel.ClientHeight := BottomOf(btnOK) + btnOK.Top;
ClientWidth := PrintPreviewPanel.Left + PrintPreviewPanel.Width + 4; // + DIST;
end;
{

View File

@ -11,6 +11,7 @@ object frmEditShape: TfrmEditShape
ClientWidth = 426
OnCreate = FormCreate
OnDestroy = FormDestroy
OnShow = FormShow
Position = poScreenCenter
ShowHint = True
LCLVersion = '1.7'
@ -63,7 +64,7 @@ object frmEditShape: TfrmEditShape
end
object cbBrushStyle: TComboBox
Left = 52
Height = 23
Height = 21
Top = 32
Width = 129
BorderSpacing.Right = 8
@ -71,6 +72,7 @@ object frmEditShape: TfrmEditShape
ItemHeight = 15
OnChange = cbBrushStyleChange
OnDrawItem = cbBrushStyleDrawItem
Style = csOwnerDrawFixed
TabOrder = 0
end
object lblBrushColor: TLabel
@ -138,13 +140,15 @@ object frmEditShape: TfrmEditShape
end
object cbPenStyle: TComboBox
Left = 52
Height = 23
Height = 21
Top = 32
Width = 124
BorderSpacing.Right = 8
ItemHeight = 15
OnChange = cbPenStyleChange
OnDrawItem = cbPenStyleDrawItem
ReadOnly = True
Style = csOwnerDrawFixed
TabOrder = 1
end
object cbPenMode: TComboBox

View File

@ -86,6 +86,7 @@ type
procedure edPenWidthChange(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure FormShow(Sender: TObject);
private
FShapeButtons: array[TVpShapeType] of TSpeedButton;
@ -233,6 +234,11 @@ begin
DestroyBitmaps;
end;
procedure TfrmEditShape.FormShow(Sender: TObject);
begin
PositionControls;
end;
{=====}
function TfrmEditShape.Execute(AShape: TVpPrintShape): Boolean;
begin
@ -298,7 +304,7 @@ end;
{=====}
procedure TfrmEditShape.PositionControls;
var
w, h: Integer;
w, hc, hb: Integer;
shape: TVpShapeType;
DELTA: Integer = 8;
VDIST: Integer = 4;
@ -307,15 +313,29 @@ begin
gbPen.AutoSize := false;
gbBrush.AutoSize := false;
// This is needed as workaround for the combobox height at higher dpi.
// We design it with Style csDropdown where the height is correct, and then
// use the corresponding, correct ItemHeight after switching to csOwnerDrawFixed
// (which is needed to draw the icons).
h := cbPenStyle.ItemHeight;
cbPenStyle.Style := csOwnerDrawFixed;
cbPenStyle.ItemHeight := h+1;
cbBrushStyle.Style := csOwnerDrawFixed;
cbBrushStyle.ItemHeight := h+1;
// A workaround for the combobox height issue at higher dpi values:
// Create a combobox at runtime, it has the correct height, and apply its
// ItemHeight to the other comboboxes.
with TCombobox.Create(self) do
try
Parent := self;
hc := ItemHeight;
finally
Free;
end;
cbPenStyle.ItemHeight := hc;
cbPenColor.ItemHeight := hc;
cbBrushStyle.ItemHeight := hc;
cbBrushColor.ItemHeight := hc;
// Fix button hight at higher dpi.
with TButton.Create(self) do
try
Parent := self;
hb := Height;
finally
Free;
end;
DELTA := round(DELTA * Screen.PixelsPerInch / DesignTimeDPI);
VDIST := round(VDIST * Screen.PixelsPerInch / DesignTimeDPI);
@ -375,6 +395,8 @@ begin
btnOK.Left := btnCancel.Left - DELTA - btnOK.Width;
{ Buttons - vert }
btnOK.Height := hb;
btnCancel.Height := hb;
btnOK.Top := BottomOf(gbPen) - btnOK.Height;
btnCancel.Top := btnOK.Top;
@ -423,8 +445,6 @@ begin
lblBrushStyle.Caption := RSStyleLbl;
btnOK.Caption := RSOKBtn;
btnCancel.Caption := RSCancelBtn;
PositionControls;
end;
procedure TfrmEditShape.SetData(AShape: TVpPrintShape);