summaryrefslogtreecommitdiffhomepage
path: root/opentrack-compat/slider.hpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2016-07-06 11:42:34 +0200
committerStanislaw Halik <sthalik@misaki.pl>2016-07-06 12:07:49 +0200
commit4707750a1578edf8afa6ed4a2a48b379cda5d01c (patch)
tree10b5df2dffe4f5bf9cb989b628a695286696dc08 /opentrack-compat/slider.hpp
parent38c0f0d5bce4db4cdbbcef14ffb60c66e8a52372 (diff)
compat/options: split too long header
Diffstat (limited to 'opentrack-compat/slider.hpp')
-rw-r--r--opentrack-compat/slider.hpp63
1 files changed, 63 insertions, 0 deletions
diff --git a/opentrack-compat/slider.hpp b/opentrack-compat/slider.hpp
new file mode 100644
index 00000000..d5e4a7d0
--- /dev/null
+++ b/opentrack-compat/slider.hpp
@@ -0,0 +1,63 @@
+/* Copyright (c) 2016 Stanislaw Halik
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ */
+
+#pragma once
+
+#include "export.hpp"
+#include <QMetaType>
+#include <QDataStream>
+#include <QDebug>
+#include <cmath>
+
+namespace options
+{
+ class OPENTRACK_COMPAT_EXPORT slider_value final
+ {
+ double cur_, min_, max_;
+ public:
+ slider_value(double cur, double min, double max);
+ slider_value(const slider_value& v);
+ slider_value();
+ slider_value& operator=(const slider_value& v);
+ bool operator==(const slider_value& v) const;
+ operator double() const { return cur_; }
+ double cur() const { return cur_; }
+ double min() const { return min_; }
+ double max() const { return max_; }
+ slider_value update_from_slider(int pos, int q_min, int q_max) const;
+ int to_slider_pos(int q_min, int q_max) const;
+ };
+}
+
+QT_BEGIN_NAMESPACE
+
+inline QDebug operator << (QDebug dbg, const options::slider_value& val)
+{
+ return dbg << val.cur();
+}
+
+inline QDataStream& operator << (QDataStream& out, const options::slider_value& v)
+{
+ out << v.cur()
+ << v.min()
+ << v.max();
+ return out;
+}
+
+inline 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);
+ return in;
+}
+
+QT_END_NAMESPACE
+
+Q_DECLARE_METATYPE(options::slider_value)