d0cdfdd2ab344de1c652e8a61bccb25b12414893
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 _relative_toggle(_("Rela_tive move"), _("Move guide relative to current position")),
43 _adjustment(0.0, -SP_DESKTOP_SCROLL_LIMIT, SP_DESKTOP_SCROLL_LIMIT, 1.0, 10.0, 10.0),
44 _unit_selector(NULL), _mode(true), _oldpos(0.0)
45 {
46 }
48 GuidelinePropertiesDialog::~GuidelinePropertiesDialog() {
49 }
51 void GuidelinePropertiesDialog::showDialog(SPGuide *guide, SPDesktop *desktop) {
52 GuidelinePropertiesDialog dialog(guide, desktop);
53 dialog._setup();
54 dialog.run();
55 }
57 void GuidelinePropertiesDialog::_modeChanged()
58 {
59 _mode = !_relative_toggle.get_active();
60 if (!_mode) {
61 _label_move.set_label(_("Move by:"));
62 } else {
63 _label_move.set_label(_("Move to:"));
64 }
65 }
67 void GuidelinePropertiesDialog::_onApply()
68 {
69 gdouble const raw_dist = _spin_button.get_value();
70 SPUnit const &unit = *sp_unit_selector_get_unit(SP_UNIT_SELECTOR(_unit_selector->gobj()));
71 gdouble const points = sp_units_get_pixels(raw_dist, unit);
72 if (_guide->normal_to_line[Geom::Y] == 1.) {
73 gdouble const newpos = ( _mode ? points : _guide->point_on_line[Geom::Y] + points );
74 sp_guide_moveto(*_guide, Geom::Point(0, newpos), true);
75 } else {
76 gdouble const newpos = ( _mode ? points : _guide->point_on_line[Geom::Y] + points );
77 sp_guide_moveto(*_guide, Geom::Point(newpos, 0), true);
78 }
79 sp_document_done(SP_OBJECT_DOCUMENT(_guide), SP_VERB_NONE,
80 _("Set guide properties"));
81 }
83 void GuidelinePropertiesDialog::_onOK()
84 {
85 _onApply();
86 }
88 void GuidelinePropertiesDialog::_onDelete()
89 {
90 SPDocument *doc = SP_OBJECT_DOCUMENT(_guide);
91 sp_guide_remove(_guide);
92 sp_document_done(doc, SP_VERB_NONE,
93 _("Delete guide"));
94 }
96 void GuidelinePropertiesDialog::_response(gint response)
97 {
98 switch (response) {
99 case Gtk::RESPONSE_OK:
100 _onOK();
101 break;
102 case -12:
103 _onDelete();
104 break;
105 case Gtk::RESPONSE_CLOSE:
106 break;
107 case Gtk::RESPONSE_DELETE_EVENT:
108 break;
109 /* case GTK_RESPONSE_APPLY:
110 _onApply();
111 break;
112 */
113 default:
114 g_assert_not_reached();
115 }
116 }
118 void GuidelinePropertiesDialog::_setup() {
119 set_title(_("Guideline"));
120 add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK);
121 add_button(Gtk::Stock::DELETE, -12);
122 add_button(Gtk::Stock::CLOSE, Gtk::RESPONSE_CLOSE);
124 Gtk::VBox *mainVBox = get_vbox();
126 _layout_table.set_spacings(4);
127 _layout_table.resize (3, 4);
129 mainVBox->pack_start(_layout_table, false, false, 0);
131 _label_descr.set_label("foo1");
132 _layout_table.attach(_label_descr,
133 0, 3, 0, 1, Gtk::FILL, Gtk::FILL);
134 _label_descr.set_alignment(0, 0.5);
136 _layout_table.attach(_label_move,
137 0, 2, 1, 2, Gtk::FILL, Gtk::FILL);
138 _label_move.set_alignment(0, 0.5);
139 _modeChanged();
141 // indent
142 _layout_table.attach(*manage(new Gtk::Label(" ")),
143 0, 1, 2, 3, Gtk::FILL, Gtk::FILL, 10);
145 // mode radio button
146 _layout_table.attach(_relative_toggle,
147 1, 3, 3, 4, Gtk::EXPAND | Gtk::FILL, Gtk::FILL);
148 _relative_toggle.signal_toggled().connect(sigc::mem_fun(*this, &GuidelinePropertiesDialog::_modeChanged));
150 // unitmenu
151 /* fixme: We should allow percents here too, as percents of the canvas size */
152 GtkWidget *unit_selector = sp_unit_selector_new(SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE);
153 sp_unit_selector_set_unit(SP_UNIT_SELECTOR(unit_selector), _desktop->namedview->doc_units);
154 _unit_selector = Gtk::manage(Glib::wrap(unit_selector));
156 // spinbutton
157 sp_unit_selector_add_adjustment(SP_UNIT_SELECTOR(unit_selector), GTK_ADJUSTMENT(_adjustment.gobj()));
158 _spin_button.configure(_adjustment, 1.0 , 3);
159 _spin_button.set_numeric(TRUE);
160 _layout_table.attach(_spin_button,
161 1, 2, 2, 3, Gtk::EXPAND | Gtk::FILL, Gtk::FILL);
162 gtk_signal_connect_object(GTK_OBJECT(_spin_button.gobj()), "activate",
163 GTK_SIGNAL_FUNC(gtk_window_activate_default),
164 gobj());
166 _layout_table.attach(*_unit_selector,
167 2, 3, 2, 3, Gtk::FILL, Gtk::FILL);
170 // dialog
171 set_default_response(Gtk::RESPONSE_OK);
172 signal_response().connect(sigc::mem_fun(*this, &GuidelinePropertiesDialog::_response));
174 // initialize dialog
175 if (_guide->normal_to_line[Geom::Y] == 0.) {
176 _oldpos = _guide->point_on_line[Geom::X];
177 } else {
178 _oldpos = _guide->point_on_line[Geom::Y];
179 }
180 {
181 gchar *guide_description = sp_guide_description(_guide);
182 Inkscape::XML::Node *repr = SP_OBJECT_REPR (_guide);
183 const gchar *guide_id = repr->attribute("id");
184 gchar *label = g_strdup_printf(_("Moving %s %s"), guide_description, guide_id);
185 g_free(guide_description);
186 _label_descr.set_label(label);
187 g_free(label);
188 }
190 SPUnit const &unit = *sp_unit_selector_get_unit(SP_UNIT_SELECTOR(unit_selector));
191 gdouble const val = sp_pixels_get_units(_oldpos, unit);
192 _spin_button.set_value(val);
193 _spin_button.grab_focus();
194 _spin_button.select_region(0, 20);
195 set_position(Gtk::WIN_POS_MOUSE);
197 show_all_children();
198 set_modal(true);
199 _desktop->setWindowTransient (gobj());
200 property_destroy_with_parent() = true;
201 }
203 }
204 }
205 }
207 /*
208 Local Variables:
209 mode:c++
210 c-file-style:"stroustrup"
211 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
212 indent-tabs-mode:nil
213 fill-column:99
214 End:
215 */
216 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :