TColorDialog: implement property AlphaChannel and associated option cdShowAlphaChannel for GTK2.

This commit is contained in:
Bart 2024-12-14 15:54:25 +01:00
parent 5a4f5ca305
commit 633cb5bbc0
3 changed files with 19 additions and 4 deletions

View File

@ -292,18 +292,20 @@ type
cdPreventFullOpen, // Disables the Define Custom Color button. cdPreventFullOpen, // Disables the Define Custom Color button.
cdShowHelp, // Causes the dialog box to display the Help button. cdShowHelp, // Causes the dialog box to display the Help button.
cdSolidColor, // Causes the dialog box to display only solid colors in the set of basic colors. cdSolidColor, // Causes the dialog box to display only solid colors in the set of basic colors.
cdAnyColor // Causes the dialog box to display all available colors in the set of basic colors. cdAnyColor, // Causes the dialog box to display all available colors in the set of basic colors.
cdShowAlphaChannel // Shows the AlphaChannel control (GTK2, QT, QT5, QT6)
); );
TColorDialogOptions = set of TColorDialogOption; TColorDialogOptions = set of TColorDialogOption;
const const
DefaultColorDialogOptions = [cdFullOpen]; //for backwards compatibility, probably not Delphi compatible DefaultColorDialogOptions = [cdFullOpen, cdShowAlphaChannel]; //for backwards compatibility, probably not Delphi compatible
{ TColorDialog } { TColorDialog }
type type
TColorDialog = class(TCommonDialog) TColorDialog = class(TCommonDialog)
private private
FAlphaChannel: Byte;
FColor: TColor; FColor: TColor;
FCustomColors: TStrings; FCustomColors: TStrings;
FOptions: TColorDialogOptions; FOptions: TColorDialogOptions;
@ -318,6 +320,7 @@ type
destructor Destroy; override; destructor Destroy; override;
published published
property Title; property Title;
property AlphaChannel: Byte read FAlphaChannel write FAlphaChannel default 255;
property Color: TColor read FColor write FColor; property Color: TColor read FColor write FColor;
// entry looks like ColorA = FFFF00 ... ColorX = C0C0C0 // entry looks like ColorA = FFFF00 ... ColorX = C0C0C0
property CustomColors: TStrings read FCustomColors write SetCustomColors; property CustomColors: TStrings read FCustomColors write SetCustomColors;

View File

@ -48,6 +48,7 @@ end;
constructor TColorDialog.Create(TheOwner: TComponent); constructor TColorDialog.Create(TheOwner: TComponent);
begin begin
inherited Create(TheOwner); inherited Create(TheOwner);
FAlphaChannel := 255;
FCustomColors := TStringList.Create; FCustomColors := TStringList.Create;
// add default colors // add default colors
GetColorValues(@AddDefaultColor); GetColorValues(@AddDefaultColor);

View File

@ -441,6 +441,7 @@ var
// colordialog // colordialog
colorsel : PGtkColorSelection; colorsel : PGtkColorSelection;
newColor : TGdkColor; newColor : TGdkColor;
newAlpha : Word;
// fontdialog // fontdialog
FontName : String; FontName : String;
ALogFont : TLogFont; ALogFont : TLogFont;
@ -542,6 +543,8 @@ begin
begin begin
colorSel := PGtkColorSelection(PGtkColorSelectionDialog(FPointer)^.colorsel); colorSel := PGtkColorSelection(PGtkColorSelectionDialog(FPointer)^.colorsel);
gtk_color_selection_get_current_color(colorsel, @newColor); gtk_color_selection_get_current_color(colorsel, @newColor);
newAlpha := gtk_color_selection_get_current_alpha(colorsel);
TColorDialog(theDialog).AlphaChannel := newAlpha and $FF; //equivalent to divide by 0x0101
TColorDialog(theDialog).Color := TGDKColorToTColor(newcolor); TColorDialog(theDialog).Color := TGDKColorToTColor(newcolor);
{$IFDEF VerboseColorDialog} {$IFDEF VerboseColorDialog}
DebugLn('gtkDialogOKclickedCB ',DbgS(TColorDialog(theDialog).Color)); DebugLn('gtkDialogOKclickedCB ',DbgS(TColorDialog(theDialog).Color));
@ -1278,16 +1281,24 @@ end;
class procedure TGtk2WSCommonDialog.ShowModal(const ACommonDialog: TCommonDialog); class procedure TGtk2WSCommonDialog.ShowModal(const ACommonDialog: TCommonDialog);
var var
GtkWindow: PGtkWindow; GtkWindow: PGtkWindow;
colorsel: PGtkColorSelection;
ColorDialog: TColorDialog;
CurrentAlpha: Word;
begin begin
ReleaseMouseCapture; ReleaseMouseCapture;
GtkWindow:={%H-}PGtkWindow(ACommonDialog.Handle); GtkWindow:={%H-}PGtkWindow(ACommonDialog.Handle);
gtk_window_set_title(GtkWindow,PChar(ACommonDialog.Title)); gtk_window_set_title(GtkWindow,PChar(ACommonDialog.Title));
if ACommonDialog is TColorDialog then if ACommonDialog is TColorDialog then
begin begin
ColorDialog := TColorDialog(ACommonDialog);
SetColorDialogColor(PGtkColorSelectionDialog(GtkWindow), SetColorDialogColor(PGtkColorSelectionDialog(GtkWindow),
TColorDialog(ACommonDialog).Color); ColorDialog.Color);
SetColorDialogPalette(PGtkColorSelectionDialog(GtkWindow), SetColorDialogPalette(PGtkColorSelectionDialog(GtkWindow),
TColorDialog(ACommonDialog).CustomColors); ColorDialog.CustomColors);
colorsel := PGtkColorSelection(PGtkColorSelectionDialog(GtkWindow)^.colorsel);
gtk_color_selection_set_has_opacity_control(colorsel, (cdShowAlphaChannel in ColorDialog.Options));
CurrentAlpha := Word(ColorDialog.AlphaChannel) * $0101;
gtk_color_selection_set_current_alpha(colorsel, CurrentAlpha);
end; end;
gtk_window_set_position(GtkWindow, GTK_WIN_POS_CENTER); gtk_window_set_position(GtkWindow, GTK_WIN_POS_CENTER);