QtGui/qabstractbutton.h Source File

qabstractbutton.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui 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 Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #ifndef QABSTRACTBUTTON_H
43 #define QABSTRACTBUTTON_H
44 
45 #include <QtGui/qicon.h>
46 #include <QtGui/qkeysequence.h>
47 #include <QtGui/qwidget.h>
48 
50 
52 
53 QT_MODULE(Gui)
54 
55 class QButtonGroup;
56 class QAbstractButtonPrivate;
57 
58 class Q_GUI_EXPORT QAbstractButton : public QWidget
59 {
60  Q_OBJECT
61 
62  Q_PROPERTY(QString text READ text WRITE setText)
63  Q_PROPERTY(QIcon icon READ icon WRITE setIcon)
64  Q_PROPERTY(QSize iconSize READ iconSize WRITE setIconSize)
65 #ifndef QT_NO_SHORTCUT
66  Q_PROPERTY(QKeySequence shortcut READ shortcut WRITE setShortcut)
67 #endif
68  Q_PROPERTY(bool checkable READ isCheckable WRITE setCheckable)
69  Q_PROPERTY(bool checked READ isChecked WRITE setChecked DESIGNABLE isCheckable NOTIFY toggled USER true)
70  Q_PROPERTY(bool autoRepeat READ autoRepeat WRITE setAutoRepeat)
71  Q_PROPERTY(bool autoExclusive READ autoExclusive WRITE setAutoExclusive)
72  Q_PROPERTY(int autoRepeatDelay READ autoRepeatDelay WRITE setAutoRepeatDelay)
73  Q_PROPERTY(int autoRepeatInterval READ autoRepeatInterval WRITE setAutoRepeatInterval)
74  Q_PROPERTY(bool down READ isDown WRITE setDown DESIGNABLE false)
75 
76 public:
77  explicit QAbstractButton(QWidget* parent=0);
78  ~QAbstractButton();
79 
80  void setText(const QString &text);
81  QString text() const;
82 
83  void setIcon(const QIcon &icon);
84  QIcon icon() const;
85 
86  QSize iconSize() const;
87 
88 #ifndef QT_NO_SHORTCUT
89  void setShortcut(const QKeySequence &key);
90  QKeySequence shortcut() const;
91 #endif
92 
93  void setCheckable(bool);
94  bool isCheckable() const;
95 
96  bool isChecked() const;
97 
98  void setDown(bool);
99  bool isDown() const;
100 
101  void setAutoRepeat(bool);
102  bool autoRepeat() const;
103 
104  void setAutoRepeatDelay(int);
105  int autoRepeatDelay() const;
106 
107  void setAutoRepeatInterval(int);
108  int autoRepeatInterval() const;
109 
110  void setAutoExclusive(bool);
111  bool autoExclusive() const;
112 
113 #ifndef QT_NO_BUTTONGROUP
114  QButtonGroup *group() const;
115 #endif
116 
117 public Q_SLOTS:
118  void setIconSize(const QSize &size);
119  void animateClick(int msec = 100);
120  void click();
121  void toggle();
122  void setChecked(bool);
123 
124 Q_SIGNALS:
125  void pressed();
126  void released();
127  void clicked(bool checked = false);
128  void toggled(bool checked);
129 
130 protected:
131  virtual void paintEvent(QPaintEvent *e) = 0;
132  virtual bool hitButton(const QPoint &pos) const;
133  virtual void checkStateSet();
134  virtual void nextCheckState();
135 
136  bool event(QEvent *e);
137  void keyPressEvent(QKeyEvent *e);
138  void keyReleaseEvent(QKeyEvent *e);
139  void mousePressEvent(QMouseEvent *e);
140  void mouseReleaseEvent(QMouseEvent *e);
141  void mouseMoveEvent(QMouseEvent *e);
142  void focusInEvent(QFocusEvent *e);
143  void focusOutEvent(QFocusEvent *e);
144  void changeEvent(QEvent *e);
145  void timerEvent(QTimerEvent *e);
146 
147 #ifdef QT3_SUPPORT
148 public:
149  QT3_SUPPORT_CONSTRUCTOR QAbstractButton(QWidget *parent, const char *name, Qt::WindowFlags f=0);
150  inline QT3_SUPPORT bool isOn() const { return isChecked(); }
151  inline QT3_SUPPORT const QPixmap *pixmap() const { return 0; } // help styles compile
152  inline QT3_SUPPORT void setPixmap( const QPixmap &p ) {
153  setIcon(QIcon(p));
154  setIconSize(p.size());
155  }
156  QT3_SUPPORT QIcon *iconSet() const;
157  inline QT3_SUPPORT void setIconSet(const QIcon &icon) { setIcon(icon); }
158  inline QT3_SUPPORT bool isToggleButton() const { return isCheckable(); }
159  inline QT3_SUPPORT void setToggleButton(bool b) { setCheckable(b); }
160  inline QT3_SUPPORT void setAccel(const QKeySequence &key) { setShortcut(key); }
161  inline QT3_SUPPORT QKeySequence accel() const { return shortcut(); }
162 
163 public Q_SLOTS:
164  inline QT_MOC_COMPAT void setOn(bool b) { setChecked(b); }
165 #endif
166 
167 protected:
168  QAbstractButton(QAbstractButtonPrivate &dd, QWidget* parent = 0);
169 
170 private:
171  Q_DECLARE_PRIVATE(QAbstractButton)
172  Q_DISABLE_COPY(QAbstractButton)
173  friend class QButtonGroup;
174 };
175 
177 
179 
180 #endif // QABSTRACTBUTTON_H
#define QT_END_NAMESPACE
Definition: qglobal.h:128
#define Q_PROPERTY(text)
Definition: qobjectdefs.h:80
#define QT_BEGIN_HEADER
Definition: qglobal.h:141
GLXFBConfig Pixmap pixmap
Definition: GLee.h:10237
#define Q_SLOTS
Definition: qobjectdefs.h:71
#define Q_SIGNALS
Definition: qobjectdefs.h:72
Definition: qicon.h:60
Definition: qpoint.h:53
#define QT_BEGIN_NAMESPACE
Definition: qglobal.h:127
QSize size() const
#define Q_OBJECT
Definition: qobjectdefs.h:157
GLubyte GLubyte b
Definition: GLee.h:5404
GLfloat GLfloat p
Definition: GLee.h:5416
Definition: qsize.h:53
GLuint const GLchar * name
Definition: GLee.h:1704
#define QT_END_HEADER
Definition: qglobal.h:142
GLclampf f
Definition: GLee.h:9303
GLsizeiptr size
Definition: GLee.h:1561