3
Implementation of tolerance slider widget.
6
* Ralf Stephan <ralf@ark.in-berlin.de>
8
* Copyright (C) 2006 Authors
10
* Released under GNU GPL. Read the file 'COPYING' for more information
17
#include <gtkmm/adjustment.h>
18
#include <gtkmm/box.h>
19
#include <gtkmm/label.h>
20
#include <gtkmm/scale.h>
23
#include "svg/stringstream.h"
27
#include "desktop-handles.h"
28
#include "sp-namedview.h"
31
#include "tolerance-slider.h"
37
//===================================================
39
//---------------------------------------------------
43
//====================================================
45
ToleranceSlider::ToleranceSlider()
50
ToleranceSlider::~ToleranceSlider()
52
if (_vbox) delete _vbox;
53
_scale_changed_connection.disconnect();
57
ToleranceSlider::init (const Glib::ustring& label1, const Glib::ustring& label2, const Glib::ustring& label3, const Glib::ustring& tip1, const Glib::ustring& tip2, const Glib::ustring& tip3, const Glib::ustring& key, Registry& wr)
59
// hbox = label + slider
63
// snap distance |-------X---| 37
69
_vbox = new Gtk::VBox;
70
_hbox = manage (new Gtk::HBox);
72
Gtk::Label *theLabel1 = manage (new Gtk::Label (label1));
73
theLabel1->set_use_underline();
74
theLabel1->set_alignment(0, 0.5);
75
// align the label with the checkbox text above by indenting 22 px.
76
_hbox->pack_start(*theLabel1, Gtk::PACK_EXPAND_WIDGET, 22);
77
_hscale = manage (new Gtk::HScale (1.0, 51, 1.0));
78
theLabel1->set_mnemonic_widget (*_hscale);
79
_hscale->set_draw_value (true);
80
_hscale->set_value_pos (Gtk::POS_RIGHT);
81
_hscale->set_size_request (100, -1);
83
_hscale->set_value (_old_val);
84
_tt.set_tip (*_hscale, tip1);
85
_hbox->add (*_hscale);
88
Gtk::Label *theLabel2 = manage (new Gtk::Label (label2));
89
theLabel2->set_use_underline();
90
Gtk::Label *theLabel3 = manage (new Gtk::Label (label3));
91
theLabel3->set_use_underline();
92
_button1 = manage (new Gtk::RadioButton);
93
_radio_button_group = _button1->get_group();
94
_button2 = manage (new Gtk::RadioButton);
95
_button2->set_group(_radio_button_group);
96
_tt.set_tip (*_button1, tip2);
97
_tt.set_tip (*_button2, tip3);
98
_button1->add (*theLabel3);
99
_button1->set_alignment (0.0, 0.5);
100
_button2->add (*theLabel2);
101
_button2->set_alignment (0.0, 0.5);
103
_vbox->add (*_button1);
104
_vbox->add (*_button2);
105
// Here we need some extra pixels to get the vertical spacing right. Why?
106
_vbox->pack_end(*_hbox, true, true, 3); // add 3 px.
108
_scale_changed_connection = _hscale->signal_value_changed().connect (sigc::mem_fun (*this, &ToleranceSlider::on_scale_changed));
109
_btn_toggled_connection = _button2->signal_toggled().connect (sigc::mem_fun (*this, &ToleranceSlider::on_toggled));
111
_vbox->show_all_children();
115
ToleranceSlider::setValue (double val)
117
Gtk::Adjustment *adj = _hscale->get_adjustment();
119
adj->set_lower (1.0);
120
adj->set_upper (51.0);
121
adj->set_step_increment (1.0);
123
if (val > 9999.9) // magic value 10000.0
125
_button1->set_active (true);
126
_button2->set_active (false);
127
_hbox->set_sensitive (false);
132
_button1->set_active (false);
133
_button2->set_active (true);
134
_hbox->set_sensitive (true);
136
_hscale->set_value (val);
141
ToleranceSlider::setLimits (double theMin, double theMax)
143
_hscale->set_range (theMin, theMax);
144
_hscale->get_adjustment()->set_step_increment (1);
148
ToleranceSlider::on_scale_changed()
150
update (_hscale->get_value());
154
ToleranceSlider::on_toggled()
156
if (!_button2->get_active())
158
_old_val = _hscale->get_value();
159
_hbox->set_sensitive (false);
166
_hbox->set_sensitive (true);
174
ToleranceSlider::update (double val)
176
if (_wr->isUpdating())
179
SPDesktop *dt = SP_ACTIVE_DESKTOP;
183
Inkscape::SVGOStringStream os;
186
_wr->setUpdating (true);
188
SPDocument *doc = sp_desktop_document(dt);
189
bool saved = sp_document_get_undo_sensitive (doc);
190
sp_document_set_undo_sensitive (doc, false);
191
Inkscape::XML::Node *repr = SP_OBJECT_REPR (sp_desktop_namedview(dt));
192
repr->setAttribute(_key.c_str(), os.str().c_str());
193
sp_document_set_undo_sensitive (doc, saved);
195
doc->setModifiedSinceSave();
197
_wr->setUpdating (false);
201
} // namespace Dialog
203
} // namespace Inkscape
208
c-file-style:"stroustrup"
209
c-file-offsets:((innamespace . 0)(inline-open . 0))
214
// vim: filetype=c++:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :