{**********************************************}
{   TSeriesBandTool and Editor Dialog          }
{   Copyright (c) 2003-2020 by Steema Software }
{   and Martin Kaul (mkaul@leuze.de)           }
{**********************************************}
unit TeeSeriesBandToolEditor;
{$I TeeDefs.inc}

interface

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

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

     {$IFDEF LINUX}
     Types,
     {$ENDIF}
     TeeToolSeriesEdit, TeCanvas, TeePenDlg, TeeTools, TeEngine,
     TeeProcs, Chart, TeeConst, TeeProCo, TeeEdiGrad, Series, TeeSeriesBandTool;

type
  TSeriesBandToolEdit = class(TSeriesToolEditor)
    PageControl1: TPageControl;
    TabSheet1: TTabSheet;
    TabSheet2: TTabSheet;
    Label4: TLabel;
    Label2: TLabel;
    CBSeries2: TComboFlat;
    CBDrawBehindSeries: TCheckBox;
    RGCondition: TRadioGroup;
    TabBorder: TTabSheet;
    TabPattern: TTabSheet;
    TBTransp: TTrackBar;
    LTransp: TLabel;
    Label3: TLabel;
    EBound: TEdit;
    procedure FormShow(Sender: TObject);
    procedure CBDrawBehindSeriesClick(Sender: TObject);
    procedure CBSeries2Change(Sender: TObject);
    procedure RGConditionClick(Sender: TObject);
    procedure TBTranspChange(Sender: TObject);
    procedure PageControl1Change(Sender: TObject);
    procedure EBoundChange(Sender: TObject);
  private
    { Private declarations }
    SeriesBand : TSeriesBandTool;
  public
    { Public declarations }
  end;

implementation

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

Uses
  Math, TeeBrushDlg;

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

  SeriesBand:=TSeriesBandTool(Tag);

  if Assigned(SeriesBand) then
  with SeriesBand do
  begin
    FillSeriesCombo(CBSeries2,Series2,ParentChart);
    CBDrawBehindSeries.Checked:=DrawBehindSeries;
    RGCondition.ItemIndex:=Ord(Condition);

    TBTransp.Position:=Transparency;
    LTransp.Caption:=IntToStr(TBTransp.Position);

    EBound.Text:=FloatToStr(BoundValue);
    EBound.Enabled:=not Assigned(Series2);
  end;
end;

procedure TSeriesBandToolEdit.CBDrawBehindSeriesClick(Sender: TObject);
begin
  SeriesBand.DrawBehindSeries:=CBDrawBehindSeries.Checked;
end;

procedure TSeriesBandToolEdit.CBSeries2Change(Sender: TObject);
begin
  SeriesBand.Series2:=TChartSeries(CBSeries2.SelectedObject);
  EBound.Enabled:=not Assigned(SeriesBand.Series2);
end;

procedure TSeriesBandToolEdit.RGConditionClick(Sender: TObject);
begin
  SeriesBand.Condition:=TBandCondition(RGCondition.ItemIndex);
end;

procedure TSeriesBandToolEdit.TBTranspChange(Sender: TObject);
begin
  if Showing then
  begin
    SeriesBand.Transparency:=TBTransp.Position;
    LTransp.Caption:=IntToStr(TBTransp.Position);
  end;
end;

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

  if (PageControl1.ActivePage=TabBorder) and (TabBorder.ControlCount=0) then
     TPenDialog.InsertForm(SeriesBand.Pen,TabBorder)
  else
  if (PageControl1.ActivePage=TabPattern) and (TabPattern.ControlCount=0) then
     TBrushDialog.AddDialog(SeriesBand.Brush,TabPattern);
end;

procedure TSeriesBandToolEdit.EBoundChange(Sender: TObject);
var tmpValue : Double;
begin
  if Showing then
     if TryStrToFloat(EBound.Text,tmpValue) then
        SeriesBand.BoundValue:=tmpValue;
end;

initialization
  RegisterClass(TSeriesBandToolEdit);
end.
