summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAlexander Valavanis <valavanisalex@gmail.com>2018-07-29 13:56:29 +0000
committerAlexander Valavanis <valavanisalex@gmail.com>2018-07-29 13:56:29 +0000
commitaa6dde633662cf5fecea6425b7367eb2b93d53fb (patch)
tree947bc444bd17b5ff424e3efcaa17f788e4b1b880 /src
parentchange header string (diff)
downloadinkscape-aa6dde633662cf5fecea6425b7367eb2b93d53fb.tar.gz
inkscape-aa6dde633662cf5fecea6425b7367eb2b93d53fb.zip
DropperToolbar: GtkAction migration
Diffstat (limited to 'src')
-rw-r--r--src/ui/toolbar/dropper-toolbar.cpp118
-rw-r--r--src/ui/toolbar/dropper-toolbar.h40
-rw-r--r--src/ui/toolbar/toolbar.cpp39
-rw-r--r--src/ui/toolbar/toolbar.h10
-rw-r--r--src/widgets/ege-output-action.h4
-rw-r--r--src/widgets/ink-toggle-action.cpp14
-rw-r--r--src/widgets/toolbox.cpp2
7 files changed, 158 insertions, 69 deletions
diff --git a/src/ui/toolbar/dropper-toolbar.cpp b/src/ui/toolbar/dropper-toolbar.cpp
index b9d21be1b..c66c5ead0 100644
--- a/src/ui/toolbar/dropper-toolbar.cpp
+++ b/src/ui/toolbar/dropper-toolbar.cpp
@@ -37,83 +37,77 @@
#include "preferences.h"
#include "widgets/spinbutton-events.h"
-using Inkscape::DocumentUndo;
+namespace Inkscape {
+namespace UI {
+namespace Toolbar {
-//########################
-//## Dropper ##
-//########################
-
-static void toggle_dropper_pick_alpha( GtkToggleAction* act, gpointer tbl )
+void DropperToolbar::on_pick_alpha_button_toggled()
{
- Inkscape::Preferences *prefs = Inkscape::Preferences::get();
- prefs->setInt( "/tools/dropper/pick", gtk_toggle_action_get_active( act ) );
- GtkAction* set_action = GTK_ACTION( g_object_get_data(G_OBJECT(tbl), "set_action") );
- if ( set_action ) {
- if ( gtk_toggle_action_get_active( act ) ) {
- gtk_action_set_sensitive( set_action, TRUE );
- } else {
- gtk_action_set_sensitive( set_action, FALSE );
- }
- }
-
- spinbutton_defocus(GTK_WIDGET(tbl));
+ auto active = _pick_alpha_button->get_active();
+
+ auto prefs = Inkscape::Preferences::get();
+ prefs->setInt( "/tools/dropper/pick", active );
+
+ _set_alpha_button->set_sensitive(active);
+
+ spinbutton_defocus(GTK_WIDGET(gobj()));
}
-static void toggle_dropper_set_alpha( GtkToggleAction* act, gpointer tbl )
+void DropperToolbar::on_set_alpha_button_toggled()
{
- Inkscape::Preferences *prefs = Inkscape::Preferences::get();
- prefs->setBool( "/tools/dropper/setalpha", gtk_toggle_action_get_active( act ) );
- spinbutton_defocus(GTK_WIDGET(tbl));
+ auto prefs = Inkscape::Preferences::get();
+ prefs->setBool( "/tools/dropper/setalpha", _set_alpha_button->get_active( ) );
+ spinbutton_defocus(GTK_WIDGET(gobj()));
}
-
-/**
- * Dropper auxiliary toolbar construction and setup.
- *
+/*
* TODO: Would like to add swatch of current color.
* TODO: Add queue of last 5 or so colors selected with new swatches so that
* can drag and drop places. Will provide a nice mixing palette.
*/
-void sp_dropper_toolbox_prep(SPDesktop * /*desktop*/, GtkActionGroup* mainActions, GObject* holder)
+DropperToolbar::DropperToolbar(SPDesktop *desktop)
+ : Toolbar(desktop)
{
+ // Add widgets to toolbar
+ add_label(_("Opacity:"));
+ _pick_alpha_button = add_toggle_button(_("Pick"),
+ _("Pick both the color and the alpha (transparency) under cursor; "
+ "otherwise, pick only the visible color premultiplied by alpha"));
+ _set_alpha_button = add_toggle_button(_("Assign"),
+ _("If alpha was picked, assign it to selection "
+ "as fill or stroke transparency"));
+
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
- gint pickAlpha = prefs->getInt( "/tools/dropper/pick", 1 );
-
- {
- EgeOutputAction* act = ege_output_action_new( "DropperOpacityAction", _("Opacity:"), "", nullptr );
- ege_output_action_set_use_markup( act, TRUE );
- gtk_action_group_add_action( mainActions, GTK_ACTION( act ) );
- }
-
- {
- InkToggleAction* act = ink_toggle_action_new( "DropperPickAlphaAction",
- _("Pick opacity"),
- _("Pick both the color and the alpha (transparency) under cursor; otherwise, pick only the visible color premultiplied by alpha"),
- nullptr,
- GTK_ICON_SIZE_MENU );
- g_object_set( act, "short_label", _("Pick"), NULL );
- gtk_action_group_add_action( mainActions, GTK_ACTION( act ) );
- g_object_set_data( holder, "pick_action", act );
- gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), pickAlpha );
- g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(toggle_dropper_pick_alpha), holder );
- }
-
- {
- InkToggleAction* act = ink_toggle_action_new( "DropperSetAlphaAction",
- _("Assign opacity"),
- _("If alpha was picked, assign it to selection as fill or stroke transparency"),
- nullptr,
- GTK_ICON_SIZE_MENU );
- g_object_set( act, "short_label", _("Assign"), NULL );
- gtk_action_group_add_action( mainActions, GTK_ACTION( act ) );
- g_object_set_data( holder, "set_action", act );
- gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool( "/tools/dropper/setalpha", true) );
- // make sure it's disabled if we're not picking alpha
- gtk_action_set_sensitive( GTK_ACTION(act), pickAlpha );
- g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(toggle_dropper_set_alpha), holder );
- }
+
+ // Set initial state of widgets
+ auto pickAlpha = prefs->getInt( "/tools/dropper/pick", 1 );
+ auto setAlpha = prefs->getBool( "/tools/dropper/setalpha", true);
+
+ _pick_alpha_button->set_active(pickAlpha);
+ _set_alpha_button->set_active(setAlpha);
+
+ // Make sure the set-alpha button is disabled if we're not picking alpha
+ _set_alpha_button->set_sensitive(pickAlpha);
+
+ // Connect signal handlers
+ auto pick_alpha_button_toggled_cb = sigc::mem_fun(*this, &DropperToolbar::on_pick_alpha_button_toggled);
+ auto set_alpha_button_toggled_cb = sigc::mem_fun(*this, &DropperToolbar::on_set_alpha_button_toggled);
+
+ _pick_alpha_button->signal_toggled().connect(pick_alpha_button_toggled_cb);
+ _set_alpha_button->signal_toggled().connect(set_alpha_button_toggled_cb);
+
+ show_all();
}
+GtkWidget *
+DropperToolbar::create(SPDesktop *desktop)
+{
+ auto toolbar = Gtk::manage(new DropperToolbar(desktop));
+ return GTK_WIDGET(toolbar->gobj());
+}
+}
+}
+}
/*
Local Variables:
diff --git a/src/ui/toolbar/dropper-toolbar.h b/src/ui/toolbar/dropper-toolbar.h
index 8d5ea2d0a..3ce8cb089 100644
--- a/src/ui/toolbar/dropper-toolbar.h
+++ b/src/ui/toolbar/dropper-toolbar.h
@@ -27,11 +27,43 @@
* Released under GNU GPL, read the file 'COPYING' for more information
*/
-class SPDesktop;
+#include "toolbar.h"
-typedef struct _GtkActionGroup GtkActionGroup;
-typedef struct _GObject GObject;
+namespace Inkscape {
+namespace UI {
+namespace Toolbar {
-void sp_dropper_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder);
+/**
+ * \brief A toolbar for controlling the dropper tool
+ */
+class DropperToolbar : public Toolbar {
+private:
+ // Tool widgets
+ Gtk::ToggleToolButton *_pick_alpha_button; ///< Control whether to pick opacity
+ Gtk::ToggleToolButton *_set_alpha_button; ///< Control whether to set opacity
+
+ // Event handlers
+ void on_pick_alpha_button_toggled();
+ void on_set_alpha_button_toggled();
+protected:
+ DropperToolbar(SPDesktop *desktop);
+
+public:
+ static GtkWidget * create(SPDesktop *desktop);
+};
+}
+}
+}
#endif /* !SEEN_DROPPER_TOOLBAR_H */
+
+/*
+ Local Variables:
+ mode:c++
+ c-file-style:"stroustrup"
+ c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
+ indent-tabs-mode:nil
+ fill-column:99
+ End:
+*/
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
diff --git a/src/ui/toolbar/toolbar.cpp b/src/ui/toolbar/toolbar.cpp
index e1c9d082f..8a17dcbea 100644
--- a/src/ui/toolbar/toolbar.cpp
+++ b/src/ui/toolbar/toolbar.cpp
@@ -1,6 +1,8 @@
#include "toolbar.h"
+#include <gtkmm/label.h>
#include <gtkmm/separatortoolitem.h>
+#include <gtkmm/toggletoolbutton.h>
#include "desktop.h"
@@ -10,17 +12,52 @@ namespace Inkscape {
namespace UI {
namespace Toolbar {
+Gtk::ToolItem *
+Toolbar::add_label(const Glib::ustring &label_text)
+{
+ auto ti = Gtk::manage(new Gtk::ToolItem());
+
+ // For now, we always enable mnemonic
+ auto label = Gtk::manage(new Gtk::Label(label_text, true));
+
+ ti->add(*label);
+ add(*ti);
+
+ return ti;
+}
+
+/**
+ * \brief Add a toggle toolbutton to the toolbar
+ *
+ * \param[in] label_text The text to display in the toolbar
+ * \param[in] tooltip_text The tooltip text for the toolitem
+ *
+ * \returns The toggle button
+ */
+Gtk::ToggleToolButton *
+Toolbar::add_toggle_button(const Glib::ustring &label_text,
+ const Glib::ustring &tooltip_text)
+{
+ auto btn = Gtk::manage(new Gtk::ToggleToolButton(label_text));
+ btn->set_tooltip_text(tooltip_text);
+ add(*btn);
+ return btn;
+}
+
/**
* \brief Add a toolbutton that performs a given verb
*
* \param[in] verb_code The code for the verb (e.g., SP_VERB_EDIT_SELECT_ALL)
+ *
+ * \returns a pointer to the toolbutton
*/
-void
+Gtk::ToolButton *
Toolbar::add_toolbutton_for_verb(unsigned int verb_code)
{
auto context = Inkscape::ActionContext(_desktop);
auto button = SPAction::create_toolbutton_for_verb(verb_code, context);
add(*button);
+ return button;
}
/**
diff --git a/src/ui/toolbar/toolbar.h b/src/ui/toolbar/toolbar.h
index 8f18cfe57..63d762b51 100644
--- a/src/ui/toolbar/toolbar.h
+++ b/src/ui/toolbar/toolbar.h
@@ -5,6 +5,11 @@
class SPDesktop;
+namespace Gtk {
+ class Label;
+ class ToggleToolButton;
+}
+
namespace Inkscape {
namespace UI {
namespace Toolbar {
@@ -27,7 +32,10 @@ protected:
: _desktop(desktop)
{}
- void add_toolbutton_for_verb(unsigned int verb_code);
+ Gtk::ToolItem * add_label(const Glib::ustring &label_text);
+ Gtk::ToggleToolButton * add_toggle_button(const Glib::ustring &label_text,
+ const Glib::ustring &tooltip_text);
+ Gtk::ToolButton * add_toolbutton_for_verb(unsigned int verb_code);
void add_separator();
protected:
diff --git a/src/widgets/ege-output-action.h b/src/widgets/ege-output-action.h
index 0f4e21805..f61493db7 100644
--- a/src/widgets/ege-output-action.h
+++ b/src/widgets/ege-output-action.h
@@ -93,6 +93,10 @@ GType ege_output_action_get_type( void );
* @param label Display label for the action.
* @param tooltip Tooltip for the action.
* @param stock_id Icon id to use.
+ *
+ * @deprecated GtkActions are deprecated. Use a GtkLabel inside a GtkToolItem instead.
+ * The Inkscape::UI::Toolbar::Toolbar base class provides an add_label function
+ * to simplify this.
*/
EgeOutputAction* ege_output_action_new( const gchar *name,
const gchar *label,
diff --git a/src/widgets/ink-toggle-action.cpp b/src/widgets/ink-toggle-action.cpp
index 77dc39c3d..7a29b95d5 100644
--- a/src/widgets/ink-toggle-action.cpp
+++ b/src/widgets/ink-toggle-action.cpp
@@ -77,6 +77,20 @@ static void ink_toggle_action_finalize( GObject* obj )
}
+/**
+ * \brief Create a new toggle action
+ *
+ * \param[in] name The name of the Action
+ * \param[in] label The label text to display on the Action's tool item
+ * \param[in] tooltip The tooltip text for the Action's tool item
+ * \param[in] inkId
+ * \param[in] size The size of the tool item to display
+ *
+ * \detail The name is used by the UI Manager to look up the action when specified in a UI XML
+ * file.
+ *
+ * \deprecated GtkActions are deprecated. Use a Gtk::ToggleToolButton instead.
+ */
InkToggleAction* ink_toggle_action_new( const gchar *name,
const gchar *label,
const gchar *tooltip,
diff --git a/src/widgets/toolbox.cpp b/src/widgets/toolbox.cpp
index 1b051f6cd..07ff69dc9 100644
--- a/src/widgets/toolbox.cpp
+++ b/src/widgets/toolbox.cpp
@@ -219,7 +219,7 @@ static struct {
// If you change TextToolbar here, change it also in desktop-widget.cpp
{ "/tools/text", "text_toolbox", nullptr, sp_text_toolbox_prep, "TextToolbar",
SP_VERB_INVALID, nullptr, nullptr},
- { "/tools/dropper", "dropper_toolbox", nullptr, sp_dropper_toolbox_prep, "DropperToolbar",
+ { "/tools/dropper", "dropper_toolbox", Inkscape::UI::Toolbar::DropperToolbar::create, nullptr, "DropperToolbar",
SP_VERB_INVALID, nullptr, nullptr},
{ "/tools/connector", "connector_toolbox", nullptr, sp_connector_toolbox_prep, "ConnectorToolbar",
SP_VERB_INVALID, nullptr, nullptr},