{**********************************************}
{   TeeChart Clock Series Editor               }
{   Copyright (c) 1999-2020 by Steema Software }
{**********************************************}
unit TeeClockEditor;
{$I TeeDefs.inc}

{$IFDEF D6}
{$WARN SYMBOL_DEPRECATED OFF}
{$ENDIF}

interface

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

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

     TeePolarEditor, TeCanvas, TeePenDlg, TeeRose, TeeBrushDlg, TeePoEdi;

type
  TClockEditor = class(TPolarSeriesEditor)
    CBRoman: TCheckBox;
    BRadius: TButtonPen;
    TabHands: TTabSheet;
    TabControl1: TTabControl;
    PageControl2: TPageControl;
    TabSheet1: TTabSheet;
    TabHandBorder: TTabSheet;
    Label4: TLabel;
    TBSize: TTrackBar;
    LabelSize: TLabel;
    TabHandBrush: TTabSheet;
    CBHandVisible: TCheckBox;
    Label6: TLabel;
    TBWidth: TTrackBar;
    LabelWidth: TLabel;
    Label9: TLabel;
    TBHeight: TTrackBar;
    LabelHeight: TLabel;
    Label5: TLabel;
    TBArrow: TTrackBar;
    LabelArrow: TLabel;
    TabCenter: TTabSheet;
    CBCustom: TCheckBox;
    procedure FormCreate(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure CBRomanClick(Sender: TObject);
    procedure TabControl1Change(Sender: TObject);
    procedure TBSizeChange(Sender: TObject);
    procedure CBHandVisibleClick(Sender: TObject);
    procedure TBWidthChange(Sender: TObject);
    procedure TBHeightChange(Sender: TObject);
    procedure PageControl2Change(Sender: TObject);
    procedure TBArrowChange(Sender: TObject);
    procedure PageControl1Change(Sender: TObject);
    procedure CBCustomClick(Sender: TObject);
    procedure DateTimePicker1Change(Sender: TObject);
  private
    { Private declarations }

    {$IFNDEF LCL}
    DateTimePicker1: TDateTimePicker;
    {$ENDIF}

    function Clock:TClockSeries;
    function CurrentHand:TClockHand;
  public
    { Public declarations }
  end;

implementation

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

procedure TClockEditor.FormCreate(Sender: TObject);
begin
  inherited;
  CBColorEach.Hide;

  {$IFNDEF LCL}
  DateTimePicker1:=TDateTimePicker.Create(Self);
  DateTimePicker1.Left:=CBCustom.Left;
  DateTimePicker1.Top:=CBCustom.Top+CBCustom.Height+10;
  DateTimePicker1.OnChange:=DateTimePicker1Change;
  DateTimePicker1.Parent:=CBCustom.Parent;
  {$ENDIF}
end;

function TClockEditor.Clock:TClockSeries;
begin
  result:=TClockSeries(Tag);
end;

procedure TClockEditor.FormShow(Sender: TObject);
begin
  inherited;

  if Tag<>0 then
  With Clock do
  begin
    CBRoman.Checked:=Style=cssRoman;

    CBCustom.Checked:=CustomTime;
    CBCustomClick(Self);
    
    TabControl1Change(Self);

    if Assigned(GetHorizAxis) then
       BRadius.LinkPen(GetHorizAxis.Grid);
  end;
end;

procedure TClockEditor.CBRomanClick(Sender: TObject);
begin
  if CBRoman.Checked then Clock.Style:=cssRoman
                     else Clock.Style:=cssDecimal;
end;

function TClockEditor.CurrentHand:TClockHand;
begin
  case TabControl1.TabIndex of
    0: result:=Clock.Hours;
    1: result:=Clock.Minutes;
  else
    result:=Clock.Seconds;
  end;
end;

procedure TClockEditor.TabControl1Change(Sender: TObject);

  procedure RefreshHand(Hand:TClockHand);
  begin
    if TabHandBorder.ControlCount>0 then
       TPenDialog(TabHandBorder.Controls[0]).RefreshPen(CurrentHand.Pen);

    if TabHandBrush.ControlCount>0 then
       TBrushDialog(TabHandBrush.Controls[0]).RefreshBrush(CurrentHand.Brush);

    CBHandVisible.Checked:=CurrentHand.Visible;

    TBArrow.Position:=CurrentHand.Arrow;
    TBArrowChange(Self);

    TBSize.Position:=CurrentHand.Size;
    TBSizeChange(Self);

    TBWidth.Position:=CurrentHand.Width;
    TBWidthChange(Self);

    TBHeight.Position:=CurrentHand.Height;
    TBHeightChange(Self);
  end;

begin
  RefreshHand(CurrentHand);
end;

procedure TClockEditor.TBSizeChange(Sender: TObject);
begin
  CurrentHand.Size:=TBSize.Position;
  LabelSize.Caption:=IntToStr(TBSize.Position)+' %';
end;

procedure TClockEditor.CBHandVisibleClick(Sender: TObject);
begin
  CurrentHand.Visible:=CBHandVisible.Checked;
end;

procedure TClockEditor.TBWidthChange(Sender: TObject);
begin
  CurrentHand.Width:=TBWidth.Position;
  LabelWidth.Caption:=IntToStr(TBWidth.Position)+' %';
end;

procedure TClockEditor.TBHeightChange(Sender: TObject);
begin
  CurrentHand.Height:=TBHeight.Position;
  LabelHeight.Caption:=IntToStr(TBHeight.Position)+' %';
end;

procedure TClockEditor.PageControl2Change(Sender: TObject);
begin
  if (PageControl2.ActivePage=TabHandBorder) and (TabHandBorder.ControlCount=0) then
     TPenDialog.InsertForm(CurrentHand.Pen,TabHandBorder)
  else
  if (PageControl2.ActivePage=TabHandBrush) and (TabHandBrush.ControlCount=0) then
     TBrushDialog.AddDialog(CurrentHand.Brush,TabHandBrush);
end;

procedure TClockEditor.TBArrowChange(Sender: TObject);
begin
  CurrentHand.Arrow:=TBArrow.Position;
  LabelArrow.Caption:=IntToStr(TBArrow.Position)+' %';
end;

procedure TClockEditor.PageControl1Change(Sender: TObject);
begin
  inherited;

  if PageControl1.ActivePage=TabCenter then
  begin
    if TabCenter.ControlCount=0 then
       TSeriesPointerEditor.InsertForm(Clock.Center,TabCenter);
  end;
end;

procedure TClockEditor.CBCustomClick(Sender: TObject);
begin
  Clock.CustomTime:=CBCustom.Checked;

  {$IFNDEF LCL}
  DateTimePicker1.Enabled:=Clock.CustomTime;
  DateTimePicker1.Time:=Clock.Time;
  {$ENDIF}
end;

procedure TClockEditor.DateTimePicker1Change(Sender: TObject);
begin
  {$IFNDEF LCL}
  Clock.Time:=DateTimePicker1.Time;
  {$ENDIF}
end;

initialization
  RegisterClass(TClockEditor);
end.
