6fab6c1c67d51dcf6574052b9dddd261f74bacdc
1 #define __GUIDELINE_CPP__
3 /*
4 * simple guideline dialog
5 *
6 * Authors:
7 * Lauris Kaplinski <lauris@kaplinski.com>
8 * Andrius R. <knutux@gmail.com>
9 *
10 * Copyright (C) 1999-2006 Authors
11 *
12 * Released under GNU GPL, read the file 'COPYING' for more information
13 */
15 #ifdef HAVE_CONFIG_H
16 # include <config.h>
17 #endif
18 #include "display/guideline.h"
19 #include "helper/unit-menu.h"
20 #include "helper/units.h"
21 #include "desktop.h"
22 #include "document.h"
23 #include "sp-guide.h"
24 #include "sp-namedview.h"
25 #include "desktop-handles.h"
26 #include "event-context.h"
27 #include "widgets/desktop-widget.h"
28 #include "sp-metrics.h"
29 #include <glibmm/i18n.h>
30 #include "dialogs/dialog-events.h"
31 #include "message-context.h"
32 #include "xml/repr.h"
34 #include "guidelinedialog.h"
36 namespace Inkscape {
37 namespace UI {
38 namespace Dialogs {
40 GuidelinePropertiesDialog::GuidelinePropertiesDialog(SPGuide *guide, SPDesktop *desktop)
41 : _desktop(desktop), _guide(guide),
42 _adjustment(0.0, -SP_DESKTOP_SCROLL_LIMIT, SP_DESKTOP_SCROLL_LIMIT, 1.0, 10.0, 10.0),
43 _unit_selector(NULL), _mode(true), _oldpos(0.0)
44 {
45 }
47 GuidelinePropertiesDialog::~GuidelinePropertiesDialog() {
48 if ( NULL != _unit_selector) {
49 //g_free(_unit_selector);
50 }
51 }
53 void GuidelinePropertiesDialog::showDialog(SPGuide *guide, SPDesktop *desktop) {
54 GuidelinePropertiesDialog *dialog = new GuidelinePropertiesDialog(guide, desktop);
55 dialog->_setup();
56 dialog->run();
57 delete dialog;
58 }
60 void GuidelinePropertiesDialog::_modeChanged()
61 {
62 if (_mode) {
63 // TRANSLATORS: This string appears when double-clicking on a guide.
64 // This is the distance by which the guide is to be moved.
65 _m.set_label(_(" relative by "));
66 _mode = false;
67 } else {
68 // TRANSLATORS: This string appears when double-clicking on a guide.
69 // This is the target location where the guide is to be moved.
70 _m.set_label(_(" absolute to "));
71 _mode = true;
72 }
73 }
75 void GuidelinePropertiesDialog::_onApply()
76 {
77 gdouble const raw_dist = _spin_button.get_value();
78 SPUnit const &unit = *sp_unit_selector_get_unit(SP_UNIT_SELECTOR(_unit_selector));
79 gdouble const points = sp_units_get_pixels(raw_dist, unit);
80 gdouble const newpos = ( _mode
81 ? points
82 : _guide->position + points );
83 sp_guide_moveto(*_guide, newpos, true);
84 sp_document_done(SP_OBJECT_DOCUMENT(_guide));
85 }
87 void GuidelinePropertiesDialog::_onOK()
88 {
89 _onApply();
90 }
92 void GuidelinePropertiesDialog::_onDelete()
93 {
94 SPDocument *doc = SP_OBJECT_DOCUMENT(_guide);
95 sp_guide_remove(_guide);
96 sp_document_done(doc);
97 }
99 void GuidelinePropertiesDialog::_response(gint response)
100 {
101 switch (response) {
102 case Gtk::RESPONSE_OK:
103 _onOK();
104 break;
105 case -12:
106 _onDelete();
107 break;
108 case Gtk::RESPONSE_CLOSE:
109 break;
110 case Gtk::RESPONSE_DELETE_EVENT:
111 break;
112 /* case GTK_RESPONSE_APPLY:
113 _onApply();
114 break;
115 */
116 default:
117 g_assert_not_reached();
118 }
119 }
121 void GuidelinePropertiesDialog::_setup() {
122 set_title(_("Guideline"));
123 add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK);
124 add_button(Gtk::Stock::DELETE, -12);
125 add_button(Gtk::Stock::CLOSE, Gtk::RESPONSE_CLOSE);
127 Gtk::VBox *mainVBox = get_vbox();
129 _b1.set_homogeneous(false);
130 _b1.set_spacing(4);
131 mainVBox->pack_start(_b1, false, false, 0);
132 _b1.set_border_width(4);
134 _b2.set_homogeneous(false);
135 _b2.set_spacing(4);
136 _b1.pack_start(_b2, true, true, 0);
138 //labels
139 _b3.set_homogeneous(false);
140 _b3.set_spacing(4);
141 _b2.pack_start(_b3, true, true, 0);
143 _label.set_label("foo1");
144 _b3.pack_start(_label, true, true, 0);
145 _label.set_alignment(1.0, 0.5);
147 _label_id.set_label("foo2");
148 _b3.pack_start(_label_id, true, true, 0);
149 _label_id.set_alignment(0.0, 0.5);
151 _b4.set_homogeneous(false);
152 _b4.set_spacing(4);
153 _b2.pack_start(_b4, false, false, 0);
155 // mode button
156 _but.set_relief(Gtk::RELIEF_NONE);
157 _b4.pack_start(_but, false, true, 0);
158 _but.signal_clicked().connect(sigc::mem_fun(*this, &GuidelinePropertiesDialog::_modeChanged));
159 _m.set_label(_(" absolute to "));
160 _but.add(_m);
162 // unitmenu
163 /* fixme: We should allow percents here too, as percents of the canvas size */
164 _unit_selector = sp_unit_selector_new(SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE);
165 sp_unit_selector_set_unit(SP_UNIT_SELECTOR(_unit_selector), _desktop->namedview->doc_units);
167 // spinbutton
168 sp_unit_selector_add_adjustment(SP_UNIT_SELECTOR(_unit_selector), GTK_ADJUSTMENT(_adjustment.gobj()));
169 _spin_button.configure(_adjustment, 1.0 , 2);
170 _spin_button.set_numeric(TRUE);
171 _b4.pack_start(_spin_button, true, true, 0);
172 gtk_signal_connect_object(GTK_OBJECT(_spin_button.gobj()), "activate",
173 GTK_SIGNAL_FUNC(gtk_window_activate_default),
174 gobj());
176 gtk_box_pack_start(GTK_BOX(_b4.gobj()), _unit_selector, FALSE, FALSE, 0);
179 // dialog
180 set_default_response(Gtk::RESPONSE_OK);
181 signal_response().connect(sigc::mem_fun(*this, &GuidelinePropertiesDialog::_response));
183 // initialize dialog
184 _oldpos = _guide->position;
185 {
186 gchar *guide_description = sp_guide_description(_guide);
187 gchar *label = g_strdup_printf(_("Move %s"), guide_description);
188 g_free(guide_description);
189 _label.set_label(label);
190 g_free(label);
192 Inkscape::XML::Node *repr = SP_OBJECT_REPR (_guide);
193 const gchar *guide_id = repr->attribute("id");
194 _label_id.set_label(guide_id);
195 }
197 SPUnit const &unit = *sp_unit_selector_get_unit(SP_UNIT_SELECTOR(_unit_selector));
198 gdouble const val = sp_pixels_get_units(_oldpos, unit);
199 _spin_button.set_value(val);
200 _spin_button.grab_focus();
201 _spin_button.select_region(0, 20);
202 set_position(Gtk::WIN_POS_MOUSE);
204 show_all_children();
205 set_modal(true);
206 _desktop->setWindowTransient (gobj());
207 property_destroy_with_parent() = true;
208 }
210 }
211 }
212 }
214 /*
215 Local Variables:
216 mode:c++
217 c-file-style:"stroustrup"
218 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
219 indent-tabs-mode:nil
220 fill-column:99
221 End:
222 */
223 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :