1 | //Kevin Smith 2005
|
---|
2 |
|
---|
3 | /* This file is heavily based upon part of the KDE libraries
|
---|
4 | Copyright (C) 2003 Stephan Binner <binner@kde.org>
|
---|
5 | Copyright (C) 2003 Zack Rusin <zack@kde.org>
|
---|
6 | */
|
---|
7 |
|
---|
8 | #ifndef PSITABWIDGET_H
|
---|
9 | #define PSITABWIDGET_H
|
---|
10 |
|
---|
11 | #include <qtabwidget.h>
|
---|
12 | #include <qstringlist.h>
|
---|
13 |
|
---|
14 | class KTabWidgetPrivate;
|
---|
15 | class QIconSet;
|
---|
16 | /**
|
---|
17 | * \brief A widget containing multiple tabs
|
---|
18 | *
|
---|
19 | * @since 0.10
|
---|
20 | */
|
---|
21 | class KTabWidget : public QTabWidget
|
---|
22 | {
|
---|
23 | Q_OBJECT
|
---|
24 | Q_PROPERTY( bool tabReorderingEnabled READ isTabReorderingEnabled WRITE setTabReorderingEnabled )
|
---|
25 | Q_PROPERTY( bool hoverCloseButton READ hoverCloseButton WRITE setHoverCloseButton )
|
---|
26 | Q_PROPERTY( bool hoverCloseButtonDelayed READ hoverCloseButtonDelayed WRITE setHoverCloseButtonDelayed )
|
---|
27 | Q_PROPERTY( bool tabCloseActivatePrevious READ tabCloseActivatePrevious WRITE setTabCloseActivatePrevious )
|
---|
28 | Q_PROPERTY( bool automaticResizeTabs READ automaticResizeTabs WRITE setAutomaticResizeTabs )
|
---|
29 |
|
---|
30 | public:
|
---|
31 | KTabWidget( QWidget *parent = 0, const char *name = 0, WFlags f = 0 );
|
---|
32 | /**
|
---|
33 | * Destructor.
|
---|
34 | */
|
---|
35 | virtual ~KTabWidget();
|
---|
36 | /*!
|
---|
37 | Set the tab of the given widget to \a color.
|
---|
38 | */
|
---|
39 | void setTabColor( QWidget *, const QColor& color );
|
---|
40 | QColor tabColor( QWidget * ) const;
|
---|
41 |
|
---|
42 | /*!
|
---|
43 | Returns true if tab ordering with the middle mouse button
|
---|
44 | has been enabled.
|
---|
45 | */
|
---|
46 | bool isTabReorderingEnabled() const;
|
---|
47 |
|
---|
48 | /*!
|
---|
49 | Returns true if the close button is shown on tabs
|
---|
50 | when mouse is hovering over them.
|
---|
51 | */
|
---|
52 | bool hoverCloseButton() const;
|
---|
53 |
|
---|
54 | /*!
|
---|
55 | Returns true if the close button is shown on tabs
|
---|
56 | after a delay.
|
---|
57 | */
|
---|
58 | bool hoverCloseButtonDelayed() const;
|
---|
59 |
|
---|
60 | /*!
|
---|
61 | Returns true if closing the current tab activates the previous
|
---|
62 | actice tab instead of the one to the right.
|
---|
63 | @since 3.3
|
---|
64 | */
|
---|
65 | bool tabCloseActivatePrevious() const;
|
---|
66 |
|
---|
67 | /*!
|
---|
68 | Returns true if calling setTitle() will resize tabs
|
---|
69 | to the width of the tab bar.
|
---|
70 | @since 3.4
|
---|
71 | */
|
---|
72 | bool automaticResizeTabs() const;
|
---|
73 |
|
---|
74 | /*!
|
---|
75 | If \a hide is true, the tabbar is hidden along with any corner
|
---|
76 | widgets.
|
---|
77 | @since 3.4
|
---|
78 | */
|
---|
79 | void setTabBarHidden( bool hide );
|
---|
80 |
|
---|
81 | /*!
|
---|
82 | Return true if the tabbar is hidden.
|
---|
83 | @since 3.4
|
---|
84 | */
|
---|
85 | bool isTabBarHidden() const;
|
---|
86 |
|
---|
87 | /*!
|
---|
88 | Sets the close icon used on the tabbar
|
---|
89 | @since 0.10
|
---|
90 | */
|
---|
91 | void setCloseIcon(const QIconSet&);
|
---|
92 |
|
---|
93 | /*!
|
---|
94 | Reimplemented for internal reasons.
|
---|
95 | */
|
---|
96 | virtual void insertTab( QWidget *, const QString &, int index = -1 );
|
---|
97 |
|
---|
98 | /*!
|
---|
99 | Reimplemented for internal reasons.
|
---|
100 | */
|
---|
101 | virtual void insertTab( QWidget *child, const QIconSet& iconset,
|
---|
102 | const QString &label, int index = -1 );
|
---|
103 | /*!
|
---|
104 | Reimplemented for internal reasons.
|
---|
105 | */
|
---|
106 | virtual void insertTab( QWidget *, QTab *, int index = -1 );
|
---|
107 |
|
---|
108 | /*!
|
---|
109 | Reimplemented for internal reasons.
|
---|
110 | */
|
---|
111 | void changeTab( QWidget *, const QString & );
|
---|
112 |
|
---|
113 | /*!
|
---|
114 | Reimplemented for internal reasons.
|
---|
115 | */
|
---|
116 | void changeTab( QWidget *child, const QIconSet& iconset, const QString &label );
|
---|
117 |
|
---|
118 | /*!
|
---|
119 | Reimplemented for internal reasons.
|
---|
120 | */
|
---|
121 | QString label( int ) const;
|
---|
122 |
|
---|
123 | /*!
|
---|
124 | Reimplemented for internal reasons.
|
---|
125 | */
|
---|
126 | QString tabLabel( QWidget * ) const;
|
---|
127 |
|
---|
128 | /*!
|
---|
129 | Reimplemented for internal reasons.
|
---|
130 | */
|
---|
131 | void setTabLabel( QWidget *, const QString & );
|
---|
132 |
|
---|
133 | public slots:
|
---|
134 | /*!
|
---|
135 | Move a widget's tab from first to second specified index and emit
|
---|
136 | signal movedTab( int, int ) afterwards.
|
---|
137 | */
|
---|
138 | virtual void moveTab( int, int );
|
---|
139 |
|
---|
140 | /*!
|
---|
141 | Removes the widget, reimplemented for
|
---|
142 | internal reasons (keeping labels in sync).
|
---|
143 | */
|
---|
144 | virtual void removePage ( QWidget * w );
|
---|
145 |
|
---|
146 | /*!
|
---|
147 | If \a enable is true, tab reordering with middle button will be enabled.
|
---|
148 |
|
---|
149 | Note that once enabled you shouldn't rely on previously queried
|
---|
150 | currentPageIndex() or indexOf( QWidget * ) values anymore.
|
---|
151 |
|
---|
152 | You can connect to signal movedTab(int, int) which will notify
|
---|
153 | you from which index to which index a tab has been moved.
|
---|
154 | */
|
---|
155 | void setTabReorderingEnabled( bool enable );
|
---|
156 |
|
---|
157 | /*!
|
---|
158 | If \a enable is true, a close button will be shown on mouse hover
|
---|
159 | over tab icons which will emit signal closeRequest( QWidget * )
|
---|
160 | when pressed.
|
---|
161 | */
|
---|
162 | void setHoverCloseButton( bool enable );
|
---|
163 |
|
---|
164 | /*!
|
---|
165 | If \a delayed is true, a close button will be shown on mouse hover
|
---|
166 | over tab icons after mouse double click delay else immediately.
|
---|
167 | */
|
---|
168 | void setHoverCloseButtonDelayed( bool delayed );
|
---|
169 |
|
---|
170 | /*!
|
---|
171 | If \a delayed is true, closing the current tab activates the
|
---|
172 | previous active tab instead of the one to the right.
|
---|
173 | @since 3.3
|
---|
174 | */
|
---|
175 | void setTabCloseActivatePrevious( bool previous );
|
---|
176 |
|
---|
177 | /*!
|
---|
178 | If \a enable is true, tabs will be resized to the width of the tab bar.
|
---|
179 |
|
---|
180 | Does not work reliable with "QTabWidget* foo=new KTabWidget()" and if
|
---|
181 | you change tabs via the tabbar or by accessing tabs directly.
|
---|
182 | @since 3.4
|
---|
183 | */
|
---|
184 | void setAutomaticResizeTabs( bool enable );
|
---|
185 |
|
---|
186 | signals:
|
---|
187 | /*!
|
---|
188 | Connect to this and set accept to true if you can and want to decode the event.
|
---|
189 | */
|
---|
190 | void testCanDecode(const QDragMoveEvent *e, bool &accept /* result */);
|
---|
191 |
|
---|
192 | /*!
|
---|
193 | Received an event in the empty space beside tabbar. Usually creates a new tab.
|
---|
194 | This signal is only possible after testCanDecode and positive accept result.
|
---|
195 | */
|
---|
196 | void receivedDropEvent( QDropEvent * );
|
---|
197 |
|
---|
198 | /*!
|
---|
199 | Received an drop event on given widget's tab.
|
---|
200 | This signal is only possible after testCanDecode and positive accept result.
|
---|
201 | */
|
---|
202 | void receivedDropEvent( QWidget *, QDropEvent * );
|
---|
203 |
|
---|
204 | /*!
|
---|
205 | Request to start a drag operation on the given tab.
|
---|
206 | */
|
---|
207 | void initiateDrag( QWidget * );
|
---|
208 |
|
---|
209 | /*!
|
---|
210 | The right mouse button was pressed over empty space besides tabbar.
|
---|
211 | */
|
---|
212 | void contextMenu( const QPoint & );
|
---|
213 |
|
---|
214 | /*!
|
---|
215 | The right mouse button was pressed over a widget.
|
---|
216 | */
|
---|
217 | void contextMenu( QWidget *, const QPoint & );
|
---|
218 |
|
---|
219 | /*!
|
---|
220 | A tab was moved from first to second index. This signal is only
|
---|
221 | possible after you have called setTabReorderingEnabled( true ).
|
---|
222 | */
|
---|
223 | void movedTab( int, int );
|
---|
224 |
|
---|
225 | /*!
|
---|
226 | A double left mouse button click was performed over empty space besides tabbar.
|
---|
227 | @since 3.3
|
---|
228 | */
|
---|
229 | void mouseDoubleClick();
|
---|
230 |
|
---|
231 | /*!
|
---|
232 | A double left mouse button click was performed over the widget.
|
---|
233 | */
|
---|
234 | void mouseDoubleClick( QWidget * );
|
---|
235 |
|
---|
236 | /*!
|
---|
237 | A middle mouse button click was performed over empty space besides tabbar.
|
---|
238 | */
|
---|
239 | void mouseMiddleClick();
|
---|
240 |
|
---|
241 | /*!
|
---|
242 | A middle mouse button click was performed over the widget.
|
---|
243 | */
|
---|
244 | void mouseMiddleClick( QWidget * );
|
---|
245 |
|
---|
246 | /*!
|
---|
247 | The close button of a widget's tab was clicked. This signal is
|
---|
248 | only possible after you have called setHoverCloseButton( true ).
|
---|
249 | */
|
---|
250 | void closeRequest( QWidget * );
|
---|
251 |
|
---|
252 | protected:
|
---|
253 | virtual void mouseDoubleClickEvent( QMouseEvent *e );
|
---|
254 | virtual void mousePressEvent( QMouseEvent * );
|
---|
255 | virtual void dragMoveEvent( QDragMoveEvent * );
|
---|
256 | virtual void dropEvent( QDropEvent * );
|
---|
257 | unsigned int tabBarWidthForMaxChars( uint maxLength );
|
---|
258 | #ifndef QT_NO_WHEELEVENT
|
---|
259 | virtual void wheelEvent( QWheelEvent *e );
|
---|
260 | #endif
|
---|
261 | virtual void resizeEvent( QResizeEvent * );
|
---|
262 |
|
---|
263 | protected slots:
|
---|
264 | virtual void receivedDropEvent( int, QDropEvent * );
|
---|
265 | virtual void initiateDrag( int );
|
---|
266 | virtual void contextMenu( int, const QPoint & );
|
---|
267 | virtual void mouseDoubleClick( int );
|
---|
268 | virtual void mouseMiddleClick( int );
|
---|
269 | virtual void closeRequest( int );
|
---|
270 | #ifndef QT_NO_WHEELEVENT
|
---|
271 | virtual void wheelDelta( int );
|
---|
272 | #endif
|
---|
273 |
|
---|
274 | private:
|
---|
275 | bool isEmptyTabbarSpace( const QPoint & ) const;
|
---|
276 | void resizeTabs( int changedTabIndex = -1 );
|
---|
277 | void updateTab( int index );
|
---|
278 | KTabWidgetPrivate *d;
|
---|
279 | };
|
---|
280 |
|
---|
281 | #endif
|
---|