diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/ui/toolbar/calligraphy-toolbar.cpp | 567 | ||||
| -rw-r--r-- | src/ui/toolbar/calligraphy-toolbar.h | 42 | ||||
| -rw-r--r-- | src/ui/tools/calligraphic-tool.cpp | 10 | ||||
| -rw-r--r-- | src/widgets/toolbox.cpp | 2 |
4 files changed, 285 insertions, 336 deletions
diff --git a/src/ui/toolbar/calligraphy-toolbar.cpp b/src/ui/toolbar/calligraphy-toolbar.cpp index a776b7508..34e7a8941 100644 --- a/src/ui/toolbar/calligraphy-toolbar.cpp +++ b/src/ui/toolbar/calligraphy-toolbar.cpp @@ -25,30 +25,22 @@ * Released under GNU GPL v2+, read the file 'COPYING' for more information. */ -#include "ui/dialog/calligraphic-profile-rename.h" -#include <glibmm/i18n.h> #include "calligraphy-toolbar.h" +#include <glibmm/i18n.h> + +#include <gtkmm/comboboxtext.h> +#include <gtkmm/separatortoolitem.h> + #include "desktop.h" #include "document-undo.h" -#include "widgets/ege-adjustment-action.h" -#include "widgets/ink-action.h" -#include "widgets/ink-toggle-action.h" -#include "widgets/toolbox.h" #include "ui/icon-names.h" -#include "ui/pref-pusher.h" +#include "ui/simple-pref-pusher.h" #include "ui/uxmanager.h" -#include "ui/widget/ink-select-one-action.h" +#include "ui/dialog/calligraphic-profile-rename.h" +#include "ui/widget/spin-button-tool-item.h" -using Inkscape::UI::UXManager; using Inkscape::DocumentUndo; -using Inkscape::UI::ToolboxFactory; -using Inkscape::UI::PrefPusher; - - -//######################## -//## Calligraphy ## -//######################## std::vector<Glib::ustring> get_presets_list() { @@ -64,349 +56,317 @@ namespace UI { namespace Toolbar { CalligraphyToolbar::CalligraphyToolbar(SPDesktop *desktop) - : Toolbar(desktop) -{} - -GtkWidget * -CalligraphyToolbar::prep(SPDesktop *desktop, GtkActionGroup* mainActions) + : Toolbar(desktop), + _presets_blocked(false) { - auto toolbar = new CalligraphyToolbar(desktop); - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + + /*calligraphic profile */ { - toolbar->_presets_blocked = true; + _profile_selector_combo = Gtk::manage(new Gtk::ComboBoxText()); + _profile_selector_combo->set_tooltip_text(_("Choose a preset")); - { - /* Width */ - gchar const* labels[] = {_("(hairline)"), nullptr, nullptr, nullptr, _("(default)"), nullptr, nullptr, nullptr, nullptr, _("(broad stroke)")}; - gdouble values[] = {1, 3, 5, 10, 15, 20, 30, 50, 75, 100}; - EgeAdjustmentAction *eact = create_adjustment_action( "CalligraphyWidthAction", - _("Pen Width"), _("Width:"), - _("The width of the calligraphic pen (relative to the visible canvas area)"), - "/tools/calligraphic/width", 15, - TRUE, "altx-calligraphy", - 1, 100, 1.0, 10.0, - labels, values, G_N_ELEMENTS(labels), - nullptr /*unit tracker*/, 1, 0 ); - ege_adjustment_action_set_focuswidget(eact, GTK_WIDGET(desktop->canvas)); - toolbar->_width_adj = Glib::wrap(ege_adjustment_action_get_adjustment(eact)); - toolbar->_width_adj->signal_value_changed().connect(sigc::mem_fun(*toolbar, &CalligraphyToolbar::width_value_changed)); - toolbar->_widget_map["width"] = G_OBJECT(toolbar->_width_adj->gobj()); - ege_adjustment_action_set_appearance( eact, TOOLBAR_SLIDER_HINT ); - gtk_action_group_add_action( mainActions, GTK_ACTION(eact) ); - gtk_action_set_sensitive( GTK_ACTION(eact), TRUE ); - } + build_presets_list(); - { - /* 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}; - EgeAdjustmentAction* eact = create_adjustment_action( "ThinningAction", - _("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/calligraphic/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(eact, GTK_WIDGET(desktop->canvas)); - toolbar->_thinning_adj = Glib::wrap(ege_adjustment_action_get_adjustment(eact)); - toolbar->_thinning_adj->signal_value_changed().connect(sigc::mem_fun(*toolbar, &CalligraphyToolbar::velthin_value_changed)); - toolbar->_widget_map["thinning"] = G_OBJECT(toolbar->_thinning_adj->gobj()); - gtk_action_group_add_action( mainActions, GTK_ACTION(eact) ); - gtk_action_set_sensitive( GTK_ACTION(eact), TRUE ); - } + auto profile_selector_ti = Gtk::manage(new Gtk::ToolItem()); + profile_selector_ti->add(*_profile_selector_combo); + add(*profile_selector_ti); - { - /* Angle */ - gchar const* labels[] = {_("(left edge up)"), nullptr, nullptr, _("(horizontal)"), _("(default)"), nullptr, _("(right edge up)")}; - gdouble values[] = {-90, -60, -30, 0, 30, 60, 90}; - toolbar->_angle_action = create_adjustment_action( "AngleAction", - _("Pen Angle"), _("Angle:"), - _("The angle of the pen's nib (in degrees; 0 = horizontal; has no effect if fixation = 0)"), - "/tools/calligraphic/angle", 30, - TRUE, "calligraphy-angle", - -90.0, 90.0, 1.0, 10.0, - labels, values, G_N_ELEMENTS(labels), - nullptr /*unit tracker*/, 1, 0 ); - ege_adjustment_action_set_focuswidget(toolbar->_angle_action, GTK_WIDGET(desktop->canvas)); - toolbar->_angle_adj = Glib::wrap(ege_adjustment_action_get_adjustment(toolbar->_angle_action)); - toolbar->_angle_adj->signal_value_changed().connect(sigc::mem_fun(*toolbar, &CalligraphyToolbar::angle_value_changed)); - toolbar->_widget_map["angle"] = G_OBJECT(toolbar->_angle_adj->gobj()); - gtk_action_group_add_action( mainActions, GTK_ACTION(toolbar->_angle_action) ); - gtk_action_set_sensitive( GTK_ACTION(toolbar->_angle_action), TRUE ); - } + _profile_selector_combo->signal_changed().connect(sigc::mem_fun(*this, &CalligraphyToolbar::change_profile)); + } - { - /* Fixation */ - gchar const* labels[] = {_("(perpendicular to stroke, \"brush\")"), nullptr, nullptr, nullptr, _("(almost fixed, default)"), _("(fixed by Angle, \"pen\")")}; - gdouble values[] = {0, 20, 40, 60, 90, 100}; - EgeAdjustmentAction* eact = create_adjustment_action( "FixationAction", - _("Fixation"), _("Fixation:"), - _("Angle behavior (0 = nib always perpendicular to stroke direction, 100 = fixed angle)"), - "/tools/calligraphic/flatness", 90, - FALSE, nullptr, - 0.0, 100, 1.0, 10.0, - labels, values, G_N_ELEMENTS(labels), - nullptr /*unit tracker*/, 1, 0); - ege_adjustment_action_set_focuswidget(eact, GTK_WIDGET(desktop->canvas)); - toolbar->_fixation_adj = Glib::wrap(ege_adjustment_action_get_adjustment(eact)); - toolbar->_fixation_adj->signal_value_changed().connect(sigc::mem_fun(*toolbar, &CalligraphyToolbar::flatness_value_changed)); - toolbar->_widget_map["flatness"] = G_OBJECT(toolbar->_fixation_adj->gobj()); - gtk_action_group_add_action( mainActions, GTK_ACTION(eact) ); - gtk_action_set_sensitive( GTK_ACTION(eact), TRUE ); - } + /*calligraphic profile editor */ + { + auto profile_edit_item = Gtk::manage(new Gtk::ToolButton(_("Add/Edit Profile"))); + profile_edit_item->set_tooltip_text(_("Add or edit calligraphic profile")); + profile_edit_item->set_icon_name(INKSCAPE_ICON("document-properties")); + profile_edit_item->signal_clicked().connect(sigc::mem_fun(*this, &CalligraphyToolbar::edit_profile)); + add(*profile_edit_item); + } - { - /* 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}; - // TRANSLATORS: "cap" means "end" (both start and finish) here - EgeAdjustmentAction* eact = create_adjustment_action( "CapRoundingAction", - _("Cap rounding"), _("Caps:"), - _("Increase to make caps at the ends of strokes protrude more (0 = no caps, 1 = round caps)"), - "/tools/calligraphic/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(eact, GTK_WIDGET(desktop->canvas)); - toolbar->_cap_rounding_adj = Glib::wrap(ege_adjustment_action_get_adjustment(eact)); - toolbar->_cap_rounding_adj->signal_value_changed().connect(sigc::mem_fun(*toolbar, &CalligraphyToolbar::cap_rounding_value_changed)); - toolbar->_widget_map["cap_rounding"] = G_OBJECT(toolbar->_cap_rounding_adj->gobj()); - gtk_action_group_add_action( mainActions, GTK_ACTION(eact) ); - gtk_action_set_sensitive( GTK_ACTION(eact), TRUE ); - } + add(* Gtk::manage(new Gtk::SeparatorToolItem())); - { - /* Tremor */ - gchar const* labels[] = {_("(smooth line)"), _("(slight tremor)"), _("(noticeable tremor)"), nullptr, nullptr, _("(maximum tremor)")}; - gdouble values[] = {0, 10, 20, 40, 60, 100}; - EgeAdjustmentAction* eact = create_adjustment_action( "TremorAction", - _("Stroke Tremor"), _("Tremor:"), - _("Increase to make strokes rugged and trembling"), - "/tools/calligraphic/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(eact, GTK_WIDGET(desktop->canvas)); - toolbar->_tremor_adj = Glib::wrap(ege_adjustment_action_get_adjustment(eact)); - toolbar->_tremor_adj->signal_value_changed().connect(sigc::mem_fun(*toolbar, &CalligraphyToolbar::tremor_value_changed)); - toolbar->_widget_map["tremor"] = G_OBJECT(toolbar->_tremor_adj->gobj()); - ege_adjustment_action_set_appearance( eact, TOOLBAR_SLIDER_HINT ); - gtk_action_group_add_action( mainActions, GTK_ACTION(eact) ); - gtk_action_set_sensitive( GTK_ACTION(eact), TRUE ); - } + { + /* Width */ + std::vector<Glib::ustring> labels = {_("(hairline)"), "", "", "", _("(default)"), "", "", "", "", _("(broad stroke)")}; + std::vector<double> values = { 1, 3, 5, 10, 15, 20, 30, 50, 75, 100}; + auto width_val = prefs->getDouble("/tools/calligraphic/width", 15); + _width_adj = Gtk::Adjustment::create(width_val, 1, 100, 1.0, 10.0); + auto width_item = Gtk::manage(new UI::Widget::SpinButtonToolItem("calligraphy-width", _("Width:"), _width_adj, 1, 0)); + width_item->set_tooltip_text(_("The width of the calligraphic pen (relative to the visible canvas area)")); + width_item->set_custom_numeric_menu_data(values, labels); + width_item->set_focus_widget(Glib::wrap(GTK_WIDGET(desktop->canvas))); + _width_adj->signal_value_changed().connect(sigc::mem_fun(*this, &CalligraphyToolbar::width_value_changed)); + _widget_map["width"] = G_OBJECT(_width_adj->gobj()); + // ege_adjustment_action_set_appearance( eact, TOOLBAR_SLIDER_HINT ); + add(*width_item); + width_item->set_sensitive(true); + } - { - /* Wiggle */ - gchar const* labels[] = {_("(no wiggle)"), _("(slight deviation)"), nullptr, nullptr, _("(wild waves and curls)")}; - gdouble values[] = {0, 20, 40, 60, 100}; - EgeAdjustmentAction* eact = create_adjustment_action( "WiggleAction", - _("Pen Wiggle"), _("Wiggle:"), - _("Increase to make the pen waver and wiggle"), - "/tools/calligraphic/wiggle", 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(eact, GTK_WIDGET(desktop->canvas)); - toolbar->_wiggle_adj = Glib::wrap(ege_adjustment_action_get_adjustment(eact)); - toolbar->_wiggle_adj->signal_value_changed().connect(sigc::mem_fun(*toolbar, &CalligraphyToolbar::wiggle_value_changed)); - toolbar->_widget_map["wiggle"] = G_OBJECT(toolbar->_wiggle_adj->gobj()); - ege_adjustment_action_set_appearance( eact, TOOLBAR_SLIDER_HINT ); - gtk_action_group_add_action( mainActions, GTK_ACTION(eact) ); - gtk_action_set_sensitive( GTK_ACTION(eact), TRUE ); - } + /* Use Pressure button */ + { + _usepressure = add_toggle_button(_("Pressure"), + _("Use the pressure of the input device to alter the width of the pen")); + _usepressure->set_icon_name(INKSCAPE_ICON("draw-use-pressure")); + _widget_map["usepressure"] = G_OBJECT(_usepressure->gobj()); + _usepressure_pusher.reset(new SimplePrefPusher(_usepressure, "/tools/calligraphic/usepressure")); + _usepressure->signal_toggled().connect(sigc::bind(sigc::mem_fun(*this, &CalligraphyToolbar::on_pref_toggled), + _usepressure, + "/tools/calligraphic/usepressure")); + } - { - /* Mass */ - gchar const* labels[] = {_("(no inertia)"), _("(slight smoothing, default)"), _("(noticeable lagging)"), nullptr, nullptr, _("(maximum inertia)")}; - gdouble values[] = {0.0, 2, 10, 20, 50, 100}; - EgeAdjustmentAction* eact = create_adjustment_action( "MassAction", - _("Pen Mass"), _("Mass:"), - _("Increase to make the pen drag behind, as if slowed by inertia"), - "/tools/calligraphic/mass", 2.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(eact, GTK_WIDGET(desktop->canvas)); - toolbar->_mass_adj = Glib::wrap(ege_adjustment_action_get_adjustment(eact)); - toolbar->_mass_adj->signal_value_changed().connect(sigc::mem_fun(*toolbar, &CalligraphyToolbar::mass_value_changed)); - toolbar->_widget_map["mass"] = G_OBJECT(toolbar->_mass_adj->gobj()); - ege_adjustment_action_set_appearance( eact, TOOLBAR_SLIDER_HINT ); - gtk_action_group_add_action( mainActions, GTK_ACTION(eact) ); - gtk_action_set_sensitive( GTK_ACTION(eact), TRUE ); - } + /* Trace Background button */ + { + _tracebackground = add_toggle_button(_("Trace Background"), + _("Trace the lightness of the background by the width of the pen (white - minimum width, black - maximum width)")); + _tracebackground->set_icon_name(INKSCAPE_ICON("draw-trace-background")); + _widget_map["tracebackground"] = G_OBJECT(_tracebackground->gobj()); + _tracebackground_pusher.reset(new SimplePrefPusher(_tracebackground, "/tools/calligraphic/tracebackground")); + _tracebackground->signal_toggled().connect(sigc::bind(sigc::mem_fun(*this, &CalligraphyToolbar::on_pref_toggled), + _tracebackground, + "/tools/calligraphic/tracebackground")); + } + { + /* Thinning */ + 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/calligraphic/thinning", 10); + _thinning_adj = Gtk::Adjustment::create(thinning_val, -100, 100, 1, 10.0); + auto thinning_item = Gtk::manage(new UI::Widget::SpinButtonToolItem("calligraphy-thinning", _("Thinning:"), _thinning_adj, 1, 0)); + thinning_item->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_item->set_custom_numeric_menu_data(values, labels); + thinning_item->set_focus_widget(Glib::wrap(GTK_WIDGET(desktop->canvas))); + _thinning_adj->signal_value_changed().connect(sigc::mem_fun(*this, &CalligraphyToolbar::velthin_value_changed)); + _widget_map["thinning"] = G_OBJECT(_thinning_adj->gobj()); + add(*thinning_item); + thinning_item->set_sensitive(true); + } - /* Trace Background button */ - { - toolbar->_tracebackground = ink_toggle_action_new( "TraceAction", - _("Trace Background"), - _("Trace the lightness of the background by the width of the pen (white - minimum width, black - maximum width)"), - INKSCAPE_ICON("draw-trace-background"), - GTK_ICON_SIZE_MENU ); - toolbar->_widget_map["tracebackground"] = G_OBJECT(toolbar->_tracebackground); - gtk_action_group_add_action( mainActions, GTK_ACTION( toolbar->_tracebackground ) ); - toolbar->_tracebackground_pusher.reset(new PrefPusher(GTK_TOGGLE_ACTION(toolbar->_tracebackground), "/tools/calligraphic/tracebackground", update_presets_list, gpointer(toolbar))); - } + add(* Gtk::manage(new Gtk::SeparatorToolItem())); - /* Use Pressure button */ - { - toolbar->_usepressure = ink_toggle_action_new( "PressureAction", - _("Pressure"), - _("Use the pressure of the input device to alter the width of the pen"), - INKSCAPE_ICON("draw-use-pressure"), - GTK_ICON_SIZE_MENU ); - toolbar->_widget_map["usepressure"] = G_OBJECT(toolbar->_usepressure); - gtk_action_group_add_action( mainActions, GTK_ACTION( toolbar->_usepressure ) ); - toolbar->_usepressure_pusher.reset(new PrefPusher(GTK_TOGGLE_ACTION(toolbar->_usepressure), "/tools/calligraphic/usepressure", update_presets_list, gpointer(toolbar))); - } + { + /* Angle */ + std::vector<Glib::ustring> labels = {_("(left edge up)"), "", "", _("(horizontal)"), _("(default)"), "", _("(right edge up)")}; + std::vector<double> values = { -90, -60, -30, 0, 30, 60, 90}; + auto angle_val = prefs->getDouble("/tools/calligraphic/angle", 30); + _angle_adj = Gtk::Adjustment::create(angle_val, -90.0, 90.0, 1.0, 10.0); + _angle_item = Gtk::manage(new UI::Widget::SpinButtonToolItem("calligraphy-angle", _("Angle:"), _angle_adj, 1, 0)); + _angle_item->set_tooltip_text(_("The angle of the pen's nib (in degrees; 0 = horizontal; has no effect if fixation = 0)")); + _angle_item->set_custom_numeric_menu_data(values, labels); + _angle_item->set_focus_widget(Glib::wrap(GTK_WIDGET(desktop->canvas))); + _angle_adj->signal_value_changed().connect(sigc::mem_fun(*this, &CalligraphyToolbar::angle_value_changed)); + _widget_map["angle"] = G_OBJECT(_angle_adj->gobj()); + add(*_angle_item); + _angle_item->set_sensitive(true); + } - /* Use Tilt button */ - { - toolbar->_usetilt = ink_toggle_action_new( "TiltAction", - _("Tilt"), - _("Use the tilt of the input device to alter the angle of the pen's nib"), - INKSCAPE_ICON("draw-use-tilt"), - GTK_ICON_SIZE_MENU ); - toolbar->_widget_map["usetilt"] = G_OBJECT(toolbar->_usetilt); - gtk_action_group_add_action( mainActions, GTK_ACTION( toolbar->_usetilt ) ); - toolbar->_usetilt_pusher.reset(new PrefPusher(GTK_TOGGLE_ACTION(toolbar->_usetilt), "/tools/calligraphic/usetilt", update_presets_list, gpointer(toolbar))); - g_signal_connect_after( G_OBJECT(toolbar->_usetilt), "toggled", G_CALLBACK(tilt_state_changed), toolbar ); - gtk_action_set_sensitive( GTK_ACTION(toolbar->_angle_action), !prefs->getBool("/tools/calligraphic/usetilt", true) ); - gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(toolbar->_usetilt), prefs->getBool("/tools/calligraphic/usetilt", true) ); - } + /* Use Tilt button */ + { + _usetilt = add_toggle_button(_("Tilt"), + _("Use the tilt of the input device to alter the angle of the pen's nib")); + _usetilt->set_icon_name(INKSCAPE_ICON("draw-use-tilt")); + _widget_map["usetilt"] = G_OBJECT(_usetilt->gobj()); + _usetilt_pusher.reset(new SimplePrefPusher(_usetilt, "/tools/calligraphic/usetilt")); + _usetilt->signal_toggled().connect(sigc::mem_fun(*this, &CalligraphyToolbar::tilt_state_changed)); + _angle_item->set_sensitive(!prefs->getBool("/tools/calligraphic/usetilt", true)); + _usetilt->set_active(prefs->getBool("/tools/calligraphic/usetilt", true)); + } - /*calligraphic profile */ - { - InkSelectOneActionColumns columns; + { + /* Fixation */ + std::vector<Glib::ustring> labels = {_("(perpendicular to stroke, \"brush\")"), "", "", "", _("(almost fixed, default)"), _("(fixed by Angle, \"pen\")")}; + std::vector<double> values = { 0, 20, 40, 60, 90, 100}; + auto flatness_val = prefs->getDouble("/tools/calligraphic/flatness", 90); + _fixation_adj = Gtk::Adjustment::create(flatness_val, 0.0, 100, 1.0, 10.0); + auto flatness_item = Gtk::manage(new UI::Widget::SpinButtonToolItem("calligraphy-fixation", _("Fixation:"), _fixation_adj, 1, 0)); + flatness_item->set_tooltip_text(_("Angle behavior (0 = nib always perpendicular to stroke direction, 100 = fixed angle)")); + flatness_item->set_custom_numeric_menu_data(values, labels); + flatness_item->set_focus_widget(Glib::wrap(GTK_WIDGET(desktop->canvas))); + _fixation_adj->signal_value_changed().connect(sigc::mem_fun(*this, &CalligraphyToolbar::flatness_value_changed)); + _widget_map["flatness"] = G_OBJECT(_fixation_adj->gobj()); + add(*flatness_item); + flatness_item->set_sensitive(true); + } - Glib::RefPtr<Gtk::ListStore> store = Gtk::ListStore::create(columns); + add(* Gtk::manage(new Gtk::SeparatorToolItem())); - toolbar->_profile_selector = - InkSelectOneAction::create( "SetProfileAction", // Name - "", // Label - _("Choose a preset"), // Tooltip - "NotUsed", // Icon - store ); // Tree store - toolbar->_profile_selector->use_radio( false ); - toolbar->_profile_selector->use_label( true ); + { + /* Cap Rounding */ + 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/calligraphic/cap_rounding", 0.0); + _cap_rounding_adj = Gtk::Adjustment::create(cap_rounding_val, 0.0, 5.0, 0.01, 0.1); + auto cap_rounding_item = Gtk::manage(new UI::Widget::SpinButtonToolItem("calligraphy-cap-rounding", _("Caps:"), _cap_rounding_adj, 0.01, 2)); - toolbar->build_presets_list(); + // TRANSLATORS: "cap" means "end" (both start and finish) here + cap_rounding_item->set_tooltip_text(_("Increase to make caps at the ends of strokes protrude more (0 = no caps, 1 = round caps)")); + cap_rounding_item->set_custom_numeric_menu_data(values, labels); + cap_rounding_item->set_focus_widget(Glib::wrap(GTK_WIDGET(desktop->canvas))); + _cap_rounding_adj->signal_value_changed().connect(sigc::mem_fun(*this, &CalligraphyToolbar::cap_rounding_value_changed)); + _widget_map["cap_rounding"] = G_OBJECT(_cap_rounding_adj->gobj()); + add(*cap_rounding_item); + cap_rounding_item->set_sensitive(true); + } - gtk_action_group_add_action(mainActions, GTK_ACTION( toolbar->_profile_selector->gobj() )); + add(* Gtk::manage(new Gtk::SeparatorToolItem())); - toolbar->_profile_selector->signal_changed().connect(sigc::mem_fun(*toolbar, &CalligraphyToolbar::change_profile)); - } + { + /* Tremor */ + 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/calligraphic/tremor", 0.0); + _tremor_adj = Gtk::Adjustment::create(tremor_val, 0.0, 100, 1, 10.0); + auto tremor_item = Gtk::manage(new UI::Widget::SpinButtonToolItem("calligraphy-tremor", _("Tremor:"), _tremor_adj, 1, 0)); + tremor_item->set_tooltip_text(_("Increase to make strokes rugged and trembling")); + tremor_item->set_custom_numeric_menu_data(values, labels); + tremor_item->set_focus_widget(Glib::wrap(GTK_WIDGET(desktop->canvas))); + _tremor_adj->signal_value_changed().connect(sigc::mem_fun(*this, &CalligraphyToolbar::tremor_value_changed)); + _widget_map["tremor"] = G_OBJECT(_tremor_adj->gobj()); + // ege_adjustment_action_set_appearance( eact, TOOLBAR_SLIDER_HINT ); + add(*tremor_item); + tremor_item->set_sensitive(true); + } - /*calligraphic profile editor */ - { - InkAction* inky = ink_action_new( "ProfileEditAction", - _("Add/Edit Profile"), - _("Add or edit calligraphic profile"), - INKSCAPE_ICON("document-properties"), - GTK_ICON_SIZE_MENU ); - gtk_action_set_short_label(GTK_ACTION(inky), _("Edit")); - g_signal_connect_after( G_OBJECT(inky), "activate", G_CALLBACK(edit_profile), toolbar ); - gtk_action_group_add_action( mainActions, GTK_ACTION(inky) ); - } + { + /* Wiggle */ + std::vector<Glib::ustring> labels = {_("(no wiggle)"), _("(slight deviation)"), "", "", _("(wild waves and curls)")}; + std::vector<double> values = { 0, 20, 40, 60, 100}; + auto wiggle_val = prefs->getDouble("/tools/calligraphic/wiggle", 0.0); + _wiggle_adj = Gtk::Adjustment::create(wiggle_val, 0.0, 100, 1, 10.0); + auto wiggle_item = Gtk::manage(new UI::Widget::SpinButtonToolItem("calligraphy-wiggle", _("Wiggle:"), _wiggle_adj, 1, 0)); + wiggle_item->set_tooltip_text(_("Increase to make the pen waver and wiggle")); + wiggle_item->set_custom_numeric_menu_data(values, labels); + wiggle_item->set_focus_widget(Glib::wrap(GTK_WIDGET(desktop->canvas))); + _wiggle_adj->signal_value_changed().connect(sigc::mem_fun(*this, &CalligraphyToolbar::wiggle_value_changed)); + _widget_map["wiggle"] = G_OBJECT(_wiggle_adj->gobj()); + // ege_adjustment_action_set_appearance( eact, TOOLBAR_SLIDER_HINT ); + add(*wiggle_item); + wiggle_item->set_sensitive(true); + } + + { + /* Mass */ + 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/calligraphic/mass", 2.0); + _mass_adj = Gtk::Adjustment::create(mass_val, 0.0, 100, 1, 10.0); + auto mass_item = Gtk::manage(new UI::Widget::SpinButtonToolItem("calligraphy-mass", _("Mass:"), _mass_adj, 1, 0)); + mass_item->set_tooltip_text(_("Increase to make the pen drag behind, as if slowed by inertia")); + mass_item->set_custom_numeric_menu_data(values, labels); + mass_item->set_focus_widget(Glib::wrap(GTK_WIDGET(desktop->canvas))); + _mass_adj->signal_value_changed().connect(sigc::mem_fun(*this, &CalligraphyToolbar::mass_value_changed)); + _widget_map["mass"] = G_OBJECT(_mass_adj->gobj()); + // ege_adjustment_action_set_appearance( eact, TOOLBAR_SLIDER_HINT ); + add(*mass_item); + mass_item->set_sensitive(true); } + show_all(); +} + +GtkWidget * +CalligraphyToolbar::create(SPDesktop *desktop) +{ + auto toolbar = new CalligraphyToolbar(desktop); return GTK_WIDGET(toolbar->gobj()); } void CalligraphyToolbar::width_value_changed() { - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + auto prefs = Inkscape::Preferences::get(); prefs->setDouble( "/tools/calligraphic/width", _width_adj->get_value() ); - update_presets_list(this); + update_presets_list(); } void CalligraphyToolbar::velthin_value_changed() { - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + auto prefs = Inkscape::Preferences::get(); prefs->setDouble("/tools/calligraphic/thinning", _thinning_adj->get_value() ); - update_presets_list(this); + update_presets_list(); } void CalligraphyToolbar::angle_value_changed() { - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + auto prefs = Inkscape::Preferences::get(); prefs->setDouble( "/tools/calligraphic/angle", _angle_adj->get_value() ); - update_presets_list(this); + update_presets_list(); } void CalligraphyToolbar::flatness_value_changed() { - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + auto prefs = Inkscape::Preferences::get(); prefs->setDouble( "/tools/calligraphic/flatness", _fixation_adj->get_value() ); - update_presets_list(this); + update_presets_list(); } void CalligraphyToolbar::cap_rounding_value_changed() { - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + auto prefs = Inkscape::Preferences::get(); prefs->setDouble( "/tools/calligraphic/cap_rounding", _cap_rounding_adj->get_value() ); - update_presets_list(this); + update_presets_list(); } void CalligraphyToolbar::tremor_value_changed() { - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + auto prefs = Inkscape::Preferences::get(); prefs->setDouble( "/tools/calligraphic/tremor", _tremor_adj->get_value() ); - update_presets_list(this); + update_presets_list(); } void CalligraphyToolbar::wiggle_value_changed() { - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + auto prefs = Inkscape::Preferences::get(); prefs->setDouble( "/tools/calligraphic/wiggle", _wiggle_adj->get_value() ); - update_presets_list(this); + update_presets_list(); } void CalligraphyToolbar::mass_value_changed() { - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + auto prefs = Inkscape::Preferences::get(); prefs->setDouble( "/tools/calligraphic/mass", _mass_adj->get_value() ); - update_presets_list(this); + update_presets_list(); } void -CalligraphyToolbar::update_presets_list(gpointer data) +CalligraphyToolbar::on_pref_toggled(Gtk::ToggleToolButton *item, + const Glib::ustring& path) { - auto toolbar = reinterpret_cast<CalligraphyToolbar *>(data); + auto prefs = Inkscape::Preferences::get(); + prefs->setBool(path, item->get_active()); + update_presets_list(); +} - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - if (toolbar->_presets_blocked) { +void +CalligraphyToolbar::update_presets_list() +{ + if (_presets_blocked) { return; } - std::vector<Glib::ustring> presets = get_presets_list(); + auto prefs = Inkscape::Preferences::get(); + auto presets = get_presets_list(); int index = 1; // 0 is for no preset. - for (std::vector<Glib::ustring>::iterator i = presets.begin(); i != presets.end(); ++i, ++index) { + for (auto i = presets.begin(); i != presets.end(); ++i, ++index) { bool match = true; - std::vector<Inkscape::Preferences::Entry> preset = prefs->getAllEntries(*i); + auto preset = prefs->getAllEntries(*i); for (auto & j : preset) { Glib::ustring entry_name = j.getEntryName(); if (entry_name == "id" || entry_name == "name") { continue; } - void *widget = toolbar->_widget_map[entry_name.data()]; + void *widget = _widget_map[entry_name.data()]; if (widget) { if (GTK_IS_ADJUSTMENT(widget)) { double v = j.getDouble(); @@ -416,11 +376,11 @@ CalligraphyToolbar::update_presets_list(gpointer data) match = false; break; } - } else if (GTK_IS_TOGGLE_ACTION(widget)) { + } else if (GTK_IS_TOGGLE_TOOL_BUTTON(widget)) { bool v = j.getBool(); - GtkToggleAction* toggle = static_cast<GtkToggleAction *>(widget); + auto toggle = GTK_TOGGLE_TOOL_BUTTON(widget); //std::cout << "compared toggle " << attr_name << gtk_toggle_action_get_active(toggle) << " to " << v << "\n"; - if ( static_cast<bool>(gtk_toggle_action_get_active(toggle)) != v ) { + if ( static_cast<bool>(gtk_toggle_tool_button_get_active(toggle)) != v ) { match = false; break; } @@ -431,25 +391,21 @@ CalligraphyToolbar::update_presets_list(gpointer data) if (match) { // newly added item is at the same index as the // save command, so we need to change twice for it to take effect - toolbar->_profile_selector->set_active(0); - toolbar->_profile_selector->set_active(index); + _profile_selector_combo->set_active(0); + _profile_selector_combo->set_active(index); return; } } // no match found - toolbar->_profile_selector->set_active(0); + _profile_selector_combo->set_active(0); } void -CalligraphyToolbar::tilt_state_changed( GtkToggleAction *act, gpointer data ) +CalligraphyToolbar::tilt_state_changed() { - auto toolbar = reinterpret_cast<CalligraphyToolbar *>(data); - - // TODO merge into PrefPusher - if (toolbar->_angle_action) { - gtk_action_set_sensitive( GTK_ACTION(toolbar->_angle_action), !gtk_toggle_action_get_active( act ) ); - } + _angle_item->set_sensitive(!_usetilt->get_active()); + on_pref_toggled(_usetilt, "/tools/calligraphic/usetilt"); } void @@ -457,41 +413,31 @@ CalligraphyToolbar::build_presets_list() { _presets_blocked = true; - auto store = _profile_selector->get_store(); - store->clear(); - - InkSelectOneActionColumns columns; - - Gtk::TreeModel::Row row; - - row = *(store->append()); - row[columns.col_label ] = _("No preset"); - row[columns.col_sensitive] = true; + _profile_selector_combo->remove_all(); + _profile_selector_combo->append(_("No preset")); // iterate over all presets to populate the list - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - std::vector<Glib::ustring> presets = get_presets_list(); - int ii=1; + auto prefs = Inkscape::Preferences::get(); + auto presets = get_presets_list(); for (auto & preset : presets) { GtkTreeIter iter; Glib::ustring preset_name = prefs->getString(preset + "/name"); if (!preset_name.empty()) { - row = *(store->append()); - row[columns.col_label ] = _(preset_name.data()); - row[columns.col_sensitive] = true; + _profile_selector_combo->append(_(preset_name.data())); } } _presets_blocked = false; - update_presets_list(this); + update_presets_list(); } void -CalligraphyToolbar::change_profile(int mode) +CalligraphyToolbar::change_profile() { + auto mode = _profile_selector_combo->get_active_row_number(); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); if (_presets_blocked) { @@ -523,9 +469,9 @@ CalligraphyToolbar::change_profile(int mode) GtkAdjustment* adj = static_cast<GtkAdjustment *>(widget); gtk_adjustment_set_value(adj, i.getDouble()); //std::cout << "set adj " << attr_name << " to " << v << "\n"; - } else if (GTK_IS_TOGGLE_ACTION(widget)) { - GtkToggleAction* toggle = static_cast<GtkToggleAction *>(widget); - gtk_toggle_action_set_active(toggle, i.getBool()); + } else if (GTK_IS_TOGGLE_TOOL_BUTTON(widget)) { + auto toggle = GTK_TOGGLE_TOOL_BUTTON(widget); + gtk_toggle_tool_button_set_active(toggle, i.getBool()); //std::cout << "set toggle " << attr_name << " to " << v << "\n"; } else { g_warning("Unknown widget type for preset: %s\n", entry_name.data()); @@ -539,10 +485,9 @@ CalligraphyToolbar::change_profile(int mode) } void -CalligraphyToolbar::edit_profile(GtkAction * /*act*/, gpointer data) +CalligraphyToolbar::edit_profile() { - auto toolbar = reinterpret_cast<CalligraphyToolbar *>(data); - toolbar->save_profile(nullptr); + save_profile(nullptr); } void @@ -558,7 +503,7 @@ CalligraphyToolbar::save_profile(GtkWidget * /*widget*/) return; } - Glib::ustring current_profile_name = _profile_selector->get_active_text(); + Glib::ustring current_profile_name = _profile_selector_combo->get_active_text(); if (current_profile_name == _("No preset")) { current_profile_name = ""; @@ -567,14 +512,14 @@ CalligraphyToolbar::save_profile(GtkWidget * /*widget*/) CalligraphicProfileRename::show(_desktop, current_profile_name); if ( !CalligraphicProfileRename::applied()) { // dialog cancelled - update_presets_list(this); + update_presets_list(); return; } Glib::ustring new_profile_name = CalligraphicProfileRename::getProfileName(); if (new_profile_name.empty()) { // empty name entered - update_presets_list (this); + update_presets_list (); return; } @@ -620,9 +565,9 @@ CalligraphyToolbar::save_profile(GtkWidget * /*widget*/) GtkAdjustment* adj = GTK_ADJUSTMENT(widget); prefs->setDouble(save_path + "/" + widget_name, gtk_adjustment_get_value(adj)); //std::cout << "wrote adj " << widget_name << ": " << v << "\n"; - } else if (GTK_IS_TOGGLE_ACTION(widget)) { - GtkToggleAction* toggle = GTK_TOGGLE_ACTION(widget); - prefs->setBool(save_path + "/" + widget_name, gtk_toggle_action_get_active(toggle)); + } else if (GTK_IS_TOGGLE_TOOL_BUTTON(widget)) { + auto toggle = GTK_TOGGLE_TOOL_BUTTON(widget); + prefs->setBool(save_path + "/" + widget_name, gtk_toggle_tool_button_get_active(toggle)); //std::cout << "wrote tog " << widget_name << ": " << v << "\n"; } else { g_warning("Unknown widget type for preset: %s\n", widget_name.c_str()); diff --git a/src/ui/toolbar/calligraphy-toolbar.h b/src/ui/toolbar/calligraphy-toolbar.h index 2cf313948..d2168888c 100644 --- a/src/ui/toolbar/calligraphy-toolbar.h +++ b/src/ui/toolbar/calligraphy-toolbar.h @@ -31,16 +31,19 @@ #include "toolbar.h" #include <gtkmm/adjustment.h> -class InkSelectOneAction; class SPDesktop; -typedef struct _EgeAdjustmentAction EgeAdjustmentAction; -typedef struct _GtkActionGroup GtkActionGroup; -typedef struct _InkToggleAction InkToggleAction; +namespace Gtk { +class ComboBoxText; +} namespace Inkscape { namespace UI { -class PrefPusher; +class SimplePrefPusher; + +namespace Widget { +class SpinButtonToolItem; +} namespace Toolbar { @@ -48,8 +51,8 @@ class CalligraphyToolbar : public Toolbar { private: bool _presets_blocked; - EgeAdjustmentAction *_angle_action; - InkSelectOneAction *_profile_selector; + UI::Widget::SpinButtonToolItem *_angle_item; + Gtk::ComboBoxText *_profile_selector_combo; std::map<Glib::ustring, GObject *> _widget_map; @@ -61,13 +64,13 @@ private: Glib::RefPtr<Gtk::Adjustment> _tremor_adj; Glib::RefPtr<Gtk::Adjustment> _fixation_adj; Glib::RefPtr<Gtk::Adjustment> _cap_rounding_adj; - InkToggleAction *_usepressure; - InkToggleAction *_tracebackground; - InkToggleAction *_usetilt; + Gtk::ToggleToolButton *_usepressure; + Gtk::ToggleToolButton *_tracebackground; + Gtk::ToggleToolButton *_usetilt; - std::unique_ptr<PrefPusher> _tracebackground_pusher; - std::unique_ptr<PrefPusher> _usepressure_pusher; - std::unique_ptr<PrefPusher> _usetilt_pusher; + std::unique_ptr<SimplePrefPusher> _tracebackground_pusher; + std::unique_ptr<SimplePrefPusher> _usepressure_pusher; + std::unique_ptr<SimplePrefPusher> _usetilt_pusher; void width_value_changed(); void velthin_value_changed(); @@ -78,18 +81,19 @@ private: void wiggle_value_changed(); void mass_value_changed(); void build_presets_list(); - void change_profile(int mode); + void change_profile(); void save_profile(GtkWidget *widget); - - static void edit_profile(GtkAction *act, gpointer data); - static void update_presets_list(gpointer data); - static void tilt_state_changed( GtkToggleAction *act, gpointer data ); + void edit_profile(); + void update_presets_list(); + void tilt_state_changed(); + void on_pref_toggled(Gtk::ToggleToolButton *item, + const Glib::ustring& path); protected: CalligraphyToolbar(SPDesktop *desktop); public: - static GtkWidget * prep(SPDesktop *desktop, GtkActionGroup* mainActions); + static GtkWidget * create(SPDesktop *desktop); }; } diff --git a/src/ui/tools/calligraphic-tool.cpp b/src/ui/tools/calligraphic-tool.cpp index 5ce2c4813..ffe1ca46c 100644 --- a/src/ui/tools/calligraphic-tool.cpp +++ b/src/ui/tools/calligraphic-tool.cpp @@ -811,7 +811,7 @@ bool CalligraphicTool::root_handler(GdkEvent* event) { this->width += 0.01; if (this->width > 1.0) this->width = 1.0; - sp_ddc_update_toolbox (desktop, "altx-calligraphy", this->width * 100); // the same spinbutton is for alt+x + sp_ddc_update_toolbox (desktop, "calligraphy-width", this->width * 100); // the same spinbutton is for alt+x ret = TRUE; } break; @@ -821,26 +821,26 @@ bool CalligraphicTool::root_handler(GdkEvent* event) { this->width -= 0.01; if (this->width < 0.01) this->width = 0.01; - sp_ddc_update_toolbox (desktop, "altx-calligraphy", this->width * 100); + sp_ddc_update_toolbox (desktop, "calligraphy-width", this->width * 100); ret = TRUE; } break; case GDK_KEY_Home: case GDK_KEY_KP_Home: this->width = 0.01; - sp_ddc_update_toolbox (desktop, "altx-calligraphy", this->width * 100); + sp_ddc_update_toolbox (desktop, "calligraphy-width", this->width * 100); ret = TRUE; break; case GDK_KEY_End: case GDK_KEY_KP_End: this->width = 1.0; - sp_ddc_update_toolbox (desktop, "altx-calligraphy", this->width * 100); + sp_ddc_update_toolbox (desktop, "calligraphy-width", this->width * 100); ret = TRUE; break; case GDK_KEY_x: case GDK_KEY_X: if (MOD__ALT_ONLY(event)) { - desktop->setToolboxFocusTo ("altx-calligraphy"); + desktop->setToolboxFocusTo ("calligraphy-width"); ret = TRUE; } break; diff --git a/src/widgets/toolbox.cpp b/src/widgets/toolbox.cpp index 918f60c8a..87d0d5699 100644 --- a/src/widgets/toolbox.cpp +++ b/src/widgets/toolbox.cpp @@ -215,7 +215,7 @@ static struct { SP_VERB_CONTEXT_PENCIL_PREFS, "/tools/freehand/pencil", N_("Style of new paths created by Pencil")}, { "/tools/freehand/pen", "pen_toolbox", Inkscape::UI::Toolbar::PencilToolbar::create_pen, nullptr, "PenToolbar", SP_VERB_CONTEXT_PEN_PREFS, "/tools/freehand/pen", N_("Style of new paths created by Pen")}, - { "/tools/calligraphic", "calligraphy_toolbox", nullptr, Inkscape::UI::Toolbar::CalligraphyToolbar::prep,"CalligraphyToolbar", + { "/tools/calligraphic", "calligraphy_toolbox", Inkscape::UI::Toolbar::CalligraphyToolbar::create, nullptr, "CalligraphyToolbar", SP_VERB_CONTEXT_CALLIGRAPHIC_PREFS, "/tools/calligraphic", N_("Style of new calligraphic strokes")}, { "/tools/eraser", "eraser_toolbox", Inkscape::UI::Toolbar::EraserToolbar::create, nullptr, "EraserToolbar", SP_VERB_CONTEXT_ERASER_PREFS, "/tools/eraser", _("TBD")}, |
