summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJohan B. C. Engelen <jbc.engelen@swissonline.ch>2011-04-17 12:51:06 +0000
committerJohan Engelen <goejendaagh@zonnet.nl>2011-04-17 12:51:06 +0000
commit70829da1b189d6d8f07f12d97b9273d56dbd789e (patch)
treed041efcd3a74ce09398665b066a0bd891dad2fde /src
parentchange spinbox to new one in many places. (diff)
downloadinkscape-70829da1b189d6d8f07f12d97b9273d56dbd789e.tar.gz
inkscape-70829da1b189d6d8f07f12d97b9273d56dbd789e.zip
add new preference widget for a number with a unit.
change Preferences > Steps to this new widget (bzr r10177)
Diffstat (limited to 'src')
-rw-r--r--src/extension/internal/bluredge.cpp8
-rw-r--r--src/gradient-context.cpp2
-rw-r--r--src/pen-context.cpp2
-rw-r--r--src/preferences-skeleton.h6
-rw-r--r--src/preferences.cpp44
-rw-r--r--src/preferences.h62
-rw-r--r--src/select-context.cpp4
-rw-r--r--src/splivarot.cpp6
-rw-r--r--src/ui/dialog/inkscape-preferences.cpp18
-rw-r--r--src/ui/dialog/inkscape-preferences.h8
-rw-r--r--src/ui/tool/control-point-selection.cpp4
-rw-r--r--src/ui/tool/path-manipulator.cpp2
-rw-r--r--src/ui/widget/preferences-widget.cpp39
-rw-r--r--src/ui/widget/preferences-widget.h16
-rw-r--r--src/ui/widget/scalar-unit.cpp16
-rw-r--r--src/ui/widget/scalar-unit.h2
-rw-r--r--src/ui/widget/unit-menu.cpp13
-rw-r--r--src/ui/widget/unit-menu.h1
18 files changed, 212 insertions, 41 deletions
diff --git a/src/extension/internal/bluredge.cpp b/src/extension/internal/bluredge.cpp
index 8ec09d11e..76582ab05 100644
--- a/src/extension/internal/bluredge.cpp
+++ b/src/extension/internal/bluredge.cpp
@@ -59,7 +59,7 @@ BlurEdge::effect (Inkscape::Extension::Effect *module, Inkscape::UI::View::View
int steps = module->get_param_int("num-steps");
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
- double old_offset = prefs->getDouble("/options/defaultoffsetwidth/value", 1.0);
+ double old_offset = prefs->getDouble("/options/defaultoffsetwidth/value", 1.0, "px");
using Inkscape::Util::GSListConstIterator;
// TODO need to properly refcount the items, at least
@@ -97,10 +97,10 @@ BlurEdge::effect (Inkscape::Extension::Effect *module, Inkscape::UI::View::View
if (offset < 0.0) {
/* Doing an inset here folks */
offset *= -1.0;
- prefs->setDouble("/options/defaultoffsetwidth/value", offset);
+ prefs->setDoubleUnit("/options/defaultoffsetwidth/value", offset, "px");
sp_action_perform(Inkscape::Verb::get(SP_VERB_SELECTION_INSET)->get_action(desktop), NULL);
} else if (offset > 0.0) {
- prefs->setDouble("/options/defaultoffsetwidth/value", offset);
+ prefs->setDoubleUnit("/options/defaultoffsetwidth/value", offset, "px");
sp_action_perform(Inkscape::Verb::get(SP_VERB_SELECTION_OFFSET)->get_action(desktop), NULL);
}
@@ -110,7 +110,7 @@ BlurEdge::effect (Inkscape::Extension::Effect *module, Inkscape::UI::View::View
Inkscape::GC::release(new_group);
}
- prefs->setDouble("/options/defaultoffsetwidth/value", old_offset);
+ prefs->setDoubleUnit("/options/defaultoffsetwidth/value", old_offset, "px");
selection->clear();
selection->add(items.begin(), items.end());
diff --git a/src/gradient-context.cpp b/src/gradient-context.cpp
index b98ae09fc..007fa549a 100644
--- a/src/gradient-context.cpp
+++ b/src/gradient-context.cpp
@@ -497,7 +497,7 @@ sp_gradient_context_root_handler(SPEventContext *event_context, GdkEvent *event)
SPGradientContext *rc = SP_GRADIENT_CONTEXT(event_context);
event_context->tolerance = prefs->getIntLimited("/options/dragtolerance/value", 0, 0, 100);
- double const nudge = prefs->getDoubleLimited("/options/nudgedistance/value", 2, 0, 1000); // in px
+ double const nudge = prefs->getDoubleLimited("/options/nudgedistance/value", 2, 0, 1000, "px"); // in px
GrDrag *drag = event_context->_grdrag;
g_assert (drag);
diff --git a/src/pen-context.cpp b/src/pen-context.cpp
index 607bdaedc..64137d56f 100644
--- a/src/pen-context.cpp
+++ b/src/pen-context.cpp
@@ -989,7 +989,7 @@ pen_handle_key_press(SPPenContext *const pc, GdkEvent *event)
gint ret = FALSE;
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
- gdouble const nudge = prefs->getDoubleLimited("/options/nudgedistance/value", 2, 0, 1000); // in px
+ gdouble const nudge = prefs->getDoubleLimited("/options/nudgedistance/value", 2, 0, 1000, "px"); // in px
switch (get_group0_keyval (&event->key)) {
diff --git a/src/preferences-skeleton.h b/src/preferences-skeleton.h
index 124a2ae51..62744bd53 100644
--- a/src/preferences-skeleton.h
+++ b/src/preferences-skeleton.h
@@ -238,7 +238,7 @@ static char const preferences_skeleton[] =
" <group id=\"trackalt\" value=\"0\" />"
" <group id=\"switchonextinput\" value=\"0\" />"
" <group id=\"useextinput\" value=\"1\" />"
-" <group id=\"nudgedistance\" value=\"2\"/>\n"
+" <group id=\"nudgedistance\" value=\"2px\"/>\n"
" <group id=\"rotationsnapsperpi\" value=\"12\"/>\n"
" <group id=\"cursortolerance\" value=\"8.0\"/>\n"
" <group id=\"dragtolerance\" value=\"4.0\"/>\n"
@@ -258,8 +258,8 @@ static char const preferences_skeleton[] =
" preserveblack=\"0\"\n"
" uri=\"\" />\n"
" <group id=\"savewindowgeometry\" value=\"1\"/>\n"
-" <group id=\"defaultoffsetwidth\" value=\"2\"/>\n"
-" <group id=\"defaultscale\" value=\"2\"/>\n"
+" <group id=\"defaultoffsetwidth\" value=\"2px\"/>\n"
+" <group id=\"defaultscale\" value=\"2px\"/>\n"
" <group id=\"maxrecentdocuments\" value=\"36\"/>\n"
" <group id=\"zoomincrement\" value=\"1.414213562\"/>\n"
" <group id=\"zoomcorrection\" value=\"1.0\" unit=\"mm\"/>\n"
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);
diff --git a/src/preferences.h b/src/preferences.h
index c79a7377d..64bb6ac4f 100644
--- a/src/preferences.h
+++ b/src/preferences.h
@@ -159,9 +159,10 @@ public:
/**
* Interpret the preference as a floating point value.
*
- * @param def Default value if the preference is not set.
+ * @param def Default value if the preference is not set.
+ * @param unit Specifies the unit of the returned result. Will be ignored when equal to "". If the preference has no unit set, the default unit will be assumed.
*/
- inline double getDouble(double def=0.0) const;
+ inline double getDouble(double def=0.0, Glib::ustring const &unit = "") const;
/**
* Interpret the preference as a limited floating point value.
@@ -172,8 +173,9 @@ public:
* @param def Default value if the preference is not set.
* @param min Minimum value allowed to return.
* @param max Maximum value allowed to return.
+ * @param unit Specifies the unit of the returned result. Will be ignored when equal to "". If the preference has no unit set, the default unit will be assumed.
*/
- inline double getDoubleLimited(double def=0.0, double min=DBL_MIN, double max=DBL_MAX) const;
+ inline double getDoubleLimited(double def=0.0, double min=DBL_MIN, double max=DBL_MAX, Glib::ustring const &unit = "") const;
/**
* Interpret the preference as an UTF-8 string.
@@ -182,6 +184,11 @@ public:
*/
inline Glib::ustring getString() const;
+ /**
+ * Interpret the preference as a number followed by a unit (without space), and return this unit string.
+ */
+ inline Glib::ustring getUnit() const;
+
/**
* Interpret the preference as an RGBA color value.
*/
@@ -316,8 +323,8 @@ public:
return getEntry(pref_path).getIntLimited(def, min, max);
}
- double getDouble(Glib::ustring const &pref_path, double def=0.0) {
- return getEntry(pref_path).getDouble(def);
+ double getDouble(Glib::ustring const &pref_path, double def=0.0, Glib::ustring const &unit = "") {
+ return getEntry(pref_path).getDouble(def, unit);
}
/**
@@ -330,9 +337,10 @@ public:
* @param def The default value to return if the preference is not set.
* @param min Minimum value to return.
* @param max Maximum value to return.
+ * @param unit Specifies the unit of the returned result. Will be ignored when equal to "". If the preference has no unit set, the default unit will be assumed.
*/
- double getDoubleLimited(Glib::ustring const &pref_path, double def=0.0, double min=DBL_MIN, double max=DBL_MAX) {
- return getEntry(pref_path).getDoubleLimited(def, min, max);
+ double getDoubleLimited(Glib::ustring const &pref_path, double def=0.0, double min=DBL_MIN, double max=DBL_MAX, Glib::ustring const &unit = "") {
+ return getEntry(pref_path).getDoubleLimited(def, min, max, unit);
}
/**
@@ -344,6 +352,15 @@ public:
return getEntry(pref_path).getString();
}
+ /**
+ * Retrieve the unit string.
+ *
+ * @param pref_path Path to the retrieved preference.
+ */
+ Glib::ustring getUnit(Glib::ustring const &pref_path) {
+ return getEntry(pref_path).getUnit();
+ }
+
guint32 getColor(Glib::ustring const &pref_path, guint32 def=0x000000ff) {
return getEntry(pref_path).getColor(def);
}
@@ -399,6 +416,11 @@ public:
void setDouble(Glib::ustring const &pref_path, double value);
/**
+ * Set a floating point value with unit.
+ */
+ void setDoubleUnit(Glib::ustring const &pref_path, double value, Glib::ustring const &unit_abbr);
+
+ /**
* Set an UTF-8 string value.
*/
void setString(Glib::ustring const &pref_path, Glib::ustring const &value);
@@ -484,7 +506,9 @@ protected:
bool _extractBool(Entry const &v);
int _extractInt(Entry const &v);
double _extractDouble(Entry const &v);
+ double _extractDouble(Entry const &v, Glib::ustring const &requested_unit);
Glib::ustring _extractString(Entry const &v);
+ Glib::ustring _extractUnit(Entry const &v);
guint32 _extractColor(Entry const &v);
SPCSSAttr *_extractStyle(Entry const &v);
SPCSSAttr *_extractInheritedStyle(Entry const &v);
@@ -566,21 +590,28 @@ inline int Preferences::Entry::getIntLimited(int def, int min, int max) const
}
}
-inline double Preferences::Entry::getDouble(double def) const
+inline double Preferences::Entry::getDouble(double def, Glib::ustring const &unit) const
{
if (!this->isValid()) {
return def;
- } else {
+ } else if (unit.length() == 0) {
return Inkscape::Preferences::get()->_extractDouble(*this);
+ } else {
+ return Inkscape::Preferences::get()->_extractDouble(*this, unit);
}
}
-inline double Preferences::Entry::getDoubleLimited(double def, double min, double max) const
+inline double Preferences::Entry::getDoubleLimited(double def, double min, double max, Glib::ustring const &unit) const
{
if (!this->isValid()) {
return def;
} else {
- double val = Inkscape::Preferences::get()->_extractDouble(*this);
+ double val = def;
+ if (unit.length() == 0) {
+ val = Inkscape::Preferences::get()->_extractDouble(*this);
+ } else {
+ val = Inkscape::Preferences::get()->_extractDouble(*this, unit);
+ }
return ( val >= min && val <= max ? val : def );
}
}
@@ -594,6 +625,15 @@ inline Glib::ustring Preferences::Entry::getString() const
}
}
+inline Glib::ustring Preferences::Entry::getUnit() const
+{
+ if (!this->isValid()) {
+ return "";
+ } else {
+ return Inkscape::Preferences::get()->_extractUnit(*this);
+ }
+}
+
inline guint32 Preferences::Entry::getColor(guint32 def) const
{
if (!this->isValid()) {
diff --git a/src/select-context.cpp b/src/select-context.cpp
index e6d78975b..640aae9ee 100644
--- a/src/select-context.cpp
+++ b/src/select-context.cpp
@@ -867,8 +867,8 @@ sp_select_context_root_handler(SPEventContext *event_context, GdkEvent *event)
}
}
- gdouble const nudge = prefs->getDoubleLimited("/options/nudgedistance/value", 2, 0, 1000); // in px
- gdouble const offset = prefs->getDoubleLimited("/options/defaultscale/value", 2, 0, 1000);
+ gdouble const nudge = prefs->getDoubleLimited("/options/nudgedistance/value", 2, 0, 1000, "px"); // in px
+ gdouble const offset = prefs->getDoubleLimited("/options/defaultscale/value", 2, 0, 1000, "px");
int const snaps = prefs->getInt("/options/rotationsnapsperpi/value", 12);
switch (get_group0_keyval (&event->key)) {
diff --git a/src/splivarot.cpp b/src/splivarot.cpp
index 0e27ce26d..ac2acf330 100644
--- a/src/splivarot.cpp
+++ b/src/splivarot.cpp
@@ -1264,7 +1264,7 @@ void
sp_selected_path_offset(SPDesktop *desktop)
{
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
- double prefOffset = prefs->getDouble("/options/defaultoffsetwidth/value", 1.0);
+ double prefOffset = prefs->getDouble("/options/defaultoffsetwidth/value", 1.0, "px");
sp_selected_path_do_offset(desktop, true, prefOffset);
}
@@ -1272,7 +1272,7 @@ void
sp_selected_path_inset(SPDesktop *desktop)
{
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
- double prefOffset = prefs->getDouble("/options/defaultoffsetwidth/value", 1.0);
+ double prefOffset = prefs->getDouble("/options/defaultoffsetwidth/value", 1.0, "px");
sp_selected_path_do_offset(desktop, false, prefOffset);
}
@@ -1398,7 +1398,7 @@ sp_selected_path_create_offset_object(SPDesktop *desktop, int expand, bool updat
{
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
- o_width = prefs->getDouble("/options/defaultoffsetwidth/value", 1.0);
+ o_width = prefs->getDouble("/options/defaultoffsetwidth/value", 1.0, "px");
}
if (o_width < 0.01)
diff --git a/src/ui/dialog/inkscape-preferences.cpp b/src/ui/dialog/inkscape-preferences.cpp
index 7963dd512..81bd4dba0 100644
--- a/src/ui/dialog/inkscape-preferences.cpp
+++ b/src/ui/dialog/inkscape-preferences.cpp
@@ -249,17 +249,17 @@ void InkscapePreferences::initPageSteps()
{
this->AddPage(_page_steps, _("Steps"), PREFS_PAGE_STEPS);
- _steps_arrow.init ( "/options/nudgedistance/value", 0.0, 1000.0, 0.01, 1.0, 2.0, false, false);
+ _steps_arrow.init ( "/options/nudgedistance/value", 0.0, 1000.0, 0.01, 2.0, UNIT_TYPE_LINEAR, "px");
//nudgedistance is limited to 1000 in select-context.cpp: use the same limit here
- _page_steps.add_line( false, _("Arrow keys move by:"), _steps_arrow, _("px"),
- _("Pressing an arrow key moves selected object(s) or node(s) by this distance (in px units)"), false);
- _steps_scale.init ( "/options/defaultscale/value", 0.0, 1000.0, 0.01, 1.0, 2.0, false, false);
+ _page_steps.add_line( false, _("Arrow keys move by:"), _steps_arrow, "",
+ _("Pressing an arrow key moves selected object(s) or node(s) by this distance"), false);
+ _steps_scale.init ( "/options/defaultscale/value", 0.0, 1000.0, 0.01, 2.0, UNIT_TYPE_LINEAR, "px");
//defaultscale is limited to 1000 in select-context.cpp: use the same limit here
- _page_steps.add_line( false, _("> and < scale by:"), _steps_scale, _("px"),
- _("Pressing > or < scales selection up or down by this increment (in px units)"), false);
- _steps_inset.init ( "/options/defaultoffsetwidth/value", 0.0, 3000.0, 0.01, 1.0, 2.0, false, false);
- _page_steps.add_line( false, _("Inset/Outset by:"), _steps_inset, _("px"),
- _("Inset and Outset commands displace the path by this distance (in px units)"), false);
+ _page_steps.add_line( false, _("> and < scale by:"), _steps_scale, "",
+ _("Pressing > or < scales selection up or down by this increment"), false);
+ _steps_inset.init ( "/options/defaultoffsetwidth/value", 0.0, 3000.0, 0.01, 2.0, UNIT_TYPE_LINEAR, "px");
+ _page_steps.add_line( false, _("Inset/Outset by:"), _steps_inset, "",
+ _("Inset and Outset commands displace the path by this distance"), false);
_steps_compass.init ( _("Compass-like display of angles"), "/options/compassangledisplay/value", true);
_page_steps.add_line( false, "", _steps_compass, "",
_("When on, angles are displayed with 0 at north, 0 to 360 range, positive clockwise; otherwise with 0 at east, -180 to 180 range, positive counterclockwise"));
diff --git a/src/ui/dialog/inkscape-preferences.h b/src/ui/dialog/inkscape-preferences.h
index a20278551..eede9eafe 100644
--- a/src/ui/dialog/inkscape-preferences.h
+++ b/src/ui/dialog/inkscape-preferences.h
@@ -178,10 +178,10 @@ protected:
UI::Widget::PrefCombo _steps_rot_snap;
UI::Widget::PrefCheckButton _steps_compass;
- UI::Widget::PrefSpinButton _steps_arrow;
- UI::Widget::PrefSpinButton _steps_scale;
- UI::Widget::PrefSpinButton _steps_inset;
- UI::Widget::PrefSpinButton _steps_zoom;
+ UI::Widget::PrefSpinUnit _steps_arrow;
+ UI::Widget::PrefSpinUnit _steps_scale;
+ UI::Widget::PrefSpinUnit _steps_inset;
+ UI::Widget::PrefSpinButton _steps_zoom;
UI::Widget::PrefRadioButton _t_sel_trans_obj;
UI::Widget::PrefRadioButton _t_sel_trans_outl;
diff --git a/src/ui/tool/control-point-selection.cpp b/src/ui/tool/control-point-selection.cpp
index 1fb98d78f..13da4a712 100644
--- a/src/ui/tool/control-point-selection.cpp
+++ b/src/ui/tool/control-point-selection.cpp
@@ -432,7 +432,7 @@ bool ControlPointSelection::_keyboardMove(GdkEventKey const &event, Geom::Point
delta /= _desktop->current_zoom();
} else {
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
- double nudge = prefs->getDoubleLimited("/options/nudgedistance/value", 2, 0, 1000);
+ double nudge = prefs->getDoubleLimited("/options/nudgedistance/value", 2, 0, 1000, "px");
delta *= nudge;
}
@@ -533,7 +533,7 @@ bool ControlPointSelection::_keyboardScale(GdkEventKey const &event, int dir)
length_change = 1.0 / _desktop->current_zoom() * dir;
} else {
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
- length_change = prefs->getDoubleLimited("/options/defaultscale/value", 2, 1, 1000);
+ length_change = prefs->getDoubleLimited("/options/defaultscale/value", 2, 1, 1000, "px");
length_change *= dir;
}
double scale = (maxext + length_change) / maxext;
diff --git a/src/ui/tool/path-manipulator.cpp b/src/ui/tool/path-manipulator.cpp
index 7c2013872..52286c6cc 100644
--- a/src/ui/tool/path-manipulator.cpp
+++ b/src/ui/tool/path-manipulator.cpp
@@ -727,7 +727,7 @@ void PathManipulator::scaleHandle(Node *n, int which, int dir, bool pixel)
length_change = 1.0 / _desktop->current_zoom() * dir;
} else {
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
- length_change = prefs->getDoubleLimited("/options/defaultscale/value", 2, 1, 1000);
+ length_change = prefs->getDoubleLimited("/options/defaultscale/value", 2, 1, 1000, "px");
length_change *= dir;
}
diff --git a/src/ui/widget/preferences-widget.cpp b/src/ui/widget/preferences-widget.cpp
index f92e2518d..9cf80153a 100644
--- a/src/ui/widget/preferences-widget.cpp
+++ b/src/ui/widget/preferences-widget.cpp
@@ -255,6 +255,45 @@ void PrefSpinButton::on_value_changed()
}
}
+void PrefSpinUnit::init(Glib::ustring const &prefs_path,
+ double lower, double upper, double step_increment,
+ double default_value, UnitType unit_type, Glib::ustring const &default_unit)
+{
+ _prefs_path = prefs_path;
+ _is_percent = (unit_type == UNIT_TYPE_DIMENSIONLESS);
+
+ setUnitType(unit_type);
+ setUnit(default_unit);
+ setRange (lower, upper); /// @fixme this disregards changes of units
+ setIncrements (step_increment, 0);
+ if (step_increment < 0.1) {
+ setDigits(4);
+ } else {
+ setDigits(2);
+ }
+
+ Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+ double value = prefs->getDoubleLimited(prefs_path, default_value, lower, upper);
+ Glib::ustring unitstr = prefs->getUnit(prefs_path);
+ if (unitstr.length() == 0) {
+ unitstr = default_unit;
+ // write the assumed unit to preferences:
+ prefs->setDoubleUnit(_prefs_path, value, unitstr);
+ }
+ setValue(value, unitstr);
+
+ signal_value_changed().connect_notify(sigc::mem_fun(*this, &PrefSpinUnit::on_my_value_changed));
+}
+
+void PrefSpinUnit::on_my_value_changed()
+{
+ Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+ if (getWidget()->is_visible()) //only take action if user changed value
+ {
+ prefs->setDoubleUnit(_prefs_path, getValue(getUnit().abbr), getUnit().abbr);
+ }
+}
+
const double ZoomCorrRuler::textsize = 7;
const double ZoomCorrRuler::textpadding = 5;
diff --git a/src/ui/widget/preferences-widget.h b/src/ui/widget/preferences-widget.h
index 758ab38cd..6caab11ae 100644
--- a/src/ui/widget/preferences-widget.h
+++ b/src/ui/widget/preferences-widget.h
@@ -33,6 +33,7 @@
#include "ui/widget/color-picker.h"
#include "ui/widget/unit-menu.h"
#include "ui/widget/spinbutton.h"
+#include "ui/widget/scalar-unit.h"
namespace Inkscape {
namespace UI {
@@ -82,6 +83,21 @@ protected:
void on_value_changed();
};
+class PrefSpinUnit : public ScalarUnit
+{
+public:
+ PrefSpinUnit() : ScalarUnit("", "") {};
+
+ void init(Glib::ustring const &prefs_path,
+ double lower, double upper, double step_increment,
+ double default_value,
+ UnitType unit_type, Glib::ustring const &default_unit);
+protected:
+ Glib::ustring _prefs_path;
+ bool _is_percent;
+ void on_my_value_changed();
+};
+
class ZoomCorrRuler : public Gtk::DrawingArea {
public:
ZoomCorrRuler(int width = 100, int height = 20);
diff --git a/src/ui/widget/scalar-unit.cpp b/src/ui/widget/scalar-unit.cpp
index e713f3e06..1c0fdff68 100644
--- a/src/ui/widget/scalar-unit.cpp
+++ b/src/ui/widget/scalar-unit.cpp
@@ -130,6 +130,22 @@ ScalarUnit::setUnit(Glib::ustring const &unit) {
return true;
}
+/** Adds the unit type to the ScalarUnit widget */
+void
+ScalarUnit::setUnitType(UnitType unit_type) {
+ g_assert(_unit_menu != NULL);
+ _unit_menu->setUnitType(unit_type);
+ lastUnits = _unit_menu->getUnitAbbr();
+}
+
+/** Resets the unit type for the ScalarUnit widget */
+void
+ScalarUnit::resetUnitType(UnitType unit_type) {
+ g_assert(_unit_menu != NULL);
+ _unit_menu->resetUnitType(unit_type);
+ lastUnits = _unit_menu->getUnitAbbr();
+}
+
/** Gets the object for the currently selected unit */
Unit
ScalarUnit::getUnit() const {
diff --git a/src/ui/widget/scalar-unit.h b/src/ui/widget/scalar-unit.h
index 4e08d63f4..ed3728e69 100644
--- a/src/ui/widget/scalar-unit.h
+++ b/src/ui/widget/scalar-unit.h
@@ -45,6 +45,8 @@ public:
double getValue(Glib::ustring const &units) const;
bool setUnit(Glib::ustring const &units);
+ void setUnitType(UnitType unit_type);
+ void resetUnitType(UnitType unit_type);
void setValue(double number, Glib::ustring const &units);
void setValueKeepUnit(double number, Glib::ustring const &units);
void setValue(double number);
diff --git a/src/ui/widget/unit-menu.cpp b/src/ui/widget/unit-menu.cpp
index b4271762c..5c68f7196 100644
--- a/src/ui/widget/unit-menu.cpp
+++ b/src/ui/widget/unit-menu.cpp
@@ -54,6 +54,19 @@ UnitMenu::setUnitType(UnitType unit_type)
return true;
}
+/** Removes all unit entries, then adds the unit type to the widget.
+ This extracts the corresponding
+ units from the unit map matching the given type, and appends them
+ to the dropdown widget. It causes the primary unit for the given
+ unit_type to be selected. */
+bool
+UnitMenu::resetUnitType(UnitType unit_type)
+{
+ clear_text();
+
+ return setUnitType(unit_type);
+}
+
/** Returns the Unit object corresponding to the current selection
in the dropdown widget */
Unit
diff --git a/src/ui/widget/unit-menu.h b/src/ui/widget/unit-menu.h
index 60a9702b4..efeb10ead 100644
--- a/src/ui/widget/unit-menu.h
+++ b/src/ui/widget/unit-menu.h
@@ -28,6 +28,7 @@ public:
virtual ~UnitMenu();
bool setUnitType(UnitType unit_type);
+ bool resetUnitType(UnitType unit_type);
bool setUnit(Glib::ustring const &unit);