qlayout.h

Go to the documentation of this file.
00001 /****************************************************************************
00002 **
00003 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
00004 ** All rights reserved.
00005 ** Contact: Nokia Corporation (qt-info@nokia.com)
00006 **
00007 ** This file is part of the QtGui module of the Qt Toolkit.
00008 **
00009 ** $QT_BEGIN_LICENSE:LGPL$
00010 ** Commercial Usage
00011 ** Licensees holding valid Qt Commercial licenses may use this file in
00012 ** accordance with the Qt Commercial License Agreement provided with the
00013 ** Software or, alternatively, in accordance with the terms contained in
00014 ** a written agreement between you and Nokia.
00015 **
00016 ** GNU Lesser General Public License Usage
00017 ** Alternatively, this file may be used under the terms of the GNU Lesser
00018 ** General Public License version 2.1 as published by the Free Software
00019 ** Foundation and appearing in the file LICENSE.LGPL included in the
00020 ** packaging of this file.  Please review the following information to
00021 ** ensure the GNU Lesser General Public License version 2.1 requirements
00022 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
00023 **
00024 ** In addition, as a special exception, Nokia gives you certain additional
00025 ** rights.  These rights are described in the Nokia Qt LGPL Exception
00026 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this module.
00027 **
00028 ** GNU General Public License Usage
00029 ** Alternatively, this file may be used under the terms of the GNU
00030 ** General Public License version 3.0 as published by the Free Software
00031 ** Foundation and appearing in the file LICENSE.GPL included in the
00032 ** packaging of this file.  Please review the following information to
00033 ** ensure the GNU General Public License version 3.0 requirements will be
00034 ** met: http://www.gnu.org/copyleft/gpl.html.
00035 **
00036 ** If you have questions regarding the use of this file, please contact
00037 ** Nokia at qt-info@nokia.com.
00038 ** $QT_END_LICENSE$
00039 **
00040 ****************************************************************************/
00041 
00042 #ifndef QLAYOUT_H
00043 #define QLAYOUT_H
00044 
00045 #include <QtCore/qobject.h>
00046 #include <QtGui/qlayoutitem.h>
00047 #include <QtGui/qsizepolicy.h>
00048 #include <QtCore/qrect.h>
00049 #include <QtCore/qmargins.h>
00050 
00051 #include <limits.h>
00052 
00053 QT_BEGIN_HEADER
00054 
00055 QT_BEGIN_NAMESPACE
00056 
00057 QT_MODULE(Gui)
00058 
00059 class QLayout;
00060 class QSize;
00061 
00062 #ifdef QT3_SUPPORT
00063 class Q_GUI_EXPORT QLayoutIterator
00064 {
00065 public:
00066     inline QT3_SUPPORT_CONSTRUCTOR QLayoutIterator(QLayout *i) : layout(i), index(0) {}
00067     inline QLayoutIterator(const QLayoutIterator &i)
00068         : layout(i.layout), index(i.index) {}
00069     inline QLayoutIterator &operator=(const QLayoutIterator &i) {
00070         layout = i.layout;
00071         index = i.index;
00072         return *this;
00073     }
00074     inline QT3_SUPPORT QLayoutItem *operator++();
00075     inline QT3_SUPPORT QLayoutItem *current();
00076     inline QT3_SUPPORT QLayoutItem *takeCurrent();
00077     inline QT3_SUPPORT void deleteCurrent();
00078 
00079 private:
00080     // hack to avoid deprecated warning
00081     friend class QLayout;
00082     inline QLayoutIterator(QLayout *i, bool) : layout(i), index(0) {}
00083     QLayout *layout;
00084     int index;
00085 };
00086 #endif
00087 
00088 class QLayoutPrivate;
00089 
00090 class Q_GUI_EXPORT QLayout : public QObject, public QLayoutItem
00091 {
00092     Q_OBJECT
00093     Q_DECLARE_PRIVATE(QLayout)
00094 
00095     Q_ENUMS(SizeConstraint)
00096     Q_PROPERTY(int margin READ margin WRITE setMargin)
00097     Q_PROPERTY(int spacing READ spacing WRITE setSpacing)
00098     Q_PROPERTY(SizeConstraint sizeConstraint READ sizeConstraint WRITE setSizeConstraint)
00099 public:
00100     enum SizeConstraint {
00101         SetDefaultConstraint,
00102         SetNoConstraint,
00103         SetMinimumSize,
00104         SetFixedSize,
00105         SetMaximumSize,
00106         SetMinAndMaxSize
00107 #if defined(QT3_SUPPORT) && !defined(Q_MOC_RUN)
00108         , Auto = SetDefaultConstraint,
00109         FreeResize = SetNoConstraint,
00110         Minimum = SetMinimumSize,
00111         Fixed = SetFixedSize
00112 #endif
00113     };
00114 
00115     QLayout(QWidget *parent);
00116     QLayout();
00117     ~QLayout();
00118 
00119     int margin() const;
00120     int spacing() const;
00121 
00122     void setMargin(int);
00123     void setSpacing(int);
00124 
00125     void setContentsMargins(int left, int top, int right, int bottom);
00126     void setContentsMargins(const QMargins &margins);
00127     void getContentsMargins(int *left, int *top, int *right, int *bottom) const;
00128     QMargins contentsMargins() const;
00129     QRect contentsRect() const;
00130 
00131     bool setAlignment(QWidget *w, Qt::Alignment alignment);
00132     bool setAlignment(QLayout *l, Qt::Alignment alignment);
00133 #ifdef Q_NO_USING_KEYWORD
00134     inline void setAlignment(Qt::Alignment alignment) { QLayoutItem::setAlignment(alignment); }
00135 #else
00136     using QLayoutItem::setAlignment;
00137 #endif
00138 
00139     void setSizeConstraint(SizeConstraint);
00140     SizeConstraint sizeConstraint() const;
00141 #ifdef QT3_SUPPORT
00142     inline QT3_SUPPORT void setResizeMode(SizeConstraint s) {setSizeConstraint(s);}
00143     inline QT3_SUPPORT SizeConstraint resizeMode() const {return sizeConstraint();}
00144 #endif
00145     void setMenuBar(QWidget *w);
00146     QWidget *menuBar() const;
00147 
00148     QWidget *parentWidget() const;
00149 
00150     void invalidate();
00151     QRect geometry() const;
00152     bool activate();
00153     void update();
00154 
00155     void addWidget(QWidget *w);
00156     virtual void addItem(QLayoutItem *) = 0;
00157 
00158     void removeWidget(QWidget *w);
00159     void removeItem(QLayoutItem *);
00160 
00161     Qt::Orientations expandingDirections() const;
00162     QSize minimumSize() const;
00163     QSize maximumSize() const;
00164     virtual void setGeometry(const QRect&);
00165     virtual QLayoutItem *itemAt(int index) const = 0;
00166     virtual QLayoutItem *takeAt(int index) = 0;
00167     virtual int indexOf(QWidget *) const;
00168     virtual int count() const = 0;
00169     bool isEmpty() const;
00170 
00171     int totalHeightForWidth(int w) const;
00172     QSize totalMinimumSize() const;
00173     QSize totalMaximumSize() const;
00174     QSize totalSizeHint() const;
00175     QLayout *layout();
00176 
00177     void setEnabled(bool);
00178     bool isEnabled() const;
00179 
00180 #ifdef QT3_SUPPORT
00181     QT3_SUPPORT void freeze(int w=0, int h=0);
00182     QT3_SUPPORT bool isTopLevel() const;
00183 #endif
00184 
00185     static QSize closestAcceptableSize(const QWidget *w, const QSize &s);
00186 
00187 protected:
00188     void widgetEvent(QEvent *);
00189     void childEvent(QChildEvent *e);
00190     void addChildLayout(QLayout *l);
00191     void addChildWidget(QWidget *w);
00192 #ifdef QT3_SUPPORT
00193     QT3_SUPPORT void deleteAllItems();
00194 #endif
00195 
00196     QRect alignmentRect(const QRect&) const;
00197 protected:
00198     QLayout(QLayoutPrivate &d, QLayout*, QWidget*);
00199 
00200 private:
00201     Q_DISABLE_COPY(QLayout)
00202 
00203     static void activateRecursiveHelper(QLayoutItem *item);
00204 
00205     friend class QApplicationPrivate;
00206     friend class QWidget;
00207 
00208 #ifdef QT3_SUPPORT
00209 public:
00210     QT3_SUPPORT_CONSTRUCTOR QLayout(QWidget *parent, int margin, int spacing = -1,
00211                              const char *name = 0);
00212     QT3_SUPPORT_CONSTRUCTOR QLayout(QLayout *parentLayout, int spacing = -1, const char *name = 0);
00213     QT3_SUPPORT_CONSTRUCTOR QLayout(int spacing, const char *name = 0);
00214     inline QT3_SUPPORT QWidget *mainWidget() const { return parentWidget(); }
00215     inline QT3_SUPPORT void remove(QWidget *w) { removeWidget(w); }
00216     inline QT3_SUPPORT void add(QWidget *w) { addWidget(w); }
00217 
00218     QT3_SUPPORT void setAutoAdd(bool a);
00219     QT3_SUPPORT bool autoAdd() const;
00220     inline QT3_SUPPORT QLayoutIterator iterator() { return QLayoutIterator(this,true); }
00221 
00222     inline QT3_SUPPORT int defaultBorder() const { return spacing(); }
00223 #endif
00224 };
00225 
00226 #ifdef QT3_SUPPORT
00227 inline QLayoutItem *QLayoutIterator::operator++() { return layout->itemAt(++index); }
00228 inline QLayoutItem *QLayoutIterator::current() { return layout->itemAt(index); }
00229 inline QLayoutItem *QLayoutIterator::takeCurrent() { return layout->takeAt(index); }
00230 inline void QLayoutIterator::deleteCurrent() { delete  layout->takeAt(index); }
00231 #endif
00232 
00233 //### support old includes
00234 #if 1 //def QT3_SUPPORT
00235 QT_BEGIN_INCLUDE_NAMESPACE
00236 #include <QtGui/qboxlayout.h>
00237 #include <QtGui/qgridlayout.h>
00238 QT_END_INCLUDE_NAMESPACE
00239 #endif
00240 
00241 QT_END_NAMESPACE
00242 
00243 QT_END_HEADER
00244 
00245 #endif // QLAYOUT_H