{*********************************************}
{  TeeChart Charting Library for FireMonkey   }
{  Copyright (c) 2012-2020 by Steema Software }
{  All Rights Reserved                        }
{*********************************************}
unit FMXTee.Editor.Panel;
{$I TeeDefs.inc}

interface

uses
  System.SysUtils, System.Types, System.Classes, System.Variants,
  FMX.Types, FMX.Controls, FMX.Forms,
  {$IFNDEF UPTOXE3}
  FMX.StdCtrls,
  {$ENDIF}
  {$IFDEF D21}
  FMX.SpinBox,
  {$ENDIF}
  FMX.Edit, FMX.ListBox, FMX.Dialogs, FMX.TabControl, FMX.Ani, FMXTee.Chart,
  FMX.Colors, FMXTee.Editor.Gradient, FMX.Layouts, FMXTee.Editor.Stroke;

type
  TPanelEditor = class(TForm)
    PageControl1: TTabControl;
    TabBack: TTabItem;
    BPanelColor: TComboColorBox;
    CBColorDef: TCheckBox;
    CBImageInside: TCheckBox;
    TabBorders: TTabItem;
    TabMargins: TTabItem;
    GBMargins: TGroupBox;
    Label5: TLabel;
    UDTopMa: TSpinBox;
    UDRightMa: TSpinBox;
    UDLeftMa: TSpinBox;
    UDBotMa: TSpinBox;
    CBMarUnits: TComboBox;
    TabGradient: TTabItem;
    TabShadow: TTabItem;
    TabEmboss: TTabItem;
    TabImage: TTabItem;
    TabControlBorders: TTabControl;
    TabBorder: TTabItem;
    TabBevels: TTabItem;
    Layout1: TLayout;
    Label1: TLabel;
    UDRound: TSpinBox;
    Label2: TLabel;
    CBInner: TComboBox;
    ListBoxItem1: TListBoxItem;
    ListBoxItem2: TListBoxItem;
    ListBoxItem3: TListBoxItem;
    Label3: TLabel;
    CBOuter: TComboBox;
    ListBoxItem4: TListBoxItem;
    ListBoxItem5: TListBoxItem;
    ListBoxItem6: TListBoxItem;
    L2: TLabel;
    UDPanelWi: TSpinBox;
    L19: TLabel;
    UDPanelBor: TSpinBox;
    procedure PageControl1Change(Sender: TObject);
    procedure CBInnerChange(Sender: TObject);
    procedure CBOuterChange(Sender: TObject);
    procedure CBMarUnitsChange(Sender: TObject);
    procedure CBImageInsideChange(Sender: TObject);
    procedure CBColorDefChange(Sender: TObject);
    procedure UDPanelWiChange(Sender: TObject);
    procedure UDPanelBorChange(Sender: TObject);
    procedure UDRoundChange(Sender: TObject);
    procedure UDTopMaChange(Sender: TObject);
    procedure UDBotMaChange(Sender: TObject);
    procedure UDLeftMaChange(Sender: TObject);
    procedure UDRightMaChange(Sender: TObject);
    procedure BPanelColorChange(Sender: TObject);
    procedure TabControlBordersChange(Sender: TObject);
  private
   { Private declarations }
    Chart : TCustomChart;

    IBorder : TStrokeEditor;

    IPicture,
    IShadow,
    IEmboss,
    IGradient : TForm;

    procedure RefreshChart(const AChart:TCustomChart);
  public
   { Public declarations }
    class function CreateEditor(const AOwner:TComponent; const AChart:TCustomChart):TForm;
  end;

implementation

{$R *.fmx}

uses
  FMXTee.Canvas, FMXTee.Procs, FMXTee.Editor.Shadow,
  FMXTee.Editor.Picture;

procedure TPanelEditor.PageControl1Change(Sender: TObject);
begin
  if PageControl1.ActiveTab=TabBorders then
     TabControlBordersChange(Self)
  else
  if (PageControl1.ActiveTab=TabGradient) and (not Assigned(IGradient)) then
    IGradient:=TGradientEditor.InsertForm(Chart.Gradient, TabGradient)
  else
  if (PageControl1.ActiveTab=TabShadow) and (not Assigned(IShadow)) then
    IShadow:=TShadowEditor.InsertForm(Chart.Shadow, TabShadow)
  else
  if (PageControl1.ActiveTab=TabEmboss) and (not Assigned(IEmboss)) then
    IEmboss:=TShadowEditor.InsertForm(Chart.Emboss, TabEmboss)
  else
  if (PageControl1.ActiveTab=TabImage) and (not Assigned(IPicture)) then
    IPicture:=TBackImageEditor.InsertForm(Chart.BackImage, TabImage)
end;

procedure TPanelEditor.RefreshChart(const AChart: TCustomChart);
begin
  Chart:=AChart;

  BPanelColor.Color:=Chart.Color;

  CBImageInside.IsChecked:=Chart.BackImage.Inside;
  CBColorDef.IsChecked:=Chart.Color=clNone;

  CBInner.ItemIndex:=Ord(Chart.BevelInner);
  CBOuter.ItemIndex:=Ord(Chart.BevelOuter);
  CBMarUnits.ItemIndex:=Ord(Chart.MarginUnits);
  UDPanelWi.Value:=Chart.BevelWidth;
  UDPanelBor.Value:=Chart.BorderWidth;
  UDRound.Value:=Chart.BorderRound;
  UDTopMa.Value:=Chart.MarginTop;
  UDRightMa.Value:=Chart.MarginRight;
  UDLeftMa.Value:=Chart.MarginLeft;
  UDBotMa.Value:=Chart.MarginBottom;
end;

procedure TPanelEditor.TabControlBordersChange(Sender: TObject);
begin
  if (TabControlBorders.ActiveTab=TabBorder) and (not Assigned(IBorder)) then
     IBorder:=TStrokeEditor.InsertForm(Chart.Border,TabBorder);
end;

procedure TPanelEditor.BPanelColorChange(Sender: TObject);
begin
  Chart.Color:=BPanelColor.Color;
  CBColorDef.IsChecked:=Chart.Color=clNone;

  if Chart.Owner is TCustomTeePanel then
     TCustomTeePanel(Chart.Owner).Repaint;
end;

procedure TPanelEditor.CBColorDefChange(Sender: TObject);
begin
  if CBColorDef.IsChecked then
  begin
    Chart.Color:=clNone;
    BPanelColor.Color:=Chart.Color;
  end;
end;

procedure TPanelEditor.CBImageInsideChange(Sender: TObject);
begin
  if Assigned(Chart) then
     Chart.BackImageInside:=CBImageInside.IsChecked;
end;

class function TPanelEditor.CreateEditor(const AOwner: TComponent; const AChart: TCustomChart):TForm;
begin
  result:=TPanelEditor.Create(AOwner);
  TPanelEditor(result).RefreshChart(AChart);
end;

procedure TPanelEditor.CBInnerChange(Sender: TObject);
begin
  if Assigned(Chart) then
     Chart.BevelInner:=TPanelBevel(CBInner.ItemIndex);
end;

procedure TPanelEditor.CBOuterChange(Sender: TObject);
begin
  if Assigned(Chart) then
     Chart.BevelOuter:=TPanelBevel(CBOuter.ItemIndex);
end;

procedure TPanelEditor.UDBotMaChange(Sender: TObject);
begin
  if Assigned(Chart) then
     Chart.MarginBottom:=Round(UDBotMa.Value);
end;

procedure TPanelEditor.UDLeftMaChange(Sender: TObject);
begin
  if Assigned(Chart) then
     Chart.MarginLeft:=Round(UDLeftMa.Value);
end;

procedure TPanelEditor.UDPanelBorChange(Sender: TObject);
begin
  if Assigned(Chart) then
     Chart.BorderWidth:=Round(UDPanelBor.Value);
end;

procedure TPanelEditor.UDPanelWiChange(Sender: TObject);
begin
  if Assigned(Chart) then
     Chart.BevelWidth:=Round(UDPanelWi.Value);
end;

procedure TPanelEditor.UDRightMaChange(Sender: TObject);
begin
  if Assigned(Chart) then
     Chart.MarginRight:=Round(UDRightMa.Value);
end;

procedure TPanelEditor.UDRoundChange(Sender: TObject);
begin
  if Assigned(Chart) then
     Chart.BorderRound:=Round(UDRound.Value);
end;

procedure TPanelEditor.UDTopMaChange(Sender: TObject);
begin
  if Assigned(Chart) then
     Chart.MarginTop:=Round(UDTopMa.Value);
end;

procedure TPanelEditor.CBMarUnitsChange(Sender: TObject);
begin
  if Assigned(Chart) then
    Chart.MarginUnits:=TTeeUnits(CBMarUnits.ItemIndex);
end;

end.
