diff options
| author | Alexander Valavanis <valavanisalex@gmail.com> | 2019-01-29 14:46:18 +0000 |
|---|---|---|
| committer | Alexander Valavanis <valavanisalex@gmail.com> | 2019-01-29 14:46:18 +0000 |
| commit | 94939a3c123496e0843ff6adf55cbe9b68c0cb0c (patch) | |
| tree | 689b28ec95baa1ccf3447c47e231d539a970c0b1 /src/ui/toolbar/eraser-toolbar.cpp | |
| parent | Box3DToolbar: GtkAction migration (diff) | |
| download | inkscape-94939a3c123496e0843ff6adf55cbe9b68c0cb0c.tar.gz inkscape-94939a3c123496e0843ff6adf55cbe9b68c0cb0c.zip | |
EraserToolbar: GtkAction migration
Diffstat (limited to 'src/ui/toolbar/eraser-toolbar.cpp')
| -rw-r--r-- | src/ui/toolbar/eraser-toolbar.cpp | 319 |
1 files changed, 153 insertions, 166 deletions
diff --git a/src/ui/toolbar/eraser-toolbar.cpp b/src/ui/toolbar/eraser-toolbar.cpp index a5225a75e..bd8eb2a41 100644 --- a/src/ui/toolbar/eraser-toolbar.cpp +++ b/src/ui/toolbar/eraser-toolbar.cpp @@ -25,25 +25,24 @@ * Released under GNU GPL v2+, read the file 'COPYING' for more information. */ -#include <glibmm/i18n.h> - #include "eraser-toolbar.h" #include <array> +#include <glibmm/i18n.h> + +#include <gtkmm/radiotoolbutton.h> +#include <gtkmm/separatortoolitem.h> + #include "desktop.h" #include "document-undo.h" -#include "widgets/ege-adjustment-action.h" -#include "widgets/ink-toggle-action.h" -#include "widgets/toolbox.h" -#include "ui/widget/ink-select-one-action.h" #include "ui/icon-names.h" -#include "ui/pref-pusher.h" +#include "ui/simple-pref-pusher.h" #include "ui/tools/eraser-tool.h" +#include "ui/widget/spin-button-tool-item.h" + using Inkscape::DocumentUndo; -using Inkscape::UI::ToolboxFactory; -using Inkscape::UI::PrefPusher; namespace Inkscape { namespace UI { @@ -51,187 +50,174 @@ namespace Toolbar { EraserToolbar::EraserToolbar(SPDesktop *desktop) : Toolbar(desktop), _freeze(false) -{} - -GtkWidget * -EraserToolbar::prep(SPDesktop *desktop, GtkActionGroup* mainActions) { - auto toolbar = new EraserToolbar(desktop); - GtkIconSize secondarySize = ToolboxFactory::prefToSize("/toolbox/secondary", 1); - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); gint eraser_mode = ERASER_MODE_DELETE; + auto prefs = Inkscape::Preferences::get(); + // Mode { - InkSelectOneActionColumns columns; - - Glib::RefPtr<Gtk::ListStore> store = Gtk::ListStore::create(columns); - - Gtk::TreeModel::Row row; - - row = *(store->append()); - row[columns.col_label ] = _("Delete"); - row[columns.col_tooltip ] = _("Delete objects touched by eraser"); - row[columns.col_icon ] = INKSCAPE_ICON("draw-eraser-delete-objects"); - row[columns.col_sensitive] = true; - - row = *(store->append()); - row[columns.col_label ] = _("Cut"); - row[columns.col_tooltip ] = _("Cut out from paths and shapes"); - row[columns.col_icon ] = INKSCAPE_ICON("path-difference"); - row[columns.col_sensitive] = true; - - row = *(store->append()); - row[columns.col_label ] = _("Clip"); - row[columns.col_tooltip ] = _("Clip from objects"); - row[columns.col_icon ] = INKSCAPE_ICON("path-intersection"); - row[columns.col_sensitive] = true; - - toolbar->_eraser_mode_action = - InkSelectOneAction::create( "EraserModeAction", // Name - _("Mode"), // Label - "", // Tooltip - "Not Used", // Icon - store ); // Tree store - toolbar->_eraser_mode_action->use_radio( true ); - toolbar->_eraser_mode_action->use_group_label( true ); + add_label(_("Mode:")); + + Gtk::RadioToolButton::Group mode_group; + + std::vector<Gtk::RadioToolButton *> mode_buttons; + + auto delete_btn = Gtk::manage(new Gtk::RadioToolButton(mode_group, _("Delete"))); + delete_btn->set_tooltip_text(_("Delete objects touched by eraser")); + delete_btn->set_icon_name(INKSCAPE_ICON("draw-eraser-delete-objects")); + mode_buttons.push_back(delete_btn); + + auto cut_btn = Gtk::manage(new Gtk::RadioToolButton(mode_group, _("Cut"))); + cut_btn->set_tooltip_text(_("Cut out from paths and shapes")); + cut_btn->set_icon_name(INKSCAPE_ICON("path-difference")); + mode_buttons.push_back(cut_btn); + + auto clip_btn = Gtk::manage(new Gtk::RadioToolButton(mode_group, _("Clip"))); + clip_btn->set_tooltip_text(_("Clip from objects")); + clip_btn->set_icon_name(INKSCAPE_ICON("path-intersection")); + mode_buttons.push_back(clip_btn); + eraser_mode = prefs->getInt("/tools/eraser/mode", ERASER_MODE_CLIP); // Used at end - toolbar->_eraser_mode_action->set_active( eraser_mode ); - gtk_action_group_add_action( mainActions, GTK_ACTION( toolbar->_eraser_mode_action->gobj() )); + mode_buttons[eraser_mode]->set_active(); - toolbar->_eraser_mode_action->signal_changed().connect(sigc::mem_fun(*toolbar, &EraserToolbar::mode_changed)); + int btn_index = 0; + + for (auto btn : mode_buttons) + { + add(*btn); + btn->signal_clicked().connect(sigc::bind(sigc::mem_fun(*this, &EraserToolbar::mode_changed), btn_index++)); + } } + _separators.push_back(Gtk::manage(new Gtk::SeparatorToolItem())); + add(*_separators.back()); /* Width */ { - gchar const* labels[] = {_("(no width)"),_("(hairline)"), nullptr, nullptr, nullptr, _("(default)"), nullptr, nullptr, nullptr, nullptr, _("(broad stroke)")}; - gdouble values[] = {0, 1, 3, 5, 10, 15, 20, 30, 50, 75, 100}; - toolbar->_width = create_adjustment_action( "EraserWidthAction", - _("Pen Width"), _("Width:"), - _("The width of the eraser pen (relative to the visible canvas area)"), - "/tools/eraser/width", 15, - TRUE, "altx-eraser", - 0, 100, 1.0, 10.0, - labels, values, G_N_ELEMENTS(labels), - nullptr /*unit tracker*/, 1, 0); - ege_adjustment_action_set_focuswidget(toolbar->_width, GTK_WIDGET(desktop->canvas)); - toolbar->_width_adj = Glib::wrap(ege_adjustment_action_get_adjustment(toolbar->_width)); - toolbar->_width_adj->signal_value_changed().connect(sigc::mem_fun(*toolbar, &EraserToolbar::width_value_changed)); - ege_adjustment_action_set_appearance( toolbar->_width, TOOLBAR_SLIDER_HINT ); - gtk_action_group_add_action( mainActions, GTK_ACTION(toolbar->_width) ); - gtk_action_set_sensitive( GTK_ACTION(toolbar->_width), TRUE ); + std::vector<Glib::ustring> labels = {_("(no width)"), _("(hairline)"), "", "", "", _("(default)"), "", "", "", "", _("(broad stroke)")}; + std::vector<double> values = { 0, 1, 3, 5, 10, 15, 20, 30, 50, 75, 100}; + auto width_val = prefs->getDouble("/tools/eraser/width", 15); + _width_adj = Gtk::Adjustment::create(width_val, 0, 100, 1.0, 10.0); + _width = Gtk::manage(new UI::Widget::SpinButtonToolItem("eraser-width", _("Width:"), _width_adj, 1, 0)); + _width->set_tooltip_text(_("The width of the eraser pen (relative to the visible canvas area)")); + _width->set_focus_widget(Glib::wrap(GTK_WIDGET(desktop->canvas))); + _width->set_custom_numeric_menu_data(values, labels); + _width_adj->signal_value_changed().connect(sigc::mem_fun(*this, &EraserToolbar::width_value_changed)); + // TODO: Allow SpinButtonToolItem to display as a slider + // ege_adjustment_action_set_appearance( toolbar->_width, TOOLBAR_SLIDER_HINT ); + add(*_width); + _width->set_sensitive(true); } - /* Use Pressure button */ { - toolbar->_usepressure = ink_toggle_action_new( "EraserPressureAction", - _("Eraser Pressure"), - _("Use the pressure of the input device to alter the width of the pen"), - INKSCAPE_ICON("draw-use-pressure"), - GTK_ICON_SIZE_MENU ); - gtk_action_group_add_action( mainActions, GTK_ACTION( toolbar->_usepressure ) ); - toolbar->_pressure_pusher.reset(new PrefPusher(GTK_TOGGLE_ACTION(toolbar->_usepressure), "/tools/eraser/usepressure", update_presets_list, (gpointer)toolbar)); + _usepressure = add_toggle_button(_("Eraser Pressure"), + _("Use the pressure of the input device to alter the width of the pen")); + _usepressure->set_icon_name(INKSCAPE_ICON("draw-use-pressure")); + _pressure_pusher.reset(new UI::SimplePrefPusher(_usepressure, "/tools/eraser/usepressure")); + _usepressure->signal_toggled().connect(sigc::mem_fun(*this, &EraserToolbar::usepressure_toggled)); } + _separators.push_back(Gtk::manage(new Gtk::SeparatorToolItem())); + add(*_separators.back()); /* Thinning */ { - gchar const* labels[] = {_("(speed blows up stroke)"), nullptr, nullptr, _("(slight widening)"), _("(constant width)"), _("(slight thinning, default)"), nullptr, nullptr, _("(speed deflates stroke)")}; - gdouble values[] = {-100, -40, -20, -10, 0, 10, 20, 40, 100}; - toolbar->_thinning = create_adjustment_action( "EraserThinningAction", - _("Eraser Stroke Thinning"), _("Thinning:"), - _("How much velocity thins the stroke (> 0 makes fast strokes thinner, < 0 makes them broader, 0 makes width independent of velocity)"), - "/tools/eraser/thinning", 10, - FALSE, nullptr, - -100, 100, 1, 10.0, - labels, values, G_N_ELEMENTS(labels), - nullptr /*unit tracker*/, 1, 0); - ege_adjustment_action_set_focuswidget(toolbar->_thinning, GTK_WIDGET(desktop->canvas)); - toolbar->_thinning_adj = Glib::wrap(ege_adjustment_action_get_adjustment(toolbar->_thinning)); - toolbar->_thinning_adj->signal_value_changed().connect(sigc::mem_fun(*toolbar, &EraserToolbar::velthin_value_changed)); - gtk_action_group_add_action( mainActions, GTK_ACTION(toolbar->_thinning) ); - gtk_action_set_sensitive( GTK_ACTION(toolbar->_thinning), TRUE ); + std::vector<Glib::ustring> labels = {_("(speed blows up stroke)"), "", "", _("(slight widening)"), _("(constant width)"), _("(slight thinning, default)"), "", "", _("(speed deflates stroke)")}; + std::vector<double> values = { -100, -40, -20, -10, 0, 10, 20, 40, 100}; + auto thinning_val = prefs->getDouble("/tools/eraser/thinning", 10); + _thinning_adj = Gtk::Adjustment::create(thinning_val, -100, 100, 1, 10.0); + _thinning = Gtk::manage(new UI::Widget::SpinButtonToolItem("eraser-thinning", _("Thinning:"), _thinning_adj, 1, 0)); + _thinning->set_tooltip_text(_("How much velocity thins the stroke (> 0 makes fast strokes thinner, < 0 makes them broader, 0 makes width independent of velocity)")); + _thinning->set_custom_numeric_menu_data(values, labels); + _thinning->set_focus_widget(Glib::wrap(GTK_WIDGET(desktop->canvas))); + _thinning_adj->signal_value_changed().connect(sigc::mem_fun(*this, &EraserToolbar::velthin_value_changed)); + add(*_thinning); + _thinning->set_sensitive(true); } + _separators.push_back(Gtk::manage(new Gtk::SeparatorToolItem())); + add(*_separators.back()); /* Cap Rounding */ { - gchar const* labels[] = {_("(blunt caps, default)"), _("(slightly bulging)"), nullptr, nullptr, _("(approximately round)"), _("(long protruding caps)")}; - gdouble values[] = {0, 0.3, 0.5, 1.0, 1.4, 5.0}; + std::vector<Glib::ustring> labels = {_("(blunt caps, default)"), _("(slightly bulging)"), "", "", _("(approximately round)"), _("(long protruding caps)")}; + std::vector<double> values = { 0, 0.3, 0.5, 1.0, 1.4, 5.0}; + auto cap_rounding_val = prefs->getDouble("/tools/eraser/cap_rounding", 0.0); + _cap_rounding_adj = Gtk::Adjustment::create(cap_rounding_val, 0.0, 5.0, 0.01, 0.1); // TRANSLATORS: "cap" means "end" (both start and finish) here - toolbar->_cap_rounding = create_adjustment_action( "EraserCapRoundingAction", - _("Eraser Cap rounding"), _("Caps:"), - _("Increase to make caps at the ends of strokes protrude more (0 = no caps, 1 = round caps)"), - "/tools/eraser/cap_rounding", 0.0, - FALSE, nullptr, - 0.0, 5.0, 0.01, 0.1, - labels, values, G_N_ELEMENTS(labels), - nullptr /*unit tracker*/, 0.01, 2 ); - ege_adjustment_action_set_focuswidget(toolbar->_cap_rounding, GTK_WIDGET(desktop->canvas)); - toolbar->_cap_rounding_adj = Glib::wrap(ege_adjustment_action_get_adjustment(toolbar->_cap_rounding)); - toolbar->_cap_rounding_adj->signal_value_changed().connect(sigc::mem_fun(*toolbar, &EraserToolbar::cap_rounding_value_changed)); - gtk_action_group_add_action( mainActions, GTK_ACTION(toolbar->_cap_rounding) ); - gtk_action_set_sensitive( GTK_ACTION(toolbar->_cap_rounding), TRUE ); + _cap_rounding = Gtk::manage(new UI::Widget::SpinButtonToolItem("eraser-cap-rounding", _("Caps:"), _cap_rounding_adj, 0.01, 2)); + _cap_rounding->set_tooltip_text(_("Increase to make caps at the ends of strokes protrude more (0 = no caps, 1 = round caps)")); + _cap_rounding->set_custom_numeric_menu_data(values, labels); + _cap_rounding->set_focus_widget(Glib::wrap(GTK_WIDGET(desktop->canvas))); + _cap_rounding_adj->signal_value_changed().connect(sigc::mem_fun(*this, &EraserToolbar::cap_rounding_value_changed)); + add(*_cap_rounding); + _cap_rounding->set_sensitive(true); } + _separators.push_back(Gtk::manage(new Gtk::SeparatorToolItem())); + add(*_separators.back()); /* Tremor */ { - gchar const* labels[] = {_("(smooth line)"), _("(slight tremor)"), _("(noticeable tremor)"), nullptr, nullptr, _("(maximum tremor)")}; - gdouble values[] = {0, 10, 20, 40, 60, 100}; - toolbar->_tremor = create_adjustment_action( "EraserTremorAction", - _("EraserStroke Tremor"), _("Tremor:"), - _("Increase to make strokes rugged and trembling"), - "/tools/eraser/tremor", 0.0, - FALSE, nullptr, - 0.0, 100, 1, 10.0, - labels, values, G_N_ELEMENTS(labels), - nullptr /*unit tracker*/, 1, 0); - ege_adjustment_action_set_focuswidget(toolbar->_tremor, GTK_WIDGET(desktop->canvas)); - toolbar->_tremor_adj = Glib::wrap(ege_adjustment_action_get_adjustment(toolbar->_tremor)); - toolbar->_tremor_adj->signal_value_changed().connect(sigc::mem_fun(*toolbar, &EraserToolbar::tremor_value_changed)); - - ege_adjustment_action_set_appearance( toolbar->_tremor, TOOLBAR_SLIDER_HINT ); - gtk_action_group_add_action( mainActions, GTK_ACTION(toolbar->_tremor) ); - gtk_action_set_sensitive( GTK_ACTION(toolbar->_tremor), TRUE ); + std::vector<Glib::ustring> labels = {_("(smooth line)"), _("(slight tremor)"), _("(noticeable tremor)"), "", "", _("(maximum tremor)")}; + std::vector<double> values = { 0, 10, 20, 40, 60, 100}; + auto tremor_val = prefs->getDouble("/tools/eraser/tremor", 0.0); + _tremor_adj = Gtk::Adjustment::create(tremor_val, 0.0, 100, 1, 10.0); + _tremor = Gtk::manage(new UI::Widget::SpinButtonToolItem("eraser-tremor", _("Tremor:"), _tremor_adj, 1, 0)); + _tremor->set_tooltip_text(_("Increase to make strokes rugged and trembling")); + _tremor->set_custom_numeric_menu_data(values, labels); + _tremor->set_focus_widget(Glib::wrap(GTK_WIDGET(desktop->canvas))); + _tremor_adj->signal_value_changed().connect(sigc::mem_fun(*this, &EraserToolbar::tremor_value_changed)); + + // TODO: Allow slider appearance + //ege_adjustment_action_set_appearance( toolbar->_tremor, TOOLBAR_SLIDER_HINT ); + add(*_tremor); + _tremor->set_sensitive(true); } + _separators.push_back(Gtk::manage(new Gtk::SeparatorToolItem())); + add(*_separators.back()); + /* Mass */ { - gchar const* labels[] = {_("(no inertia)"), _("(slight smoothing, default)"), _("(noticeable lagging)"), nullptr, nullptr, _("(maximum inertia)")}; - gdouble values[] = {0.0, 2, 10, 20, 50, 100}; - toolbar->_mass = create_adjustment_action( "EraserMassAction", - _("Eraser Mass"), _("Mass:"), - _("Increase to make the eraser drag behind, as if slowed by inertia"), - "/tools/eraser/mass", 10.0, - FALSE, nullptr, - 0.0, 100, 1, 10.0, - labels, values, G_N_ELEMENTS(labels), - nullptr /*unit tracker*/, 1, 0); - ege_adjustment_action_set_focuswidget(toolbar->_mass, GTK_WIDGET(desktop->canvas)); - toolbar->_mass_adj = Glib::wrap(ege_adjustment_action_get_adjustment(toolbar->_mass)); - toolbar->_mass_adj->signal_value_changed().connect(sigc::mem_fun(*toolbar, &EraserToolbar::mass_value_changed)); - ege_adjustment_action_set_appearance( toolbar->_mass, TOOLBAR_SLIDER_HINT ); - gtk_action_group_add_action( mainActions, GTK_ACTION(toolbar->_mass) ); - gtk_action_set_sensitive( GTK_ACTION(toolbar->_mass), TRUE ); + std::vector<Glib::ustring> labels = {_("(no inertia)"), _("(slight smoothing, default)"), _("(noticeable lagging)"), "", "", _("(maximum inertia)")}; + std::vector<double> values = { 0.0, 2, 10, 20, 50, 100}; + auto mass_val = prefs->getDouble("/tools/eraser/mass", 10.0); + _mass = Gtk::manage(new UI::Widget::SpinButtonToolItem("eraser-mass", _("Mass:"), _mass_adj, 1, 0)); + _mass_adj = Gtk::Adjustment::create(mass_val, 0.0, 100, 1, 10.0); + _mass->set_tooltip_text(_("Increase to make the eraser drag behind, as if slowed by inertia")); + _mass->set_custom_numeric_menu_data(values, labels); + _mass->set_focus_widget(Glib::wrap(GTK_WIDGET(desktop->canvas))); + _mass_adj->signal_value_changed().connect(sigc::mem_fun(*this, &EraserToolbar::mass_value_changed)); + // TODO: Allow slider appearance + //ege_adjustment_action_set_appearance( toolbar->_mass, TOOLBAR_SLIDER_HINT ); + add(*_mass); + _mass->set_sensitive(true); } + _separators.push_back(Gtk::manage(new Gtk::SeparatorToolItem())); + add(*_separators.back()); + /* Overlap */ { - toolbar->_split = ink_toggle_action_new( "EraserBreakAppart", - _("Break apart cut items"), - _("Break apart cut items"), - INKSCAPE_ICON("distribute-randomize"), - secondarySize ); - gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(toolbar->_split), prefs->getBool("/tools/eraser/break_apart", false) ); - g_signal_connect_after( G_OBJECT(toolbar->_split), "toggled", G_CALLBACK(toggle_break_apart), (gpointer)toolbar); - gtk_action_group_add_action( mainActions, GTK_ACTION(toolbar->_split) ); + _split = add_toggle_button(_("Break apart cut items"), + _("Break apart cut items")); + _split->set_icon_name(INKSCAPE_ICON("distribute-randomize")); + _split->set_active( prefs->getBool("/tools/eraser/break_apart", false) ); + _split->signal_toggled().connect(sigc::mem_fun(*this, &EraserToolbar::toggle_break_apart)); } - toolbar->set_eraser_mode_visibility(eraser_mode); + show_all(); + + set_eraser_mode_visibility(eraser_mode); +} +GtkWidget * +EraserToolbar::create(SPDesktop *desktop) +{ + auto toolbar = new EraserToolbar(desktop); return GTK_WIDGET(toolbar->gobj()); } @@ -264,18 +250,22 @@ EraserToolbar::mode_changed(int mode) void EraserToolbar::set_eraser_mode_visibility(const guint eraser_mode) { - gtk_action_set_visible( GTK_ACTION(_split), (eraser_mode == ERASER_MODE_CUT)); + _split->set_visible((eraser_mode == ERASER_MODE_CUT)); const gboolean visibility = (eraser_mode != ERASER_MODE_DELETE); - const std::array<GtkAction *, 6> arr = {GTK_ACTION(_cap_rounding), - GTK_ACTION(_mass), - GTK_ACTION(_thinning), - GTK_ACTION(_tremor), - GTK_ACTION(_usepressure), - GTK_ACTION(_width)}; - for (auto act : arr) { - gtk_action_set_visible( act, visibility ); + const std::array<Gtk::Widget *, 6> arr = {_cap_rounding, + _mass, + _thinning, + _tremor, + _usepressure, + _width}; + for (auto widget : arr) { + widget->set_visible(visibility); + } + + for (auto separator : _separators) { + separator->set_visible(visibility); } } @@ -314,22 +304,19 @@ EraserToolbar::tremor_value_changed() prefs->setDouble( "/tools/eraser/tremor", _tremor_adj->get_value() ); } -// A dummy function for PrefPusher. -// The code was calling the update_presets_list function in the calligraphy tool -// which was immediately returning. TODO: Investigate this further. void -EraserToolbar::update_presets_list(gpointer data) +EraserToolbar::toggle_break_apart() { - return; + auto prefs = Inkscape::Preferences::get(); + bool active = _split->get_active(); + prefs->setBool("/tools/eraser/break_apart", active); } void -EraserToolbar::toggle_break_apart(GtkToggleAction *act, - gpointer data) +EraserToolbar::usepressure_toggled() { - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - gboolean active = gtk_toggle_action_get_active(act); - prefs->setBool("/tools/eraser/break_apart", active); + auto prefs = Inkscape::Preferences::get(); + prefs->setBool("/tools/eraser/usepressure", _usepressure->get_active()); } } |
