654936814ec61f824e465b7ee7652a993c49c023
1 /** \file
2 *
3 Implementation of tolerance slider widget.
4 *
5 * Authors:
6 * Ralf Stephan <ralf@ark.in-berlin.de>
7 *
8 * Copyright (C) 2006 Authors
9 *
10 * Released under GNU GPL. Read the file 'COPYING' for more information
11 */
13 #ifdef HAVE_CONFIG_H
14 # include <config.h>
15 #endif
17 #include <gtkmm/adjustment.h>
18 #include <gtkmm/box.h>
19 #include <gtkmm/label.h>
20 #include <gtkmm/scale.h>
22 #include "xml/repr.h"
23 #include "svg/stringstream.h"
25 #include "inkscape.h"
26 #include "document.h"
27 #include "desktop-handles.h"
28 #include "sp-namedview.h"
30 #include "registry.h"
31 #include "tolerance-slider.h"
33 namespace Inkscape {
34 namespace UI {
35 namespace Widget {
37 //===================================================
39 //---------------------------------------------------
43 //====================================================
45 ToleranceSlider::ToleranceSlider()
46 : _vbox(0)
47 {
48 }
50 ToleranceSlider::~ToleranceSlider()
51 {
52 if (_vbox) delete _vbox;
53 _scale_changed_connection.disconnect();
54 }
56 void
57 ToleranceSlider::init (const Glib::ustring& label1, const Glib::ustring& label2, const Glib::ustring& tip1, const Glib::ustring& tip2, const Glib::ustring& key, Registry& wr)
58 {
59 _vbox = new Gtk::VBox;
60 _hbox = manage (new Gtk::HBox);
61 Gtk::Label *theLabel1 = manage (new Gtk::Label (label1));
62 theLabel1->set_use_underline();
63 _hbox->add (*theLabel1);
64 _hscale = manage (new Gtk::HScale (0.4, 50.1, 0.1));
65 theLabel1->set_mnemonic_widget (*_hscale);
66 _hscale->set_draw_value (true);
67 _hscale->set_value_pos (Gtk::POS_RIGHT);
68 _hscale->set_size_request (100, -1);
69 _tt.set_tip (*_hscale, tip1);
70 _hbox->add (*_hscale);
71 _vbox->add (*_hbox);
72 Gtk::Label *theLabel2 = manage (new Gtk::Label (label2));
73 theLabel2->set_use_underline();
74 _button = manage (new Gtk::CheckButton);
75 _tt.set_tip (*_button, tip2);
76 _button->add (*theLabel2);
77 _button->set_alignment (0.0, 0.5);
78 _vbox->add (*_button);
79 _key = key;
80 _scale_changed_connection = _hscale->signal_value_changed().connect (sigc::mem_fun (*this, &ToleranceSlider::on_scale_changed));
81 _btn_toggled_connection = _button->signal_toggled().connect (sigc::mem_fun (*this, &ToleranceSlider::on_toggled));
82 _wr = ≀
83 _vbox->show_all_children();
84 }
86 void
87 ToleranceSlider::setValue (double val, bool is_absolute)
88 {
89 Gtk::Adjustment *adj = _hscale->get_adjustment();
90 if (is_absolute)
91 {
92 adj->set_lower (1.0);
93 adj->set_upper (51.0);
94 adj->set_step_increment (1.0);
95 }
96 else
97 {
98 adj->set_lower (0.4);
99 adj->set_upper (50.1);
100 adj->set_step_increment (0.1);
101 }
103 if (val > 9999.9) // magic value 10000.0
104 {
105 _button->set_active (true);
106 _hbox->set_sensitive (false);
107 val = 50.0;
108 }
109 else
110 {
111 _button->set_active (false);
112 _hbox->set_sensitive (true);
113 }
114 _hscale->set_value (val);
115 _hbox->show_all();
116 }
118 void
119 ToleranceSlider::setLimits (double theMin, double theMax)
120 {
121 _hscale->set_range (theMin, theMax);
122 _hscale->get_adjustment()->set_step_increment (1);
123 }
125 void
126 ToleranceSlider::on_scale_changed()
127 {
128 update (_hscale->get_value());
129 }
131 void
132 ToleranceSlider::on_toggled()
133 {
134 if (_button->get_active())
135 {
136 _hbox->set_sensitive (false);
137 _hbox->show_all();
138 setValue (10000.0);
139 update (10000.0);
140 }
141 else
142 {
143 _hbox->set_sensitive (true);
144 _hbox->show_all();
145 setValue (50.0);
146 update (50.0);
147 }
148 }
150 void
151 ToleranceSlider::update (double val)
152 {
153 if (_wr->isUpdating())
154 return;
156 SPDesktop *dt = SP_ACTIVE_DESKTOP;
157 if (!dt)
158 return;
160 Inkscape::SVGOStringStream os;
161 os << val;
163 _wr->setUpdating (true);
165 SPDocument *doc = sp_desktop_document(dt);
166 gboolean saved = sp_document_get_undo_sensitive (doc);
167 sp_document_set_undo_sensitive (doc, FALSE);
168 Inkscape::XML::Node *repr = SP_OBJECT_REPR (sp_desktop_namedview(dt));
169 repr->setAttribute(_key.c_str(), os.str().c_str());
170 doc->rroot->setAttribute("sodipodi:modified", "true");
171 sp_document_set_undo_sensitive (doc, saved);
172 sp_document_done (doc);
174 _wr->setUpdating (false);
175 }
178 } // namespace Dialog
179 } // namespace UI
180 } // namespace Inkscape
182 /*
183 Local Variables:
184 mode:c++
185 c-file-style:"stroustrup"
186 c-file-offsets:((innamespace . 0)(inline-open . 0))
187 indent-tabs-mode:nil
188 fill-column:99
189 End:
190 */
191 // vim: filetype=c++:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :