summaryrefslogtreecommitdiffhomepage
path: root/opentrack-compat
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2016-05-25 19:41:42 +0200
committerStanislaw Halik <sthalik@misaki.pl>2016-05-25 19:42:13 +0200
commitdeed74dd2153295a2b34ffbada5b58394e614b65 (patch)
tree5603c45e24961b4624abc260c9accfe1ad6a0792 /opentrack-compat
parent7fd6c9e83593f51326ea0ed745f4b22b6bb3701b (diff)
compat/options: allow binding floats 0->1 to slider widgets
Diffstat (limited to 'opentrack-compat')
-rw-r--r--opentrack-compat/options.hpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/opentrack-compat/options.hpp b/opentrack-compat/options.hpp
index c15b9874..2853fc91 100644
--- a/opentrack-compat/options.hpp
+++ b/opentrack-compat/options.hpp
@@ -396,4 +396,29 @@ namespace options {
base_value::connect(t, SIGNAL(currentChanged(int)), &v, SLOT(setValue(int)), v.DIRECT_CONNTYPE);
base_value::connect(&v, SIGNAL(valueChanged(int)), t, SLOT(setCurrentIndex(int)), v.DIRECT_CONNTYPE);
}
+
+ template<>
+ inline void tie_setting(value<double>& v, QSlider* w)
+ {
+ // we can't get these at runtime since signals cross threads
+ const int min = w->minimum();
+ const int max = w->maximum();
+ const int max_ = max - min;
+
+ w->setValue(int(v * max_) + min);
+ v = max_ <= 0 ? 0 : (w->value() - min) / (double)max_;
+
+ base_value::connect(w, &QSlider::valueChanged, &v,
+ [=, &v](int pos) -> void
+ {
+ v = max_ <= 0 ? 0 : (pos - min) / (double)max_;
+ },
+ v.DIRECT_CONNTYPE);
+ base_value::connect(&v, static_cast<void(base_value::*)(double)>(&base_value::valueChanged), w,
+ [=](double value) -> void
+ {
+ w->setValue(int(value * max_) + min);
+ },
+ v.DIRECT_CONNTYPE);
+ }
}