qabstractbutton.h

Go to the documentation of this file.
00001 /****************************************************************************
00002 **
00003 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
00004 ** All rights reserved.
00005 ** Contact: Nokia Corporation (qt-info@nokia.com)
00006 **
00007 ** This file is part of the QtGui module of the Qt Toolkit.
00008 **
00009 ** $QT_BEGIN_LICENSE:LGPL$
00010 ** Commercial Usage
00011 ** Licensees holding valid Qt Commercial licenses may use this file in
00012 ** accordance with the Qt Commercial License Agreement provided with the
00013 ** Software or, alternatively, in accordance with the terms contained in
00014 ** a written agreement between you and Nokia.
00015 **
00016 ** GNU Lesser General Public License Usage
00017 ** Alternatively, this file may be used under the terms of the GNU Lesser
00018 ** General Public License version 2.1 as published by the Free Software
00019 ** Foundation and appearing in the file LICENSE.LGPL included in the
00020 ** packaging of this file.  Please review the following information to
00021 ** ensure the GNU Lesser General Public License version 2.1 requirements
00022 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
00023 **
00024 ** In addition, as a special exception, Nokia gives you certain additional
00025 ** rights.  These rights are described in the Nokia Qt LGPL Exception
00026 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this module.
00027 **
00028 ** GNU General Public License Usage
00029 ** Alternatively, this file may be used under the terms of the GNU
00030 ** General Public License version 3.0 as published by the Free Software
00031 ** Foundation and appearing in the file LICENSE.GPL included in the
00032 ** packaging of this file.  Please review the following information to
00033 ** ensure the GNU General Public License version 3.0 requirements will be
00034 ** met: http://www.gnu.org/copyleft/gpl.html.
00035 **
00036 ** If you have questions regarding the use of this file, please contact
00037 ** Nokia at qt-info@nokia.com.
00038 ** $QT_END_LICENSE$
00039 **
00040 ****************************************************************************/
00041 
00042 #ifndef QABSTRACTBUTTON_H
00043 #define QABSTRACTBUTTON_H
00044 
00045 #include <QtGui/qicon.h>
00046 #include <QtGui/qkeysequence.h>
00047 #include <QtGui/qwidget.h>
00048 
00049 QT_BEGIN_HEADER
00050 
00051 QT_BEGIN_NAMESPACE
00052 
00053 QT_MODULE(Gui)
00054 
00055 class QButtonGroup;
00056 class QAbstractButtonPrivate;
00057 
00058 class Q_GUI_EXPORT QAbstractButton : public QWidget
00059 {
00060     Q_OBJECT
00061 
00062     Q_PROPERTY(QString text READ text WRITE setText)
00063     Q_PROPERTY(QIcon icon READ icon WRITE setIcon)
00064     Q_PROPERTY(QSize iconSize READ iconSize WRITE setIconSize)
00065 #ifndef QT_NO_SHORTCUT
00066     Q_PROPERTY(QKeySequence shortcut READ shortcut WRITE setShortcut)
00067 #endif
00068     Q_PROPERTY(bool checkable READ isCheckable WRITE setCheckable)
00069     Q_PROPERTY(bool checked READ isChecked WRITE setChecked DESIGNABLE isCheckable NOTIFY toggled USER true)
00070     Q_PROPERTY(bool autoRepeat READ autoRepeat WRITE setAutoRepeat)
00071     Q_PROPERTY(bool autoExclusive READ autoExclusive WRITE setAutoExclusive)
00072     Q_PROPERTY(int autoRepeatDelay READ autoRepeatDelay WRITE setAutoRepeatDelay)
00073     Q_PROPERTY(int autoRepeatInterval READ autoRepeatInterval WRITE setAutoRepeatInterval)
00074     Q_PROPERTY(bool down READ isDown WRITE setDown DESIGNABLE false)
00075 
00076 public:
00077     explicit QAbstractButton(QWidget* parent=0);
00078     ~QAbstractButton();
00079 
00080     void setText(const QString &text);
00081     QString text() const;
00082 
00083     void setIcon(const QIcon &icon);
00084     QIcon icon() const;
00085 
00086     QSize iconSize() const;
00087 
00088 #ifndef QT_NO_SHORTCUT
00089     void setShortcut(const QKeySequence &key);
00090     QKeySequence shortcut() const;
00091 #endif
00092 
00093     void setCheckable(bool);
00094     bool isCheckable() const;
00095 
00096     bool isChecked() const;
00097 
00098     void setDown(bool);
00099     bool isDown() const;
00100 
00101     void setAutoRepeat(bool);
00102     bool autoRepeat() const;
00103 
00104     void setAutoRepeatDelay(int);
00105     int autoRepeatDelay() const;
00106 
00107     void setAutoRepeatInterval(int);
00108     int autoRepeatInterval() const;
00109 
00110     void setAutoExclusive(bool);
00111     bool autoExclusive() const;
00112 
00113 #ifndef QT_NO_BUTTONGROUP
00114     QButtonGroup *group() const;
00115 #endif
00116 
00117 public Q_SLOTS:
00118     void setIconSize(const QSize &size);
00119     void animateClick(int msec = 100);
00120     void click();
00121     void toggle();
00122     void setChecked(bool);
00123 
00124 Q_SIGNALS:
00125     void pressed();
00126     void released();
00127     void clicked(bool checked = false);
00128     void toggled(bool checked);
00129 
00130 protected:
00131     virtual void paintEvent(QPaintEvent *e) = 0;
00132     virtual bool hitButton(const QPoint &pos) const;
00133     virtual void checkStateSet();
00134     virtual void nextCheckState();
00135 
00136     bool event(QEvent *e);
00137     void keyPressEvent(QKeyEvent *e);
00138     void keyReleaseEvent(QKeyEvent *e);
00139     void mousePressEvent(QMouseEvent *e);
00140     void mouseReleaseEvent(QMouseEvent *e);
00141     void mouseMoveEvent(QMouseEvent *e);
00142     void focusInEvent(QFocusEvent *e);
00143     void focusOutEvent(QFocusEvent *e);
00144     void changeEvent(QEvent *e);
00145     void timerEvent(QTimerEvent *e);
00146 
00147 #ifdef QT3_SUPPORT
00148 public:
00149     QT3_SUPPORT_CONSTRUCTOR QAbstractButton(QWidget *parent, const char *name, Qt::WindowFlags f=0);
00150     inline QT3_SUPPORT bool isOn() const { return isChecked(); }
00151     inline QT3_SUPPORT const QPixmap *pixmap() const { return 0; } // help styles compile
00152     inline QT3_SUPPORT void setPixmap( const QPixmap &p ) {
00153         setIcon(QIcon(p));
00154         setIconSize(p.size());
00155     }
00156     QT3_SUPPORT QIcon *iconSet() const;
00157     inline QT3_SUPPORT void setIconSet(const QIcon &icon) { setIcon(icon); }
00158     inline QT3_SUPPORT bool isToggleButton() const { return isCheckable(); }
00159     inline QT3_SUPPORT void setToggleButton(bool b) { setCheckable(b); }
00160     inline QT3_SUPPORT void setAccel(const QKeySequence &key) { setShortcut(key); }
00161     inline QT3_SUPPORT QKeySequence accel() const { return shortcut(); }
00162 
00163 public Q_SLOTS:
00164     inline QT_MOC_COMPAT void setOn(bool b) { setChecked(b); }
00165 #endif
00166 
00167 protected:
00168     QAbstractButton(QAbstractButtonPrivate &dd, QWidget* parent = 0);
00169 
00170 private:
00171     Q_DECLARE_PRIVATE(QAbstractButton)
00172     Q_DISABLE_COPY(QAbstractButton)
00173     friend class QButtonGroup;
00174 };
00175 
00176 QT_END_NAMESPACE
00177 
00178 QT_END_HEADER
00179 
00180 #endif // QABSTRACTBUTTON_H