unit FMXTee.Editor.Series.Pie;

interface

uses
  System.SysUtils, System.Types, System.Classes, System.Variants, FMX.Types,
  FMX.Controls, FMX.Forms,
  FMX.Edit, FMX.ListBox, FMX.Dialogs, FMX.TabControl, FMXTee.Series,
  FMXTee.Editor.Series.Circled;

type
  TPieSeriesEditor = class(TForm)
    PageControl1: TTabControl;
    TabOptions: TTabItem;
    Label4: TLabel;
    Label2: TLabel;
    Label1: TLabel;
    Label3: TLabel;
    LTransparency: TLabel;
    LBevelPercent: TLabel;
    LEdgeStyle: TLabel;
    Label11: TLabel;
    CBDark3d: TCheckBox;
    UDExpBig: TSpinBox;
    CBPatterns: TCheckBox;
    BPen: TButton;
    UDAngleSize: TSpinBox;
    UDDarkPen: TSpinBox;
    CBMultiple: TComboBox;
    CBEdgeStyle: TComboBox;
    UDTransparency: TSpinBox;
    UDBevelPercent: TSpinBox;
    TabGroup: TTabItem;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    CBOther: TComboBox;
    EOtherValue: TEdit;
    EOtherLabel: TEdit;
    Button2: TButton;
    TabSheet1: TTabItem;
    Label9: TLabel;
    CBColorEach: TCheckBox;
    BColor: TButton;
    CBPalette: TComboBox;
    TabSheet2: TTabItem;
    Label8: TLabel;
    LLegSize: TLabel;
    CBMarksAutoPosition: TCheckBox;
    CBVertCenter: TCheckBox;
    SBLegSize: TScrollBar;
    TabFrame: TTabItem;
    TabSheet8: TTabItem;
    Label10: TLabel;
    LBright: TLabel;
    BGradient: TButton;
    TBBright: TTrackBar;
    CBGradVisible: TCheckBox;
    procedure PageControl1Change(Sender: TObject);
    procedure CBMultipleChange(Sender: TObject);
    procedure CBEdgeStyleChange(Sender: TObject);
    procedure CBOtherChange(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure SBLegSizeChange(Sender: TObject);
    procedure TBBrightChange(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure CBDark3dChange(Sender: TObject);
    procedure CBPatternsChange(Sender: TObject);
    procedure CBColorEachChange(Sender: TObject);
    procedure CBMarksAutoPositionChange(Sender: TObject);
    procedure CBVertCenterChange(Sender: TObject);
    procedure CBGradVisibleChange(Sender: TObject);
    procedure BGradientClick(Sender: TObject);
    procedure BColorClick(Sender: TObject);
    procedure BPenClick(Sender: TObject);
    procedure UDTransparencyChange(Sender: TObject);
    procedure UDBevelPercentChange(Sender: TObject);
    procedure UDExpBigChange(Sender: TObject);
    procedure UDAngleSizeChange(Sender: TObject);
    procedure UDDarkPenChange(Sender: TObject);
    procedure CBPaletteChange(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure EOtherValueTyping(Sender: TObject);
    procedure EOtherLabelTyping(Sender: TObject);
  private
   { Private declarations }
    Pie : TPieSeries;

    FCircledEditor : TCircledSeriesEditor;
    FFrameEditor   : TForm;

    procedure RefreshPie(APie:TPieSeries);
  public
   { Public declarations }
    class function CreateEditor(AOwner:TComponent; APie:TPieSeries):TForm;
  end;

implementation

{$R *.fmx}

uses
  FMXTee.Constants, FMXTee.Canvas, FMXTee.Editor.Gradient, FMXTee.Chart,
  FMXTee.Editor.Stroke, FMXTee.Procs, FMXTee.Editor.Legend;

class function TPieSeriesEditor.CreateEditor(AOwner: TComponent;
  APie:TPieSeries): TForm;
begin
  result:=TPieSeriesEditor.Create(AOwner);
  TPieSeriesEditor(result).RefreshPie(APie);
end;

procedure TPieSeriesEditor.FormActivate(Sender: TObject);
begin
  if not Assigned(Pie) then
     RefreshPie(TPieSeries(TagObject));
end;

procedure TPieSeriesEditor.FormCreate(Sender: TObject);
begin
  PageControl1.ActiveTab:=TabOptions;
end;

procedure TPieSeriesEditor.PageControl1Change(Sender: TObject);
begin
  if (PageControl1.ActiveTab=TabFrame) and (not Assigned(FFrameEditor)) then
    // TODO
end;

procedure TPieSeriesEditor.RefreshPie(APie: TPieSeries);
var TabCircled : TTabItem;
begin
  Pie:=APie;

  UDExpBig.Value:=Pie.ExplodeBiggest;
  UDAngleSize.Value:=Pie.AngleSize;
  UDDarkPen.Value:=Pie.DarkPen;
  UDTransparency.Value:=Pie.Transparency;
  UDBevelPercent.Value:=Pie.BevelPercent;

  CBDark3d.IsChecked:=Pie.Dark3D;
  CBPatterns.IsChecked:=Pie.UsePatterns;
  CBMultiple.ItemIndex:=Ord(Pie.MultiPie);
  CBEdgeStyle.ItemIndex:=Ord(Pie.EdgeStyle);

  CBOther.ItemIndex:=Ord(Pie.OtherSlice.Style);
  EOtherLabel.Text:=Pie.OtherSlice.Text;
  EOtherValue.Text:=FloatToStr(Pie.OtherSlice.Value);

  CBColorEach.IsChecked:=Pie.ColorEachPoint;

  CBPalette.Clear;
  ColorPalettes.AddTo(CBPalette.ListBox.Items,True);

  CBPalette.Enabled:=Assigned(Pie.ParentChart);

  if Assigned(Pie.ParentChart) then
     CBPalette.ItemIndex:=(Pie.ParentChart as TCustomChart).ColorPaletteIndex+1;

  CBMarksAutoPosition.IsChecked:=Pie.AutoMarkPosition;
  CBVertCenter.IsChecked:=Pie.PieMarks.VertCenter;
  CBGradVisible.IsChecked:=Pie.Gradient.Visible;

  SBLegSize.Value:=Pie.PieMarks.LegSize;
  LLegSize.Text:=TeeStr(Round(SBLegSize.Value));

  TBBright.Value:=Pie.GradientBright;

  case Pie.EdgeStyle of
    edFlat: CBEdgeStyle.ItemIndex:=1;
    edCurved: CBEdgeStyle.ItemIndex:=2;
    edNone: CBEdgeStyle.ItemIndex:=0;
  end;

  if not Assigned(FCircledEditor) then
  begin
    FCircledEditor:=TCircledSeriesEditor.Create(Self);

    TabCircled:=TTabItem.Create(Self);
    TabCircled.Text:=TeeMsg_GalleryCircled;
    PageControl1.AddObject(TabCircled);

    EmbeddForm(FCircledEditor,TabCircled);
  end;

  FCircledEditor.RefreshCircled(Pie);
end;

procedure TPieSeriesEditor.CBDark3dChange(Sender: TObject);
begin
  Pie.Dark3D:=CBDark3d.IsChecked;
end;

procedure TPieSeriesEditor.CBPaletteChange(Sender: TObject);
begin
  TCustomChart(Pie.ParentChart).ColorPaletteIndex:=CBPalette.ItemIndex-1;
end;

procedure TPieSeriesEditor.CBPatternsChange(Sender: TObject);
begin
  Pie.UsePatterns:=CBPatterns.IsChecked;
end;

procedure TPieSeriesEditor.CBMultipleChange(Sender: TObject);
begin
  Pie.MultiPie:=TMultiPie(CBMultiple.ItemIndex);
end;

procedure TPieSeriesEditor.CBEdgeStyleChange(Sender: TObject);
begin
  Pie.EdgeStyle:=TEdgeStyle(CBEdgeStyle.ItemIndex);
end;

procedure TPieSeriesEditor.CBOtherChange(Sender: TObject);
begin
  Pie.OtherSlice.Style:=TPieOtherStyle(CBOther.ItemIndex);
end;

procedure TPieSeriesEditor.EOtherLabelTyping(Sender: TObject);
begin
  Pie.OtherSlice.Text:=EOtherLabel.Text;
end;

procedure TPieSeriesEditor.EOtherValueTyping(Sender: TObject);
begin
  Pie.OtherSlice.Value:=StrToFloat(EOtherValue.Text);
end;

procedure TPieSeriesEditor.BColorClick(Sender: TObject);
begin
  Pie.Color:=EditColor(Self, Pie.Color);
end;

procedure TPieSeriesEditor.BGradientClick(Sender: TObject);
begin
  TGradientEditor.Edit(Self, Pie.Gradient);
end;

procedure TPieSeriesEditor.BPenClick(Sender: TObject);
begin
  TStrokeEditor.Edit(Self, Pie.Pen);
end;

procedure TPieSeriesEditor.Button2Click(Sender: TObject);
begin
  with TLegendEditor.CreateEditor(Self, Pie.OtherSlice.Legend) do
  try
    ShowModal;
  finally
    Free;
  end;
end;

procedure TPieSeriesEditor.CBColorEachChange(Sender: TObject);
begin
  Pie.ColorEachPoint:=CBColorEach.IsChecked;
end;

procedure TPieSeriesEditor.CBMarksAutoPositionChange(Sender: TObject);
begin
  Pie.AutoMarkPosition:=CBMarksAutoPosition.IsChecked;
end;

procedure TPieSeriesEditor.CBVertCenterChange(Sender: TObject);
begin
  Pie.PieMarks.VertCenter:=CBVertCenter.IsChecked;
end;

procedure TPieSeriesEditor.SBLegSizeChange(Sender: TObject);
begin
  if Assigned(Pie) then
  begin
    Pie.PieMarks.LegSize:=Round(SBLegSize.Value);
    LLegSize.Text:=IntToStr(Pie.PieMarks.LegSize);
  end;
end;

procedure TPieSeriesEditor.TBBrightChange(Sender: TObject);
begin
  if Assigned(Pie) then
     Pie.GradientBright:=Round(TBBright.Value);
end;

procedure TPieSeriesEditor.UDAngleSizeChange(Sender: TObject);
begin
  if Assigned(Pie) then
     Pie.AngleSize:=Round(UDAngleSize.Value);
end;

procedure TPieSeriesEditor.UDBevelPercentChange(Sender: TObject);
begin
  if Assigned(Pie) then
     Pie.BevelPercent:=Round(UDBevelPercent.Value);
end;

procedure TPieSeriesEditor.UDExpBigChange(Sender: TObject);
begin
  if Assigned(Pie) then
     Pie.ExplodeBiggest:=Round(UDExpBig.Value);
end;

procedure TPieSeriesEditor.UDTransparencyChange(Sender: TObject);
begin
  if Assigned(Pie) then
     Pie.Transparency:=Round(UDTransparency.Value);
end;

procedure TPieSeriesEditor.UDDarkPenChange(Sender: TObject);
begin
  if Assigned(Pie) then
     Pie.DarkPen:=Round(UDDarkPen.Value);
end;

procedure TPieSeriesEditor.CBGradVisibleChange(Sender: TObject);
begin
  Pie.Gradient.Visible:=CBGradVisible.IsChecked;
end;

initialization
  RegisterSeriesEditor(TPieSeriesEditor);
end.
