fd98b0a3774dc5e1249eed57006f09d8e43b0eb4
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)
88 {
89 Gtk::Adjustment *adj = _hscale->get_adjustment();
91 adj->set_lower (1.0);
92 adj->set_upper (50.0);
93 adj->set_step_increment (1.0);
95 if (val > 9999.9) // magic value 10000.0
96 {
97 _button->set_active (true);
98 _hbox->set_sensitive (false);
99 val = 50.0;
100 }
101 else
102 {
103 _button->set_active (false);
104 _hbox->set_sensitive (true);
105 }
106 _hscale->set_value (val);
107 _hbox->show_all();
108 }
110 void
111 ToleranceSlider::setLimits (double theMin, double theMax)
112 {
113 _hscale->set_range (theMin, theMax);
114 _hscale->get_adjustment()->set_step_increment (1);
115 }
117 void
118 ToleranceSlider::on_scale_changed()
119 {
120 update (_hscale->get_value());
121 }
123 void
124 ToleranceSlider::on_toggled()
125 {
126 if (_button->get_active())
127 {
128 _hbox->set_sensitive (false);
129 _hbox->show_all();
130 setValue (10000.0);
131 update (10000.0);
132 }
133 else
134 {
135 _hbox->set_sensitive (true);
136 _hbox->show_all();
137 setValue (50.0);
138 update (50.0);
139 }
140 }
142 void
143 ToleranceSlider::update (double val)
144 {
145 if (_wr->isUpdating())
146 return;
148 SPDesktop *dt = SP_ACTIVE_DESKTOP;
149 if (!dt)
150 return;
152 Inkscape::SVGOStringStream os;
153 os << val;
155 _wr->setUpdating (true);
157 SPDocument *doc = sp_desktop_document(dt);
158 bool saved = sp_document_get_undo_sensitive (doc);
159 sp_document_set_undo_sensitive (doc, false);
160 Inkscape::XML::Node *repr = SP_OBJECT_REPR (sp_desktop_namedview(dt));
161 repr->setAttribute(_key.c_str(), os.str().c_str());
162 doc->rroot->setAttribute("sodipodi:modified", "true");
163 sp_document_set_undo_sensitive (doc, saved);
164 sp_document_done (doc, SP_VERB_NONE,
165 /* TODO: annotate */ "tolerance-slider.cpp:173");
167 _wr->setUpdating (false);
168 }
171 } // namespace Dialog
172 } // namespace UI
173 } // namespace Inkscape
175 /*
176 Local Variables:
177 mode:c++
178 c-file-style:"stroustrup"
179 c-file-offsets:((innamespace . 0)(inline-open . 0))
180 indent-tabs-mode:nil
181 fill-column:99
182 End:
183 */
184 // vim: filetype=c++:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :