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

source code of qtbase/src/widgets/widgets/qabstractspinbox.h