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