diff options
| author | Johan B. C. Engelen <jbc.engelen@swissonline.ch> | 2008-01-15 23:43:23 +0000 |
|---|---|---|
| committer | johanengelen <johanengelen@users.sourceforge.net> | 2008-01-15 23:43:23 +0000 |
| commit | b32949eaefba1f07e3898efe060b21a6377b6741 (patch) | |
| tree | 21e97f39886b62bcc5fa2a284a61640cfdfb62a6 /src/ui/widget | |
| parent | Slightly more 'object-oriented' way to invoke item-specific conversion-to-gui... (diff) | |
| download | inkscape-b32949eaefba1f07e3898efe060b21a6377b6741.tar.gz inkscape-b32949eaefba1f07e3898efe060b21a6377b6741.zip | |
RegisteredCheckbutton is now subclassed from RegisteredWidget<CheckButton>
(bzr r4500)
Diffstat (limited to 'src/ui/widget')
| -rw-r--r-- | src/ui/widget/registered-widget.cpp | 70 | ||||
| -rw-r--r-- | src/ui/widget/registered-widget.h | 46 |
2 files changed, 39 insertions, 77 deletions
diff --git a/src/ui/widget/registered-widget.cpp b/src/ui/widget/registered-widget.cpp index a54c89292..e582a117f 100644 --- a/src/ui/widget/registered-widget.cpp +++ b/src/ui/widget/registered-widget.cpp @@ -107,37 +107,31 @@ RegisteredWdg::write_to_xml(const char * svgstr) //==================================================== -RegisteredCheckButton::RegisteredCheckButton() -: _button(0), - setProgrammatically(false) -{ -} - RegisteredCheckButton::~RegisteredCheckButton() { _toggled_connection.disconnect(); - if (_button) delete _button; } -void -RegisteredCheckButton::init (const Glib::ustring& label, const Glib::ustring& tip, const Glib::ustring& key, Registry& wr, bool right, Inkscape::XML::Node* repr_in, SPDocument *doc_in) +RegisteredCheckButton::RegisteredCheckButton (const Glib::ustring& label, const Glib::ustring& tip, const Glib::ustring& key, Registry& wr, bool right, Inkscape::XML::Node* repr_in, SPDocument *doc_in) + : RegisteredWidget<Gtk::CheckButton>() { init_parent(key, wr, repr_in, doc_in); - _button = new Gtk::CheckButton; - _tt.set_tip (*_button, tip); + setProgrammatically = false; + + _tt.set_tip (*this, tip); Gtk::Label *l = new Gtk::Label (label); l->set_use_underline (true); - _button->add (*manage (l)); - _button->set_alignment (right? 1.0 : 0.0, 0.5); - _toggled_connection = _button->signal_toggled().connect (sigc::mem_fun (*this, &RegisteredCheckButton::on_toggled)); + add (*manage (l)); + set_alignment (right? 1.0 : 0.0, 0.5); + _toggled_connection = signal_toggled().connect (sigc::mem_fun (*this, &RegisteredCheckButton::on_toggled)); } void RegisteredCheckButton::setActive (bool b) { setProgrammatically = true; - _button->set_active (b); + set_active (b); //The slave button is greyed out if the master button is unchecked for (std::list<Gtk::ToggleButton*>::const_iterator i = _slavebuttons.begin(); i != _slavebuttons.end(); i++) { (*i)->set_sensitive(b); @@ -157,10 +151,10 @@ RegisteredCheckButton::on_toggled() return; _wr->setUpdating (true); - write_to_xml(_button->get_active() ? "true" : "false"); + write_to_xml(get_active() ? "true" : "false"); //The slave button is greyed out if the master button is unchecked for (std::list<Gtk::ToggleButton*>::const_iterator i = _slavebuttons.begin(); i != _slavebuttons.end(); i++) { - (*i)->set_sensitive(_button->get_active()); + (*i)->set_sensitive(get_active()); } _wr->setUpdating (false); @@ -546,53 +540,31 @@ RegisteredRadioButtonPair::on_value_changed() * Registered POINT */ -RegisteredPoint::RegisteredPoint() -{ - _widget = NULL; -} - RegisteredPoint::~RegisteredPoint() { - if (_widget) - delete _widget; - _value_x_changed_connection.disconnect(); _value_y_changed_connection.disconnect(); } -void -RegisteredPoint::init ( const Glib::ustring& label, const Glib::ustring& tip, +RegisteredPoint::RegisteredPoint ( const Glib::ustring& label, const Glib::ustring& tip, const Glib::ustring& key, Registry& wr, Inkscape::XML::Node* repr_in, SPDocument* doc_in ) + : RegisteredWidget<Point> (label, tip) { init_parent(key, wr, repr_in, doc_in); - _widget = new Point (label, tip); - _widget->setRange (-1e6, 1e6); - _widget->setDigits (2); - _widget->setIncrements(0.1, 1.0); - _value_x_changed_connection = _widget->signal_x_value_changed().connect (sigc::mem_fun (*this, &RegisteredPoint::on_value_changed)); - _value_y_changed_connection = _widget->signal_y_value_changed().connect (sigc::mem_fun (*this, &RegisteredPoint::on_value_changed)); -} - -Point* -RegisteredPoint::getPoint() -{ - return _widget; -} - -void -RegisteredPoint::setValue (double xval, double yval) -{ - if (_widget) - _widget->setValue(xval, yval); + setRange (-1e6, 1e6); + setDigits (2); + setIncrements(0.1, 1.0); + _value_x_changed_connection = signal_x_value_changed().connect (sigc::mem_fun (*this, &RegisteredPoint::on_value_changed)); + _value_y_changed_connection = signal_y_value_changed().connect (sigc::mem_fun (*this, &RegisteredPoint::on_value_changed)); } void RegisteredPoint::on_value_changed() { - if (_widget->setProgrammatically()) { - _widget->clearProgrammatically(); + if (setProgrammatically()) { + clearProgrammatically(); return; } @@ -602,7 +574,7 @@ RegisteredPoint::on_value_changed() _wr->setUpdating (true); Inkscape::SVGOStringStream os; - os << _widget->getXValue() << "," << _widget->getYValue(); + os << getXValue() << "," << getYValue(); write_to_xml(os.str().c_str()); diff --git a/src/ui/widget/registered-widget.h b/src/ui/widget/registered-widget.h index 1a5501427..7c643715f 100644 --- a/src/ui/widget/registered-widget.h +++ b/src/ui/widget/registered-widget.h @@ -3,8 +3,9 @@ * * Authors: * Ralf Stephan <ralf@ark.in-berlin.de> + * Johan Engelen <j.b.c.engelen@utwente.nl> * - * Copyright (C) 2005 Authors + * Copyright (C) 2005-2008 Authors * * Released under GNU GPL. Read the file 'COPYING' for more information. */ @@ -15,10 +16,12 @@ #include <gtkmm/box.h> #include <gtkmm/adjustment.h> #include <gtkmm/tooltips.h> +#include <gtkmm/togglebutton.h> #include "xml/node.h" #include "registry.h" +#include "ui/widget/point.h" #include "ui/widget/random.h" class SPUnit; @@ -28,7 +31,6 @@ namespace Gtk { class HScale; class RadioButton; class SpinButton; - class ToggleButton; } namespace Inkscape { @@ -40,7 +42,6 @@ class Registry; class Scalar; class ScalarUnit; class UnitMenu; -class Point; template <class W> class RegisteredWidget : public W { @@ -137,24 +138,23 @@ protected: //####################################################### -class RegisteredCheckButton : public RegisteredWdg { +class RegisteredCheckButton : public RegisteredWidget<Gtk::CheckButton> { public: - RegisteredCheckButton(); - ~RegisteredCheckButton(); - void init (const Glib::ustring& label, const Glib::ustring& tip, const Glib::ustring& key, Registry& wr, bool right=true, Inkscape::XML::Node* repr_in=NULL, SPDocument *doc_in=NULL); + virtual ~RegisteredCheckButton(); + RegisteredCheckButton (const Glib::ustring& label, const Glib::ustring& tip, const Glib::ustring& key, Registry& wr, bool right=true, Inkscape::XML::Node* repr_in=NULL, SPDocument *doc_in=NULL); + void setActive (bool); - Gtk::ToggleButton *_button; std::list<Gtk::ToggleButton*> _slavebuttons; // a slave button is only sensitive when the master button is active // i.e. a slave button is greyed-out when the master button is not checked void setSlaveButton(std::list<Gtk::ToggleButton*> btns) { - _slavebuttons = btns; + _slavebuttons = btns; } - bool setProgrammatically; // true if the value was set by setValue, not changed by the user; + bool setProgrammatically; // true if the value was set by setActive, not changed by the user; // if a callback checks it, it must reset it back to false @@ -336,27 +336,17 @@ protected: void on_value_changed(); }; -class RegisteredPoint : public RegisteredWdg { +class RegisteredPoint : public RegisteredWidget<Point> { public: - RegisteredPoint(); - ~RegisteredPoint(); - void init (const Glib::ustring& label, - const Glib::ustring& tip, - const Glib::ustring& key, - Registry& wr, - Inkscape::XML::Node* repr_in, - SPDocument *doc_in); - inline void init ( const Glib::ustring& label, - const Glib::ustring& tip, - const Glib::ustring& key, - Registry& wr) - { init(label, tip, key, wr, NULL, NULL); }; - - Point* getPoint(); - void setValue (double xval, double yval); + virtual ~RegisteredPoint(); + RegisteredPoint ( const Glib::ustring& label, + const Glib::ustring& tip, + const Glib::ustring& key, + Registry& wr, + Inkscape::XML::Node* repr_in = NULL, + SPDocument *doc_in = NULL ); protected: - Point *_widget; sigc::connection _value_x_changed_connection; sigc::connection _value_y_changed_connection; void on_value_changed(); |
