Code

f27cfe8c686b9e2fba56947e021cebfc92076176
[inkscape.git] / src / ui / widget / point.cpp
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)
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();
106 /** Fetches the precision of the spin buton */
107 unsigned
108 Point::getDigits() const
110     return xwidget.getDigits();
113 /** Gets the current step ingrement used by the spin button */
114 double
115 Point::getStep() const
117     return xwidget.getStep();
120 /** Gets the current page increment used by the spin button */
121 double
122 Point::getPage() const
124     return xwidget.getPage();
127 /** Gets the minimum range value allowed for the spin button */
128 double
129 Point::getRangeMin() const
131     return xwidget.getRangeMin();
134 /** Gets the maximum range value allowed for the spin button */
135 double
136 Point::getRangeMax() const
138     return xwidget.getRangeMax();
141 /** Get the value in the spin_button . */
142 double
143 Point::getXValue() const
145     return xwidget.getValue();
147 double
148 Point::getYValue() const
150     return ywidget.getValue();
152 Geom::Point
153 Point::getValue() const
155     return Geom::Point( getXValue() , getYValue() );
158 /** Get the value spin_button represented as an integer. */
159 int
160 Point::getXValueAsInt() const
162     return xwidget.getValueAsInt();
164 int
165 Point::getYValueAsInt() const
167     return ywidget.getValueAsInt();
171 /** Sets the precision to be displayed by the spin button */
172 void
173 Point::setDigits(unsigned digits)
175     xwidget.setDigits(digits);
176     ywidget.setDigits(digits);
179 /** Sets the step and page increments for the spin button */
180 void
181 Point::setIncrements(double step, double page)
183     xwidget.setIncrements(step, page);
184     ywidget.setIncrements(step, page);
187 /** Sets the minimum and maximum range allowed for the spin button */
188 void
189 Point::setRange(double min, double max)
191     xwidget.setRange(min, max);
192     ywidget.setRange(min, max);
195 /** Sets the value of the spin button */
196 void
197 Point::setValue(Geom::Point const & p)
199     xwidget.setValue(p[0]);
200     ywidget.setValue(p[1]);
203 /** Manually forces an update of the spin button */
204 void
205 Point::update() {
206     xwidget.update();
207     ywidget.update();
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);
216 void
217 Point::clearProgrammatically() {
218     xwidget.setProgrammatically = false;
219     ywidget.setProgrammatically = false;
223 /** Signal raised when the spin button's value changes */
224 Glib::SignalProxy0<void>
225 Point::signal_x_value_changed()
227     return xwidget.signal_value_changed();
229 Glib::SignalProxy0<void>
230 Point::signal_y_value_changed()
232     return ywidget.signal_value_changed();
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 :