| 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 QABSTRACTBUTTON_H |
| 5 | #define QABSTRACTBUTTON_H |
| 6 | |
| 7 | #include <QtWidgets/qtwidgetsglobal.h> |
| 8 | #include <QtGui/qicon.h> |
| 9 | #if QT_CONFIG(shortcut) |
| 10 | # include <QtGui/qkeysequence.h> |
| 11 | #endif |
| 12 | #include <QtWidgets/qwidget.h> |
| 13 | |
| 14 | QT_REQUIRE_CONFIG(abstractbutton); |
| 15 | |
| 16 | QT_BEGIN_NAMESPACE |
| 17 | |
| 18 | |
| 19 | class QButtonGroup; |
| 20 | class QAbstractButtonPrivate; |
| 21 | |
| 22 | class Q_WIDGETS_EXPORT QAbstractButton : public QWidget |
| 23 | { |
| 24 | Q_OBJECT |
| 25 | |
| 26 | Q_PROPERTY(QString text READ text WRITE setText) |
| 27 | Q_PROPERTY(QIcon icon READ icon WRITE setIcon) |
| 28 | Q_PROPERTY(QSize iconSize READ iconSize WRITE setIconSize) |
| 29 | #ifndef QT_NO_SHORTCUT |
| 30 | Q_PROPERTY(QKeySequence shortcut READ shortcut WRITE setShortcut) |
| 31 | #endif |
| 32 | Q_PROPERTY(bool checkable READ isCheckable WRITE setCheckable) |
| 33 | Q_PROPERTY(bool checked READ isChecked WRITE setChecked NOTIFY toggled USER true) |
| 34 | Q_PROPERTY(bool autoRepeat READ autoRepeat WRITE setAutoRepeat) |
| 35 | Q_PROPERTY(bool autoExclusive READ autoExclusive WRITE setAutoExclusive) |
| 36 | Q_PROPERTY(int autoRepeatDelay READ autoRepeatDelay WRITE setAutoRepeatDelay) |
| 37 | Q_PROPERTY(int autoRepeatInterval READ autoRepeatInterval WRITE setAutoRepeatInterval) |
| 38 | Q_PROPERTY(bool down READ isDown WRITE setDown DESIGNABLE false) |
| 39 | |
| 40 | public: |
| 41 | explicit QAbstractButton(QWidget *parent = nullptr); |
| 42 | ~QAbstractButton(); |
| 43 | |
| 44 | void setText(const QString &text); |
| 45 | QString text() const; |
| 46 | |
| 47 | void setIcon(const QIcon &icon); |
| 48 | QIcon icon() const; |
| 49 | |
| 50 | QSize iconSize() const; |
| 51 | |
| 52 | #ifndef QT_NO_SHORTCUT |
| 53 | void setShortcut(const QKeySequence &key); |
| 54 | QKeySequence shortcut() const; |
| 55 | #endif |
| 56 | |
| 57 | void setCheckable(bool); |
| 58 | bool isCheckable() const; |
| 59 | |
| 60 | bool isChecked() const; |
| 61 | |
| 62 | void setDown(bool); |
| 63 | bool isDown() const; |
| 64 | |
| 65 | void setAutoRepeat(bool); |
| 66 | bool autoRepeat() const; |
| 67 | |
| 68 | void setAutoRepeatDelay(int); |
| 69 | int autoRepeatDelay() const; |
| 70 | |
| 71 | void setAutoRepeatInterval(int); |
| 72 | int autoRepeatInterval() const; |
| 73 | |
| 74 | void setAutoExclusive(bool); |
| 75 | bool autoExclusive() const; |
| 76 | |
| 77 | #if QT_CONFIG(buttongroup) |
| 78 | QButtonGroup *group() const; |
| 79 | #endif |
| 80 | |
| 81 | public Q_SLOTS: |
| 82 | void setIconSize(const QSize &size); |
| 83 | void animateClick(); |
| 84 | void click(); |
| 85 | void toggle(); |
| 86 | void setChecked(bool); |
| 87 | |
| 88 | Q_SIGNALS: |
| 89 | void pressed(); |
| 90 | void released(); |
| 91 | void clicked(bool checked = false); |
| 92 | void toggled(bool checked); |
| 93 | |
| 94 | protected: |
| 95 | void paintEvent(QPaintEvent *e) override = 0; |
| 96 | virtual bool hitButton(const QPoint &pos) const; |
| 97 | virtual void checkStateSet(); |
| 98 | virtual void nextCheckState(); |
| 99 | |
| 100 | bool event(QEvent *e) override; |
| 101 | void keyPressEvent(QKeyEvent *e) override; |
| 102 | void keyReleaseEvent(QKeyEvent *e) override; |
| 103 | void mousePressEvent(QMouseEvent *e) override; |
| 104 | void mouseReleaseEvent(QMouseEvent *e) override; |
| 105 | void mouseMoveEvent(QMouseEvent *e) override; |
| 106 | void focusInEvent(QFocusEvent *e) override; |
| 107 | void focusOutEvent(QFocusEvent *e) override; |
| 108 | void changeEvent(QEvent *e) override; |
| 109 | void timerEvent(QTimerEvent *e) override; |
| 110 | |
| 111 | |
| 112 | protected: |
| 113 | QAbstractButton(QAbstractButtonPrivate &dd, QWidget* parent = nullptr); |
| 114 | |
| 115 | private: |
| 116 | Q_DECLARE_PRIVATE(QAbstractButton) |
| 117 | Q_DISABLE_COPY(QAbstractButton) |
| 118 | friend class QButtonGroup; |
| 119 | }; |
| 120 | |
| 121 | QT_END_NAMESPACE |
| 122 | |
| 123 | #endif // QABSTRACTBUTTON_H |
| 124 | |