From a0d74348937bf217b073311936e5aefc6105a1b9 Mon Sep 17 00:00:00 2001 From: "Johan B. C. Engelen" Date: Sat, 16 Apr 2011 23:09:31 +0200 Subject: ScalarUnit widget: fix initialization bug. add constructor which takes another scalarunit's unitmenu. (bzr r10171) --- src/ui/widget/scalar-unit.cpp | 34 ++++++++++++++++++++++++++++++++++ src/ui/widget/scalar-unit.h | 5 +++++ 2 files changed, 39 insertions(+) (limited to 'src') diff --git a/src/ui/widget/scalar-unit.cpp b/src/ui/widget/scalar-unit.cpp index 533f0a200..e713f3e06 100644 --- a/src/ui/widget/scalar-unit.cpp +++ b/src/ui/widget/scalar-unit.cpp @@ -68,8 +68,42 @@ ScalarUnit::ScalarUnit(Glib::ustring const &label, Glib::ustring const &tooltip, .connect_notify(sigc::mem_fun(*this, &ScalarUnit::on_unit_changed)); static_cast(_widget)->setUnitMenu(_unit_menu); + + lastUnits = _unit_menu->getUnitAbbr(); +} + +/** + * Construct a ScalarUnit + * + * \param label Label. + * \param tooltip Tooltip text. + * \param take_unitmenu Use the unitmenu from this parameter. + * \param suffix Suffix, placed after the widget (defaults to ""). + * \param icon Icon filename, placed before the label (defaults to ""). + * \param mnemonic Mnemonic toggle; if true, an underscore (_) in the label + * indicates the next character should be used for the + * mnemonic accelerator key (defaults to true). + */ +ScalarUnit::ScalarUnit(Glib::ustring const &label, Glib::ustring const &tooltip, + ScalarUnit &take_unitmenu, + Glib::ustring const &suffix, + Glib::ustring const &icon, + bool mnemonic) + : Scalar(label, tooltip, suffix, icon, mnemonic), + _unit_menu(take_unitmenu._unit_menu), + _hundred_percent(0), + _absolute_is_increment(false), + _percentage_is_increment(false) +{ + _unit_menu->signal_changed() + .connect_notify(sigc::mem_fun(*this, &ScalarUnit::on_unit_changed)); + + static_cast(_widget)->setUnitMenu(_unit_menu); + + lastUnits = _unit_menu->getUnitAbbr(); } + /** * Initializes the scalar based on the settings in _unit_menu. * Requires that _unit_menu has already been initialized. diff --git a/src/ui/widget/scalar-unit.h b/src/ui/widget/scalar-unit.h index 8f6c8e210..4e08d63f4 100644 --- a/src/ui/widget/scalar-unit.h +++ b/src/ui/widget/scalar-unit.h @@ -32,6 +32,11 @@ public: Glib::ustring const &icon = "", UnitMenu *unit_menu = NULL, bool mnemonic = true); + ScalarUnit(Glib::ustring const &label, Glib::ustring const &tooltip, + ScalarUnit &take_unitmenu, + Glib::ustring const &suffix = "", + Glib::ustring const &icon = "", + bool mnemonic = true); void initScalar(double min_value, double max_value); -- cgit v1.2.3