summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAlexander Valavanis <valavanisalex@gmail.com>2019-01-27 14:24:01 +0000
committerAlexander Valavanis <valavanisalex@gmail.com>2019-01-27 14:24:01 +0000
commited037b19105f01b4b7cb4d5b79b4daeb57a25884 (patch)
tree2c85b5ab0f111250778ecc8b3dfaa7b153719362 /src
parentSpinButtonToolItem: Allow custom numeric menu items (diff)
downloadinkscape-ed037b19105f01b4b7cb4d5b79b4daeb57a25884.tar.gz
inkscape-ed037b19105f01b4b7cb4d5b79b4daeb57a25884.zip
SpinButtonToolItem: Allow default numeric menu descriptions & migrate RectToolbar
Diffstat (limited to 'src')
-rw-r--r--src/ui/toolbar/rect-toolbar.cpp29
-rw-r--r--src/ui/widget/spin-button-tool-item.cpp13
-rw-r--r--src/ui/widget/spin-button-tool-item.h4
3 files changed, 21 insertions, 25 deletions
diff --git a/src/ui/toolbar/rect-toolbar.cpp b/src/ui/toolbar/rect-toolbar.cpp
index e4caae189..019cc138d 100644
--- a/src/ui/toolbar/rect-toolbar.cpp
+++ b/src/ui/toolbar/rect-toolbar.cpp
@@ -104,12 +104,8 @@ RectToolbar::RectToolbar(SPDesktop *desktop)
_tracker->addAdjustment(_width_adj->gobj());
_width_item->set_sensitive(false);
- gchar const* labels[] = {nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr};
- gdouble values[] = {1, 2, 3, 5, 10, 20, 50, 100, 200, 500};
-
- // holder->_width_action = create_adjustment_action( "RectWidthAction",
- // _("Width"), _("W:"),
- // labels, values, G_N_ELEMENTS(labels),
+ std::vector<double> values = {1, 2, 3, 5, 10, 20, 50, 100, 200, 500};
+ _width_item->set_custom_numeric_menu_data(values);
}
/* H */
@@ -123,21 +119,18 @@ RectToolbar::RectToolbar(SPDesktop *desktop)
&SPRect::setVisibleHeight));
_tracker->addAdjustment(_height_adj->gobj());
- gchar const* labels[] = {nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr};
- gdouble values[] = {1, 2, 3, 5, 10, 20, 50, 100, 200, 500};
+ std::vector<double> values = { 1, 2, 3, 5, 10, 20, 50, 100, 200, 500};
_height_item = Gtk::manage(new UI::Widget::SpinButtonToolItem("rect-height", _("H:"), _height_adj));
+ _height_item->set_custom_numeric_menu_data(values);
_height_item->set_all_tooltip_text(_("Height of rectangle"));
_height_item->set_focus_widget(Glib::wrap(GTK_WIDGET(desktop->canvas)));
_height_item->set_sensitive(false);
-
-// holder->_height_action = create_adjustment_action( "RectHeightAction",
- // labels, values, G_N_ELEMENTS(labels),
}
/* rx */
{
- gchar const* labels[] = {_("not rounded"), nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr};
- gdouble values[] = {0.5, 1, 2, 3, 5, 10, 20, 50, 100};
+ std::vector<Glib::ustring> labels = {_("not rounded"), "", "", "", "", "", "", "", ""};
+ std::vector<double> values = { 0.5, 1, 2, 3, 5, 10, 20, 50, 100};
auto rx_val = prefs->getDouble("/tools/shapes/rect/rx", 0);
_rx_adj = Gtk::Adjustment::create(rx_val, 0, 1e6, SPIN_STEP, SPIN_PAGE_STEP);
_rx_adj->signal_value_changed().connect(sigc::bind(sigc::mem_fun(*this, &RectToolbar::value_changed),
@@ -148,14 +141,13 @@ RectToolbar::RectToolbar(SPDesktop *desktop)
_rx_item = Gtk::manage(new UI::Widget::SpinButtonToolItem("rect-rx", _("Rx:"), _rx_adj));
_rx_item->set_all_tooltip_text(_("Horizontal radius of rounded corners"));
_rx_item->set_focus_widget(Glib::wrap(GTK_WIDGET(_desktop->canvas)));
-// eact = create_adjustment_action( "RadiusXAction",
-// labels, values, G_N_ELEMENTS(labels),
+ _rx_item->set_custom_numeric_menu_data(values, labels);
}
/* ry */
{
- gchar const* labels[] = {_("not rounded"), nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr};
- gdouble values[] = {0.5, 1, 2, 3, 5, 10, 20, 50, 100};
+ std::vector<Glib::ustring> labels = {_("not rounded"), "", "", "", "", "", "", "", ""};
+ std::vector<double> values = { 0.5, 1, 2, 3, 5, 10, 20, 50, 100};
auto ry_val = prefs->getDouble("/tools/shapes/rect/ry", 0);
_ry_adj = Gtk::Adjustment::create(ry_val, 0, 1e6, SPIN_STEP, SPIN_PAGE_STEP);
_ry_adj->signal_value_changed().connect(sigc::bind(sigc::mem_fun(*this, &RectToolbar::value_changed),
@@ -166,8 +158,7 @@ RectToolbar::RectToolbar(SPDesktop *desktop)
_ry_item = Gtk::manage(new UI::Widget::SpinButtonToolItem("rect-ry", _("Ry:"), _ry_adj));
_ry_item->set_all_tooltip_text(_("Vertical radius of rounded corners"));
_ry_item->set_focus_widget(Glib::wrap(GTK_WIDGET(_desktop->canvas)));
- //eact = create_adjustment_action( "RadiusYAction",
- // labels, values, G_N_ELEMENTS(labels),
+ _ry_item->set_custom_numeric_menu_data(values, labels);
}
// add the units menu
diff --git a/src/ui/widget/spin-button-tool-item.cpp b/src/ui/widget/spin-button-tool-item.cpp
index ecca051a4..2efb24ff9 100644
--- a/src/ui/widget/spin-button-tool-item.cpp
+++ b/src/ui/widget/spin-button-tool-item.cpp
@@ -484,10 +484,10 @@ SpinButtonToolItem::grab_button_focus()
}
void
-SpinButtonToolItem::set_custom_numeric_menu_items(std::vector<double>& values,
- std::vector<Glib::ustring>& labels)
+SpinButtonToolItem::set_custom_numeric_menu_data(std::vector<double>& values,
+ const std::vector<Glib::ustring>& labels)
{
- if(values.size() != labels.size()) {
+ if(values.size() != labels.size() && !labels.empty()) {
g_warning("Cannot add custom menu items. Value and label arrays are different sizes");
return;
}
@@ -497,7 +497,12 @@ SpinButtonToolItem::set_custom_numeric_menu_items(std::vector<double>& va
int i = 0;
for (auto value : values) {
- _custom_menu_data.push_back(std::make_pair(value, labels[i++]));
+ if(labels.empty()) {
+ _custom_menu_data.push_back(std::make_pair(value, ""));
+ }
+ else {
+ _custom_menu_data.push_back(std::make_pair(value, labels[i++]));
+ }
}
}
diff --git a/src/ui/widget/spin-button-tool-item.h b/src/ui/widget/spin-button-tool-item.h
index 90667da54..2dd0b2172 100644
--- a/src/ui/widget/spin-button-tool-item.h
+++ b/src/ui/widget/spin-button-tool-item.h
@@ -73,8 +73,8 @@ public:
void set_focus_widget(Gtk::Widget *widget);
void grab_button_focus();
- void set_custom_numeric_menu_items(std::vector<double>& values,
- std::vector<Glib::ustring>& labels);
+ void set_custom_numeric_menu_data(std::vector<double>& values,
+ const std::vector<Glib::ustring>& labels = std::vector<Glib::ustring>());
};
} // namespace Widget
} // namespace UI