tvplanit: Translate element editor, auto-place controls

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@4932 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2016-07-07 20:51:29 +00:00
parent 38700edbf4
commit 57afcadf85
8 changed files with 677 additions and 73 deletions

View File

@ -1,27 +1,19 @@
object frmEditElement: TfrmEditElement
Left = 376
Height = 427
Top = 163
Left = 691
Height = 479
Top = 226
Width = 413
HorzScrollBar.Page = 378
VertScrollBar.Page = 444
BorderStyle = bsDialog
Caption = 'Edit Element'
ClientHeight = 427
ClientHeight = 479
ClientWidth = 413
OnCreate = FormCreate
OnShow = FormShow
Position = poScreenCenter
LCLVersion = '1.7'
object Label1: TLabel
Left = 20
Height = 15
Top = 136
Width = 58
Caption = 'Day Offset:'
ParentColor = False
end
object Label2: TLabel
object lblName: TLabel
Left = 12
Height = 15
Top = 16
@ -61,9 +53,9 @@ object frmEditElement: TfrmEditElement
OnClick = rgItemTypeClick
TabOrder = 1
end
object rgDayOffset: TRadioGroup
object rgDayOffsetUnit: TRadioGroup
Left = 116
Height = 43
Height = 56
Top = 136
Width = 284
AutoFill = True
@ -76,7 +68,7 @@ object frmEditElement: TfrmEditElement
ChildSizing.ShrinkVertical = crsScaleChilds
ChildSizing.Layout = cclLeftToRightThenTopToBottom
ChildSizing.ControlsPerLine = 4
ClientHeight = 23
ClientHeight = 36
ClientWidth = 280
Columns = 4
ItemIndex = 0
@ -91,22 +83,22 @@ object frmEditElement: TfrmEditElement
object btnOk: TButton
Left = 240
Height = 25
Top = 392
Top = 440
Width = 75
Caption = 'OK'
Default = True
OnClick = btnOkClick
TabOrder = 8
TabOrder = 7
end
object btnCancel: TButton
Left = 320
Height = 25
Top = 392
Top = 440
Width = 75
Cancel = True
Caption = 'Cancel'
OnClick = btnCancelClick
TabOrder = 9
TabOrder = 8
end
object edName: TEdit
Left = 56
@ -118,52 +110,56 @@ object frmEditElement: TfrmEditElement
object btnShape: TButton
Left = 12
Height = 25
Top = 392
Top = 440
Width = 75
Caption = 'Shape...'
Enabled = False
OnClick = btnShapeClick
TabOrder = 7
TabOrder = 6
end
object gbVisual: TGroupBox
Left = 12
Height = 129
Top = 184
Top = 208
Width = 388
Caption = ' Visual '
ClientHeight = 109
ClientWidth = 384
TabOrder = 5
object Label3: TLabel
TabOrder = 4
object LblTop: TLabel
Left = 172
Height = 15
Top = 20
Width = 23
Caption = 'Top:'
FocusControl = edTop
ParentColor = False
end
object Label4: TLabel
object LblLeft: TLabel
Left = 172
Height = 15
Top = 48
Width = 23
Caption = 'Left:'
FocusControl = edLeft
ParentColor = False
end
object Label5: TLabel
object LblHeight: TLabel
Left = 276
Height = 15
Top = 20
Width = 39
Caption = 'Height:'
FocusControl = edHeight
ParentColor = False
end
object Label6: TLabel
object LblWidth: TLabel
Left = 280
Height = 15
Top = 48
Width = 35
Caption = 'Width:'
FocusControl = edWidth
ParentColor = False
end
object rgMeasurement: TRadioGroup
@ -222,7 +218,7 @@ object frmEditElement: TfrmEditElement
Left = 208
Height = 23
Top = 16
Width = 40
Width = 48
OnEnter = PosEditEnter
OnExit = PosEditExit
TabOrder = 2
@ -232,7 +228,7 @@ object frmEditElement: TfrmEditElement
Left = 208
Height = 23
Top = 44
Width = 40
Width = 48
OnEnter = PosEditEnter
OnExit = PosEditExit
TabOrder = 4
@ -259,7 +255,7 @@ object frmEditElement: TfrmEditElement
Text = '0.00'
end
object chkVisible: TCheckBox
Left = 228
Left = 208
Height = 19
Top = 80
Width = 54
@ -267,7 +263,7 @@ object frmEditElement: TfrmEditElement
TabOrder = 10
end
object udTop: TUpDown
Left = 248
Left = 256
Height = 23
Top = 16
Width = 12
@ -279,7 +275,7 @@ object frmEditElement: TfrmEditElement
Wrap = False
end
object udLeft: TUpDown
Left = 248
Left = 256
Height = 23
Top = 44
Width = 12
@ -318,24 +314,25 @@ object frmEditElement: TfrmEditElement
object gbCaption: TGroupBox
Left = 12
Height = 69
Top = 316
Top = 352
Width = 388
Caption = ' Caption '
ClientHeight = 49
ClientWidth = 384
TabOrder = 6
object lbCaptionText: TLabel
TabOrder = 5
object lblCaptionText: TLabel
Left = 16
Height = 15
Top = 12
Width = 27
Caption = 'Text: '
FocusControl = edCaptionText
ParentColor = False
end
object btnCaptionFont: TButton
Left = 312
Height = 25
Top = 6
Top = 7
Width = 67
Caption = 'Font...'
OnClick = btnCaptionFontClick
@ -350,24 +347,34 @@ object frmEditElement: TfrmEditElement
TabOrder = 0
end
end
object edOffset: TEdit
Left = 20
Height = 23
Top = 156
Width = 54
object gbDayOffset: TGroupBox
Left = 12
Height = 56
Top = 136
Width = 92
Caption = 'Day Offset'
ClientHeight = 36
ClientWidth = 88
TabOrder = 2
Text = '0'
end
object udOffset: TUpDown
Left = 74
Height = 23
Top = 156
Width = 11
Associate = edOffset
Min = 0
Position = 0
TabOrder = 4
Wrap = False
object edOffset: TEdit
Left = 8
Height = 23
Top = 6
Width = 54
TabOrder = 0
Text = '0'
end
object udOffset: TUpDown
Left = 62
Height = 23
Top = 6
Width = 11
Associate = edOffset
Min = 0
Position = 0
TabOrder = 1
Wrap = False
end
end
object FontDialog1: TFontDialog
Font.Height = -11
@ -375,6 +382,6 @@ object frmEditElement: TfrmEditElement
MinFontSize = 0
MaxFontSize = 0
left = 176
top = 296
top = 288
end
end

View File

@ -43,20 +43,23 @@ uses
VpBase, VpSR, VpPrtFmt, ComCtrls;
type
{ TfrmEditElement }
TfrmEditElement = class(TForm)
btnCancel: TButton;
btnOk: TButton;
btnShape: TButton;
edName: TEdit;
Label1: TLabel;
Label2: TLabel;
rgDayOffset: TRadioGroup;
gbDayOffset: TGroupBox;
lblName: TLabel;
rgDayOffsetUnit: TRadioGroup;
rgItemType: TRadioGroup;
gbVisual: TGroupBox;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
LblTop: TLabel;
LblLeft: TLabel;
LblHeight: TLabel;
LblWidth: TLabel;
rgMeasurement: TRadioGroup;
rgRotation: TRadioGroup;
edTop: TEdit;
@ -68,7 +71,7 @@ type
btnCaptionFont: TButton;
FontDialog1: TFontDialog;
edCaptionText: TEdit;
lbCaptionText: TLabel;
lblCaptionText: TLabel;
edOffset: TEdit;
udOffset: TUpDown;
udTop: TUpDown;
@ -88,6 +91,8 @@ type
procedure PosEditEnter(Sender: TObject);
procedure UpDownClick(Sender: TObject; Button: TUDBtnType);
private
procedure RepositionControls;
procedure SetCaptions;
procedure SetMaxSpin(Spin: Integer);
protected
TheShape : TVpPrintShape;
@ -108,7 +113,8 @@ type
implementation
uses VpEdShape;
uses
Math, VpMisc, VpEdShape;
{$IFDEF LCL}
{$R *.lfm}
@ -127,8 +133,10 @@ begin
gbCaption.Enabled := False;
edCaptionText.Enabled := False;
lbCaptionText.Enabled := False;
lblCaptionText.Enabled := False;
btnCaptionFont.Enabled := False;
SetCaptions;
end;
{=====}
procedure TfrmEditElement.FormShow(Sender: TObject);
@ -230,13 +238,163 @@ begin
AnElement.ItemType := TVpItemType(rgItemType.ItemIndex);
AnElement.DayOffsetUnits := TVpDayUnits(rgDayOffset.ItemIndex);
AnElement.DayOffsetUnits := TVpDayUnits(rgDayOffsetUnit.ItemIndex);
AnElement.Rotation := TVpRotationAngle(rgRotation.ItemIndex);
AnElement.Measurement := TVpItemMeasurement(rgMeasurement.ItemIndex);
AnElement.Visible := chkVisible.Checked;
end;
{=====}
procedure TfrmEditElement.SetCaptions;
begin
Caption := RSEditElementCaption;
lblName.Caption := RSNameLbl;
rgItemType.Caption := RSElementTypeLbl;
rgItemType.Items[0] := RSDayViewElement;
rgItemType.Items[1] := RSWeekViewElement;
rgItemType.Items[2] := RSMonthViewElement;
rgItemType.Items[3] := RSCalendarElement;
rgItemType.Items[4] := RSShapeElement;
rgItemType.Items[5] := RSCaptionElement;
rgItemType.Items[6] := RSTasksElement;
rgItemType.Items[7] := RSContactsElement;
gbDayOffset.Caption := RSTimeIncLbl;
rgDayOffsetUnit.Caption := RSTimeIncUnits;
rgDayOffsetUnit.Items[0] := RSDays;
rgDayOffsetUnit.Items[1] := RSWeeks;
rgDayOffsetUnit.Items[2] := RSMonths;
rgDayOffsetUnit.Items[3] := RSYears;
gbVisual.Caption := RSVisualCaption;
rgRotation.Caption := RSRotationCaption;
rgMeasurement.Caption := RSMeasurementCaption;
rgMeasurement.Items[0] := RSPixels;
rgMeasurement.Items[1] := RSPercent;
rgMeasurement.Items[2] := RSInches;
lblLeft.Caption := RSLeft;
lblTop.Caption := RSTop;
lblWidth.Caption := RSWidth;
lblHeight.Caption := RSHeight;
chkVisible.Caption := RSVisible;
gbCaption.Caption := RSCaption;
lblCaptionText.Caption := RSTextCaption;
btnCaptionFont.Caption := RSFontBtn;
btnShape.Caption := RSShapeBtn;
btnOK.Caption := RSOKBtn;
btnCancel.Caption := RSCancelBtn;
RepositionControls;
end;
procedure TfrmEditElement.RepositionControls;
const
MARGIN = 16;
DELTA = 8;
RADIOITEM_CORRECTION = 24 + DELTA;
BUTTON_CORRECTION = 16;
GROUPBOX_CORRECTION = 16;
GROUPBOX_DISTANCE = 16;
var
i, w: Integer;
cnv: TControlCanvas;
begin
cnv := TControlCanvas.Create;
try
cnv.Control := rgItemType;
// Calculate with of ItemType groupbbox
cnv.Font.Assign(rgItemType.Font);
w := 0;
for i:=0 to rgItemType.Items.Count - 1 do
w := Max(w, cnv.TextWidth(rgItemType.Items[i]));
rgItemType.ClientWidth := rgItemType.Columns * (w + RADIOITEM_CORRECTION);
// Calculate width of Visual groupbox
cnv.Font.Assign(rgRotation.Font);
rgRotation.ClientWidth := Max(
cnv.TextWidth(RSRotationCaption) + GROUPBOX_CORRECTION,
cnv.TextWidth('270') + RADIOITEM_CORRECTION
);
cnv.Font.Assign(rgMeasurement.Font);
w := 0;
for i:=0 to RgMeasurement.Items.Count-1 do
w := Max(w, cnv.TextWidth(RgMeasurement.Items[i]));
rgMeasurement.ClientWidth := Max(
cnv.TextWidth(RSMeasurementCaption) + GROUPBOX_CORRECTION,
w + RADIOITEM_CORRECTION
);
rgMeasurement.Left := rgRotation.Left + rgRotation.Width + GROUPBOX_DISTANCE;
w := Max(GetLabelWidth(lblTop), GetLabelWidth(lblLeft)) + DELTA + EdTop.Width + udTop.Width + 24 +
Max(GetLabelWidth(lblHeight), GetLabelWidth(lblWidth) + DELTA) + EdHeight.Width + udHeight.Width;
gbVisual.ClientWidth := RightOf(rgMeasurement) + 24 + w + rgRotation.Left;
// The longest box determines the width of the form
if gbVisual.ClientWidth > rgItemType.ClientWidth then
rgItemType.ClientWidth := gbVisual.ClientWidth
else
gbVisual.ClientWidth := rgItemType.ClientWidth;
// Width of the form
ClientWidth := gbVisual.ClientWidth + MARGIN * 2;
// Position Left/Top etc controls
edTop.Left := (gbVisual.ClientWidth + RightOf(rgMeasurement) - w) div 2 +
Max(GetLabelWidth(lblTop), GetLabelWidth(lblLeft)) + DELTA;
edLeft.Left := edTop.Left;
udTop.Left := RightOf(edTop);
udLeft.Left := udTop.Left;
lblTop.Left := edTop.Left - GetLabelWidth(lblTop) - DELTA;
lblLeft.Left := edTop.Left - GetLabelWidth(lblLeft) - DELTA;
edHeight.Left := (gbVisual.ClientWidth + RightOf(rgMeasurement) + w ) div 2 - udHeight.Width - edHeight.Width;
edWidth.Left := edHeight.Left;
lblHeight.Left := edHeight.Left - GetLabelWidth(lblHeight) - DELTA;
lblWidth.Left := edHeight.Left - GetLabelWidth(lblWidth) - DELTA;
udHeight.Left := RightOf(edHeight);
udWidth.Left := RightOf(edWidth);
// Name
LblName.Left := MARGIN;
EdName.Left := LblName.Left + GetLabelWidth(LblName) + DELTA;
EdName.Width := RightOf(gbVisual) - EdName.Left;
// DayOffset groupbox
cnv.Font.Assign(gbDayOffset.Font);
gbDayOffset.Width := Max(RightOf(udOffset) + DELTA, cnv.TextWidth(gbDayOffset.Caption) + GROUPBOX_CORRECTION);
// Day Offset Unit groupbox
rgDayOffsetUnit.Left := RightOf(gbDayOffset) + GROUPBOX_DISTANCE;
rgDayOffsetUnit.Width := RightOf(gbVisual) - rgDayOffsetUnit.Left;
// Caption groupbox
gbCaption.Width := gbVisual.Width;
lblCaptionText.Left := DELTA;
edCaptionText.Left := lblCaptionText.Left + GetLabelWidth(lblCaptionTExt) + DELTA;
cnv.Font.Assign(btnCaptionFont.Font);
w := cnv.TextWidth(btnCaptionFont.Caption) + BUTTON_CORRECTION;
btnCaptionFont.Left := gbCaption.ClientWidth - DELTA - w;
edCaptionText.Width := btnCaptionFont.Left - DELTA - edCaptionText.Left;
// Buttons at the bottom
cnv.Font.Assign(btnOK.Font);
w := Max(cnv.TextWidth(btnOK.Caption), cnv.TextWidth(btnCancel.Caption));
btnOK.Width := w + BUTTON_CORRECTION;
btnCancel.Width := btnOK.Width;
btnCancel.Left := RightOf(gbCaption) - btnCancel.Width;
btnOK.Left := btnCancel.Left - DELTA - btnOK.Width;
finally
cnv.Free;
end;
end;
procedure TfrmEditElement.SetData(AnElement : TVpPrintFormatElementItem);
begin
edName.Text := AnElement.ElementName;
@ -247,7 +405,7 @@ begin
TheShape := AnElement.Shape;
TheCaption := AnElement.Caption;
rgDayOffset.ItemIndex := Ord(AnElement.DayOffsetUnits);
rgDayOffsetUnit.ItemIndex := Ord(AnElement.DayOffsetUnits);
rgRotation.ItemIndex := Ord(AnElement.Rotation);
rgMeasurement.ItemIndex := Ord(AnElement.Measurement);
SetMaxSpin(rgMeasurement.ItemIndex);
@ -272,7 +430,7 @@ begin
rgItemType.ItemIndex := Index;
gbCaption.Enabled := False;
edCaptionText.Enabled := False;
lbCaptionText.Enabled := False;
lblCaptionText.Enabled := False;
btnCaptionFont.Enabled := False;
@ -280,7 +438,7 @@ begin
if Index = 5 then begin
gbCaption.Enabled := True;
edCaptionText.Enabled := True;
lbCaptionText.Enabled := True;
lblCaptionText.Enabled := True;
btnCaptionFont.Enabled := True;
end;
end;

