1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
|
{
*****************************************************************************
See the file COPYING.modifiedLGPL.txt, included in this distribution,
for details about the license.
*****************************************************************************
Author: Tomas Gregorovic
Abstract:
This units defines the Load Image Dialog (TGraphicPropertyEditorForm)
for graphic or picture property editor.
}
unit GraphicPropEdit;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls,
ExtCtrls, Buttons, ButtonPanel, ExtDlgs, ActnList, StdActns, Clipbrd,
IDEDialogs, ObjInspStrConsts;
type
{ TGraphicPropertyEditorForm }
TGraphicPropertyEditorForm = class(TForm)
FileOpenAction: TAction;
FileSaveAction: TAction;
ClearAction: TEditDelete;
ActionList: TActionList;
CopyButton: TButton;
PasteButton: TButton;
CopyAction: TEditCopy;
PasteAction: TEditPaste;
OkCancelButtonPanel: TButtonPanel;
ImagePreview: TImage;
LoadButton: TButton;
LoadSaveBtnPanel: TPanel;
OpenDialog: TOpenPictureDialog;
SaveButton: TButton;
ClearButton: TButton;
GroupBox1: TGroupBox;
SaveDialog: TSavePictureDialog;
ScrollBox: TScrollBox;
procedure CopyActionExecute(Sender: TObject);
procedure CopyActionUpdate(Sender: TObject);
procedure PasteActionExecute(Sender: TObject);
procedure PasteActionUpdate(Sender: TObject);
procedure ClearActionExecute(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FileOpenActionExecute(Sender: TObject);
procedure FileSaveActionExecute(Sender: TObject);
procedure FileSaveActionUpdate(Sender: TObject);
procedure PictureChanged(Sender: TObject);
private
FFileName: String;
FModified: Boolean;
function GetGraphic: TGraphic;
procedure SetGraphic(Value: TGraphic);
procedure SetCaptionDetail(Value: String);
public
property CaptionDetail: String write SetCaptionDetail;
property FileName: String read FFileName;
property Modified: Boolean read FModified;
property Graphic: TGraphic read GetGraphic write SetGraphic;
end;
implementation
{$R *.lfm}
{ TGraphicPropertyEditorForm }
procedure TGraphicPropertyEditorForm.FormCreate(Sender: TObject);
begin
Caption := oisLoadImageDialog;
GroupBox1.Caption:=oisPEPicture;
OkCancelButtonPanel.OKButton.Caption := oisOK;
OkCancelButtonPanel.CancelButton.Caption := oisCancel;
CopyAction.Caption := oiStdActEditCopyHeadLine;
PasteAction.Caption := oiStdActEditPasteHeadLine;
FileOpenAction.Caption := oisLoad;
FileSaveAction.Caption := oisSave;
ClearAction.Caption := oisClear;
OpenDialog.Title:=oisPEOpenImageFile;
SaveDialog.Title:=oisPESaveImageAs;
ImagePreview.OnPictureChanged:=@PictureChanged;
end;
procedure TGraphicPropertyEditorForm.ClearActionExecute(Sender: TObject);
begin
ImagePreview.Picture.Clear;
end;
procedure TGraphicPropertyEditorForm.CopyActionExecute(Sender: TObject);
begin
Clipboard.Assign(ImagePreview.Picture.Graphic);
end;
procedure TGraphicPropertyEditorForm.CopyActionUpdate(Sender: TObject);
begin
CopyAction.Enabled := ImagePreview.Picture.Graphic <> nil;
end;
procedure TGraphicPropertyEditorForm.FileSaveActionUpdate(Sender: TObject);
begin
(Sender as TAction).Enabled := (Graphic <> nil) and (not Graphic.Empty);
end;
procedure TGraphicPropertyEditorForm.PasteActionExecute(Sender: TObject);
begin
ImagePreview.Picture.Assign(Clipboard);
end;
procedure TGraphicPropertyEditorForm.PasteActionUpdate(Sender: TObject);
begin
PasteAction.Enabled := Clipboard.HasPictureFormat;
end;
procedure TGraphicPropertyEditorForm.FileOpenActionExecute(Sender: TObject);
begin
InitIDEFileDialog(OpenDialog);
if OpenDialog.Execute then
begin
try
ImagePreview.Picture.LoadFromFile(OpenDialog.FileName);
FFileName := OpenDialog.FileName; // OnPictureChange clears the field.
except
on E: Exception do begin
MessageDlg(oisErrorLoadingImage,
Format(oisErrorLoadingImage2, ['"', FileName, '"', LineEnding, E.Message]),
mtError, [mbOk], 0);
exit;
end;
end;
end;
StoreIDEFileDialog(OpenDialog);
end;
procedure TGraphicPropertyEditorForm.PictureChanged(Sender: TObject);
begin
FModified := True;
FFileName := '';
if Graphic <> nil then
ScrollBox.Hint := Graphic.ClassName
else
ScrollBox.Hint := '';
end;
procedure TGraphicPropertyEditorForm.FileSaveActionExecute(Sender: TObject);
begin
InitIDEFileDialog(SaveDialog);
if SaveDialog.Execute then
if SaveDialog.FilterIndex > 1 then
ImagePreview.Picture.SaveToFile(SaveDialog.FileName, SaveDialog.GetFilterExt)
else
ImagePreview.Picture.SaveToFile(SaveDialog.FileName);
StoreIDEFileDialog(SaveDialog);
end;
function TGraphicPropertyEditorForm.GetGraphic: TGraphic;
begin
Result := ImagePreview.Picture.Graphic;
end;
procedure TGraphicPropertyEditorForm.SetGraphic(Value: TGraphic);
begin
ImagePreview.Picture.Assign(Value);
FModified := False;
end;
procedure TGraphicPropertyEditorForm.SetCaptionDetail(Value: String);
begin
Caption := oisLoadImageDialog + ' - ' + Value;
end;
end.
|