1 /****************************************************************************
2 ** $Id: qt/qtoolbutton.h   3.3.8   edited Jan 11 14:39 $
3 **
4 ** Definition of QToolButton class
5 **
6 ** Created : 979899
7 **
8 ** Copyright (C) 1992-2007 Trolltech ASA.  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 ASA 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 QTOOLBUTTON_H
39 #define QTOOLBUTTON_H
40 
41 #ifndef QT_H
42 #include "qbutton.h"
43 #include "qstring.h"
44 #include "qpixmap.h"
45 #include "qiconset.h"
46 #endif // QT_H
47 
48 #ifndef QT_NO_TOOLBUTTON
49 
50 class QToolButtonPrivate;
51 class QToolBar;
52 class QPopupMenu;
53 
54 class Q_EXPORT QToolButton : public QButton
55 {
56     Q_OBJECT
57     Q_ENUMS( TextPosition )
58 
59     Q_PROPERTY( QIconSet iconSet READ iconSet WRITE setIconSet )
60     Q_PROPERTY( QIconSet onIconSet READ onIconSet WRITE setOnIconSet DESIGNABLE false STORED false )
61     Q_PROPERTY( QIconSet offIconSet READ offIconSet WRITE setOffIconSet DESIGNABLE false STORED false )
62     Q_PROPERTY( bool usesBigPixmap READ usesBigPixmap WRITE setUsesBigPixmap )
63     Q_PROPERTY( bool usesTextLabel READ usesTextLabel WRITE setUsesTextLabel )
64     Q_PROPERTY( QString textLabel READ textLabel WRITE setTextLabel )
65     Q_PROPERTY( int popupDelay READ popupDelay WRITE setPopupDelay )
66     Q_PROPERTY( bool autoRaise READ autoRaise WRITE setAutoRaise )
67     Q_PROPERTY( TextPosition textPosition READ textPosition WRITE setTextPosition )
68 
69     Q_OVERRIDE( bool toggleButton WRITE setToggleButton )
70     Q_OVERRIDE( bool on WRITE setOn )
71     Q_OVERRIDE( QPixmap pixmap DESIGNABLE false STORED false )
72     Q_OVERRIDE( BackgroundMode backgroundMode DESIGNABLE true)
73 
74 public:
75     enum TextPosition {
76 	BesideIcon,
77 	BelowIcon,
78 	Right = BesideIcon, // obsolete
79 	Under = BelowIcon // obsolete
80     };
81     QToolButton( QWidget * parent, const char* name=0 );
82 #ifndef QT_NO_TOOLBAR
83     QToolButton( const QIconSet& s, const QString &textLabel,
84 		 const QString& grouptext,
85 		 QObject * receiver, const char* slot,
86 		 QToolBar * parent, const char* name=0 );
87 #endif
88     QToolButton( ArrowType type, QWidget *parent, const char* name=0 );
89     ~QToolButton();
90 
91     QSize sizeHint() const;
92     QSize minimumSizeHint() const;
93 
94 #ifndef QT_NO_COMPAT
95     void setOnIconSet( const QIconSet& );
96     void setOffIconSet( const QIconSet& );
97     void setIconSet( const QIconSet &, bool on );
98     QIconSet onIconSet() const;
99     QIconSet offIconSet( ) const;
100     QIconSet iconSet( bool on ) const;
101 #endif
102     virtual void setIconSet( const QIconSet & );
103     QIconSet iconSet() const;
104 
usesBigPixmap()105     bool usesBigPixmap() const { return ubp; }
usesTextLabel()106     bool usesTextLabel() const { return utl; }
textLabel()107     QString textLabel() const { return tl; }
108 
109 #ifndef QT_NO_POPUPMENU
110     void setPopup( QPopupMenu* popup );
111     QPopupMenu* popup() const;
112 
113     void setPopupDelay( int delay );
114     int popupDelay() const;
115 
116     void openPopup();
117 #endif
118 
119     void setAutoRaise( bool enable );
120     bool autoRaise() const;
121     TextPosition textPosition() const;
122 
123     void setText( const QString &txt );
124 
125 public slots:
126     virtual void setUsesBigPixmap( bool enable );
127     virtual void setUsesTextLabel( bool enable );
128     virtual void setTextLabel( const QString &, bool );
129 
130     virtual void setToggleButton( bool enable );
131 
132     virtual void setOn( bool enable );
133     void toggle();
134     void setTextLabel( const QString & );
135     void setTextPosition( TextPosition pos );
136 
137 protected:
138     void mousePressEvent( QMouseEvent * );
139     void drawButton( QPainter * );
140     void drawButtonLabel(QPainter *);
141 
142     void enterEvent( QEvent * );
143     void leaveEvent( QEvent * );
144     void moveEvent( QMoveEvent * );
145 
146     // ### Make virtual in 4.0, maybe act like QPushButton with
147     // regards to setFlat() instead?  Andy
148     bool uses3D() const;
149 #if (QT_VERSION >= 0x040000)
150 #error "Some functions need to be changed to virtual for Qt 4.0"
151 #endif
152 
153     bool eventFilter( QObject *o, QEvent *e );
154 
155 #ifndef QT_NO_PALETTE
156     void paletteChange( const QPalette & );
157 #endif
158 
159 private slots:
160     void popupTimerDone();
161     void popupPressed();
162 
163 private:
164     void init();
165 
166     QPixmap bp;
167     int bpID;
168     QPixmap sp;
169     int spID;
170 
171     QString tl;
172 
173     QToolButtonPrivate *d;
174     QIconSet *s;
175 
176     uint utl : 1;
177     uint ubp : 1;
178     uint hasArrow : 1;
179 
180 private:	// Disabled copy constructor and operator=
181 #if defined(Q_DISABLE_COPY)
182     QToolButton( const QToolButton & );
183     QToolButton& operator=( const QToolButton & );
184 #endif
185 };
186 
187 #endif // QT_NO_TOOLBUTTON
188 
189 #endif // QTOOLBUTTON_H
190