View File

@ -126,6 +126,7 @@ function GetLineDuration(Granularity: TVpGranularity): Double;
function GetLabelWidth(ALabel: TLabel): Integer;
function GetRealFontHeight(AFont: TFont): Integer;
function RightOf(AControl: TControl): Integer;
function DecodeLineEndings(const AText: String): String;
function EncodeLineEndings(const AText: String): String;
@ -584,6 +585,11 @@ begin
Result := AFont.Height;
end;
function RightOf(AControl: TControl): Integer;
begin
Result := AControl.Left + AControl.Width;
end;
function SameDate(dt1, dt2: TDateTime): Boolean;
begin
Result := trunc(dt1) = trunc(dt2);

View File

@ -425,6 +425,33 @@ resourcestring
RSTimeIncLbl = 'Time increment:';
RSTimeIncUnits = 'Time increment units:';
{ Format element editor }
RSEditElementCaption = 'Edit element';
RSElementTypeLbl = 'Element type';
RSDayViewElement = 'Day view';
RSWeekViewElement = 'Week view';
RSMonthViewElement = 'Month view';
RSCalendarElement = 'Calendar';
RSShapeElement = 'Shape';
RSCaptionElement = 'Caption';
RSTasksElement = 'Tasks';
RSContactsElement = 'Contacts';
RSVisualCaption = 'Visual';
RSRotationCaption = 'Rotation';
RSMeasurementCaption = 'Measurement';
RSPixels = 'Pixels';
RSPercent = 'Percent';
RSInches = 'Inches';
RSLeft = 'Left';
RSTop = 'Top';
RSWidth = 'Width';
RSHeight = 'Height';
RSVisible = 'Visible';
RSCaption = 'Caption';
RSTextCaption = 'Text';
RSShapeBtn = 'Shape...';
RSFontBtn = 'Font...';
{ Automatic resource adding/selection} {!!.01}
RSAddNewResource = 'No resources have been defined. Would you ' + {!!.01}