Merge lp:~inkscape.dev/inkscape/measureOverItem into lp:~inkscape.dev/inkscape/trunk

Proposed by Jabiertxof
Status: Merged
Merge reported by: Martin Owens
Merged at revision: not available
Proposed branch: lp:~inkscape.dev/inkscape/measureOverItem
Merge into: lp:~inkscape.dev/inkscape/trunk
Diff against target: 163 lines (+121/-0)
2 files modified
src/ui/tools/measure-tool.cpp (+112/-0)
src/ui/tools/measure-tool.h (+9/-0)
To merge this branch: bzr merge lp:~inkscape.dev/inkscape/measureOverItem
Reviewer Review Type Date Requested Status
Martin Owens Approve
Review via email: mp+297125@code.launchpad.net

Description of the change

It has 4 strings to be translated so maybe is better merge on 0.93/Experimental branch.
Here are a video working.
https://www.youtube.com/watch?v=xgXDJ0yDaZM

To post a comment you must log in.
Revision history for this message
Martin Owens (doctormo) wrote :

This merge request is good, I've merged it into current trunk.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/ui/tools/measure-tool.cpp'
2--- src/ui/tools/measure-tool.cpp 2016-06-08 07:01:39 +0000
3+++ src/ui/tools/measure-tool.cpp 2016-06-11 12:07:59 +0000
4@@ -394,6 +394,10 @@
5 sp_canvas_item_destroy(measure_tmp_items[idx]);
6 }
7 measure_tmp_items.clear();
8+ for (size_t idx = 0; idx < measure_item.size(); ++idx) {
9+ sp_canvas_item_destroy(measure_item[idx]);
10+ }
11+ measure_item.clear();
12 for (size_t idx = 0; idx < measure_phantom_items.size(); ++idx) {
13 sp_canvas_item_destroy(measure_phantom_items[idx]);
14 }
15@@ -608,6 +612,12 @@
16 snap_manager.preSnap(scp);
17 snap_manager.unSetup();
18 }
19+ Geom::Point const motion_w(event->motion.x, event->motion.y);
20+ if(event->motion.state & GDK_SHIFT_MASK) {
21+ showInfoBox(motion_w, true);
22+ } else {
23+ showInfoBox(motion_w, false);
24+ }
25 } else {
26 ret = TRUE;
27 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
28@@ -1128,6 +1138,108 @@
29 }
30 }
31
32+void MeasureTool::showItemInfoText(Geom::Point pos, gchar *measure_str, double fontsize)
33+{
34+ SPCanvasText *canvas_tooltip = sp_canvastext_new(desktop->getTempGroup(),
35+ desktop,
36+ pos,
37+ measure_str);
38+ sp_canvastext_set_fontsize(canvas_tooltip, fontsize);
39+ canvas_tooltip->rgba = 0xffffffff;
40+ canvas_tooltip->outline = false;
41+ canvas_tooltip->background = true;
42+ canvas_tooltip->anchor_position = TEXT_ANCHOR_LEFT;
43+ canvas_tooltip->rgba_background = 0x00000099;
44+ measure_item.push_back(SP_CANVAS_ITEM(canvas_tooltip));
45+ sp_canvas_item_show(SP_CANVAS_ITEM(canvas_tooltip));
46+}
47+
48+void MeasureTool::showInfoBox(Geom::Point cursor, bool into_groups)
49+{
50+ SPDesktop *desktop = SP_ACTIVE_DESKTOP;
51+ Inkscape::Util::Unit const * unit = desktop->getNamedView()->getDisplayUnit();
52+ for (size_t idx = 0; idx < measure_item.size(); ++idx) {
53+ sp_canvas_item_destroy(measure_item[idx]);
54+ }
55+ measure_item.clear();
56+
57+ SPItem *newover = desktop->getItemAtPoint(cursor, into_groups);
58+ if (newover) {
59+ Inkscape::Preferences *prefs = Inkscape::Preferences::get();
60+ double fontsize = prefs->getDouble("/tools/measure/fontsize", 10.0);
61+ double scale = prefs->getDouble("/tools/measure/scale", 100.0) / 100.0;
62+ int precision = prefs->getInt("/tools/measure/precision", 2);
63+ Glib::ustring unit_name = prefs->getString("/tools/measure/unit");
64+ if (!unit_name.compare("")) {
65+ unit_name = "px";
66+ }
67+ Geom::Scale zoom = Geom::Scale(Inkscape::Util::Quantity::convert(desktop->current_zoom(), "px", unit->abbr)).inverse();
68+ if(newover != over){
69+ over = newover;
70+ Preferences *prefs = Preferences::get();
71+ int prefs_bbox = prefs->getBool("/tools/bounding_box", 0);
72+ SPItem::BBoxType bbox_type = !prefs_bbox ? SPItem::VISUAL_BBOX : SPItem::GEOMETRIC_BBOX;
73+ Geom::OptRect bbox = over->bounds(bbox_type);
74+ if (bbox) {
75+
76+ item_width = Inkscape::Util::Quantity::convert((*bbox).width() * scale, unit->abbr, unit_name);
77+ item_height = Inkscape::Util::Quantity::convert((*bbox).height() * scale, unit->abbr, unit_name);
78+ item_x = Inkscape::Util::Quantity::convert((*bbox).left(), unit->abbr, unit_name);
79+ Geom::Point y_point(0,Inkscape::Util::Quantity::convert((*bbox).bottom() * scale, unit->abbr, "px"));
80+ y_point *= desktop->doc2dt();
81+ item_y = Inkscape::Util::Quantity::convert(y_point[Geom::Y] * scale, "px", unit_name);
82+ if (SP_IS_SHAPE(over)) {
83+ Geom::PathVector shape = SP_SHAPE(over)->getCurve()->get_pathvector();
84+ item_length = Geom::length(paths_to_pw(shape));
85+ item_length = Inkscape::Util::Quantity::convert(item_length * scale, unit->abbr, unit_name);
86+ }
87+ }
88+ }
89+ gchar *measure_str = NULL;
90+ std::stringstream precision_str;
91+ precision_str.imbue(std::locale::classic());
92+ double origin = Inkscape::Util::Quantity::convert(14, "px", unit->abbr);
93+ Geom::Point rel_position = Geom::Point(origin, origin);
94+ Geom::Point pos = desktop->w2d(cursor);
95+ double gap = Inkscape::Util::Quantity::convert(7 + fontsize, "px", unit->abbr);
96+ if (SP_IS_SHAPE(over)) {
97+ precision_str << _("Length") << ": %." << precision << "f %s";
98+ measure_str = g_strdup_printf(precision_str.str().c_str(), item_length, unit_name.c_str());
99+ precision_str.str("");
100+ showItemInfoText(pos + (rel_position * zoom),measure_str,fontsize);
101+ rel_position = Geom::Point(rel_position[Geom::X], rel_position[Geom::Y] + gap);
102+ } else if (SP_IS_GROUP(over)) {
103+ measure_str = _("Shift to measure into group");
104+ showItemInfoText(pos + (rel_position * zoom),measure_str,fontsize);
105+ rel_position = Geom::Point(rel_position[Geom::X], rel_position[Geom::Y] + gap);
106+ }
107+
108+ precision_str << "Y: %." << precision << "f %s";
109+ measure_str = g_strdup_printf(precision_str.str().c_str(), item_y, unit_name.c_str());
110+ precision_str.str("");
111+ showItemInfoText(pos + (rel_position * zoom),measure_str,fontsize);
112+ rel_position = Geom::Point(rel_position[Geom::X], rel_position[Geom::Y] + gap);
113+
114+ precision_str << "X: %." << precision << "f %s";
115+ measure_str = g_strdup_printf(precision_str.str().c_str(), item_x, unit_name.c_str());
116+ precision_str.str("");
117+ showItemInfoText(pos + (rel_position * zoom),measure_str,fontsize);
118+ rel_position = Geom::Point(rel_position[Geom::X], rel_position[Geom::Y] + gap);
119+
120+ precision_str << _("Height") << ": %." << precision << "f %s";
121+ measure_str = g_strdup_printf(precision_str.str().c_str(), item_height, unit_name.c_str());
122+ precision_str.str("");
123+ showItemInfoText(pos + (rel_position * zoom),measure_str,fontsize);
124+ rel_position = Geom::Point(rel_position[Geom::X], rel_position[Geom::Y] + gap);
125+
126+ precision_str << _("Width") << ": %." << precision << "f %s";
127+ measure_str = g_strdup_printf(precision_str.str().c_str(), item_width, unit_name.c_str());
128+ precision_str.str("");
129+ showItemInfoText(pos + (rel_position * zoom),measure_str,fontsize);
130+ g_free(measure_str);
131+ }
132+}
133+
134 void MeasureTool::showCanvasItems(bool to_guides, bool to_item, bool to_phantom, Inkscape::XML::Node *measure_repr)
135 {
136 SPDesktop *desktop = SP_ACTIVE_DESKTOP;
137
138=== modified file 'src/ui/tools/measure-tool.h'
139--- src/ui/tools/measure-tool.h 2016-02-11 15:16:11 +0000
140+++ src/ui/tools/measure-tool.h 2016-06-11 12:07:59 +0000
141@@ -54,6 +54,8 @@
142 virtual void setMarker(bool isStart);
143 virtual const std::string& getPrefsPath();
144 Geom::Point readMeasurePoint(bool is_start);
145+ void showInfoBox(Geom::Point cursor, bool into_groups);
146+ void showItemInfoText(Geom::Point pos, gchar *measure_str, double fontsize);
147 void writeMeasurePoint(Geom::Point point, bool is_start);
148 void setGuide(Geom::Point origin, double angle, const char *label);
149 void setPoint(Geom::Point origin, Inkscape::XML::Node *measure_repr);
150@@ -77,6 +79,13 @@
151 Geom::Point end_p;
152 std::vector<SPCanvasItem *> measure_tmp_items;
153 std::vector<SPCanvasItem *> measure_phantom_items;
154+ std::vector<SPCanvasItem *> measure_item;
155+ double item_width;
156+ double item_height;
157+ double item_x;
158+ double item_y;
159+ double item_length;
160+ SPItem *over;
161 sigc::connection _knot_start_moved_connection;
162 sigc::connection _knot_start_ungrabbed_connection;
163 sigc::connection _knot_start_click_connection;