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 QABSTRACTSPINBOX_P_H |
5 | #define QABSTRACTSPINBOX_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 "QtWidgets/qabstractspinbox.h" |
20 | |
21 | #include "QtWidgets/qlineedit.h" |
22 | #include "QtWidgets/qstyleoption.h" |
23 | #include "QtGui/qvalidator.h" |
24 | #include "QtCore/qdatetime.h" |
25 | #include "QtCore/qvariant.h" |
26 | #include "private/qwidget_p.h" |
27 | |
28 | QT_REQUIRE_CONFIG(spinbox); |
29 | |
30 | QT_BEGIN_NAMESPACE |
31 | |
32 | QVariant operator+(const QVariant &arg1, const QVariant &arg2); |
33 | QVariant operator-(const QVariant &arg1, const QVariant &arg2); |
34 | QVariant operator*(const QVariant &arg1, double multiplier); |
35 | double operator/(const QVariant &arg1, const QVariant &arg2); |
36 | |
37 | enum EmitPolicy { |
38 | EmitIfChanged, |
39 | AlwaysEmit, |
40 | NeverEmit |
41 | }; |
42 | |
43 | enum Button { |
44 | None = 0x000, |
45 | Keyboard = 0x001, |
46 | Mouse = 0x002, |
47 | Wheel = 0x004, |
48 | ButtonMask = 0x008, |
49 | Up = 0x010, |
50 | Down = 0x020, |
51 | DirectionMask = 0x040 |
52 | }; |
53 | class QSpinBoxValidator; |
54 | class QAbstractSpinBoxPrivate : public QWidgetPrivate |
55 | { |
56 | Q_DECLARE_PUBLIC(QAbstractSpinBox) |
57 | public: |
58 | QAbstractSpinBoxPrivate(); |
59 | ~QAbstractSpinBoxPrivate(); |
60 | |
61 | void init(); |
62 | void reset(); |
63 | void updateState(bool up, bool fromKeyboard = false); |
64 | QString stripped(const QString &text, int *pos = nullptr) const; |
65 | bool specialValue() const; |
66 | virtual QVariant getZeroVariant() const; |
67 | virtual void setRange(const QVariant &min, const QVariant &max); |
68 | void setValue(const QVariant &val, EmitPolicy ep, bool updateEdit = true); |
69 | virtual QVariant bound(const QVariant &val, const QVariant &old = QVariant(), int steps = 0) const; |
70 | virtual void updateEdit(); |
71 | |
72 | virtual void emitSignals(EmitPolicy ep, const QVariant &old); |
73 | virtual void interpret(EmitPolicy ep); |
74 | virtual QString textFromValue(const QVariant &n) const; |
75 | virtual QVariant valueFromText(const QString &input) const; |
76 | |
77 | void _q_editorTextChanged(const QString &); |
78 | virtual void _q_editorCursorPositionChanged(int oldpos, int newpos); |
79 | |
80 | virtual QStyle::SubControl newHoverControl(const QPoint &pos); |
81 | bool updateHoverControl(const QPoint &pos); |
82 | |
83 | virtual void clearCache() const; |
84 | virtual void updateEditFieldGeometry(); |
85 | |
86 | static int variantCompare(const QVariant &arg1, const QVariant &arg2); |
87 | static QVariant variantBound(const QVariant &min, const QVariant &value, const QVariant &max); |
88 | |
89 | virtual QVariant calculateAdaptiveDecimalStep(int steps) const; |
90 | |
91 | QString prefix, suffix, specialValueText; |
92 | QVariant value, minimum, maximum, singleStep; |
93 | QRect hoverRect; |
94 | |
95 | mutable QString cachedText = { u'\x01' }; |
96 | mutable QVariant cachedValue; |
97 | mutable QSize cachedSizeHint, cachedMinimumSizeHint; |
98 | QLineEdit *edit = nullptr; |
99 | QSpinBoxValidator *validator = nullptr; |
100 | QMetaType::Type type = QMetaType::UnknownType; |
101 | int spinClickTimerId = -1; |
102 | int spinClickTimerInterval = 100; |
103 | int spinClickThresholdTimerId = -1; |
104 | int spinClickThresholdTimerInterval = -1; |
105 | qreal effectiveSpinRepeatRate = 1; |
106 | int acceleration = 0; |
107 | int wheelDeltaRemainder = 0; |
108 | |
109 | Qt::KeyboardModifiers keyboardModifiers = Qt::NoModifier; |
110 | Qt::KeyboardModifier stepModifier = Qt::ControlModifier; |
111 | QAbstractSpinBox::CorrectionMode correctionMode = QAbstractSpinBox::CorrectToPreviousValue; |
112 | QAbstractSpinBox::StepType stepType = QAbstractSpinBox::StepType::DefaultStepType; |
113 | QAbstractSpinBox::ButtonSymbols buttonSymbols = QAbstractSpinBox::UpDownArrows; |
114 | QStyle::SubControl hoverControl = QStyle::SC_None; |
115 | mutable QValidator::State cachedState = QValidator::Invalid; |
116 | uint buttonState = None; |
117 | uint pendingEmit : 1; |
118 | uint readOnly : 1; |
119 | uint wrapping : 1; |
120 | uint ignoreCursorPositionChanged : 1; |
121 | uint frame : 1; |
122 | uint accelerate : 1; |
123 | uint keyboardTracking : 1; |
124 | uint cleared : 1; |
125 | uint ignoreUpdateEdit : 1; |
126 | uint showGroupSeparator : 1; |
127 | }; |
128 | |
129 | class QSpinBoxValidator : public QValidator |
130 | { |
131 | public: |
132 | QSpinBoxValidator(QAbstractSpinBox *qptr, QAbstractSpinBoxPrivate *dptr); |
133 | QValidator::State validate(QString &input, int &) const override; |
134 | void fixup(QString &) const override; |
135 | private: |
136 | QAbstractSpinBox *qptr; |
137 | QAbstractSpinBoxPrivate *dptr; |
138 | }; |
139 | |
140 | QT_END_NAMESPACE |
141 | |
142 | #endif // QABSTRACTSPINBOX_P_H |
143 | |