Eneboo - Documentación para desarrolladores
|
00001 /**************************************************************************** 00002 ** $Id: qt/qlayout.h 3.3.8 edited Jan 11 14:38 $ 00003 ** 00004 ** Definition of layout classes 00005 ** 00006 ** Created : 960416 00007 ** 00008 ** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved. 00009 ** 00010 ** This file is part of the kernel module of the Qt GUI Toolkit. 00011 ** 00012 ** This file may be distributed under the terms of the Q Public License 00013 ** as defined by Trolltech ASA of Norway and appearing in the file 00014 ** LICENSE.QPL included in the packaging of this file. 00015 ** 00016 ** This file may be distributed and/or modified under the terms of the 00017 ** GNU General Public License version 2 as published by the Free Software 00018 ** Foundation and appearing in the file LICENSE.GPL included in the 00019 ** packaging of this file. 00020 ** 00021 ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition 00022 ** licenses may use this file in accordance with the Qt Commercial License 00023 ** Agreement provided with the Software. 00024 ** 00025 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 00026 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 00027 ** 00028 ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for 00029 ** information about Qt Commercial License Agreements. 00030 ** See http://www.trolltech.com/qpl/ for QPL licensing information. 00031 ** See http://www.trolltech.com/gpl/ for GPL licensing information. 00032 ** 00033 ** Contact info@trolltech.com if any conditions of this licensing are 00034 ** not clear to you. 00035 ** 00036 **********************************************************************/ 00037 00038 #ifndef QLAYOUT_H 00039 #define QLAYOUT_H 00040 00041 #ifndef QT_H 00042 #include "qobject.h" 00043 #include "qsizepolicy.h" 00044 #include "qwidget.h" 00045 #endif // QT_H 00046 00047 #include <limits.h> 00048 00049 #ifndef QT_NO_LAYOUT 00050 00051 #if 0 00052 Q_OBJECT 00053 #endif 00054 00055 static const int QLAYOUTSIZE_MAX = INT_MAX/256/16; 00056 00057 class QGridLayoutBox; 00058 class QGridLayoutData; 00059 class QLayout; 00060 class QLayoutItem; 00061 struct QLayoutData; 00062 class QMenuBar; 00063 class QSpacerItem; 00064 class QWidget; 00065 00066 class Q_EXPORT QGLayoutIterator : public QShared 00067 { 00068 public: 00069 virtual ~QGLayoutIterator(); 00070 virtual QLayoutItem *next() = 0; 00071 virtual QLayoutItem *current() = 0; 00072 virtual QLayoutItem *takeCurrent() = 0; 00073 }; 00074 00075 class Q_EXPORT QLayoutIterator 00076 { 00077 public: 00078 QLayoutIterator( QGLayoutIterator *i ) : it( i ) { } 00079 QLayoutIterator( const QLayoutIterator &i ) : it( i.it ) { 00080 if ( it ) 00081 it->ref(); 00082 } 00083 ~QLayoutIterator() { if ( it && it->deref() ) delete it; } 00084 QLayoutIterator &operator=( const QLayoutIterator &i ) { 00085 if ( i.it ) 00086 i.it->ref(); 00087 if ( it && it->deref() ) 00088 delete it; 00089 it = i.it; 00090 return *this; 00091 } 00092 QLayoutItem *operator++() { return it ? it->next() : 0; } 00093 QLayoutItem *current() { return it ? it->current() : 0; } 00094 QLayoutItem *takeCurrent() { return it ? it->takeCurrent() : 0; } 00095 void deleteCurrent(); 00096 00097 private: 00098 QGLayoutIterator *it; 00099 }; 00100 00101 class Q_EXPORT QLayoutItem 00102 { 00103 public: 00104 QLayoutItem( int alignment = 0 ) : align( alignment ) { } 00105 virtual ~QLayoutItem(); 00106 virtual QSize sizeHint() const = 0; 00107 virtual QSize minimumSize() const = 0; 00108 virtual QSize maximumSize() const = 0; 00109 virtual QSizePolicy::ExpandData expanding() const = 0; 00110 virtual void setGeometry( const QRect& ) = 0; 00111 virtual QRect geometry() const = 0; 00112 virtual bool isEmpty() const = 0; 00113 virtual bool hasHeightForWidth() const; 00114 virtual int heightForWidth( int ) const; 00115 // ### add minimumHeightForWidth( int ) in Qt 4.0 00116 virtual void invalidate(); 00117 00118 virtual QWidget *widget(); 00119 virtual QLayoutIterator iterator(); 00120 virtual QLayout *layout(); 00121 virtual QSpacerItem *spacerItem(); 00122 00123 int alignment() const { return align; } 00124 virtual void setAlignment( int a ); 00125 00126 protected: 00127 int align; 00128 }; 00129 00130 class Q_EXPORT QSpacerItem : public QLayoutItem 00131 { 00132 public: 00133 QSpacerItem( int w, int h, 00134 QSizePolicy::SizeType hData = QSizePolicy::Minimum, 00135 QSizePolicy::SizeType vData = QSizePolicy::Minimum ) 00136 : width( w ), height( h ), sizeP( hData, vData ) { } 00137 void changeSize( int w, int h, 00138 QSizePolicy::SizeType hData = QSizePolicy::Minimum, 00139 QSizePolicy::SizeType vData = QSizePolicy::Minimum ); 00140 QSize sizeHint() const; 00141 QSize minimumSize() const; 00142 QSize maximumSize() const; 00143 QSizePolicy::ExpandData expanding() const; 00144 bool isEmpty() const; 00145 void setGeometry( const QRect& ); 00146 QRect geometry() const; 00147 QSpacerItem *spacerItem(); 00148 00149 private: 00150 int width; 00151 int height; 00152 QSizePolicy sizeP; 00153 QRect rect; 00154 }; 00155 00156 class Q_EXPORT QWidgetItem : public QLayoutItem 00157 { 00158 public: 00159 QWidgetItem( QWidget *w ) : wid( w ) { } 00160 QSize sizeHint() const; 00161 QSize minimumSize() const; 00162 QSize maximumSize() const; 00163 QSizePolicy::ExpandData expanding() const; 00164 bool isEmpty() const; 00165 void setGeometry( const QRect& ); 00166 QRect geometry() const; 00167 virtual QWidget *widget(); 00168 00169 bool hasHeightForWidth() const; 00170 int heightForWidth( int ) const; 00171 00172 private: 00173 QWidget *wid; 00174 }; 00175 00176 class Q_EXPORT QLayout : public QObject, public QLayoutItem 00177 { 00178 Q_OBJECT 00179 Q_ENUMS( ResizeMode ) 00180 Q_PROPERTY( int margin READ margin WRITE setMargin ) 00181 Q_PROPERTY( int spacing READ spacing WRITE setSpacing ) 00182 Q_PROPERTY( ResizeMode resizeMode READ resizeMode WRITE setResizeMode ) 00183 00184 public: 00185 // ### Qt 4.0: put 'Auto' first in enum 00186 enum ResizeMode { FreeResize, Minimum, Fixed, Auto }; 00187 00188 QLayout( QWidget *parent, int margin = 0, int spacing = -1, 00189 const char *name = 0 ); 00190 QLayout( QLayout *parentLayout, int spacing = -1, const char *name = 0 ); 00191 QLayout( int spacing = -1, const char *name = 0 ); 00192 ~QLayout(); 00193 00194 int margin() const { return outsideBorder; } 00195 int spacing() const { return insideSpacing; } 00196 00197 virtual void setMargin( int ); 00198 virtual void setSpacing( int ); 00199 00200 int defaultBorder() const { return insideSpacing; } 00201 void freeze( int w, int h ); 00202 void freeze() { setResizeMode( Fixed ); } 00203 00204 void setResizeMode( ResizeMode ); 00205 ResizeMode resizeMode() const; 00206 00207 #ifndef QT_NO_MENUBAR 00208 virtual void setMenuBar( QMenuBar *w ); 00209 QMenuBar *menuBar() const { return menubar; } 00210 #endif 00211 00212 QWidget *mainWidget(); 00213 bool isTopLevel() const { return topLevel; } 00214 00215 virtual void setAutoAdd( bool ); 00216 bool autoAdd() const { return autoNewChild; } 00217 00218 void invalidate(); 00219 QRect geometry() const; 00220 bool activate(); 00221 00222 void add( QWidget *w ) { addItem( new QWidgetItem(w) ); } 00223 virtual void addItem( QLayoutItem * ) = 0; 00224 00225 void remove( QWidget *w ); 00226 void removeItem( QLayoutItem * ); 00227 00228 QSizePolicy::ExpandData expanding() const; 00229 QSize minimumSize() const; 00230 QSize maximumSize() const; 00231 void setGeometry( const QRect& ) = 0; 00232 QLayoutIterator iterator() = 0; 00233 bool isEmpty() const; 00234 00235 int totalHeightForWidth( int w ) const; 00236 QSize totalMinimumSize() const; 00237 QSize totalMaximumSize() const; 00238 QSize totalSizeHint() const; 00239 QLayout *layout(); 00240 00241 bool supportsMargin() const { return marginImpl; } 00242 00243 void setEnabled( bool ); 00244 bool isEnabled() const; 00245 00246 protected: 00247 bool eventFilter( QObject *, QEvent * ); 00248 void childEvent( QChildEvent *e ); 00249 void addChildLayout( QLayout *l ); 00250 void deleteAllItems(); 00251 00252 void setSupportsMargin( bool ); 00253 QRect alignmentRect( const QRect& ) const; 00254 00255 private: 00256 void setWidgetLayout( QWidget *, QLayout * ); 00257 void init(); 00258 int insideSpacing; 00259 int outsideBorder; 00260 uint topLevel : 1; 00261 uint enabled : 1; 00262 uint autoNewChild : 1; 00263 uint frozen : 1; 00264 uint activated : 1; 00265 uint marginImpl : 1; 00266 uint autoMinimum : 1; 00267 uint autoResizeMode : 1; 00268 QRect rect; 00269 QLayoutData *extraData; 00270 #ifndef QT_NO_MENUBAR 00271 QMenuBar *menubar; 00272 #endif 00273 00274 private: 00275 #if defined(Q_DISABLE_COPY) 00276 QLayout( const QLayout & ); 00277 QLayout &operator=( const QLayout & ); 00278 #endif 00279 00280 static void propagateSpacing( QLayout *layout ); 00281 }; 00282 00283 inline void QLayoutIterator::deleteCurrent() 00284 { 00285 delete takeCurrent(); 00286 } 00287 00288 class Q_EXPORT QGridLayout : public QLayout 00289 { 00290 Q_OBJECT 00291 public: 00292 QGridLayout( QWidget *parent, int nRows = 1, int nCols = 1, int border = 0, 00293 int spacing = -1, const char *name = 0 ); 00294 QGridLayout( int nRows = 1, int nCols = 1, int spacing = -1, 00295 const char *name = 0 ); 00296 QGridLayout( QLayout *parentLayout, int nRows = 1, int nCols = 1, 00297 int spacing = -1, const char *name = 0 ); 00298 ~QGridLayout(); 00299 00300 QSize sizeHint() const; 00301 QSize minimumSize() const; 00302 QSize maximumSize() const; 00303 00304 // ### remove 'virtual' in 4.0 (or add 'virtual' to set{Row,Col}Spacing()) 00305 virtual void setRowStretch( int row, int stretch ); 00306 virtual void setColStretch( int col, int stretch ); 00307 int rowStretch( int row ) const; 00308 int colStretch( int col ) const; 00309 00310 void setRowSpacing( int row, int minSize ); 00311 void setColSpacing( int col, int minSize ); 00312 int rowSpacing( int row ) const; 00313 int colSpacing( int col ) const; 00314 00315 int numRows() const; 00316 int numCols() const; 00317 QRect cellGeometry( int row, int col ) const; 00318 00319 bool hasHeightForWidth() const; 00320 int heightForWidth( int ) const; 00321 int minimumHeightForWidth( int ) const; 00322 00323 QSizePolicy::ExpandData expanding() const; 00324 void invalidate(); 00325 00326 void addItem( QLayoutItem * ); 00327 void addItem( QLayoutItem *item, int row, int col ); 00328 void addMultiCell( QLayoutItem *, int fromRow, int toRow, 00329 int fromCol, int toCol, int align = 0 ); 00330 00331 void addWidget( QWidget *, int row, int col, int align = 0 ); 00332 void addMultiCellWidget( QWidget *, int fromRow, int toRow, 00333 int fromCol, int toCol, int align = 0 ); 00334 void addLayout( QLayout *layout, int row, int col); 00335 void addMultiCellLayout( QLayout *layout, int fromRow, int toRow, 00336 int fromCol, int toCol, int align = 0 ); 00337 void addRowSpacing( int row, int minsize ); 00338 void addColSpacing( int col, int minsize ); 00339 00340 void expand( int rows, int cols ); 00341 00342 enum Corner { TopLeft, TopRight, BottomLeft, BottomRight }; 00343 void setOrigin( Corner ); 00344 Corner origin() const; 00345 QLayoutIterator iterator(); 00346 void setGeometry( const QRect& ); 00347 00348 protected: 00349 bool findWidget( QWidget* w, int *r, int *c ); 00350 void add( QLayoutItem*, int row, int col ); 00351 00352 private: 00353 #if defined(Q_DISABLE_COPY) 00354 QGridLayout( const QGridLayout & ); 00355 QGridLayout &operator=( const QGridLayout & ); 00356 #endif 00357 00358 void init( int rows, int cols ); 00359 QGridLayoutData *data; 00360 }; 00361 00362 class QBoxLayoutData; 00363 class QDockWindow; 00364 00365 class Q_EXPORT QBoxLayout : public QLayout 00366 { 00367 Q_OBJECT 00368 public: 00369 enum Direction { LeftToRight, RightToLeft, TopToBottom, BottomToTop, 00370 Down = TopToBottom, Up = BottomToTop }; 00371 00372 QBoxLayout( QWidget *parent, Direction, int border = 0, int spacing = -1, 00373 const char *name = 0 ); 00374 QBoxLayout( QLayout *parentLayout, Direction, int spacing = -1, 00375 const char *name = 0 ); 00376 QBoxLayout( Direction, int spacing = -1, const char *name = 0 ); 00377 ~QBoxLayout(); 00378 00379 void addItem( QLayoutItem * ); 00380 00381 Direction direction() const { return dir; } 00382 void setDirection( Direction ); 00383 00384 void addSpacing( int size ); 00385 void addStretch( int stretch = 0 ); 00386 void addWidget( QWidget *, int stretch = 0, int alignment = 0 ); 00387 void addLayout( QLayout *layout, int stretch = 0 ); 00388 void addStrut( int ); 00389 00390 void insertSpacing( int index, int size ); 00391 void insertStretch( int index, int stretch = 0 ); 00392 void insertWidget( int index, QWidget *widget, int stretch = 0, 00393 int alignment = 0 ); 00394 void insertLayout( int index, QLayout *layout, int stretch = 0 ); 00395 00396 bool setStretchFactor( QWidget*, int stretch ); 00397 bool setStretchFactor( QLayout *l, int stretch ); 00398 00399 QSize sizeHint() const; 00400 QSize minimumSize() const; 00401 QSize maximumSize() const; 00402 00403 bool hasHeightForWidth() const; 00404 int heightForWidth( int ) const; 00405 int minimumHeightForWidth( int ) const; 00406 00407 QSizePolicy::ExpandData expanding() const; 00408 void invalidate(); 00409 QLayoutIterator iterator(); 00410 void setGeometry( const QRect& ); 00411 00412 int findWidget( QWidget* w ); 00413 00414 protected: 00415 void insertItem( int index, QLayoutItem * ); 00416 00417 private: 00418 friend class QDockWindow; 00419 #if defined(Q_DISABLE_COPY) 00420 QBoxLayout( const QBoxLayout & ); 00421 QBoxLayout &operator=( const QBoxLayout & ); 00422 #endif 00423 00424 void setupGeom(); 00425 void calcHfw( int ); 00426 QBoxLayoutData *data; 00427 Direction dir; 00428 QBoxLayout *createTmpCopy(); 00429 }; 00430 00431 class Q_EXPORT QHBoxLayout : public QBoxLayout 00432 { 00433 Q_OBJECT 00434 public: 00435 QHBoxLayout( QWidget *parent, int border = 0, 00436 int spacing = -1, const char *name = 0 ); 00437 QHBoxLayout( QLayout *parentLayout, 00438 int spacing = -1, const char *name = 0 ); 00439 QHBoxLayout( int spacing = -1, const char *name = 0 ); 00440 00441 ~QHBoxLayout(); 00442 00443 private: // Disabled copy constructor and operator= 00444 #if defined(Q_DISABLE_COPY) 00445 QHBoxLayout( const QHBoxLayout & ); 00446 QHBoxLayout &operator=( const QHBoxLayout & ); 00447 #endif 00448 }; 00449 00450 class Q_EXPORT QVBoxLayout : public QBoxLayout 00451 { 00452 Q_OBJECT 00453 public: 00454 QVBoxLayout( QWidget *parent, int border = 0, 00455 int spacing = -1, const char *name = 0 ); 00456 QVBoxLayout( QLayout *parentLayout, 00457 int spacing = -1, const char *name = 0 ); 00458 QVBoxLayout( int spacing = -1, const char *name = 0 ); 00459 00460 ~QVBoxLayout(); 00461 00462 private: // Disabled copy constructor and operator= 00463 #if defined(Q_DISABLE_COPY) 00464 QVBoxLayout( const QVBoxLayout & ); 00465 QVBoxLayout &operator=( const QVBoxLayout & ); 00466 #endif 00467 }; 00468 00469 #endif // QT_NO_LAYOUT 00470 #endif // QLAYOUT_H