1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtWidgets module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QABSTRACTSPINBOX_P_H
41#define QABSTRACTSPINBOX_P_H
42
43//
44// W A R N I N G
45// -------------
46//
47// This file is not part of the Qt API. It exists purely as an
48// implementation detail. This header file may change from version to
49// version without notice, or even be removed.
50//
51// We mean it.
52//
53
54#include <QtWidgets/private/qtwidgetsglobal_p.h>
55#include "QtWidgets/qabstractspinbox.h"
56
57#include "QtWidgets/qlineedit.h"
58#include "QtWidgets/qstyleoption.h"
59#include "QtGui/qvalidator.h"
60#include "QtCore/qdatetime.h"
61#include "QtCore/qvariant.h"
62#include "private/qwidget_p.h"
63
64QT_REQUIRE_CONFIG(spinbox);
65
66QT_BEGIN_NAMESPACE
67
68QVariant operator+(const QVariant &arg1, const QVariant &arg2);
69QVariant operator-(const QVariant &arg1, const QVariant &arg2);
70QVariant operator*(const QVariant &arg1, double multiplier);
71double operator/(const QVariant &arg1, const QVariant &arg2);
72
73enum EmitPolicy {
74 EmitIfChanged,
75 AlwaysEmit,
76 NeverEmit
77};
78
79enum Button {
80 None = 0x000,
81 Keyboard = 0x001,
82 Mouse = 0x002,
83 Wheel = 0x004,
84 ButtonMask = 0x008,
85 Up = 0x010,
86 Down = 0x020,
87 DirectionMask = 0x040
88};
89class QSpinBoxValidator;
90class QAbstractSpinBoxPrivate : public QWidgetPrivate
91{
92 Q_DECLARE_PUBLIC(QAbstractSpinBox)
93public:
94 QAbstractSpinBoxPrivate();
95 ~QAbstractSpinBoxPrivate();
96
97 void init();
98 void reset();
99 void updateState(bool up, bool fromKeyboard = false);
100 QString stripped(const QString &text, int *pos = nullptr) const;
101 bool specialValue() const;
102 virtual QVariant getZeroVariant() const;
103 virtual void setRange(const QVariant &min, const QVariant &max);
104 void setValue(const QVariant &val, EmitPolicy ep, bool updateEdit = true);
105 virtual QVariant bound(const QVariant &val, const QVariant &old = QVariant(), int steps = 0) const;
106 virtual void updateEdit();
107
108 virtual void emitSignals(EmitPolicy ep, const QVariant &old);
109 virtual void interpret(EmitPolicy ep);
110 virtual QString textFromValue(const QVariant &n) const;
111 virtual QVariant valueFromText(const QString &input) const;
112
113 void _q_editorTextChanged(const QString &);
114 virtual void _q_editorCursorPositionChanged(int oldpos, int newpos);
115
116 virtual QStyle::SubControl newHoverControl(const QPoint &pos);
117 bool updateHoverControl(const QPoint &pos);
118
119 virtual void clearCache() const;
120 virtual void updateEditFieldGeometry();
121
122 static int variantCompare(const QVariant &arg1, const QVariant &arg2);
123 static QVariant variantBound(const QVariant &min, const QVariant &value, const QVariant &max);
124
125 virtual QVariant calculateAdaptiveDecimalStep(int steps) const;
126
127 QLineEdit *edit;
128 QString prefix, suffix, specialValueText;
129 QVariant value, minimum, maximum, singleStep;
130 QVariant::Type type;
131 int spinClickTimerId, spinClickTimerInterval, spinClickThresholdTimerId, spinClickThresholdTimerInterval;
132 int effectiveSpinRepeatRate;
133 uint buttonState;
134 mutable QString cachedText;
135 mutable QVariant cachedValue;
136 mutable QValidator::State cachedState;
137 mutable QSize cachedSizeHint, cachedMinimumSizeHint;
138 uint pendingEmit : 1;
139 uint readOnly : 1;
140 uint wrapping : 1;
141 uint ignoreCursorPositionChanged : 1;
142 uint frame : 1;
143 uint accelerate : 1;
144 uint keyboardTracking : 1;
145 uint cleared : 1;
146 uint ignoreUpdateEdit : 1;
147 QAbstractSpinBox::CorrectionMode correctionMode;
148 QAbstractSpinBox::StepType stepType = QAbstractSpinBox::StepType::DefaultStepType;
149 Qt::KeyboardModifier stepModifier = Qt::ControlModifier;
150 int acceleration;
151 QStyle::SubControl hoverControl;
152 QRect hoverRect;
153 QAbstractSpinBox::ButtonSymbols buttonSymbols;
154 QSpinBoxValidator *validator;
155 uint showGroupSeparator : 1;
156 int wheelDeltaRemainder;
157};
158
159class QSpinBoxValidator : public QValidator
160{
161public:
162 QSpinBoxValidator(QAbstractSpinBox *qptr, QAbstractSpinBoxPrivate *dptr);
163 QValidator::State validate(QString &input, int &) const override;
164 void fixup(QString &) const override;
165private:
166 QAbstractSpinBox *qptr;
167 QAbstractSpinBoxPrivate *dptr;
168};
169
170QT_END_NAMESPACE
171
172#endif // QABSTRACTSPINBOX_P_H
173