source: trunk/src/gui/kernel/qlayout.h@ 352

Last change on this file since 352 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 7.5 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: Qt Software Information ([email protected])
5**
6** This file is part of the QtGui module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial Usage
10** Licensees holding valid Qt Commercial licenses may use this file in
11** accordance with the Qt Commercial License Agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Nokia.
14**
15** GNU Lesser General Public License Usage
16** Alternatively, this file may be used under the terms of the GNU Lesser
17** General Public License version 2.1 as published by the Free Software
18** Foundation and appearing in the file LICENSE.LGPL included in the
19** packaging of this file. Please review the following information to
20** ensure the GNU Lesser General Public License version 2.1 requirements
21** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22**
23** In addition, as a special exception, Nokia gives you certain
24** additional rights. These rights are described in the Nokia Qt LGPL
25** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
26** package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you are unsure which license is appropriate for your use, please
37** contact the sales department at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#ifndef QLAYOUT_H
43#define QLAYOUT_H
44
45#include <QtCore/qobject.h>
46#include <QtGui/qlayoutitem.h>
47#include <QtGui/qsizepolicy.h>
48#include <QtCore/qrect.h>
49
50#include <limits.h>
51
52QT_BEGIN_HEADER
53
54QT_BEGIN_NAMESPACE
55
56QT_MODULE(Gui)
57
58class QLayout;
59class QSize;
60
61#ifdef QT3_SUPPORT
62class Q_GUI_EXPORT QLayoutIterator
63{
64public:
65 inline QT3_SUPPORT_CONSTRUCTOR QLayoutIterator(QLayout *i) : layout(i), index(0) {}
66 inline QLayoutIterator(const QLayoutIterator &i)
67 : layout(i.layout), index(i.index) {}
68 inline QLayoutIterator &operator=(const QLayoutIterator &i) {
69 layout = i.layout;
70 index = i.index;
71 return *this;
72 }
73 inline QT3_SUPPORT QLayoutItem *operator++();
74 inline QT3_SUPPORT QLayoutItem *current();
75 inline QT3_SUPPORT QLayoutItem *takeCurrent();
76 inline QT3_SUPPORT void deleteCurrent();
77
78private:
79 // hack to avoid deprecated warning
80 friend class QLayout;
81 inline QLayoutIterator(QLayout *i, bool) : layout(i), index(0) {}
82 QLayout *layout;
83 int index;
84};
85#endif
86
87class QLayoutPrivate;
88
89class Q_GUI_EXPORT QLayout : public QObject, public QLayoutItem
90{
91 Q_OBJECT
92 Q_DECLARE_PRIVATE(QLayout)
93
94 Q_ENUMS(SizeConstraint)
95 Q_PROPERTY(int margin READ margin WRITE setMargin)
96 Q_PROPERTY(int spacing READ spacing WRITE setSpacing)
97 Q_PROPERTY(SizeConstraint sizeConstraint READ sizeConstraint WRITE setSizeConstraint)
98public:
99 enum SizeConstraint {
100 SetDefaultConstraint,
101 SetNoConstraint,
102 SetMinimumSize,
103 SetFixedSize,
104 SetMaximumSize,
105 SetMinAndMaxSize
106#if defined(QT3_SUPPORT) && !defined(Q_MOC_RUN)
107 , Auto = SetDefaultConstraint,
108 FreeResize = SetNoConstraint,
109 Minimum = SetMinimumSize,
110 Fixed = SetFixedSize
111#endif
112 };
113
114 QLayout(QWidget *parent);
115 QLayout();
116 ~QLayout();
117
118 int margin() const;
119 int spacing() const;
120
121 void setMargin(int);
122 void setSpacing(int);
123
124 void setContentsMargins(int left, int top, int right, int bottom);
125 void getContentsMargins(int *left, int *top, int *right, int *bottom) const;
126 QRect contentsRect() const;
127
128 bool setAlignment(QWidget *w, Qt::Alignment alignment);
129 bool setAlignment(QLayout *l, Qt::Alignment alignment);
130#ifdef Q_NO_USING_KEYWORD
131 inline void setAlignment(Qt::Alignment alignment) { QLayoutItem::setAlignment(alignment); }
132#else
133 using QLayoutItem::setAlignment;
134#endif
135
136 void setSizeConstraint(SizeConstraint);
137 SizeConstraint sizeConstraint() const;
138#ifdef QT3_SUPPORT
139 inline QT3_SUPPORT void setResizeMode(SizeConstraint s) {setSizeConstraint(s);}
140 inline QT3_SUPPORT SizeConstraint resizeMode() const {return sizeConstraint();}
141#endif
142 void setMenuBar(QWidget *w);
143 QWidget *menuBar() const;
144
145 QWidget *parentWidget() const;
146
147 void invalidate();
148 QRect geometry() const;
149 bool activate();
150 void update();
151
152 void addWidget(QWidget *w);
153 virtual void addItem(QLayoutItem *) = 0;
154
155 void removeWidget(QWidget *w);
156 void removeItem(QLayoutItem *);
157
158 Qt::Orientations expandingDirections() const;
159 QSize minimumSize() const;
160 QSize maximumSize() const;
161 virtual void setGeometry(const QRect&);
162 virtual QLayoutItem *itemAt(int index) const = 0;
163 virtual QLayoutItem *takeAt(int index) = 0;
164 virtual int indexOf(QWidget *) const;
165 virtual int count() const = 0;
166 bool isEmpty() const;
167
168 int totalHeightForWidth(int w) const;
169 QSize totalMinimumSize() const;
170 QSize totalMaximumSize() const;
171 QSize totalSizeHint() const;
172 QLayout *layout();
173
174 void setEnabled(bool);
175 bool isEnabled() const;
176
177#ifdef QT3_SUPPORT
178 QT3_SUPPORT void freeze(int w=0, int h=0);
179 QT3_SUPPORT bool isTopLevel() const;
180#endif
181
182 static QSize closestAcceptableSize(const QWidget *w, const QSize &s);
183
184protected:
185 void widgetEvent(QEvent *);
186 void childEvent(QChildEvent *e);
187 void addChildLayout(QLayout *l);
188 void addChildWidget(QWidget *w);
189#ifdef QT3_SUPPORT
190 QT3_SUPPORT void deleteAllItems();
191#endif
192
193 QRect alignmentRect(const QRect&) const;
194protected:
195 QLayout(QLayoutPrivate &d, QLayout*, QWidget*);
196
197private:
198 Q_DISABLE_COPY(QLayout)
199
200 static void activateRecursiveHelper(QLayoutItem *item);
201
202 friend class QApplicationPrivate;
203 friend class QWidget;
204
205#ifdef QT3_SUPPORT
206public:
207 QT3_SUPPORT_CONSTRUCTOR QLayout(QWidget *parent, int margin, int spacing = -1,
208 const char *name = 0);
209 QT3_SUPPORT_CONSTRUCTOR QLayout(QLayout *parentLayout, int spacing = -1, const char *name = 0);
210 QT3_SUPPORT_CONSTRUCTOR QLayout(int spacing, const char *name = 0);
211 inline QT3_SUPPORT QWidget *mainWidget() const { return parentWidget(); }
212 inline QT3_SUPPORT void remove(QWidget *w) { removeWidget(w); }
213 inline QT3_SUPPORT void add(QWidget *w) { addWidget(w); }
214
215 QT3_SUPPORT void setAutoAdd(bool a);
216 QT3_SUPPORT bool autoAdd() const;
217 inline QT3_SUPPORT QLayoutIterator iterator() { return QLayoutIterator(this,true); }
218
219 inline QT3_SUPPORT int defaultBorder() const { return spacing(); }
220#endif
221};
222
223#ifdef QT3_SUPPORT
224inline QLayoutItem *QLayoutIterator::operator++() { return layout->itemAt(++index); }
225inline QLayoutItem *QLayoutIterator::current() { return layout->itemAt(index); }
226inline QLayoutItem *QLayoutIterator::takeCurrent() { return layout->takeAt(index); }
227inline void QLayoutIterator::deleteCurrent() { delete layout->takeAt(index); }
228#endif
229
230//### support old includes
231#if 1 //def QT3_SUPPORT
232QT_BEGIN_INCLUDE_NAMESPACE
233#include <QtGui/qboxlayout.h>
234#include <QtGui/qgridlayout.h>
235QT_END_INCLUDE_NAMESPACE
236#endif
237
238QT_END_NAMESPACE
239
240QT_END_HEADER
241
242#endif // QLAYOUT_H
Note: See TracBrowser for help on using the repository browser.