diff options
| author | Alexander Valavanis <valavanisalex@gmail.com> | 2018-06-17 21:46:25 +0000 |
|---|---|---|
| committer | Alexander Valavanis <valavanisalex@gmail.com> | 2018-06-17 21:46:25 +0000 |
| commit | 860d9295fd3fd6b5ed8e7141651cda01b016d46c (patch) | |
| tree | 93f9e943625ba0f538839f8b2e0e7b732a8f542c /src | |
| parent | Potential fix for FTBFS introduced in 60ecfba7 (diff) | |
| download | inkscape-860d9295fd3fd6b5ed8e7141651cda01b016d46c.tar.gz inkscape-860d9295fd3fd6b5ed8e7141651cda01b016d46c.zip | |
ZoomToolbar: C++ify and GtkAction migration
Diffstat (limited to 'src')
| -rw-r--r-- | src/helper/action.cpp | 36 | ||||
| -rw-r--r-- | src/helper/action.h | 9 | ||||
| -rw-r--r-- | src/ui/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | src/ui/toolbar/toolbar.cpp | 56 | ||||
| -rw-r--r-- | src/ui/toolbar/toolbar.h | 50 | ||||
| -rw-r--r-- | src/ui/toolbar/zoom-toolbar.cpp | 48 | ||||
| -rw-r--r-- | src/ui/toolbar/zoom-toolbar.h | 32 | ||||
| -rw-r--r-- | src/widgets/toolbox.cpp | 2 |
8 files changed, 223 insertions, 12 deletions
diff --git a/src/helper/action.cpp b/src/helper/action.cpp index e37575a9c..48e051ada 100644 --- a/src/helper/action.cpp +++ b/src/helper/action.cpp @@ -9,6 +9,10 @@ * This code is in public domain */ +#include "helper/action.h" + +#include <gtkmm/toolbutton.h> + #include "debug/logger.h" #include "debug/timestamp.h" #include "debug/simple-event.h" @@ -16,7 +20,7 @@ #include "ui/view/view.h" #include "desktop.h" #include "document.h" -#include "helper/action.h" +#include "verbs.h" static void sp_action_finalize (GObject *object); @@ -213,6 +217,36 @@ sp_action_get_desktop (SPAction *action) return static_cast<SPDesktop *>(sp_action_get_view(action)); } +/** + * \brief Create a toolbutton whose "clicked" signal performs an Inkscape verb + * + * \param[in] verb_code The code (e.g., SP_VERB_EDIT_SELECT_ALL) for the verb we want + * + * \todo This should really attach the toolbutton to an application action instead of + * hooking up the "clicked" signal. This should probably wait until we've + * migrated to Gtk::Application + */ +Gtk::ToolButton * +SPAction::create_toolbutton_for_verb(unsigned int verb_code, + Inkscape::ActionContext &context) +{ + // Get display properties for the verb + auto verb = Inkscape::Verb::get(verb_code); + auto target_action = verb->get_action(context); + auto icon_name = verb->get_image(); + + // Create a button with the required display properties + auto button = Gtk::manage(new Gtk::ToolButton(verb->get_name())); + button->set_icon_name(icon_name); + button->set_tooltip_text(verb->get_tip()); + + // Hook up signal handler + auto button_clicked_cb = sigc::bind(sigc::ptr_fun(&sp_action_perform), + target_action, nullptr); + button->signal_clicked().connect(button_clicked_cb); + + return button; +} /* Local Variables: mode:c++ diff --git a/src/helper/action.h b/src/helper/action.h index 4b81ee7f9..d731f2884 100644 --- a/src/helper/action.h +++ b/src/helper/action.h @@ -12,6 +12,8 @@ #ifndef SEEN_INKSCAPE_SP_ACTION_H #define SEEN_INKSCAPE_SP_ACTION_H +#include <glib-object.h> + #include "helper/action-context.h" #include <sigc++/signal.h> #include <glibmm/ustring.h> @@ -21,6 +23,10 @@ #define SP_ACTION_CLASS(o) (G_TYPE_CHECK_CLASS_CAST((o), SP_TYPE_ACTION, SPActionClass)) #define SP_IS_ACTION(o) (G_TYPE_CHECK_INSTANCE_TYPE((o), SP_TYPE_ACTION)) +namespace Gtk { +class ToolButton; +} + class SPDesktop; class SPDocument; namespace Inkscape { @@ -52,6 +58,9 @@ struct SPAction : public GObject { sigc::signal<void, bool> signal_set_sensitive; sigc::signal<void, bool> signal_set_active; sigc::signal<void, Glib::ustring const &> signal_set_name; + + static Gtk::ToolButton * create_toolbutton_for_verb(unsigned int verb_code, + Inkscape::ActionContext &context); }; /** The action class is the same as its parent. */ diff --git a/src/ui/CMakeLists.txt b/src/ui/CMakeLists.txt index 0374fad15..0ae3b8624 100644 --- a/src/ui/CMakeLists.txt +++ b/src/ui/CMakeLists.txt @@ -48,6 +48,7 @@ set(ui_SRC toolbar/spray-toolbar.cpp toolbar/star-toolbar.cpp toolbar/text-toolbar.cpp + toolbar/toolbar.cpp toolbar/tweak-toolbar.cpp toolbar/zoom-toolbar.cpp @@ -328,6 +329,7 @@ set(ui_SRC toolbar/spray-toolbar.h toolbar/star-toolbar.h toolbar/text-toolbar.h + toolbar/toolbar.h toolbar/tweak-toolbar.h toolbar/zoom-toolbar.h diff --git a/src/ui/toolbar/toolbar.cpp b/src/ui/toolbar/toolbar.cpp new file mode 100644 index 000000000..e1c9d082f --- /dev/null +++ b/src/ui/toolbar/toolbar.cpp @@ -0,0 +1,56 @@ +#include "toolbar.h" + +#include <gtkmm/separatortoolitem.h> + +#include "desktop.h" + +#include "helper/action.h" + +namespace Inkscape { +namespace UI { +namespace Toolbar { + +/** + * \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) + */ +void +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); +} + +/** + * \brief Add a separator line to the toolbar + * + * \details This is just a convenience wrapper for the + * standard GtkMM functionality + */ +void +Toolbar::add_separator() +{ + add(* Gtk::manage(new Gtk::SeparatorToolItem())); +} + +GtkWidget * +Toolbar::create(SPDesktop *desktop) +{ + auto toolbar = Gtk::manage(new Toolbar(desktop)); + return GTK_WIDGET(toolbar->gobj()); +} +} +} +} +/* + 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.h b/src/ui/toolbar/toolbar.h new file mode 100644 index 000000000..8f18cfe57 --- /dev/null +++ b/src/ui/toolbar/toolbar.h @@ -0,0 +1,50 @@ +#ifndef SEEN_TOOLBAR_H +#define SEEN_TOOLBAR_H + +#include <gtkmm/toolbar.h> + +class SPDesktop; + +namespace Inkscape { +namespace UI { +namespace Toolbar { +/** + * \brief An abstract definition for a toolbar within Inkscape + * + * \detail This is basically the same as a Gtk::Toolbar but contains a + * few convenience functions. All toolbars must define a "create" + * function that adds all the required tool-items and returns the + * toolbar as a GtkWidget + */ +class Toolbar : public Gtk::Toolbar { +protected: + SPDesktop *_desktop; + + /** + * \brief A default constructor that just assigns the desktop + */ + Toolbar(SPDesktop *desktop) + : _desktop(desktop) + {} + + void add_toolbutton_for_verb(unsigned int verb_code); + void add_separator(); + +protected: + static GtkWidget * create(SPDesktop *desktop); +}; +} +} +} + +#endif +/* + 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/zoom-toolbar.cpp b/src/ui/toolbar/zoom-toolbar.cpp index a961c0061..ec28dda89 100644 --- a/src/ui/toolbar/zoom-toolbar.cpp +++ b/src/ui/toolbar/zoom-toolbar.cpp @@ -30,14 +30,50 @@ #include "zoom-toolbar.h" -//######################## -//## Zoom Toolbox ## -//######################## +#include "desktop.h" +#include "verbs.h" -void sp_zoom_toolbox_prep(SPDesktop * /*desktop*/, GtkActionGroup* /*mainActions*/, GObject* /*holder*/) +#include "helper/action.h" + +namespace Inkscape { +namespace UI { +namespace Toolbar { +ZoomToolbar::ZoomToolbar(SPDesktop *desktop) + : Toolbar(desktop) +{ + add_toolbutton_for_verb(SP_VERB_ZOOM_IN); + add_toolbutton_for_verb(SP_VERB_ZOOM_OUT); + + add_separator(); + + add_toolbutton_for_verb(SP_VERB_ZOOM_1_1); + add_toolbutton_for_verb(SP_VERB_ZOOM_1_2); + add_toolbutton_for_verb(SP_VERB_ZOOM_2_1); + + add_separator(); + + add_toolbutton_for_verb(SP_VERB_ZOOM_SELECTION); + add_toolbutton_for_verb(SP_VERB_ZOOM_DRAWING); + add_toolbutton_for_verb(SP_VERB_ZOOM_PAGE); + add_toolbutton_for_verb(SP_VERB_ZOOM_PAGE_WIDTH); + + add_separator(); + + add_toolbutton_for_verb(SP_VERB_ZOOM_PREV); + add_toolbutton_for_verb(SP_VERB_ZOOM_NEXT); + + show_all(); +} + +GtkWidget * +ZoomToolbar::create(SPDesktop *desktop) { - // no custom GtkAction setup needed -} // end of sp_zoom_toolbox_prep() + auto toolbar = Gtk::manage(new ZoomToolbar(desktop)); + return GTK_WIDGET(toolbar->gobj()); +} +} +} +} /* Local Variables: diff --git a/src/ui/toolbar/zoom-toolbar.h b/src/ui/toolbar/zoom-toolbar.h index 45d979066..6be5856eb 100644 --- a/src/ui/toolbar/zoom-toolbar.h +++ b/src/ui/toolbar/zoom-toolbar.h @@ -27,11 +27,35 @@ * 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_zoom_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder); +/** + * \brief A toolbar for controlling the zoom + */ +class ZoomToolbar : public Toolbar { +protected: + ZoomToolbar(SPDesktop *desktop); + +public: + static GtkWidget * create(SPDesktop *desktop); +}; +} +} +} #endif /* !SEEN_ZOOM_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/widgets/toolbox.cpp b/src/widgets/toolbox.cpp index af2fcf26f..58ea6c116 100644 --- a/src/widgets/toolbox.cpp +++ b/src/widgets/toolbox.cpp @@ -192,7 +192,7 @@ static struct { SP_VERB_CONTEXT_TWEAK_PREFS, "/tools/tweak", N_("Color/opacity used for color tweaking")}, { "/tools/spray", "spray_toolbox", 0, sp_spray_toolbox_prep, "SprayToolbar", SP_VERB_INVALID, 0, 0}, - { "/tools/zoom", "zoom_toolbox", 0, sp_zoom_toolbox_prep, "ZoomToolbar", + { "/tools/zoom", "zoom_toolbox", Inkscape::UI::Toolbar::ZoomToolbar::create, nullptr, "ZoomToolbar", SP_VERB_INVALID, 0, 0}, { "/tools/measure", "measure_toolbox", 0, sp_measure_toolbox_prep, "MeasureToolbar", SP_VERB_INVALID, 0, 0}, |
