1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QLAYOUT_H
5#define QLAYOUT_H
6
7#include <QtWidgets/qtwidgetsglobal.h>
8#include <QtCore/qobject.h>
9#include <QtWidgets/qlayoutitem.h>
10#include <QtWidgets/qsizepolicy.h>
11#include <QtCore/qrect.h>
12#include <QtCore/qmargins.h>
13
14#include <limits.h>
15
16QT_BEGIN_NAMESPACE
17
18
19class QLayout;
20class QSize;
21
22
23class QLayoutPrivate;
24
25class Q_WIDGETS_EXPORT QLayout : public QObject, public QLayoutItem
26{
27 Q_OBJECT
28 Q_DECLARE_PRIVATE(QLayout)
29
30 Q_PROPERTY(int spacing READ spacing WRITE setSpacing)
31 Q_PROPERTY(QMargins contentsMargins READ contentsMargins WRITE setContentsMargins
32 RESET unsetContentsMargins)
33 Q_PROPERTY(SizeConstraint sizeConstraint READ sizeConstraint WRITE setSizeConstraint)
34public:
35 enum SizeConstraint {
36 SetDefaultConstraint,
37 SetNoConstraint,
38 SetMinimumSize,
39 SetFixedSize,
40 SetMaximumSize,
41 SetMinAndMaxSize
42 };
43 Q_ENUM(SizeConstraint)
44
45 explicit QLayout(QWidget *parent = nullptr);
46 ~QLayout();
47
48 virtual int spacing() const;
49 virtual void setSpacing(int);
50
51 void setContentsMargins(int left, int top, int right, int bottom);
52 void setContentsMargins(const QMargins &margins);
53 void unsetContentsMargins();
54 void getContentsMargins(int *left, int *top, int *right, int *bottom) const;
55 QMargins contentsMargins() const;
56 QRect contentsRect() const;
57
58 bool setAlignment(QWidget *w, Qt::Alignment alignment);
59 bool setAlignment(QLayout *l, Qt::Alignment alignment);
60 using QLayoutItem::setAlignment;
61
62 void setSizeConstraint(SizeConstraint);
63 SizeConstraint sizeConstraint() const;
64 void setMenuBar(QWidget *w);
65 QWidget *menuBar() const;
66
67 QWidget *parentWidget() const;
68
69 void invalidate() override;
70 QRect geometry() const override;
71 bool activate();
72 void update();
73
74 void addWidget(QWidget *w);
75 virtual void addItem(QLayoutItem *) = 0;
76
77 void removeWidget(QWidget *w);
78 void removeItem(QLayoutItem *);
79
80 Qt::Orientations expandingDirections() const override;
81 QSize minimumSize() const override;
82 QSize maximumSize() const override;
83 virtual void setGeometry(const QRect&) override;
84 virtual QLayoutItem *itemAt(int index) const = 0;
85 virtual QLayoutItem *takeAt(int index) = 0;
86 virtual int indexOf(const QWidget *) const;
87 virtual int indexOf(const QLayoutItem *) const;
88 virtual int count() const = 0;
89 bool isEmpty() const override;
90 QSizePolicy::ControlTypes controlTypes() const override;
91
92 virtual QLayoutItem *replaceWidget(QWidget *from, QWidget *to,
93 Qt::FindChildOptions options = Qt::FindChildrenRecursively);
94
95 int totalMinimumHeightForWidth(int w) const;
96 int totalHeightForWidth(int w) const;
97 QSize totalMinimumSize() const;
98 QSize totalMaximumSize() const;
99 QSize totalSizeHint() const;
100 QLayout *layout() override;
101
102 void setEnabled(bool);
103 bool isEnabled() const;
104
105
106 static QSize closestAcceptableSize(const QWidget *w, const QSize &s);
107
108protected:
109 void widgetEvent(QEvent *);
110 void childEvent(QChildEvent *e) override;
111 void addChildLayout(QLayout *l);
112 void addChildWidget(QWidget *w);
113 bool adoptLayout(QLayout *layout);
114
115 QRect alignmentRect(const QRect&) const;
116protected:
117 QLayout(QLayoutPrivate &d, QLayout*, QWidget*);
118
119private:
120 Q_DISABLE_COPY(QLayout)
121
122 static void activateRecursiveHelper(QLayoutItem *item);
123
124 friend class QApplicationPrivate;
125 friend class QWidget;
126
127};
128
129QT_END_NAMESPACE
130
131//### support old includes
132#include <QtWidgets/qboxlayout.h>
133#include <QtWidgets/qgridlayout.h>
134
135#endif // QLAYOUT_H
136

source code of qtbase/src/widgets/kernel/qlayout.h