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