diff --git a/lcl/dialogs.pp b/lcl/dialogs.pp index 65f39e5e7c..6ac54612e5 100644 --- a/lcl/dialogs.pp +++ b/lcl/dialogs.pp @@ -292,18 +292,20 @@ type cdPreventFullOpen, // Disables the Define Custom Color 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. - 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; const - DefaultColorDialogOptions = [cdFullOpen]; //for backwards compatibility, probably not Delphi compatible + DefaultColorDialogOptions = [cdFullOpen, cdShowAlphaChannel]; //for backwards compatibility, probably not Delphi compatible { TColorDialog } type TColorDialog = class(TCommonDialog) private + FAlphaChannel: Byte; FColor: TColor; FCustomColors: TStrings; FOptions: TColorDialogOptions; @@ -318,6 +320,7 @@ type destructor Destroy; override; published property Title; + property AlphaChannel: Byte read FAlphaChannel write FAlphaChannel default 255; property Color: TColor read FColor write FColor; // entry looks like ColorA = FFFF00 ... ColorX = C0C0C0 property CustomColors: TStrings read FCustomColors write SetCustomColors; diff --git a/lcl/include/lclcolordialog.inc b/lcl/include/lclcolordialog.inc index 37af28b189..1019b6992a 100644 --- a/lcl/include/lclcolordialog.inc +++ b/lcl/include/lclcolordialog.inc @@ -48,6 +48,7 @@ end; constructor TColorDialog.Create(TheOwner: TComponent); begin inherited Create(TheOwner); + FAlphaChannel := 255; FCustomColors := TStringList.Create; // add default colors GetColorValues(@AddDefaultColor); diff --git a/lcl/interfaces/gtk2/gtk2wsdialogs.pp b/lcl/interfaces/gtk2/gtk2wsdialogs.pp index 1264ae6cc7..d522cec238 100644 --- a/lcl/interfaces/gtk2/gtk2wsdialogs.pp +++ b/lcl/interfaces/gtk2/gtk2wsdialogs.pp @@ -441,6 +441,7 @@ var // colordialog colorsel : PGtkColorSelection; newColor : TGdkColor; + newAlpha : Word; // fontdialog FontName : String; ALogFont : TLogFont; @@ -542,6 +543,8 @@ begin begin colorSel := PGtkColorSelection(PGtkColorSelectionDialog(FPointer)^.colorsel); 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); {$IFDEF VerboseColorDialog} DebugLn('gtkDialogOKclickedCB ',DbgS(TColorDialog(theDialog).Color)); @@ -1278,16 +1281,24 @@ end; class procedure TGtk2WSCommonDialog.ShowModal(const ACommonDialog: TCommonDialog); var GtkWindow: PGtkWindow; + colorsel: PGtkColorSelection; + ColorDialog: TColorDialog; + CurrentAlpha: Word; begin ReleaseMouseCapture; GtkWindow:={%H-}PGtkWindow(ACommonDialog.Handle); gtk_window_set_title(GtkWindow,PChar(ACommonDialog.Title)); if ACommonDialog is TColorDialog then begin + ColorDialog := TColorDialog(ACommonDialog); SetColorDialogColor(PGtkColorSelectionDialog(GtkWindow), - TColorDialog(ACommonDialog).Color); + ColorDialog.Color); 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; gtk_window_set_position(GtkWindow, GTK_WIN_POS_CENTER);