diff options
| author | Johan B. C. Engelen <jbc.engelen@swissonline.ch> | 2010-02-14 21:56:16 +0000 |
|---|---|---|
| committer | Johan <Johan@JohannesMobile> | 2010-02-14 21:56:16 +0000 |
| commit | fcdf77adc6f2561600db805f202180ca8ef33e7b (patch) | |
| tree | adcf387f915bc75faace2ee79b9d824f9934eb0f /src/ui/widget | |
| parent | File preview max size increased to 10Mio. (diff) | |
| download | inkscape-fcdf77adc6f2561600db805f202180ca8ef33e7b.tar.gz inkscape-fcdf77adc6f2561600db805f202180ca8ef33e7b.zip | |
add widget controls for LPE VectorParam. Hide these controls for LPE Hatches.
(bzr r9086.1.1)
Diffstat (limited to 'src/ui/widget')
| -rw-r--r-- | src/ui/widget/labelled.h | 2 | ||||
| -rw-r--r-- | src/ui/widget/point.cpp | 2 | ||||
| -rw-r--r-- | src/ui/widget/point.h | 2 | ||||
| -rw-r--r-- | src/ui/widget/registered-widget.cpp | 90 | ||||
| -rw-r--r-- | src/ui/widget/registered-widget.h | 25 |
5 files changed, 119 insertions, 2 deletions
diff --git a/src/ui/widget/labelled.h b/src/ui/widget/labelled.h index 3685944a4..5670af0b6 100644 --- a/src/ui/widget/labelled.h +++ b/src/ui/widget/labelled.h @@ -39,6 +39,8 @@ public: Gtk::Widget const *getWidget() const; Gtk::Label const *getLabel() const; + void setLabelText(const Glib::ustring &str) { _label->set_text(str); }; + protected: Gtk::Widget *_widget; Gtk::Label *_label; diff --git a/src/ui/widget/point.cpp b/src/ui/widget/point.cpp index 508a8d961..f27cfe8c6 100644 --- a/src/ui/widget/point.cpp +++ b/src/ui/widget/point.cpp @@ -194,7 +194,7 @@ Point::setRange(double min, double max) /** Sets the value of the spin button */ void -Point::setValue(Geom::Point & p) +Point::setValue(Geom::Point const & p) { xwidget.setValue(p[0]); ywidget.setValue(p[1]); diff --git a/src/ui/widget/point.h b/src/ui/widget/point.h index 57a46de76..94477d877 100644 --- a/src/ui/widget/point.h +++ b/src/ui/widget/point.h @@ -64,7 +64,7 @@ public: void setDigits(unsigned digits); void setIncrements(double step, double page); void setRange(double min, double max); - void setValue(Geom::Point & p); + void setValue(Geom::Point const & p); void update(); diff --git a/src/ui/widget/registered-widget.cpp b/src/ui/widget/registered-widget.cpp index 95ddec286..db31d08d3 100644 --- a/src/ui/widget/registered-widget.cpp +++ b/src/ui/widget/registered-widget.cpp @@ -587,6 +587,96 @@ RegisteredTransformedPoint::on_value_changed() } /*######################################### + * Registered TRANSFORMEDPOINT + */ + +RegisteredVector::~RegisteredVector() +{ + _value_x_changed_connection.disconnect(); + _value_y_changed_connection.disconnect(); +} + +RegisteredVector::RegisteredVector ( 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), + _polar_coords(false) +{ + init_parent(key, wr, repr_in, doc_in); + + setRange (-1e6, 1e6); + setDigits (2); + setIncrements(0.1, 1.0); + _value_x_changed_connection = signal_x_value_changed().connect (sigc::mem_fun (*this, &RegisteredVector::on_value_changed)); + _value_y_changed_connection = signal_y_value_changed().connect (sigc::mem_fun (*this, &RegisteredVector::on_value_changed)); +} + +void +RegisteredVector::setValue(Geom::Point const & p) +{ + if (!_polar_coords) { + Point::setValue(p); + } else { + Geom::Point polar; + polar[Geom::X] = atan2(p) *180/M_PI; + polar[Geom::Y] = p.length(); + Point::setValue(polar); + } +} + +void +RegisteredVector::setValue(Geom::Point const & p, Geom::Point const & origin) +{ + RegisteredVector::setValue(p); + _origin = origin; +} + +/** + * Changes the widgets text to polar coordinates. The SVG output will still be a normal carthesian vector. + * Careful: when calling getValue(), the return value's X-coord will be the angle, Y-value will be the distance/length. + * After changing the coords type (polar/non-polar), the value has to be reset (setValue). + */ +void +RegisteredVector::setPolarCoords(bool polar_coords) +{ + _polar_coords = polar_coords; + if (polar_coords) { + xwidget.setLabelText("Angle:"); + ywidget.setLabelText("Distance:"); + } else { + xwidget.setLabelText("X:"); + ywidget.setLabelText("Y:"); + } +} + +void +RegisteredVector::on_value_changed() +{ + if (setProgrammatically()) { + clearProgrammatically(); + return; + } + + if (_wr->isUpdating()) + return; + + _wr->setUpdating (true); + + Geom::Point origin = _origin; + Geom::Point vector = getValue(); + if (_polar_coords) { + vector = Geom::Point::polar(vector[Geom::X]*M_PI/180, vector[Geom::Y]); + } + + Inkscape::SVGOStringStream os; + os << origin << " , " << vector; + + write_to_xml(os.str().c_str()); + + _wr->setUpdating (false); +} + +/*######################################### * Registered RANDOM */ diff --git a/src/ui/widget/registered-widget.h b/src/ui/widget/registered-widget.h index a5c61f68a..7aefbb90e 100644 --- a/src/ui/widget/registered-widget.h +++ b/src/ui/widget/registered-widget.h @@ -334,6 +334,31 @@ protected: }; +class RegisteredVector : public RegisteredWidget<Point> { +public: + virtual ~RegisteredVector(); + RegisteredVector (const Glib::ustring& label, + const Glib::ustring& tip, + const Glib::ustring& key, + Registry& wr, + Inkscape::XML::Node* repr_in = NULL, + SPDocument *doc_in = NULL ); + + // redefine setValue, because transform must be applied + void setValue(Geom::Point const & p); + void setValue(Geom::Point const & p, Geom::Point const & origin); + void setPolarCoords(bool polar_coords = true); + +protected: + sigc::connection _value_x_changed_connection; + sigc::connection _value_y_changed_connection; + void on_value_changed(); + + Geom::Point _origin; + bool _polar_coords; +}; + + class RegisteredRandom : public RegisteredWidget<Random> { public: virtual ~RegisteredRandom(); |
