1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtWidgets 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 The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/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 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QLAYOUT_H
41#define QLAYOUT_H
42
43#include <QtWidgets/qtwidgetsglobal.h>
44#include <QtCore/qobject.h>
45#include <QtWidgets/qlayoutitem.h>
46#include <QtWidgets/qsizepolicy.h>
47#include <QtCore/qrect.h>
48#include <QtCore/qmargins.h>
49
50#include <limits.h>
51
52QT_BEGIN_NAMESPACE
53
54
55class QLayout;
56class QSize;
57
58
59class QLayoutPrivate;
60
61class Q_WIDGETS_EXPORT QLayout : public QObject, public QLayoutItem
62{
63 Q_OBJECT
64 Q_DECLARE_PRIVATE(QLayout)
65
66#if QT_DEPRECATED_SINCE(5, 13)
67 Q_PROPERTY(int margin READ margin WRITE setMargin)
68#endif
69 Q_PROPERTY(int spacing READ spacing WRITE setSpacing)
70 Q_PROPERTY(SizeConstraint sizeConstraint READ sizeConstraint WRITE setSizeConstraint)
71public:
72 enum SizeConstraint {
73 SetDefaultConstraint,
74 SetNoConstraint,
75 SetMinimumSize,
76 SetFixedSize,
77 SetMaximumSize,
78 SetMinAndMaxSize
79 };
80 Q_ENUM(SizeConstraint)
81
82 QLayout(QWidget *parent);
83 QLayout();
84 ~QLayout();
85
86#if QT_DEPRECATED_SINCE(5, 13)
87 int margin() const;
88 void setMargin(int);
89#endif
90
91 int spacing() const;
92 void setSpacing(int);
93
94 void setContentsMargins(int left, int top, int right, int bottom);
95 void setContentsMargins(const QMargins &margins);
96 void getContentsMargins(int *left, int *top, int *right, int *bottom) const;
97 QMargins contentsMargins() const;
98 QRect contentsRect() const;
99
100 bool setAlignment(QWidget *w, Qt::Alignment alignment);
101 bool setAlignment(QLayout *l, Qt::Alignment alignment);
102 using QLayoutItem::setAlignment;
103
104 void setSizeConstraint(SizeConstraint);
105 SizeConstraint sizeConstraint() const;
106 void setMenuBar(QWidget *w);
107 QWidget *menuBar() const;
108
109 QWidget *parentWidget() const;
110
111 void invalidate() override;
112 QRect geometry() const override;
113 bool activate();
114 void update();
115
116 void addWidget(QWidget *w);
117 virtual void addItem(QLayoutItem *) = 0;
118
119 void removeWidget(QWidget *w);
120 void removeItem(QLayoutItem *);
121
122 Qt::Orientations expandingDirections() const override;
123 QSize minimumSize() const override;
124 QSize maximumSize() const override;
125 virtual void setGeometry(const QRect&) override;
126 virtual QLayoutItem *itemAt(int index) const = 0;
127 virtual QLayoutItem *takeAt(int index) = 0;
128 virtual int indexOf(QWidget *) const;
129 QT6_VIRTUAL int indexOf(QLayoutItem *) const;
130 virtual int count() const = 0;
131 bool isEmpty() const override;
132 QSizePolicy::ControlTypes controlTypes() const override;
133
134 QT6_VIRTUAL QLayoutItem *replaceWidget(QWidget *from, QWidget *to,
135 Qt::FindChildOptions options = Qt::FindChildrenRecursively);
136
137 int totalHeightForWidth(int w) const;
138 QSize totalMinimumSize() const;
139 QSize totalMaximumSize() const;
140 QSize totalSizeHint() const;
141 QLayout *layout() override;
142
143 void setEnabled(bool);
144 bool isEnabled() const;
145
146
147 static QSize closestAcceptableSize(const QWidget *w, const QSize &s);
148
149protected:
150 void widgetEvent(QEvent *);
151 void childEvent(QChildEvent *e) override;
152 void addChildLayout(QLayout *l);
153 void addChildWidget(QWidget *w);
154 bool adoptLayout(QLayout *layout);
155
156 QRect alignmentRect(const QRect&) const;
157protected:
158 QLayout(QLayoutPrivate &d, QLayout*, QWidget*);
159
160private:
161 Q_DISABLE_COPY(QLayout)
162
163 static void activateRecursiveHelper(QLayoutItem *item);
164
165 friend class QApplicationPrivate;
166 friend class QWidget;
167
168};
169
170QT_END_NAMESPACE
171
172//### support old includes
173#include <QtWidgets/qboxlayout.h>
174#include <QtWidgets/qgridlayout.h>
175
176#endif // QLAYOUT_H
177