summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorFelipe Corr??a da Silva Sanches <juca@members.fsf.org>2011-06-14 20:28:34 +0000
committerFelipe C. da S. Sanches <juca@members.fsf.org>2011-06-14 20:28:34 +0000
commitc64a07e4e76524cebf777837cdf78b8e3de9092a (patch)
treef00d300cd63186791c8edc45a3e54aca9166b2a3 /src
parentpatch for 771738, 635469, 700298, 705382, 716057 by Gellule (diff)
downloadinkscape-c64a07e4e76524cebf777837cdf78b8e3de9092a.tar.gz
inkscape-c64a07e4e76524cebf777837cdf78b8e3de9092a.zip
toggle units in the measure tool
(bzr r10302)
Diffstat (limited to 'src')
-rw-r--r--src/measure-context.cpp12
-rw-r--r--src/widgets/toolbox.cpp21
2 files changed, 29 insertions, 4 deletions
diff --git a/src/measure-context.cpp b/src/measure-context.cpp
index a4e81475e..78bfb1cee 100644
--- a/src/measure-context.cpp
+++ b/src/measure-context.cpp
@@ -11,7 +11,7 @@
#include <gdk/gdkkeysyms.h>
-
+#include "helper/units.h"
#include "macros.h"
#include "display/curve.h"
#include "sp-shape.h"
@@ -292,6 +292,9 @@ static gint sp_measure_context_root_handler(SPEventContext *event_context, GdkEv
}
+ SPUnitId unitid = static_cast<SPUnitId>(prefs->getInt("/tools/measure/unitid", SP_UNIT_PX));
+ SPUnit unit = sp_unit_get_by_id(unitid);
+
double fontsize = prefs->getInt("/tools/measure/fontsize");
Geom::Point previous_point;
@@ -302,8 +305,11 @@ static gint sp_measure_context_root_handler(SPEventContext *event_context, GdkEv
Geom::Point measure_text_pos = (previous_point + intersections[idx])/2;
//TODO: shift label a few pixels in the y coordinate
+ double lengthval = (intersections[idx] - previous_point).length();
+ sp_convert_distance(&lengthval, &sp_unit_get_by_id(SP_UNIT_PX), &unit);
+
char* measure_str = (char*) malloc(sizeof(char)*20);
- sprintf(measure_str, "%.2f", (intersections[idx] - previous_point).length());
+ sprintf(measure_str, "%.2f %s", lengthval, unit.abbr);
SPCanvasItem *canvas_tooltip = sp_canvastext_new(sp_desktop_tempgroup(desktop), desktop, desktop->dt2doc(measure_text_pos), measure_str);
sp_canvastext_set_fontsize (SP_CANVASTEXT(canvas_tooltip), fontsize);
@@ -315,7 +321,7 @@ static gint sp_measure_context_root_handler(SPEventContext *event_context, GdkEv
char* angle_str = (char*) malloc(sizeof(char)*20);
sprintf(angle_str, "%.2f °", angle * 180/3.1415 );
- SPCanvasItem *canvas_tooltip = sp_canvastext_new(sp_desktop_tempgroup(desktop), desktop, motion_dt + desktop->w2d(Geom::Point(50,0)), angle_str);
+ SPCanvasItem *canvas_tooltip = sp_canvastext_new(sp_desktop_tempgroup(desktop), desktop, motion_dt + desktop->w2d(Geom::Point(5*fontsize,0)), angle_str);
sp_canvastext_set_fontsize (SP_CANVASTEXT(canvas_tooltip), fontsize);
sp_canvastext_set_rgba32 (SP_CANVASTEXT(canvas_tooltip), 0x337f33ff, 0xffffffff);
diff --git a/src/widgets/toolbox.cpp b/src/widgets/toolbox.cpp
index 122c014eb..30fb753de 100644
--- a/src/widgets/toolbox.cpp
+++ b/src/widgets/toolbox.cpp
@@ -367,6 +367,7 @@ static gchar const * ui_descr =
" <toolbar name='MeasureToolbar'>"
" <toolitem action='MeasureFontSizeAction' />"
+ " <toolitem action='MeasureUnitsAction' />"
" </toolbar>"
" <toolbar name='StarToolbar'>"
@@ -1642,10 +1643,21 @@ sp_measure_fontsize_value_changed(GtkAdjustment *adj, GObject *tbl)
}
}
+static void measure_unit_changed(GtkAction* /*act*/, GObject* tbl)
+{
+ UnitTracker* tracker = reinterpret_cast<UnitTracker*>(g_object_get_data(tbl, "tracker"));
+ SPUnit const *unit = tracker->getActiveUnit();
+ Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+ prefs->setInt("/tools/measure/unitid", unit->unit_id);
+}
static void sp_measure_toolbox_prep(SPDesktop * desktop, GtkActionGroup* mainActions, GObject* holder)
{
- EgeAdjustmentAction* eact = 0;
+ UnitTracker* tracker = new UnitTracker( SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE );
+ tracker->setActiveUnit( sp_desktop_namedview(desktop)->doc_units );
+ g_object_set_data( holder, "tracker", tracker );
+
+ EgeAdjustmentAction *eact = 0;
/* Font Size */
{
@@ -1659,6 +1671,13 @@ static void sp_measure_toolbox_prep(SPDesktop * desktop, GtkActionGroup* mainAct
sp_measure_fontsize_value_changed);
gtk_action_group_add_action( mainActions, GTK_ACTION(eact) );
}
+
+ // add the units menu
+ {
+ GtkAction* act = tracker->createAction( "MeasureUnitsAction", _("Units"), _("Units:") );
+ g_signal_connect_after( G_OBJECT(act), "changed", G_CALLBACK(measure_unit_changed), (GObject*)holder );
+ gtk_action_group_add_action( mainActions, act );
+ }
} // end of sp_measure_toolbox_prep()
void ToolboxFactory::setToolboxDesktop(GtkWidget *toolbox, SPDesktop *desktop)