Changeset View
Changeset View
Standalone View
Standalone View
kcms/touchpadx/src/kcm/xlib/customslider.h
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright (C) 2013 Alexander Mezin <mezin.alexander@gmail.com> | ||||
3 | * | ||||
4 | * This program is free software; you can redistribute it and/or modify | ||||
5 | * it under the terms of the GNU General Public License as published by | ||||
6 | * the Free Software Foundation; either version 2 of the License, or | ||||
7 | * (at your option) any later version. | ||||
8 | * | ||||
9 | * This program is distributed in the hope that it will be useful, | ||||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
12 | * GNU General Public License for more details. | ||||
13 | * | ||||
14 | * You should have received a copy of the GNU General Public License | ||||
15 | * along with this program; if not, write to the Free Software | ||||
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||||
17 | */ | ||||
18 | | ||||
19 | #ifndef CUSTOMSLIDER_H | ||||
20 | #define CUSTOMSLIDER_H | ||||
21 | | ||||
22 | #include <QSlider> | ||||
23 | | ||||
24 | class CustomSlider : public QSlider | ||||
25 | { | ||||
26 | Q_OBJECT | ||||
27 | | ||||
28 | Q_PROPERTY(double minimum READ doubleMinimum WRITE setDoubleMinimum) | ||||
29 | Q_PROPERTY(double maximum READ doubleMaximum WRITE setDoubleMaximum) | ||||
30 | Q_PROPERTY(double value READ doubleValue WRITE setDoubleValue \ | ||||
31 | NOTIFY valueChanged USER true) | ||||
32 | | ||||
33 | public: | ||||
34 | explicit CustomSlider(QWidget *parent = 0); | ||||
35 | | ||||
36 | void setDoubleMinimum(double); | ||||
37 | double doubleMinimum() const; | ||||
38 | | ||||
39 | void setDoubleMaximum(double); | ||||
40 | double doubleMaximum() const; | ||||
41 | | ||||
42 | class Interpolator | ||||
43 | { | ||||
44 | public: | ||||
45 | Interpolator() { } | ||||
46 | virtual double absolute(double relative, | ||||
47 | double minimum, double maximum) const; | ||||
48 | virtual double relative(double absolute, | ||||
49 | double minimum, double maximum) const; | ||||
50 | | ||||
51 | virtual ~Interpolator(); | ||||
52 | }; | ||||
53 | | ||||
54 | class SqrtInterpolator : public Interpolator | ||||
55 | { | ||||
56 | public: | ||||
57 | SqrtInterpolator() { } | ||||
58 | double absolute(double relative, double minimum, double maximum) const override; | ||||
59 | double relative(double absolute, double minimum, double maximum) const override; | ||||
60 | }; | ||||
61 | | ||||
62 | const Interpolator *interpolator() const; | ||||
63 | void setInterpolator(const Interpolator *); | ||||
64 | | ||||
65 | double doubleValue() const; | ||||
66 | double fixup(double) const; | ||||
67 | | ||||
68 | public Q_SLOTS: | ||||
69 | void setDoubleValue(double); | ||||
70 | | ||||
71 | Q_SIGNALS: | ||||
72 | void valueChanged(double); | ||||
73 | | ||||
74 | protected: | ||||
75 | void resizeEvent(QResizeEvent *) override; | ||||
76 | | ||||
77 | private Q_SLOTS: | ||||
78 | void updateValue(); | ||||
79 | | ||||
80 | private: | ||||
81 | void updateRange(const QSize &); | ||||
82 | void moveSlider(); | ||||
83 | int doubleToInt(double) const; | ||||
84 | double intToDouble(int) const; | ||||
85 | | ||||
86 | static const Interpolator lerp; | ||||
87 | | ||||
88 | double m_min, m_max, m_value; | ||||
89 | const Interpolator *m_interpolator; | ||||
90 | }; | ||||
91 | | ||||
92 | #endif // CUSTOMSLIDER_H |