Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qquickflexboxlayout_p.h
Go to the documentation of this file.
1// Copyright (C) 2025 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// Qt-Security score:significant reason:default
4
5#ifndef QQUICKFLEXBOXLAYOUT_H
6#define QQUICKFLEXBOXLAYOUT_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <bitset>
20#include <QtQuickLayouts/private/qquicklayoutglobal_p.h>
21#include <QtQuickLayouts/private/qquicklayout_p.h>
22
23QT_BEGIN_NAMESPACE
24
25class QQuickFlexboxLayoutPrivate;
26class QQuickFlexboxLayoutAttached;
27
28class Q_QUICKLAYOUTS_EXPORT QQuickFlexboxLayout : public QQuickLayout
29{
30 Q_OBJECT
31
32 Q_PROPERTY(FlexboxDirection direction READ direction WRITE setDirection NOTIFY directionChanged FINAL)
33 Q_PROPERTY(FlexboxWrap wrap READ wrap WRITE setWrap NOTIFY wrapChanged FINAL)
34 Q_PROPERTY(FlexboxAlignment alignItems READ alignItems WRITE setAlignItems NOTIFY alignItemsChanged FINAL)
35 Q_PROPERTY(FlexboxAlignment alignContent READ alignContent WRITE setAlignContent NOTIFY alignContentChanged FINAL)
36 Q_PROPERTY(FlexboxJustify justifyContent READ justifyContent WRITE setJustifyContent NOTIFY justifyContentChanged FINAL)
37 Q_PROPERTY(qreal gap READ gap WRITE setGap NOTIFY gapChanged RESET resetGap FINAL)
38 Q_PROPERTY(qreal rowGap READ rowGap WRITE setRowGap NOTIFY rowGapChanged RESET resetRowGap FINAL)
39 Q_PROPERTY(qreal columnGap READ columnGap WRITE setColumnGap NOTIFY columnGapChanged RESET resetColumnGap FINAL)
40
41 QML_NAMED_ELEMENT(FlexboxLayout)
42 QML_ADDED_IN_VERSION(6, 10)
43 QML_ATTACHED(QQuickFlexboxLayoutAttached)
44
45public:
46 explicit QQuickFlexboxLayout(QQuickItem *parent = nullptr);
47 ~QQuickFlexboxLayout();
48
49 enum FlexboxDirection { // Used as similar to CSS standard
50 Column,
51 ColumnReverse,
52 Row,
53 RowReverse
54 };
55 Q_ENUM(FlexboxDirection);
56
57 enum FlexboxWrap {
58 NoWrap,
59 Wrap,
60 WrapReverse
61 };
62 Q_ENUM(FlexboxWrap);
63
64 // The alignments here can be mapped to the flexbox CSS assignments: align-items, align-content
65 //
66 // alignItems: AlignStart | AlignCenter | AlignEnd | AlignStretch
67 // Note: AlignSpace* not supported by the flexAlignItems
68 //
69 // alignContent: AlignStart | AlignEnd | AlignCenter | AlignStretch | AlignSpaceBetween |
70 // AlignSpaceAround
71 //
72 // For instance, consider placing the items are placed within the flex with flexDirection
73 // set to Row
74 //
75 // alignItems - This property causes flex items to be positioned as below with respective
76 // value set
77 //
78 // AlignStart - Flex items are positioned from the start of the cross axis
79 // [[Item1][Item2][Item3][Item4][Item5]...]
80 // AlignEnd - Flex items are positioned from the end of the cross axis
81 // [...[Item1][Item2][Item3][Item4][Item5]]
82 // AlignStretch - Flex items are stretched along the cross axis
83 // || | | | | ||
84 // ||Item1|Item2|Item3|Item4|Item5||
85 // || | | | | ||
86 // AlignCenter - Flex items are centered along the cross axis
87 // | | ||
88 // |[Item1][Item2][Item3][Item4]|Item5||
89 // | | ||
90 //
91 // alignContent - This property causes flex items to be positioned considering space around
92 // edge lines and in-between with respective value set
93 //
94 // AlignStart - Lines are packed towards the start of the container
95 // [[Item1][Item2][Item3][Item4][Item5]...]
96 // AlignEnd - Lines are packed towards the end of the container
97 // [...[Item1][Item2][Item3][Item4][Item5]]
98 // AlignCenter - Lines are packed towards the center
99 // || | | | | ||
100 // ||Item1|Item2|Item3|Item4|Item5||
101 // || | | | | ||
102 // AlignSpaceBetween - Lines are packed at the edges of the container and spaces
103 // are placed in-between rows of the flex items
104 // |[Item1][Item2][Item3]|
105 // | |
106 // |[Item4][Item5][Item6]|
107 // AlignSpaceAround - Spaces are placed in-between the rows of the flex items and
108 // would be shared around the edges (i.e. the space between the
109 // items and at the edge of the container will vary)
110 // | |
111 // |[Item1][Item2][Item3]|
112 // | |
113 // | |
114 // |[Item4][Item5][Item6]|
115 // | |
116 // AlignStretch - Lines are stretched and there will be no space in-between
117 // |[Item1][Item2][Item3]|
118 // |[Item4][Item5][Item6]|
119 enum FlexboxAlignment {
120 AlignAuto = 0,
121 AlignStart,
122 AlignCenter,
123 AlignEnd,
124 AlignStretch, // Same as Layout.fillHeight or Layout.fillWidth
125 AlignBaseline,
126 AlignSpaceBetween,
127 AlignSpaceAround,
128 AlignSpaceEvenly
129 };
130 Q_ENUM(FlexboxAlignment)
131
132 // The alignments can be used for justify-content
133 enum FlexboxJustify {
134 JustifyStart,
135 JustifyCenter,
136 JustifyEnd,
137 JustifySpaceBetween,
138 JustifySpaceAround,
139 JustifySpaceEvenly
140 };
141 Q_ENUM(FlexboxJustify)
142
143 // The alignments can be used for justify-content
144 enum FlexboxEdge {
145 EdgeLeft,
146 EdgeRight,
147 EdgeTop,
148 EdgeBottom,
149 EdgeAll,
150 EdgeMax
151 };
152 Q_ENUM(FlexboxEdge)
153
154 // The alignments can be used for justify-content
155 enum FlexboxGap {
156 GapRow,
157 GapColumn,
158 GapAll,
159 GapMax
160 };
161 Q_ENUM(FlexboxGap)
162
163 FlexboxDirection direction() const;
164 void setDirection(FlexboxDirection);
165
166 FlexboxWrap wrap() const;
167 void setWrap(FlexboxWrap);
168
169 FlexboxAlignment alignItems() const;
170 void setAlignItems(FlexboxAlignment);
171
172 FlexboxJustify justifyContent() const;
173 void setJustifyContent(FlexboxJustify);
174
175 FlexboxAlignment alignContent() const;
176 void setAlignContent(FlexboxAlignment);
177
178 qreal gap() const;
179 void setGap(qreal);
180 void resetGap();
181
182 qreal rowGap() const;
183 void setRowGap(qreal);
184 void resetRowGap();
185
186 qreal columnGap() const;
187 void setColumnGap(qreal);
188 void resetColumnGap();
189
190 void componentComplete() override;
191 QSizeF sizeHint(Qt::SizeHint whichSizeHint) const override;
192 void setAlignment(QQuickItem *, Qt::Alignment) override {}
193 void setStretchFactor(QQuickItem *, int, Qt::Orientation) override {}
194
195 void invalidate(QQuickItem *childItem = nullptr) override;
196 void updateLayoutItems() override;
197 void rearrange(const QSizeF &) override;
198
199 // iterator
200 QQuickItem *itemAt(int index) const override;
201 int itemCount() const override;
202
203 /* QQuickItemChangeListener */
204 void itemSiblingOrderChanged(QQuickItem *item) override;
205 void itemVisibilityChanged(QQuickItem *item) override;
206
207 /* internal */
208 static QQuickFlexboxLayoutAttached *qmlAttachedProperties(QObject *object);
209 bool isGapBitSet(QQuickFlexboxLayout::FlexboxGap gap) const;
210 void checkAnchors(QQuickItem *item) const;
211
212Q_SIGNALS:
213 void countChanged();
214 void directionChanged();
215 void wrapChanged();
216 void alignItemsChanged();
217 void alignContentChanged();
218 void justifyContentChanged();
219 void gapChanged();
220 void rowGapChanged();
221 void columnGapChanged();
222
223private:
224 void childItemsChanged();
225
226 friend class QQuickFlexboxLayoutAttached;
227 Q_DECLARE_PRIVATE(QQuickFlexboxLayout)
228};
229
230class Q_QUICKLAYOUTS_EXPORT QQuickFlexboxLayoutAttached : public QObject
231{
232 Q_OBJECT
233
234 Q_PROPERTY(QQuickFlexboxLayout::FlexboxAlignment alignSelf READ alignSelf WRITE setAlignSelf NOTIFY alignSelfChanged FINAL)
235
236public:
237 QQuickFlexboxLayoutAttached(QObject *object);
238
239 QQuickFlexboxLayout::FlexboxAlignment alignSelf() const;
240 void setAlignSelf(const QQuickFlexboxLayout::FlexboxAlignment);
241
242Q_SIGNALS:
243 void alignSelfChanged();
244
245private:
246 // The child item in the flex layout allowed to override the parent align-item property
247 QQuickFlexboxLayout::FlexboxAlignment m_alignSelf = QQuickFlexboxLayout::AlignAuto;
248};
249
250QT_END_NAMESPACE
251
252#endif // QQUICKFLEXBOXLAYOUT_H