[gimp] libgimp: new gimp_procedure_dialog_get_scale_entry() function.



commit 87062e22ecdf5eba0e037c64d1a1ced8aef2c9e8
Author: Jehan <jehan girinstud io>
Date:   Wed Nov 25 12:25:59 2020 +0100

    libgimp: new gimp_procedure_dialog_get_scale_entry() function.
    
    Though a GimpScaleEntry could already be created with
    gimp_procedure_dialog_get_widget(), this specific function allows to add
    a factor to the property range.

 libgimp/gimpproceduredialog.c | 65 +++++++++++++++++++++++++++++++++++++++++++
 libgimp/gimpproceduredialog.h |  3 ++
 2 files changed, 68 insertions(+)
---
diff --git a/libgimp/gimpproceduredialog.c b/libgimp/gimpproceduredialog.c
index 74c0bbf43d..54f09ea0ed 100644
--- a/libgimp/gimpproceduredialog.c
+++ b/libgimp/gimpproceduredialog.c
@@ -600,6 +600,71 @@ gimp_procedure_dialog_get_int_combo (GimpProcedureDialog *dialog,
   return widget;
 }
 
+/**
+ * gimp_procedure_dialog_get_scale_entry:
+ * @dialog:   the associated #GimpProcedureDialog.
+ * @property: name of the int property to build a combo for. It must be
+ *            a property of the #GimpProcedure @dialog has been created
+ *            for.
+ * @factor:   a display factor for the range shown by the widget.
+ *
+ * Creates a new #GimpScaleEntry for @property which must necessarily be
+ * an integer or double property.
+ * This can be used instead of gimp_procedure_dialog_get_widget() in
+ * particular if you want to tweak the display factor. A typical example
+ * is showing a [0.0, 1.0] range as [0.0, 100.0] instead (@factor = 100.0).
+ *
+ * If a widget has already been created for this procedure, it will be
+ * returned instead (whatever its actual widget type).
+ *
+ * Returns: (transfer none): the #GtkWidget representing @property. The
+ *                           object belongs to @dialog and must not be
+ *                           freed.
+ */
+GtkWidget *
+gimp_procedure_dialog_get_scale_entry (GimpProcedureDialog *dialog,
+                                       const gchar         *property,
+                                       gdouble              factor)
+{
+  GtkWidget  *widget = NULL;
+  GParamSpec *pspec;
+
+  g_return_val_if_fail (GIMP_IS_PROCEDURE_DIALOG (dialog), NULL);
+  g_return_val_if_fail (property != NULL, NULL);
+
+  pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (dialog->priv->config),
+                                        property);
+
+  if (! pspec)
+    {
+      g_warning ("%s: parameter %s does not exist.",
+                 G_STRFUNC, property);
+      return NULL;
+    }
+
+  g_return_val_if_fail (G_PARAM_SPEC_TYPE (pspec) == G_TYPE_PARAM_INT ||
+                        G_PARAM_SPEC_TYPE (pspec) == G_TYPE_PARAM_DOUBLE, NULL);
+
+  /* First check if it already exists. */
+  widget = g_hash_table_lookup (dialog->priv->widgets, property);
+
+  if (widget)
+    return widget;
+
+  widget = gimp_prop_scale_entry_new (G_OBJECT (dialog->priv->config),
+                                      property,
+                                      _(g_param_spec_get_nick (pspec)),
+                                      factor, FALSE, 0.0, 0.0);
+
+  gtk_size_group_add_widget (dialog->priv->label_group,
+                             gimp_labeled_get_label (GIMP_LABELED (widget)));
+
+  gimp_procedure_dialog_check_mnemonic (dialog, widget, property, NULL);
+  g_hash_table_insert (dialog->priv->widgets, g_strdup (property), widget);
+
+  return widget;
+}
+
 /**
  * gimp_procedure_dialog_get_label:
  * @dialog:   the #GimpProcedureDialog.
diff --git a/libgimp/gimpproceduredialog.h b/libgimp/gimpproceduredialog.h
index d8d321f357..21408b6f56 100644
--- a/libgimp/gimpproceduredialog.h
+++ b/libgimp/gimpproceduredialog.h
@@ -81,6 +81,9 @@ GtkWidget * gimp_procedure_dialog_get_widget        (GimpProcedureDialog *dialog
 GtkWidget * gimp_procedure_dialog_get_int_combo     (GimpProcedureDialog *dialog,
                                                      const gchar         *property,
                                                      GimpIntStore        *store);
+GtkWidget * gimp_procedure_dialog_get_scale_entry   (GimpProcedureDialog *dialog,
+                                                     const gchar         *property,
+                                                     gdouble              factor);
 GtkWidget * gimp_procedure_dialog_get_label         (GimpProcedureDialog *dialog,
                                                      const gchar         *label_id,
                                                      const gchar         *text);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]