f9a991c245694657771ccda5463a59611cb26684
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 (1.0, 51, 1.0));
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 _old_val = 10;
70 _hscale->set_value (_old_val);
71 _tt.set_tip (*_hscale, tip1);
72 _hbox->add (*_hscale);
73 _vbox->add (*_hbox);
74 Gtk::Label *theLabel2 = manage (new Gtk::Label (label2));
75 theLabel2->set_use_underline();
76 _button = manage (new Gtk::CheckButton);
77 _tt.set_tip (*_button, tip2);
78 _button->add (*theLabel2);
79 _button->set_alignment (0.0, 0.5);
80 _vbox->add (*_button);
81 _key = key;
82 _scale_changed_connection = _hscale->signal_value_changed().connect (sigc::mem_fun (*this, &ToleranceSlider::on_scale_changed));
83 _btn_toggled_connection = _button->signal_toggled().connect (sigc::mem_fun (*this, &ToleranceSlider::on_toggled));
84 _wr = ≀
85 _vbox->show_all_children();
86 }
88 void
89 ToleranceSlider::setValue (double val)
90 {
91 Gtk::Adjustment *adj = _hscale->get_adjustment();
93 adj->set_lower (1.0);
94 adj->set_upper (51.0);
95 adj->set_step_increment (1.0);
97 if (val > 9999.9) // magic value 10000.0
98 {
99 _button->set_active (true);
100 _hbox->set_sensitive (false);
101 val = 50.0;
102 }
103 else
104 {
105 _button->set_active (false);
106 _hbox->set_sensitive (true);
107 }
108 _hscale->set_value (val);
109 _hbox->show_all();
110 }
112 void
113 ToleranceSlider::setLimits (double theMin, double theMax)
114 {
115 _hscale->set_range (theMin, theMax);
116 _hscale->get_adjustment()->set_step_increment (1);
117 }
119 void
120 ToleranceSlider::on_scale_changed()
121 {
122 update (_hscale->get_value());
123 }
125 void
126 ToleranceSlider::on_toggled()
127 {
128 if (_button->get_active())
129 {
130 _old_val = _hscale->get_value();
131 _hbox->set_sensitive (false);
132 _hbox->show_all();
133 setValue (10000.0);
134 update (10000.0);
135 }
136 else
137 {
138 _hbox->set_sensitive (true);
139 _hbox->show_all();
140 setValue (_old_val);
141 update (_old_val);
142 }
143 }
145 void
146 ToleranceSlider::update (double val)
147 {
148 if (_wr->isUpdating())
149 return;
151 SPDesktop *dt = SP_ACTIVE_DESKTOP;
152 if (!dt)
153 return;
155 Inkscape::SVGOStringStream os;
156 os << val;
158 _wr->setUpdating (true);
160 SPDocument *doc = sp_desktop_document(dt);
161 bool saved = sp_document_get_undo_sensitive (doc);
162 sp_document_set_undo_sensitive (doc, false);
163 Inkscape::XML::Node *repr = SP_OBJECT_REPR (sp_desktop_namedview(dt));
164 repr->setAttribute(_key.c_str(), os.str().c_str());
165 doc->rroot->setAttribute("sodipodi:modified", "true");
166 sp_document_set_undo_sensitive (doc, saved);
168 _wr->setUpdating (false);
169 }
172 } // namespace Dialog
173 } // namespace UI
174 } // namespace Inkscape
176 /*
177 Local Variables:
178 mode:c++
179 c-file-style:"stroustrup"
180 c-file-offsets:((innamespace . 0)(inline-open . 0))
181 indent-tabs-mode:nil
182 fill-column:99
183 End:
184 */
185 // vim: filetype=c++:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :