1// Copyright (C) 2017 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 QQUICKABSTRACTBUTTON_P_H
5#define QQUICKABSTRACTBUTTON_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 <QtQuickTemplates2/private/qquickcontrol_p.h>
19#include <QtQuickTemplates2/private/qquickicon_p.h>
20
21QT_BEGIN_NAMESPACE
22
23class QQuickAction;
24class QQuickAbstractButtonPrivate;
25
26class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickAbstractButton : public QQuickControl
27{
28 Q_OBJECT
29 Q_PROPERTY(QString text READ text WRITE setText RESET resetText NOTIFY textChanged FINAL)
30 Q_PROPERTY(bool down READ isDown WRITE setDown NOTIFY downChanged RESET resetDown FINAL)
31 Q_PROPERTY(bool pressed READ isPressed NOTIFY pressedChanged FINAL)
32 Q_PROPERTY(bool checked READ isChecked WRITE setChecked NOTIFY checkedChanged FINAL)
33 Q_PROPERTY(bool checkable READ isCheckable WRITE setCheckable NOTIFY checkableChanged FINAL)
34 Q_PROPERTY(bool autoExclusive READ autoExclusive WRITE setAutoExclusive NOTIFY autoExclusiveChanged FINAL)
35 Q_PROPERTY(bool autoRepeat READ autoRepeat WRITE setAutoRepeat NOTIFY autoRepeatChanged FINAL)
36 Q_PROPERTY(QQuickItem *indicator READ indicator WRITE setIndicator NOTIFY indicatorChanged FINAL)
37 // 2.3 (Qt 5.10)
38 Q_PROPERTY(QQuickIcon icon READ icon WRITE setIcon NOTIFY iconChanged FINAL REVISION(2, 3))
39 Q_PROPERTY(Display display READ display WRITE setDisplay NOTIFY displayChanged FINAL REVISION(2, 3))
40 Q_PROPERTY(QQuickAction *action READ action WRITE setAction NOTIFY actionChanged FINAL REVISION(2, 3))
41 // 2.4 (Qt 5.11)
42 Q_PROPERTY(int autoRepeatDelay READ autoRepeatDelay WRITE setAutoRepeatDelay NOTIFY autoRepeatDelayChanged FINAL REVISION(2, 4))
43 Q_PROPERTY(int autoRepeatInterval READ autoRepeatInterval WRITE setAutoRepeatInterval NOTIFY autoRepeatIntervalChanged FINAL REVISION(2, 4))
44 Q_PROPERTY(qreal pressX READ pressX NOTIFY pressXChanged FINAL REVISION(2, 4))
45 Q_PROPERTY(qreal pressY READ pressY NOTIFY pressYChanged FINAL REVISION(2, 4))
46 // 2.5 (Qt 5.12)
47 Q_PROPERTY(qreal implicitIndicatorWidth READ implicitIndicatorWidth NOTIFY implicitIndicatorWidthChanged FINAL REVISION(2, 5))
48 Q_PROPERTY(qreal implicitIndicatorHeight READ implicitIndicatorHeight NOTIFY implicitIndicatorHeightChanged FINAL REVISION(2, 5))
49 Q_CLASSINFO("DeferredPropertyNames", "background,contentItem,indicator")
50 QML_NAMED_ELEMENT(AbstractButton)
51 QML_ADDED_IN_VERSION(2, 0)
52
53public:
54 explicit QQuickAbstractButton(QQuickItem *parent = nullptr);
55 ~QQuickAbstractButton();
56
57 QString text() const;
58 void setText(const QString &text);
59 void resetText();
60
61 bool isDown() const;
62 void setDown(bool down);
63 void resetDown();
64
65 bool isPressed() const;
66 void setPressed(bool pressed);
67
68 bool isChecked() const;
69 void setChecked(bool checked);
70
71 bool isCheckable() const;
72 void setCheckable(bool checkable);
73
74 bool autoExclusive() const;
75 void setAutoExclusive(bool exclusive);
76
77 bool autoRepeat() const;
78 void setAutoRepeat(bool repeat);
79
80 QQuickItem *indicator() const;
81 void setIndicator(QQuickItem *indicator);
82
83 // 2.3 (Qt 5.10)
84 QQuickIcon icon() const;
85 void setIcon(const QQuickIcon &icon);
86
87 enum Display {
88 IconOnly,
89 TextOnly,
90 TextBesideIcon,
91 TextUnderIcon
92 };
93 Q_ENUM(Display)
94
95 Display display() const;
96 void setDisplay(Display display);
97
98 QQuickAction *action() const;
99 void setAction(QQuickAction *action);
100
101#if QT_CONFIG(shortcut)
102 QKeySequence shortcut() const;
103 void setShortcut(const QKeySequence &shortcut);
104#endif
105
106 // 2.4 (Qt 5.11)
107 int autoRepeatDelay() const;
108 void setAutoRepeatDelay(int delay);
109
110 int autoRepeatInterval() const;
111 void setAutoRepeatInterval(int interval);
112
113 qreal pressX() const;
114 qreal pressY() const;
115
116 // 2.5 (Qt 5.12)
117 qreal implicitIndicatorWidth() const;
118 qreal implicitIndicatorHeight() const;
119
120public Q_SLOTS:
121 void toggle();
122
123Q_SIGNALS:
124 void pressed();
125 void released();
126 void canceled();
127 void clicked();
128 void pressAndHold();
129 void doubleClicked();
130 void textChanged();
131 void downChanged();
132 void pressedChanged();
133 void checkedChanged();
134 void checkableChanged();
135 void autoExclusiveChanged();
136 void autoRepeatChanged();
137 void indicatorChanged();
138 // 2.2 (Qt 5.9)
139 Q_REVISION(2, 2) void toggled();
140 // 2.3 (Qt 5.10)
141 Q_REVISION(2, 3) void iconChanged();
142 Q_REVISION(2, 3) void displayChanged();
143 Q_REVISION(2, 3) void actionChanged();
144 // 2.4 (Qt 5.11)
145 Q_REVISION(2, 4) void autoRepeatDelayChanged();
146 Q_REVISION(2, 4) void autoRepeatIntervalChanged();
147 Q_REVISION(2, 4) void pressXChanged();
148 Q_REVISION(2, 4) void pressYChanged();
149 // 2.5 (Qt 5.12)
150 Q_REVISION(2, 5) void implicitIndicatorWidthChanged();
151 Q_REVISION(2, 5) void implicitIndicatorHeightChanged();
152
153protected:
154 QQuickAbstractButton(QQuickAbstractButtonPrivate &dd, QQuickItem *parent);
155
156 void componentComplete() override;
157
158 bool event(QEvent *event) override;
159 void focusOutEvent(QFocusEvent *event) override;
160 void keyPressEvent(QKeyEvent *event) override;
161 void keyReleaseEvent(QKeyEvent *event) override;
162 void mousePressEvent(QMouseEvent *event) override;
163 void mouseDoubleClickEvent(QMouseEvent *event) override;
164 void timerEvent(QTimerEvent *event) override;
165
166 void itemChange(ItemChange change, const ItemChangeData &value) override;
167
168 enum ButtonChange {
169 ButtonCheckedChange,
170 ButtonCheckableChange,
171 ButtonPressedChanged,
172 ButtonTextChange
173 };
174 virtual void buttonChange(ButtonChange change);
175
176 virtual void nextCheckState();
177
178#if QT_CONFIG(accessibility)
179 void accessibilityActiveChanged(bool active) override;
180 QAccessible::Role accessibleRole() const override;
181 Q_INVOKABLE void accessiblePressAction();
182#endif
183
184private:
185 Q_DISABLE_COPY(QQuickAbstractButton)
186 Q_DECLARE_PRIVATE(QQuickAbstractButton)
187};
188
189QT_END_NAMESPACE
190
191QML_DECLARE_TYPE(QQuickAbstractButton)
192
193#endif // QQUICKABSTRACTBUTTON_P_H
194

source code of qtdeclarative/src/quicktemplates/qquickabstractbutton_p.h