{**********************************************}
{   TErrorBarSeries Editor Dialog              }
{   Copyright (c) 2013-2020 by Steema Software }
{**********************************************}
unit FMXTee.Editor.Series.ErrorBar;
{$I TeeDefs.inc}

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
  FMX.Types, FMX.Controls, FMX.Forms, FMX.Dialogs, FMX.Edit, FMX.Colors,
  FMX.TabControl,
  FMX.StdCtrls,
  {$IFDEF D21}
  FMX.SpinBox,
  {$ENDIF}
  FMXTee.Chart, FMXTee.Series, FMXTee.Series.Error, FMXTee.Canvas,
  FMXTee.Editor.Stroke, FMXTee.Procs;

type
  TErrorBarSeriesEditor = class(TForm)
    TabControl1: TTabControl;
    TabOptions: TTabItem;
    TabBorder: TTabItem;
    RGStyle: TGroupBox;
    rbTop: TRadioButton;
    rbRight: TRadioButton;
    rbLeft: TRadioButton;
    rbBottom: TRadioButton;
    rbLeftRight: TRadioButton;
    rbTopBottom: TRadioButton;
    BColor: TComboColorBox;
    CBColorEach: TCheckBox;
    LHeight: TLabel;
    UDBarWidth: TSpinBox;
    GroupBox2: TGroupBox;
    rbPixels: TRadioButton;
    rbPercent: TRadioButton;
    procedure FormActivate(Sender: TObject);
    procedure UDBarWidthChange(Sender: TObject);
    procedure CBColorEachChange(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure BColorChange(Sender: TObject);
    procedure TabControl1Change(Sender: TObject);
  private
    { Private declarations }
    ErrorSeries : TCustomErrorSeries;
    FBarForm : TCustomForm;
    IPenEditor : TStrokeEditor;

    // TODO: procedure ChangedPen(Sender: TObject);
  public
    { Public declarations }
  end;

implementation

{$R *.fmx}

Uses
  FMXTee.Editor.Brush, FMXTee.Constants, FMXTee.Editor.Series;

procedure TErrorBarSeriesEditor.FormActivate(Sender: TObject);
begin
  ErrorSeries:=TCustomErrorSeries(TagObject);

  if Assigned(ErrorSeries) then
  With ErrorSeries do
  begin
    UDBarWidth.Value:=ErrorWidth;

    if ErrorWidthUnits=ewuPercent then rbPercent.IsChecked:=False
                                  else rbPercent.IsChecked:=True;

    RGStyle.Visible:=ErrorSeries is TErrorSeries;
    RGStyle.Enabled:=RGStyle.Visible;

// TODO    RGStyle.ItemIndex:=Ord(ErrorStyle);

    CBColorEach.IsChecked:=ColorEachPoint;
  end;

  (* TODO
  if (ErrorSeries is TErrorBarSeries) and (not Assigned(FBarForm)) then
     FBarForm:=TFormTeeSeries.InsertSeriesForm(Parent,TBarSeriesEditor,
                                                     1,TeeMsg_GalleryBar,
                                                     ErrorSeries);
                                                     *)
end;

procedure TErrorBarSeriesEditor.FormDestroy(Sender: TObject);
begin
  FreeAndNil(FBarForm);
end;

procedure TErrorBarSeriesEditor.TabControl1Change(Sender: TObject);
begin
  if (TabControl1.ActiveTab=TabBorder) and (not assigned(IPenEditor)) then
  begin
    IPenEditor:=TStrokeEditor.InsertForm(ErrorSeries.ErrorPen,TabBorder);
// TODO     IPenEditor.OnChangedPen:=ChangedPen;
  end;
end;

procedure TErrorBarSeriesEditor.UDBarWidthChange(Sender: TObject);
begin
  ErrorSeries.ErrorWidth:=Round(UDBarWidth.Value);
end;

procedure TErrorBarSeriesEditor.BColorChange(Sender: TObject);
begin
  if Assigned(IPenEditor) then
     IPenEditor.ComboColorBox1.Repaint;
end;

procedure TErrorBarSeriesEditor.CBColorEachChange(Sender: TObject);
begin
  ErrorSeries.ColorEachPoint:=CBColorEach.IsChecked;
end;

// TODO:
{
procedure TErrorBarSeriesEditor.ChangedPen(Sender: TObject);
begin
  if not (ErrorSeries is TErrorBarSeries) then
     ErrorSeries.SeriesColor:=ErrorSeries.ErrorPen.Color;
end;
}

initialization
  RegisterClass(TErrorBarSeriesEditor);
end.
