1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
|
/**
* @file
* Measure aux toolbar
*/
/* Authors:
* MenTaLguY <mental@rydia.net>
* Lauris Kaplinski <lauris@kaplinski.com>
* bulia byak <buliabyak@users.sf.net>
* Frank Felfe <innerspace@iname.com>
* John Cliff <simarilius@yahoo.com>
* David Turner <novalis@gnu.org>
* Josh Andler <scislac@scislac.com>
* Jon A. Cruz <jon@joncruz.org>
* Maximilian Albert <maximilian.albert@gmail.com>
* Tavmjong Bah <tavmjong@free.fr>
* Abhishek Sharma
* Kris De Gussem <Kris.DeGussem@gmail.com>
*
* Copyright (C) 2004 David Turner
* Copyright (C) 2003 MenTaLguY
* Copyright (C) 1999-2011 authors
* Copyright (C) 2001-2002 Ximian, Inc.
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <glibmm/i18n.h>
#include "measure-toolbar.h"
#include "desktop.h"
#include "inkscape.h"
#include "message-stack.h"
#include "document-undo.h"
#include "widgets/ege-adjustment-action.h"
#include "widgets/ege-output-action.h"
#include "preferences.h"
#include "toolbox.h"
#include "widgets/ink-action.h"
#include "ui/icon-names.h"
#include "ui/tools/measure-tool.h"
#include "ui/widget/unit-tracker.h"
using Inkscape::UI::Widget::UnitTracker;
using Inkscape::Util::Unit;
using Inkscape::DocumentUndo;
using Inkscape::UI::ToolboxFactory;
using Inkscape::UI::PrefPusher;
using Inkscape::UI::Tools::MeasureTool;
//########################
//## Measure Toolbox ##
//########################
/** Temporary hack: Returns the node tool in the active desktop.
* Will go away during tool refactoring. */
static MeasureTool *get_measure_tool()
{
MeasureTool *tool = 0;
if (SP_ACTIVE_DESKTOP ) {
Inkscape::UI::Tools::ToolBase *ec = SP_ACTIVE_DESKTOP->event_context;
if (SP_IS_MEASURE_CONTEXT(ec)) {
tool = static_cast<MeasureTool*>(ec);
}
}
return tool;
}
static void
sp_measure_fontsize_value_changed(GtkAdjustment *adj, GObject *tbl)
{
SPDesktop *desktop = static_cast<SPDesktop *>(g_object_get_data( tbl, "desktop" ));
if (DocumentUndo::getUndoSensitive(desktop->getDocument())) {
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
prefs->setInt(Glib::ustring("/tools/measure/fontsize"),
gtk_adjustment_get_value(adj));
MeasureTool *mt = get_measure_tool();
if (mt) {
mt->showCanvasItems();
}
}
}
static void
sp_measure_offset_value_changed(GtkAdjustment *adj, GObject *tbl)
{
SPDesktop *desktop = static_cast<SPDesktop *>(g_object_get_data( tbl, "desktop" ));
if (DocumentUndo::getUndoSensitive(desktop->getDocument())) {
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
prefs->setInt(Glib::ustring("/tools/measure/offset"),
gtk_adjustment_get_value(adj));
MeasureTool *mt = get_measure_tool();
if (mt) {
mt->showCanvasItems();
}
}
}
static void measure_unit_changed(GtkAction* /*act*/, GObject* tbl)
{
UnitTracker* tracker = reinterpret_cast<UnitTracker*>(g_object_get_data(tbl, "tracker"));
Glib::ustring const unit = tracker->getActiveUnit()->abbr;
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
prefs->setString("/tools/measure/unit", unit);
MeasureTool *mt = get_measure_tool();
if (mt) {
mt->showCanvasItems();
}
}
static void toggle_ignore_1st_and_last( GtkToggleAction* act, gpointer data )
{
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
gboolean active = gtk_toggle_action_get_active(act);
prefs->setInt("/tools/measure/ignore_1st_and_last", active);
SPDesktop *desktop = static_cast<SPDesktop *>(data);
if ( active ) {
desktop->messageStack()->flash(Inkscape::INFORMATION_MESSAGE, _("Start and end measures inactive."));
} else {
desktop->messageStack()->flash(Inkscape::INFORMATION_MESSAGE, _("Start and end measures active."));
}
MeasureTool *mt = get_measure_tool();
if (mt) {
mt->showCanvasItems();
}
}
static void toggle_all_layers( GtkToggleAction* act, gpointer data )
{
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
gboolean active = gtk_toggle_action_get_active(act);
prefs->setInt("/tools/measure/all_layers", active);
SPDesktop *desktop = static_cast<SPDesktop *>(data);
if ( active ) {
desktop->messageStack()->flash(Inkscape::INFORMATION_MESSAGE, _("Use all layers in the measure."));
} else {
desktop->messageStack()->flash(Inkscape::INFORMATION_MESSAGE, _("Use current layer in the measure."));
}
MeasureTool *mt = get_measure_tool();
if (mt) {
mt->showCanvasItems();
}
}
static void toggle_show_in_between( GtkToggleAction* act, gpointer data )
{
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
gboolean active = gtk_toggle_action_get_active(act);
prefs->setInt("/tools/measure/show_in_between", active);
SPDesktop *desktop = static_cast<SPDesktop *>(data);
if ( active ) {
desktop->messageStack()->flash(Inkscape::INFORMATION_MESSAGE, _("Compute all elements."));
} else {
desktop->messageStack()->flash(Inkscape::INFORMATION_MESSAGE, _("Compute max lenght."));
}
MeasureTool *mt = get_measure_tool();
if (mt) {
mt->showCanvasItems();
}
}
static void sp_reverse_knots(void){
MeasureTool *mt = get_measure_tool();
if (mt) {
mt->reverseKnots();
}
}
static void sp_to_mark_dimension(void){
MeasureTool *mt = get_measure_tool();
if (mt) {
mt->toMarkDimension();
}
}
static void sp_to_guides(void){
MeasureTool *mt = get_measure_tool();
if (mt) {
mt->toGuides();
}
}
static void sp_to_item(void){
MeasureTool *mt = get_measure_tool();
if (mt) {
mt->toItem();
}
}
void sp_measure_toolbox_prep(SPDesktop * desktop, GtkActionGroup* mainActions, GObject* holder)
{
UnitTracker* tracker = new UnitTracker(Inkscape::Util::UNIT_TYPE_LINEAR);
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
tracker->setActiveUnitByAbbr(prefs->getString("/tools/measure/unit").c_str());
g_object_set_data( holder, "tracker", tracker );
EgeAdjustmentAction *eact = 0;
Inkscape::IconSize secondarySize = ToolboxFactory::prefToSize("/toolbox/secondary", 1);
/* Font Size */
{
eact = create_adjustment_action( "MeasureFontSizeAction",
_("Font Size"), _("Font Size:"),
_("The font size to be used in the measurement labels"),
"/tools/measure/fontsize", 0.0,
GTK_WIDGET(desktop->canvas), holder, FALSE, NULL,
1, 36, 1.0, 4.0,
0, 0, 0,
sp_measure_fontsize_value_changed);
gtk_action_group_add_action( mainActions, GTK_ACTION(eact) );
}
// units label
{
EgeOutputAction* act = ege_output_action_new( "measure_units_label", _("Units:"), _("The units to be used for the measurements"), 0 );
ege_output_action_set_use_markup( act, TRUE );
g_object_set( act, "visible-overflown", FALSE, NULL );
gtk_action_group_add_action( mainActions, GTK_ACTION( act ) );
}
// units menu
{
GtkAction* act = tracker->createAction( "MeasureUnitsAction", _("Units:"), _("The units to be used for the measurements") );
g_signal_connect_after( G_OBJECT(act), "changed", G_CALLBACK(measure_unit_changed), holder );
gtk_action_group_add_action( mainActions, act );
}
/* Offset */
{
eact = create_adjustment_action( "MeasureOffsetAction",
_("Offset"), _("Offset:"),
_("The offset size"),
"/tools/measure/offset", 30.0,
GTK_WIDGET(desktop->canvas), holder, FALSE, NULL,
0.0, 90000.0, 1.0, 4.0,
0, 0, 0,
sp_measure_offset_value_changed);
gtk_action_group_add_action( mainActions, GTK_ACTION(eact) );
}
// ignore_1st_and_last
{
InkToggleAction* act = ink_toggle_action_new( "MeasureIgnore1stAndLast",
_("Ignore first and last"),
_("Ignore first and last"),
INKSCAPE_ICON("draw-geometry-line-segment"),
secondarySize );
gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/measure/ignore_1st_and_last", true) );
g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(toggle_ignore_1st_and_last), desktop) ;
gtk_action_group_add_action( mainActions, GTK_ACTION(act) );
}
// measure imbetweens
{
InkToggleAction* act = ink_toggle_action_new( "MeasureInBettween",
_("Show measures between items"),
_("Show measures between items"),
INKSCAPE_ICON("distribute-randomize"),
secondarySize );
gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/measure/show_in_between", true) );
g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(toggle_show_in_between), desktop) ;
gtk_action_group_add_action( mainActions, GTK_ACTION(act) );
}
// measure only current layer
{
InkToggleAction* act = ink_toggle_action_new( "MeasureAllLayers",
_("Measure all layers"),
_("Measure all layers"),
INKSCAPE_ICON("dialog-layers"),
secondarySize );
gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/measure/all_layers", true) );
g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(toggle_all_layers), desktop) ;
gtk_action_group_add_action( mainActions, GTK_ACTION(act) );
}
//toogle start end
{
InkAction* act = ink_action_new( "MeasureReverse",
_("Reverse measure"),
_("Reverse measure"),
INKSCAPE_ICON("draw-geometry-mirror"),
secondarySize );
g_signal_connect_after( G_OBJECT(act), "activate", G_CALLBACK(sp_reverse_knots), 0 );
gtk_action_group_add_action( mainActions, GTK_ACTION(act) );
}
//to guides
{
InkAction* act = ink_action_new( "MeasureToGuides",
_("To guides"),
_("To guides"),
INKSCAPE_ICON("guides"),
secondarySize );
g_signal_connect_after( G_OBJECT(act), "activate", G_CALLBACK(sp_to_guides), 0 );
gtk_action_group_add_action( mainActions, GTK_ACTION(act) );
}
//to mark dimensions
{
InkAction* act = ink_action_new( "MeasureMarkDimension",
_("Mark Dimension"),
_("Mark Dimension"),
INKSCAPE_ICON("tool-pointer"),
secondarySize );
g_signal_connect_after( G_OBJECT(act), "activate", G_CALLBACK(sp_to_mark_dimension), 0 );
gtk_action_group_add_action( mainActions, GTK_ACTION(act) );
}
//to item
{
InkAction* act = ink_action_new( "MeasureToItem",
_("Convert to item"),
_("Convert to item"),
INKSCAPE_ICON("path-reverse"),
secondarySize );
g_signal_connect_after( G_OBJECT(act), "activate", G_CALLBACK(sp_to_item), 0 );
gtk_action_group_add_action( mainActions, GTK_ACTION(act) );
}
} // end of sp_measure_toolbox_prep()
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
|