summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMatthew Petroff <matthew@mpetroff.net>2013-07-19 19:48:48 +0000
committerMatthew Petroff <matthew@mpetroff.net>2013-07-19 19:48:48 +0000
commit4f6415189dc97ccb8b8dfaa5ad515b56dd72de0f (patch)
treecbca786ef7899e318ea87882404557d704dde254 /src
parentRemoved "helper/units.h" from "pen-context.cpp". (diff)
downloadinkscape-4f6415189dc97ccb8b8dfaa5ad515b56dd72de0f.tar.gz
inkscape-4f6415189dc97ccb8b8dfaa5ad515b56dd72de0f.zip
Ported "ui/widget/selected-style.*".
(bzr r12380.1.39)
Diffstat (limited to 'src')
-rw-r--r--src/desktop.cpp1
-rw-r--r--src/ui/widget/selected-style.cpp29
-rw-r--r--src/ui/widget/selected-style.h11
-rw-r--r--src/widgets/desktop-widget.cpp5
4 files changed, 26 insertions, 20 deletions
diff --git a/src/desktop.cpp b/src/desktop.cpp
index ce740f76f..13e339abe 100644
--- a/src/desktop.cpp
+++ b/src/desktop.cpp
@@ -54,7 +54,6 @@
#include "document.h"
#include "event-log.h"
#include "helper/action-context.h"
-#include "helper/units.h"
#include "interface.h"
#include "inkscape-private.h"
#include "layer-fns.h"
diff --git a/src/ui/widget/selected-style.cpp b/src/ui/widget/selected-style.cpp
index 102132158..edf53d25c 100644
--- a/src/ui/widget/selected-style.cpp
+++ b/src/ui/widget/selected-style.cpp
@@ -50,6 +50,7 @@
#include "pixmaps/cursor-adj-a.xpm"
#include "sp-cursor.h"
#include "gradient-chemistry.h"
+#include "util/units.h"
static gdouble const _sw_presets[] = { 32 , 16 , 10 , 8 , 6 , 4 , 3 , 2 , 1.5 , 1 , 0.75 , 0.5 , 0.25 , 0.1 };
static gchar const *const _sw_presets_str[] = {"32", "16", "10", "8", "6", "4", "3", "2", "1.5", "1", "0.75", "0.5", "0.25", "0.1"};
@@ -306,15 +307,18 @@ SelectedStyle::SelectedStyle(bool /*layout*/)
{
int row = 0;
- // List of units should match with Fill/Stroke dialog stroke style width list
- for (GSList *l = sp_unit_get_list(SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE); l != NULL; l = l->next) {
- SPUnit const *u = static_cast<SPUnit*>(l->data);
+ Inkscape::Util::UnitTable unit_table;
+ Inkscape::Util::UnitTable::UnitMap m = unit_table.units(Inkscape::Util::UNIT_TYPE_LINEAR);
+ Inkscape::Util::UnitTable::UnitMap::iterator iter = m.begin();
+ while(iter != m.end()) {
Gtk::RadioMenuItem *mi = Gtk::manage(new Gtk::RadioMenuItem(_sw_group));
- mi->add(*(new Gtk::Label(u->abbr, 0.0, 0.5)));
+ mi->add(*(new Gtk::Label((*iter).first, 0.0, 0.5)));
_unit_mis = g_slist_append(_unit_mis, mi);
- mi->signal_activate().connect(sigc::bind<SPUnitId>(sigc::mem_fun(*this, &SelectedStyle::on_popup_units), u->unit_id));
+ Inkscape::Util::Unit const *u = new Inkscape::Util::Unit(unit_table.getUnit(iter->first));
+ mi->signal_activate().connect(sigc::bind<Inkscape::Util::Unit>(sigc::mem_fun(*this, &SelectedStyle::on_popup_units), *u));
_popup_sw.attach(*mi, 0,1, row, row+1);
row++;
+ ++iter;
}
_popup_sw.attach(*(new Gtk::SeparatorMenuItem()), 0,1, row, row+1);
@@ -476,14 +480,13 @@ SelectedStyle::setDesktop(SPDesktop *desktop)
this )
));
- //_sw_unit = const_cast<SPUnit*>(sp_desktop_namedview(desktop)->doc_units);
- _sw_unit = const_cast<SPUnit*>(&sp_unit_get_by_id(SP_UNIT_PX));
+ _sw_unit = const_cast<Inkscape::Util::Unit*>(sp_desktop_namedview(desktop)->doc_units);
// Set the doc default unit active in the units list
gint length = g_slist_length(_unit_mis);
for (int i = 0; i < length; i++) {
Gtk::RadioMenuItem *mi = (Gtk::RadioMenuItem *) g_slist_nth_data(_unit_mis, i);
- if (mi && mi->get_label() == Glib::ustring(_sw_unit->abbr)) {
+ if (mi && mi->get_label() == _sw_unit->abbr) {
mi->set_active();
break;
}
@@ -927,8 +930,8 @@ SelectedStyle::on_opacity_click(GdkEventButton *event)
return false;
}
-void SelectedStyle::on_popup_units(SPUnitId id) {
- _sw_unit = (SPUnit *) &(sp_unit_get_by_id(id));
+void SelectedStyle::on_popup_units(Inkscape::Util::Unit &unit) {
+ _sw_unit = new Inkscape::Util::Unit(unit);
update();
}
@@ -936,7 +939,7 @@ void SelectedStyle::on_popup_preset(int i) {
SPCSSAttr *css = sp_repr_css_attr_new ();
gdouble w;
if (_sw_unit) {
- w = sp_units_get_pixels (_sw_presets[i], *_sw_unit);
+ w = Inkscape::Util::Quantity::convert(_sw_presets[i], *_sw_unit, "px");
} else {
w = _sw_presets[i];
}
@@ -1115,7 +1118,7 @@ SelectedStyle::update()
{
double w;
if (_sw_unit) {
- w = sp_pixels_get_units(query->stroke_width.computed, *_sw_unit);
+ w = Inkscape::Util::Quantity::convert(query->stroke_width.computed, "px", *_sw_unit);
} else {
w = query->stroke_width.computed;
}
@@ -1129,7 +1132,7 @@ SelectedStyle::update()
{
gchar *str = g_strdup_printf(_("Stroke width: %.5g%s%s"),
w,
- _sw_unit? sp_unit_get_abbreviation(_sw_unit) : "px",
+ _sw_unit? _sw_unit->abbr.c_str() : "px",
(result_sw == QUERY_STYLE_MULTIPLE_AVERAGED)?
_(" (averaged)") : "");
_stroke_width_place.set_tooltip_text(str);
diff --git a/src/ui/widget/selected-style.h b/src/ui/widget/selected-style.h
index e5bc4f883..0a907f1fd 100644
--- a/src/ui/widget/selected-style.h
+++ b/src/ui/widget/selected-style.h
@@ -41,12 +41,15 @@
#include <sigc++/sigc++.h>
#include "rotateable.h"
-#include "helper/units.h"
class SPDesktop;
-struct SPUnit;
namespace Inkscape {
+
+namespace Util {
+ class Unit;
+}
+
namespace UI {
namespace Widget {
@@ -273,11 +276,11 @@ protected:
Gtk::Menu _popup_sw;
Gtk::RadioButtonGroup _sw_group;
GSList *_unit_mis;
- void on_popup_units(SPUnitId id);
+ void on_popup_units(Inkscape::Util::Unit &u);
void on_popup_preset(int i);
Gtk::MenuItem _popup_sw_remove;
- SPUnit *_sw_unit;
+ Inkscape::Util::Unit *_sw_unit;
void *_drop[2];
bool _dropEnabled[2];
diff --git a/src/widgets/desktop-widget.cpp b/src/widgets/desktop-widget.cpp
index 1c6852f35..56a5baf5b 100644
--- a/src/widgets/desktop-widget.cpp
+++ b/src/widgets/desktop-widget.cpp
@@ -394,7 +394,8 @@ void SPDesktopWidget::init( SPDesktopWidget *dtw )
dtw->hruler = sp_ruler_new(GTK_ORIENTATION_HORIZONTAL);
dtw->hruler_box = eventbox;
sp_ruler_set_unit(SP_RULER(dtw->hruler), SP_PT);
- gtk_widget_set_tooltip_text (dtw->hruler_box, gettext(sp_unit_get_plural (&sp_unit_get_by_id(SP_UNIT_PT))));
+ Inkscape::Util::UnitTable unit_table;
+ gtk_widget_set_tooltip_text (dtw->hruler_box, gettext(unit_table.getUnit("pt").name_plural.c_str()));
gtk_container_add (GTK_CONTAINER (eventbox), dtw->hruler);
g_signal_connect (G_OBJECT (eventbox), "button_press_event", G_CALLBACK (sp_dt_hruler_event), dtw);
g_signal_connect (G_OBJECT (eventbox), "button_release_event", G_CALLBACK (sp_dt_hruler_event), dtw);
@@ -423,7 +424,7 @@ void SPDesktopWidget::init( SPDesktopWidget *dtw )
dtw->vruler = sp_ruler_new(GTK_ORIENTATION_VERTICAL);
dtw->vruler_box = eventbox;
sp_ruler_set_unit (SP_RULER (dtw->vruler), SP_PT);
- gtk_widget_set_tooltip_text (dtw->vruler_box, gettext(sp_unit_get_plural (&sp_unit_get_by_id(SP_UNIT_PT))));
+ gtk_widget_set_tooltip_text (dtw->vruler_box, gettext(unit_table.getUnit("pt").name_plural.c_str()));
gtk_container_add (GTK_CONTAINER (eventbox), GTK_WIDGET (dtw->vruler));
#if GTK_CHECK_VERSION(3,0,0)