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_H |
41 | #define QABSTRACTSPINBOX_H |
42 | |
43 | #include <QtWidgets/qtwidgetsglobal.h> |
44 | #include <QtWidgets/qwidget.h> |
45 | #include <QtGui/qvalidator.h> |
46 | |
47 | QT_REQUIRE_CONFIG(spinbox); |
48 | |
49 | QT_BEGIN_NAMESPACE |
50 | |
51 | class QLineEdit; |
52 | |
53 | class QAbstractSpinBoxPrivate; |
54 | class QStyleOptionSpinBox; |
55 | |
56 | class Q_WIDGETS_EXPORT QAbstractSpinBox : public QWidget |
57 | { |
58 | Q_OBJECT |
59 | |
60 | Q_PROPERTY(bool wrapping READ wrapping WRITE setWrapping) |
61 | Q_PROPERTY(bool frame READ hasFrame WRITE setFrame) |
62 | Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment) |
63 | Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly) |
64 | Q_PROPERTY(ButtonSymbols buttonSymbols READ buttonSymbols WRITE setButtonSymbols) |
65 | Q_PROPERTY(QString specialValueText READ specialValueText WRITE setSpecialValueText) |
66 | Q_PROPERTY(QString text READ text) |
67 | Q_PROPERTY(bool accelerated READ isAccelerated WRITE setAccelerated) |
68 | Q_PROPERTY(CorrectionMode correctionMode READ correctionMode WRITE setCorrectionMode) |
69 | Q_PROPERTY(bool acceptableInput READ hasAcceptableInput) |
70 | Q_PROPERTY(bool keyboardTracking READ keyboardTracking WRITE setKeyboardTracking) |
71 | Q_PROPERTY(bool showGroupSeparator READ isGroupSeparatorShown WRITE setGroupSeparatorShown) |
72 | public: |
73 | explicit QAbstractSpinBox(QWidget *parent = nullptr); |
74 | ~QAbstractSpinBox(); |
75 | |
76 | enum StepEnabledFlag { StepNone = 0x00, StepUpEnabled = 0x01, |
77 | StepDownEnabled = 0x02 }; |
78 | Q_DECLARE_FLAGS(StepEnabled, StepEnabledFlag) |
79 | |
80 | enum ButtonSymbols { UpDownArrows, PlusMinus, NoButtons }; |
81 | Q_ENUM(ButtonSymbols) |
82 | |
83 | ButtonSymbols buttonSymbols() const; |
84 | void setButtonSymbols(ButtonSymbols bs); |
85 | |
86 | enum CorrectionMode { CorrectToPreviousValue, CorrectToNearestValue }; |
87 | Q_ENUM(CorrectionMode) |
88 | |
89 | void setCorrectionMode(CorrectionMode cm); |
90 | CorrectionMode correctionMode() const; |
91 | |
92 | bool hasAcceptableInput() const; |
93 | QString text() const; |
94 | |
95 | QString specialValueText() const; |
96 | void setSpecialValueText(const QString &txt); |
97 | |
98 | bool wrapping() const; |
99 | void setWrapping(bool w); |
100 | |
101 | void setReadOnly(bool r); |
102 | bool isReadOnly() const; |
103 | |
104 | void setKeyboardTracking(bool kt); |
105 | bool keyboardTracking() const; |
106 | |
107 | void setAlignment(Qt::Alignment flag); |
108 | Qt::Alignment alignment() const; |
109 | |
110 | void setFrame(bool); |
111 | bool hasFrame() const; |
112 | |
113 | void setAccelerated(bool on); |
114 | bool isAccelerated() const; |
115 | |
116 | void setGroupSeparatorShown(bool shown); |
117 | bool isGroupSeparatorShown() const; |
118 | |
119 | QSize sizeHint() const override; |
120 | QSize minimumSizeHint() const override; |
121 | void interpretText(); |
122 | bool event(QEvent *event) override; |
123 | |
124 | QVariant inputMethodQuery(Qt::InputMethodQuery) const override; |
125 | |
126 | virtual QValidator::State validate(QString &input, int &pos) const; |
127 | virtual void fixup(QString &input) const; |
128 | |
129 | virtual void stepBy(int steps); |
130 | |
131 | enum StepType { |
132 | DefaultStepType, |
133 | AdaptiveDecimalStepType |
134 | }; |
135 | Q_ENUM(StepType) |
136 | |
137 | public Q_SLOTS: |
138 | void stepUp(); |
139 | void stepDown(); |
140 | void selectAll(); |
141 | virtual void clear(); |
142 | protected: |
143 | void resizeEvent(QResizeEvent *event) override; |
144 | void keyPressEvent(QKeyEvent *event) override; |
145 | void keyReleaseEvent(QKeyEvent *event) override; |
146 | #if QT_CONFIG(wheelevent) |
147 | void wheelEvent(QWheelEvent *event) override; |
148 | #endif |
149 | void focusInEvent(QFocusEvent *event) override; |
150 | void focusOutEvent(QFocusEvent *event) override; |
151 | #if QT_CONFIG(contextmenu) |
152 | void (QContextMenuEvent *event) override; |
153 | #endif |
154 | void changeEvent(QEvent *event) override; |
155 | void closeEvent(QCloseEvent *event) override; |
156 | void hideEvent(QHideEvent *event) override; |
157 | void mousePressEvent(QMouseEvent *event) override; |
158 | void mouseReleaseEvent(QMouseEvent *event) override; |
159 | void mouseMoveEvent(QMouseEvent *event) override; |
160 | void timerEvent(QTimerEvent *event) override; |
161 | void paintEvent(QPaintEvent *event) override; |
162 | void showEvent(QShowEvent *event) override; |
163 | void initStyleOption(QStyleOptionSpinBox *option) const; |
164 | |
165 | QLineEdit *lineEdit() const; |
166 | void setLineEdit(QLineEdit *edit); |
167 | |
168 | virtual StepEnabled stepEnabled() const; |
169 | Q_SIGNALS: |
170 | void editingFinished(); |
171 | protected: |
172 | QAbstractSpinBox(QAbstractSpinBoxPrivate &dd, QWidget *parent = nullptr); |
173 | |
174 | private: |
175 | Q_PRIVATE_SLOT(d_func(), void _q_editorTextChanged(const QString &)) |
176 | Q_PRIVATE_SLOT(d_func(), void _q_editorCursorPositionChanged(int, int)) |
177 | |
178 | Q_DECLARE_PRIVATE(QAbstractSpinBox) |
179 | Q_DISABLE_COPY(QAbstractSpinBox) |
180 | friend class QAccessibleAbstractSpinBox; |
181 | }; |
182 | Q_DECLARE_OPERATORS_FOR_FLAGS(QAbstractSpinBox::StepEnabled) |
183 | |
184 | QT_END_NAMESPACE |
185 | |
186 | #endif // QABSTRACTSPINBOX_H |
187 | |