Browse Source

OpenPictureDialog Changed Predefined Controls

Massimo Magnano 11 months ago
parent
commit
c30b62dacd

+ 52 - 16
bgradialogs.pas

@@ -1,6 +1,8 @@
 // SPDX-License-Identifier: LGPL-3.0-linking-exception
 {
   Additional dialogs to take advantage of our controls
+
+  2025-01 Massimo Magnano
 }
 unit BGRADialogs;
 
@@ -9,23 +11,32 @@ unit BGRADialogs;
 interface
 
 uses
-  Classes, SysUtils, ExtDlgs, Controls, StdCtrls, BGRABitmapTypes, BCRoundedImage;
+  Classes, SysUtils, ExtDlgs, Controls, StdCtrls, ExtCtrls,
+  BGRABitmapTypes, BCRoundedImage;
+
+resourcestring
+  rsSelectAPreviewFile = 'Select the File to preview';
 
 type
   TBGRAOpenPictureDialog = class(TPreviewFileDialog)
    private
     FDefaultFilter: string;
     FImageCtrl: TBCRoundedImage;
-    FPictureGroupBox: TGroupBox;
+    FPicturePanel: TPanel;
+    FPictureDetails: TLabel;
     FPreviewFilename: string;
+
   protected
     class procedure WSRegisterClass; override;
     function  IsFilterStored: Boolean; virtual;
-    property ImageCtrl: TBCRoundedImage read FImageCtrl;
-    property PictureGroupBox: TGroupBox read FPictureGroupBox;
     procedure InitPreviewControl; override;
     procedure ClearPreview; virtual;
     procedure UpdatePreview; virtual;
+
+    property ImageCtrl: TBCRoundedImage read FImageCtrl;
+    property PicturePanel: TPanel read FPicturePanel;
+    property PictureDetails: TLabel read FPictureDetails;
+
   public
     constructor Create(TheOwner: TComponent); override;
     procedure DoClose; override;
@@ -152,13 +163,34 @@ end;
 procedure TBGRAOpenPictureDialog.InitPreviewControl;
 begin
   inherited InitPreviewControl;
-  FPictureGroupBox.Parent:=PreviewFileControl;
+
+  PreviewFileControl.Width:=300;
+  PreviewFileControl.Height:=300;
+  FPicturePanel.Parent:=PreviewFileControl;
+  FPicturePanel.Align:=alClient;
+  { #note -oMaxM : We create it here because the LCL assumes there is a groupbox
+                   with only an image inside and crashes if it find it before this point }
+  FPictureDetails:=TLabel.Create(Self);
+    with FPictureDetails do begin
+      Name:='FPictureDetails';
+      Parent:= FPicturePanel;
+      Top:=PreviewFileControl.Height-20;
+      Height:=20;
+      Width:=PreviewFileControl.Width;
+      Align:=alBottom;
+      Caption:='';
+    end;
+
+  FImageCtrl.Align:=alClient;
 end;
 
 procedure TBGRAOpenPictureDialog.ClearPreview;
 begin
-  FPictureGroupBox.Caption:='None';
+  FPicturePanel.VerticalAlignment:=taVerticalCenter;
+  FPicturePanel.Caption:= rsSelectAPreviewFile;
   FImageCtrl.Bitmap:=nil;
+  FImageCtrl.Visible:= False;
+  FPictureDetails.Caption:='';
 end;
 
 procedure TBGRAOpenPictureDialog.UpdatePreview;
@@ -166,6 +198,9 @@ var
   CurFilename: String;
   FileIsValid: boolean;
 begin
+  FPicturePanel.Caption:= '';
+  FPictureDetails.Caption:='';
+
   CurFilename := FileName;
   if CurFilename = FPreviewFilename then exit;
 
@@ -176,14 +211,14 @@ begin
   if FileIsValid then
     try
       FImageCtrl.Bitmap.LoadFromFile(FPreviewFilename);
