summaryrefslogtreecommitdiffstats
path: root/src/lpe-tool-context.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/lpe-tool-context.cpp')
-rw-r--r--src/lpe-tool-context.cpp46
1 files changed, 26 insertions, 20 deletions
diff --git a/src/lpe-tool-context.cpp b/src/lpe-tool-context.cpp
index feabfa02d..062a75a7b 100644
--- a/src/lpe-tool-context.cpp
+++ b/src/lpe-tool-context.cpp
@@ -37,10 +37,12 @@
#include "display/canvas-text.h"
#include "message-stack.h"
#include "sp-path.h"
-#include "helper/units.h"
+#include "util/units.h"
#include "lpe-tool-context.h"
+using Inkscape::Util::unit_table;
+
static void sp_lpetool_context_dispose(GObject *object);
static void sp_lpetool_context_setup(SPEventContext *ec);
@@ -453,13 +455,16 @@ lpetool_create_measuring_items(SPLPEToolContext *lc, Inkscape::Selection *select
if (!show)
sp_canvas_item_hide(SP_CANVAS_ITEM(canvas_text));
- SPUnitId unitid = static_cast<SPUnitId>(prefs->getInt("/tools/lpetool/unitid", SP_UNIT_PX));
- SPUnit unit = sp_unit_get_by_id(unitid);
+ Inkscape::Util::Unit unit;
+ if (prefs->getString("/tools/lpetool/unit").compare("")) {
+ unit = unit_table.getUnit(prefs->getString("/tools/lpetool/unit"));
+ } else {
+ unit = unit_table.getUnit("px");
+ }
lengthval = Geom::length(pwd2);
- gboolean success;
- success = sp_convert_distance(&lengthval, &sp_unit_get_by_id(SP_UNIT_PX), &unit);
- arc_length = g_strdup_printf("%.2f %s", lengthval, success ? sp_unit_get_abbreviation(&unit) : "px");
+ lengthval = Inkscape::Util::Quantity::convert(lengthval, "px", unit);
+ arc_length = g_strdup_printf("%.2f %s", lengthval, unit.abbr.c_str());
sp_canvastext_set_text (canvas_text, arc_length);
set_pos_and_anchor(canvas_text, pwd2, 0.5, 10);
// TODO: must we free arc_length?
@@ -482,21 +487,22 @@ void
lpetool_update_measuring_items(SPLPEToolContext *lc)
{
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
- SPPath *path;
- SPCurve *curve;
- double lengthval;
- gchar *arc_length;
- std::map<SPPath *, SPCanvasItem*>::iterator i;
- for (i = lc->measuring_items->begin(); i != lc->measuring_items->end(); ++i) {
- path = i->first;
- curve = SP_SHAPE(path)->getCurve();
+ for ( std::map<SPPath *, SPCanvasItem*>::iterator i = lc->measuring_items->begin();
+ i != lc->measuring_items->end();
+ ++i )
+ {
+ SPPath *path = i->first;
+ SPCurve *curve = SP_SHAPE(path)->getCurve();
Geom::Piecewise<Geom::D2<Geom::SBasis> > pwd2 = Geom::paths_to_pw(curve->get_pathvector());
- SPUnitId unitid = static_cast<SPUnitId>(prefs->getInt("/tools/lpetool/unitid", SP_UNIT_PX));
- SPUnit unit = sp_unit_get_by_id(unitid);
- lengthval = Geom::length(pwd2);
- gboolean success;
- success = sp_convert_distance(&lengthval, &sp_unit_get_by_id(SP_UNIT_PX), &unit);
- arc_length = g_strdup_printf("%.2f %s", lengthval, success ? sp_unit_get_abbreviation(&unit) : "px");
+ Inkscape::Util::Unit unit;
+ if (prefs->getString("/tools/lpetool/unit").compare("")) {
+ unit = unit_table.getUnit(prefs->getString("/tools/lpetool/unit"));
+ } else {
+ unit = unit_table.getUnit("px");
+ }
+ double lengthval = Geom::length(pwd2);
+ lengthval = Inkscape::Util::Quantity::convert(lengthval, "px", unit);
+ gchar *arc_length = g_strdup_printf("%.2f %s", lengthval, unit.abbr.c_str());
sp_canvastext_set_text (SP_CANVASTEXT(i->second), arc_length);
set_pos_and_anchor(SP_CANVASTEXT(i->second), pwd2, 0.5, 10);
// TODO: must we free arc_length?