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 QQUICKLINEARLAYOUT_P_H
5#define QQUICKLINEARLAYOUT_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtQuickLayouts/private/qquicklayoutglobal_p.h>
19#include "qquicklayout_p.h"
20#include "qquickgridlayoutengine_p.h"
21
22QT_BEGIN_NAMESPACE
23
24/**********************************
25 **
26 ** QQuickGridLayoutBase
27 **
28 **/
29class QQuickGridLayoutBasePrivate;
30
31class Q_QUICKLAYOUTS_PRIVATE_EXPORT QQuickGridLayoutBase : public QQuickLayout
32{
33 Q_OBJECT
34
35 Q_PROPERTY(Qt::LayoutDirection layoutDirection READ layoutDirection WRITE setLayoutDirection
36 NOTIFY layoutDirectionChanged REVISION(1, 1) FINAL)
37 QML_ANONYMOUS
38 QML_ADDED_IN_VERSION(1, 1)
39
40public:
41
42 QQuickGridLayoutBase();
43
44 explicit QQuickGridLayoutBase(QQuickGridLayoutBasePrivate &dd,
45 Qt::Orientation orientation,
46 QQuickItem *parent = nullptr);
47
48 ~QQuickGridLayoutBase();
49 void componentComplete() override;
50 void invalidate(QQuickItem *childItem = nullptr) override;
51 Qt::Orientation orientation() const;
52 void setOrientation(Qt::Orientation orientation);
53 QSizeF sizeHint(Qt::SizeHint whichSizeHint) const override;
54 Qt::LayoutDirection layoutDirection() const;
55 void setLayoutDirection(Qt::LayoutDirection dir);
56 Qt::LayoutDirection effectiveLayoutDirection() const;
57 void setAlignment(QQuickItem *item, Qt::Alignment align) override;
58 void setStretchFactor(QQuickItem *item, int stretchFactor, Qt::Orientation orient) override;
59
60 /* QQuickItemChangeListener */
61 void itemDestroyed(QQuickItem *item) override;
62 void itemVisibilityChanged(QQuickItem *item) override;
63
64protected:
65 void updateLayoutItems() override;
66 QQuickItem *itemAt(int index) const override;
67 int itemCount() const override;
68
69 void rearrange(const QSizeF &size) override;
70 virtual void insertLayoutItems() {}
71
72Q_SIGNALS:
73 Q_REVISION(1, 1) void layoutDirectionChanged();
74
75private:
76 void removeGridItem(QGridLayoutItem *gridItem);
77 Q_DECLARE_PRIVATE(QQuickGridLayoutBase)
78};
79
80class QQuickLayoutStyleInfo;
81
82class QQuickGridLayoutBasePrivate : public QQuickLayoutPrivate
83{
84 Q_DECLARE_PUBLIC(QQuickGridLayoutBase)
85
86public:
87 QQuickGridLayoutBasePrivate() : m_recurRearrangeCounter(0)
88 , m_rearranging(false)
89 , m_layoutDirection(Qt::LeftToRight)
90 {}
91
92 void mirrorChange() override
93 {
94 Q_Q(QQuickGridLayoutBase);
95 q->invalidate();
96 }
97
98 QQuickGridLayoutEngine engine;
99 Qt::Orientation orientation;
100 unsigned m_recurRearrangeCounter : 2;
101 unsigned m_rearranging : 1;
102 QVector<QQuickItem *> m_invalidateAfterRearrange;
103 Qt::LayoutDirection m_layoutDirection : 2;
104
105 QQuickLayoutStyleInfo *styleInfo;
106};
107
108/**********************************
109 **
110 ** QQuickGridLayout
111 **
112 **/
113class QQuickGridLayoutPrivate;
114class Q_QUICKLAYOUTS_PRIVATE_EXPORT QQuickGridLayout : public QQuickGridLayoutBase
115{
116 Q_OBJECT
117
118 Q_PROPERTY(qreal columnSpacing READ columnSpacing WRITE setColumnSpacing NOTIFY columnSpacingChanged FINAL)
119 Q_PROPERTY(qreal rowSpacing READ rowSpacing WRITE setRowSpacing NOTIFY rowSpacingChanged FINAL)
120 Q_PROPERTY(int columns READ columns WRITE setColumns NOTIFY columnsChanged FINAL)
121 Q_PROPERTY(int rows READ rows WRITE setRows NOTIFY rowsChanged FINAL)
122 Q_PROPERTY(Flow flow READ flow WRITE setFlow NOTIFY flowChanged FINAL)
123 Q_PROPERTY(bool uniformCellWidths READ uniformCellWidths WRITE setUniformCellWidths
124 NOTIFY uniformCellWidthsChanged REVISION(6, 6) FINAL)
125 Q_PROPERTY(bool uniformCellHeights READ uniformCellHeights WRITE setUniformCellHeights
126 NOTIFY uniformCellHeightsChanged REVISION(6, 6) FINAL)
127 QML_NAMED_ELEMENT(GridLayout)
128 QML_ADDED_IN_VERSION(1, 0)
129public:
130 explicit QQuickGridLayout(QQuickItem *parent = nullptr);
131 qreal columnSpacing() const;
132 void setColumnSpacing(qreal spacing);
133 qreal rowSpacing() const;
134 void setRowSpacing(qreal spacing);
135
136 int columns() const;
137 void setColumns(int columns);
138 int rows() const;
139 void setRows(int rows);
140
141 enum Flow { LeftToRight, TopToBottom };
142 Q_ENUM(Flow)
143 Flow flow() const;
144 void setFlow(Flow flow);
145
146 bool uniformCellWidths() const;
147 void setUniformCellWidths(bool uniformCellWidths);
148 bool uniformCellHeights() const;
149 void setUniformCellHeights(bool uniformCellHeights);
150
151 void insertLayoutItems() override;
152
153Q_SIGNALS:
154 void columnSpacingChanged();
155 void rowSpacingChanged();
156
157 void columnsChanged();
158 void rowsChanged();
159
160 void flowChanged();
161
162 Q_REVISION(6, 6) void uniformCellWidthsChanged();
163 Q_REVISION(6, 6) void uniformCellHeightsChanged();
164private:
165 Q_DECLARE_PRIVATE(QQuickGridLayout)
166};
167
168class QQuickGridLayoutPrivate : public QQuickGridLayoutBasePrivate
169{
170 Q_DECLARE_PUBLIC(QQuickGridLayout)
171public:
172 QQuickGridLayoutPrivate(): columns(-1), rows(-1), flow(QQuickGridLayout::LeftToRight) {}
173 int columns;
174 int rows;
175 QQuickGridLayout::Flow flow;
176};
177
178
179/**********************************
180 **
181 ** QQuickLinearLayout
182 **
183 **/
184class QQuickLinearLayoutPrivate;
185class Q_QUICKLAYOUTS_PRIVATE_EXPORT QQuickLinearLayout : public QQuickGridLayoutBase
186{
187 Q_OBJECT
188 Q_PROPERTY(qreal spacing READ spacing WRITE setSpacing NOTIFY spacingChanged FINAL)
189 Q_PROPERTY(bool uniformCellSizes READ uniformCellSizes WRITE setUniformCellSizes
190 NOTIFY uniformCellSizesChanged REVISION(6, 6) FINAL)
191public:
192 explicit QQuickLinearLayout(Qt::Orientation orientation,
193 QQuickItem *parent = nullptr);
194 void insertLayoutItem(QQuickItem *item);
195 qreal spacing() const;
196 void setSpacing(qreal spacing);
197 bool uniformCellSizes() const;
198 void setUniformCellSizes(bool uniformCellSizes);
199
200 void insertLayoutItems() override;
201
202Q_SIGNALS:
203 void spacingChanged();
204 Q_REVISION(6, 6) void uniformCellSizesChanged();
205private:
206 Q_DECLARE_PRIVATE(QQuickLinearLayout)
207};
208
209class QQuickLinearLayoutPrivate : public QQuickGridLayoutBasePrivate
210{
211 Q_DECLARE_PUBLIC(QQuickLinearLayout)
212public:
213 QQuickLinearLayoutPrivate() {}
214};
215
216
217/**********************************
218 **
219 ** QQuickRowLayout
220 **
221 **/
222class Q_QUICKLAYOUTS_PRIVATE_EXPORT QQuickRowLayout : public QQuickLinearLayout
223{
224 Q_OBJECT
225 QML_NAMED_ELEMENT(RowLayout)
226 QML_ADDED_IN_VERSION(1, 0)
227
228public:
229 explicit QQuickRowLayout(QQuickItem *parent = nullptr)
230 : QQuickLinearLayout(Qt::Horizontal, parent) {}
231};
232
233
234/**********************************
235 **
236 ** QQuickColumnLayout
237 **
238 **/
239class Q_QUICKLAYOUTS_PRIVATE_EXPORT QQuickColumnLayout : public QQuickLinearLayout
240{
241 Q_OBJECT
242 QML_NAMED_ELEMENT(ColumnLayout)
243 QML_ADDED_IN_VERSION(1, 0)
244
245public:
246 explicit QQuickColumnLayout(QQuickItem *parent = nullptr)
247 : QQuickLinearLayout(Qt::Vertical, parent) {}
248};
249
250QT_END_NAMESPACE
251
252#endif // QQUICKLINEARLAYOUT_P_H
253

source code of qtdeclarative/src/quicklayouts/qquicklinearlayout_p.h