+      FImageCtrl.Visible:= True;
       FImageCtrl.Invalidate; { #todo -oMaxM : an event in TBGRBitmap might be useful }
-      FPictureGroupBox.Caption := Format('(%dx%d)',
-        [FImageCtrl.Picture.Width, FImageCtrl.Picture.Height]);
+
+      FPictureDetails.Caption:= Format('%d x %d x %d dpi', [FImageCtrl.Bitmap.Width, FImageCtrl.Bitmap.Height, Trunc(FImageCtrl.Bitmap.ResolutionX)]);
     except
       FileIsValid := False;
     end;
-  if not FileIsValid then
-    ClearPreview;
+  if not FileIsValid then ClearPreview;
 end;
 
 constructor TBGRAOpenPictureDialog.Create(TheOwner: TComponent);
@@ -193,17 +228,18 @@ begin
                     Format(rsAllFiles,[GetAllFilesMask, GetAllFilesMask,'']);
   Filter:=FDefaultFilter;
 
-  FPictureGroupBox:=TGroupBox.Create(Self);
-  with FPictureGroupBox do begin
-    Name:='FPictureGroupBox';
-    Align:=alClient;
+  FPicturePanel:=TPanel.Create(Self);
+  with FPicturePanel do begin
+    Name:='FPicturePanel';
+    BorderStyle:=bsNone;
+    BevelOuter:=bvNone;
+    VerticalAlignment:=taVerticalCenter;
   end;
 
   FImageCtrl:=TBCRoundedImage.Create(Self);
   with FImageCtrl do begin
     Name:='FImageCtrl';
-    Parent:=FPictureGroupBox;
-    Align:=alClient;
+    Parent:=FPicturePanel;
     Style:=isSquare;
     Proportional:=true;
   end;

+ 57 - 48
test/test_bcroundedimage_pictdialogs/test_bcroundedimage_pictdialogs_main.lfm

@@ -1,16 +1,17 @@
 object Form1: TForm1
-  Left = 297
-  Height = 315
-  Top = 250
-  Width = 500
+  Left = 334
+  Height = 328
+  Top = 229
+  Width = 510
   Caption = 'Form1'
-  ClientHeight = 315
-  ClientWidth = 500
+  ClientHeight = 328
+  ClientWidth = 510
+  LCLVersion = '4.99.0.0'
   object rgStyle: TRadioGroup
     Left = 320
-    Height = 66
+    Height = 80
     Top = 136
-    Width = 137
+    Width = 168
     AutoFill = True
     Caption = 'Style'
     ChildSizing.LeftRightSpacing = 6
@@ -20,8 +21,8 @@ object Form1: TForm1
     ChildSizing.ShrinkVertical = crsScaleChilds
     ChildSizing.Layout = cclLeftToRightThenTopToBottom
     ChildSizing.ControlsPerLine = 1
-    ClientHeight = 46
-    ClientWidth = 133
+    ClientHeight = 60
+    ClientWidth = 166
     ItemIndex = 2
     Items.Strings = (
       'Circle'
@@ -34,16 +35,16 @@ object Form1: TForm1
   end
   object Label1: TLabel
     Left = 320
-    Height = 15
-    Top = 211
-    Width = 55
+    Height = 19
+    Top = 219
+    Width = 62
     Caption = 'Rounding:'
   end
   object edRounding: TFloatSpinEdit
     Left = 384
-    Height = 23
-    Top = 208
-    Width = 50
+    Height = 29
+    Top = 216
+    Width = 56
     MaxValue = 100
     TabOrder = 1
     Value = 10
@@ -52,17 +53,17 @@ object Form1: TForm1
   object btLoad: TButton
     Left = 320
     Height = 25
-    Top = 240
-    Width = 75
+    Top = 248
+    Width = 80
     Caption = 'Load (BGRA)'
     TabOrder = 2
     OnClick = btLoadClick
   end
   object cbProportional: TCheckBox
     Left = 320
-    Height = 19
+    Height = 21
     Top = 32
-    Width = 84
+    Width = 100
     Caption = 'Proportional'
     TabOrder = 3
     OnChange = cbProportionalChange
@@ -90,7 +91,7 @@ object Form1: TForm1
   end
   object rgAlign: TRadioGroup
     Left = 320
-    Height = 65
+    Height = 80
     Top = 56
     Width = 79
     AutoFill = True
@@ -102,8 +103,8 @@ object Form1: TForm1
     ChildSizing.ShrinkVertical = crsScaleChilds
     ChildSizing.Layout = cclLeftToRightThenTopToBottom
     ChildSizing.ControlsPerLine = 1
-    ClientHeight = 45
-    ClientWidth = 75
+    ClientHeight = 60
+    ClientWidth = 77
     ItemIndex = 2
     Items.Strings = (
       'Left'
@@ -115,7 +116,7 @@ object Form1: TForm1
   end
   object rgAlignV: TRadioGroup
     Left = 400
-    Height = 65
+    Height = 81
     Top = 56
     Width = 79
     AutoFill = True
@@ -127,8 +128,8 @@ object Form1: TForm1
     ChildSizing.ShrinkVertical = crsScaleChilds
     ChildSizing.Layout = cclLeftToRightThenTopToBottom
     ChildSizing.ControlsPerLine = 1
-    ClientHeight = 45
-    ClientWidth = 75
+    ClientHeight = 61
+    ClientWidth = 77
     ItemIndex = 1
     Items.Strings = (
       'Top'
@@ -140,9 +141,9 @@ object Form1: TForm1
   end
   object cbStretch: TCheckBox
     Left = 320
-    Height = 19
+    Height = 21
     Top = 8
-    Width = 55
+    Width = 67
     Caption = 'Stretch'
     Checked = True
     State = cbChecked
@@ -150,54 +151,62 @@ object Form1: TForm1
     OnChange = cbStretchChange
   end
   object btLoadT: TButton
-    Left = 400
+    Left = 408
     Height = 25
-    Top = 240
-    Width = 88
+    Top = 248
+    Width = 96
     Caption = 'Load (TPicture)'
     TabOrder = 8
     OnClick = btLoadTClick
   end
-  object btLoad2: TButton
+  object btSavePictBGRA: TButton
     Left = 320
     Height = 25
-    Top = 269
-    Width = 75
+    Top = 277
+    Width = 80
     Caption = 'Save (BGRA)'
     TabOrder = 9
-    OnClick = btLoadClick
+    OnClick = btSavePictBGRAClick
   end
-  object btLoad3: TButton
-    Left = 400
+  object btSavePict: TButton
+    Left = 408
     Height = 25
-    Top = 269
-    Width = 88
+    Top = 277
+    Width = 96
     Caption = 'Save (TPicture)'
     TabOrder = 10
-    OnClick = btLoadClick
+    OnClick = btSavePictClick
   end
   object lbDetails: TLabel
     Left = 320
-    Height = 15
-    Top = 296
-    Width = 36
+    Height = 19
+    Top = 304
+    Width = 40
     Caption = 'image:'
   end
   object Button1: TButton
     Left = 448
     Height = 25
-    Top = 208
+    Top = 216
     Width = 40
     Caption = 'test'
     TabOrder = 11
     OnClick = Button1Click
   end
   object openPict: TOpenPictureDialog
-    Left = 472
-    Top = 48
+    Left = 72
+    Top = 136
   end
   object savePict: TSavePictureDialog
-    Left = 472
-    Top = 99
+    Left = 192
+    Top = 136
+  end
+  object openPictBGRA: TBGRAOpenPictureDialog
+    Left = 72
+    Top = 56
+  end
+  object savePictBGRA: TBGRASavePictureDialog
+    Left = 192
+    Top = 56
   end
 end

+ 20 - 7
test/test_bcroundedimage_pictdialogs/test_bcroundedimage_pictdialogs_main.pas

@@ -14,10 +14,12 @@ type
 
   TForm1 = class(TForm)
     BCRoundedImage1: TBCRoundedImage;
+    openPictBGRA: TBGRAOpenPictureDialog;
+    savePictBGRA: TBGRASavePictureDialog;
     btLoad: TButton;
     btLoadT: TButton;
-    btLoad2: TButton;
-    btLoad3: TButton;
+    btSavePictBGRA: TButton;
+    btSavePict: TButton;
     Button1: TButton;
     cbProportional: TCheckBox;
     cbStretch: TCheckBox;
@@ -31,6 +33,8 @@ type
     rgStyle: TRadioGroup;
     savePict: TSavePictureDialog;
     procedure BCRoundedImage1PaintEvent(const Sender: TBCRoundedImage; const Bitmap: TBGRABitmap);
+    procedure btSavePictBGRAClick(Sender: TObject);
+    procedure btSavePictClick(Sender: TObject);
     procedure btLoadClick(Sender: TObject);
     procedure btLoadTClick(Sender: TObject);
     procedure Button1Click(Sender: TObject);
@@ -60,13 +64,23 @@ begin
   //
 end;
 
-procedure TForm1.btLoadClick(Sender: TObject);
-var
-   openPictBGRA: TBGRAOpenPictureDialog;
+procedure TForm1.btSavePictBGRAClick(Sender: TObject);
+begin
+  if savePictBGRA.Execute then
+  begin
+  end;
+end;
 
+procedure TForm1.btSavePictClick(Sender: TObject);
+begin
+  if savePict.Execute then
+  begin
+  end;
+end;
+
+procedure TForm1.btLoadClick(Sender: TObject);
 begin
   try
-     openPictBGRA:= TBGRAOpenPictureDialog.Create(Self);
      if openPictBGRA.Execute then
      begin
        BCRoundedImage1.Picture:= nil;
@@ -76,7 +90,6 @@ begin
      end;
 
   finally
-    openPictBGRA.Free;
   end;
 end;