qabstractbutton.h 5.0 KB

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