From 91d5bb754933ec128238a3a570d59e4d74c5c349 Mon Sep 17 00:00:00 2001 From: "Johan B. C. Engelen" Date: Fri, 15 Apr 2011 01:02:53 +0200 Subject: ScalarUnit: add functionality to grab focus and select the entry text. and add setValueKeepUnit (bzr r10165) --- src/ui/widget/scalar-unit.cpp | 22 ++++++++++++++++++++++ src/ui/widget/scalar-unit.h | 3 +++ 2 files changed, 25 insertions(+) (limited to 'src') diff --git a/src/ui/widget/scalar-unit.cpp b/src/ui/widget/scalar-unit.cpp index e00e82198..533f0a200 100644 --- a/src/ui/widget/scalar-unit.cpp +++ b/src/ui/widget/scalar-unit.cpp @@ -118,6 +118,19 @@ ScalarUnit::setValue(double number, Glib::ustring const &units) { Scalar::setValue(number); } +/** Convert and sets the number only and keeps the current unit. */ +void +ScalarUnit::setValueKeepUnit(double number, Glib::ustring const &units) { + g_assert(_unit_menu != NULL); + if (units == "") { + // set the value in the default units + Scalar::setValue(number); + } else { + double conversion = _unit_menu->getConversion(units); + Scalar::setValue(number / conversion); + } +} + /** Sets the number only */ void ScalarUnit::setValue(double number) { @@ -137,6 +150,15 @@ ScalarUnit::getValue(Glib::ustring const &unit_name) const { } } +/** Grab focus, and select the text that is in the entry field. + */ +void +ScalarUnit::grabFocusAndSelectEntry() { + _widget->grab_focus(); + static_cast(_widget)->select_region(0, 20); +} + + void ScalarUnit::setHundredPercent(double number) { diff --git a/src/ui/widget/scalar-unit.h b/src/ui/widget/scalar-unit.h index d8b2edbd5..8f6c8e210 100644 --- a/src/ui/widget/scalar-unit.h +++ b/src/ui/widget/scalar-unit.h @@ -41,8 +41,11 @@ public: bool setUnit(Glib::ustring const &units); void setValue(double number, Glib::ustring const &units); + void setValueKeepUnit(double number, Glib::ustring const &units); void setValue(double number); + void grabFocusAndSelectEntry(); + void setHundredPercent(double number); void setAbsoluteIsIncrement(bool value); void setPercentageIsIncrement(bool value); -- cgit v1.2.3