From 9dc7b786c9ef31060012ea4ae13a8188548b4f62 Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Tue, 9 Jul 2013 16:42:04 -0400 Subject: Ported sp-namedview.cpp (todo: fix a bunch of things). (bzr r12380.1.8) --- src/ui/dialog/clonetiler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/ui/dialog/clonetiler.cpp') diff --git a/src/ui/dialog/clonetiler.cpp b/src/ui/dialog/clonetiler.cpp index 753320ab9..00bb6f0e2 100644 --- a/src/ui/dialog/clonetiler.cpp +++ b/src/ui/dialog/clonetiler.cpp @@ -1093,7 +1093,7 @@ CloneTiler::CloneTiler (void) : // unitmenu GtkWidget *u = sp_unit_selector_new (SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE); - sp_unit_selector_set_unit (SP_UNIT_SELECTOR(u), sp_desktop_namedview(SP_ACTIVE_DESKTOP)->doc_units); + //sp_unit_selector_set_unit (SP_UNIT_SELECTOR(u), sp_desktop_namedview(SP_ACTIVE_DESKTOP)->doc_units); { // Width spinbutton -- cgit v1.2.3 From ce25410db81c6a22a6b841efdb4790f7f19319ec Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Thu, 18 Jul 2013 10:39:48 -0400 Subject: Ported "ui/dialog/clonetiler.*". (bzr r12380.1.23) --- src/ui/dialog/clonetiler.cpp | 86 +++++++++++++++++++++++++++----------------- 1 file changed, 54 insertions(+), 32 deletions(-) (limited to 'src/ui/dialog/clonetiler.cpp') diff --git a/src/ui/dialog/clonetiler.cpp b/src/ui/dialog/clonetiler.cpp index 00bb6f0e2..d270afc3f 100644 --- a/src/ui/dialog/clonetiler.cpp +++ b/src/ui/dialog/clonetiler.cpp @@ -34,8 +34,8 @@ #include "document.h" #include "document-undo.h" #include "filter-chemistry.h" -#include "helper/unit-menu.h" -#include "helper/units.h" +#include "ui/widget/unit-menu.h" +#include "util/units.h" #include "helper/window.h" #include "inkscape.h" #include "interface.h" @@ -1092,35 +1092,38 @@ CloneTiler::CloneTiler (void) : g_object_set_data (G_OBJECT(dlg), "widthheight", (gpointer) hb); // unitmenu - GtkWidget *u = sp_unit_selector_new (SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE); - //sp_unit_selector_set_unit (SP_UNIT_SELECTOR(u), sp_desktop_namedview(SP_ACTIVE_DESKTOP)->doc_units); + unit_menu = new Inkscape::UI::Widget::UnitMenu(); + unit_menu->setUnitType(Inkscape::Util::UNIT_TYPE_LINEAR); + unit_menu->setUnit(sp_desktop_namedview(SP_ACTIVE_DESKTOP)->doc_units->abbr); + unitChangedConn = unit_menu->signal_changed().connect(sigc::mem_fun(*this, &CloneTiler::clonetiler_unit_changed)); { // Width spinbutton #if WITH_GTKMM_3_0 - Glib::RefPtr a = Gtk::Adjustment::create(0.0, -1e6, 1e6, 1.0, 10.0, 0); + fill_width = Gtk::Adjustment::create(0.0, -1e6, 1e6, 1.0, 10.0, 0); #else - Gtk::Adjustment *a = new Gtk::Adjustment (0.0, -1e6, 1e6, 1.0, 10.0, 0); + fill_width = new Gtk::Adjustment (0.0, -1e6, 1e6, 1.0, 10.0, 0); #endif - sp_unit_selector_add_adjustment (SP_UNIT_SELECTOR (u), GTK_ADJUSTMENT (a->gobj())); double value = prefs->getDouble(prefs_path + "fillwidth", 50.0); - SPUnit const &unit = *sp_unit_selector_get_unit(SP_UNIT_SELECTOR(u)); - gdouble const units = sp_pixels_get_units (value, unit); - a->set_value (units); + Inkscape::Util::Unit const unit = unit_menu->getUnit(); + Inkscape::Util::UnitTable unit_table; + Inkscape::Util::Unit const px = unit_table.getUnit("px"); + gdouble const units = Inkscape::Util::Quantity::convert(value, &px, &unit); + fill_width->set_value (units); #if WITH_GTKMM_3_0 - Inkscape::UI::Widget::SpinButton *e = new Inkscape::UI::Widget::SpinButton(a, 1.0, 2); + Inkscape::UI::Widget::SpinButton *e = new Inkscape::UI::Widget::SpinButton(fill_width, 1.0, 2); #else - Inkscape::UI::Widget::SpinButton *e = new Inkscape::UI::Widget::SpinButton (*a, 1.0, 2); + Inkscape::UI::Widget::SpinButton *e = new Inkscape::UI::Widget::SpinButton (*fill_width, 1.0, 2); #endif e->set_tooltip_text (_("Width of the rectangle to be filled")); e->set_width_chars (7); e->set_digits (4); gtk_box_pack_start (GTK_BOX (hb), GTK_WIDGET(e->gobj()), TRUE, TRUE, 0); // TODO: C++ification - g_signal_connect(G_OBJECT(a->gobj()), "value_changed", - G_CALLBACK(clonetiler_fill_width_changed), u); + g_signal_connect(G_OBJECT(fill_width->gobj()), "value_changed", + G_CALLBACK(clonetiler_fill_width_changed), unit_menu); } { GtkWidget *l = gtk_label_new (""); @@ -1132,32 +1135,33 @@ CloneTiler::CloneTiler (void) : { // Height spinbutton #if WITH_GTKMM_3_0 - Glib::RefPtr a = Gtk::Adjustment::create(0.0, -1e6, 1e6, 1.0, 10.0, 0); + fill_height = Gtk::Adjustment::create(0.0, -1e6, 1e6, 1.0, 10.0, 0); #else - Gtk::Adjustment *a = new Gtk::Adjustment (0.0, -1e6, 1e6, 1.0, 10.0, 0); + fill_height = new Gtk::Adjustment (0.0, -1e6, 1e6, 1.0, 10.0, 0); #endif - sp_unit_selector_add_adjustment (SP_UNIT_SELECTOR (u), GTK_ADJUSTMENT (a->gobj())); double value = prefs->getDouble(prefs_path + "fillheight", 50.0); - SPUnit const &unit = *sp_unit_selector_get_unit(SP_UNIT_SELECTOR(u)); - gdouble const units = sp_pixels_get_units (value, unit); - a->set_value (units); + Inkscape::Util::Unit const unit = unit_menu->getUnit(); + Inkscape::Util::UnitTable unit_table; + Inkscape::Util::Unit const px = unit_table.getUnit("px"); + gdouble const units = Inkscape::Util::Quantity::convert(value, &px, &unit); + fill_height->set_value (units); #if WITH_GTKMM_3_0 - Inkscape::UI::Widget::SpinButton *e = new Inkscape::UI::Widget::SpinButton(a, 1.0, 2); + Inkscape::UI::Widget::SpinButton *e = new Inkscape::UI::Widget::SpinButton(fill_height, 1.0, 2); #else - Inkscape::UI::Widget::SpinButton *e = new Inkscape::UI::Widget::SpinButton (*a, 1.0, 2); + Inkscape::UI::Widget::SpinButton *e = new Inkscape::UI::Widget::SpinButton (*fill_height, 1.0, 2); #endif e->set_tooltip_text (_("Height of the rectangle to be filled")); e->set_width_chars (7); e->set_digits (4); gtk_box_pack_start (GTK_BOX (hb), GTK_WIDGET(e->gobj()), TRUE, TRUE, 0); // TODO: C++ification - g_signal_connect(G_OBJECT(a->gobj()), "value_changed", - G_CALLBACK(clonetiler_fill_height_changed), u); + g_signal_connect(G_OBJECT(fill_height->gobj()), "value_changed", + G_CALLBACK(clonetiler_fill_height_changed), unit_menu); } - gtk_box_pack_start (GTK_BOX (hb), u, TRUE, TRUE, 0); + gtk_box_pack_start (GTK_BOX (hb), (GtkWidget*) unit_menu->gobj(), TRUE, TRUE, 0); clonetiler_table_attach (table, hb, 0.0, 2, 2); } @@ -2944,26 +2948,45 @@ void CloneTiler::clonetiler_switch_to_fill(GtkToggleButton * /*tb*/, GtkWidget * -void CloneTiler::clonetiler_fill_width_changed(GtkAdjustment *adj, GtkWidget *u) +void CloneTiler::clonetiler_fill_width_changed(GtkAdjustment *adj, Inkscape::UI::Widget::UnitMenu *u) { gdouble const raw_dist = gtk_adjustment_get_value (adj); - SPUnit const &unit = *sp_unit_selector_get_unit(SP_UNIT_SELECTOR(u)); - gdouble const pixels = sp_units_get_pixels (raw_dist, unit); + Inkscape::Util::Unit const unit = u->getUnit(); + Inkscape::Util::UnitTable unit_table; + Inkscape::Util::Unit const px = unit_table.getUnit("px"); + gdouble const pixels = Inkscape::Util::Quantity::convert(raw_dist, &unit, &px); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); prefs->setDouble(prefs_path + "fillwidth", pixels); } -void CloneTiler::clonetiler_fill_height_changed(GtkAdjustment *adj, GtkWidget *u) +void CloneTiler::clonetiler_fill_height_changed(GtkAdjustment *adj, Inkscape::UI::Widget::UnitMenu *u) { gdouble const raw_dist = gtk_adjustment_get_value (adj); - SPUnit const &unit = *sp_unit_selector_get_unit(SP_UNIT_SELECTOR(u)); - gdouble const pixels = sp_units_get_pixels (raw_dist, unit); + Inkscape::Util::Unit const unit = u->getUnit(); + Inkscape::Util::UnitTable unit_table; + Inkscape::Util::Unit const px = unit_table.getUnit("px"); + gdouble const pixels = Inkscape::Util::Quantity::convert(raw_dist, &unit, &px); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); prefs->setDouble(prefs_path + "fillheight", pixels); } +void CloneTiler::clonetiler_unit_changed() +{ + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + gdouble width_pixels = prefs->getDouble(prefs_path + "fillwidth"); + gdouble height_pixels = prefs->getDouble(prefs_path + "fillheight"); + + Inkscape::Util::Unit unit = unit_menu->getUnit(); + Inkscape::Util::UnitTable unit_table; + Inkscape::Util::Unit px = unit_table.getUnit("px"); + + gdouble width_value = Inkscape::Util::Quantity::convert(width_pixels, &px, &unit); + gdouble height_value = Inkscape::Util::Quantity::convert(height_pixels, &px, &unit); + gtk_adjustment_set_value(fill_width->gobj(), width_value); + gtk_adjustment_set_value(fill_height->gobj(), height_value); +} void CloneTiler::clonetiler_do_pick_toggled(GtkToggleButton *tb, GtkWidget *dlg) { @@ -2977,7 +3000,6 @@ void CloneTiler::clonetiler_do_pick_toggled(GtkToggleButton *tb, GtkWidget *dlg) } } - } } } -- cgit v1.2.3 From 3772fc428950b2b946a1bd7c7c97e06219c3165f Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Thu, 18 Jul 2013 17:21:24 -0400 Subject: Switch unit functions from using pointer arguements to reference arguements. (bzr r12380.1.28) --- src/ui/dialog/clonetiler.cpp | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) (limited to 'src/ui/dialog/clonetiler.cpp') diff --git a/src/ui/dialog/clonetiler.cpp b/src/ui/dialog/clonetiler.cpp index d270afc3f..abb2512f7 100644 --- a/src/ui/dialog/clonetiler.cpp +++ b/src/ui/dialog/clonetiler.cpp @@ -1108,8 +1108,7 @@ CloneTiler::CloneTiler (void) : double value = prefs->getDouble(prefs_path + "fillwidth", 50.0); Inkscape::Util::Unit const unit = unit_menu->getUnit(); Inkscape::Util::UnitTable unit_table; - Inkscape::Util::Unit const px = unit_table.getUnit("px"); - gdouble const units = Inkscape::Util::Quantity::convert(value, &px, &unit); + gdouble const units = Inkscape::Util::Quantity::convert(value, "px", unit); fill_width->set_value (units); #if WITH_GTKMM_3_0 @@ -1143,8 +1142,7 @@ CloneTiler::CloneTiler (void) : double value = prefs->getDouble(prefs_path + "fillheight", 50.0); Inkscape::Util::Unit const unit = unit_menu->getUnit(); Inkscape::Util::UnitTable unit_table; - Inkscape::Util::Unit const px = unit_table.getUnit("px"); - gdouble const units = Inkscape::Util::Quantity::convert(value, &px, &unit); + gdouble const units = Inkscape::Util::Quantity::convert(value, "px", unit); fill_height->set_value (units); #if WITH_GTKMM_3_0 @@ -2953,8 +2951,7 @@ void CloneTiler::clonetiler_fill_width_changed(GtkAdjustment *adj, Inkscape::UI: gdouble const raw_dist = gtk_adjustment_get_value (adj); Inkscape::Util::Unit const unit = u->getUnit(); Inkscape::Util::UnitTable unit_table; - Inkscape::Util::Unit const px = unit_table.getUnit("px"); - gdouble const pixels = Inkscape::Util::Quantity::convert(raw_dist, &unit, &px); + gdouble const pixels = Inkscape::Util::Quantity::convert(raw_dist, unit, "px"); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); prefs->setDouble(prefs_path + "fillwidth", pixels); @@ -2965,8 +2962,7 @@ void CloneTiler::clonetiler_fill_height_changed(GtkAdjustment *adj, Inkscape::UI gdouble const raw_dist = gtk_adjustment_get_value (adj); Inkscape::Util::Unit const unit = u->getUnit(); Inkscape::Util::UnitTable unit_table; - Inkscape::Util::Unit const px = unit_table.getUnit("px"); - gdouble const pixels = Inkscape::Util::Quantity::convert(raw_dist, &unit, &px); + gdouble const pixels = Inkscape::Util::Quantity::convert(raw_dist, unit, "px"); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); prefs->setDouble(prefs_path + "fillheight", pixels); @@ -2980,10 +2976,9 @@ void CloneTiler::clonetiler_unit_changed() Inkscape::Util::Unit unit = unit_menu->getUnit(); Inkscape::Util::UnitTable unit_table; - Inkscape::Util::Unit px = unit_table.getUnit("px"); - gdouble width_value = Inkscape::Util::Quantity::convert(width_pixels, &px, &unit); - gdouble height_value = Inkscape::Util::Quantity::convert(height_pixels, &px, &unit); + gdouble width_value = Inkscape::Util::Quantity::convert(width_pixels, "px", unit); + gdouble height_value = Inkscape::Util::Quantity::convert(height_pixels, "px", unit); gtk_adjustment_set_value(fill_width->gobj(), width_value); gtk_adjustment_set_value(fill_height->gobj(), height_value); } -- cgit v1.2.3 From 6ae6c0bea96eef09907091279e0678aa5f83102d Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Sun, 4 Aug 2013 18:01:18 -0400 Subject: Switched to global UnitTable. (bzr r12380.1.62) --- src/ui/dialog/clonetiler.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'src/ui/dialog/clonetiler.cpp') diff --git a/src/ui/dialog/clonetiler.cpp b/src/ui/dialog/clonetiler.cpp index abb2512f7..b3675440b 100644 --- a/src/ui/dialog/clonetiler.cpp +++ b/src/ui/dialog/clonetiler.cpp @@ -58,6 +58,7 @@ #include "sp-root.h" using Inkscape::DocumentUndo; +using Inkscape::Util::unit_table; namespace Inkscape { namespace UI { @@ -1107,7 +1108,6 @@ CloneTiler::CloneTiler (void) : double value = prefs->getDouble(prefs_path + "fillwidth", 50.0); Inkscape::Util::Unit const unit = unit_menu->getUnit(); - Inkscape::Util::UnitTable unit_table; gdouble const units = Inkscape::Util::Quantity::convert(value, "px", unit); fill_width->set_value (units); @@ -1141,7 +1141,6 @@ CloneTiler::CloneTiler (void) : double value = prefs->getDouble(prefs_path + "fillheight", 50.0); Inkscape::Util::Unit const unit = unit_menu->getUnit(); - Inkscape::Util::UnitTable unit_table; gdouble const units = Inkscape::Util::Quantity::convert(value, "px", unit); fill_height->set_value (units); @@ -2950,7 +2949,6 @@ void CloneTiler::clonetiler_fill_width_changed(GtkAdjustment *adj, Inkscape::UI: { gdouble const raw_dist = gtk_adjustment_get_value (adj); Inkscape::Util::Unit const unit = u->getUnit(); - Inkscape::Util::UnitTable unit_table; gdouble const pixels = Inkscape::Util::Quantity::convert(raw_dist, unit, "px"); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); @@ -2961,7 +2959,6 @@ void CloneTiler::clonetiler_fill_height_changed(GtkAdjustment *adj, Inkscape::UI { gdouble const raw_dist = gtk_adjustment_get_value (adj); Inkscape::Util::Unit const unit = u->getUnit(); - Inkscape::Util::UnitTable unit_table; gdouble const pixels = Inkscape::Util::Quantity::convert(raw_dist, unit, "px"); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); @@ -2975,7 +2972,6 @@ void CloneTiler::clonetiler_unit_changed() gdouble height_pixels = prefs->getDouble(prefs_path + "fillheight"); Inkscape::Util::Unit unit = unit_menu->getUnit(); - Inkscape::Util::UnitTable unit_table; gdouble width_value = Inkscape::Util::Quantity::convert(width_pixels, "px", unit); gdouble height_value = Inkscape::Util::Quantity::convert(height_pixels, "px", unit); -- cgit v1.2.3