summaryrefslogtreecommitdiffstats
path: root/src/preferences.cpp
diff options
context:
space:
mode:
authorKrzysztof Kosi??ski <tweenk.pl@gmail.com>2011-06-19 10:00:24 +0000
committerKrzysztof KosiƄski <tweenk.pl@gmail.com>2011-06-19 10:00:24 +0000
commit06dfaa02d7a80bcdff717d579a48f81643f53f31 (patch)
tree49b8e67ad9051f1507b0959cac986383ab4001e2 /src/preferences.cpp
parentFix rendering of control points (diff)
parentfix bug 796451: Measure tools should support rotation constraint (diff)
downloadinkscape-06dfaa02d7a80bcdff717d579a48f81643f53f31.tar.gz
inkscape-06dfaa02d7a80bcdff717d579a48f81643f53f31.zip
Merge from trunk
(bzr r9508.1.89)
Diffstat (limited to 'src/preferences.cpp')
-rw-r--r--src/preferences.cpp44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/preferences.cpp b/src/preferences.cpp
index 94fbc7257..444acfcac 100644
--- a/src/preferences.cpp
+++ b/src/preferences.cpp
@@ -23,6 +23,7 @@
#include "xml/node-observer.h"
#include "xml/node-iterators.h"
#include "xml/attribute-record.h"
+#include "util/units.h"
#define PREFERENCES_FILE_NAME "preferences.xml"
@@ -452,6 +453,22 @@ void Preferences::setDouble(Glib::ustring const &pref_path, double value)
_setRawValue(pref_path, buf);
}
+/**
+ * Set a floating point attribute of a preference.
+ *
+ * @param pref_path Path of the preference to modify.
+ * @param value The new value of the pref attribute.
+ * @param unit_abbr The string of the unit (abbreviated).
+ */
+void Preferences::setDoubleUnit(Glib::ustring const &pref_path, double value, Glib::ustring const &unit_abbr)
+{
+ gchar buf[G_ASCII_DTOSTR_BUF_SIZE];
+ g_ascii_dtostr(buf, G_ASCII_DTOSTR_BUF_SIZE, value);
+ Glib::ustring str(buf);
+ str += unit_abbr;
+ _setRawValue(pref_path, str.c_str());
+}
+
void Preferences::setColor(Glib::ustring const &pref_path, guint32 value)
{
gchar buf[16];
@@ -745,11 +762,38 @@ double Preferences::_extractDouble(Entry const &v)
return g_ascii_strtod(s, NULL);
}
+double Preferences::_extractDouble(Entry const &v, Glib::ustring const &requested_unit)
+{
+ static Inkscape::Util::UnitTable unit_table; // load the unit_table once by making it static
+
+ double val = _extractDouble(v);
+ Glib::ustring unit = _extractUnit(v);
+
+ return val * (unit_table.getUnit(unit).factor / unit_table.getUnit(requested_unit).factor);
+}
+
Glib::ustring Preferences::_extractString(Entry const &v)
{
return Glib::ustring(static_cast<gchar const *>(v._value));
}
+Glib::ustring Preferences::_extractUnit(Entry const &v)
+{
+ gchar const *str = static_cast<gchar const *>(v._value);
+ gchar const *e;
+ g_ascii_strtod(str, (char **) &e);
+ if (e == str) {
+ return "";
+ }
+
+ if (e[0] == 0) {
+ /* Unitless */
+ return "";
+ } else {
+ return Glib::ustring(e);
+ }
+}
+
guint32 Preferences::_extractColor(Entry const &v)
{
gchar const *s = static_cast<gchar const *>(v._value);