From 299391ade90fc5f64e57ee6d9431b90fcaf63db8 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sun, 12 Jun 2016 16:47:14 +0200 Subject: compat/options: finish slider value support Keeping "cur" in 0->1 distorts the value on save/reload. --- opentrack-compat/options.cpp | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) (limited to 'opentrack-compat/options.cpp') diff --git a/opentrack-compat/options.cpp b/opentrack-compat/options.cpp index 1c222ba0..55a4b795 100644 --- a/opentrack-compat/options.cpp +++ b/opentrack-compat/options.cpp @@ -203,19 +203,34 @@ pbundle bundle(const QString& name) slider_value::operator double() const { - return min + cur * (max-min); + return cur_; } -slider_value slider_value::from_abs(double val, double min, double max) +custom_type_initializer::custom_type_initializer() { - if (min > max) - min = max; - if (val < min) - val = min; - if (val > max) - val = max; - return slider_value((val - min) / (max - min), min, max); + qDebug() << "options: registering stream operators"; + + qRegisterMetaTypeStreamOperators("slider_value"); } -// end +custom_type_initializer custom_type_initializer::singleton = custom_type_initializer(); + +} // end + +QDataStream& operator <<(QDataStream& out, const options::slider_value& v) +{ + out << v.cur() << v.min() << v.max(); + qDebug() << "out cur" << v.cur(); + return out; +} + +QDataStream& operator >>(QDataStream& in, options::slider_value& v) +{ + double cur, min, max; + in >> cur; + in >> min; + in >> max; + v = options::slider_value(cur, min, max); + qDebug() << "in cur" << v.cur(); + return in; } -- cgit v1.2.3