{********************************************}
{ TPieSeries Editor Dialog                   }
{ Copyright (c) 1996-2020 by Steema Software }
{********************************************}
unit TeePieEdit;
{$I TeeDefs.inc}

{$IFNDEF LCL}

{$IFNDEF BCB}
{$DEFINE TEEGDI}
{$ENDIF}

{$IFDEF D14}
{$DEFINE TEEGDI}
{$ENDIF}

{$ENDIF}

interface

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

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

     Chart, Series, TeCanvas, TeePenDlg, TeeProcs, TeeCircledEdit, TeeEdiGrad,
     TeeFrames;

type
  TPieSeriesEditor = class(TForm)
    PageControl1: TPageControl;
    TabOptions: TTabSheet;
    Label4: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    LTransparency: TLabel;
    LEdgeStyle: TLabel;
    CBDark3d: TCheckBox;
    SEExpBig: TEdit;
    UDExpBig: TUpDown;
    CBPatterns: TCheckBox;
    Edit1: TEdit;
    UDAngleSize: TUpDown;
    CBMultiple: TComboFlat;
    CBEdgeStyle: TComboFlat;
    TabGroup: TTabSheet;
    TabSheet1: TTabSheet;
    Label9: TLabel;
    CBColorEach: TCheckBox;
    BColor: TButtonColor;
    CBPalette: TComboFlat;
    TabSheet2: TTabSheet;
    Label8: TLabel;
    CBMarksAutoPosition: TCheckBox;
    CBVertCenter: TCheckBox;
    TabFrame: TTabSheet;
    TabGradient: TTabSheet;
    Label11: TLabel;
    LLegSize: TLabel;
    TabBorders: TTabSheet;
    CBMarksInside: TCheckBox;
    PageControl2: TPageControl;
    TabBevel: TTabSheet;
    TabBorder: TTabSheet;
    LBevelPercent: TLabel;
    Label12: TLabel;
    LBevelBright: TLabel;
    TBBevelBright: TTrackBar;
    CBBevelBorder: TCheckBox;
    TBTransp: TTrackBar;
    TBBevel: TTrackBar;
    Label1: TLabel;
    TBDark: TTrackBar;
    PageControl3: TPageControl;
    TabSheet3: TTabSheet;
    TabLegend: TTabSheet;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    CBOther: TComboFlat;
    EOtherValue: TEdit;
    EOtherLabel: TEdit;
    Panel1: TPanel;
    Label10: TLabel;
    LBright: TLabel;
    TBBright: TTrackBar;
    CBRotated: TCheckBox;
    TBLegSize: TTrackBar;
    CBMarksEmpty: TCheckBox;
    LBevelPerc: TLabel;
    CBRotateStyle: TComboFlat;
    Label13: TLabel;
    procedure FormShow(Sender: TObject);
    procedure CBDark3dClick(Sender: TObject);
    procedure CBPatternsClick(Sender: TObject);
    procedure CBOtherChange(Sender: TObject);
    procedure EOtherValueChange(Sender: TObject);
    procedure EOtherLabelChange(Sender: TObject);
    procedure SEExpBigChange(Sender: TObject);
    procedure Edit1Change(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure CBMarksAutoPositionClick(Sender: TObject);
    procedure CBMultipleChange(Sender: TObject);
    procedure CBColorEachClick(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure CBVertCenterClick(Sender: TObject);
    procedure CBPaletteChange(Sender: TObject);
    procedure TBBrightChange(Sender: TObject);
    procedure CBEdgeStyleChange(Sender: TObject);
    procedure PageControl1Change(Sender: TObject);
    procedure TBBevelBrightChange(Sender: TObject);
    procedure CBBevelBorderClick(Sender: TObject);
    procedure CBMarksInsideClick(Sender: TObject);
    procedure PageControl2Change(Sender: TObject);
    procedure TBTranspChange(Sender: TObject);
    procedure TBBevelChange(Sender: TObject);
    procedure TBDarkChange(Sender: TObject);
    procedure PageControl3Change(Sender: TObject);
    procedure CBRotatedClick(Sender: TObject);
    procedure TBLegSizeChange(Sender: TObject);
    procedure CBMarksEmptyClick(Sender: TObject);
    procedure CBRotateStyleChange(Sender: TObject);
  private
    { Private declarations }
    Pie : TPieSeries;
    tmpCircled  : TCircledSeriesEditor;
  public
    { Public declarations }
    procedure CheckCircledEditor;
  end;

implementation

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

Uses
  TeeConst, TeEngine, TeeEdiLege, TeeBrushDlg;

procedure TPieSeriesEditor.FormShow(Sender: TObject);
var tmpTab : TTabSheet;
begin
  Pie:=TPieSeries(Tag);

  if Assigned(Pie) then
  begin
    BColor.LinkProperty(Pie,'SeriesColor');

    With Pie do
    begin
      UDExpBig.Position  :=ExplodeBiggest;
      CBDark3D.Checked   :=Dark3D;
      CBDark3D.Enabled   :=Assigned(ParentChart) and ParentChart.View3D;
      CBPatterns.Checked :=UsePatterns;

      case MultiPie of
        mpAutomatic: CBMultiple.ItemIndex:=0;
        mpDisabled : CBMultiple.ItemIndex:=1;
      else
        CBMultiple.ItemIndex:=2; // Concentric
      end;

      CBColorEach.Checked:=ColorEachPoint;

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

      CBPalette.Enabled:=Assigned(ParentChart);

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

      With OtherSlice do
      begin
        EOtherLabel.Text:=Text;
        EOtherValue.Text:=FloatToStr(Value);
        CBOther.ItemIndex:=Ord(Style);
        EnableControls(Style<>poNone,[EOtherLabel,EOtherValue]);
      end;

      UDAngleSize.Position:=AngleSize;
      CBMarksAutoPosition.Checked:=AutoMarkPosition;
      TBDark.Position:=DarkPen;

      CBVertCenter.Checked:=PieMarks.VertCenter;

      TBLegSize.Position:=PieMarks.LegSize;
      LLegSize.Caption:=TeeStr(TBLegSize.Position);

      CBMarksInside.Checked:=PieMarks.InsideSlice;
      CBRotated.Checked:=PieMarks.Rotated;
      CBRotateStyle.ItemIndex:=Ord(PieMarks.RotateStyle);
      CBRotateStyle.Enabled:=cbRotated.Checked;
      CBMarksEmpty.Checked:=PieMarks.EmptySlice;
      
      TBBright.Position:=GradientBright;
      LBright.Caption:=IntToStr(GradientBright);

      TBBevelBright.Position:=Bevel.Bright;
      LBevelBright.Caption:=IntToStr(Bevel.Bright);

      CBBevelBorder.Checked:=Bevel.UseBorder;

      TBTransp.Position:=Transparency;

      TBBevel.Position:=Bevel.Percent;
      LBevelPerc.Caption:=IntToStr(Bevel.Percent);

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

      {$IFDEF TEEGDI}
      //EnableControls(Pie.ParentChart.Canvas is TGDIPlusCanvas,[LEdgeStyle,CBEdgeStyle]);
      {$ENDIF}
    end;

    CheckCircledEditor;

    if not Assigned(tmpCircled.Parent) then
    begin
      tmpTab:=TTabSheet.Create(Self);
      tmpTab.Caption:=TeeMsg_GalleryCircled;
      tmpTab.PageControl:=PageControl1;

      tmpCircled.Align:=alClient;
      AddFormTo(tmpCircled,tmpTab,Pie);
    end;
  end;

  PageControl1.ActivePage:=TabOptions;

  TeeTranslateControl(Self);
end;

procedure TPieSeriesEditor.CheckCircledEditor;
begin
  if not Assigned(tmpCircled) then
     tmpCircled:=TCircledSeriesEditor.CreateForm(Self,TCircledSeries(Tag));
end;

procedure TPieSeriesEditor.CBDark3DClick(Sender: TObject);
begin
  if Showing then Pie.Dark3D:=CBDark3D.Checked;
end;

procedure TPieSeriesEditor.CBEdgeStyleChange(Sender: TObject);
begin
  case CBEdgeStyle.ItemIndex of
    0: Pie.EdgeStyle:=edNone;
    1: Pie.EdgeStyle:=edFlat;
  else
    Pie.EdgeStyle:=edCurved;
  end;
end;

procedure TPieSeriesEditor.CBPatternsClick(Sender: TObject);
begin
  Pie.UsePatterns:=CBPatterns.Checked;
end;

procedure TPieSeriesEditor.CBOtherChange(Sender: TObject);
begin
  With Pie.OtherSlice do
  begin
    Style:=TPieOtherStyle(CBOther.ItemIndex);
    EnableControls(Style<>poNone,[EOtherLabel,EOtherValue]);
  end;
end;

procedure TPieSeriesEditor.EOtherValueChange(Sender: TObject);
begin
  if EOtherValue.Text<>'' then
     Pie.OtherSlice.Value:=StrToFloat(EOtherValue.Text);
end;

procedure TPieSeriesEditor.EOtherLabelChange(Sender: TObject);
begin
  if Assigned(Pie) then
     Pie.OtherSlice.Text:=EOtherLabel.Text;
end;

procedure TPieSeriesEditor.SEExpBigChange(Sender: TObject);
begin
  if Showing and Assigned(Pie) then
     Pie.ExplodeBiggest:=UDExpBig.Position;
end;

procedure TPieSeriesEditor.Edit1Change(Sender: TObject);
begin
  if Showing and Assigned(Pie) then
     Pie.AngleSize:=UDAngleSize.Position;
end;

procedure TPieSeriesEditor.FormCreate(Sender: TObject);
begin
  BorderStyle:=TeeBorderStyle;
  PageControl1.ActivePage:=TabOptions;
end;

procedure TPieSeriesEditor.CBMarksAutoPositionClick(Sender: TObject);
begin
  Pie.AutoMarkPosition:=CBMarksAutoPosition.Checked;
end;

procedure TPieSeriesEditor.CBMultipleChange(Sender: TObject);
begin
  case CBMultiple.ItemIndex of
    0: Pie.MultiPie:=mpAutomatic;
    1: Pie.MultiPie:=mpDisabled;
  else
   Pie.MultiPie:=mpConcentric;
  end;
end;

procedure TPieSeriesEditor.CBColorEachClick(Sender: TObject);
begin
  Pie.ColorEachPoint:=CBColorEach.Checked;
  BColor.Enabled:=not Pie.ColorEachPoint;
  CBPalette.Enabled:=Pie.ColorEachPoint;
end;

procedure TPieSeriesEditor.FormDestroy(Sender: TObject);
begin
  FreeAndNil(tmpCircled);
end;

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

procedure TPieSeriesEditor.CBPaletteChange(Sender: TObject);
var tmp : TCustomChart;
begin
  tmp:=TCustomChart(Pie.ParentChart);

  if tmp<>nil then
     tmp.ColorPaletteIndex:=CBPalette.ItemIndex-1;
end;

procedure TPieSeriesEditor.TBBrightChange(Sender: TObject);
begin
  Pie.GradientBright:=TBBright.Position;
  LBright.Caption:=IntToStr(Pie.GradientBright);
end;

procedure TPieSeriesEditor.PageControl1Change(Sender: TObject);
var tmp : TTeeGradientEditor;
begin
  if Assigned(Pie) then
     if (PageControl1.ActivePage=TabFrame) and (TabFrame.ControlCount=0) then
        TFramedBorderEditor.InsertDialog(TabFrame,Pie.Frame)
     else
     if (PageControl1.ActivePage=TabGradient) and (TabGradient.ControlCount<2) then
     begin
       tmp:=TTeeGradientEditor.CreateCustom(Self,Pie.Gradient,True);
       tmp.Align:=alClient;
       AddFormTo(tmp,TabGradient);
     end;
end;

procedure TPieSeriesEditor.TBBevelBrightChange(Sender: TObject);
begin
  Pie.Bevel.Bright:=TBBevelBright.Position;
  LBevelBright.Caption:=IntToStr(Pie.Bevel.Bright);
end;

procedure TPieSeriesEditor.CBBevelBorderClick(Sender: TObject);
begin
  Pie.Bevel.UseBorder:=CBBevelBorder.Checked;
end;

procedure TPieSeriesEditor.CBMarksInsideClick(Sender: TObject);
begin
  Pie.PieMarks.InsideSlice:=CBMarksInside.Checked;
end;

procedure TPieSeriesEditor.PageControl2Change(Sender: TObject);
begin
  if PageControl2.ActivePage=TabBorder then
     if TabBorder.ControlCount=0 then
        TPenDialog.InsertForm(Pie.PiePen,TabBorder);
end;

procedure TPieSeriesEditor.TBTranspChange(Sender: TObject);
begin
 if Showing and Assigned(Pie) then
    Pie.Transparency:=TBTransp.Position;
end;

procedure TPieSeriesEditor.TBBevelChange(Sender: TObject);
begin
  if Showing and Assigned(Pie) then
  begin
    Pie.BevelPercent:=TBBevel.Position;
    LBevelPerc.Caption:=IntToStr(Pie.BevelPercent);
  end;
end;

procedure TPieSeriesEditor.TBDarkChange(Sender: TObject);
begin
  if Showing and Assigned(Pie) then
     Pie.DarkPen:=TBDark.Position;
end;

procedure TPieSeriesEditor.PageControl3Change(Sender: TObject);
var tmp : TFormTeeLegend;
begin
  if (PageControl3.ActivePage=TabLegend) and (TabLegend.ControlCount=0) then
  begin
    tmp:=TFormTeeLegend.CreateLegend(Self,Pie.OtherSlice.Legend);
    tmp.Align:=alClient;
    AddFormTo(tmp,TabLegend);
  end;
end;

procedure TPieSeriesEditor.CBRotatedClick(Sender: TObject);
begin
  Pie.PieMarks.Rotated:=CBRotated.Checked;
  CBRotateStyle.Enabled:=cbRotated.Checked;
end;

procedure TPieSeriesEditor.CBRotateStyleChange(Sender: TObject);
begin
    case CBRotateStyle.ItemIndex of
    0: Pie.PieMarks.RotateStyle:=rsRadial;
  else
    Pie.PieMarks.RotateStyle:=rsTangencial;
  end;
end;

procedure TPieSeriesEditor.TBLegSizeChange(Sender: TObject);
begin
  Pie.PieMarks.LegSize:=TBLegSize.Position;
  LLegSize.Caption:=TeeStr(TBLegSize.Position);
end;

procedure TPieSeriesEditor.CBMarksEmptyClick(Sender: TObject);
begin
  Pie.PieMarks.EmptySlice:=CBMarksEmpty.Checked;
end;

initialization
  RegisterSeriesEditor(TPieSeriesEditor);
end.
