Code

1ea90a7eeb75683c14b9951b84b8cd5886f7858a
[inkscape.git] / src / ui / widget / tolerance-slider.cpp
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 : _hbox(0)
47 {
48 }
50 ToleranceSlider::~ToleranceSlider()
51 {
52     if (_hbox) delete _hbox;
53     _scale_changed_connection.disconnect();
54 }
56 void
57 ToleranceSlider::init (const Glib::ustring& label1, const Glib::ustring& tip, const Glib::ustring& key, Registry& wr)
58 {
59     _hbox = new Gtk::HBox;
60     Gtk::Label *theLabel1 = manage (new Gtk::Label (label1));
61     theLabel1->set_use_underline();
62     _hbox->add (*theLabel1);
63     _hscale = manage (new Gtk::HScale (0.4, 50.1, 0.1));
64     theLabel1->set_mnemonic_widget (*_hscale);
65     _hscale->set_draw_value (true);
66     _hscale->set_value_pos (Gtk::POS_RIGHT);
67     _hscale->set_size_request (100, -1);
68     _tt.set_tip (*_hscale, tip);
69     _hbox->add (*_hscale);
70 //    Gtk::Label *theLabel2 = manage (new Gtk::Label (label2));
71 //    _hbox->add (*theLabel2);
72     _key = key;
73     _scale_changed_connection = _hscale->signal_value_changed().connect (sigc::mem_fun (*this, &ToleranceSlider::update));
74     _wr = &wr;
75 }
77 void 
78 ToleranceSlider::setValue (double val, bool is_absolute)
79 {
80     _hscale->set_value (val);
81     Gtk::Adjustment *adj = _hscale->get_adjustment();
82     if (is_absolute) 
83     { 
84         adj->set_lower (1.0); 
85         adj->set_upper (51.0);
86         adj->set_step_increment (1.0);
87     }
88     else             
89     { 
90         adj->set_lower (0.4); 
91         adj->set_upper (50.1);
92         adj->set_step_increment (0.1);
93     }
94     update();
95 }
97 void
98 ToleranceSlider::setLimits (double theMin, double theMax)
99 {
100     _hscale->set_range (theMin, theMax);
101     _hscale->get_adjustment()->set_step_increment (1);
104 void
105 ToleranceSlider::update()
107     if (_wr->isUpdating())
108         return;
110     SPDesktop *dt = SP_ACTIVE_DESKTOP;
111     if (!dt) 
112         return;
114     Inkscape::SVGOStringStream os;
115     os << _hscale->get_value();
117     _wr->setUpdating (true);
119     SPDocument *doc = SP_DT_DOCUMENT(dt);
120     gboolean saved = sp_document_get_undo_sensitive (doc);
121     sp_document_set_undo_sensitive (doc, FALSE);
122     Inkscape::XML::Node *repr = SP_OBJECT_REPR (SP_DT_NAMEDVIEW(dt));
123     repr->setAttribute(_key.c_str(), os.str().c_str());
124     doc->rroot->setAttribute("sodipodi:modified", "true");
125     sp_document_set_undo_sensitive (doc, saved);
126     sp_document_done (doc);
127     
128     _wr->setUpdating (false);
132 } // namespace Dialog
133 } // namespace UI
134 } // namespace Inkscape
136 /*
137   Local Variables:
138   mode:c++
139   c-file-style:"stroustrup"
140   c-file-offsets:((innamespace . 0)(inline-open . 0))
141   indent-tabs-mode:nil
142   fill-column:99
143   End:
144 */
145 // vim: filetype=c++:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :