{********************************************}
{ TCursorTool Editor Dialog                  }
{ Copyright (c) 1999-2020 by Steema Software }
{********************************************}
unit TeeCursorEdit;
{$I TeeDefs.inc}

interface

uses SysUtils, Classes,

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

     Chart, TeeTools, TeeProcs, TeCanvas, TeePenDlg, TeeToolSeriesEdit,
     TeeAnnToolEdit;

type
  TCursorToolEditor = class(TSeriesToolEditor)
    PageControl1: TPageControl;
    TabSheet1: TTabSheet;
    TabSheet2: TTabSheet;
    CBZ: TCheckBox;
    CBSnap: TCheckBox;
    CBSnapStyle: TComboFlat;
    Label5: TLabel;
    CBStyle: TComboFlat;
    TabSheet3: TTabSheet;
    CBFollow: TCheckBox;
    Label3: TLabel;
    EPixels: TEdit;
    UDClick: TUpDown;
    Label4: TLabel;
    Label2: TLabel;
    Edit1: TEdit;
    UDHorizSize: TUpDown;
    Label7: TLabel;
    Edit2: TEdit;
    UDVertSize: TUpDown;
    Label9: TLabel;
    Label10: TLabel;
    EScope: TEdit;
    UDScope: TUpDown;
    Label6: TLabel;
    CBScopeStyle: TComboFlat;
    TabBorder: TTabSheet;
    TabAnnotation: TTabSheet;
    CBFullRepaint: TCheckBox;
    procedure FormShow(Sender: TObject);
    procedure CBSeriesChange(Sender: TObject);
    procedure CBStyleChange(Sender: TObject);
    procedure CBSnapClick(Sender: TObject);
    procedure CBFollowClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure CBZClick(Sender: TObject);
    procedure EPixelsChange(Sender: TObject);
    procedure CBSnapStyleChange(Sender: TObject);
    procedure Edit1Change(Sender: TObject);
    procedure Edit2Change(Sender: TObject);
    procedure EScopeChange(Sender: TObject);
    procedure CBScopeStyleChange(Sender: TObject);
    procedure PageControl1Change(Sender: TObject);
    procedure CBFullRepaintClick(Sender: TObject);
  private
    { Private declarations }
    CursorTool : TCursorTool;
    IBorderEditor : TPenDialog;
    IAnnEditor : TAnnotationToolEdit;

    procedure EnableSnap;
    procedure EnableScope;
  public
    { Public declarations }
  end;

implementation

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

uses
  TeEngine, TeeConst, TeeProCo;

procedure TCursorToolEditor.FormShow(Sender: TObject);
begin
  inherited;
  CursorTool:=TCursorTool(Tag);

  if Assigned(CursorTool) then
  With CursorTool do
  begin
    CBStyle.ItemIndex:=Ord(Style);
    CBSnap.Checked:=Snap;
    CBSnapStyle.ItemIndex:=Ord(SnapStyle);
    CBZ.Checked:=UseSeriesZ;
    CBZ.Enabled:=CBSnap.Enabled;
    CBFollow.Checked:=FollowMouse;
    UDClick.Position:=ClickTolerance;
    UDHorizSize.Position:=HorizSize;
    UDVertSize.Position:=VertSize;
    UDScope.Position:=ScopeSize;
    CBScopeStyle.ItemIndex:=Ord(ScopeStyle);
    CBFullRepaint.Checked:=FullRepaint;

    EnableSnap;
    EnableScope;
  end;
end;

procedure TCursorToolEditor.EnableSnap;
begin
  CBSnap.Enabled:=Assigned(CursorTool.Series);
  CBSnapStyle.Enabled:=CBSnap.Enabled and CursorTool.Snap;
end;

procedure TCursorToolEditor.CBSeriesChange(Sender: TObject);
begin
  inherited;
  EnableSnap;
  CBZ.Enabled:=CBSnap.Enabled;
end;

procedure TCursorToolEditor.CBStyleChange(Sender: TObject);
begin
  CursorTool.Style:=TCursorToolStyle(CBStyle.ItemIndex);
  EnableScope;
end;

procedure TCursorToolEditor.EnableScope;
begin
  UDScope.Enabled:=(CursorTool.Style=cssScope) or (CursorTool.Style=cssScopeOnly);
  EScope.Enabled:=UDScope.Enabled;
  CBScopeStyle.Enabled:=UDScope.Enabled;
end;

procedure TCursorToolEditor.CBSnapClick(Sender: TObject);
begin
  CursorTool.Snap:=CBSnap.Checked;
  EnableSnap;
end;

procedure TCursorToolEditor.CBFollowClick(Sender: TObject);
begin
  CursorTool.FollowMouse:=CBFollow.Checked
end;

procedure TCursorToolEditor.FormCreate(Sender: TObject);
begin
  inherited;
  Align:=alClient;
end;

procedure TCursorToolEditor.CBZClick(Sender: TObject);
begin
  CursorTool.UseSeriesZ:=CBZ.Checked
end;

procedure TCursorToolEditor.EPixelsChange(Sender: TObject);
begin
  if Assigned(CursorTool) then
     CursorTool.ClickTolerance:=UDClick.Position;
end;

procedure TCursorToolEditor.CBSnapStyleChange(Sender: TObject);
begin
  CursorTool.SnapStyle:=TSnapStyle(CBSnapStyle.ItemIndex);
end;

procedure TCursorToolEditor.Edit1Change(Sender: TObject);
begin
  if Assigned(CursorTool) then
     CursorTool.HorizSize:=UDHorizSize.Position;
end;

procedure TCursorToolEditor.Edit2Change(Sender: TObject);
begin
  if Assigned(CursorTool) then
     CursorTool.VertSize:=UDVertSize.Position;
end;

procedure TCursorToolEditor.EScopeChange(Sender: TObject);
begin
  if Assigned(CursorTool) then
     CursorTool.ScopeSize:=UDScope.Position;
end;

procedure TCursorToolEditor.CBScopeStyleChange(Sender: TObject);
begin
  CursorTool.ScopeStyle:=TScopeCursorStyle(CBScopeStyle.ItemIndex);
end;

procedure TCursorToolEditor.PageControl1Change(Sender: TObject);
begin
  if PageControl1.ActivePage=TabBorder then
  begin
    if not Assigned(IBorderEditor) then
       IBorderEditor:=TPenDialog.InsertForm(CursorTool.Pen,TabBorder);
  end
  else
  if PageControl1.ActivePage=TabAnnotation then
     if not Assigned(IAnnEditor) then
     begin
       IAnnEditor:=TAnnotationToolEdit.InsertForm(CursorTool.AxisAnnotation,TabAnnotation);
       IAnnEditor.HideTextTab:=True;
     end;
end;

procedure TCursorToolEditor.CBFullRepaintClick(Sender: TObject);
begin
  CursorTool.FullRepaint:=CBFullRepaint.Checked;
end;

initialization
  RegisterClass(TCursorToolEditor);
end.
