1 /**
2 * \brief Point Widget - A labelled text box, with spin buttons and optional
3 * icon or suffix, for entering arbitrary coordinate values.
4 *
5 * Authors:
6 * Johan Engelen <j.b.c.engelen@utwente.nl>
7 * Carl Hetherington <inkscape@carlh.net>
8 * Derek P. Moore <derekm@hackunix.org>
9 * Bryce Harrington <bryce@bryceharrington.org>
10 *
11 * Copyright (C) 2007 Authors
12 * Copyright (C) 2004 Authors
13 *
14 * Released under GNU GPL. Read the file 'COPYING' for more information.
15 */
17 #ifdef HAVE_CONFIG_H
18 # include <config.h>
19 #endif
22 #include "ui/widget/point.h"
23 #include "ui/widget/labelled.h"
24 #include "ui/widget/scalar.h"
25 #include <gtkmm/box.h>
27 namespace Inkscape {
28 namespace UI {
29 namespace Widget {
31 /**
32 * Construct a Point Widget.
33 *
34 * \param label Label.
35 * \param suffix Suffix, placed after the widget (defaults to "").
36 * \param icon Icon filename, placed before the label (defaults to "").
37 * \param mnemonic Mnemonic toggle; if true, an underscore (_) in the label
38 * indicates the next character should be used for the
39 * mnemonic accelerator key (defaults to false).
40 */
41 Point::Point(Glib::ustring const &label, Glib::ustring const &tooltip,
42 Glib::ustring const &suffix,
43 Glib::ustring const &icon,
44 bool mnemonic)
45 : Labelled(label, tooltip, new Gtk::VBox(), suffix, icon, mnemonic),
46 xwidget("X:",""),
47 ywidget("Y:","")
48 {
49 static_cast<Gtk::VBox*>(_widget)->pack_start(xwidget, true, true);
50 static_cast<Gtk::VBox*>(_widget)->pack_start(ywidget, true, true);
51 static_cast<Gtk::VBox*>(_widget)->show_all_children();
52 }
54 /**
55 * Construct a Point Widget.
56 *
57 * \param label Label.
58 * \param digits Number of decimal digits to display.
59 * \param suffix Suffix, placed after the widget (defaults to "").
60 * \param icon Icon filename, placed before the label (defaults to "").
61 * \param mnemonic Mnemonic toggle; if true, an underscore (_) in the label
62 * indicates the next character should be used for the
63 * mnemonic accelerator key (defaults to false).
64 */
65 Point::Point(Glib::ustring const &label, Glib::ustring const &tooltip,
66 unsigned digits,
67 Glib::ustring const &suffix,
68 Glib::ustring const &icon,
69 bool mnemonic)
70 : Labelled(label, tooltip, new Gtk::VBox(), suffix, icon, mnemonic),
71 xwidget("X:","", digits),
72 ywidget("Y:","", digits)
73 {
74 static_cast<Gtk::VBox*>(_widget)->pack_start(xwidget, true, true);
75 static_cast<Gtk::VBox*>(_widget)->pack_start(ywidget, true, true);
76 static_cast<Gtk::VBox*>(_widget)->show_all_children();
77 }
79 /**
80 * Construct a Point Widget.
81 *
82 * \param label Label.
83 * \param adjust Adjustment to use for the SpinButton.
84 * \param digits Number of decimal digits to display (defaults to 0).
85 * \param suffix Suffix, placed after the widget (defaults to "").
86 * \param icon Icon filename, placed before the label (defaults to "").
87 * \param mnemonic Mnemonic toggle; if true, an underscore (_) in the label
88 * indicates the next character should be used for the
89 * mnemonic accelerator key (defaults to true).
90 */
91 Point::Point(Glib::ustring const &label, Glib::ustring const &tooltip,
92 Gtk::Adjustment &adjust,
93 unsigned digits,
94 Glib::ustring const &suffix,
95 Glib::ustring const &icon,
96 bool mnemonic)
97 : Labelled(label, tooltip, new Gtk::VBox(), suffix, icon, mnemonic),
98 xwidget("X:","", adjust, digits),
99 ywidget("Y:","", adjust, digits)
100 {
101 static_cast<Gtk::VBox*>(_widget)->pack_start(xwidget, true, true);
102 static_cast<Gtk::VBox*>(_widget)->pack_start(ywidget, true, true);
103 static_cast<Gtk::VBox*>(_widget)->show_all_children();
104 }
106 /** Fetches the precision of the spin buton */
107 unsigned
108 Point::getDigits() const
109 {
110 return xwidget.getDigits();
111 }
113 /** Gets the current step ingrement used by the spin button */
114 double
115 Point::getStep() const
116 {
117 return xwidget.getStep();
118 }
120 /** Gets the current page increment used by the spin button */
121 double
122 Point::getPage() const
123 {
124 return xwidget.getPage();
125 }
127 /** Gets the minimum range value allowed for the spin button */
128 double
129 Point::getRangeMin() const
130 {
131 return xwidget.getRangeMin();
132 }
134 /** Gets the maximum range value allowed for the spin button */
135 double
136 Point::getRangeMax() const
137 {
138 return xwidget.getRangeMax();
139 }
141 /** Get the value in the spin_button . */
142 double
143 Point::getXValue() const
144 {
145 return xwidget.getValue();
146 }
147 double
148 Point::getYValue() const
149 {
150 return ywidget.getValue();
151 }
152 Geom::Point
153 Point::getValue() const
154 {
155 return Geom::Point( getXValue() , getYValue() );
156 }
158 /** Get the value spin_button represented as an integer. */
159 int
160 Point::getXValueAsInt() const
161 {
162 return xwidget.getValueAsInt();
163 }
164 int
165 Point::getYValueAsInt() const
166 {
167 return ywidget.getValueAsInt();
168 }
171 /** Sets the precision to be displayed by the spin button */
172 void
173 Point::setDigits(unsigned digits)
174 {
175 xwidget.setDigits(digits);
176 ywidget.setDigits(digits);
177 }
179 /** Sets the step and page increments for the spin button */
180 void
181 Point::setIncrements(double step, double page)
182 {
183 xwidget.setIncrements(step, page);
184 ywidget.setIncrements(step, page);
185 }
187 /** Sets the minimum and maximum range allowed for the spin button */
188 void
189 Point::setRange(double min, double max)
190 {
191 xwidget.setRange(min, max);
192 ywidget.setRange(min, max);
193 }
195 /** Sets the value of the spin button */
196 void
197 Point::setValue(Geom::Point & p)
198 {
199 xwidget.setValue(p[0]);
200 ywidget.setValue(p[1]);
201 }
203 /** Manually forces an update of the spin button */
204 void
205 Point::update() {
206 xwidget.update();
207 ywidget.update();
208 }
210 /** Check 'setProgrammatically' of both scalar widgets. False if value is changed by user by clicking the widget. */
211 bool
212 Point::setProgrammatically() {
213 return (xwidget.setProgrammatically || ywidget.setProgrammatically);
214 }
216 void
217 Point::clearProgrammatically() {
218 xwidget.setProgrammatically = false;
219 ywidget.setProgrammatically = false;
220 }
223 /** Signal raised when the spin button's value changes */
224 Glib::SignalProxy0<void>
225 Point::signal_x_value_changed()
226 {
227 return xwidget.signal_value_changed();
228 }
229 Glib::SignalProxy0<void>
230 Point::signal_y_value_changed()
231 {
232 return ywidget.signal_value_changed();
233 }
236 } // namespace Widget
237 } // namespace UI
238 } // namespace Inkscape
240 /*
241 Local Variables:
242 mode:c++
243 c-file-style:"stroustrup"
244 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
245 indent-tabs-mode:nil
246 fill-column:99
247 End:
248 */
249 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :