summaryrefslogtreecommitdiffhomepage
path: root/options/tie.hpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2016-09-16 15:11:08 +0200
committerStanislaw Halik <sthalik@misaki.pl>2016-09-16 18:04:34 +0200
commit33c4e66568b128312b1dcdf96b54f72cf902e498 (patch)
treea45edce70d8995f4dd540f33c4e76d3f8aa93fac /options/tie.hpp
parent7925bcf3aaa46b7e4757097cd21e9335b8925bb8 (diff)
options/tie: use existing slider functionality
Diffstat (limited to 'options/tie.hpp')
-rw-r--r--options/tie.hpp30
1 files changed, 10 insertions, 20 deletions
diff --git a/options/tie.hpp b/options/tie.hpp
index 1b8056a7..228aef8c 100644
--- a/options/tie.hpp
+++ b/options/tie.hpp
@@ -177,36 +177,26 @@ inline void tie_setting(value<slider_value>& v, QSlider* w)
// we can't get these at runtime since signals cross threads
const int q_min = w->minimum();
const int q_max = w->maximum();
- const int q_diff = q_max - q_min;
- slider_value sv(v);
-
- const double sv_c = sv.max() - sv.min();
-
- using std::round;
+ {
+ const int q_diff = q_max - q_min;
+ slider_value sv(v);
+ const double sv_c = sv.max() - sv.min();
- w->setValue(int((sv.cur() - sv.min()) / sv_c * q_diff + q_min));
- v = slider_value(q_diff <= 0 ? 0 : (w->value() - q_min) * sv_c / (double)q_diff + sv.min(), sv.min(), sv.max());
+ w->setValue(int((sv.cur() - sv.min()) / sv_c * q_diff + q_min));
+ v = slider_value(q_diff <= 0 ? 0 : (w->value() - q_min) * sv_c / (double)q_diff + sv.min(), sv.min(), sv.max());
+ }
base_value::connect(w,
&QSlider::valueChanged,
&v,
- [=, &v](int pos) {
- const int q_diff = q_max - q_min;
- if (q_diff <= 0 || pos <= 0)
- v = slider_value(sv.min(), sv.min(), sv.max());
- else
- {
- const float c = float(sv.max()-sv.min());
- v = slider_value((pos - q_min) * c / (float)q_diff + float(sv.min()), sv.min(), sv.max());
- }
- },
+ [=, &v](int pos) { v = v->update_from_slider(pos, q_min, q_max); },
v.DIRECT_CONNTYPE);
base_value::connect(&v,
static_cast<void(base_value::*)(double) const>(&base_value::valueChanged),
w,
- [=](double value) { w->setValue(int(round(value * q_diff) + q_min)); },
- v.SAFE_CONNTYPE);
+ [=, &v](double) { w->setValue(v->to_slider_pos(q_min, q_max)); },
+ v.SAFE_CONNTYPE);
}
}