[gimp] app: factor gimp_prop_widget_new() out of gimp_prop_table_new()
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] app: factor gimp_prop_widget_new() out of gimp_prop_table_new()
- Date: Tue, 27 May 2014 00:11:05 +0000 (UTC)
commit 5ffa278da57f979351fa8570738de39e4488d370
Author: Michael Natterer <mitch gimp org>
Date: Tue May 27 02:07:23 2014 +0200
app: factor gimp_prop_widget_new() out of gimp_prop_table_new()
The new function generically returns a widget for one property and is
used in gimp_prop_table_new().
app/widgets/gimpproptable.c | 482 +++++++++++++++++++++++--------------------
app/widgets/gimpproptable.h | 17 +-
2 files changed, 269 insertions(+), 230 deletions(-)
---
diff --git a/app/widgets/gimpproptable.c b/app/widgets/gimpproptable.c
index d3ddebf..1ffffd4 100644
--- a/app/widgets/gimpproptable.c
+++ b/app/widgets/gimpproptable.c
@@ -47,43 +47,228 @@
#include "gimp-intl.h"
-static void
-gimp_prop_table_chain_toggled (GimpChainButton *chain,
- GtkAdjustment *x_adj)
+#define HAS_KEY(p,k,v) gimp_gegl_param_spec_has_key (p, k, v)
+
+
+static void gimp_prop_widget_new_seed_clicked (GtkButton *button,
+ GtkAdjustment *adj);
+static void gimp_prop_table_chain_toggled (GimpChainButton *chain,
+ GtkAdjustment *x_adj);
+
+
+/* public functions */
+
+GtkWidget *
+gimp_prop_widget_new (GObject *config,
+ GParamSpec *pspec,
+ GimpContext *context,
+ GimpCreatePickerFunc create_picker_func,
+ gpointer picker_creator,
+ const gchar **label)
{
- GtkAdjustment *y_adj;
+ GtkWidget *widget = NULL;
- y_adj = g_object_get_data (G_OBJECT (x_adj), "y-adjustment");
+ g_return_val_if_fail (G_IS_OBJECT (config), NULL);
+ g_return_val_if_fail (g_type_is_a (G_OBJECT_TYPE (config), pspec->owner_type),
+ NULL);
+ g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
+ g_return_val_if_fail (label != NULL, NULL);
- if (gimp_chain_button_get_active (chain))
+ *label = NULL;
+
+ if (G_IS_PARAM_SPEC_INT (pspec) ||
+ G_IS_PARAM_SPEC_UINT (pspec) ||
+ G_IS_PARAM_SPEC_FLOAT (pspec) ||
+ G_IS_PARAM_SPEC_DOUBLE (pspec))
{
- GBinding *binding;
+ gdouble lower;
+ gdouble upper;
+ gdouble step;
+ gdouble page;
+ gint digits;
- binding = g_object_bind_property (x_adj, "value",
- y_adj, "value",
- G_BINDING_BIDIRECTIONAL);
+ if (GEGL_IS_PARAM_SPEC_DOUBLE (pspec))
+ {
+ GeglParamSpecDouble *gspec = GEGL_PARAM_SPEC_DOUBLE (pspec);
- g_object_set_data (G_OBJECT (chain), "binding", binding);
+ lower = gspec->ui_minimum;
+ upper = gspec->ui_maximum;
+ step = gspec->ui_step_small;
+ page = gspec->ui_step_big;
+ digits = gspec->ui_digits;
+ }
+ else if (GEGL_IS_PARAM_SPEC_INT (pspec))
+ {
+ GeglParamSpecInt *gspec = GEGL_PARAM_SPEC_INT (pspec);
+
+ lower = gspec->ui_minimum;
+ upper = gspec->ui_maximum;
+ step = gspec->ui_step_small;
+ page = gspec->ui_step_big;
+ digits = 0;
+ }
+ else
+ {
+ gdouble value;
+
+ _gimp_prop_widgets_get_numeric_values (config, pspec,
+ &value, &lower, &upper,
+ G_STRFUNC);
+
+ if ((upper - lower <= 1.0) &&
+ (G_IS_PARAM_SPEC_FLOAT (pspec) ||
+ G_IS_PARAM_SPEC_DOUBLE (pspec)))
+ {
+ step = 0.01;
+ page = 0.1;
+ digits = 4;
+ }
+ else if ((upper - lower <= 10.0) &&
+ (G_IS_PARAM_SPEC_FLOAT (pspec) ||
+ G_IS_PARAM_SPEC_DOUBLE (pspec)))
+ {
+ step = 0.1;
+ page = 1.0;
+ digits = 3;
+ }
+ else
+ {
+ step = 1.0;
+ page = 10.0;
+ digits = (G_IS_PARAM_SPEC_FLOAT (pspec) ||
+ G_IS_PARAM_SPEC_DOUBLE (pspec)) ? 2 : 0;
+ }
+ }
+
+ widget = gimp_prop_spin_scale_new (config, pspec->name,
+ g_param_spec_get_nick (pspec),
+ step, page, digits);
+
+ if (HAS_KEY (pspec, "unit", "degree") &&
+ (upper - lower) == 360.0)
+ {
+ GtkWidget *hbox;
+ GtkWidget *dial;
+
+ gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (widget), TRUE);
+
+ hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4);
+
+ gtk_box_pack_start (GTK_BOX (hbox), widget, TRUE, TRUE, 0);
+ gtk_widget_show (widget);
+
+ dial = gimp_prop_angle_dial_new (config, pspec->name);
+ gtk_box_pack_start (GTK_BOX (hbox), dial, FALSE, FALSE, 0);
+ gtk_widget_show (dial);
+
+ widget = hbox;
+ }
}
- else
+ else if (G_IS_PARAM_SPEC_STRING (pspec))
{
- GBinding *binding;
+ static GQuark multiline_quark = 0;
- binding = g_object_get_data (G_OBJECT (chain), "binding");
+ if (! multiline_quark)
+ multiline_quark = g_quark_from_static_string ("multiline");
- g_object_unref (binding);
- g_object_set_data (G_OBJECT (chain), "binding", NULL);
+ if (GIMP_IS_PARAM_SPEC_CONFIG_PATH (pspec))
+ {
+ widget = gimp_prop_file_chooser_button_new (config,
+ pspec->name,
+ g_param_spec_get_nick (pspec),
+ GTK_FILE_CHOOSER_ACTION_OPEN);
+ }
+ else if (g_param_spec_get_qdata (pspec, multiline_quark))
+ {
+ GtkTextBuffer *buffer;
+ GtkWidget *view;
+
+ buffer = gimp_prop_text_buffer_new (config, pspec->name, -1);
+ view = gtk_text_view_new_with_buffer (buffer);
+
+ widget = gtk_scrolled_window_new (NULL, NULL);
+ gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (widget),
+ GTK_SHADOW_IN);
+ gtk_container_add (GTK_CONTAINER (widget), view);
+ gtk_widget_show (view);
+ }
+ else
+ {
+ widget = gimp_prop_entry_new (config, pspec->name, -1);
+ }
+
+ *label = g_param_spec_get_nick (pspec);
}
-}
+ else if (G_IS_PARAM_SPEC_BOOLEAN (pspec))
+ {
+ widget = gimp_prop_check_button_new (config, pspec->name,
+ g_param_spec_get_nick (pspec));
+ }
+ else if (G_IS_PARAM_SPEC_ENUM (pspec))
+ {
+ widget = gimp_prop_enum_combo_box_new (config, pspec->name, 0, 0);
+ gimp_int_combo_box_set_label (GIMP_INT_COMBO_BOX (widget),
+ g_param_spec_get_nick (pspec));
+ }
+ else if (GEGL_IS_PARAM_SPEC_SEED (pspec))
+ {
+ GtkAdjustment *adj;
+ GtkWidget *spin;
+ GtkWidget *button;
-static void
-gimp_prop_table_new_seed_clicked (GtkButton *button,
- GtkAdjustment *adj)
-{
- guint32 value = g_random_int_range (gtk_adjustment_get_lower (adj),
- gtk_adjustment_get_upper (adj));
+ widget = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4);
- gtk_adjustment_set_value (adj, value);
+ spin = gimp_prop_spin_button_new (config, pspec->name,
+ 1.0, 10.0, 0);
+ gtk_box_pack_start (GTK_BOX (widget), spin, TRUE, TRUE, 0);
+ gtk_widget_show (spin);
+
+ button = gtk_button_new_with_label (_("New Seed"));
+ gtk_box_pack_start (GTK_BOX (widget), button, FALSE, FALSE, 0);
+ gtk_widget_show (button);
+
+ adj = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (spin));
+
+ g_signal_connect (button, "clicked",
+ G_CALLBACK (gimp_prop_widget_new_seed_clicked),
+ adj);
+
+ *label = g_param_spec_get_nick (pspec);
+ }
+ else if (GIMP_IS_PARAM_SPEC_RGB (pspec))
+ {
+ GtkWidget *button;
+
+ widget = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4);
+
+ button = gimp_prop_color_button_new (config, pspec->name,
+ g_param_spec_get_nick (pspec),
+ 128, 24,
+ GIMP_COLOR_AREA_SMALL_CHECKS);
+ gimp_color_button_set_update (GIMP_COLOR_BUTTON (button), TRUE);
+ gimp_color_panel_set_context (GIMP_COLOR_PANEL (button), context);
+ gtk_box_pack_start (GTK_BOX (widget), button, TRUE, TRUE, 0);
+ gtk_widget_show (button);
+
+ if (create_picker_func)
+ {
+ button = create_picker_func (picker_creator,
+ pspec->name,
+ GIMP_STOCK_COLOR_PICKER_GRAY,
+ _("Pick color from the image"));
+ gtk_box_pack_start (GTK_BOX (widget), button, FALSE, FALSE, 0);
+ gtk_widget_show (button);
+ }
+
+ *label = g_param_spec_get_nick (pspec);
+ }
+ else
+ {
+ g_warning ("%s: not supported: %s (%s)\n", G_STRFUNC,
+ g_type_name (G_TYPE_FROM_INSTANCE (pspec)), pspec->name);
+ }
+
+ return widget;
}
GtkWidget *
@@ -94,7 +279,6 @@ gimp_prop_table_new (GObject *config,
gpointer picker_creator)
{
GtkWidget *table;
- GtkSizeGroup *size_group;
GParamSpec **param_specs;
guint n_param_specs;
gint i;
@@ -104,13 +288,11 @@ gimp_prop_table_new (GObject *config,
gint last_x_row = 0;
g_return_val_if_fail (G_IS_OBJECT (config), NULL);
- g_return_val_if_fail (context == NULL || GIMP_IS_CONTEXT (context), NULL);
+ g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
param_specs = g_object_class_list_properties (G_OBJECT_GET_CLASS (config),
&n_param_specs);
- size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
-
table = gtk_table_new (3, 1, FALSE);
gtk_table_set_col_spacings (GTK_TABLE (table), 4);
gtk_table_set_row_spacings (GTK_TABLE (table), 2);
@@ -125,178 +307,20 @@ gimp_prop_table_new (GObject *config,
if (! g_type_is_a (pspec->owner_type, owner_type))
continue;
-#define HAS_KEY(p,k,v) gimp_gegl_param_spec_has_key (p, k, v)
-
if (HAS_KEY (pspec, "role", "output-extent"))
continue;
- if (G_IS_PARAM_SPEC_STRING (pspec))
- {
- static GQuark multiline_quark = 0;
-
- if (! multiline_quark)
- multiline_quark = g_quark_from_static_string ("multiline");
-
- if (GIMP_IS_PARAM_SPEC_CONFIG_PATH (pspec))
- {
- widget = gimp_prop_file_chooser_button_new (config,
- pspec->name,
- g_param_spec_get_nick (pspec),
- GTK_FILE_CHOOSER_ACTION_OPEN);
- }
- else if (g_param_spec_get_qdata (pspec, multiline_quark))
- {
- GtkTextBuffer *buffer;
- GtkWidget *view;
-
- buffer = gimp_prop_text_buffer_new (config, pspec->name, -1);
- view = gtk_text_view_new_with_buffer (buffer);
-
- widget = gtk_scrolled_window_new (NULL, NULL);
- gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (widget),
- GTK_SHADOW_IN);
- gtk_container_add (GTK_CONTAINER (widget), view);
- gtk_widget_show (view);
- }
- else
- {
- widget = gimp_prop_entry_new (config, pspec->name, -1);
- }
-
- label = g_param_spec_get_nick (pspec);
- }
- else if (G_IS_PARAM_SPEC_BOOLEAN (pspec))
- {
- widget = gimp_prop_check_button_new (config, pspec->name,
- g_param_spec_get_nick (pspec));
- }
- else if (G_IS_PARAM_SPEC_ENUM (pspec))
- {
- widget = gimp_prop_enum_combo_box_new (config, pspec->name, 0, 0);
- gimp_int_combo_box_set_label (GIMP_INT_COMBO_BOX (widget),
- g_param_spec_get_nick (pspec));
- }
- else if (GEGL_IS_PARAM_SPEC_SEED (pspec))
- {
- GtkAdjustment *adj;
- GtkWidget *spin;
- GtkWidget *button;
-
- widget = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4);
-
- spin = gimp_prop_spin_button_new (config, pspec->name,
- 1.0, 10.0, 0);
- gtk_box_pack_start (GTK_BOX (widget), spin, TRUE, TRUE, 0);
- gtk_widget_show (spin);
-
- button = gtk_button_new_with_label (_("New Seed"));
- gtk_box_pack_start (GTK_BOX (widget), button, FALSE, FALSE, 0);
- gtk_widget_show (button);
-
- adj = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (spin));
-
- g_signal_connect (button, "clicked",
- G_CALLBACK (gimp_prop_table_new_seed_clicked),
- adj);
+ widget = gimp_prop_widget_new (config, pspec, context,
+ create_picker_func, picker_creator,
+ &label);
- label = g_param_spec_get_nick (pspec);
- }
- else if (G_IS_PARAM_SPEC_INT (pspec) ||
- G_IS_PARAM_SPEC_UINT (pspec) ||
- G_IS_PARAM_SPEC_FLOAT (pspec) ||
- G_IS_PARAM_SPEC_DOUBLE (pspec))
+ if (GTK_IS_SPIN_BUTTON (widget))
{
GtkAdjustment *adj;
- gdouble lower;
- gdouble upper;
- gdouble step;
- gdouble page;
- gint digits;
-
- if (GEGL_IS_PARAM_SPEC_DOUBLE (pspec))
- {
- GeglParamSpecDouble *gspec = GEGL_PARAM_SPEC_DOUBLE (pspec);
-
- lower = gspec->ui_minimum;
- upper = gspec->ui_maximum;
- }
- else if (GEGL_IS_PARAM_SPEC_INT (pspec))
- {
- GeglParamSpecInt *gspec = GEGL_PARAM_SPEC_INT (pspec);
-
- lower = gspec->ui_minimum;
- upper = gspec->ui_maximum;
- }
- else
- {
- gdouble value;
-
- _gimp_prop_widgets_get_numeric_values (config, pspec,
- &value, &lower, &upper,
- G_STRFUNC);
- }
-
- if (GEGL_IS_PARAM_SPEC_DOUBLE (pspec))
- {
- GeglParamSpecDouble *gspec = GEGL_PARAM_SPEC_DOUBLE (pspec);
-
- step = gspec->ui_step_small;
- page = gspec->ui_step_big;
- digits = gspec->ui_digits;
- }
- else if (GEGL_IS_PARAM_SPEC_INT (pspec))
- {
- GeglParamSpecInt *gspec = GEGL_PARAM_SPEC_INT (pspec);
-
- step = gspec->ui_step_small;
- page = gspec->ui_step_big;
- digits = 0;
- }
- else if ((upper - lower <= 1.0) &&
- (G_IS_PARAM_SPEC_FLOAT (pspec) ||
- G_IS_PARAM_SPEC_DOUBLE (pspec)))
- {
- step = 0.01;
- page = 0.1;
- digits = 4;
- }
- else if ((upper - lower <= 10.0) &&
- (G_IS_PARAM_SPEC_FLOAT (pspec) ||
- G_IS_PARAM_SPEC_DOUBLE (pspec)))
- {
- step = 0.1;
- page = 1.0;
- digits = 3;
- }
- else
- {
- step = 1.0;
- page = 10.0;
- digits = (G_IS_PARAM_SPEC_FLOAT (pspec) ||
- G_IS_PARAM_SPEC_DOUBLE (pspec)) ? 2 : 0;
- }
-
- widget = gimp_prop_spin_scale_new (config, pspec->name,
- g_param_spec_get_nick (pspec),
- step, page, digits);
adj = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (widget));
- if (HAS_KEY (pspec, "unit", "degree") &&
- (upper - lower) == 360.0)
- {
- GtkWidget *dial;
-
- gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (widget), TRUE);
-
- dial = gimp_prop_angle_dial_new (config, pspec->name);
- gtk_table_attach (GTK_TABLE (table), dial,
- 4, 5, row, row + 1,
- GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL,
- 0, 0);
- gtk_widget_show (dial);
- }
- else if (HAS_KEY (pspec, "axis", "x"))
+ if (HAS_KEY (pspec, "axis", "x"))
{
last_pspec = pspec;
last_x_adj = adj;
@@ -362,38 +386,6 @@ gimp_prop_table_new (GObject *config,
}
}
}
- else if (GIMP_IS_PARAM_SPEC_RGB (pspec))
- {
- GtkWidget *button;
-
- widget = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4);
-
- button = gimp_prop_color_button_new (config, pspec->name,
- g_param_spec_get_nick (pspec),
- 128, 24,
- GIMP_COLOR_AREA_SMALL_CHECKS);
- gimp_color_button_set_update (GIMP_COLOR_BUTTON (button), TRUE);
- gimp_color_panel_set_context (GIMP_COLOR_PANEL (button), context);
- gtk_box_pack_start (GTK_BOX (widget), button, TRUE, TRUE, 0);
- gtk_widget_show (button);
-
- if (create_picker_func)
- {
- button = create_picker_func (picker_creator,
- pspec->name,
- GIMP_STOCK_COLOR_PICKER_GRAY,
- _("Pick color from the image"));
- gtk_box_pack_start (GTK_BOX (widget), button, FALSE, FALSE, 0);
- gtk_widget_show (button);
- }
-
- label = g_param_spec_get_nick (pspec);
- }
- else
- {
- g_warning ("%s: not supported: %s (%s)\n", G_STRFUNC,
- g_type_name (G_TYPE_FROM_INSTANCE (pspec)), pspec->name);
- }
if (widget)
{
@@ -414,9 +406,49 @@ gimp_prop_table_new (GObject *config,
}
}
- g_object_unref (size_group);
-
g_free (param_specs);
return table;
}
+
+
+/* private functions */
+
+static void
+gimp_prop_widget_new_seed_clicked (GtkButton *button,
+ GtkAdjustment *adj)
+{
+ guint32 value = g_random_int_range (gtk_adjustment_get_lower (adj),
+ gtk_adjustment_get_upper (adj));
+
+ gtk_adjustment_set_value (adj, value);
+}
+
+static void
+gimp_prop_table_chain_toggled (GimpChainButton *chain,
+ GtkAdjustment *x_adj)
+{
+ GtkAdjustment *y_adj;
+
+ y_adj = g_object_get_data (G_OBJECT (x_adj), "y-adjustment");
+
+ if (gimp_chain_button_get_active (chain))
+ {
+ GBinding *binding;
+
+ binding = g_object_bind_property (x_adj, "value",
+ y_adj, "value",
+ G_BINDING_BIDIRECTIONAL);
+
+ g_object_set_data (G_OBJECT (chain), "binding", binding);
+ }
+ else
+ {
+ GBinding *binding;
+
+ binding = g_object_get_data (G_OBJECT (chain), "binding");
+
+ g_object_unref (binding);
+ g_object_set_data (G_OBJECT (chain), "binding", NULL);
+ }
+}
diff --git a/app/widgets/gimpproptable.h b/app/widgets/gimpproptable.h
index 16d3a76..5f0c25b 100644
--- a/app/widgets/gimpproptable.h
+++ b/app/widgets/gimpproptable.h
@@ -29,11 +29,18 @@ typedef GtkWidget * (* GimpCreatePickerFunc) (gpointer creator,
const gchar *icon_name,
const gchar *tooltip);
-GtkWidget * gimp_prop_table_new (GObject *config,
- GType owner_type,
- GimpContext *context,
- GimpCreatePickerFunc create_picker_func,
- gpointer picker_creator);
+GtkWidget * gimp_prop_widget_new (GObject *config,
+ GParamSpec *pspec,
+ GimpContext *context,
+ GimpCreatePickerFunc create_picker_func,
+ gpointer picker_creator,
+ const gchar **label);
+GtkWidget * gimp_prop_table_new (GObject *config,
+ GType owner_type,
+ GimpContext *context,
+ GimpCreatePickerFunc create_picker_func,
+ gpointer picker_creator);
+
#endif /* __GIMP_PROP_TABLE_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]