diff options
| author | Alexander Valavanis <valavanisalex@gmail.com> | 2019-02-02 20:16:00 +0000 |
|---|---|---|
| committer | Alexander Valavanis <valavanisalex@gmail.com> | 2019-02-02 20:16:00 +0000 |
| commit | fa98857205dbaf2c15bb302e3eb28f4738fb6415 (patch) | |
| tree | 5c91217ada74209becdf97006f271b749e51d032 /src/ui | |
| parent | object properties dialog: label placeholder (diff) | |
| download | inkscape-fa98857205dbaf2c15bb302e3eb28f4738fb6415.tar.gz inkscape-fa98857205dbaf2c15bb302e3eb28f4738fb6415.zip | |
TweakToolbar: GtkAction migration
Diffstat (limited to 'src/ui')
| -rw-r--r-- | src/ui/toolbar/tweak-toolbar.cpp | 503 | ||||
| -rw-r--r-- | src/ui/toolbar/tweak-toolbar.h | 56 | ||||
| -rw-r--r-- | src/ui/tools/tweak-tool.cpp | 10 | ||||
| -rw-r--r-- | src/ui/widget/spin-button-tool-item.cpp | 7 | ||||
| -rw-r--r-- | src/ui/widget/spin-button-tool-item.h | 3 |
5 files changed, 273 insertions, 306 deletions
diff --git a/src/ui/toolbar/tweak-toolbar.cpp b/src/ui/toolbar/tweak-toolbar.cpp index d6bc11cc6..7b6025790 100644 --- a/src/ui/toolbar/tweak-toolbar.cpp +++ b/src/ui/toolbar/tweak-toolbar.cpp @@ -25,361 +25,312 @@ * Released under GNU GPL v2+, read the file 'COPYING' for more information. */ +#include "tweak-toolbar.h" + #include <glibmm/i18n.h> -#include "tweak-toolbar.h" +#include <gtkmm/radiotoolbutton.h> +#include <gtkmm/separatortoolitem.h> #include "desktop.h" #include "document-undo.h" #include "ui/icon-names.h" #include "ui/tools/tweak-tool.h" -#include "ui/widget/ink-select-one-action.h" +#include "ui/widget/label-tool-item.h" #include "ui/widget/spinbutton.h" - -#include "widgets/ege-adjustment-action.h" -#include "widgets/ege-output-action.h" -#include "widgets/ink-radio-action.h" -#include "widgets/ink-toggle-action.h" -#include "widgets/toolbox.h" - -using Inkscape::DocumentUndo; -using Inkscape::UI::ToolboxFactory; - -//######################## -//## Tweak ## -//######################## - -static void sp_tweak_pressure_state_changed( GtkToggleAction *act, gpointer /*data*/ ) -{ - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - prefs->setBool("/tools/tweak/usepressure", gtk_toggle_action_get_active(act)); -} - - -static void tweak_toggle_doh(GtkToggleAction *act, gpointer /*data*/) { - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - prefs->setBool("/tools/tweak/doh", gtk_toggle_action_get_active(act)); -} -static void tweak_toggle_dos(GtkToggleAction *act, gpointer /*data*/) { - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - prefs->setBool("/tools/tweak/dos", gtk_toggle_action_get_active(act)); -} -static void tweak_toggle_dol(GtkToggleAction *act, gpointer /*data*/) { - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - prefs->setBool("/tools/tweak/dol", gtk_toggle_action_get_active(act)); -} -static void tweak_toggle_doo(GtkToggleAction *act, gpointer /*data*/) { - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - prefs->setBool("/tools/tweak/doo", gtk_toggle_action_get_active(act)); -} +#include "ui/widget/spin-button-tool-item.h" namespace Inkscape { namespace UI { namespace Toolbar { -GtkWidget * -TweakToolbar::prep(SPDesktop *desktop, GtkActionGroup* mainActions) +TweakToolbar::TweakToolbar(SPDesktop *desktop) + : Toolbar(desktop) { - auto holder = new TweakToolbar(desktop); - - GtkIconSize secondarySize = ToolboxFactory::prefToSize("/toolbox/secondary", 1); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + /* Width */ { - /* Width */ - gchar const* labels[] = {_("(pinch tweak)"), nullptr, nullptr, nullptr, _("(default)"), nullptr, nullptr, nullptr, nullptr, _("(broad tweak)")}; - gdouble values[] = {1, 3, 5, 10, 15, 20, 30, 50, 75, 100}; - EgeAdjustmentAction *eact = create_adjustment_action( "TweakWidthAction", - _("Width"), _("Width:"), _("The width of the tweak area (relative to the visible canvas area)"), - "/tools/tweak/width", 15, - TRUE, "altx-tweak", - 1, 100, 1.0, 10.0, - labels, values, G_N_ELEMENTS(labels), - nullptr /*unit tracker*/, 0.01, 0, 100 ); - ege_adjustment_action_set_focuswidget(eact, GTK_WIDGET(desktop->canvas)); - holder->_adj_tweak_width = Glib::wrap(ege_adjustment_action_get_adjustment(eact)); - holder->_adj_tweak_width->signal_value_changed().connect(sigc::mem_fun(*holder, &TweakToolbar::tweak_width_value_changed)); - 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 ); + std::vector<Glib::ustring> labels = {_("(pinch tweak)"), "", "", "", _("(default)"), "", "", "", "", _("(broad tweak)")}; + std::vector<double> values = { 1, 3, 5, 10, 15, 20, 30, 50, 75, 100}; + + auto width_val = prefs->getDouble("/tools/tweak/width", 15); + _width_adj = Gtk::Adjustment::create(width_val * 100, 1, 100, 1.0, 10.0); + _width_item = Gtk::manage(new UI::Widget::SpinButtonToolItem("tweak-width", _("Width:"), _width_adj, 0.01, 0)); + _width_item->set_tooltip_text(_("The width of the tweak area (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, &TweakToolbar::width_value_changed)); + // ege_adjustment_action_set_appearance( eact, TOOLBAR_SLIDER_HINT ); + add(*_width_item); + _width_item->set_sensitive(true); } + // Force + { + std::vector<Glib::ustring> labels = {_("(minimum force)"), "", "", _("(default)"), "", "", "", _("(maximum force)")}; + std::vector<double> values = { 1, 5, 10, 20, 30, 50, 70, 100}; + auto force_val = prefs->getDouble("/tools/tweak/force", 20); + _force_adj = Gtk::Adjustment::create(force_val * 100, 1, 100, 1.0, 10.0); + _force_item = Gtk::manage(new UI::Widget::SpinButtonToolItem("tweak-force", _("Force:"), _force_adj, 0.01, 0)); + _force_item->set_tooltip_text(_("The force of the tweak action")); + _force_item->set_custom_numeric_menu_data(values, labels); + _force_item->set_focus_widget(Glib::wrap(GTK_WIDGET(desktop->canvas))); + _force_adj->signal_value_changed().connect(sigc::mem_fun(*this, &TweakToolbar::force_value_changed)); + // ege_adjustment_action_set_appearance( eact, TOOLBAR_SLIDER_HINT ); + add(*_force_item); + _force_item->set_sensitive(true); + } + /* Use Pressure button */ { - /* Force */ - gchar const* labels[] = {_("(minimum force)"), nullptr, nullptr, _("(default)"), nullptr, nullptr, nullptr, _("(maximum force)")}; - gdouble values[] = {1, 5, 10, 20, 30, 50, 70, 100}; - EgeAdjustmentAction *eact = create_adjustment_action( "TweakForceAction", - _("Force"), _("Force:"), _("The force of the tweak action"), - "/tools/tweak/force", 20, - TRUE, "tweak-force", - 1, 100, 1.0, 10.0, - labels, values, G_N_ELEMENTS(labels), - nullptr /*unit tracker*/, 0.01, 0, 100 ); - ege_adjustment_action_set_focuswidget(eact, GTK_WIDGET(desktop->canvas)); - holder->_adj_tweak_force = Glib::wrap(ege_adjustment_action_get_adjustment(eact)); - holder->_adj_tweak_force->signal_value_changed().connect(sigc::mem_fun(*holder, &TweakToolbar::tweak_force_value_changed)); - 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 ); + _pressure_item = add_toggle_button(_("Pressure"), + _("Use the pressure of the input device to alter the force of tweak action")); + _pressure_item->set_icon_name(INKSCAPE_ICON("draw-use-pressure")); + _pressure_item->signal_toggled().connect(sigc::mem_fun(*this, &TweakToolbar::pressure_state_changed)); + _pressure_item->set_active(prefs->getBool("/tools/tweak/usepressure", true)); } + add(* Gtk::manage(new Gtk::SeparatorToolItem())); + /* Mode */ { - InkSelectOneActionColumns columns; - - Glib::RefPtr<Gtk::ListStore> store = Gtk::ListStore::create(columns); - - Gtk::TreeModel::Row row; - - row = *(store->append()); - row[columns.col_label ] = _("Move mode"); - row[columns.col_tooltip ] = _("Move objects in any direction"); - row[columns.col_icon ] = INKSCAPE_ICON("object-tweak-push"); - row[columns.col_sensitive] = true; - - row = *(store->append()); - row[columns.col_label ] = _("Move in/out mode"); - row[columns.col_tooltip ] = _("Move objects towards cursor; with Shift from cursor"); - row[columns.col_icon ] = INKSCAPE_ICON("object-tweak-attract"); - row[columns.col_sensitive] = true; - - row = *(store->append()); - row[columns.col_label ] = _("Move jitter mode"); - row[columns.col_tooltip ] = _("Move objects in random directions"); - row[columns.col_icon ] = INKSCAPE_ICON("object-tweak-randomize"); - row[columns.col_sensitive] = true; - - row = *(store->append()); - row[columns.col_label ] = _("Scale mode"); - row[columns.col_tooltip ] = _("Shrink objects, with Shift enlarge"); - row[columns.col_icon ] = INKSCAPE_ICON("object-tweak-shrink"); - row[columns.col_sensitive] = true; - - row = *(store->append()); - row[columns.col_label ] = _("Rotate mode"); - row[columns.col_tooltip ] = _("Rotate objects, with Shift counterclockwise"); - row[columns.col_icon ] = INKSCAPE_ICON("object-tweak-rotate"); - row[columns.col_sensitive] = true; - - row = *(store->append()); - row[columns.col_label ] = _("Duplicate/delete mode"); - row[columns.col_tooltip ] = _("Duplicate objects, with Shift delete"); - row[columns.col_icon ] = INKSCAPE_ICON("object-tweak-duplicate"); - row[columns.col_sensitive] = true; - - row = *(store->append()); - row[columns.col_label ] = _("Push mode"); - row[columns.col_tooltip ] = _("Push parts of paths in any direction"); - row[columns.col_icon ] = INKSCAPE_ICON("path-tweak-push"); - row[columns.col_sensitive] = true; - - row = *(store->append()); - row[columns.col_label ] = _("Shrink/grow mode"); - row[columns.col_tooltip ] = _("Shrink (inset) parts of paths; with Shift grow (outset)"); - row[columns.col_icon ] = INKSCAPE_ICON("path-tweak-shrink"); - row[columns.col_sensitive] = true; - - row = *(store->append()); - row[columns.col_label ] = _("Attract/repel mode"); - row[columns.col_tooltip ] = _("Attract parts of paths towards cursor; with Shift from cursor"); - row[columns.col_icon ] = INKSCAPE_ICON("path-tweak-attract"); - row[columns.col_sensitive] = true; - - row = *(store->append()); - row[columns.col_label ] = _("Roughen mode"); - row[columns.col_tooltip ] = _("Roughen parts of paths"); - row[columns.col_icon ] = INKSCAPE_ICON("path-tweak-roughen"); - row[columns.col_sensitive] = true; - - row = *(store->append()); - row[columns.col_label ] = _("Color paint mode"); - row[columns.col_tooltip ] = _("Paint the tool's color upon selected objects"); - row[columns.col_icon ] = INKSCAPE_ICON("object-tweak-paint"); - row[columns.col_sensitive] = true; - - row = *(store->append()); - row[columns.col_label ] = _("Color jitter mode"); - row[columns.col_tooltip ] = _("Jitter the colors of selected objects"); - row[columns.col_icon ] = INKSCAPE_ICON("object-tweak-jitter-color"); - row[columns.col_sensitive] = true; - - row = *(store->append()); - row[columns.col_label ] = _("Blur mode"); - row[columns.col_tooltip ] = _("Blur selected objects more; with Shift, blur less"); - row[columns.col_icon ] = INKSCAPE_ICON("object-tweak-blur"); - row[columns.col_sensitive] = true; - - holder->_tweak_tool_mode = - InkSelectOneAction::create( "TweakModeAction", // Name - _("Mode"), // Label - (""), // Tooltip - "Not Used", // Icon - store ); // Tree store - - holder->_tweak_tool_mode->use_radio( true ); - holder->_tweak_tool_mode->use_icon( true ); - holder->_tweak_tool_mode->use_label( false ); - holder->_tweak_tool_mode->use_group_label( true ); - int mode = prefs->getInt("/tools/tweak/mode", 0); - holder->_tweak_tool_mode->set_active( mode ); - - gtk_action_group_add_action( mainActions, GTK_ACTION( holder->_tweak_tool_mode->gobj() )); - - holder->_tweak_tool_mode->signal_changed().connect(sigc::mem_fun(*holder, &TweakToolbar::tweak_mode_changed)); + add_label(_("Mode:")); + Gtk::RadioToolButton::Group mode_group; + + auto mode_move_btn = Gtk::manage(new Gtk::RadioToolButton(mode_group, _("Move mode"))); + mode_move_btn->set_tooltip_text(_("Move objects in any direction")); + mode_move_btn->set_icon_name(INKSCAPE_ICON("object-tweak-push")); + _mode_buttons.push_back(mode_move_btn); + + auto mode_inout_btn = Gtk::manage(new Gtk::RadioToolButton(mode_group, _("Move in/out mode"))); + mode_inout_btn->set_tooltip_text(_("Move objects towards cursor; with Shift from cursor")); + mode_inout_btn->set_icon_name(INKSCAPE_ICON("object-tweak-attract")); + _mode_buttons.push_back(mode_inout_btn); + + auto mode_jitter_btn = Gtk::manage(new Gtk::RadioToolButton(mode_group, _("Move jitter mode"))); + mode_jitter_btn->set_tooltip_text(_("Move objects in random directions")); + mode_jitter_btn->set_icon_name(INKSCAPE_ICON("object-tweak-randomize")); + _mode_buttons.push_back(mode_jitter_btn); + + auto mode_scale_btn = Gtk::manage(new Gtk::RadioToolButton(mode_group, _("Scale mode"))); + mode_scale_btn->set_tooltip_text(_("Shrink objects, with Shift enlarge")); + mode_scale_btn->set_icon_name(INKSCAPE_ICON("object-tweak-shrink")); + _mode_buttons.push_back(mode_scale_btn); + + auto mode_rotate_btn = Gtk::manage(new Gtk::RadioToolButton(mode_group, _("Rotate mode"))); + mode_rotate_btn->set_tooltip_text(_("Rotate objects, with Shift counterclockwise")); + mode_rotate_btn->set_icon_name(INKSCAPE_ICON("object-tweak-rotate")); + _mode_buttons.push_back(mode_rotate_btn); + + auto mode_dupdel_btn = Gtk::manage(new Gtk::RadioToolButton(mode_group, _("Duplicate/delete mode"))); + mode_dupdel_btn->set_tooltip_text(_("Duplicate objects, with Shift delete")); + mode_dupdel_btn->set_icon_name(INKSCAPE_ICON("object-tweak-duplicate")); + _mode_buttons.push_back(mode_dupdel_btn); + + auto mode_push_btn = Gtk::manage(new Gtk::RadioToolButton(mode_group, _("Push mode"))); + mode_push_btn->set_tooltip_text(_("Push parts of paths in any direction")); + mode_push_btn->set_icon_name(INKSCAPE_ICON("path-tweak-push")); + _mode_buttons.push_back(mode_push_btn); + + auto mode_shrinkgrow_btn = Gtk::manage(new Gtk::RadioToolButton(mode_group, _("Shrink/grow mode"))); + mode_shrinkgrow_btn->set_tooltip_text(_("Shrink (inset) parts of paths; with Shift grow (outset)")); + mode_shrinkgrow_btn->set_icon_name(INKSCAPE_ICON("path-tweak-shrink")); + _mode_buttons.push_back(mode_shrinkgrow_btn); + + auto mode_attrep_btn = Gtk::manage(new Gtk::RadioToolButton(mode_group, _("Attract/repel mode"))); + mode_attrep_btn->set_tooltip_text(_("Attract parts of paths towards cursor; with Shift from cursor")); + mode_attrep_btn->set_icon_name(INKSCAPE_ICON("path-tweak-attract")); + _mode_buttons.push_back(mode_attrep_btn); + + auto mode_roughen_btn = Gtk::manage(new Gtk::RadioToolButton(mode_group, _("Roughen mode"))); + mode_roughen_btn->set_tooltip_text(_("Roughen parts of paths")); + mode_roughen_btn->set_icon_name(INKSCAPE_ICON("path-tweak-roughen")); + _mode_buttons.push_back(mode_roughen_btn); + + auto mode_colpaint_btn = Gtk::manage(new Gtk::RadioToolButton(mode_group, _("Color paint mode"))); + mode_colpaint_btn->set_tooltip_text(_("Paint the tool's color upon selected objects")); + mode_colpaint_btn->set_icon_name(INKSCAPE_ICON("object-tweak-paint")); + _mode_buttons.push_back(mode_colpaint_btn); + + auto mode_coljitter_btn = Gtk::manage(new Gtk::RadioToolButton(mode_group, _("Color jitter mode"))); + mode_coljitter_btn->set_tooltip_text(_("Jitter the colors of selected objects")); + mode_coljitter_btn->set_icon_name(INKSCAPE_ICON("object-tweak-jitter-color")); + _mode_buttons.push_back(mode_coljitter_btn); + + auto mode_blur_btn = Gtk::manage(new Gtk::RadioToolButton(mode_group, _("Blur mode"))); + mode_blur_btn->set_tooltip_text(_("Blur selected objects more; with Shift, blur less")); + mode_blur_btn->set_icon_name(INKSCAPE_ICON("object-tweak-blur")); + _mode_buttons.push_back(mode_blur_btn); + + int btn_idx = 0; + + for (auto btn : _mode_buttons) { + btn->set_sensitive(); + add(*btn); + btn->signal_clicked().connect(sigc::bind(sigc::mem_fun(*this, &TweakToolbar::mode_changed), btn_idx++)); + } } + add(* Gtk::manage(new Gtk::SeparatorToolItem())); + guint mode = prefs->getInt("/tools/tweak/mode", 0); + /* Fidelity */ { - holder->_tweak_channels_label = ege_output_action_new( "TweakChannelsLabel", _("Channels:"), "", nullptr ); - ege_output_action_set_use_markup( holder->_tweak_channels_label, TRUE ); - gtk_action_group_add_action( mainActions, GTK_ACTION( holder->_tweak_channels_label ) ); - if (mode != Inkscape::UI::Tools::TWEAK_MODE_COLORPAINT && mode != Inkscape::UI::Tools::TWEAK_MODE_COLORJITTER) { - gtk_action_set_visible (GTK_ACTION(holder->_tweak_channels_label), FALSE); + std::vector<Glib::ustring> labels = {_("(rough, simplified)"), "", "", _("(default)"), "", "", _("(fine, but many nodes)")}; + std::vector<double> values = { 10, 25, 35, 50, 60, 80, 100}; + + auto fidelity_val = prefs->getDouble("/tools/tweak/fidelity", 50); + _fidelity_adj = Gtk::Adjustment::create(fidelity_val * 100, 1, 100, 1.0, 10.0); + _fidelity_item = Gtk::manage(new UI::Widget::SpinButtonToolItem("tweak-fidelity", _("Fidelity:"), _fidelity_adj, 0.01, 0)); + _fidelity_item->set_tooltip_text(_("Low fidelity simplifies paths; high fidelity preserves path features but may generate a lot of new nodes")); + _fidelity_item->set_custom_numeric_menu_data(values, labels); + _fidelity_item->set_focus_widget(Glib::wrap(GTK_WIDGET(desktop->canvas))); + _fidelity_adj->signal_value_changed().connect(sigc::mem_fun(*this, &TweakToolbar::fidelity_value_changed)); + add(*_fidelity_item); + _fidelity_item->set_visible(true); + if (mode == Inkscape::UI::Tools::TWEAK_MODE_COLORPAINT || mode == Inkscape::UI::Tools::TWEAK_MODE_COLORJITTER) { + _fidelity_item->set_visible(false); } } + add(* Gtk::manage(new Gtk::SeparatorToolItem())); + { - holder->_tweak_doh = ink_toggle_action_new( "TweakDoH", - _("Hue"), - _("In color mode, act on objects' hue"), - nullptr, - GTK_ICON_SIZE_MENU ); - //TRANSLATORS: "H" here stands for hue - gtk_action_set_short_label(GTK_ACTION(holder->_tweak_doh), C_("Hue", "H")); - gtk_action_group_add_action( mainActions, GTK_ACTION( holder->_tweak_doh ) ); - g_signal_connect_after( G_OBJECT(holder->_tweak_doh), "toggled", G_CALLBACK(tweak_toggle_doh), desktop ); - gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(holder->_tweak_doh), prefs->getBool("/tools/tweak/doh", true) ); + _channels_label = Gtk::manage(new UI::Widget::LabelToolItem(_("Channels:"))); + _channels_label->set_use_markup(true); + add(*_channels_label); if (mode != Inkscape::UI::Tools::TWEAK_MODE_COLORPAINT && mode != Inkscape::UI::Tools::TWEAK_MODE_COLORJITTER) { - gtk_action_set_visible (GTK_ACTION(holder->_tweak_doh), FALSE); + _channels_label->set_visible(false); } } + { - holder->_tweak_dos = ink_toggle_action_new( "TweakDoS", - _("Saturation"), - _("In color mode, act on objects' saturation"), - nullptr, - GTK_ICON_SIZE_MENU ); - //TRANSLATORS: "S" here stands for Saturation - gtk_action_set_short_label( GTK_ACTION(holder->_tweak_dos), C_("Saturation", "S")); - gtk_action_group_add_action( mainActions, GTK_ACTION( holder->_tweak_dos ) ); - g_signal_connect_after( G_OBJECT(holder->_tweak_dos), "toggled", G_CALLBACK(tweak_toggle_dos), desktop ); - gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(holder->_tweak_dos), prefs->getBool("/tools/tweak/dos", true) ); + //TRANSLATORS: "H" here stands for hue + _doh_item = add_toggle_button(C_("Hue", "H"), + _("In color mode, act on object's hue")); + _doh_item->signal_toggled().connect(sigc::mem_fun(*this, &TweakToolbar::toggle_doh)); + _doh_item->set_active(prefs->getBool("/tools/tweak/doh", true)); if (mode != Inkscape::UI::Tools::TWEAK_MODE_COLORPAINT && mode != Inkscape::UI::Tools::TWEAK_MODE_COLORJITTER) { - gtk_action_set_visible (GTK_ACTION(holder->_tweak_dos), FALSE); + _doh_item->set_visible(false); } } { - holder->_tweak_dol = ink_toggle_action_new( "TweakDoL", - _("Lightness"), - _("In color mode, act on objects' lightness"), - nullptr, - GTK_ICON_SIZE_MENU ); - //TRANSLATORS: "L" here stands for Lightness - gtk_action_set_short_label( GTK_ACTION(holder->_tweak_dol), C_("Lightness", "L")); - gtk_action_group_add_action( mainActions, GTK_ACTION( holder->_tweak_dol ) ); - g_signal_connect_after( G_OBJECT(holder->_tweak_dol), "toggled", G_CALLBACK(tweak_toggle_dol), desktop ); - gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(holder->_tweak_dol), prefs->getBool("/tools/tweak/dol", true) ); + //TRANSLATORS: "S" here stands for saturation + _dos_item = add_toggle_button(C_("Saturation", "S"), + _("In color mode, act on object's saturation")); + _dos_item->signal_toggled().connect(sigc::mem_fun(*this, &TweakToolbar::toggle_dos)); + _dos_item->set_active(prefs->getBool("/tools/tweak/dos", true)); if (mode != Inkscape::UI::Tools::TWEAK_MODE_COLORPAINT && mode != Inkscape::UI::Tools::TWEAK_MODE_COLORJITTER) { - gtk_action_set_visible (GTK_ACTION(holder->_tweak_dol), FALSE); + _dos_item->set_visible(false); } } { - holder->_tweak_doo = ink_toggle_action_new( "TweakDoO", - _("Opacity"), - _("In color mode, act on objects' opacity"), - nullptr, - GTK_ICON_SIZE_MENU ); - //TRANSLATORS: "O" here stands for Opacity - gtk_action_set_short_label( GTK_ACTION(holder->_tweak_doo), C_("Opacity", "O")); - gtk_action_group_add_action( mainActions, GTK_ACTION( holder->_tweak_doo ) ); - g_signal_connect_after( G_OBJECT(holder->_tweak_doo), "toggled", G_CALLBACK(tweak_toggle_doo), desktop ); - gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(holder->_tweak_doo), prefs->getBool("/tools/tweak/doo", true) ); + //TRANSLATORS: "S" here stands for saturation + _dol_item = add_toggle_button(C_("Lightness", "L"), + _("In color mode, act on object's lightness")); + _dol_item->signal_toggled().connect(sigc::mem_fun(*this, &TweakToolbar::toggle_dol)); + _dol_item->set_active(prefs->getBool("/tools/tweak/dol", true)); if (mode != Inkscape::UI::Tools::TWEAK_MODE_COLORPAINT && mode != Inkscape::UI::Tools::TWEAK_MODE_COLORJITTER) { - gtk_action_set_visible (GTK_ACTION(holder->_tweak_doo), FALSE); + _dol_item->set_visible(false); } } - - { /* Fidelity */ - gchar const* labels[] = {_("(rough, simplified)"), nullptr, nullptr, _("(default)"), nullptr, nullptr, _("(fine, but many nodes)")}; - gdouble values[] = {10, 25, 35, 50, 60, 80, 100}; - holder->_tweak_fidelity = create_adjustment_action( "TweakFidelityAction", - _("Fidelity"), _("Fidelity:"), - _("Low fidelity simplifies paths; high fidelity preserves path features but may generate a lot of new nodes"), - "/tools/tweak/fidelity", 50, - TRUE, "tweak-fidelity", - 1, 100, 1.0, 10.0, - labels, values, G_N_ELEMENTS(labels), - nullptr /*unit tracker*/, 0.01, 0, 100 ); - ege_adjustment_action_set_focuswidget(holder->_tweak_fidelity, GTK_WIDGET(desktop->canvas)); - holder->_adj_tweak_fidelity = Glib::wrap(ege_adjustment_action_get_adjustment(holder->_tweak_fidelity)); - holder->_adj_tweak_fidelity->signal_value_changed().connect(sigc::mem_fun(*holder, &TweakToolbar::tweak_fidelity_value_changed)); - gtk_action_group_add_action( mainActions, GTK_ACTION(holder->_tweak_fidelity) ); - gtk_action_set_visible( GTK_ACTION(holder->_tweak_fidelity), TRUE ); - if (mode == Inkscape::UI::Tools::TWEAK_MODE_COLORPAINT || mode == Inkscape::UI::Tools::TWEAK_MODE_COLORJITTER) { - gtk_action_set_visible (GTK_ACTION(holder->_tweak_fidelity), FALSE); + { + //TRANSLATORS: "O" here stands for opacity + _doo_item = add_toggle_button(C_("Opacity", "O"), + _("In color mode, act on object's opacity")); + _doo_item->signal_toggled().connect(sigc::mem_fun(*this, &TweakToolbar::toggle_doo)); + _doo_item->set_active(prefs->getBool("/tools/tweak/doo", true)); + if (mode != Inkscape::UI::Tools::TWEAK_MODE_COLORPAINT && mode != Inkscape::UI::Tools::TWEAK_MODE_COLORJITTER) { + _doo_item->set_visible(false); } } + _mode_buttons[mode]->set_active(); + show_all(); +} - /* Use Pressure button */ - { - InkToggleAction* act = ink_toggle_action_new( "TweakPressureAction", - _("Pressure"), - _("Use the pressure of the input device to alter the force of tweak action"), - INKSCAPE_ICON("draw-use-pressure"), - GTK_ICON_SIZE_MENU ); - gtk_action_group_add_action( mainActions, GTK_ACTION( act ) ); - g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(sp_tweak_pressure_state_changed), NULL); - gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/tweak/usepressure", true) ); - } - - return GTK_WIDGET(holder->gobj()); +GtkWidget * +TweakToolbar::create(SPDesktop *desktop) +{ + auto toolbar = new TweakToolbar(desktop); + return GTK_WIDGET(toolbar->gobj()); } void -TweakToolbar::tweak_width_value_changed() +TweakToolbar::width_value_changed() { - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + auto prefs = Inkscape::Preferences::get(); prefs->setDouble( "/tools/tweak/width", - _adj_tweak_width->get_value() * 0.01 ); + _width_adj->get_value() * 0.01 ); } void -TweakToolbar::tweak_force_value_changed() +TweakToolbar::force_value_changed() { - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + auto prefs = Inkscape::Preferences::get(); prefs->setDouble( "/tools/tweak/force", - _adj_tweak_force->get_value() * 0.01 ); + _force_adj->get_value() * 0.01 ); } void -TweakToolbar::tweak_mode_changed(int mode) +TweakToolbar::mode_changed(int mode) { - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + auto prefs = Inkscape::Preferences::get(); prefs->setInt("/tools/tweak/mode", mode); bool flag = ((mode == Inkscape::UI::Tools::TWEAK_MODE_COLORPAINT) || (mode == Inkscape::UI::Tools::TWEAK_MODE_COLORJITTER)); - gtk_action_set_visible(GTK_ACTION(_tweak_doh), flag); - gtk_action_set_visible(GTK_ACTION(_tweak_dos), flag); - gtk_action_set_visible(GTK_ACTION(_tweak_dol), flag); - gtk_action_set_visible(GTK_ACTION(_tweak_doo), flag); - gtk_action_set_visible(GTK_ACTION(_tweak_channels_label), flag); + _doh_item->set_visible(flag); + _dos_item->set_visible(flag); + _dol_item->set_visible(flag); + _doo_item->set_visible(flag); + _channels_label->set_visible(flag); - if (_tweak_fidelity) { - gtk_action_set_visible(GTK_ACTION(_tweak_fidelity), !flag); + if (_fidelity_item) { + _fidelity_item->set_visible(!flag); } } void -TweakToolbar::tweak_fidelity_value_changed() +TweakToolbar::fidelity_value_changed() { - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + auto prefs = Inkscape::Preferences::get(); prefs->setDouble( "/tools/tweak/fidelity", - _adj_tweak_fidelity->get_value() * 0.01 ); + _fidelity_adj->get_value() * 0.01 ); +} + +void +TweakToolbar::pressure_state_changed() +{ + auto prefs = Inkscape::Preferences::get(); + prefs->setBool("/tools/tweak/usepressure", _pressure_item->get_active()); +} + +void +TweakToolbar::toggle_doh() { + auto prefs = Inkscape::Preferences::get(); + prefs->setBool("/tools/tweak/doh", _doh_item->get_active()); +} + +void +TweakToolbar::toggle_dos() { + auto prefs = Inkscape::Preferences::get(); + prefs->setBool("/tools/tweak/dos", _dos_item->get_active()); +} + +void +TweakToolbar::toggle_dol() { + auto prefs = Inkscape::Preferences::get(); + prefs->setBool("/tools/tweak/dol", _dol_item->get_active()); +} + +void +TweakToolbar::toggle_doo() { + auto prefs = Inkscape::Preferences::get(); + prefs->setBool("/tools/tweak/doo", _doo_item->get_active()); } } diff --git a/src/ui/toolbar/tweak-toolbar.h b/src/ui/toolbar/tweak-toolbar.h index 6489bd234..8995c64e2 100644 --- a/src/ui/toolbar/tweak-toolbar.h +++ b/src/ui/toolbar/tweak-toolbar.h @@ -30,45 +30,55 @@ #include "toolbar.h" -class InkSelectOneAction; class SPDesktop; -typedef struct _EgeAdjustmentAction EgeAdjustmentAction; -typedef struct _EgeOutputAction EgeOutputAction; -typedef struct _GtkActionGroup GtkActionGroup; -typedef struct _InkToggleAction InkToggleAction; +namespace Gtk { +class RadioToolButton; +} namespace Inkscape { namespace UI { +namespace Widget { +class LabelToolItem; +class SpinButtonToolItem; +} + namespace Toolbar { class TweakToolbar : public Toolbar { private: - Glib::RefPtr<Gtk::Adjustment> _adj_tweak_width; - Glib::RefPtr<Gtk::Adjustment> _adj_tweak_force; - Glib::RefPtr<Gtk::Adjustment> _adj_tweak_fidelity; + UI::Widget::SpinButtonToolItem *_width_item; + UI::Widget::SpinButtonToolItem *_force_item; + UI::Widget::SpinButtonToolItem *_fidelity_item; + + Gtk::ToggleToolButton *_pressure_item; - InkSelectOneAction *_tweak_tool_mode; + Glib::RefPtr<Gtk::Adjustment> _width_adj; + Glib::RefPtr<Gtk::Adjustment> _force_adj; + Glib::RefPtr<Gtk::Adjustment> _fidelity_adj; - EgeOutputAction *_tweak_channels_label; - InkToggleAction *_tweak_doh; - InkToggleAction *_tweak_dos; - InkToggleAction *_tweak_dol; - InkToggleAction *_tweak_doo; + std::vector<Gtk::RadioToolButton *> _mode_buttons; - EgeAdjustmentAction *_tweak_fidelity; + UI::Widget::LabelToolItem *_channels_label; + Gtk::ToggleToolButton *_doh_item; + Gtk::ToggleToolButton *_dos_item; + Gtk::ToggleToolButton *_dol_item; + Gtk::ToggleToolButton *_doo_item; - void tweak_width_value_changed(); - void tweak_force_value_changed(); - void tweak_mode_changed(int mode); - void tweak_fidelity_value_changed(); + void width_value_changed(); + void force_value_changed(); + void mode_changed(int mode); + void fidelity_value_changed(); + void pressure_state_changed(); + void toggle_doh(); + void toggle_dos(); + void toggle_dol(); + void toggle_doo(); protected: - TweakToolbar(SPDesktop *_desktop) - : Toolbar(_desktop) - {} + TweakToolbar(SPDesktop *desktop); public: - static GtkWidget * prep(SPDesktop *desktop, GtkActionGroup* mainActions); + static GtkWidget * create(SPDesktop *desktop); }; } } diff --git a/src/ui/tools/tweak-tool.cpp b/src/ui/tools/tweak-tool.cpp index d8db9ceaf..b8cf5549c 100644 --- a/src/ui/tools/tweak-tool.cpp +++ b/src/ui/tools/tweak-tool.cpp @@ -1416,7 +1416,7 @@ bool TweakTool::root_handler(GdkEvent* event) { if (this->width > 1.0) { this->width = 1.0; } - desktop->setToolboxAdjustmentValue ("altx-tweak", this->width * 100); // the same spinbutton is for alt+x + desktop->setToolboxAdjustmentValue ("tweak-width", this->width * 100); // the same spinbutton is for alt+x sp_tweak_update_area(this); ret = TRUE; } @@ -1428,7 +1428,7 @@ bool TweakTool::root_handler(GdkEvent* event) { if (this->width < 0.01) { this->width = 0.01; } - desktop->setToolboxAdjustmentValue ("altx-tweak", this->width * 100); + desktop->setToolboxAdjustmentValue ("tweak-width", this->width * 100); sp_tweak_update_area(this); ret = TRUE; } @@ -1436,21 +1436,21 @@ bool TweakTool::root_handler(GdkEvent* event) { case GDK_KEY_Home: case GDK_KEY_KP_Home: this->width = 0.01; - desktop->setToolboxAdjustmentValue ("altx-tweak", this->width * 100); + desktop->setToolboxAdjustmentValue ("tweak-width", this->width * 100); sp_tweak_update_area(this); ret = TRUE; break; case GDK_KEY_End: case GDK_KEY_KP_End: this->width = 1.0; - desktop->setToolboxAdjustmentValue ("altx-tweak", this->width * 100); + desktop->setToolboxAdjustmentValue ("tweak-width", this->width * 100); sp_tweak_update_area(this); ret = TRUE; break; case GDK_KEY_x: case GDK_KEY_X: if (MOD__ALT_ONLY(event)) { - desktop->setToolboxFocusTo ("altx-tweak"); + desktop->setToolboxFocusTo ("tweak-width"); ret = TRUE; } break; diff --git a/src/ui/widget/spin-button-tool-item.cpp b/src/ui/widget/spin-button-tool-item.cpp index 140df1586..b5eefdbb1 100644 --- a/src/ui/widget/spin-button-tool-item.cpp +++ b/src/ui/widget/spin-button-tool-item.cpp @@ -359,7 +359,7 @@ SpinButtonToolItem::SpinButtonToolItem(const Glib::ustring name, const Glib::ustring& label_text, Glib::RefPtr<Gtk::Adjustment>& adjustment, double climb_rate, - double digits) + int digits) : _btn(Gtk::manage(new SpinButton(adjustment, climb_rate, digits))), _name(std::move(name)), _label_text(label_text), @@ -505,6 +505,11 @@ SpinButtonToolItem::set_custom_numeric_menu_data(std::vector<double>& } } +Glib::RefPtr<Gtk::Adjustment> +SpinButtonToolItem::get_adjustment() +{ + return _btn->get_adjustment(); +} } // namespace Widget } // namespace UI } // namespace Inkscape diff --git a/src/ui/widget/spin-button-tool-item.h b/src/ui/widget/spin-button-tool-item.h index 2dd0b2172..4d3b75250 100644 --- a/src/ui/widget/spin-button-tool-item.h +++ b/src/ui/widget/spin-button-tool-item.h @@ -67,7 +67,7 @@ public: const Glib::ustring& label_text, Glib::RefPtr<Gtk::Adjustment>& adjustment, double climb_rate = 0.1, - double digits = 3); + int digits = 3); void set_all_tooltip_text(const Glib::ustring& text); void set_focus_widget(Gtk::Widget *widget); @@ -75,6 +75,7 @@ public: void set_custom_numeric_menu_data(std::vector<double>& values, const std::vector<Glib::ustring>& labels = std::vector<Glib::ustring>()); + Glib::RefPtr<Gtk::Adjustment> get_adjustment(); }; } // namespace Widget } // namespace UI |
