diff options
Diffstat (limited to 'src/ui/widget')
| -rw-r--r-- | src/ui/widget/preferences-widget.cpp | 39 | ||||
| -rw-r--r-- | src/ui/widget/preferences-widget.h | 16 | ||||
| -rw-r--r-- | src/ui/widget/scalar-unit.cpp | 16 | ||||
| -rw-r--r-- | src/ui/widget/scalar-unit.h | 2 | ||||
| -rw-r--r-- | src/ui/widget/unit-menu.cpp | 13 | ||||
| -rw-r--r-- | src/ui/widget/unit-menu.h | 1 |
6 files changed, 87 insertions, 0 deletions
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); |
