background: Better handling of colours and gradients
Implement gradients, make sure that selecting one particular gradient or solid colour doesn't overwrite the previous one.
This commit is contained in:
parent
f0e4595d9b
commit
2365e47228
3 changed files with 109 additions and 55 deletions
|
@ -160,7 +160,7 @@
|
|||
<property name="visible">True</property>
|
||||
<property name="spacing">12</property>
|
||||
<child>
|
||||
<object class="GtkColorButton" id="style-color">
|
||||
<object class="GtkColorButton" id="style-pcolor">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
|
@ -171,6 +171,18 @@
|
|||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkColorButton" id="style-scolor">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="color">#000000000000</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkComboBox" id="style-combobox">
|
||||
<property name="visible">True</property>
|
||||
|
@ -185,7 +197,7 @@
|
|||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="position">1</property>
|
||||
<property name="position">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
|
|
|
@ -37,63 +37,47 @@ bg_colors_source_class_init (BgColorsSourceClass *klass)
|
|||
{
|
||||
}
|
||||
|
||||
static gchar *colors[] =
|
||||
{
|
||||
"#c4a000",
|
||||
"#ce5c00",
|
||||
"#8f5902",
|
||||
"#4e9a06",
|
||||
"#204a87",
|
||||
"#5c3566",
|
||||
"#a40000",
|
||||
"#babdb6",
|
||||
"#2e3436",
|
||||
"#000000",
|
||||
NULL
|
||||
struct {
|
||||
const char *name;
|
||||
GDesktopBackgroundShading type;
|
||||
} items[] = {
|
||||
{ N_("Horizontal Gradient"), G_DESKTOP_BACKGROUND_SHADING_HORIZONTAL },
|
||||
{ N_("Vertical Gradient"), G_DESKTOP_BACKGROUND_SHADING_VERTICAL },
|
||||
{ N_("Solid Color"), G_DESKTOP_BACKGROUND_SHADING_SOLID },
|
||||
};
|
||||
|
||||
static gchar *color_names[] =
|
||||
{
|
||||
N_("Butter"),
|
||||
N_("Orange"),
|
||||
N_("Chocolate"),
|
||||
N_("Chameleon"),
|
||||
N_("Blue"),
|
||||
N_("Plum"),
|
||||
N_("Red"),
|
||||
N_("Aluminium"),
|
||||
N_("Gray"),
|
||||
N_("Black"),
|
||||
NULL
|
||||
};
|
||||
#define PCOLOR "#023c88"
|
||||
#define SCOLOR "#5789ca"
|
||||
|
||||
static void
|
||||
bg_colors_source_init (BgColorsSource *self)
|
||||
{
|
||||
GnomeDesktopThumbnailFactory *thumb_factory;
|
||||
gchar **c, **n;
|
||||
guint i;
|
||||
GtkListStore *store;
|
||||
GdkColor pcolor, scolor;
|
||||
|
||||
store = bg_source_get_liststore (BG_SOURCE (self));
|
||||
|
||||
thumb_factory = gnome_desktop_thumbnail_factory_new (GNOME_DESKTOP_THUMBNAIL_SIZE_NORMAL);
|
||||
|
||||
for (c = colors, n = color_names; *c; c++, n++)
|
||||
gdk_color_parse (PCOLOR, &pcolor);
|
||||
gdk_color_parse (SCOLOR, &scolor);
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS (items); i++)
|
||||
{
|
||||
GnomeWPItem *item;
|
||||
GIcon *pixbuf;
|
||||
GdkColor color;
|
||||
|
||||
item = g_new0 (GnomeWPItem, 1);
|
||||
|
||||
item->filename = g_strdup ("(none)");
|
||||
item->name = g_strdup (_(*n));
|
||||
item->name = g_strdup (_(items[i].name));
|
||||
|
||||
gdk_color_parse (*c, &color);
|
||||
item->pcolor = gdk_color_copy (&color);
|
||||
item->scolor = gdk_color_copy (&color);
|
||||
item->pcolor = gdk_color_copy (&pcolor);
|
||||
item->scolor = gdk_color_copy (&scolor);
|
||||
|
||||
item->shade_type = G_DESKTOP_BACKGROUND_SHADING_SOLID;
|
||||
item->shade_type = items[i].type;
|
||||
|
||||
gnome_wp_item_ensure_gnome_bg (item);
|
||||
|
||||
|
|
|
@ -67,6 +67,7 @@ struct _CcBackgroundPanelPrivate
|
|||
|
||||
GnomeWPItem *current_background;
|
||||
gboolean current_source_readonly;
|
||||
gint current_source;
|
||||
|
||||
GCancellable *copy_cancellable;
|
||||
|
||||
|
@ -223,6 +224,37 @@ cc_background_panel_class_finalize (CcBackgroundPanelClass *klass)
|
|||
|
||||
}
|
||||
|
||||
static void
|
||||
source_update_edit_box (CcBackgroundPanelPrivate *priv)
|
||||
{
|
||||
if (priv->current_source == SOURCE_COLORS)
|
||||
{
|
||||
gtk_widget_hide (WID ("style-combobox"));
|
||||
gtk_widget_show (WID ("style-pcolor"));
|
||||
|
||||
if (priv->current_background &&
|
||||
priv->current_background->shade_type == G_DESKTOP_BACKGROUND_SHADING_SOLID)
|
||||
gtk_widget_hide (WID ("style-scolor"));
|
||||
else
|
||||
gtk_widget_show (WID ("style-scolor"));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!priv->current_source_readonly)
|
||||
{
|
||||
gtk_widget_show (WID ("style-pcolor"));
|
||||
gtk_widget_hide (WID ("style-scolor"));
|
||||
gtk_widget_show (WID ("style-combobox"));
|
||||
}
|
||||
else
|
||||
{
|
||||
gtk_widget_hide (WID ("style-pcolor"));
|
||||
gtk_widget_hide (WID ("style-scolor"));
|
||||
gtk_widget_hide (WID ("style-combobox"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
source_changed_cb (GtkComboBox *combo,
|
||||
CcBackgroundPanelPrivate *priv)
|
||||
|
@ -340,11 +372,7 @@ update_preview (CcBackgroundPanelPrivate *priv,
|
|||
gnome_wp_item_update_size (priv->current_background, priv->thumb_factory);
|
||||
}
|
||||
|
||||
|
||||
if (!priv->current_source_readonly)
|
||||
gtk_widget_show (WID ("edit-hbox"));
|
||||
else
|
||||
gtk_widget_hide (WID ("edit-hbox"));
|
||||
source_update_edit_box (priv);
|
||||
|
||||
changes_with_time = FALSE;
|
||||
|
||||
|
@ -356,8 +384,10 @@ update_preview (CcBackgroundPanelPrivate *priv,
|
|||
|
||||
gtk_label_set_text (GTK_LABEL (WID ("size_label")), priv->current_background->size);
|
||||
|
||||
gtk_color_button_set_color (GTK_COLOR_BUTTON (WID ("style-color")),
|
||||
gtk_color_button_set_color (GTK_COLOR_BUTTON (WID ("style-pcolor")),
|
||||
priv->current_background->pcolor);
|
||||
gtk_color_button_set_color (GTK_COLOR_BUTTON (WID ("style-scolor")),
|
||||
priv->current_background->scolor);
|
||||
|
||||
select_style (GTK_COMBO_BOX (WID ("style-combobox")),
|
||||
priv->current_background->options);
|
||||
|
@ -395,8 +425,9 @@ backgrounds_changed_cb (GtkIconView *icon_view,
|
|||
model = gtk_combo_box_get_model (GTK_COMBO_BOX (WID ("sources-combobox")));
|
||||
gtk_combo_box_get_active_iter (GTK_COMBO_BOX (WID ("sources-combobox")),
|
||||
&iter);
|
||||
gtk_tree_model_get (model, &iter, COL_SOURCE_READONLY, &priv->current_source_readonly, -1);
|
||||
|
||||
gtk_tree_model_get (model, &iter,
|
||||
COL_SOURCE_READONLY, &priv->current_source_readonly,
|
||||
COL_SOURCE_TYPE, &priv->current_source, -1);
|
||||
|
||||
model = gtk_icon_view_get_model (icon_view);
|
||||
|
||||
|
@ -495,10 +526,23 @@ backgrounds_changed_cb (GtkIconView *icon_view,
|
|||
|
||||
g_settings_set_enum (priv->settings, WP_SHADING_KEY, item->shade_type);
|
||||
|
||||
/* When changing for another colour, don't overwrite what's
|
||||
* in GSettings, but read from it instead */
|
||||
if (priv->current_source == SOURCE_COLORS)
|
||||
{
|
||||
pcolor = g_settings_get_string (priv->settings, WP_PCOLOR_KEY);
|
||||
scolor = g_settings_get_string (priv->settings, WP_SCOLOR_KEY);
|
||||
gdk_color_parse (pcolor, item->pcolor);
|
||||
gdk_color_parse (scolor, item->scolor);
|
||||
}
|
||||
else
|
||||
{
|
||||
pcolor = gdk_color_to_string (item->pcolor);
|
||||
scolor = gdk_color_to_string (item->scolor);
|
||||
g_settings_set_string (priv->settings, WP_PCOLOR_KEY, pcolor);
|
||||
g_settings_set_string (priv->settings, WP_SCOLOR_KEY, scolor);
|
||||
}
|
||||
|
||||
g_free (pcolor);
|
||||
g_free (scolor);
|
||||
|
||||
|
@ -616,15 +660,25 @@ color_changed_cb (GtkColorButton *button,
|
|||
CcBackgroundPanelPrivate *priv = panel->priv;
|
||||
GdkColor color;
|
||||
gchar *value;
|
||||
gboolean is_pcolor = FALSE;
|
||||
|
||||
gtk_color_button_get_color (button, &color);
|
||||
if (WID ("style-pcolor") == GTK_WIDGET (button))
|
||||
is_pcolor = TRUE;
|
||||
|
||||
if (priv->current_background)
|
||||
{
|
||||
if (is_pcolor)
|
||||
*priv->current_background->pcolor = color;
|
||||
else
|
||||
*priv->current_background->scolor = color;
|
||||
}
|
||||
|
||||
value = gdk_color_to_string (&color);
|
||||
|
||||
if (is_pcolor)
|
||||
g_settings_set_string (priv->settings, WP_PCOLOR_KEY, value);
|
||||
else
|
||||
g_settings_set_string (priv->settings, WP_SCOLOR_KEY, value);
|
||||
|
||||
g_free (value);
|
||||
|
@ -681,9 +735,9 @@ cc_background_panel_init (CcBackgroundPanel *self)
|
|||
|
||||
priv->colors_source = bg_colors_source_new ();
|
||||
gtk_list_store_insert_with_values (store, NULL, G_MAXINT,
|
||||
COL_SOURCE_NAME, _("Colors"),
|
||||
COL_SOURCE_NAME, _("Colors & Gradients"),
|
||||
COL_SOURCE_TYPE, SOURCE_COLORS,
|
||||
COL_SOURCE_READONLY, TRUE,
|
||||
COL_SOURCE_READONLY, FALSE,
|
||||
COL_SOURCE, priv->colors_source,
|
||||
-1);
|
||||
|
||||
|
@ -732,7 +786,9 @@ cc_background_panel_init (CcBackgroundPanel *self)
|
|||
g_signal_connect (WID ("style-combobox"), "changed",
|
||||
G_CALLBACK (style_changed_cb), self);
|
||||
|
||||
g_signal_connect (WID ("style-color"), "color-set",
|
||||
g_signal_connect (WID ("style-pcolor"), "color-set",
|
||||
G_CALLBACK (color_changed_cb), self);
|
||||
g_signal_connect (WID ("style-scolor"), "color-set",
|
||||
G_CALLBACK (color_changed_cb), self);
|
||||
|
||||
priv->copy_cancellable = g_cancellable_new ();
|
||||
|
@ -755,6 +811,8 @@ cc_background_panel_init (CcBackgroundPanel *self)
|
|||
gnome_wp_item_ensure_gnome_bg (priv->current_background);
|
||||
gnome_wp_item_update_size (priv->current_background, priv->thumb_factory);
|
||||
|
||||
/* FIXME hide the edit box as appropriate for the current background */
|
||||
|
||||
update_preview (priv, NULL, TRUE);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue