libgimpconfig: Retain color scale preferences

RGB 0..255/0..100 and LCh/HSV settings are now remembered when closing
and reopening GIMP.
This commit is contained in:
Alx Sa 2023-01-19 02:35:10 +00:00
parent b9448777e7
commit a8777a7374
2 changed files with 87 additions and 19 deletions

View File

@ -110,6 +110,13 @@
#define OUT_OF_GAMUT_COLOR_BLURB \
_("The color to use for marking colors which are out of gamut.")
#define SHOW_RGB_U8_BLURB \
_("When enabled, set the color scales to display 0...255 instead " \
"of percentages")
#define SHOW_HSV_BLURB \
_("When enabled, set the color scales to display HSV blend mode instead " \
"of LCh")
enum
{
@ -129,6 +136,8 @@ enum
PROP_SIMULATION_OPTIMIZE,
PROP_SIMULATION_GAMUT_CHECK,
PROP_OUT_OF_GAMUT_COLOR,
PROP_SHOW_RGB_U8,
PROP_SHOW_HSV,
PROP_DISPLAY_MODULE
};
@ -139,6 +148,9 @@ struct _GimpColorConfigPrivate
{
gboolean display_optimize;
gboolean simulation_optimize;
gboolean show_rgb_u8;
gboolean show_hsv;
};
#define GET_PRIVATE(obj) \
@ -302,6 +314,20 @@ gimp_color_config_class_init (GimpColorConfigClass *klass)
FALSE, &color,
GIMP_PARAM_STATIC_STRINGS);
GIMP_CONFIG_PROP_BOOLEAN (object_class, PROP_SHOW_RGB_U8,
"show-rgb-u8",
"Show RGB 0..255",
_("Show RGB 0..255 scales"),
FALSE,
GIMP_PARAM_STATIC_STRINGS);
GIMP_CONFIG_PROP_BOOLEAN (object_class, PROP_SHOW_HSV,
"show-hsv",
"Show HSV",
_("Show HSV instead of LCH"),
FALSE,
GIMP_PARAM_STATIC_STRINGS);
GIMP_CONFIG_PROP_STRING (object_class, PROP_DISPLAY_MODULE,
"display-module",
"Display module",
@ -408,6 +434,12 @@ gimp_color_config_set_property (GObject *object,
case PROP_OUT_OF_GAMUT_COLOR:
color_config->out_of_gamut_color = *(GimpRGB *) g_value_get_boxed (value);
break;
case PROP_SHOW_RGB_U8:
priv->show_rgb_u8 = g_value_get_boolean (value);
break;
case PROP_SHOW_HSV:
priv->show_hsv = g_value_get_boolean (value);
break;
case PROP_DISPLAY_MODULE:
g_free (color_config->display_module);
color_config->display_module = g_value_dup_string (value);
@ -481,6 +513,12 @@ gimp_color_config_get_property (GObject *object,
case PROP_OUT_OF_GAMUT_COLOR:
g_value_set_boxed (value, &color_config->out_of_gamut_color);
break;
case PROP_SHOW_RGB_U8:
g_value_set_boolean (value, priv->show_rgb_u8);
break;
case PROP_SHOW_HSV:
g_value_set_boolean (value, priv->show_hsv);
break;
case PROP_DISPLAY_MODULE:
g_value_set_string (value, color_config->display_module);
break;

View File

@ -56,7 +56,8 @@
enum
{
PROP_0,
PROP_SHOW_RGB_U8
PROP_SHOW_RGB_U8,
PROP_SHOW_HSV
};
enum
@ -220,6 +221,13 @@ gimp_color_scales_class_init (GimpColorScalesClass *klass)
FALSE,
GIMP_PARAM_READWRITE |
G_PARAM_CONSTRUCT));
g_object_class_install_property (object_class, PROP_SHOW_HSV,
g_param_spec_boolean ("show-hsv",
"Show HSV",
"Show HSV instead of LCH",
FALSE,
GIMP_PARAM_READWRITE |
G_PARAM_CONSTRUCT));
fish_rgb_to_lch = babl_fish (babl_format ("R'G'B'A double"),
babl_format ("CIE LCH(ab) alpha double"));
@ -474,6 +482,11 @@ gimp_color_scales_init (GimpColorScales *scales)
GIMP_COLOR_SELECTOR_MODEL_HSV))
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio2), TRUE);
g_object_bind_property (G_OBJECT (radio2), "active",
G_OBJECT (scales), "show-hsv",
G_BINDING_SYNC_CREATE |
G_BINDING_BIDIRECTIONAL);
g_signal_connect (radio1, "toggled",
G_CALLBACK (gimp_color_scales_toggle_lch_hsv),
scales);
@ -496,12 +509,18 @@ gimp_color_scales_get_property (GObject *object,
GParamSpec *pspec)
{
GimpColorScales *scales = GIMP_COLOR_SCALES (object);
gboolean hsv;
switch (property_id)
{
case PROP_SHOW_RGB_U8:
g_value_set_boolean (value, scales->show_rgb_u8);
break;
case PROP_SHOW_HSV:
hsv = gimp_color_selector_get_model_visible (GIMP_COLOR_SELECTOR (object),
GIMP_COLOR_SELECTOR_MODEL_HSV);
g_value_set_boolean (value, hsv);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@ -516,12 +535,23 @@ gimp_color_scales_set_property (GObject *object,
GParamSpec *pspec)
{
GimpColorScales *scales = GIMP_COLOR_SCALES (object);
gboolean show_hsv;
switch (property_id)
{
case PROP_SHOW_RGB_U8:
gimp_color_scales_set_show_rgb_u8 (scales, g_value_get_boolean (value));
break;
case PROP_SHOW_HSV:
show_hsv = g_value_get_boolean (value);
gimp_color_selector_set_model_visible (GIMP_COLOR_SELECTOR (object),
GIMP_COLOR_SELECTOR_MODEL_LCH,
! show_hsv);
gimp_color_selector_set_model_visible (GIMP_COLOR_SELECTOR (object),
GIMP_COLOR_SELECTOR_MODEL_HSV,
show_hsv);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@ -606,6 +636,16 @@ gimp_color_scales_set_config (GimpColorSelector *selector,
GimpColorScales *scales = GIMP_COLOR_SCALES (selector);
gint i;
if (config)
{
g_object_bind_property (config, "show-rgb-u8",
scales, "show-rgb-u8",
G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
g_object_bind_property (config, "show-hsv",
scales, "show-hsv",
G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
}
for (i = 0; i < G_N_ELEMENTS (scale_defs); i++)
{
if (scales->scales[i])
@ -862,23 +902,13 @@ gimp_color_scales_toggle_lch_hsv (GtkToggleButton *toggle,
GimpColorScales *scales)
{
GimpColorSelector *selector = GIMP_COLOR_SELECTOR (scales);
gboolean show_hsv = ! gtk_toggle_button_get_active (toggle);
if (gtk_toggle_button_get_active (toggle))
{
gimp_color_selector_set_model_visible (selector,
GIMP_COLOR_SELECTOR_MODEL_LCH,
TRUE);
gimp_color_selector_set_model_visible (selector,
GIMP_COLOR_SELECTOR_MODEL_HSV,
FALSE);
}
else
{
gimp_color_selector_set_model_visible (selector,
GIMP_COLOR_SELECTOR_MODEL_LCH,
FALSE);
gimp_color_selector_set_model_visible (selector,
GIMP_COLOR_SELECTOR_MODEL_HSV,
TRUE);
}
gimp_color_selector_set_model_visible (selector,
GIMP_COLOR_SELECTOR_MODEL_LCH,
! show_hsv);
gimp_color_selector_set_model_visible (selector,
GIMP_COLOR_SELECTOR_MODEL_HSV,
show_hsv);
g_object_set (scales, "show-hsv", show_hsv, NULL);
}