app: clean up a lot of werid code in GimpColorOptions and GimpFilterOptions

First of all, derive GimpFilterOptions from GimpColorOptions, not the
other way around, which was a sick way of magically showing the right
options for various tools. That approach has failed and needed
additional hacks to do the right thing. Simply have the right class
hierarchy and call the right tool options GUI constructors and done.

Remove gimp_histogram_options_gui(), we don't need histogram scale
controls in tool options when we already have them next to the
histograms in the tool dialogs.

Also remove gimp_histogram_options_connect_view() and use a simple
g_object_bind_property() instead.
This commit is contained in:
Michael Natterer 2016-05-13 22:00:25 +02:00
parent 81e7cb6ba5
commit 13b1e6aafc
13 changed files with 56 additions and 83 deletions

View File

@ -39,7 +39,7 @@
#include "display/gimpdisplay.h" #include "display/gimpdisplay.h"
#include "gimpcolorizetool.h" #include "gimpcolorizetool.h"
#include "gimpcoloroptions.h" #include "gimpfilteroptions.h"
#include "gimp-intl.h" #include "gimp-intl.h"
@ -75,7 +75,7 @@ gimp_colorize_tool_register (GimpToolRegisterCallback callback,
gpointer data) gpointer data)
{ {
(* callback) (GIMP_TYPE_COLORIZE_TOOL, (* callback) (GIMP_TYPE_COLORIZE_TOOL,
GIMP_TYPE_COLOR_OPTIONS, GIMP_TYPE_FILTER_OPTIONS,
gimp_color_options_gui, gimp_color_options_gui,
0, 0,
"gimp-colorize-tool", "gimp-colorize-tool",

View File

@ -27,7 +27,6 @@
#include "widgets/gimppropwidgets.h" #include "widgets/gimppropwidgets.h"
#include "gimphistogramoptions.h"
#include "gimpcoloroptions.h" #include "gimpcoloroptions.h"
#include "gimptooloptions-gui.h" #include "gimptooloptions-gui.h"
@ -54,7 +53,7 @@ static void gimp_color_options_get_property (GObject *object,
G_DEFINE_TYPE (GimpColorOptions, gimp_color_options, G_DEFINE_TYPE (GimpColorOptions, gimp_color_options,
GIMP_TYPE_FILTER_OPTIONS) GIMP_TYPE_TOOL_OPTIONS)
static void static void
@ -146,16 +145,11 @@ GtkWidget *
gimp_color_options_gui (GimpToolOptions *tool_options) gimp_color_options_gui (GimpToolOptions *tool_options)
{ {
GObject *config = G_OBJECT (tool_options); GObject *config = G_OBJECT (tool_options);
GtkWidget *vbox; GtkWidget *vbox = gimp_tool_options_gui (tool_options);
GtkWidget *frame; GtkWidget *frame;
GtkWidget *scale; GtkWidget *scale;
GtkWidget *button; GtkWidget *button;
if (GIMP_IS_HISTOGRAM_OPTIONS (tool_options))
vbox = gimp_histogram_options_gui (tool_options);
else
vbox = gimp_tool_options_gui (tool_options);
/* the sample average options */ /* the sample average options */
frame = gimp_frame_new (NULL); frame = gimp_frame_new (NULL);
gtk_box_pack_start (GTK_BOX (vbox), frame, TRUE, TRUE, 0); gtk_box_pack_start (GTK_BOX (vbox), frame, TRUE, TRUE, 0);

View File

@ -19,7 +19,7 @@
#define __GIMP_COLOR_OPTIONS_H__ #define __GIMP_COLOR_OPTIONS_H__
#include "gimpfilteroptions.h" #include "core/gimptooloptions.h"
#define GIMP_TYPE_COLOR_OPTIONS (gimp_color_options_get_type ()) #define GIMP_TYPE_COLOR_OPTIONS (gimp_color_options_get_type ())
@ -30,20 +30,20 @@
#define GIMP_COLOR_OPTIONS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_COLOR_OPTIONS, GimpColorOptionsClass)) #define GIMP_COLOR_OPTIONS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_COLOR_OPTIONS, GimpColorOptionsClass))
typedef struct _GimpColorOptionsClass GimpColorOptionsClass; typedef struct _GimpColorOptionsClass GimpColorOptionsClass;
struct _GimpColorOptions struct _GimpColorOptions
{ {
GimpFilterOptions parent_instance; GimpToolOptions parent_instance;
gboolean sample_merged; gboolean sample_merged;
gboolean sample_average; gboolean sample_average;
gdouble average_radius; gdouble average_radius;
}; };
struct _GimpColorOptionsClass struct _GimpColorOptionsClass
{ {
GimpFilterOptionsClass parent_instance; GimpToolOptionsClass parent_instance;
}; };

View File

@ -541,8 +541,10 @@ gimp_curves_tool_dialog (GimpFilterTool *filter_tool)
gtk_container_add (GTK_CONTAINER (frame), tool->graph); gtk_container_add (GTK_CONTAINER (frame), tool->graph);
gtk_widget_show (tool->graph); gtk_widget_show (tool->graph);
gimp_histogram_options_connect_view (GIMP_HISTOGRAM_OPTIONS (tool_options), g_object_bind_property (G_OBJECT (tool_options), "histogram-scale",
GIMP_HISTOGRAM_VIEW (tool->graph)); G_OBJECT (tool->graph), "histogram-scale",
G_BINDING_SYNC_CREATE |
G_BINDING_BIDIRECTIONAL);
/* The bottom color bar */ /* The bottom color bar */
hbox2 = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); hbox2 = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);

View File

@ -54,7 +54,7 @@ static void gimp_filter_options_get_property (GObject *object,
G_DEFINE_TYPE (GimpFilterOptions, gimp_filter_options, G_DEFINE_TYPE (GimpFilterOptions, gimp_filter_options,
GIMP_TYPE_TOOL_OPTIONS) GIMP_TYPE_COLOR_OPTIONS)
#define parent_class gimp_filter_options_parent_class #define parent_class gimp_filter_options_parent_class

View File

@ -19,7 +19,7 @@
#define __GIMP_FILTER_OPTIONS_H__ #define __GIMP_FILTER_OPTIONS_H__
#include "core/gimptooloptions.h" #include "gimpcoloroptions.h"
#define GIMP_TYPE_FILTER_OPTIONS (gimp_filter_options_get_type ()) #define GIMP_TYPE_FILTER_OPTIONS (gimp_filter_options_get_type ())
@ -30,20 +30,25 @@
#define GIMP_FILTER_OPTIONS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_FILTER_OPTIONS, GimpFilterOptionsClass)) #define GIMP_FILTER_OPTIONS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_FILTER_OPTIONS, GimpFilterOptionsClass))
typedef struct _GimpToolOptionsClass GimpFilterOptionsClass; typedef struct _GimpFilterOptionsClass GimpFilterOptionsClass;
struct _GimpFilterOptions struct _GimpFilterOptions
{ {
GimpToolOptions parent_instance; GimpColorOptions parent_instance;
gboolean preview; gboolean preview;
gboolean preview_split; gboolean preview_split;
GimpAlignmentType preview_alignment; GimpAlignmentType preview_alignment;
gdouble preview_position; gdouble preview_position;
GimpFilterRegion region; GimpFilterRegion region;
gboolean gamma_hack; gboolean gamma_hack;
GFile *settings; GFile *settings;
};
struct _GimpFilterOptionsClass
{
GimpColorOptionsClass parent_instance;
}; };

View File

@ -66,7 +66,7 @@
#include "display/gimpdisplayshell-transform.h" #include "display/gimpdisplayshell-transform.h"
#include "display/gimptoolgui.h" #include "display/gimptoolgui.h"
#include "gimpcoloroptions.h" #include "gimpfilteroptions.h"
#include "gimpfiltertool.h" #include "gimpfiltertool.h"
#include "gimpfiltertool-settings.h" #include "gimpfiltertool-settings.h"
#include "gimpguidetool.h" #include "gimpguidetool.h"

View File

@ -32,7 +32,7 @@
#include "widgets/gimphelp-ids.h" #include "widgets/gimphelp-ids.h"
#include "widgets/gimppropwidgets.h" #include "widgets/gimppropwidgets.h"
#include "gimpcoloroptions.h" #include "gimpfilteroptions.h"
#include "gimpgegltool.h" #include "gimpgegltool.h"
#include "gimp-intl.h" #include "gimp-intl.h"
@ -65,7 +65,7 @@ gimp_gegl_tool_register (GimpToolRegisterCallback callback,
gpointer data) gpointer data)
{ {
(* callback) (GIMP_TYPE_GEGL_TOOL, (* callback) (GIMP_TYPE_GEGL_TOOL,
GIMP_TYPE_COLOR_OPTIONS, GIMP_TYPE_FILTER_OPTIONS,
gimp_color_options_gui, gimp_color_options_gui,
0, 0,
"gimp-gegl-tool", "gimp-gegl-tool",

View File

@ -21,16 +21,10 @@
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include "libgimpconfig/gimpconfig.h" #include "libgimpconfig/gimpconfig.h"
#include "libgimpwidgets/gimpwidgets.h"
#include "tools-types.h" #include "tools-types.h"
#include "config/gimpconfig-utils.h"
#include "widgets/gimphistogramview.h"
#include "gimphistogramoptions.h" #include "gimphistogramoptions.h"
#include "gimptooloptions-gui.h"
#include "gimp-intl.h" #include "gimp-intl.h"
@ -53,7 +47,7 @@ static void gimp_histogram_options_get_property (GObject *object,
G_DEFINE_TYPE (GimpHistogramOptions, gimp_histogram_options, G_DEFINE_TYPE (GimpHistogramOptions, gimp_histogram_options,
GIMP_TYPE_COLOR_OPTIONS) GIMP_TYPE_FILTER_OPTIONS)
static void static void
@ -117,30 +111,3 @@ gimp_histogram_options_get_property (GObject *object,
break; break;
} }
} }
GtkWidget *
gimp_histogram_options_gui (GimpToolOptions *tool_options)
{
GObject *config = G_OBJECT (tool_options);
GtkWidget *vbox = gimp_tool_options_gui (tool_options);
GtkWidget *frame;
frame = gimp_prop_enum_radio_frame_new (config, "histogram-scale", NULL,
0, 0);
gtk_box_pack_start (GTK_BOX (vbox), frame, TRUE, TRUE, 0);
gtk_widget_show (frame);
return vbox;
}
void
gimp_histogram_options_connect_view (GimpHistogramOptions *options,
GimpHistogramView *view)
{
g_return_if_fail (GIMP_IS_HISTOGRAM_OPTIONS (options));
g_return_if_fail (GIMP_IS_HISTOGRAM_VIEW (view));
gimp_config_connect (G_OBJECT (options), G_OBJECT (view), "histogram-scale");
g_object_notify (G_OBJECT (options), "histogram-scale");
}

View File

@ -19,7 +19,7 @@
#define __GIMP_HISTOGRAM_OPTIONS_H__ #define __GIMP_HISTOGRAM_OPTIONS_H__
#include "gimpcoloroptions.h" #include "gimpfilteroptions.h"
#define GIMP_TYPE_HISTOGRAM_OPTIONS (gimp_histogram_options_get_type ()) #define GIMP_TYPE_HISTOGRAM_OPTIONS (gimp_histogram_options_get_type ())
@ -30,22 +30,23 @@
#define GIMP_HISTOGRAM_OPTIONS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_HISTOGRAM_OPTIONS, GimpHistogramOptionsClass)) #define GIMP_HISTOGRAM_OPTIONS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_HISTOGRAM_OPTIONS, GimpHistogramOptionsClass))
typedef struct _GimpHistogramOptions GimpHistogramOptions; typedef struct _GimpHistogramOptions GimpHistogramOptions;
typedef GimpColorOptionsClass GimpHistogramOptionsClass; typedef struct _GimpHistogramOptionsClass GimpHistogramOptionsClass;
struct _GimpHistogramOptions struct _GimpHistogramOptions
{ {
GimpColorOptions parent_instance; GimpFilterOptions parent_instance;
GimpHistogramScale scale; GimpHistogramScale scale;
}; };
struct _GimpHistogramOptionsClass
{
GimpFilterOptionsClass parent_class;
};
GType gimp_histogram_options_get_type (void) G_GNUC_CONST;
GtkWidget * gimp_histogram_options_gui (GimpToolOptions *tool_options); GType gimp_histogram_options_get_type (void) G_GNUC_CONST;
void gimp_histogram_options_connect_view (GimpHistogramOptions *options,
GimpHistogramView *view);
#endif /* __GIMP_HISTOGRAM_OPTIONS_H__ */ #endif /* __GIMP_HISTOGRAM_OPTIONS_H__ */

View File

@ -425,8 +425,10 @@ gimp_levels_tool_dialog (GimpFilterTool *filter_tool)
gtk_box_pack_start (GTK_BOX (vbox2), tool->histogram_view, TRUE, TRUE, 0); gtk_box_pack_start (GTK_BOX (vbox2), tool->histogram_view, TRUE, TRUE, 0);
gtk_widget_show (GTK_WIDGET (tool->histogram_view)); gtk_widget_show (GTK_WIDGET (tool->histogram_view));
gimp_histogram_options_connect_view (GIMP_HISTOGRAM_OPTIONS (tool_options), g_object_bind_property (G_OBJECT (tool_options), "histogram-scale",
GIMP_HISTOGRAM_VIEW (tool->histogram_view)); G_OBJECT (tool->histogram_view), "histogram-scale",
G_BINDING_SYNC_CREATE |
G_BINDING_BIDIRECTIONAL);
g_object_get (tool->histogram_view, "border-width", &border, NULL); g_object_get (tool->histogram_view, "border-width", &border, NULL);

View File

@ -51,7 +51,7 @@
#include "display/gimpdisplay.h" #include "display/gimpdisplay.h"
#include "display/gimptoolgui.h" #include "display/gimptoolgui.h"
#include "gimpcoloroptions.h" #include "gimpfilteroptions.h"
#include "gimpoperationtool.h" #include "gimpoperationtool.h"
#include "gimp-intl.h" #include "gimp-intl.h"
@ -124,7 +124,7 @@ gimp_operation_tool_register (GimpToolRegisterCallback callback,
gpointer data) gpointer data)
{ {
(* callback) (GIMP_TYPE_OPERATION_TOOL, (* callback) (GIMP_TYPE_OPERATION_TOOL,
GIMP_TYPE_COLOR_OPTIONS, GIMP_TYPE_FILTER_OPTIONS,
gimp_color_options_gui, gimp_color_options_gui,
GIMP_CONTEXT_PROP_MASK_FOREGROUND | GIMP_CONTEXT_PROP_MASK_FOREGROUND |
GIMP_CONTEXT_PROP_MASK_BACKGROUND, GIMP_CONTEXT_PROP_MASK_BACKGROUND,

View File

@ -27,7 +27,6 @@
#include "core/gimpdrawable.h" #include "core/gimpdrawable.h"
#include "core/gimpdrawable-histogram.h" #include "core/gimpdrawable-histogram.h"
#include "core/gimperror.h"
#include "core/gimphistogram.h" #include "core/gimphistogram.h"
#include "core/gimpimage.h" #include "core/gimpimage.h"
@ -39,6 +38,7 @@
#include "gimphistogramoptions.h" #include "gimphistogramoptions.h"
#include "gimpthresholdtool.h" #include "gimpthresholdtool.h"
#include "gimptooloptions-gui.h"
#include "gimp-intl.h" #include "gimp-intl.h"
@ -84,7 +84,7 @@ gimp_threshold_tool_register (GimpToolRegisterCallback callback,
{ {
(* callback) (GIMP_TYPE_THRESHOLD_TOOL, (* callback) (GIMP_TYPE_THRESHOLD_TOOL,
GIMP_TYPE_HISTOGRAM_OPTIONS, GIMP_TYPE_HISTOGRAM_OPTIONS,
gimp_histogram_options_gui, NULL,
0, 0,
"gimp-threshold-tool", "gimp-threshold-tool",
_("Threshold"), _("Threshold"),
@ -231,8 +231,10 @@ gimp_threshold_tool_dialog (GimpFilterTool *filter_tool)
G_CALLBACK (gimp_threshold_tool_histogram_range), G_CALLBACK (gimp_threshold_tool_histogram_range),
t_tool); t_tool);
gimp_histogram_options_connect_view (GIMP_HISTOGRAM_OPTIONS (tool_options), g_object_bind_property (G_OBJECT (tool_options), "histogram-scale",
t_tool->histogram_box->view); G_OBJECT (t_tool->histogram_box->view), "histogram-scale",
G_BINDING_SYNC_CREATE |
G_BINDING_BIDIRECTIONAL);
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6); hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
gtk_box_pack_start (GTK_BOX (main_vbox), hbox, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (main_vbox), hbox, FALSE, FALSE, 0);