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_P_H |
5 | #define QABSTRACTSLIDER_P_H |
6 | |
7 | // |
8 | // W A R N I N G |
9 | // ------------- |
10 | // |
11 | // This file is not part of the Qt API. It exists purely as an |
12 | // implementation detail. This header file may change from version to |
13 | // version without notice, or even be removed. |
14 | // |
15 | // We mean it. |
16 | // |
17 | |
18 | #include <QtWidgets/private/qtwidgetsglobal_p.h> |
19 | #include "QtCore/qbasictimer.h" |
20 | #include "QtCore/qelapsedtimer.h" |
21 | #include "private/qwidget_p.h" |
22 | #include "qstyle.h" |
23 | |
24 | QT_REQUIRE_CONFIG(abstractslider); |
25 | |
26 | QT_BEGIN_NAMESPACE |
27 | |
28 | class QAbstractSliderPrivate : public QWidgetPrivate |
29 | { |
30 | Q_DECLARE_PUBLIC(QAbstractSlider) |
31 | public: |
32 | QAbstractSliderPrivate(); |
33 | ~QAbstractSliderPrivate(); |
34 | |
35 | void setSteps(int single, int page); |
36 | |
37 | int minimum, maximum, pageStep, value, position, pressValue; |
38 | |
39 | /** |
40 | * Call effectiveSingleStep() when changing the slider value. |
41 | */ |
42 | int singleStep; |
43 | int singleStepFromItemView; // If we have itemViews we track the views preferred singleStep value. |
44 | bool viewMayChangeSingleStep; |
45 | |
46 | float offset_accumulated; |
47 | uint tracking : 1; |
48 | uint blocktracking :1; |
49 | uint pressed : 1; |
50 | uint invertedAppearance : 1; |
51 | uint invertedControls : 1; |
52 | Qt::Orientation orientation; |
53 | |
54 | QBasicTimer repeatActionTimer; |
55 | int repeatActionTime; |
56 | QAbstractSlider::SliderAction repeatAction; |
57 | |
58 | #ifdef QT_KEYPAD_NAVIGATION |
59 | int origValue; |
60 | |
61 | /** |
62 | */ |
63 | bool isAutoRepeating; |
64 | |
65 | /** |
66 | * When we're auto repeating, we multiply singleStep with this value to |
67 | * get our effective step. |
68 | */ |
69 | qreal repeatMultiplier; |
70 | |
71 | /** |
72 | * The time of when the first auto repeating key press event occurs. |
73 | */ |
74 | QElapsedTimer firstRepeat; |
75 | |
76 | #endif |
77 | |
78 | inline int effectiveSingleStep() const |
79 | { |
80 | return singleStep |
81 | #ifdef QT_KEYPAD_NAVIGATION |
82 | * repeatMultiplier |
83 | #endif |
84 | ; |
85 | } |
86 | void itemviewChangeSingleStep(int step); |
87 | |
88 | virtual int bound(int val) const { return qMax(a: minimum, b: qMin(a: maximum, b: val)); } |
89 | inline int overflowSafeAdd(int add) const |
90 | { |
91 | int newValue = value + add; |
92 | if (add > 0 && newValue < value) |
93 | newValue = maximum; |
94 | else if (add < 0 && newValue > value) |
95 | newValue = minimum; |
96 | return newValue; |
97 | } |
98 | inline void setAdjustedSliderPosition(int position) |
99 | { |
100 | Q_Q(QAbstractSlider); |
101 | if (q->style()->styleHint(stylehint: QStyle::SH_Slider_StopMouseOverSlider, opt: nullptr, widget: q)) { |
102 | if ((position > pressValue - 2 * pageStep) && (position < pressValue + 2 * pageStep)) { |
103 | repeatAction = QAbstractSlider::SliderNoAction; |
104 | q->setSliderPosition(pressValue); |
105 | return; |
106 | } |
107 | } |
108 | q->triggerAction(action: repeatAction); |
109 | } |
110 | bool scrollByDelta(Qt::Orientation orientation, Qt::KeyboardModifiers modifiers, int delta); |
111 | }; |
112 | |
113 | QT_END_NAMESPACE |
114 | |
115 | #endif // QABSTRACTSLIDER_P_H |
116 | |