[gtk+] widget-factory: Add a color editor example
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] widget-factory: Add a color editor example
- Date: Sun, 24 Jan 2016 03:31:45 +0000 (UTC)
commit 873a024f5b4060568e05cd998de815ff4d8a6412
Author: Matthias Clasen <mclasen redhat com>
Date: Sat Jan 23 22:30:59 2016 -0500
widget-factory: Add a color editor example
demos/widget-factory/widget-factory.c | 40 ++++++++++++++++++++++++++++++-
demos/widget-factory/widget-factory.ui | 5 +--
2 files changed, 40 insertions(+), 5 deletions(-)
---
diff --git a/demos/widget-factory/widget-factory.c b/demos/widget-factory/widget-factory.c
index 34a307a..84eb846 100644
--- a/demos/widget-factory/widget-factory.c
+++ b/demos/widget-factory/widget-factory.c
@@ -786,10 +786,39 @@ overshot (GtkScrolledWindow *sw, GtkPositionType pos, GtkWidget *widget)
row = gtk_widget_get_parent (row);
gtk_list_box_row_set_activatable (GTK_LIST_BOX_ROW (row), FALSE);
g_object_set_data (G_OBJECT (widget), color, row);
+ g_object_set_data (G_OBJECT (row), "color", (gpointer)color);
}
static void
-populate_colors (GtkWidget *widget)
+rgba_changed (GtkColorChooser *chooser, GParamSpec *pspec, GtkListBox *box)
+{
+ gtk_list_box_select_row (box, NULL);
+}
+
+static void
+set_color (GtkListBox *box, GtkListBoxRow *row, GtkColorChooser *chooser)
+{
+ const char *color;
+ GdkRGBA rgba;
+
+ if (!row)
+ return;
+
+ color = (const char *)g_object_get_data (G_OBJECT (row), "color");
+
+ if (!color)
+ return;
+
+ if (gdk_rgba_parse (&rgba, color))
+ {
+ g_signal_handlers_block_by_func (chooser, rgba_changed, box);
+ gtk_color_chooser_set_rgba (chooser, &rgba);
+ g_signal_handlers_unblock_by_func (chooser, rgba_changed, box);
+ }
+}
+
+static void
+populate_colors (GtkWidget *widget, GtkWidget *chooser)
{
struct { const gchar *name; const gchar *color; const gchar *title; } colors[] = {
{ "2.5", "#C8828C", "Red" },
@@ -867,10 +896,13 @@ populate_colors (GtkWidget *widget)
gtk_list_box_insert (GTK_LIST_BOX (widget), row, -1);
row = gtk_widget_get_parent (row);
gtk_list_box_row_set_activatable (GTK_LIST_BOX_ROW (row), FALSE);
+ g_object_set_data (G_OBJECT (row), "color", (gpointer)colors[i].color);
if (colors[i].title)
g_object_set_data (G_OBJECT (row), "title", (gpointer)colors[i].title);
}
+ g_signal_connect (widget, "row-selected", G_CALLBACK (set_color), chooser);
+
gtk_list_box_invalidate_headers (GTK_LIST_BOX (widget));
sw = gtk_widget_get_ancestor (widget, GTK_TYPE_SCROLLED_WINDOW);
@@ -1626,7 +1658,11 @@ activate (GApplication *app)
gtk_tree_view_set_row_separator_func (GTK_TREE_VIEW (widget), row_separator_func, NULL, NULL);
gtk_tree_view_expand_all (GTK_TREE_VIEW (widget));
- populate_colors ((GtkWidget *)gtk_builder_get_object (builder, "munsell"));
+ widget = GTK_WIDGET (gtk_builder_get_object (builder, "munsell"));
+ widget2 = GTK_WIDGET (gtk_builder_get_object (builder, "cchooser"));
+
+ populate_colors (widget, widget2);
+ g_signal_connect (widget2, "notify::rgba", G_CALLBACK (rgba_changed), widget);
widget = (GtkWidget *)gtk_builder_get_object (builder, "page_combo");
gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (widget), page_combo_separator_func, NULL, NULL);
diff --git a/demos/widget-factory/widget-factory.ui b/demos/widget-factory/widget-factory.ui
index 07a6ade..13931bb 100644
--- a/demos/widget-factory/widget-factory.ui
+++ b/demos/widget-factory/widget-factory.ui
@@ -3769,10 +3769,9 @@ microphone-sensitivity-medium-symbolic</property>
</object>
</child>
<child>
- <object class="GtkSpinner">
+ <object class="GtkColorChooserWidget" id="cchooser">
<property name="visible">1</property>
- <property name="active">1</property>
- <property name="expand">1</property>
+ <property name="show-editor">1</property>
</object>
</child>
</object>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]