widgets: Allow color dialogues to not match the image mode

For some GUI elements, we may not want to restrict
the color options to the image mode (for instance,
grid colors on a grayscale or indexed image).

This patch adds a "user_context_aware" boolean
to GimpColorPanel so it can be passed on to set
the same boolean already in GimpColorDialog.
This allows GUI elements like GimpGridEditor to
optionally give full color choices to users,
independent of the image mode.
This commit is contained in:
Alx Sa 2025-05-10 14:18:41 +00:00
parent 2f7209482b
commit 258344031c
3 changed files with 24 additions and 3 deletions

View file

@ -101,8 +101,9 @@ gimp_color_panel_class_init (GimpColorPanelClass *klass)
static void
gimp_color_panel_init (GimpColorPanel *panel)
{
panel->context = NULL;
panel->color_dialog = NULL;
panel->context = NULL;
panel->color_dialog = NULL;
panel->user_context_aware = TRUE;
}
static void
@ -183,7 +184,8 @@ gimp_color_panel_clicked (GtkButton *button)
GimpColorButton *color_button = GIMP_COLOR_BUTTON (button);
panel->color_dialog =
gimp_color_dialog_new (NULL, panel->context, TRUE,
gimp_color_dialog_new (NULL, panel->context,
panel->user_context_aware,
gimp_color_button_get_title (color_button),
NULL, NULL,
GTK_WIDGET (button),
@ -275,6 +277,15 @@ gimp_color_panel_set_context (GimpColorPanel *panel,
context->gimp->config->color_management);
}
void
gimp_color_panel_set_user_context_aware (GimpColorPanel *panel,
gboolean user_context_aware)
{
g_return_if_fail (GIMP_IS_COLOR_PANEL (panel));
panel->user_context_aware = user_context_aware;
}
void
gimp_color_panel_dialog_response (GimpColorPanel *panel,
GimpColorDialogState state)

View file

@ -35,6 +35,8 @@ struct _GimpColorPanel
GimpContext *context;
GtkWidget *color_dialog;
gboolean user_context_aware;
};
struct _GimpColorPanelClass
@ -58,6 +60,10 @@ GtkWidget * gimp_color_panel_new (const gchar *title,
void gimp_color_panel_set_context (GimpColorPanel *panel,
GimpContext *context);
void gimp_color_panel_set_user_context_aware
(GimpColorPanel *panel,
gboolean user_context_aware);
void gimp_color_panel_dialog_response (GimpColorPanel *panel,
GimpColorDialogState state);

View file

@ -154,6 +154,8 @@ gimp_grid_editor_constructed (GObject *object)
gtk_widget_set_halign (color_button, GTK_ALIGN_START);
gimp_color_panel_set_context (GIMP_COLOR_PANEL (color_button),
editor->context);
gimp_color_panel_set_user_context_aware (GIMP_COLOR_PANEL (color_button),
FALSE);
gimp_grid_attach_aligned (GTK_GRID (grid), 0, 1,
_("_Foreground color:"), 0.0, 0.5,
color_button, 1);
@ -166,6 +168,8 @@ gimp_grid_editor_constructed (GObject *object)
gtk_widget_set_halign (color_button, GTK_ALIGN_START);
gimp_color_panel_set_context (GIMP_COLOR_PANEL (color_button),
editor->context);
gimp_color_panel_set_user_context_aware (GIMP_COLOR_PANEL (color_button),
FALSE);
gimp_grid_attach_aligned (GTK_GRID (grid), 0, 2,
_("_Background color:"), 0.0, 0.5,
color_button, 1);