tolerance-slider.cpp revision 1e595ddc34dd7090b285ed9f6fc8e125b9a264d9
f200d31b8a03050faa7243929bbd5698db488399Diederik van Lierop/** \file
f200d31b8a03050faa7243929bbd5698db488399Diederik van Lierop *
f200d31b8a03050faa7243929bbd5698db488399Diederik van Lierop Implementation of tolerance slider widget.
f200d31b8a03050faa7243929bbd5698db488399Diederik van Lierop *
f200d31b8a03050faa7243929bbd5698db488399Diederik van Lierop * Authors:
f200d31b8a03050faa7243929bbd5698db488399Diederik van Lierop * Ralf Stephan <ralf@ark.in-berlin.de>
f200d31b8a03050faa7243929bbd5698db488399Diederik van Lierop *
f200d31b8a03050faa7243929bbd5698db488399Diederik van Lierop * Copyright (C) 2006 Authors
f200d31b8a03050faa7243929bbd5698db488399Diederik van Lierop *
f200d31b8a03050faa7243929bbd5698db488399Diederik van Lierop * Released under GNU GPL. Read the file 'COPYING' for more information
f200d31b8a03050faa7243929bbd5698db488399Diederik van Lierop */
f200d31b8a03050faa7243929bbd5698db488399Diederik van Lierop
f200d31b8a03050faa7243929bbd5698db488399Diederik van Lierop#ifdef HAVE_CONFIG_H
f200d31b8a03050faa7243929bbd5698db488399Diederik van Lierop# include <config.h>
f200d31b8a03050faa7243929bbd5698db488399Diederik van Lierop#endif
f200d31b8a03050faa7243929bbd5698db488399Diederik van Lierop
f200d31b8a03050faa7243929bbd5698db488399Diederik van Lierop#include <gtkmm/adjustment.h>
f200d31b8a03050faa7243929bbd5698db488399Diederik van Lierop#include <gtkmm/box.h>
f200d31b8a03050faa7243929bbd5698db488399Diederik van Lierop#include <gtkmm/label.h>
f200d31b8a03050faa7243929bbd5698db488399Diederik van Lierop#include <gtkmm/scale.h>
f200d31b8a03050faa7243929bbd5698db488399Diederik van Lierop
f200d31b8a03050faa7243929bbd5698db488399Diederik van Lierop#include "xml/repr.h"
727eeb2592befe925906eb7605e9ed770697162bDiederik van Lierop#include "svg/stringstream.h"
45d2569e428fc3733725b5e64e313e48c2a9d989Diederik van Lierop
f200d31b8a03050faa7243929bbd5698db488399Diederik van Lierop#include "inkscape.h"
f200d31b8a03050faa7243929bbd5698db488399Diederik van Lierop#include "document.h"
f200d31b8a03050faa7243929bbd5698db488399Diederik van Lierop#include "desktop-handles.h"
f200d31b8a03050faa7243929bbd5698db488399Diederik van Lierop#include "sp-namedview.h"
f200d31b8a03050faa7243929bbd5698db488399Diederik van Lierop
727eeb2592befe925906eb7605e9ed770697162bDiederik van Lierop#include "registry.h"
ae73b82cf10057153a43afdcb1f3a22deac18ea2Diederik van Lierop#include "tolerance-slider.h"
f200d31b8a03050faa7243929bbd5698db488399Diederik van Lierop
f200d31b8a03050faa7243929bbd5698db488399Diederik van Lieropnamespace Inkscape {
f200d31b8a03050faa7243929bbd5698db488399Diederik van Lieropnamespace UI {
45d2569e428fc3733725b5e64e313e48c2a9d989Diederik van Lieropnamespace Widget {
f200d31b8a03050faa7243929bbd5698db488399Diederik van Lierop
f200d31b8a03050faa7243929bbd5698db488399Diederik van Lierop//===================================================
e0762361898748e8a6943d30ef1b5b070d4498a1Diederik van Lierop
f200d31b8a03050faa7243929bbd5698db488399Diederik van Lierop//---------------------------------------------------
727eeb2592befe925906eb7605e9ed770697162bDiederik van Lierop
727eeb2592befe925906eb7605e9ed770697162bDiederik van Lierop
727eeb2592befe925906eb7605e9ed770697162bDiederik van Lierop
727eeb2592befe925906eb7605e9ed770697162bDiederik van Lierop//====================================================
727eeb2592befe925906eb7605e9ed770697162bDiederik van Lierop
727eeb2592befe925906eb7605e9ed770697162bDiederik van LieropToleranceSlider::ToleranceSlider()
45d2569e428fc3733725b5e64e313e48c2a9d989Diederik van Lierop: _vbox(0)
f200d31b8a03050faa7243929bbd5698db488399Diederik van Lierop{
c60180049420944fe78f7d8b2ca1df28cba163fdDiederik van Lierop}
45d2569e428fc3733725b5e64e313e48c2a9d989Diederik van Lierop
72cd517ebd6730a0b8b1b71bdb267ffe9f1d94ffDiederik van LieropToleranceSlider::~ToleranceSlider()
c60180049420944fe78f7d8b2ca1df28cba163fdDiederik van Lierop{
195e5fada891025f6d2f260e915ac209e0c0a5d0Diederik van Lierop if (_vbox) delete _vbox;
f200d31b8a03050faa7243929bbd5698db488399Diederik van Lierop _scale_changed_connection.disconnect();
f200d31b8a03050faa7243929bbd5698db488399Diederik van Lierop}
72cd517ebd6730a0b8b1b71bdb267ffe9f1d94ffDiederik van Lierop
72cd517ebd6730a0b8b1b71bdb267ffe9f1d94ffDiederik van Lieropvoid
72cd517ebd6730a0b8b1b71bdb267ffe9f1d94ffDiederik van LieropToleranceSlider::init (const Glib::ustring& label1, const Glib::ustring& label2, const Glib::ustring& tip1, const Glib::ustring& tip2, const Glib::ustring& key, Registry& wr)
727eeb2592befe925906eb7605e9ed770697162bDiederik van Lierop{
45d2569e428fc3733725b5e64e313e48c2a9d989Diederik van Lierop // hbox = label + slider
45d2569e428fc3733725b5e64e313e48c2a9d989Diederik van Lierop //
72cd517ebd6730a0b8b1b71bdb267ffe9f1d94ffDiederik van Lierop // e.g.
72cd517ebd6730a0b8b1b71bdb267ffe9f1d94ffDiederik van Lierop //
72cd517ebd6730a0b8b1b71bdb267ffe9f1d94ffDiederik van Lierop // snap distance |-------X---| 37
72cd517ebd6730a0b8b1b71bdb267ffe9f1d94ffDiederik van Lierop
72cd517ebd6730a0b8b1b71bdb267ffe9f1d94ffDiederik van Lierop // vbox = checkbutton
727eeb2592befe925906eb7605e9ed770697162bDiederik van Lierop // +
72cd517ebd6730a0b8b1b71bdb267ffe9f1d94ffDiederik van Lierop // hbox
72cd517ebd6730a0b8b1b71bdb267ffe9f1d94ffDiederik van Lierop
72cd517ebd6730a0b8b1b71bdb267ffe9f1d94ffDiederik van Lierop _vbox = new Gtk::VBox;
72cd517ebd6730a0b8b1b71bdb267ffe9f1d94ffDiederik van Lierop _hbox = manage (new Gtk::HBox);
72cd517ebd6730a0b8b1b71bdb267ffe9f1d94ffDiederik van Lierop
45d2569e428fc3733725b5e64e313e48c2a9d989Diederik van Lierop Gtk::Label *theLabel1 = manage (new Gtk::Label (label1));
45d2569e428fc3733725b5e64e313e48c2a9d989Diederik van Lierop theLabel1->set_use_underline();
72cd517ebd6730a0b8b1b71bdb267ffe9f1d94ffDiederik van Lierop theLabel1->set_alignment(0, 0.5);
727eeb2592befe925906eb7605e9ed770697162bDiederik van Lierop // align the label with the checkbox text above by indenting 22 px.
72cd517ebd6730a0b8b1b71bdb267ffe9f1d94ffDiederik van Lierop _hbox->pack_start(*theLabel1, Gtk::PACK_EXPAND_WIDGET, 22);
72cd517ebd6730a0b8b1b71bdb267ffe9f1d94ffDiederik van Lierop _hscale = manage (new Gtk::HScale (1.0, 51, 1.0));
72cd517ebd6730a0b8b1b71bdb267ffe9f1d94ffDiederik van Lierop theLabel1->set_mnemonic_widget (*_hscale);
72cd517ebd6730a0b8b1b71bdb267ffe9f1d94ffDiederik van Lierop _hscale->set_draw_value (true);
72cd517ebd6730a0b8b1b71bdb267ffe9f1d94ffDiederik van Lierop _hscale->set_value_pos (Gtk::POS_RIGHT);
72cd517ebd6730a0b8b1b71bdb267ffe9f1d94ffDiederik van Lierop _hscale->set_size_request (100, -1);
727eeb2592befe925906eb7605e9ed770697162bDiederik van Lierop _old_val = 10;
727eeb2592befe925906eb7605e9ed770697162bDiederik van Lierop _hscale->set_value (_old_val);
727eeb2592befe925906eb7605e9ed770697162bDiederik van Lierop _tt.set_tip (*_hscale, tip1);
727eeb2592befe925906eb7605e9ed770697162bDiederik van Lierop _hbox->add (*_hscale);
72cd517ebd6730a0b8b1b71bdb267ffe9f1d94ffDiederik van Lierop
45d2569e428fc3733725b5e64e313e48c2a9d989Diederik van Lierop
72cd517ebd6730a0b8b1b71bdb267ffe9f1d94ffDiederik van Lierop Gtk::Label *theLabel2 = manage (new Gtk::Label (label2));
72cd517ebd6730a0b8b1b71bdb267ffe9f1d94ffDiederik van Lierop theLabel2->set_use_underline();
72cd517ebd6730a0b8b1b71bdb267ffe9f1d94ffDiederik van Lierop _button = manage (new Gtk::CheckButton);
72cd517ebd6730a0b8b1b71bdb267ffe9f1d94ffDiederik van Lierop _tt.set_tip (*_button, tip2);
45d2569e428fc3733725b5e64e313e48c2a9d989Diederik van Lierop _button->add (*theLabel2);
45d2569e428fc3733725b5e64e313e48c2a9d989Diederik van Lierop _button->set_alignment (0.0, 0.5);
45d2569e428fc3733725b5e64e313e48c2a9d989Diederik van Lierop
72cd517ebd6730a0b8b1b71bdb267ffe9f1d94ffDiederik van Lierop _vbox->add (*_button);
72cd517ebd6730a0b8b1b71bdb267ffe9f1d94ffDiederik van Lierop // Here we need some extra pixels to get the vertical spacing right. Why?
f200d31b8a03050faa7243929bbd5698db488399Diederik van Lierop _vbox->pack_end(*_hbox, true, true, 3); // add 3 px.
f200d31b8a03050faa7243929bbd5698db488399Diederik van Lierop _key = key;
_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
ToleranceSlider::setValue (double val)
{
Gtk::Adjustment *adj = _hscale->get_adjustment();
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 (false);
_hbox->set_sensitive (false);
val = 50.0;
}
else
{
_button->set_active (true);
_hbox->set_sensitive (true);
}
_hscale->set_value (val);
_hbox->show_all();
}
void
ToleranceSlider::setLimits (double theMin, double theMax)
{
_hscale->set_range (theMin, theMax);
_hscale->get_adjustment()->set_step_increment (1);
}
void
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;
SPDesktop *dt = SP_ACTIVE_DESKTOP;
if (!dt)
return;
Inkscape::SVGOStringStream os;
os << val;
_wr->setUpdating (true);
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());
sp_document_set_undo_sensitive (doc, saved);
doc->setModifiedSinceSave();
_wr->setUpdating (false);
}
} // namespace Dialog
} // namespace UI
} // namespace Inkscape
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=c++:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :