1 | /****************************************************************************
|
---|
2 | ** $Id: qlayout.h 2 2005-11-16 15:49:26Z dmik $
|
---|
3 | **
|
---|
4 | ** Definition of layout classes
|
---|
5 | **
|
---|
6 | ** Created : 960416
|
---|
7 | **
|
---|
8 | ** Copyright (C) 1992-2002 Trolltech AS. All rights reserved.
|
---|
9 | **
|
---|
10 | ** This file is part of the kernel 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 QLAYOUT_H
|
---|
39 | #define QLAYOUT_H
|
---|
40 |
|
---|
41 | #ifndef QT_H
|
---|
42 | #include "qobject.h"
|
---|
43 | #include "qsizepolicy.h"
|
---|
44 | #include "qwidget.h"
|
---|
45 | #endif // QT_H
|
---|
46 |
|
---|
47 | #include <limits.h>
|
---|
48 |
|
---|
49 | #ifndef QT_NO_LAYOUT
|
---|
50 |
|
---|
51 | #if 0
|
---|
52 | Q_OBJECT
|
---|
53 | #endif
|
---|
54 |
|
---|
55 | static const int QLAYOUTSIZE_MAX = INT_MAX/256/16;
|
---|
56 |
|
---|
57 | class QGridLayoutBox;
|
---|
58 | class QGridLayoutData;
|
---|
59 | class QLayout;
|
---|
60 | class QLayoutItem;
|
---|
61 | struct QLayoutData;
|
---|
62 | class QMenuBar;
|
---|
63 | class QSpacerItem;
|
---|
64 | class QWidget;
|
---|
65 |
|
---|
66 | class Q_EXPORT QGLayoutIterator : public QShared
|
---|
67 | {
|
---|
68 | public:
|
---|
69 | virtual ~QGLayoutIterator();
|
---|
70 | virtual QLayoutItem *next() = 0;
|
---|
71 | virtual QLayoutItem *current() = 0;
|
---|
72 | virtual QLayoutItem *takeCurrent() = 0;
|
---|
73 | };
|
---|
74 |
|
---|
75 | class Q_EXPORT QLayoutIterator
|
---|
76 | {
|
---|
77 | public:
|
---|
78 | QLayoutIterator( QGLayoutIterator *i ) : it( i ) { }
|
---|
79 | QLayoutIterator( const QLayoutIterator &i ) : it( i.it ) {
|
---|
80 | if ( it )
|
---|
81 | it->ref();
|
---|
82 | }
|
---|
83 | ~QLayoutIterator() { if ( it && it->deref() ) delete it; }
|
---|
84 | QLayoutIterator &operator=( const QLayoutIterator &i ) {
|
---|
85 | if ( i.it )
|
---|
86 | i.it->ref();
|
---|
87 | if ( it && it->deref() )
|
---|
88 | delete it;
|
---|
89 | it = i.it;
|
---|
90 | return *this;
|
---|
91 | }
|
---|
92 | QLayoutItem *operator++() { return it ? it->next() : 0; }
|
---|
93 | QLayoutItem *current() { return it ? it->current() : 0; }
|
---|
94 | QLayoutItem *takeCurrent() { return it ? it->takeCurrent() : 0; }
|
---|
95 | void deleteCurrent();
|
---|
96 |
|
---|
97 | private:
|
---|
98 | QGLayoutIterator *it;
|
---|
99 | };
|
---|
100 |
|
---|
101 | class Q_EXPORT QLayoutItem
|
---|
102 | {
|
---|
103 | public:
|
---|
104 | QLayoutItem( int alignment = 0 ) : align( alignment ) { }
|
---|
105 | virtual ~QLayoutItem();
|
---|
106 | virtual QSize sizeHint() const = 0;
|
---|
107 | virtual QSize minimumSize() const = 0;
|
---|
108 | virtual QSize maximumSize() const = 0;
|
---|
109 | virtual QSizePolicy::ExpandData expanding() const = 0;
|
---|
110 | virtual void setGeometry( const QRect& ) = 0;
|
---|
111 | virtual QRect geometry() const = 0;
|
---|
112 | virtual bool isEmpty() const = 0;
|
---|
113 | virtual bool hasHeightForWidth() const;
|
---|
114 | virtual int heightForWidth( int ) const;
|
---|
115 | // ### add minimumHeightForWidth( int ) in Qt 4.0
|
---|
116 | virtual void invalidate();
|
---|
117 |
|
---|
118 | virtual QWidget *widget();
|
---|
119 | virtual QLayoutIterator iterator();
|
---|
120 | virtual QLayout *layout();
|
---|
121 | virtual QSpacerItem *spacerItem();
|
---|
122 |
|
---|
123 | int alignment() const { return align; }
|
---|
124 | virtual void setAlignment( int a );
|
---|
125 |
|
---|
126 | protected:
|
---|
127 | int align;
|
---|
128 | };
|
---|
129 |
|
---|
130 | class Q_EXPORT QSpacerItem : public QLayoutItem
|
---|
131 | {
|
---|
132 | public:
|
---|
133 | QSpacerItem( int w, int h,
|
---|
134 | QSizePolicy::SizeType hData = QSizePolicy::Minimum,
|
---|
135 | QSizePolicy::SizeType vData = QSizePolicy::Minimum )
|
---|
136 | : width( w ), height( h ), sizeP( hData, vData ) { }
|
---|
137 | void changeSize( int w, int h,
|
---|
138 | QSizePolicy::SizeType hData = QSizePolicy::Minimum,
|
---|
139 | QSizePolicy::SizeType vData = QSizePolicy::Minimum );
|
---|
140 | QSize sizeHint() const;
|
---|
141 | QSize minimumSize() const;
|
---|
142 | QSize maximumSize() const;
|
---|
143 | QSizePolicy::ExpandData expanding() const;
|
---|
144 | bool isEmpty() const;
|
---|
145 | void setGeometry( const QRect& );
|
---|
146 | QRect geometry() const;
|
---|
147 | QSpacerItem *spacerItem();
|
---|
148 |
|
---|
149 | private:
|
---|
150 | int width;
|
---|
151 | int height;
|
---|
152 | QSizePolicy sizeP;
|
---|
153 | QRect rect;
|
---|
154 | };
|
---|
155 |
|
---|
156 | class Q_EXPORT QWidgetItem : public QLayoutItem
|
---|
157 | {
|
---|
158 | public:
|
---|
159 | QWidgetItem( QWidget *w ) : wid( w ) { }
|
---|
160 | QSize sizeHint() const;
|
---|
161 | QSize minimumSize() const;
|
---|
162 | QSize maximumSize() const;
|
---|
163 | QSizePolicy::ExpandData expanding() const;
|
---|
164 | bool isEmpty() const;
|
---|
165 | void setGeometry( const QRect& );
|
---|
166 | QRect geometry() const;
|
---|
167 | virtual QWidget *widget();
|
---|
168 |
|
---|
169 | bool hasHeightForWidth() const;
|
---|
170 | int heightForWidth( int ) const;
|
---|
171 |
|
---|
172 | private:
|
---|
173 | QWidget *wid;
|
---|
174 | };
|
---|
175 |
|
---|
176 | class Q_EXPORT QLayout : public QObject, public QLayoutItem
|
---|
177 | {
|
---|
178 | Q_OBJECT
|
---|
179 | Q_ENUMS( ResizeMode )
|
---|
180 | Q_PROPERTY( int margin READ margin WRITE setMargin )
|
---|
181 | Q_PROPERTY( int spacing READ spacing WRITE setSpacing )
|
---|
182 | Q_PROPERTY( ResizeMode resizeMode READ resizeMode WRITE setResizeMode )
|
---|
183 |
|
---|
184 | public:
|
---|
185 | // ### Qt 4.0: put 'Auto' first in enum
|
---|
186 | enum ResizeMode { FreeResize, Minimum, Fixed, Auto };
|
---|
187 |
|
---|
188 | QLayout( QWidget *parent, int margin = 0, int spacing = -1,
|
---|
189 | const char *name = 0 );
|
---|
190 | QLayout( QLayout *parentLayout, int spacing = -1, const char *name = 0 );
|
---|
191 | QLayout( int spacing = -1, const char *name = 0 );
|
---|
192 | ~QLayout();
|
---|
193 |
|
---|
194 | int margin() const { return outsideBorder; }
|
---|
195 | int spacing() const { return insideSpacing; }
|
---|
196 |
|
---|
197 | virtual void setMargin( int );
|
---|
198 | virtual void setSpacing( int );
|
---|
199 |
|
---|
200 | int defaultBorder() const { return insideSpacing; }
|
---|
201 | void freeze( int w, int h );
|
---|
202 | void freeze() { setResizeMode( Fixed ); }
|
---|
203 |
|
---|
204 | void setResizeMode( ResizeMode );
|
---|
205 | ResizeMode resizeMode() const;
|
---|
206 |
|
---|
207 | #ifndef QT_NO_MENUBAR
|
---|
208 | virtual void setMenuBar( QMenuBar *w );
|
---|
209 | QMenuBar *menuBar() const { return menubar; }
|
---|
210 | #endif
|
---|
211 |
|
---|
212 | QWidget *mainWidget();
|
---|
213 | bool isTopLevel() const { return topLevel; }
|
---|
214 |
|
---|
215 | virtual void setAutoAdd( bool );
|
---|
216 | bool autoAdd() const { return autoNewChild; }
|
---|
217 |
|
---|
218 | void invalidate();
|
---|
219 | QRect geometry() const;
|
---|
220 | bool activate();
|
---|
221 |
|
---|
222 | void add( QWidget *w ) { addItem( new QWidgetItem(w) ); }
|
---|
223 | virtual void addItem( QLayoutItem * ) = 0;
|
---|
224 |
|
---|
225 | void remove( QWidget *w );
|
---|
226 | void removeItem( QLayoutItem * );
|
---|
227 |
|
---|
228 | QSizePolicy::ExpandData expanding() const;
|
---|
229 | QSize minimumSize() const;
|
---|
230 | QSize maximumSize() const;
|
---|
231 | void setGeometry( const QRect& ) = 0;
|
---|
232 | QLayoutIterator iterator() = 0;
|
---|
233 | bool isEmpty() const;
|
---|
234 |
|
---|
235 | int totalHeightForWidth( int w ) const;
|
---|
236 | QSize totalMinimumSize() const;
|
---|
237 | QSize totalMaximumSize() const;
|
---|
238 | QSize totalSizeHint() const;
|
---|
239 | QLayout *layout();
|
---|
240 |
|
---|
241 | bool supportsMargin() const { return marginImpl; }
|
---|
242 |
|
---|
243 | void setEnabled( bool );
|
---|
244 | bool isEnabled() const;
|
---|
245 |
|
---|
246 | protected:
|
---|
247 | bool eventFilter( QObject *, QEvent * );
|
---|
248 | void childEvent( QChildEvent *e );
|
---|
249 | void addChildLayout( QLayout *l );
|
---|
250 | void deleteAllItems();
|
---|
251 |
|
---|
252 | void setSupportsMargin( bool );
|
---|
253 | QRect alignmentRect( const QRect& ) const;
|
---|
254 |
|
---|
255 | private:
|
---|
256 | void setWidgetLayout( QWidget *, QLayout * );
|
---|
257 | void init();
|
---|
258 | int insideSpacing;
|
---|
259 | int outsideBorder;
|
---|
260 | uint topLevel : 1;
|
---|
261 | uint enabled : 1;
|
---|
262 | uint autoNewChild : 1;
|
---|
263 | uint frozen : 1;
|
---|
264 | uint activated : 1;
|
---|
265 | uint marginImpl : 1;
|
---|
266 | uint autoMinimum : 1;
|
---|
267 | uint autoResizeMode : 1;
|
---|
268 | QRect rect;
|
---|
269 | QLayoutData *extraData;
|
---|
270 | #ifndef QT_NO_MENUBAR
|
---|
271 | QMenuBar *menubar;
|
---|
272 | #endif
|
---|
273 |
|
---|
274 | private:
|
---|
275 | #if defined(Q_DISABLE_COPY)
|
---|
276 | QLayout( const QLayout & );
|
---|
277 | QLayout &operator=( const QLayout & );
|
---|
278 | #endif
|
---|
279 |
|
---|
280 | static void propagateSpacing( QLayout *layout );
|
---|
281 | };
|
---|
282 |
|
---|
283 | inline void QLayoutIterator::deleteCurrent()
|
---|
284 | {
|
---|
285 | delete takeCurrent();
|
---|
286 | }
|
---|
287 |
|
---|
288 | class Q_EXPORT QGridLayout : public QLayout
|
---|
289 | {
|
---|
290 | Q_OBJECT
|
---|
291 | public:
|
---|
292 | QGridLayout( QWidget *parent, int nRows = 1, int nCols = 1, int border = 0,
|
---|
293 | int spacing = -1, const char *name = 0 );
|
---|
294 | QGridLayout( int nRows = 1, int nCols = 1, int spacing = -1,
|
---|
295 | const char *name = 0 );
|
---|
296 | QGridLayout( QLayout *parentLayout, int nRows = 1, int nCols = 1,
|
---|
297 | int spacing = -1, const char *name = 0 );
|
---|
298 | ~QGridLayout();
|
---|
299 |
|
---|
300 | QSize sizeHint() const;
|
---|
301 | QSize minimumSize() const;
|
---|
302 | QSize maximumSize() const;
|
---|
303 |
|
---|
304 | // ### remove 'virtual' in 4.0 (or add 'virtual' to set{Row,Col}Spacing())
|
---|
305 | virtual void setRowStretch( int row, int stretch );
|
---|
306 | virtual void setColStretch( int col, int stretch );
|
---|
307 | int rowStretch( int row ) const;
|
---|
308 | int colStretch( int col ) const;
|
---|
309 |
|
---|
310 | void setRowSpacing( int row, int minSize );
|
---|
311 | void setColSpacing( int col, int minSize );
|
---|
312 | int rowSpacing( int row ) const;
|
---|
313 | int colSpacing( int col ) const;
|
---|
314 |
|
---|
315 | int numRows() const;
|
---|
316 | int numCols() const;
|
---|
317 | QRect cellGeometry( int row, int col ) const;
|
---|
318 |
|
---|
319 | bool hasHeightForWidth() const;
|
---|
320 | int heightForWidth( int ) const;
|
---|
321 | int minimumHeightForWidth( int ) const;
|
---|
322 |
|
---|
323 | QSizePolicy::ExpandData expanding() const;
|
---|
324 | void invalidate();
|
---|
325 |
|
---|
326 | void addItem( QLayoutItem * );
|
---|
327 | void addItem( QLayoutItem *item, int row, int col );
|
---|
328 | void addMultiCell( QLayoutItem *, int fromRow, int toRow,
|
---|
329 | int fromCol, int toCol, int align = 0 );
|
---|
330 |
|
---|
331 | void addWidget( QWidget *, int row, int col, int align = 0 );
|
---|
332 | void addMultiCellWidget( QWidget *, int fromRow, int toRow,
|
---|
333 | int fromCol, int toCol, int align = 0 );
|
---|
334 | void addLayout( QLayout *layout, int row, int col);
|
---|
335 | void addMultiCellLayout( QLayout *layout, int fromRow, int toRow,
|
---|
336 | int fromCol, int toCol, int align = 0 );
|
---|
337 | void addRowSpacing( int row, int minsize );
|
---|
338 | void addColSpacing( int col, int minsize );
|
---|
339 |
|
---|
340 | void expand( int rows, int cols );
|
---|
341 |
|
---|
342 | enum Corner { TopLeft, TopRight, BottomLeft, BottomRight };
|
---|
343 | void setOrigin( Corner );
|
---|
344 | Corner origin() const;
|
---|
345 | QLayoutIterator iterator();
|
---|
346 | void setGeometry( const QRect& );
|
---|
347 |
|
---|
348 | protected:
|
---|
349 | bool findWidget( QWidget* w, int *r, int *c );
|
---|
350 | void add( QLayoutItem*, int row, int col );
|
---|
351 |
|
---|
352 | private:
|
---|
353 | #if defined(Q_DISABLE_COPY)
|
---|
354 | QGridLayout( const QGridLayout & );
|
---|
355 | QGridLayout &operator=( const QGridLayout & );
|
---|
356 | #endif
|
---|
357 |
|
---|
358 | void init( int rows, int cols );
|
---|
359 | QGridLayoutData *data;
|
---|
360 | };
|
---|
361 |
|
---|
362 | class QBoxLayoutData;
|
---|
363 | class QDockWindow;
|
---|
364 |
|
---|
365 | class Q_EXPORT QBoxLayout : public QLayout
|
---|
366 | {
|
---|
367 | Q_OBJECT
|
---|
368 | public:
|
---|
369 | enum Direction { LeftToRight, RightToLeft, TopToBottom, BottomToTop,
|
---|
370 | Down = TopToBottom, Up = BottomToTop };
|
---|
371 |
|
---|
372 | QBoxLayout( QWidget *parent, Direction, int border = 0, int spacing = -1,
|
---|
373 | const char *name = 0 );
|
---|
374 | QBoxLayout( QLayout *parentLayout, Direction, int spacing = -1,
|
---|
375 | const char *name = 0 );
|
---|
376 | QBoxLayout( Direction, int spacing = -1, const char *name = 0 );
|
---|
377 | ~QBoxLayout();
|
---|
378 |
|
---|
379 | void addItem( QLayoutItem * );
|
---|
380 |
|
---|
381 | Direction direction() const { return dir; }
|
---|
382 | void setDirection( Direction );
|
---|
383 |
|
---|
384 | void addSpacing( int size );
|
---|
385 | void addStretch( int stretch = 0 );
|
---|
386 | void addWidget( QWidget *, int stretch = 0, int alignment = 0 );
|
---|
387 | void addLayout( QLayout *layout, int stretch = 0 );
|
---|
388 | void addStrut( int );
|
---|
389 |
|
---|
390 | void insertSpacing( int index, int size );
|
---|
391 | void insertStretch( int index, int stretch = 0 );
|
---|
392 | void insertWidget( int index, QWidget *widget, int stretch = 0,
|
---|
393 | int alignment = 0 );
|
---|
394 | void insertLayout( int index, QLayout *layout, int stretch = 0 );
|
---|
395 |
|
---|
396 | bool setStretchFactor( QWidget*, int stretch );
|
---|
397 | bool setStretchFactor( QLayout *l, int stretch );
|
---|
398 |
|
---|
399 | QSize sizeHint() const;
|
---|
400 | QSize minimumSize() const;
|
---|
401 | QSize maximumSize() const;
|
---|
402 |
|
---|
403 | bool hasHeightForWidth() const;
|
---|
404 | int heightForWidth( int ) const;
|
---|
405 | int minimumHeightForWidth( int ) const;
|
---|
406 |
|
---|
407 | QSizePolicy::ExpandData expanding() const;
|
---|
408 | void invalidate();
|
---|
409 | QLayoutIterator iterator();
|
---|
410 | void setGeometry( const QRect& );
|
---|
411 |
|
---|
412 | int findWidget( QWidget* w );
|
---|
413 |
|
---|
414 | protected:
|
---|
415 | void insertItem( int index, QLayoutItem * );
|
---|
416 |
|
---|
417 | private:
|
---|
418 | friend class QDockWindow;
|
---|
419 | #if defined(Q_DISABLE_COPY)
|
---|
420 | QBoxLayout( const QBoxLayout & );
|
---|
421 | QBoxLayout &operator=( const QBoxLayout & );
|
---|
422 | #endif
|
---|
423 |
|
---|
424 | void setupGeom();
|
---|
425 | void calcHfw( int );
|
---|
426 | QBoxLayoutData *data;
|
---|
427 | Direction dir;
|
---|
428 | QBoxLayout *createTmpCopy();
|
---|
429 | };
|
---|
430 |
|
---|
431 | class Q_EXPORT QHBoxLayout : public QBoxLayout
|
---|
432 | {
|
---|
433 | Q_OBJECT
|
---|
434 | public:
|
---|
435 | QHBoxLayout( QWidget *parent, int border = 0,
|
---|
436 | int spacing = -1, const char *name = 0 );
|
---|
437 | QHBoxLayout( QLayout *parentLayout,
|
---|
438 | int spacing = -1, const char *name = 0 );
|
---|
439 | QHBoxLayout( int spacing = -1, const char *name = 0 );
|
---|
440 |
|
---|
441 | ~QHBoxLayout();
|
---|
442 |
|
---|
443 | private: // Disabled copy constructor and operator=
|
---|
444 | #if defined(Q_DISABLE_COPY)
|
---|
445 | QHBoxLayout( const QHBoxLayout & );
|
---|
446 | QHBoxLayout &operator=( const QHBoxLayout & );
|
---|
447 | #endif
|
---|
448 | };
|
---|
449 |
|
---|
450 | class Q_EXPORT QVBoxLayout : public QBoxLayout
|
---|
451 | {
|
---|
452 | Q_OBJECT
|
---|
453 | public:
|
---|
454 | QVBoxLayout( QWidget *parent, int border = 0,
|
---|
455 | int spacing = -1, const char *name = 0 );
|
---|
456 | QVBoxLayout( QLayout *parentLayout,
|
---|
457 | int spacing = -1, const char *name = 0 );
|
---|
458 | QVBoxLayout( int spacing = -1, const char *name = 0 );
|
---|
459 |
|
---|
460 | ~QVBoxLayout();
|
---|
461 |
|
---|
462 | private: // Disabled copy constructor and operator=
|
---|
463 | #if defined(Q_DISABLE_COPY)
|
---|
464 | QVBoxLayout( const QVBoxLayout & );
|
---|
465 | QVBoxLayout &operator=( const QVBoxLayout & );
|
---|
466 | #endif
|
---|
467 | };
|
---|
468 |
|
---|
469 | #endif // QT_NO_LAYOUT
|
---|
470 | #endif // QLAYOUT_H
|
---|