summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMatthew Petroff <matthew@mpetroff.net>2013-07-06 14:03:42 +0000
committerMatthew Petroff <matthew@mpetroff.net>2013-07-06 14:03:42 +0000
commitdd961a4de274306767c27756e80630d57f75ee0c (patch)
tree39cffac4c0ac1eefec9c3e0350b0eeaea31ad93d /src
parentMerge from trunk. (diff)
downloadinkscape-dd961a4de274306767c27756e80630d57f75ee0c.tar.gz
inkscape-dd961a4de274306767c27756e80630d57f75ee0c.zip
Ported measure-context.cpp (to do: port widgets/measure-toolbar.cpp so unit selector works again).
(bzr r12380.1.6)
Diffstat (limited to 'src')
-rw-r--r--src/measure-context.cpp21
1 files changed, 13 insertions, 8 deletions
diff --git a/src/measure-context.cpp b/src/measure-context.cpp
index 9d60d38e8..6e7709d56 100644
--- a/src/measure-context.cpp
+++ b/src/measure-context.cpp
@@ -515,8 +515,13 @@ static gint sp_measure_context_root_handler(SPEventContext *event_context, GdkEv
std::sort(intersections.begin(), intersections.end(), GeomPointSortPredicate);
}
- SPUnitId unitid = static_cast<SPUnitId>(prefs->getInt("/tools/measure/unitid", SP_UNIT_PX));
- SPUnit unit = sp_unit_get_by_id(unitid);
+ Inkscape::Util::UnitTable unit_table;
+ Glib::ustring unit_name = prefs->getString("/tools/measure/unit");
+ if (!unit_name.compare("")) {
+ unit_name = "px";
+ }
+ Inkscape::Util::Unit unit = unit_table.getUnit(unit_name);
+ Inkscape::Util::Unit px = unit_table.getUnit("px");
double fontsize = prefs->getInt("/tools/measure/fontsize");
@@ -527,7 +532,7 @@ static gint sp_measure_context_root_handler(SPEventContext *event_context, GdkEv
for (size_t idx = 1; idx < intersections.size(); ++idx) {
LabelPlacement placement;
placement.lengthVal = (intersections[idx] - intersections[idx - 1]).length();
- sp_convert_distance(&placement.lengthVal, &sp_unit_get_by_id(SP_UNIT_PX), &unit);
+ placement.lengthVal = Inkscape::Util::Quantity::convert(placement.lengthVal, &px, &unit);
placement.offset = DIMENSION_OFFSET;
placement.start = desktop->doc2dt( (intersections[idx - 1] + intersections[idx]) / 2 );
placement.end = placement.start - (normal * placement.offset);
@@ -543,7 +548,7 @@ static gint sp_measure_context_root_handler(SPEventContext *event_context, GdkEv
LabelPlacement &place = *it;
// TODO cleanup memory, Glib::ustring, etc.:
- gchar *measure_str = g_strdup_printf("%.2f %s", place.lengthVal, unit.abbr);
+ gchar *measure_str = g_strdup_printf("%.2f %s", place.lengthVal, unit.abbr.c_str());
SPCanvasText *canvas_tooltip = sp_canvastext_new(sp_desktop_tempgroup(desktop),
desktop,
place.end,
@@ -584,10 +589,10 @@ static gint sp_measure_context_root_handler(SPEventContext *event_context, GdkEv
{
double totallengthval = (end_point - start_point).length();
- sp_convert_distance(&totallengthval, &sp_unit_get_by_id(SP_UNIT_PX), &unit);
+ totallengthval = Inkscape::Util::Quantity::convert(totallengthval, &px, &unit);
// TODO cleanup memory, Glib::ustring, etc.:
- gchar *totallength_str = g_strdup_printf("%.2f %s", totallengthval, unit.abbr);
+ gchar *totallength_str = g_strdup_printf("%.2f %s", totallengthval, unit.abbr.c_str());
SPCanvasText *canvas_tooltip = sp_canvastext_new(sp_desktop_tempgroup(desktop),
desktop,
end_point + desktop->w2d(Geom::Point(3*fontsize, -fontsize)),
@@ -605,10 +610,10 @@ static gint sp_measure_context_root_handler(SPEventContext *event_context, GdkEv
if (intersections.size() > 2) {
double totallengthval = (intersections[intersections.size()-1] - intersections[0]).length();
- sp_convert_distance(&totallengthval, &sp_unit_get_by_id(SP_UNIT_PX), &unit);
+ totallengthval = Inkscape::Util::Quantity::convert(totallengthval, &px, &unit);
// TODO cleanup memory, Glib::ustring, etc.:
- gchar *total_str = g_strdup_printf("%.2f %s", totallengthval, unit.abbr);
+ gchar *total_str = g_strdup_printf("%.2f %s", totallengthval, unit.abbr.c_str());
SPCanvasText *canvas_tooltip = sp_canvastext_new(sp_desktop_tempgroup(desktop),
desktop,
desktop->doc2dt((intersections[0] + intersections[intersections.size()-1])/2) + normal * 60,