summaryrefslogtreecommitdiffhomepage
path: root/compat/slider.hpp
blob: 7d54c650357904aece494ed8b2b907dd933b0856 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/* 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>

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)