| 1 | /**************************************************************************** | 
|---|
| 2 | ** $Id: qbutton.h 2 2005-11-16 15:49:26Z dmik $ | 
|---|
| 3 | ** | 
|---|
| 4 | ** Definition of QButton widget class | 
|---|
| 5 | ** | 
|---|
| 6 | ** Created : 940206 | 
|---|
| 7 | ** | 
|---|
| 8 | ** Copyright (C) 1992-2000 Trolltech AS.  All rights reserved. | 
|---|
| 9 | ** | 
|---|
| 10 | ** This file is part of the widgets module of the Qt GUI Toolkit. | 
|---|
| 11 | ** | 
|---|
| 12 | ** This file may be distributed under the terms of the Q Public License | 
|---|
| 13 | ** as defined by Trolltech AS of Norway and appearing in the file | 
|---|
| 14 | ** LICENSE.QPL included in the packaging of this file. | 
|---|
| 15 | ** | 
|---|
| 16 | ** This file may be distributed and/or modified under the terms of the | 
|---|
| 17 | ** GNU General Public License version 2 as published by the Free Software | 
|---|
| 18 | ** Foundation and appearing in the file LICENSE.GPL included in the | 
|---|
| 19 | ** packaging of this file. | 
|---|
| 20 | ** | 
|---|
| 21 | ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition | 
|---|
| 22 | ** licenses may use this file in accordance with the Qt Commercial License | 
|---|
| 23 | ** Agreement provided with the Software. | 
|---|
| 24 | ** | 
|---|
| 25 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 
|---|
| 26 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 
|---|
| 27 | ** | 
|---|
| 28 | ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for | 
|---|
| 29 | **   information about Qt Commercial License Agreements. | 
|---|
| 30 | ** See http://www.trolltech.com/qpl/ for QPL licensing information. | 
|---|
| 31 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 
|---|
| 32 | ** | 
|---|
| 33 | ** Contact info@trolltech.com if any conditions of this licensing are | 
|---|
| 34 | ** not clear to you. | 
|---|
| 35 | ** | 
|---|
| 36 | **********************************************************************/ | 
|---|
| 37 |  | 
|---|
| 38 | #ifndef QBUTTON_H | 
|---|
| 39 | #define QBUTTON_H | 
|---|
| 40 |  | 
|---|
| 41 | #ifndef QT_H | 
|---|
| 42 | #include "qwidget.h" | 
|---|
| 43 | #include "qkeysequence.h" | 
|---|
| 44 | #endif // QT_H | 
|---|
| 45 |  | 
|---|
| 46 | #ifndef QT_NO_BUTTON | 
|---|
| 47 |  | 
|---|
| 48 |  | 
|---|
| 49 | class QButtonGroup; | 
|---|
| 50 | class QToolBar; | 
|---|
| 51 | class QButtonData; | 
|---|
| 52 |  | 
|---|
| 53 | class Q_EXPORT QButton : public QWidget | 
|---|
| 54 | { | 
|---|
| 55 | Q_OBJECT | 
|---|
| 56 | Q_ENUMS( ToggleType ToggleState ) | 
|---|
| 57 | Q_PROPERTY( QString text READ text WRITE setText ) | 
|---|
| 58 | Q_PROPERTY( QPixmap pixmap READ pixmap WRITE setPixmap ) | 
|---|
| 59 | Q_PROPERTY( QKeySequence accel READ accel WRITE setAccel ) | 
|---|
| 60 | Q_PROPERTY( bool toggleButton READ isToggleButton ) | 
|---|
| 61 | Q_PROPERTY( ToggleType toggleType READ toggleType ) | 
|---|
| 62 | Q_PROPERTY( bool down READ isDown WRITE setDown DESIGNABLE false  ) | 
|---|
| 63 | Q_PROPERTY( bool on READ isOn ) | 
|---|
| 64 | Q_PROPERTY( ToggleState toggleState READ state ) | 
|---|
| 65 | Q_PROPERTY( bool autoResize READ autoResize WRITE setAutoResize DESIGNABLE false ) | 
|---|
| 66 | Q_PROPERTY( bool autoRepeat READ autoRepeat WRITE setAutoRepeat ) | 
|---|
| 67 | Q_PROPERTY( bool exclusiveToggle READ isExclusiveToggle ) | 
|---|
| 68 |  | 
|---|
| 69 | public: | 
|---|
| 70 | QButton( QWidget* parent=0, const char* name=0, WFlags f=0 ); | 
|---|
| 71 | ~QButton(); | 
|---|
| 72 |  | 
|---|
| 73 | QString text() const; | 
|---|
| 74 | virtual void setText( const QString &); | 
|---|
| 75 | const QPixmap *pixmap() const; | 
|---|
| 76 | virtual void setPixmap( const QPixmap & ); | 
|---|
| 77 |  | 
|---|
| 78 | #ifndef QT_NO_ACCEL | 
|---|
| 79 | QKeySequence                accel() const; | 
|---|
| 80 | virtual void        setAccel( const QKeySequence& ); | 
|---|
| 81 | #endif | 
|---|
| 82 |  | 
|---|
| 83 | bool        isToggleButton() const; | 
|---|
| 84 |  | 
|---|
| 85 | enum ToggleType { SingleShot, Toggle, Tristate }; | 
|---|
| 86 | ToggleType  toggleType() const; | 
|---|
| 87 |  | 
|---|
| 88 | virtual void setDown( bool ); | 
|---|
| 89 | bool        isDown() const; | 
|---|
| 90 |  | 
|---|
| 91 | bool        isOn() const; | 
|---|
| 92 |  | 
|---|
| 93 | enum ToggleState { Off, NoChange, On }; | 
|---|
| 94 | ToggleState state() const; | 
|---|
| 95 |  | 
|---|
| 96 | #ifndef QT_NO_COMPAT | 
|---|
| 97 | bool        autoResize() const; | 
|---|
| 98 | void        setAutoResize( bool ); | 
|---|
| 99 | #endif | 
|---|
| 100 |  | 
|---|
| 101 | bool        autoRepeat() const; | 
|---|
| 102 | virtual void setAutoRepeat( bool ); | 
|---|
| 103 | bool        isExclusiveToggle() const; | 
|---|
| 104 |  | 
|---|
| 105 | QButtonGroup *group() const; | 
|---|
| 106 |  | 
|---|
| 107 | public slots: | 
|---|
| 108 | void        animateClick(); | 
|---|
| 109 | void        toggle(); | 
|---|
| 110 |  | 
|---|
| 111 | signals: | 
|---|
| 112 | void        pressed(); | 
|---|
| 113 | void        released(); | 
|---|
| 114 | void        clicked(); | 
|---|
| 115 | void        toggled( bool ); | 
|---|
| 116 | void        stateChanged( int ); | 
|---|
| 117 |  | 
|---|
| 118 | protected: | 
|---|
| 119 | void        setToggleButton( bool ); | 
|---|
| 120 | virtual void        setToggleType( ToggleType ); | 
|---|
| 121 | void        setOn( bool ); | 
|---|
| 122 | virtual void        setState( ToggleState ); | 
|---|
| 123 |  | 
|---|
| 124 | virtual bool hitButton( const QPoint &pos ) const; | 
|---|
| 125 | virtual void drawButton( QPainter * ); | 
|---|
| 126 | virtual void drawButtonLabel( QPainter * ); | 
|---|
| 127 |  | 
|---|
| 128 | void        keyPressEvent( QKeyEvent *); | 
|---|
| 129 | void        keyReleaseEvent( QKeyEvent *); | 
|---|
| 130 | void        mousePressEvent( QMouseEvent * ); | 
|---|
| 131 | void        mouseReleaseEvent( QMouseEvent * ); | 
|---|
| 132 | void        mouseMoveEvent( QMouseEvent * ); | 
|---|
| 133 | void        paintEvent( QPaintEvent * ); | 
|---|
| 134 | void        focusInEvent( QFocusEvent * ); | 
|---|
| 135 | void        focusOutEvent( QFocusEvent * ); | 
|---|
| 136 |  | 
|---|
| 137 | void        enabledChange( bool ); | 
|---|
| 138 |  | 
|---|
| 139 | private slots: | 
|---|
| 140 | void        animateTimeout(); | 
|---|
| 141 | void        autoRepeatTimeout(); | 
|---|
| 142 | void        emulateClick(); | 
|---|
| 143 |  | 
|---|
| 144 | private: | 
|---|
| 145 | QString     btext; | 
|---|
| 146 | QPixmap    *bpixmap; | 
|---|
| 147 | uint        toggleTyp       : 2; | 
|---|
| 148 | uint        buttonDown      : 1; | 
|---|
| 149 | uint        stat            : 2; | 
|---|
| 150 | uint        mlbDown         : 1; | 
|---|
| 151 | uint        autoresize      : 1; | 
|---|
| 152 | uint        animation       : 1; | 
|---|
| 153 | uint        repeat          : 1; | 
|---|
| 154 | QButtonData *d; | 
|---|
| 155 |  | 
|---|
| 156 | friend class QButtonGroup; | 
|---|
| 157 | friend class QToolBar; | 
|---|
| 158 | void          ensureData(); | 
|---|
| 159 | virtual void setGroup( QButtonGroup* ); | 
|---|
| 160 | QTimer       *timer(); | 
|---|
| 161 | void        nextState(); | 
|---|
| 162 |  | 
|---|
| 163 | private:        // Disabled copy constructor and operator= | 
|---|
| 164 | #if defined(Q_DISABLE_COPY) | 
|---|
| 165 | QButton( const QButton & ); | 
|---|
| 166 | QButton &operator=( const QButton & ); | 
|---|
| 167 | #endif | 
|---|
| 168 | }; | 
|---|
| 169 |  | 
|---|
| 170 |  | 
|---|
| 171 | inline QString QButton::text() const | 
|---|
| 172 | { | 
|---|
| 173 | return btext; | 
|---|
| 174 | } | 
|---|
| 175 |  | 
|---|
| 176 | inline const QPixmap *QButton::pixmap() const | 
|---|
| 177 | { | 
|---|
| 178 | return bpixmap; | 
|---|
| 179 | } | 
|---|
| 180 |  | 
|---|
| 181 | inline bool QButton::isToggleButton() const | 
|---|
| 182 | { | 
|---|
| 183 | return toggleTyp != SingleShot; | 
|---|
| 184 | } | 
|---|
| 185 |  | 
|---|
| 186 | inline  bool QButton::isDown() const | 
|---|
| 187 | { | 
|---|
| 188 | return buttonDown; | 
|---|
| 189 | } | 
|---|
| 190 |  | 
|---|
| 191 | inline bool QButton::isOn() const | 
|---|
| 192 | { | 
|---|
| 193 | return stat != Off; | 
|---|
| 194 | } | 
|---|
| 195 |  | 
|---|
| 196 | #ifndef QT_NO_COMPAT | 
|---|
| 197 | inline bool QButton::autoResize() const | 
|---|
| 198 | { | 
|---|
| 199 | return autoresize; | 
|---|
| 200 | } | 
|---|
| 201 | #endif | 
|---|
| 202 |  | 
|---|
| 203 | inline bool QButton::autoRepeat() const | 
|---|
| 204 | { | 
|---|
| 205 | return repeat; | 
|---|
| 206 | } | 
|---|
| 207 |  | 
|---|
| 208 | inline QButton::ToggleState QButton::state() const | 
|---|
| 209 | { | 
|---|
| 210 | return ToggleState(stat); | 
|---|
| 211 | } | 
|---|
| 212 |  | 
|---|
| 213 | inline void QButton::setToggleButton( bool b ) | 
|---|
| 214 | { | 
|---|
| 215 | setToggleType( b ? Toggle : SingleShot ); | 
|---|
| 216 | } | 
|---|
| 217 |  | 
|---|
| 218 | inline void QButton::setOn( bool y ) | 
|---|
| 219 | { | 
|---|
| 220 | setState( y ? On : Off ); | 
|---|
| 221 | } | 
|---|
| 222 |  | 
|---|
| 223 | inline QButton::ToggleType QButton::toggleType() const | 
|---|
| 224 | { | 
|---|
| 225 | return ToggleType(toggleTyp); | 
|---|
| 226 | } | 
|---|
| 227 |  | 
|---|
| 228 |  | 
|---|
| 229 | #endif // QT_NO_BUTTON | 
|---|
| 230 |  | 
|---|
| 231 | #endif // QBUTTON_H | 
|---|