1 | // Copyright (C) 2016 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #ifndef QABSTRACTSLIDER_H |
5 | #define QABSTRACTSLIDER_H |
6 | |
7 | #include <QtWidgets/qtwidgetsglobal.h> |
8 | #include <QtWidgets/qwidget.h> |
9 | |
10 | QT_REQUIRE_CONFIG(abstractslider); |
11 | |
12 | QT_BEGIN_NAMESPACE |
13 | |
14 | |
15 | class QAbstractSliderPrivate; |
16 | |
17 | class Q_WIDGETS_EXPORT QAbstractSlider : public QWidget |
18 | { |
19 | Q_OBJECT |
20 | |
21 | Q_PROPERTY(int minimum READ minimum WRITE setMinimum) |
22 | Q_PROPERTY(int maximum READ maximum WRITE setMaximum) |
23 | Q_PROPERTY(int singleStep READ singleStep WRITE setSingleStep) |
24 | Q_PROPERTY(int pageStep READ pageStep WRITE setPageStep) |
25 | Q_PROPERTY(int value READ value WRITE setValue NOTIFY valueChanged USER true) |
26 | Q_PROPERTY(int sliderPosition READ sliderPosition WRITE setSliderPosition NOTIFY sliderMoved) |
27 | Q_PROPERTY(bool tracking READ hasTracking WRITE setTracking) |
28 | Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation) |
29 | Q_PROPERTY(bool invertedAppearance READ invertedAppearance WRITE setInvertedAppearance) |
30 | Q_PROPERTY(bool invertedControls READ invertedControls WRITE setInvertedControls) |
31 | Q_PROPERTY(bool sliderDown READ isSliderDown WRITE setSliderDown DESIGNABLE false) |
32 | |
33 | public: |
34 | explicit QAbstractSlider(QWidget *parent = nullptr); |
35 | ~QAbstractSlider(); |
36 | |
37 | Qt::Orientation orientation() const; |
38 | |
39 | void setMinimum(int); |
40 | int minimum() const; |
41 | |
42 | void setMaximum(int); |
43 | int maximum() const; |
44 | |
45 | void setSingleStep(int); |
46 | int singleStep() const; |
47 | |
48 | void setPageStep(int); |
49 | int pageStep() const; |
50 | |
51 | void setTracking(bool enable); |
52 | bool hasTracking() const; |
53 | |
54 | void setSliderDown(bool); |
55 | bool isSliderDown() const; |
56 | |
57 | void setSliderPosition(int); |
58 | int sliderPosition() const; |
59 | |
60 | void setInvertedAppearance(bool); |
61 | bool invertedAppearance() const; |
62 | |
63 | void setInvertedControls(bool); |
64 | bool invertedControls() const; |
65 | |
66 | enum SliderAction { |
67 | SliderNoAction, |
68 | SliderSingleStepAdd, |
69 | SliderSingleStepSub, |
70 | SliderPageStepAdd, |
71 | SliderPageStepSub, |
72 | SliderToMinimum, |
73 | SliderToMaximum, |
74 | SliderMove |
75 | }; |
76 | |
77 | int value() const; |
78 | |
79 | void triggerAction(SliderAction action); |
80 | |
81 | public Q_SLOTS: |
82 | void setValue(int); |
83 | void setOrientation(Qt::Orientation); |
84 | void setRange(int min, int max); |
85 | |
86 | Q_SIGNALS: |
87 | void valueChanged(int value); |
88 | |
89 | void sliderPressed(); |
90 | void sliderMoved(int position); |
91 | void sliderReleased(); |
92 | |
93 | void rangeChanged(int min, int max); |
94 | |
95 | void actionTriggered(int action); |
96 | |
97 | protected: |
98 | bool event(QEvent *e) override; |
99 | |
100 | void setRepeatAction(SliderAction action, int thresholdTime = 500, int repeatTime = 50); |
101 | SliderAction repeatAction() const; |
102 | |
103 | enum SliderChange { |
104 | SliderRangeChange, |
105 | SliderOrientationChange, |
106 | SliderStepsChange, |
107 | SliderValueChange |
108 | }; |
109 | virtual void sliderChange(SliderChange change); |
110 | |
111 | void keyPressEvent(QKeyEvent *ev) override; |
112 | void timerEvent(QTimerEvent *) override; |
113 | #if QT_CONFIG(wheelevent) |
114 | void wheelEvent(QWheelEvent *e) override; |
115 | #endif |
116 | void changeEvent(QEvent *e) override; |
117 | |
118 | |
119 | protected: |
120 | QAbstractSlider(QAbstractSliderPrivate &dd, QWidget *parent = nullptr); |
121 | |
122 | private: |
123 | Q_DISABLE_COPY(QAbstractSlider) |
124 | Q_DECLARE_PRIVATE(QAbstractSlider) |
125 | }; |
126 | |
127 | QT_END_NAMESPACE |
128 | |
129 | #endif // QABSTRACTSLIDER_H |
130 | |