summaryrefslogtreecommitdiffstats
path: root/src/ui/widget/registered-widget.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/widget/registered-widget.cpp')
-rw-r--r--src/ui/widget/registered-widget.cpp29
1 files changed, 24 insertions, 5 deletions
diff --git a/src/ui/widget/registered-widget.cpp b/src/ui/widget/registered-widget.cpp
index e97285de4..4065bd550 100644
--- a/src/ui/widget/registered-widget.cpp
+++ b/src/ui/widget/registered-widget.cpp
@@ -36,6 +36,8 @@
// for interruptability bug:
#include "display/sp-canvas.h"
+#include "sp-root.h"
+
namespace Inkscape {
namespace UI {
namespace Widget {
@@ -203,7 +205,7 @@ RegisteredScalarUnit::~RegisteredScalarUnit()
_value_changed_connection.disconnect();
}
-RegisteredScalarUnit::RegisteredScalarUnit (const Glib::ustring& label, const Glib::ustring& tip, const Glib::ustring& key, const RegisteredUnitMenu &rum, Registry& wr, Inkscape::XML::Node* repr_in, SPDocument *doc_in)
+RegisteredScalarUnit::RegisteredScalarUnit (const Glib::ustring& label, const Glib::ustring& tip, const Glib::ustring& key, const RegisteredUnitMenu &rum, Registry& wr, Inkscape::XML::Node* repr_in, SPDocument *doc_in, RSU_UserUnits user_units)
: RegisteredWidget<ScalarUnit>(label, tip, UNIT_TYPE_LINEAR, "", "", rum.getUnitMenu()),
_um(0)
{
@@ -215,6 +217,7 @@ RegisteredScalarUnit::RegisteredScalarUnit (const Glib::ustring& label, const Gl
setUnit (rum.getUnitMenu()->getUnitAbbr());
setDigits (2);
_um = rum.getUnitMenu();
+ _user_units = user_units;
_value_changed_connection = signal_value_changed().connect (sigc::mem_fun (*this, &RegisteredScalarUnit::on_value_changed));
}
@@ -233,12 +236,28 @@ RegisteredScalarUnit::on_value_changed()
_wr->setUpdating (true);
Inkscape::SVGOStringStream os;
- os << getValue("");
- if (_um)
- os << _um->getUnitAbbr();
+ if (_user_units != RSU_none) {
+ // Output length in 'user units', taking into account scale in 'x' or 'y'.
+ double scale = 1.0;
+ if (doc) {
+ SPRoot *root = doc->getRoot();
+ if (root->viewBox_set) {
+ if (_user_units == RSU_x) {
+ scale = root->viewBox.width() / root->width.computed;
+ } else {
+ scale = root->viewBox.height() / root->height.computed;
+ }
+ }
+ }
+ os << getValue("px") * scale;
+ } else {
+ // Output using unit identifiers.
+ os << getValue("");
+ if (_um)
+ os << _um->getUnitAbbr();
+ }
write_to_xml(os.str().c_str());
-
_wr->setUpdating (false);
}