home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / qt3_emx.zip / include / qlayout.h < prev    next >
C/C++ Source or Header  |  2001-10-11  |  13KB  |  450 lines

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