| 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 | |
| 21 | QT_BEGIN_NAMESPACE |
| 22 | |
| 23 | class QQuickAction; |
| 24 | class QQuickAbstractButtonPrivate; |
| 25 | |
| 26 | class Q_QUICKTEMPLATES2_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 | |
| 53 | public: |
| 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 | |
| 120 | public Q_SLOTS: |
| 121 | void toggle(); |
| 122 | Q_REVISION(6, 8) void click(); |
| 123 | Q_REVISION(6, 8) void animateClick(); |
| 124 | |
| 125 | Q_SIGNALS: |
| 126 | void pressed(); |
| 127 | void released(); |
| 128 | void canceled(); |
| 129 | void clicked(); |
| 130 | void pressAndHold(); |
| 131 | void doubleClicked(); |
| 132 | void textChanged(); |
| 133 | void downChanged(); |
| 134 | void pressedChanged(); |
| 135 | void checkedChanged(); |
| 136 | void checkableChanged(); |
| 137 | void autoExclusiveChanged(); |
| 138 | void autoRepeatChanged(); |
| 139 | void indicatorChanged(); |
| 140 | // 2.2 (Qt 5.9) |
| 141 | Q_REVISION(2, 2) void toggled(); |
| 142 | // 2.3 (Qt 5.10) |
| 143 | Q_REVISION(2, 3) void iconChanged(); |
| 144 | Q_REVISION(2, 3) void displayChanged(); |
| 145 | Q_REVISION(2, 3) void actionChanged(); |
| 146 | // 2.4 (Qt 5.11) |
| 147 | Q_REVISION(2, 4) void autoRepeatDelayChanged(); |
| 148 | Q_REVISION(2, 4) void autoRepeatIntervalChanged(); |
| 149 | Q_REVISION(2, 4) void pressXChanged(); |
| 150 | Q_REVISION(2, 4) void pressYChanged(); |
| 151 | // 2.5 (Qt 5.12) |
| 152 | Q_REVISION(2, 5) void implicitIndicatorWidthChanged(); |
| 153 | Q_REVISION(2, 5) void implicitIndicatorHeightChanged(); |
| 154 | |
| 155 | protected: |
| 156 | QQuickAbstractButton(QQuickAbstractButtonPrivate &dd, QQuickItem *parent); |
| 157 | |
| 158 | void componentComplete() override; |
| 159 | |
| 160 | bool event(QEvent *event) override; |
| 161 | void focusOutEvent(QFocusEvent *event) override; |
| 162 | void keyPressEvent(QKeyEvent *event) override; |
| 163 | void keyReleaseEvent(QKeyEvent *event) override; |
| 164 | void mousePressEvent(QMouseEvent *event) override; |
| 165 | void mouseDoubleClickEvent(QMouseEvent *event) override; |
| 166 | void timerEvent(QTimerEvent *event) override; |
| 167 | |
| 168 | void itemChange(ItemChange change, const ItemChangeData &value) override; |
| 169 | |
| 170 | enum ButtonChange { |
| 171 | ButtonCheckedChange, |
| 172 | ButtonCheckableChange, |
| 173 | ButtonPressedChanged, |
| 174 | ButtonTextChange |
| 175 | }; |
| 176 | virtual void buttonChange(ButtonChange change); |
| 177 | |
| 178 | virtual void nextCheckState(); |
| 179 | |
| 180 | #if QT_CONFIG(accessibility) |
| 181 | void accessibilityActiveChanged(bool active) override; |
| 182 | QAccessible::Role accessibleRole() const override; |
| 183 | Q_INVOKABLE void accessiblePressAction(); |
| 184 | #endif |
| 185 | |
| 186 | private: |
| 187 | Q_DISABLE_COPY(QQuickAbstractButton) |
| 188 | Q_DECLARE_PRIVATE(QQuickAbstractButton) |
| 189 | }; |
| 190 | |
| 191 | QT_END_NAMESPACE |
| 192 | |
| 193 | #endif // QQUICKABSTRACTBUTTON_P_H |
| 194 | |