e777542e3e3eb79e390939327557cdbd4685692b
1 /**
2 * \brief Groups an HScale and a SpinButton together using the same Adjustment
3 *
4 * Author:
5 * Nicholas Bishop <nicholasbishop@gmail.com>
6 *
7 * Copyright (C) 2007 Author
8 *
9 * Released under GNU GPL. Read the file 'COPYING' for more information.
10 */
12 #include "glib/gstrfuncs.h"
14 #include "spin-slider.h"
16 namespace Inkscape {
17 namespace UI {
18 namespace Widget {
20 SpinSlider::SpinSlider(double value, double lower, double upper, double step_inc,
21 double climb_rate, int digits, const SPAttributeEnum a)
22 : AttrWidget(a), _adjustment(value, lower, upper, step_inc),
23 _scale(_adjustment), _spin(_adjustment, climb_rate, digits)
24 {
25 pack_start(_scale);
26 pack_start(_spin, false, false);
28 _scale.set_draw_value(false);
30 show_all_children();
31 }
33 Glib::ustring SpinSlider::get_as_attribute() const
34 {
35 const double val = _adjustment.get_value();
37 if(_spin.get_digits() == 0)
38 return Glib::Ascii::dtostr((int)val);
39 else
40 return Glib::Ascii::dtostr(val);
41 }
43 void SpinSlider::set_from_attribute(SPObject* o)
44 {
45 const gchar* val = attribute_value(o);
46 if(val)
47 _adjustment.set_value(Glib::Ascii::strtod(val));
48 }
50 Glib::SignalProxy0<void> SpinSlider::signal_value_changed()
51 {
52 return _adjustment.signal_value_changed();
53 }
55 double SpinSlider::get_value() const
56 {
57 return _adjustment.get_value();
58 }
60 void SpinSlider::set_value(const double val)
61 {
62 _adjustment.set_value(val);
63 }
65 const Gtk::Adjustment& SpinSlider::get_adjustment() const
66 {
67 return _adjustment;
68 }
69 Gtk::Adjustment& SpinSlider::get_adjustment()
70 {
71 return _adjustment;
72 }
74 const Gtk::HScale& SpinSlider::get_scale() const
75 {
76 return _scale;
77 }
78 Gtk::HScale& SpinSlider::get_scale()
79 {
80 return _scale;
81 }
83 const Gtk::SpinButton& SpinSlider::get_spin_button() const
84 {
85 return _spin;
86 }
87 Gtk::SpinButton& SpinSlider::get_spin_button()
88 {
89 return _spin;
90 }
92 void SpinSlider::set_update_policy(const Gtk::UpdateType u)
93 {
94 _scale.set_update_policy(u);
95 }
97 void SpinSlider::remove_scale()
98 {
99 remove(_scale);
100 }
102 DualSpinSlider::DualSpinSlider(double value, double lower, double upper, double step_inc,
103 double climb_rate, int digits, const SPAttributeEnum a)
104 : AttrWidget(a), _s1(value, lower, upper, step_inc, climb_rate, digits),
105 _s2(value, lower, upper, step_inc, climb_rate, digits)
106 {
107 _s1.get_adjustment().signal_value_changed().connect(_signal_value_changed.make_slot());
108 _s2.get_adjustment().signal_value_changed().connect(_signal_value_changed.make_slot());
109 }
111 Glib::ustring DualSpinSlider::get_as_attribute() const
112 {
113 return _s1.get_as_attribute() + " " + _s2.get_as_attribute();
114 }
116 void DualSpinSlider::set_from_attribute(SPObject* o)
117 {
118 const gchar* val = attribute_value(o);
119 if(val) {
120 // Split val into parts
121 gchar** toks = g_strsplit(val, " ", 2);
123 if(toks) {
124 double v1, v2;
125 if(toks[0])
126 v1 = v2 = Glib::Ascii::strtod(toks[0]);
127 if(toks[1])
128 v2 = Glib::Ascii::strtod(toks[1]);
130 _s1.get_adjustment().set_value(v1);
131 _s2.get_adjustment().set_value(v2);
133 g_strfreev(toks);
134 }
135 }
136 }
138 sigc::signal<void>& DualSpinSlider::signal_value_changed()
139 {
140 return _signal_value_changed;
141 }
143 const SpinSlider& DualSpinSlider::get_spinslider1() const
144 {
145 return _s1;
146 }
148 SpinSlider& DualSpinSlider::get_spinslider1()
149 {
150 return _s1;
151 }
153 const SpinSlider& DualSpinSlider::get_spinslider2() const
154 {
155 return _s2;
156 }
158 SpinSlider& DualSpinSlider::get_spinslider2()
159 {
160 return _s2;
161 }
163 void DualSpinSlider::set_update_policy(const Gtk::UpdateType u)
164 {
165 _s1.set_update_policy(u);
166 _s2.set_update_policy(u);
167 }
169 void DualSpinSlider::remove_scale()
170 {
171 _s1.remove_scale();
172 _s2.remove_scale();
173 }
175 } // namespace Widget
176 } // namespace UI
177 } // namespace Inkscape
179 /*
180 Local Variables:
181 mode:c++
182 c-file-style:"stroustrup"
183 c-file-offsets:((innamespace . 0)(inline-open . 0))
184 indent-tabs-mode:nil
185 fill-column:99
186 End:
187 */
188 // vim: filetype=c++:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :