{**********************************************}
{   TImageTool Editor                          }
{   Copyright (c) 1999-2020 by Steema Software }
{**********************************************}
unit TeeImageToolEdit;
{$I TeeDefs.inc}

interface

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

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

     TeeToolSeriesEdit, TeeTools, TeCanvas, TeePenDlg;

type
  TChartImageToolEditor = class(TSeriesToolEditor)
    PageControl1: TPageControl;
    TabSheet1: TTabSheet;
    TabBorder: TTabSheet;
    Button1: TButton;
    Button2: TButton;
    Image1: TImage;
    BSave: TButton;
    procedure Button1Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure BSaveClick(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure PageControl1Change(Sender: TObject);
  private
    { Private declarations }
    Image : TChartImageTool;
    Procedure CheckImageButton;
  public
    { Public declarations }
  end;

implementation

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

uses
  TeeBrushDlg, TeeConst, TeeFiltersEditor;

procedure TChartImageToolEditor.Button1Click(Sender: TObject);
var tmp : String;
begin
  if Button1.Tag=1 then
     Image.Picture:=nil
  else
  begin
    tmp:=TeeGetPictureFileName(Self);
    if tmp<>'' then
    begin
      Image.Picture.LoadFromFile(tmp);
      Image.Repaint;
    end;
  end;

  CheckImageButton;
end;

Procedure TChartImageToolEditor.CheckImageButton;
begin
  if Assigned(Image.Picture.Graphic) then
  begin
    Button1.Tag:=1;
    Button1.Caption:=TeeMsg_ClearImage;
    Image1.Picture.Assign(Image.Picture);
    BSave.Enabled:=True;
  end
  else
  begin
    Button1.Tag:=0;
    Button1.Caption:=TeeMsg_BrowseImage;
    Image1.Picture:=nil;
    BSave.Enabled:=False;
  end;
end;

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

  Image:=TChartImageTool(Tag);

  if Assigned(Image) then
     CheckImageButton;
end;

procedure TChartImageToolEditor.FormCreate(Sender: TObject);
begin
  inherited;
  Align:=alClient;
end;

procedure TChartImageToolEditor.BSaveClick(Sender: TObject);
begin
  if Assigned(Image.Picture.Graphic) then
     TeeSavePictureDialog(Self,Image.Picture.Graphic);
end;

procedure TChartImageToolEditor.Button2Click(Sender: TObject);
begin
  ShowFiltersEditor(Self, Image.Picture);
end;

procedure TChartImageToolEditor.PageControl1Change(Sender: TObject);
begin
  if (PageControl1.ActivePage=TabBorder) and (TabBorder.ControlCount=0) then
     TPenDialog.InsertForm(Image.Pen,TabBorder);
end;

initialization
  RegisterClass(TChartImageToolEditor);
end.

