{********************************************}
{ TGaugeSeries Editor Dialog                 }
{ Copyright (c) 2002-2020 by Steema Software }
{********************************************}
unit TeeGaugeEditor;
{$I TeeDefs.inc}

interface

uses {$IFNDEF LINUX}
     Windows, Messages,
     {$ENDIF}
     SysUtils, Classes,

     Graphics, Controls, Forms, Dialogs, ExtCtrls, StdCtrls, ComCtrls, Buttons,

     TeeProcs, TeEngine, Chart, TeCanvas, TeePenDlg, TeePoEdi, TeeEdiFont,
     Series, TeeGauges, TeeCircledEdit;

type
  TGaugeSeriesEditor = class(TForm)
    PageControl1: TPageControl;
    TabSheet1: TTabSheet;
    TabSheet2: TTabSheet;
    TabSheet3: TTabSheet;
    BTicks: TButtonPen;
    BMinor: TButtonPen;
    Edit2: TEdit;
    UpDown1: TUpDown;
    Edit4: TEdit;
    UpDown3: TUpDown;
    CheckBox4: TCheckBox;
    Label2: TLabel;
    Label1: TLabel;
    Edit8: TEdit;
    UDValue: TUpDown;
    Edit3: TEdit;
    UpDown2: TUpDown;
    Edit5: TEdit;
    UpDown4: TUpDown;
    TabEndPoint: TTabSheet;
    TabCenter: TTabSheet;
    TabAxis: TTabSheet;
    TabHand: TTabSheet;
    PageControl2: TPageControl;
    TabLabels: TTabSheet;
    TabFont: TTabSheet;
    Label11: TLabel;
    Label5: TLabel;
    CheckBox1: TCheckBox;
    Edit1: TEdit;
    CBInside: TCheckBox;
    Edit11: TEdit;
    UDIncrement: TUpDown;
    Panel1: TPanel;
    Label12: TLabel;
    Edit7: TEdit;
    UDDist: TUpDown;
    Label6: TLabel;
    CBHandStyle: TComboFlat;
    Label3: TLabel;
    Label4: TLabel;
    Edit9: TEdit;
    UDMin: TUpDown;
    Edit10: TEdit;
    UDMax: TUpDown;
    Label7: TLabel;
    TBRot: TTrackBar;
    LRot: TLabel;
    TBTotal: TTrackBar;
    LTotal: TLabel;
    TabBack: TTabSheet;
    PageControl3: TPageControl;
    TabSheet4: TTabSheet;
    TabBorder: TTabSheet;
    TabBrush: TTabSheet;
    RGShape: TRadioGroup;
    procedure CheckBox1Click(Sender: TObject);
    procedure Edit1Change(Sender: TObject);
    procedure CBHandStyleChange(Sender: TObject);
    procedure CheckBox4Click(Sender: TObject);
    procedure Edit2Change(Sender: TObject);
    procedure Edit3Change(Sender: TObject);
    procedure Edit4Change(Sender: TObject);
    procedure Edit5Change(Sender: TObject);
    procedure Edit7Change(Sender: TObject);
    procedure Edit8Change(Sender: TObject);
    procedure Edit9Change(Sender: TObject);
    procedure Edit10Change(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure CBInsideClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Edit11Change(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure PageControl1Change(Sender: TObject);
    procedure PageControl2Change(Sender: TObject);
    procedure TBRotChange(Sender: TObject);
    procedure TBTotalChange(Sender: TObject);
    procedure PageControl3Change(Sender: TObject);
    procedure RGShapeClick(Sender: TObject);
  private
    { Private declarations }
    Gauge : TGaugeSeries;
    tmpCircled : TCircledSeriesEditor;

    function CanModifyAxis:Boolean;
  public
    { Public declarations }
  end;

implementation

{$IFNDEF LCL}
{$R *.DFM}
{$ELSE}
{$R *.lfm}
{$ENDIF}

uses
  TeeBrushDlg;

procedure TGaugeSeriesEditor.CheckBox1Click(Sender: TObject);
begin
  if CanModifyAxis then
     Gauge.Axis.Labels:=CheckBox1.Checked;
end;

procedure TGaugeSeriesEditor.Edit1Change(Sender: TObject);
begin
  Gauge.ValueFormat:=Edit1.Text;
end;

procedure TGaugeSeriesEditor.CBHandStyleChange(Sender: TObject);
begin
  if CBHandStyle.ItemIndex=0 then
     Gauge.HandStyle:=hsLine
  else
     Gauge.HandStyle:=hsTriangle;
end;

procedure TGaugeSeriesEditor.CheckBox4Click(Sender: TObject);
begin
  Gauge.FullRepaint:=CheckBox4.Checked;
end;

function TGaugeSeriesEditor.CanModifyAxis:Boolean;
begin
  result:=Showing and (Gauge.Axis<>nil);
end;

procedure TGaugeSeriesEditor.Edit2Change(Sender: TObject);
begin
  if CanModifyAxis then
     Gauge.Axis.MinorTickCount:=UpDown1.Position;
end;

procedure TGaugeSeriesEditor.Edit3Change(Sender: TObject);
begin
  if Showing then
     Gauge.MinorTickDistance:=UpDown2.Position;
end;

procedure TGaugeSeriesEditor.Edit4Change(Sender: TObject);
begin
  if CanModifyAxis then
     Gauge.Axis.TickLength:=UpDown3.Position;
end;

procedure TGaugeSeriesEditor.Edit5Change(Sender: TObject);
begin
  if CanModifyAxis then
     Gauge.Axis.MinorTickLength:=UpDown4.Position;
end;

procedure TGaugeSeriesEditor.Edit7Change(Sender: TObject);
begin
  if Showing then
     Gauge.HandDistance:=UDDist.Position;
end;

procedure TGaugeSeriesEditor.Edit8Change(Sender: TObject);
begin
  if Showing then
     Gauge.Value:=UDValue.Position;
end;

procedure TGaugeSeriesEditor.Edit9Change(Sender: TObject);
begin
  if Showing then
  begin
    Gauge.Minimum:=UDMin.Position;
    UDMax.Min:=Round(Gauge.Minimum);
  end;
end;

procedure TGaugeSeriesEditor.Edit10Change(Sender: TObject);
begin
  if Showing then
  begin
    Gauge.Maximum:=UDMax.Position;
    UDMin.Max:=Round(Gauge.Maximum);
  end;
end;

procedure TGaugeSeriesEditor.FormShow(Sender: TObject);
begin
  Gauge:=TGaugeSeries(Tag);

  if Assigned(Gauge) then
  begin
    CBHandStyle.ItemIndex:=0;

    with Gauge do
    begin
      UDMin.Position:=Round(Minimum);
      UDMax.Position:=Round(Maximum);
      UDValue.Position:=Round(Value);
      CBInside.Checked:=LabelsInside;
      UDDist.Position:=HandDistance;
      Edit1.Text:=ValueFormat;

      TBRot.Position:=RotationAngle;
      LRot.Caption:=IntToStr(RotationAngle);

      TBTotal.Position:=Round(TotalAngle);
      LTotal.Caption:=IntToStr(TBTotal.Position);

      RGShape.ItemIndex:=Ord(ShapeStyle);

      if Axis<>nil then
      with Axis do
      begin
        UDIncrement.Position:=Round(Increment);
        UpDown1.Position:=MinorTickCount;
        UpDown3.Position:=TickLength;
        UpDown4.Position:=MinorTickLength;
        CheckBox1.Checked:=Labels;
        BTicks.LinkPen(Ticks);
        BMinor.LinkPen(MinorTicks);
      end;
    end;

    if not Assigned(tmpCircled) then
       tmpCircled:=TCircledSeriesEditor.CreateForm(Self,Gauge);
  end;
end;

procedure TGaugeSeriesEditor.CBInsideClick(Sender: TObject);
begin
  Gauge.LabelsInside:=CBInside.Checked;
end;

procedure TGaugeSeriesEditor.FormCreate(Sender: TObject);
begin
  PageControl1.ActivePage:=TabSheet1;
end;

procedure TGaugeSeriesEditor.Edit11Change(Sender: TObject);
begin
  if CanModifyAxis then
     Gauge.Axis.Increment:=UDIncrement.Position;
end;

procedure TGaugeSeriesEditor.FormDestroy(Sender: TObject);
begin
  FreeAndNil(tmpCircled);
end;

procedure TGaugeSeriesEditor.PageControl1Change(Sender: TObject);
begin
  if (PageControl1.ActivePage=TabHand) and (TabHand.ControlCount<2) then
     TPenDialog.InsertForm(Gauge.Pen,TabHand)
  else
  if (PageControl1.ActivePage=TabCenter) and (TabCenter.ControlCount=0) then
     TSeriesPointerEditor.InsertForm(Gauge.Center,TabCenter)
  else
  if (PageControl1.ActivePage=TabEndPoint) and (TabEndPoint.ControlCount=0) then
     TSeriesPointerEditor.InsertForm(Gauge.EndPoint,TabEndPoint)
  else
  if (PageControl1.ActivePage=TabAxis) and (TabAxis.ControlCount=0) then
     TPenDialog.InsertForm(Gauge.Axis.Axis,TabAxis)
end;

procedure TGaugeSeriesEditor.PageControl2Change(Sender: TObject);
begin
  if (PageControl2.ActivePage=TabFont) and (TabFont.ControlCount=0) then
     InsertTeeFontEditor(TabFont).RefreshControls(Gauge.Axis.Items.Format.Font);
end;

procedure TGaugeSeriesEditor.TBRotChange(Sender: TObject);
begin
  if Showing then
  begin
    Gauge.RotationAngle:=TBRot.Position;
    LRot.Caption:=IntToStr(TBRot.Position);
  end;
end;

procedure TGaugeSeriesEditor.TBTotalChange(Sender: TObject);
begin
  if Showing then
  begin
    Gauge.TotalAngle:=TBTotal.Position;
    LTotal.Caption:=IntToStr(TBTotal.Position);
  end;
end;

procedure TGaugeSeriesEditor.PageControl3Change(Sender: TObject);
begin
  if (PageControl3.ActivePage=TabBorder) and (TabBorder.ControlCount=0) then
     TPenDialog.InsertForm(Gauge.CirclePen,TabBorder)
  else
  if (PageControl3.ActivePage=TabBrush) and (TabBrush.ControlCount=0) then
     TBrushDialog.AddDialog(Gauge.CircleBrush,TabBrush)
end;

procedure TGaugeSeriesEditor.RGShapeClick(Sender: TObject);
begin
  Gauge.ShapeStyle:=TGaugeShapeStyle(RGShape.ItemIndex);
end;

initialization
  RegisterClass(TGaugeSeriesEditor);
end.
