diff --git a/.gitattributes b/.gitattributes index 92d722cd98..a6613ed472 100644 --- a/.gitattributes +++ b/.gitattributes @@ -5166,6 +5166,8 @@ components/tachart/demo/charteditor/cefontframe.lfm svneol=native#text/plain components/tachart/demo/charteditor/cefontframe.pas svneol=native#text/pascal components/tachart/demo/charteditor/celegenddlg.lfm svneol=native#text/plain components/tachart/demo/charteditor/celegenddlg.pas svneol=native#text/pascal +components/tachart/demo/charteditor/celegendframe.lfm svneol=native#text/plain +components/tachart/demo/charteditor/celegendframe.pas svneol=native#text/pascal components/tachart/demo/charteditor/cemain.lfm svneol=native#text/plain components/tachart/demo/charteditor/cemain.pas svneol=native#text/pascal components/tachart/demo/charteditor/cepenframe.lfm svneol=native#text/plain diff --git a/components/tachart/demo/charteditor/celegenddlg.lfm b/components/tachart/demo/charteditor/celegenddlg.lfm index 96bb99c278..94f3df64ec 100644 --- a/components/tachart/demo/charteditor/celegenddlg.lfm +++ b/components/tachart/demo/charteditor/celegenddlg.lfm @@ -1,9 +1,8 @@ -object LegendEditor: TChartLegendEditor +object ChartLegendEditor: TChartLegendEditor Left = 978 Height = 396 Top = 169 Width = 590 - ActiveControl = cbShow BorderStyle = bsDialog Caption = 'Legend editor' ClientHeight = 396 @@ -28,516 +27,8 @@ object LegendEditor: TChartLegendEditor CloseButton.DefaultCaption = True CancelButton.Name = 'CancelButton' CancelButton.DefaultCaption = True - TabOrder = 2 + TabOrder = 0 ShowButtons = [pbOK, pbCancel] ShowGlyphs = [pbOK, pbCancel, pbClose] end - object ParamsPanel: TPanel - Left = 8 - Height = 309 - Top = 39 - Width = 574 - Align = alClient - AutoSize = True - BorderSpacing.Around = 8 - BevelOuter = bvNone - ClientHeight = 309 - ClientWidth = 574 - TabOrder = 1 - object gbBackground: TGroupBox - AnchorSideLeft.Control = gbAlignment - AnchorSideTop.Control = gbAlignment - AnchorSideTop.Side = asrBottom - AnchorSideBottom.Side = asrBottom - Left = 0 - Height = 83 - Top = 128 - Width = 140 - BorderSpacing.Top = 16 - Caption = 'Background' - ClientHeight = 63 - ClientWidth = 136 - TabOrder = 2 - object cbFilled: TCheckBox - AnchorSideLeft.Control = gbBackground - AnchorSideTop.Control = gbBackground - Left = 8 - Height = 19 - Top = 6 - Width = 48 - BorderSpacing.Left = 8 - BorderSpacing.Top = 6 - Caption = 'Filled' - OnChange = cbFilledChange - TabOrder = 0 - end - object cbFillColor: TColorBox - AnchorSideLeft.Control = cbFilled - AnchorSideTop.Control = cbFilled - AnchorSideTop.Side = asrBottom - Left = 8 - Height = 22 - Top = 33 - Width = 120 - Style = [cbStandardColors, cbExtendedColors, cbSystemColors, cbPrettyNames, cbCustomColors] - BorderSpacing.Top = 8 - BorderSpacing.Right = 8 - BorderSpacing.Bottom = 8 - ItemHeight = 16 - OnChange = cbFillColorChange - TabOrder = 1 - end - end - object gbBorder: TGroupBox - AnchorSideLeft.Control = gbBackground - AnchorSideLeft.Side = asrBottom - AnchorSideTop.Control = gbAlignment - AnchorSideTop.Side = asrBottom - AnchorSideBottom.Control = gbBackground - AnchorSideBottom.Side = asrBottom - Left = 156 - Height = 83 - Top = 128 - Width = 140 - Anchors = [akTop, akLeft, akBottom] - BorderSpacing.Left = 16 - BorderSpacing.Top = 16 - Caption = 'Border' - ClientHeight = 63 - ClientWidth = 136 - TabOrder = 3 - object cbShowBorder: TCheckBox - AnchorSideLeft.Control = gbBorder - AnchorSideTop.Control = gbBorder - Left = 8 - Height = 19 - Top = 6 - Width = 54 - BorderSpacing.Left = 8 - BorderSpacing.Top = 6 - Caption = 'Visible' - OnChange = cbShowBorderChange - TabOrder = 0 - end - object cbBorderColor: TColorBox - AnchorSideLeft.Control = cbShowBorder - AnchorSideTop.Control = cbShowBorder - AnchorSideTop.Side = asrBottom - Left = 8 - Height = 22 - Top = 33 - Width = 120 - Style = [cbStandardColors, cbExtendedColors, cbSystemColors, cbPrettyNames] - BorderSpacing.Top = 8 - BorderSpacing.Right = 8 - BorderSpacing.Bottom = 6 - ItemHeight = 16 - OnChange = cbBorderColorChange - TabOrder = 1 - Visible = False - end - end - object gbFont: TGroupBox - AnchorSideLeft.Control = gbAlignment - AnchorSideLeft.Side = asrBottom - AnchorSideTop.Control = gbAlignment - AnchorSideBottom.Control = gbAlignment - AnchorSideBottom.Side = asrBottom - Left = 316 - Height = 112 - Top = 0 - Width = 216 - Anchors = [akTop, akLeft, akBottom] - BorderSpacing.Left = 20 - Caption = 'gbFont' - TabOrder = 1 - end - object gbAlignment: TGroupBox - AnchorSideLeft.Control = ParamsPanel - AnchorSideTop.Control = ParamsPanel - AnchorSideBottom.Control = gbFont - AnchorSideBottom.Side = asrBottom - Left = 0 - Height = 112 - Top = 0 - Width = 296 - Caption = 'Position' - ChildSizing.LeftRightSpacing = 6 - ChildSizing.TopBottomSpacing = 6 - ChildSizing.EnlargeHorizontal = crsHomogenousChildResize - ChildSizing.EnlargeVertical = crsHomogenousChildResize - ChildSizing.ShrinkHorizontal = crsScaleChilds - ChildSizing.ShrinkVertical = crsScaleChilds - ChildSizing.Layout = cclLeftToRightThenTopToBottom - ChildSizing.ControlsPerLine = 3 - ClientHeight = 92 - ClientWidth = 292 - TabOrder = 0 - object rbTopLeft: TRadioButton - Left = 6 - Height = 17 - Top = 6 - Width = 86 - Caption = 'top/left' - OnChange = rbAlignmentChange - TabOrder = 0 - end - object rbTopCenter: TRadioButton - Tag = 3 - Left = 92 - Height = 17 - Top = 6 - Width = 102 - Caption = 'top/center' - OnChange = rbAlignmentChange - TabOrder = 1 - end - object rbTopRight: TRadioButton - Tag = 5 - Left = 194 - Height = 17 - Top = 6 - Width = 92 - Caption = 'top/right' - Checked = True - OnChange = rbAlignmentChange - TabOrder = 2 - TabStop = True - end - object rbCenterLeft: TRadioButton - Tag = 1 - Left = 6 - Height = 46 - Top = 23 - Width = 86 - Caption = 'center/left' - OnChange = rbAlignmentChange - TabOrder = 3 - end - object Bevel1: TBevel - Tag = 999 - Left = 92 - Height = 46 - Top = 23 - Width = 102 - Shape = bsSpacer - end - object rbCenterRight: TRadioButton - Tag = 6 - Left = 194 - Height = 46 - Top = 23 - Width = 92 - Caption = 'center/right' - OnChange = rbAlignmentChange - TabOrder = 4 - end - object rbBottomLeft: TRadioButton - Tag = 2 - Left = 6 - Height = 17 - Top = 69 - Width = 86 - Caption = 'bottom/left' - OnChange = rbAlignmentChange - TabOrder = 5 - end - object rbBottomCenter: TRadioButton - Tag = 4 - Left = 92 - Height = 17 - Top = 69 - Width = 102 - Caption = 'bottom/center' - OnChange = rbAlignmentChange - TabOrder = 6 - end - object rbBottomRight: TRadioButton - Tag = 7 - Left = 194 - Height = 17 - Top = 69 - Width = 92 - Caption = 'bottom/right' - OnChange = rbAlignmentChange - TabOrder = 7 - end - end - object gbMargins: TGroupBox - AnchorSideLeft.Control = ParamsPanel - AnchorSideTop.Control = gbBackground - AnchorSideTop.Side = asrBottom - AnchorSideRight.Control = gbBackground - AnchorSideRight.Side = asrBottom - Left = 0 - Height = 83 - Top = 224 - Width = 140 - Anchors = [akTop, akRight] - BorderSpacing.Top = 13 - Caption = 'Margins' - ClientHeight = 63 - ClientWidth = 136 - TabOrder = 4 - object lblMarginX: TLabel - AnchorSideTop.Control = seMarginX - AnchorSideTop.Side = asrCenter - AnchorSideRight.Control = seMarginX - Left = 31 - Height = 15 - Top = 8 - Width = 7 - Anchors = [akTop, akRight] - BorderSpacing.Right = 8 - Caption = 'X' - FocusControl = seMarginX - ParentColor = False - end - object seMarginX: TSpinEdit - AnchorSideTop.Control = gbMargins - AnchorSideRight.Side = asrBottom - Left = 46 - Height = 23 - Top = 4 - Width = 74 - Alignment = taRightJustify - Anchors = [akTop, akRight] - BorderSpacing.Top = 4 - BorderSpacing.Right = 10 - OnChange = seMarginXChange - TabOrder = 0 - Value = 1 - end - object lblMarginY: TLabel - AnchorSideTop.Control = seMarginY - AnchorSideTop.Side = asrCenter - AnchorSideRight.Control = seMarginY - Left = 31 - Height = 15 - Top = 37 - Width = 7 - Anchors = [akTop, akRight] - BorderSpacing.Right = 8 - Caption = 'Y' - FocusControl = seMarginY - ParentColor = False - end - object seMarginY: TSpinEdit - AnchorSideTop.Control = seMarginX - AnchorSideTop.Side = asrBottom - AnchorSideRight.Side = asrBottom - Left = 46 - Height = 23 - Top = 33 - Width = 74 - Alignment = taRightJustify - Anchors = [akTop, akRight] - BorderSpacing.Top = 6 - BorderSpacing.Right = 10 - OnChange = seMarginYChange - TabOrder = 1 - Value = 1 - end - end - object gbItems: TGroupBox - AnchorSideLeft.Control = gbFont - AnchorSideTop.Control = gbBackground - Left = 316 - Height = 179 - Top = 128 - Width = 222 - Caption = 'Items' - ClientHeight = 159 - ClientWidth = 218 - TabOrder = 5 - object cbInverted: TCheckBox - AnchorSideLeft.Control = gbItems - AnchorSideTop.Control = gbItems - Left = 8 - Height = 19 - Top = 6 - Width = 63 - BorderSpacing.Left = 8 - BorderSpacing.Top = 6 - Caption = 'Inverted' - OnChange = cbInvertedChange - TabOrder = 0 - end - object seColumns: TSpinEdit - AnchorSideTop.Control = cbInverted - AnchorSideTop.Side = asrBottom - AnchorSideRight.Control = gbItems - AnchorSideRight.Side = asrBottom - Left = 114 - Height = 23 - Top = 33 - Width = 96 - Alignment = taRightJustify - Anchors = [akTop, akRight] - BorderSpacing.Top = 8 - BorderSpacing.Right = 8 - OnChange = seColumnsChange - TabOrder = 1 - Value = 1 - end - object lblColumns: TLabel - AnchorSideLeft.Control = cbInverted - AnchorSideTop.Control = seColumns - AnchorSideTop.Side = asrCenter - AnchorSideRight.Control = seColumns - Left = 8 - Height = 15 - Top = 37 - Width = 98 - Anchors = [akTop, akLeft, akRight] - BorderSpacing.Right = 8 - Caption = 'Columns' - FocusControl = seColumns - ParentColor = False - end - object lblItemFillOrder: TLabel - AnchorSideLeft.Control = cbInverted - AnchorSideTop.Control = cbItemFillOrder - AnchorSideTop.Side = asrCenter - AnchorSideRight.Control = cbItemFillOrder - Left = 8 - Height = 15 - Top = 68 - Width = 98 - Anchors = [akTop, akLeft, akRight] - BorderSpacing.Right = 8 - Caption = 'Item fill order' - ParentColor = False - end - object cbItemFillOrder: TComboBox - AnchorSideTop.Control = seColumns - AnchorSideTop.Side = asrBottom - AnchorSideRight.Control = gbItems - AnchorSideRight.Side = asrBottom - Left = 114 - Height = 23 - Top = 64 - Width = 96 - Anchors = [akTop, akRight] - BorderSpacing.Top = 8 - BorderSpacing.Right = 8 - ItemHeight = 15 - ItemIndex = 0 - Items.Strings = ( - 'by columns' - 'by rows' - ) - OnChange = cbItemFillOrderChange - TabOrder = 2 - Text = 'by columns' - end - object seSpacing: TSpinEdit - AnchorSideTop.Control = cbItemFillOrder - AnchorSideTop.Side = asrBottom - AnchorSideRight.Control = gbItems - AnchorSideRight.Side = asrBottom - Left = 114 - Height = 23 - Top = 95 - Width = 96 - Alignment = taRightJustify - Anchors = [akTop, akRight] - BorderSpacing.Top = 8 - BorderSpacing.Right = 8 - OnChange = seSpacingChange - TabOrder = 3 - Value = 20 - end - object lblSpacing: TLabel - AnchorSideLeft.Control = cbInverted - AnchorSideTop.Control = seSpacing - AnchorSideTop.Side = asrCenter - AnchorSideRight.Control = seSpacing - Left = 8 - Height = 15 - Top = 99 - Width = 98 - Anchors = [akTop, akLeft, akRight] - BorderSpacing.Right = 8 - Caption = 'Spacing' - FocusControl = seSpacing - ParentColor = False - end - object seSymbolWidth: TSpinEdit - AnchorSideTop.Control = seSpacing - AnchorSideTop.Side = asrBottom - AnchorSideRight.Control = gbItems - AnchorSideRight.Side = asrBottom - Left = 114 - Height = 23 - Top = 126 - Width = 96 - Alignment = taRightJustify - Anchors = [akTop, akRight] - BorderSpacing.Top = 8 - BorderSpacing.Right = 8 - OnChange = seSymbolWidthChange - TabOrder = 4 - Value = 20 - end - object lblSymbolWidth: TLabel - AnchorSideLeft.Control = cbInverted - AnchorSideTop.Control = seSymbolWidth - AnchorSideTop.Side = asrCenter - AnchorSideRight.Control = seSymbolWidth - Left = 8 - Height = 15 - Top = 130 - Width = 98 - Anchors = [akTop, akLeft, akRight] - BorderSpacing.Right = 8 - Caption = 'Symbol width' - FocusControl = seSymbolWidth - ParentColor = False - end - end - end - object PanelTop: TPanel - Left = 0 - Height = 31 - Top = 0 - Width = 590 - Align = alTop - AutoSize = True - BevelOuter = bvNone - ClientHeight = 31 - ClientWidth = 590 - TabOrder = 0 - object cbShow: TCheckBox - Left = 8 - Height = 19 - Top = 8 - Width = 49 - BorderSpacing.Left = 8 - BorderSpacing.Top = 8 - BorderSpacing.Bottom = 4 - Caption = 'Show' - Checked = True - OnChange = cbShowChange - State = cbChecked - TabOrder = 0 - end - object cbUseSideBar: TCheckBox - AnchorSideLeft.Control = cbShow - AnchorSideLeft.Side = asrBottom - AnchorSideTop.Control = cbShow - AnchorSideRight.Side = asrBottom - Left = 73 - Height = 19 - Top = 8 - Width = 87 - Alignment = taLeftJustify - BorderSpacing.Left = 16 - Caption = 'Outside axes' - Checked = True - OnChange = cbUseSideBarChange - State = cbChecked - TabOrder = 1 - end - end end diff --git a/components/tachart/demo/charteditor/celegenddlg.pas b/components/tachart/demo/charteditor/celegenddlg.pas index 2669ecfe33..2846b47c03 100644 --- a/components/tachart/demo/charteditor/celegenddlg.pas +++ b/components/tachart/demo/charteditor/celegenddlg.pas @@ -6,78 +6,26 @@ interface uses Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ButtonPanel, - ExtCtrls, Buttons, ColorBox, ComCtrls, Spin, ceFontFrame, - TAGraph, TALegend; + ExtCtrls, Buttons, ColorBox, ComCtrls, Spin, + TAGraph, TALegend, + ceLegendFrame; type { TChartLegendEditor } TChartLegendEditor = class(TForm) - Bevel1: TBevel; ButtonPanel: TButtonPanel; - cbFilled: TCheckBox; - cbShowBorder: TCheckBox; - cbShow: TCheckBox; - cbFillColor: TColorBox; - cbBorderColor: TColorBox; - cbInverted: TCheckBox; - cbUseSideBar: TCheckBox; - cbItemFillOrder: TComboBox; - gbBackground: TGroupBox; - gbBorder: TGroupBox; - gbFont: TGroupBox; - gbMargins: TGroupBox; - gbItems: TGroupBox; - lblMarginX: TLabel; - lblMarginY: TLabel; - lblItemFillOrder: TLabel; - lblColumns: TLabel; - lblSymbolWidth: TLabel; - lblSpacing: TLabel; - PanelTop: TPanel; - ParamsPanel: TPanel; - rbTopLeft: TRadioButton; - rbTopCenter: TRadioButton; - rbTopRight: TRadioButton; - rbCenterLeft: TRadioButton; - rbCenterRight: TRadioButton; - rbBottomLeft: TRadioButton; - rbBottomCenter: TRadioButton; - rbBottomRight: TRadioButton; - gbAlignment: TGroupBox; - seColumns: TSpinEdit; - seMarginX: TSpinEdit; - seMarginY: TSpinEdit; - seSymbolWidth: TSpinEdit; - seSpacing: TSpinEdit; - procedure cbBorderColorChange(Sender: TObject); - procedure cbFillColorChange(Sender: TObject); - procedure cbInvertedChange(Sender: TObject); - procedure cbItemFillOrderChange(Sender: TObject); - procedure cbFilledChange(Sender: TObject); - procedure cbShowBorderChange(Sender: TObject); - procedure cbShowChange(Sender: TObject); - procedure cbUseSideBarChange(Sender: TObject); procedure FormCloseQuery(Sender: TObject; var CanClose: boolean); procedure FormCreate(Sender: TObject); procedure FormDestroy(Sender: TObject); procedure FormShow(Sender: TObject); procedure OKButtonClick(Sender: TObject); - procedure rbAlignmentChange(Sender: TObject); - procedure seColumnsChange(Sender: TObject); - procedure seMarginXChange(Sender: TObject); - procedure seMarginYChange(Sender: TObject); - procedure seSpacingChange(Sender: TObject); - procedure seSymbolWidthChange(Sender: TObject); private FLegend: TChartLegend; + FLegendFrame: TChartLegendFrame; FSavedLegend: TChartLegend; FOKClicked: Boolean; - FFontFrame: TChartFontFrame; - procedure ChangedHandler(Sender: TObject); - function GetAlignment: TLegendAlignment; - procedure SetAlignment(AValue: TLegendAlignment); protected function GetChart: TChart; public @@ -95,63 +43,6 @@ implementation uses ceUtils; -procedure TChartLegendEditor.cbBorderColorChange(Sender: TObject); -begin - FLegend.Frame.Color := cbBorderColor.Selected; -end; - -procedure TChartLegendEditor.cbFillColorChange(Sender: TObject); -begin - FLegend.BackgroundBrush.Color := cbFillColor.Selected; -end; - -procedure TChartLegendEditor.cbInvertedChange(Sender: TObject); -begin - FLegend.Inverted := cbInverted.Checked; -end; - -procedure TChartLegendEditor.cbItemFillOrderChange(Sender: TObject); -begin - FLegend.ItemFillOrder := TLegendItemFillOrder(cbItemFillOrder.ItemIndex); -end; - -procedure TChartLegendEditor.cbFilledChange(Sender: TObject); -begin - cbFillColor.Visible := cbFilled.Checked; - if cbFilled.Checked then - FLegend.BackgroundBrush.Style := bsSolid - else - FLegend.BackgroundBrush.Style := bsClear; -end; - -procedure TChartLegendEditor.cbShowBorderChange(Sender: TObject); -begin - FLegend.Frame.Visible := cbShowBorder.Checked; - cbBorderColor.Visible := cbShowBorder.Checked; -end; - -procedure TChartLegendEditor.cbShowChange(Sender: TObject); -begin - FLegend.Visible := cbShow.Checked; - cbUseSideBar.Visible := cbShow.Checked; - gbAlignment.Visible := cbShow.Checked; - gbFont.Visible := cbShow.Checked; - gbBackground.Visible := cbShow.Checked; - gbBorder.Visible := cbShow.Checked; - gbItems.Visible := cbShow.Checked; - gbMargins.Visible := cbShow.Checked; -end; - -procedure TChartLegendEditor.cbUseSideBarChange(Sender: TObject); -begin - FLegend.UseSideBar := cbUseSideBar.Checked; -end; - -procedure TChartLegendEditor.ChangedHandler(Sender: TObject); -begin - GetChart.Invalidate; -end; - procedure TChartLegendEditor.FormCloseQuery(Sender: TObject; var CanClose: boolean); begin if not CanClose then exit; @@ -163,18 +54,14 @@ end; procedure TChartLegendEditor.FormCreate(Sender: TObject); begin - FFontFrame := TChartFontFrame.Create(self); - FFontFrame.Parent := gbFont; - FFontFrame.Name := ''; - FFontFrame.Align := alClient; - FFontFrame.BorderSpacing.Left := 8; - FFontFrame.BorderSpacing.Right := 8; - FFontFrame.AutoSize := true; - FFontFrame.OnChange := @ChangedHandler; - gbFont.AutoSize := true; - gbFont.Caption := 'Font'; + FLegendFrame := TChartLegendFrame.Create(self); + FLegendFrame.Parent := self; + FLegendFrame.Name := ''; + FLegendFrame.Align := alClient; + FLegendFrame.BorderSpacing.Around := 8; + FLegendFrame.AutoSize := true; - BoldHeaders(Self); + AutoSize := true; end; procedure TChartLegendEditor.FormDestroy(Sender: TObject); @@ -184,32 +71,9 @@ end; procedure TChartLegendEditor.FormShow(Sender: TObject); begin - if cbShow.Checked then begin - AutoSize := true; - Constraints.MinWidth := Width; - Constraints.MinHeight := Height; - AutoSize := false; - end; - FOKClicked := false; end; -function TChartLegendEditor.GetAlignment: TLegendAlignment; -var - i: Integer; - rb: TRadioButton; -begin - for i := 0 to gbAlignment.ControlCount-1 do - if (gbAlignment.Controls[i] is TRadioButton) then begin - rb := TRadioButton(gbAlignment.Controls[i]); - if rb.Checked then begin - Result := TLegendAlignment(rb.Tag); - exit; - end; - end; - Result := laTopRight; -end; - function TChartLegendEditor.GetChart: TChart; begin Result := FLegend.GetOwner as TChart; @@ -220,51 +84,6 @@ begin FOKClicked := true; end; -procedure TChartLegendEditor.rbAlignmentChange(Sender: TObject); -begin - FLegend.Alignment := GetAlignment; -end; - -procedure TChartLegendEditor.seColumnsChange(Sender: TObject); -begin - FLegend.ColumnCount := seColumns.Value; -end; - -procedure TChartLegendEditor.seMarginXChange(Sender: TObject); -begin - FLegend.MarginX := seMarginX.Value; -end; - -procedure TChartLegendEditor.seMarginYChange(Sender: TObject); -begin - FLegend.MarginY := seMarginY.Value; -end; - -procedure TChartLegendEditor.seSpacingChange(Sender: TObject); -begin - FLegend.Spacing := seSpacing.Value; -end; - -procedure TChartLegendEditor.seSymbolWidthChange(Sender: TObject); -begin - FLegend.SymbolWidth := seSymbolWidth.Value; -end; - -procedure TChartLegendEditor.SetAlignment(AValue: TLegendAlignment); -var - i: Integer; - rb: TRadioButton; -begin - for i:=0 to gbAlignment.ControlCount-1 do - if (gbAlignment.Controls[i] is TRadioButton) then begin - rb := TRadioButton(gbAlignment.Controls[i]); - if rb.Tag = ord(AValue) then begin - rb.Checked := true; - exit; - end; - end; -end; - procedure TChartLegendEditor.Prepare(ALegend: TChartLegend; ACaption: String = ''); begin @@ -276,26 +95,7 @@ begin if ACaption <> '' then Caption := ACaption; - cbShow.Checked := ALegend.Visible; - SetAlignment(ALegend.Alignment); - - cbFilled.Checked := ALegend.BackgroundBrush.Style <> bsClear; - cbFillColor.Selected := ColorToRGB(ALegend.BackgroundBrush.Color); - - cbShowBorder.Checked := (ALegend.Frame.Style <> psClear) and ALegend.Frame.Visible; - cbBorderColor.Selected := ColorToRGB(ALegend.Frame.Color); - - seMarginX.Value := ALegend.MarginX; - seMarginY.Value := ALegend.MarginY; - - cbUseSideBar.Checked := ALegend.UseSidebar; - cbInverted.Checked := ALegend.Inverted; - seColumns.Value := ALegend.ColumnCount; - seSymbolWidth.Value := ALegend.SymbolWidth; - seSpacing.Value := ALegend.Spacing; - cbItemFillOrder.ItemIndex := ord(ALegend.ItemFillOrder); - - FFontFrame.Prepare(ALegend.Font, false); + FLegendFrame.Prepare(ALegend); end; end. diff --git a/components/tachart/demo/charteditor/celegendframe.lfm b/components/tachart/demo/charteditor/celegendframe.lfm new file mode 100644 index 0000000000..b481551511 --- /dev/null +++ b/components/tachart/demo/charteditor/celegendframe.lfm @@ -0,0 +1,509 @@ +object ChartLegendFrame: TChartLegendFrame + Left = 0 + Height = 400 + Top = 0 + Width = 671 + ClientHeight = 400 + ClientWidth = 671 + TabOrder = 0 + DesignLeft = 380 + DesignTop = 303 + object PanelTop: TPanel + Left = 0 + Height = 23 + Top = 0 + Width = 671 + Align = alTop + AutoSize = True + BorderSpacing.Bottom = 8 + BevelOuter = bvNone + ClientHeight = 23 + ClientWidth = 671 + TabOrder = 0 + object cbShow: TCheckBox + Left = 0 + Height = 19 + Top = 0 + Width = 49 + BorderSpacing.Bottom = 4 + Caption = 'Show' + Checked = True + OnChange = cbShowChange + State = cbChecked + TabOrder = 0 + end + object cbUseSideBar: TCheckBox + AnchorSideLeft.Control = cbShow + AnchorSideLeft.Side = asrBottom + AnchorSideTop.Control = cbShow + AnchorSideRight.Side = asrBottom + Left = 65 + Height = 19 + Top = 0 + Width = 87 + Alignment = taLeftJustify + BorderSpacing.Left = 16 + Caption = 'Outside axes' + Checked = True + OnChange = cbUseSideBarChange + State = cbChecked + TabOrder = 1 + end + end + object ParamsPanel: TPanel + Left = 0 + Height = 369 + Top = 31 + Width = 671 + Align = alClient + AutoSize = True + BevelOuter = bvNone + ClientHeight = 369 + ClientWidth = 671 + TabOrder = 1 + object gbBackground: TGroupBox + AnchorSideLeft.Control = gbAlignment + AnchorSideTop.Control = gbAlignment + AnchorSideTop.Side = asrBottom + AnchorSideBottom.Side = asrBottom + Left = 0 + Height = 83 + Top = 128 + Width = 140 + BorderSpacing.Top = 16 + Caption = 'Background' + ClientHeight = 63 + ClientWidth = 136 + TabOrder = 2 + object cbFilled: TCheckBox + AnchorSideLeft.Control = gbBackground + AnchorSideTop.Control = gbBackground + Left = 8 + Height = 19 + Top = 6 + Width = 48 + BorderSpacing.Left = 8 + BorderSpacing.Top = 6 + Caption = 'Filled' + OnChange = cbFilledChange + TabOrder = 0 + end + object cbFillColor: TColorBox + AnchorSideLeft.Control = cbFilled + AnchorSideTop.Control = cbFilled + AnchorSideTop.Side = asrBottom + Left = 8 + Height = 22 + Top = 33 + Width = 120 + Style = [cbStandardColors, cbExtendedColors, cbSystemColors, cbPrettyNames, cbCustomColors] + BorderSpacing.Top = 8 + BorderSpacing.Right = 8 + BorderSpacing.Bottom = 8 + ItemHeight = 16 + OnChange = cbFillColorChange + TabOrder = 1 + end + end + object gbBorder: TGroupBox + AnchorSideLeft.Control = gbBackground + AnchorSideLeft.Side = asrBottom + AnchorSideTop.Control = gbAlignment + AnchorSideTop.Side = asrBottom + AnchorSideBottom.Control = gbBackground + AnchorSideBottom.Side = asrBottom + Left = 156 + Height = 83 + Top = 128 + Width = 140 + Anchors = [akTop, akLeft, akBottom] + BorderSpacing.Left = 16 + BorderSpacing.Top = 16 + Caption = 'Border' + ClientHeight = 63 + ClientWidth = 136 + TabOrder = 3 + object cbShowBorder: TCheckBox + AnchorSideLeft.Control = gbBorder + AnchorSideTop.Control = gbBorder + Left = 8 + Height = 19 + Top = 6 + Width = 54 + BorderSpacing.Left = 8 + BorderSpacing.Top = 6 + Caption = 'Visible' + OnChange = cbShowBorderChange + TabOrder = 0 + end + object cbBorderColor: TColorBox + AnchorSideLeft.Control = cbShowBorder + AnchorSideTop.Control = cbShowBorder + AnchorSideTop.Side = asrBottom + Left = 8 + Height = 22 + Top = 33 + Width = 120 + Style = [cbStandardColors, cbExtendedColors, cbSystemColors, cbPrettyNames] + BorderSpacing.Top = 8 + BorderSpacing.Right = 8 + BorderSpacing.Bottom = 6 + ItemHeight = 16 + OnChange = cbBorderColorChange + TabOrder = 1 + Visible = False + end + end + object gbFont: TGroupBox + AnchorSideLeft.Control = gbAlignment + AnchorSideLeft.Side = asrBottom + AnchorSideTop.Control = gbAlignment + AnchorSideBottom.Control = gbAlignment + AnchorSideBottom.Side = asrBottom + Left = 316 + Height = 112 + Top = 0 + Width = 216 + Anchors = [akTop, akLeft, akBottom] + BorderSpacing.Left = 20 + Caption = 'gbFont' + TabOrder = 1 + end + object gbAlignment: TGroupBox + AnchorSideLeft.Control = ParamsPanel + AnchorSideTop.Control = ParamsPanel + AnchorSideBottom.Control = gbFont + AnchorSideBottom.Side = asrBottom + Left = 0 + Height = 112 + Top = 0 + Width = 296 + Caption = 'Position' + ChildSizing.LeftRightSpacing = 6 + ChildSizing.TopBottomSpacing = 6 + ChildSizing.EnlargeHorizontal = crsHomogenousChildResize + ChildSizing.EnlargeVertical = crsHomogenousChildResize + ChildSizing.ShrinkHorizontal = crsScaleChilds + ChildSizing.ShrinkVertical = crsScaleChilds + ChildSizing.Layout = cclLeftToRightThenTopToBottom + ChildSizing.ControlsPerLine = 3 + ClientHeight = 92 + ClientWidth = 292 + TabOrder = 0 + OnClick = gbAlignmentClick + object rbTopLeft: TRadioButton + Left = 6 + Height = 17 + Top = 6 + Width = 86 + Caption = 'top/left' + TabOrder = 0 + end + object rbTopCenter: TRadioButton + Tag = 3 + Left = 92 + Height = 17 + Top = 6 + Width = 102 + Caption = 'top/center' + TabOrder = 1 + end + object rbTopRight: TRadioButton + Tag = 5 + Left = 194 + Height = 17 + Top = 6 + Width = 92 + Caption = 'top/right' + Checked = True + TabOrder = 2 + TabStop = True + end + object rbCenterLeft: TRadioButton + Tag = 1 + Left = 6 + Height = 46 + Top = 23 + Width = 86 + Caption = 'center/left' + TabOrder = 3 + end + object Bevel1: TBevel + Tag = 999 + Left = 92 + Height = 46 + Top = 23 + Width = 102 + Shape = bsSpacer + end + object rbCenterRight: TRadioButton + Tag = 6 + Left = 194 + Height = 46 + Top = 23 + Width = 92 + Caption = 'center/right' + TabOrder = 4 + end + object rbBottomLeft: TRadioButton + Tag = 2 + Left = 6 + Height = 17 + Top = 69 + Width = 86 + Caption = 'bottom/left' + TabOrder = 5 + end + object rbBottomCenter: TRadioButton + Tag = 4 + Left = 92 + Height = 17 + Top = 69 + Width = 102 + Caption = 'bottom/center' + TabOrder = 6 + end + object rbBottomRight: TRadioButton + Tag = 7 + Left = 194 + Height = 17 + Top = 69 + Width = 92 + Caption = 'bottom/right' + TabOrder = 7 + end + end + object gbMargins: TGroupBox + AnchorSideLeft.Control = ParamsPanel + AnchorSideTop.Control = gbBackground + AnchorSideTop.Side = asrBottom + AnchorSideRight.Control = gbBackground + AnchorSideRight.Side = asrBottom + Left = 0 + Height = 83 + Top = 224 + Width = 140 + Anchors = [akTop, akRight] + BorderSpacing.Top = 13 + Caption = 'Margins' + ClientHeight = 63 + ClientWidth = 136 + TabOrder = 4 + object lblMarginX: TLabel + AnchorSideTop.Control = seMarginX + AnchorSideTop.Side = asrCenter + AnchorSideRight.Control = seMarginX + Left = 31 + Height = 15 + Top = 8 + Width = 7 + Anchors = [akTop, akRight] + BorderSpacing.Right = 8 + Caption = 'X' + FocusControl = seMarginX + ParentColor = False + end + object seMarginX: TSpinEdit + AnchorSideTop.Control = gbMargins + AnchorSideRight.Side = asrBottom + Left = 46 + Height = 23 + Top = 4 + Width = 74 + Alignment = taRightJustify + Anchors = [akTop, akRight] + BorderSpacing.Top = 4 + BorderSpacing.Right = 10 + OnChange = seMarginXChange + TabOrder = 0 + Value = 1 + end + object lblMarginY: TLabel + AnchorSideTop.Control = seMarginY + AnchorSideTop.Side = asrCenter + AnchorSideRight.Control = seMarginY + Left = 31 + Height = 15 + Top = 37 + Width = 7 + Anchors = [akTop, akRight] + BorderSpacing.Right = 8 + Caption = 'Y' + FocusControl = seMarginY + ParentColor = False + end + object seMarginY: TSpinEdit + AnchorSideTop.Control = seMarginX + AnchorSideTop.Side = asrBottom + AnchorSideRight.Side = asrBottom + Left = 46 + Height = 23 + Top = 33 + Width = 74 + Alignment = taRightJustify + Anchors = [akTop, akRight] + BorderSpacing.Top = 6 + BorderSpacing.Right = 10 + TabOrder = 1 + Value = 1 + end + end + object gbItems: TGroupBox + AnchorSideLeft.Control = gbFont + AnchorSideTop.Control = gbBackground + Left = 316 + Height = 179 + Top = 128 + Width = 222 + Caption = 'Items' + ClientHeight = 159 + ClientWidth = 218 + TabOrder = 5 + object cbInverted: TCheckBox + AnchorSideLeft.Control = gbItems + AnchorSideTop.Control = gbItems + Left = 8 + Height = 19 + Top = 6 + Width = 63 + BorderSpacing.Left = 8 + BorderSpacing.Top = 6 + Caption = 'Inverted' + OnChange = cbInvertedChange + TabOrder = 0 + end + object seColumns: TSpinEdit + AnchorSideTop.Control = cbInverted + AnchorSideTop.Side = asrBottom + AnchorSideRight.Control = gbItems + AnchorSideRight.Side = asrBottom + Left = 114 + Height = 23 + Top = 33 + Width = 96 + Alignment = taRightJustify + Anchors = [akTop, akRight] + BorderSpacing.Top = 8 + BorderSpacing.Right = 8 + OnChange = seColumnsChange + TabOrder = 1 + Value = 1 + end + object lblColumns: TLabel + AnchorSideLeft.Control = cbInverted + AnchorSideTop.Control = seColumns + AnchorSideTop.Side = asrCenter + AnchorSideRight.Control = seColumns + Left = 8 + Height = 15 + Top = 37 + Width = 98 + Anchors = [akTop, akLeft, akRight] + BorderSpacing.Right = 8 + Caption = 'Columns' + FocusControl = seColumns + ParentColor = False + end + object lblItemFillOrder: TLabel + AnchorSideLeft.Control = cbInverted + AnchorSideTop.Control = cbItemFillOrder + AnchorSideTop.Side = asrCenter + AnchorSideRight.Control = cbItemFillOrder + Left = 8 + Height = 15 + Top = 68 + Width = 98 + Anchors = [akTop, akLeft, akRight] + BorderSpacing.Right = 8 + Caption = 'Item fill order' + ParentColor = False + end + object cbItemFillOrder: TComboBox + AnchorSideTop.Control = seColumns + AnchorSideTop.Side = asrBottom + AnchorSideRight.Control = gbItems + AnchorSideRight.Side = asrBottom + Left = 114 + Height = 23 + Top = 64 + Width = 96 + Anchors = [akTop, akRight] + BorderSpacing.Top = 8 + BorderSpacing.Right = 8 + ItemHeight = 15 + ItemIndex = 0 + Items.Strings = ( + 'by columns' + 'by rows' + ) + OnChange = cbItemFillOrderChange + TabOrder = 2 + Text = 'by columns' + end + object seSpacing: TSpinEdit + AnchorSideTop.Control = cbItemFillOrder + AnchorSideTop.Side = asrBottom + AnchorSideRight.Control = gbItems + AnchorSideRight.Side = asrBottom + Left = 114 + Height = 23 + Top = 95 + Width = 96 + Alignment = taRightJustify + Anchors = [akTop, akRight] + BorderSpacing.Top = 8 + BorderSpacing.Right = 8 + OnChange = seSpacingChange + TabOrder = 3 + Value = 20 + end + object lblSpacing: TLabel + AnchorSideLeft.Control = cbInverted + AnchorSideTop.Control = seSpacing + AnchorSideTop.Side = asrCenter + AnchorSideRight.Control = seSpacing + Left = 8 + Height = 15 + Top = 99 + Width = 98 + Anchors = [akTop, akLeft, akRight] + BorderSpacing.Right = 8 + Caption = 'Spacing' + FocusControl = seSpacing + ParentColor = False + end + object seSymbolWidth: TSpinEdit + AnchorSideTop.Control = seSpacing + AnchorSideTop.Side = asrBottom + AnchorSideRight.Control = gbItems + AnchorSideRight.Side = asrBottom + Left = 114 + Height = 23 + Top = 126 + Width = 96 + Alignment = taRightJustify + Anchors = [akTop, akRight] + BorderSpacing.Top = 8 + BorderSpacing.Right = 8 + OnChange = seSymbolWidthChange + TabOrder = 4 + Value = 20 + end + object lblSymbolWidth: TLabel + AnchorSideLeft.Control = cbInverted + AnchorSideTop.Control = seSymbolWidth + AnchorSideTop.Side = asrCenter + AnchorSideRight.Control = seSymbolWidth + Left = 8 + Height = 15 + Top = 130 + Width = 98 + Anchors = [akTop, akLeft, akRight] + BorderSpacing.Right = 8 + Caption = 'Symbol width' + FocusControl = seSymbolWidth + ParentColor = False + end + end + end +end diff --git a/components/tachart/demo/charteditor/celegendframe.pas b/components/tachart/demo/charteditor/celegendframe.pas new file mode 100644 index 0000000000..6c40041884 --- /dev/null +++ b/components/tachart/demo/charteditor/celegendframe.pas @@ -0,0 +1,257 @@ +unit ceLegendFrame; + +{$mode ObjFPC}{$H+} + +interface + +uses + Classes, SysUtils, Graphics, + Forms, Controls, ExtCtrls, ColorBox, StdCtrls, Spin, + TALegend, TAGraph, + ceFontFrame; + +type + + { TChartLegendFrame } + + TChartLegendFrame = class(TFrame) + Bevel1: TBevel; + cbBorderColor: TColorBox; + cbFillColor: TColorBox; + cbFilled: TCheckBox; + cbInverted: TCheckBox; + cbItemFillOrder: TComboBox; + cbShow: TCheckBox; + cbShowBorder: TCheckBox; + cbUseSideBar: TCheckBox; + gbAlignment: TGroupBox; + gbBackground: TGroupBox; + gbBorder: TGroupBox; + gbFont: TGroupBox; + gbItems: TGroupBox; + gbMargins: TGroupBox; + lblColumns: TLabel; + lblItemFillOrder: TLabel; + lblMarginX: TLabel; + lblMarginY: TLabel; + lblSpacing: TLabel; + lblSymbolWidth: TLabel; + PanelTop: TPanel; + ParamsPanel: TPanel; + rbBottomCenter: TRadioButton; + rbBottomLeft: TRadioButton; + rbBottomRight: TRadioButton; + rbCenterLeft: TRadioButton; + rbCenterRight: TRadioButton; + rbTopCenter: TRadioButton; + rbTopLeft: TRadioButton; + rbTopRight: TRadioButton; + seColumns: TSpinEdit; + seMarginX: TSpinEdit; + seMarginY: TSpinEdit; + seSpacing: TSpinEdit; + seSymbolWidth: TSpinEdit; + procedure cbBorderColorChange(Sender: TObject); + procedure cbFillColorChange(Sender: TObject); + procedure cbFilledChange(Sender: TObject); + procedure cbInvertedChange(Sender: TObject); + procedure cbItemFillOrderChange(Sender: TObject); + procedure cbShowBorderChange(Sender: TObject); + procedure cbShowChange(Sender: TObject); + procedure cbUseSideBarChange(Sender: TObject); + procedure gbAlignmentClick(Sender: TObject); + procedure seColumnsChange(Sender: TObject); + procedure seMarginXChange(Sender: TObject); + procedure seMarginYChange(Sender: TObject); + procedure seSpacingChange(Sender: TObject); + procedure seSymbolWidthChange(Sender: TObject); + private + FLegend: TChartLegend; + FFontFrame: TChartFontFrame; + procedure ChangedHandler(Sender: TObject); + function GetAlignment: TLegendAlignment; + procedure SetAlignment(AValue: TLegendAlignment); + protected + function GetChart: TChart; + public + constructor Create(AOwner: TComponent); override; + procedure Prepare(ALegend: TChartLegend); + end; + + +implementation + +{$R *.lfm} + +uses + ceUtils; + +constructor TChartLegendFrame.Create(AOwner: TComponent); +begin + inherited; + + FFontFrame := TChartFontFrame.Create(self); + FFontFrame.Parent := gbFont; + FFontFrame.Name := ''; + FFontFrame.Align := alClient; + FFontFrame.BorderSpacing.Left := 8; + FFontFrame.BorderSpacing.Right := 8; + FFontFrame.AutoSize := true; + FFontFrame.OnChange := @ChangedHandler; + gbFont.AutoSize := true; + gbFont.Caption := 'Font'; + + BoldHeaders(Self); +end; + +procedure TChartLegendFrame.cbBorderColorChange(Sender: TObject); +begin + FLegend.Frame.Color := cbBorderColor.Selected; +end; + +procedure TChartLegendFrame.cbFilledChange(Sender: TObject); +begin + cbFillColor.Visible := cbFilled.Checked; + if cbFilled.Checked then + FLegend.BackgroundBrush.Style := bsSolid + else + FLegend.BackgroundBrush.Style := bsClear; +end; + +procedure TChartLegendFrame.cbFillColorChange(Sender: TObject); +begin + FLegend.BackgroundBrush.Color := cbFillColor.Selected; +end; + +procedure TChartLegendFrame.cbInvertedChange(Sender: TObject); +begin + FLegend.Inverted := cbInverted.Checked; +end; + +procedure TChartLegendFrame.cbItemFillOrderChange(Sender: TObject); +begin + FLegend.ItemFillOrder := TLegendItemFillOrder(cbItemFillOrder.ItemIndex); +end; + +procedure TChartLegendFrame.cbShowChange(Sender: TObject); +begin + FLegend.Visible := cbShow.Checked; + cbUseSideBar.Visible := cbShow.Checked; + gbAlignment.Visible := cbShow.Checked; + gbFont.Visible := cbShow.Checked; + gbBackground.Visible := cbShow.Checked; + gbBorder.Visible := cbShow.Checked; + gbItems.Visible := cbShow.Checked; + gbMargins.Visible := cbShow.Checked; +end; + +procedure TChartLegendFrame.cbShowBorderChange(Sender: TObject); +begin + FLegend.Frame.Visible := cbShowBorder.Checked; + cbBorderColor.Visible := cbShowBorder.Checked; +end; + +procedure TChartLegendFrame.cbUseSideBarChange(Sender: TObject); +begin + FLegend.UseSideBar := cbUseSideBar.Checked; +end; + +procedure TChartLegendFrame.ChangedHandler(Sender: TObject); +begin + GetChart.Invalidate; +end; + +function TChartLegendFrame.GetChart: TChart; +begin + Result := FLegend.GetOwner as TChart; +end; + +procedure TChartLegendFrame.Prepare(ALegend: TChartLegend); +begin + FLegend := ALegend; + + cbShow.Checked := ALegend.Visible; + SetAlignment(ALegend.Alignment); + + cbFilled.Checked := ALegend.BackgroundBrush.Style <> bsClear; + cbFillColor.Selected := ColorToRGB(ALegend.BackgroundBrush.Color); + + cbShowBorder.Checked := (ALegend.Frame.Style <> psClear) and ALegend.Frame.Visible; + cbBorderColor.Selected := ColorToRGB(ALegend.Frame.Color); + + seMarginX.Value := ALegend.MarginX; + seMarginY.Value := ALegend.MarginY; + + cbUseSideBar.Checked := ALegend.UseSidebar; + cbInverted.Checked := ALegend.Inverted; + seColumns.Value := ALegend.ColumnCount; + seSymbolWidth.Value := ALegend.SymbolWidth; + seSpacing.Value := ALegend.Spacing; + cbItemFillOrder.ItemIndex := ord(ALegend.ItemFillOrder); + + FFontFrame.Prepare(ALegend.Font, false); +end; + +function TChartLegendFrame.GetAlignment: TLegendAlignment; +var + i: Integer; + rb: TRadioButton; +begin + for i := 0 to gbAlignment.ControlCount-1 do + if (gbAlignment.Controls[i] is TRadioButton) then begin + rb := TRadioButton(gbAlignment.Controls[i]); + if rb.Checked then begin + Result := TLegendAlignment(rb.Tag); + exit; + end; + end; + Result := laTopRight; +end; + +procedure TChartLegendFrame.gbAlignmentClick(Sender: TObject); +begin + FLegend.Alignment := GetAlignment; +end; + +procedure TChartLegendFrame.seColumnsChange(Sender: TObject); +begin + FLegend.ColumnCount := seColumns.Value; +end; + +procedure TChartLegendFrame.seMarginXChange(Sender: TObject); +begin + FLegend.MarginX := seMarginX.Value; +end; + +procedure TChartLegendFrame.seMarginYChange(Sender: TObject); +begin + FLegend.MarginY := seMarginY.Value; +end; + +procedure TChartLegendFrame.seSpacingChange(Sender: TObject); +begin + FLegend.Spacing := seSpacing.Value; +end; + +procedure TChartLegendFrame.seSymbolWidthChange(Sender: TObject); +begin + FLegend.SymbolWidth := seSymbolWidth.Value; +end; + +procedure TChartLegendFrame.SetAlignment(AValue: TLegendAlignment); +var + i: Integer; + rb: TRadioButton; +begin + for i:=0 to gbAlignment.ControlCount-1 do + if (gbAlignment.Controls[i] is TRadioButton) then begin + rb := TRadioButton(gbAlignment.Controls[i]); + if rb.Tag = ord(AValue) then begin + rb.Checked := true; + exit; + end; + end; +end; + +end. + diff --git a/components/tachart/demo/charteditor/charteditordemo.lpi b/components/tachart/demo/charteditor/charteditordemo.lpi index ecc54e3d06..cdb5f16115 100644 --- a/components/tachart/demo/charteditor/charteditordemo.lpi +++ b/components/tachart/demo/charteditor/charteditordemo.lpi @@ -122,6 +122,13 @@ + + + + + + +