background: Add "swap" button for gradients

https://bugzilla.gnome.org/show_bug.cgi?id=34498
This commit is contained in:
Bastien Nocera 2011-07-14 16:38:22 +01:00
parent 2066d456ab
commit dd1b9d8336
2 changed files with 64 additions and 2 deletions

View file

@ -241,11 +241,18 @@
</packing>
</child>
<child>
<object class="GtkColorButton" id="style-scolor">
<object class="GtkButton" id="swap-color-button">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="color">#000000000000</property>
<property name="use_action_appearance">False</property>
<child>
<object class="GtkImage" id="image1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon_name">object-flip-horizontal-symbolic</property>
</object>
</child>
</object>
<packing>
<property name="expand">False</property>
@ -269,6 +276,20 @@
<property name="expand">False</property>
<property name="fill">False</property>
<property name="pack_type">end</property>
<property name="position">3</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="use_action_appearance">False</property>
<property name="color">#000000000000</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">2</property>
</packing>
</child>

View file

@ -250,6 +250,12 @@ source_update_edit_box (CcBackgroundPanelPrivate *priv,
else
gtk_widget_show (WID ("style-pcolor"));
if (gtk_widget_get_visible (WID ("style-pcolor")) &&
gtk_widget_get_visible (WID ("style-scolor")))
gtk_widget_show (WID ("swap-color-button"));
else
gtk_widget_hide (WID ("swap-color-button"));
if (flags & CC_BACKGROUND_ITEM_HAS_PLACEMENT ||
cc_background_item_get_uri (priv->current_background) == NULL)
gtk_widget_hide (WID ("style-combobox"));
@ -813,6 +819,39 @@ color_changed_cb (GtkColorButton *button,
update_preview (priv, NULL);
}
static void
swap_colors_clicked (GtkButton *button,
CcBackgroundPanel *panel)
{
CcBackgroundPanelPrivate *priv = panel->priv;
GdkColor pcolor, scolor;
char *new_pcolor, *new_scolor;
gtk_color_button_get_color (GTK_COLOR_BUTTON (WID ("style-pcolor")), &pcolor);
gtk_color_button_get_color (GTK_COLOR_BUTTON (WID ("style-scolor")), &scolor);
gtk_color_button_set_color (GTK_COLOR_BUTTON (WID ("style-scolor")), &pcolor);
gtk_color_button_set_color (GTK_COLOR_BUTTON (WID ("style-pcolor")), &scolor);
new_pcolor = gdk_color_to_string (&scolor);
new_scolor = gdk_color_to_string (&pcolor);
g_object_set (priv->current_background,
"primary-color", new_pcolor,
"secondary-color", new_scolor,
NULL);
g_settings_set_string (priv->settings, WP_PCOLOR_KEY, new_pcolor);
g_settings_set_string (priv->settings, WP_SCOLOR_KEY, new_scolor);
g_free (new_pcolor);
g_free (new_scolor);
g_settings_apply (priv->settings);
update_preview (priv, NULL);
}
static void
row_inserted (GtkTreeModel *tree_model,
GtkTreePath *path,
@ -1216,6 +1255,8 @@ cc_background_panel_init (CcBackgroundPanel *self)
G_CALLBACK (color_changed_cb), self);
g_signal_connect (WID ("style-scolor"), "color-set",
G_CALLBACK (color_changed_cb), self);
g_signal_connect (WID ("swap-color-button"), "clicked",
G_CALLBACK (swap_colors_clicked), self);
priv->copy_cancellable = g_cancellable_new ();