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
|
/**
* @file
* Simple guideline dialog.
*/
/* Authors:
* Lauris Kaplinski <lauris@kaplinski.com>
* Andrius R. <knutux@gmail.com>
* Johan Engelen
* Abhishek Sharma
*
* Copyright (C) 1999-2007 Authors
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include "guides.h"
#include "display/guideline.h"
#include "desktop.h"
#include "document.h"
#include "document-undo.h"
#include "sp-guide.h"
#include "sp-namedview.h"
#include "desktop-handles.h"
#include "event-context.h"
#include "widgets/desktop-widget.h"
#include <glibmm/i18n.h>
#include "dialogs/dialog-events.h"
#include "message-context.h"
#include "xml/repr.h"
#include "verbs.h"
#include <2geom/point.h>
#include <2geom/angle.h>
#include <gtkmm/stock.h>
namespace Inkscape {
namespace UI {
namespace Dialogs {
GuidelinePropertiesDialog::GuidelinePropertiesDialog(SPGuide *guide, SPDesktop *desktop)
: _desktop(desktop), _guide(guide),
_relative_toggle(_("Rela_tive change"), _("Move and/or rotate the guide relative to current settings")),
_spin_button_x(_("_X:"), "", UNIT_TYPE_LINEAR, "", "", &_unit_menu),
_spin_button_y(_("_Y:"), "", UNIT_TYPE_LINEAR, "", "", &_unit_menu),
_label_entry(_("_Label:"), _("Optionally give this guideline a name")),
_spin_angle(_("_Angle:"), "", UNIT_TYPE_RADIAL),
_mode(true), _oldpos(0.,0.), _oldangle(0.0)
{
}
bool GuidelinePropertiesDialog::_relative_toggle_status = false; // initialize relative checkbox status for when this dialog is opened for first time
Glib::ustring GuidelinePropertiesDialog::_angle_unit_status = "deg"; // initialize angle unit status
GuidelinePropertiesDialog::~GuidelinePropertiesDialog() {
// save current status
_relative_toggle_status = _relative_toggle.get_active();
_angle_unit_status = _spin_angle.getUnit().abbr;
}
void GuidelinePropertiesDialog::showDialog(SPGuide *guide, SPDesktop *desktop) {
GuidelinePropertiesDialog dialog(guide, desktop);
dialog._setup();
dialog.run();
}
void GuidelinePropertiesDialog::_colorChanged()
{
const Gdk::Color c = _color.get_color();
char r = c.get_red()/257, g = c.get_green()/257, b = c.get_blue()/257;
//TODO: why 257? verify this!
sp_guide_set_color(*_guide, r, g, b, true);
}
void GuidelinePropertiesDialog::_modeChanged()
{
_mode = !_relative_toggle.get_active();
if (!_mode) {
// relative
_spin_angle.setValue(0);
_spin_button_y.setValue(0);
_spin_button_x.setValue(0);
} else {
// absolute
_spin_angle.setValueKeepUnit(_oldangle, "deg");
_spin_button_x.setValueKeepUnit(_oldpos[Geom::X], "px");
_spin_button_y.setValueKeepUnit(_oldpos[Geom::Y], "px");
}
}
void GuidelinePropertiesDialog::_onApply()
{
double deg_angle = _spin_angle.getValue("deg");
if (!_mode)
deg_angle += _oldangle;
Geom::Point normal;
if ( deg_angle == 90. || deg_angle == 270. || deg_angle == -90. || deg_angle == -270.) {
normal = Geom::Point(1.,0.);
} else if ( deg_angle == 0. || deg_angle == 180. || deg_angle == -180.) {
normal = Geom::Point(0.,1.);
} else {
double rad_angle = Geom::deg_to_rad( deg_angle );
normal = Geom::rot90(Geom::Point::polar(rad_angle, 1.0));
}
sp_guide_set_normal(*_guide, normal, true);
double const points_x = _spin_button_x.getValue("px");
double const points_y = _spin_button_y.getValue("px");
Geom::Point newpos(points_x, points_y);
if (!_mode)
newpos += _oldpos;
sp_guide_moveto(*_guide, newpos, true);
const gchar* name = _label_entry.getEntry()->get_text().c_str();
sp_guide_set_label(*_guide, name, true);
DocumentUndo::done(_guide->document, SP_VERB_NONE,
_("Set guide properties"));
}
void GuidelinePropertiesDialog::_onOK()
{
_onApply();
}
void GuidelinePropertiesDialog::_onDelete()
{
SPDocument *doc = _guide->document;
sp_guide_remove(_guide);
DocumentUndo::done(doc, SP_VERB_NONE,
_("Delete guide"));
}
void GuidelinePropertiesDialog::_response(gint response)
{
switch (response) {
case Gtk::RESPONSE_OK:
_onOK();
break;
case -12:
_onDelete();
break;
case Gtk::RESPONSE_CANCEL:
break;
case Gtk::RESPONSE_DELETE_EVENT:
break;
/* case GTK_RESPONSE_APPLY:
_onApply();
break;
*/
default:
g_assert_not_reached();
}
}
void GuidelinePropertiesDialog::_setup() {
set_title(_("Guideline"));
add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK);
add_button(Gtk::Stock::DELETE, -12);
add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
Gtk::VBox *mainVBox = get_vbox();
_layout_table.set_spacings(4);
_layout_table.resize (3, 4);
mainVBox->pack_start(_layout_table, false, false, 0);
_label_name.set_label("foo0");
_layout_table.attach(_label_name,
0, 3, 0, 1, Gtk::FILL, Gtk::FILL);
_label_name.set_alignment(0, 0.5);
_label_descr.set_label("foo1");
_layout_table.attach(_label_descr,
0, 3, 1, 2, Gtk::FILL, Gtk::FILL);
_label_descr.set_alignment(0, 0.5);
// indent
// _layout_table.attach(*manage(new Gtk::Label(" ")),
// 0, 1, 2, 3, Gtk::FILL, Gtk::FILL, 10);
_layout_table.attach(_label_entry,
1, 3, 2, 3, Gtk::EXPAND | Gtk::FILL, Gtk::FILL);
_layout_table.attach(_color,
1, 3, 3, 4, Gtk::EXPAND | Gtk::FILL, Gtk::FILL);
_color.signal_color_set().connect(sigc::mem_fun(*this, &GuidelinePropertiesDialog::_colorChanged));
// unitmenus
/* fixme: We should allow percents here too, as percents of the canvas size */
_unit_menu.setUnitType(UNIT_TYPE_LINEAR);
_unit_menu.setUnit("px");
if (_desktop->namedview->doc_units) {
_unit_menu.setUnit( sp_unit_get_abbreviation(_desktop->namedview->doc_units) );
}
_spin_angle.setUnit(_angle_unit_status);
// position spinbuttons
_spin_button_x.setDigits(3);
_spin_button_x.setIncrements(1.0, 10.0);
_spin_button_x.setRange(-1e6, 1e6);
_spin_button_y.setDigits(3);
_spin_button_y.setIncrements(1.0, 10.0);
_spin_button_y.setRange(-1e6, 1e6);
_layout_table.attach(_spin_button_x,
1, 2, 4, 5, Gtk::EXPAND | Gtk::FILL, Gtk::FILL);
_layout_table.attach(_spin_button_y,
1, 2, 5, 6, Gtk::EXPAND | Gtk::FILL, Gtk::FILL);
_layout_table.attach(_unit_menu,
2, 3, 4, 5, Gtk::FILL, Gtk::FILL);
// angle spinbutton
_spin_angle.setDigits(3);
_spin_angle.setIncrements(1.0, 10.0);
_spin_angle.setRange(-3600., 3600.);
_layout_table.attach(_spin_angle,
1, 3, 6, 7, Gtk::EXPAND | Gtk::FILL, Gtk::FILL);
// mode radio button
_layout_table.attach(_relative_toggle,
1, 3, 7, 8, Gtk::EXPAND | Gtk::FILL, Gtk::FILL);
_relative_toggle.signal_toggled().connect(sigc::mem_fun(*this, &GuidelinePropertiesDialog::_modeChanged));
_relative_toggle.set_active(_relative_toggle_status);
// don't know what this exactly does, but it results in that the dialog closes when entering a value and pressing enter (see LP bug 484187)
g_signal_connect_swapped(G_OBJECT(_spin_button_x.getWidget()->gobj()), "activate",
G_CALLBACK(gtk_window_activate_default), gobj());
g_signal_connect_swapped(G_OBJECT(_spin_button_y.getWidget()->gobj()), "activate",
G_CALLBACK(gtk_window_activate_default), gobj());
g_signal_connect_swapped(G_OBJECT(_spin_angle.getWidget()->gobj()), "activate",
G_CALLBACK(gtk_window_activate_default), gobj());
// dialog
set_default_response(Gtk::RESPONSE_OK);
signal_response().connect(sigc::mem_fun(*this, &GuidelinePropertiesDialog::_response));
// initialize dialog
_oldpos = _guide->point_on_line;
if (_guide->isVertical()) {
_oldangle = 90;
} else if (_guide->isHorizontal()) {
_oldangle = 0;
} else {
_oldangle = Geom::rad_to_deg( std::atan2( - _guide->normal_to_line[Geom::X], _guide->normal_to_line[Geom::Y] ) );
}
{
Inkscape::XML::Node *repr = _guide->getRepr();
const gchar *guide_id = repr->attribute("id");
gchar *label = g_strdup_printf(_("Guideline ID: %s"), guide_id);
_label_name.set_label(label);
g_free(label);
}
{
gchar *guide_description = sp_guide_description(_guide, false);
gchar *label = g_strdup_printf(_("Current: %s"), guide_description);
g_free(guide_description);
_label_descr.set_markup(label);
g_free(label);
}
// init name entry
_label_entry.getEntry()->set_text(_guide->label ? _guide->label : "");
Gdk::Color c;
c.set_rgb_p(((_guide->color>>24)&0xff) / 255.0, ((_guide->color>>16)&0xff) / 255.0, ((_guide->color>>8)&0xff) / 255.0);
_color.set_color(c);
_modeChanged(); // sets values of spinboxes.
if ( _oldangle == 90. || _oldangle == 270. || _oldangle == -90. || _oldangle == -270.) {
_spin_button_x.grabFocusAndSelectEntry();
} else if ( _oldangle == 0. || _oldangle == 180. || _oldangle == -180.) {
_spin_button_y.grabFocusAndSelectEntry();
} else {
_spin_angle.grabFocusAndSelectEntry();
}
set_position(Gtk::WIN_POS_MOUSE);
show_all_children();
set_modal(true);
_desktop->setWindowTransient (gobj());
property_destroy_with_parent() = true;
}
}
}
}
/*
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 :
|