index dbef74eaf6b7729ef0be6c82bcff6bf4d9cd847c..d89d4cf5c858299a47f1bcfe7afa7985060ae00a 100644 (file)
//====================================================
ToleranceSlider::ToleranceSlider()
//====================================================
ToleranceSlider::ToleranceSlider()
-: _hbox(0)
+: _vbox(0)
{
}
ToleranceSlider::~ToleranceSlider()
{
{
}
ToleranceSlider::~ToleranceSlider()
{
- if (_hbox) delete _hbox;
+ if (_vbox) delete _vbox;
_scale_changed_connection.disconnect();
}
void
_scale_changed_connection.disconnect();
}
void
-ToleranceSlider::init (const Glib::ustring& label1, const Glib::ustring& label2, const Glib::ustring& tip, const Glib::ustring& key, Registry& wr)
+ToleranceSlider::init (const Glib::ustring& label1, const Glib::ustring& label2, const Glib::ustring& tip1, const Glib::ustring& tip2, const Glib::ustring& key, Registry& wr)
{
{
- _hbox = new Gtk::HBox;
+ // hbox = label + slider
+ //
+ // e.g.
+ //
+ // snap distance |-------X---| 37
+
+ // vbox = checkbutton
+ // +
+ // hbox
+
+ _vbox = new Gtk::VBox;
+ _hbox = manage (new Gtk::HBox);
+
Gtk::Label *theLabel1 = manage (new Gtk::Label (label1));
Gtk::Label *theLabel1 = manage (new Gtk::Label (label1));
- _hbox->add (*theLabel1);
- _hscale = manage (new Gtk::HScale (0.4, 50.1, 0.1));
+ theLabel1->set_use_underline();
+ theLabel1->set_alignment(0, 0.5);
+ // align the label with the checkbox text above by indenting 22 px.
+ _hbox->pack_start(*theLabel1, Gtk::PACK_EXPAND_WIDGET, 22);
+ _hscale = manage (new Gtk::HScale (1.0, 51, 1.0));
+ theLabel1->set_mnemonic_widget (*_hscale);
_hscale->set_draw_value (true);
_hscale->set_value_pos (Gtk::POS_RIGHT);
_hscale->set_size_request (100, -1);
_hscale->set_draw_value (true);
_hscale->set_value_pos (Gtk::POS_RIGHT);
_hscale->set_size_request (100, -1);
- _hbox->add (*_hscale);
+ _old_val = 10;
+ _hscale->set_value (_old_val);
+ _tt.set_tip (*_hscale, tip1);
+ _hbox->add (*_hscale);
+
+
Gtk::Label *theLabel2 = manage (new Gtk::Label (label2));
Gtk::Label *theLabel2 = manage (new Gtk::Label (label2));
- _hbox->add (*theLabel2);
+ theLabel2->set_use_underline();
+ _button = manage (new Gtk::CheckButton);
+ _tt.set_tip (*_button, tip2);
+ _button->add (*theLabel2);
+ _button->set_alignment (0.0, 0.5);
+
+ _vbox->add (*_button);
+ // Here we need some extra pixels to get the vertical spacing right. Why?
+ _vbox->pack_end(*_hbox, true, true, 3); // add 3 px.
_key = key;
_key = key;
- _scale_changed_connection = _hscale->signal_value_changed().connect (sigc::mem_fun (*this, &ToleranceSlider::update));
+ _scale_changed_connection = _hscale->signal_value_changed().connect (sigc::mem_fun (*this, &ToleranceSlider::on_scale_changed));
+ _btn_toggled_connection = _button->signal_toggled().connect (sigc::mem_fun (*this, &ToleranceSlider::on_toggled));
_wr = ≀
_wr = ≀
+ _vbox->show_all_children();
}
void
}
void
-ToleranceSlider::setValue (double val, bool is_absolute)
+ToleranceSlider::setValue (double val)
{
{
- _hscale->set_value (val);
Gtk::Adjustment *adj = _hscale->get_adjustment();
Gtk::Adjustment *adj = _hscale->get_adjustment();
- if (is_absolute)
- {
- adj->set_lower (0.4);
- adj->set_upper (50.1);
- adj->set_step_increment (0.1);
+
+ adj->set_lower (1.0);
+ adj->set_upper (51.0);
+ adj->set_step_increment (1.0);
+
+ if (val > 9999.9) // magic value 10000.0
+ {
+ _button->set_active (true);
+ _hbox->set_sensitive (false);
+ val = 50.0;
}
}
- else
- {
- adj->set_lower (1.0);
- adj->set_upper (51.0);
- adj->set_step_increment (1.0);
+ else
+ {
+ _button->set_active (false);
+ _hbox->set_sensitive (true);
}
}
- update();
+ _hscale->set_value (val);
+ _hbox->show_all();
}
void
}
void
}
void
}
void
-ToleranceSlider::update()
+ToleranceSlider::on_scale_changed()
+{
+ update (_hscale->get_value());
+}
+
+void
+ToleranceSlider::on_toggled()
+{
+ if (_button->get_active())
+ {
+ _old_val = _hscale->get_value();
+ _hbox->set_sensitive (false);
+ _hbox->show_all();
+ setValue (10000.0);
+ update (10000.0);
+ }
+ else
+ {
+ _hbox->set_sensitive (true);
+ _hbox->show_all();
+ setValue (_old_val);
+ update (_old_val);
+ }
+}
+
+void
+ToleranceSlider::update (double val)
{
if (_wr->isUpdating())
return;
{
if (_wr->isUpdating())
return;
return;
Inkscape::SVGOStringStream os;
return;
Inkscape::SVGOStringStream os;
- os << _hscale->get_value();
+ os << val;
_wr->setUpdating (true);
_wr->setUpdating (true);
- SPDocument *doc = SP_DT_DOCUMENT(dt);
- gboolean saved = sp_document_get_undo_sensitive (doc);
- sp_document_set_undo_sensitive (doc, FALSE);
- Inkscape::XML::Node *repr = SP_OBJECT_REPR (SP_DT_NAMEDVIEW(dt));
+ SPDocument *doc = sp_desktop_document(dt);
+ bool saved = sp_document_get_undo_sensitive (doc);
+ sp_document_set_undo_sensitive (doc, false);
+ Inkscape::XML::Node *repr = SP_OBJECT_REPR (sp_desktop_namedview(dt));
repr->setAttribute(_key.c_str(), os.str().c_str());
doc->rroot->setAttribute("sodipodi:modified", "true");
sp_document_set_undo_sensitive (doc, saved);
repr->setAttribute(_key.c_str(), os.str().c_str());
doc->rroot->setAttribute("sodipodi:modified", "true");
sp_document_set_undo_sensitive (doc, saved);
- sp_document_done (doc);
_wr->setUpdating (false);
}
_wr->setUpdating (false);
}