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