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 QQUICKPOSITIONERS_P_H
5#define QQUICKPOSITIONERS_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 <QtQuick/private/qtquickglobal_p.h>
19
20QT_REQUIRE_CONFIG(quick_positioners);
21
22#include "qquickimplicitsizeitem_p.h"
23#if QT_CONFIG(quick_viewtransitions)
24#include "qquickitemviewtransition_p.h"
25#endif
26
27#include <private/qpodvector_p.h>
28
29#include <QtCore/qobject.h>
30#include <QtCore/qstring.h>
31
32QT_BEGIN_NAMESPACE
33
34class QQuickBasePositionerPrivate;
35
36class QQuickPositionerAttached : public QObject
37{
38 Q_OBJECT
39
40public:
41 QQuickPositionerAttached(QObject *parent);
42
43 Q_PROPERTY(int index READ index NOTIFY indexChanged FINAL)
44 Q_PROPERTY(bool isFirstItem READ isFirstItem NOTIFY isFirstItemChanged FINAL)
45 Q_PROPERTY(bool isLastItem READ isLastItem NOTIFY isLastItemChanged FINAL)
46
47 int index() const { return m_index; }
48 void setIndex(int index);
49
50 bool isFirstItem() const { return m_isFirstItem; }
51 void setIsFirstItem(bool isFirstItem);
52
53 bool isLastItem() const { return m_isLastItem; }
54 void setIsLastItem(bool isLastItem);
55
56Q_SIGNALS:
57 void indexChanged();
58 void isFirstItemChanged();
59 void isLastItemChanged();
60
61private:
62 int m_index;
63 bool m_isFirstItem;
64 bool m_isLastItem;
65};
66
67class Q_QUICK_PRIVATE_EXPORT QQuickBasePositioner : public QQuickImplicitSizeItem
68{
69 Q_OBJECT
70
71 Q_PROPERTY(qreal spacing READ spacing WRITE setSpacing NOTIFY spacingChanged FINAL)
72#if QT_CONFIG(quick_viewtransitions)
73 Q_PROPERTY(QQuickTransition *populate READ populate WRITE setPopulate NOTIFY populateChanged FINAL)
74 Q_PROPERTY(QQuickTransition *move READ move WRITE setMove NOTIFY moveChanged FINAL)
75 Q_PROPERTY(QQuickTransition *add READ add WRITE setAdd NOTIFY addChanged FINAL)
76#endif
77
78 Q_PROPERTY(qreal padding READ padding WRITE setPadding RESET resetPadding NOTIFY paddingChanged REVISION(2, 6) FINAL)
79 Q_PROPERTY(qreal topPadding READ topPadding WRITE setTopPadding RESET resetTopPadding NOTIFY topPaddingChanged REVISION(2, 6) FINAL)
80 Q_PROPERTY(qreal leftPadding READ leftPadding WRITE setLeftPadding RESET resetLeftPadding NOTIFY leftPaddingChanged REVISION(2, 6) FINAL)
81 Q_PROPERTY(qreal rightPadding READ rightPadding WRITE setRightPadding RESET resetRightPadding NOTIFY rightPaddingChanged REVISION(2, 6) FINAL)
82 Q_PROPERTY(qreal bottomPadding READ bottomPadding WRITE setBottomPadding RESET resetBottomPadding NOTIFY bottomPaddingChanged REVISION(2, 6) FINAL)
83
84 QML_NAMED_ELEMENT(Positioner)
85 QML_ADDED_IN_VERSION(2, 0)
86 QML_UNCREATABLE("Positioner is an abstract type that is only available as an attached property.")
87 QML_ATTACHED(QQuickPositionerAttached)
88
89public:
90 enum PositionerType { None = 0x0, Horizontal = 0x1, Vertical = 0x2, Both = 0x3 };
91
92 QQuickBasePositioner(PositionerType, QQuickItem *parent);
93 ~QQuickBasePositioner();
94
95 qreal spacing() const;
96 void setSpacing(qreal);
97
98#if QT_CONFIG(quick_viewtransitions)
99 QQuickTransition *populate() const;
100 void setPopulate(QQuickTransition *);
101
102 QQuickTransition *move() const;
103 void setMove(QQuickTransition *);
104
105 QQuickTransition *add() const;
106 void setAdd(QQuickTransition *);
107#endif
108
109 static QQuickPositionerAttached *qmlAttachedProperties(QObject *obj);
110
111 void updateAttachedProperties(QQuickPositionerAttached *specificProperty = nullptr, QQuickItem *specificPropertyOwner = nullptr) const;
112
113 qreal padding() const;
114 void setPadding(qreal padding);
115 void resetPadding();
116
117 qreal topPadding() const;
118 void setTopPadding(qreal padding);
119 void resetTopPadding();
120
121 qreal leftPadding() const;
122 void setLeftPadding(qreal padding);
123 void resetLeftPadding();
124
125 qreal rightPadding() const;
126 void setRightPadding(qreal padding);
127 void resetRightPadding();
128
129 qreal bottomPadding() const;
130 void setBottomPadding(qreal padding);
131 void resetBottomPadding();
132
133 Q_REVISION(2, 9) Q_INVOKABLE void forceLayout();
134
135protected:
136 QQuickBasePositioner(QQuickBasePositionerPrivate &dd, PositionerType at, QQuickItem *parent);
137 void componentComplete() override;
138 void itemChange(ItemChange, const ItemChangeData &) override;
139
140 void updatePolish() override;
141
142Q_SIGNALS:
143 void spacingChanged();
144 void populateChanged();
145 void moveChanged();
146 void addChanged();
147 Q_REVISION(2, 6) void paddingChanged();
148 Q_REVISION(2, 6) void topPaddingChanged();
149 Q_REVISION(2, 6) void leftPaddingChanged();
150 Q_REVISION(2, 6) void rightPaddingChanged();
151 Q_REVISION(2, 6) void bottomPaddingChanged();
152 Q_REVISION(2, 9) void positioningComplete();
153
154protected Q_SLOTS:
155 void prePositioning();
156
157protected:
158 virtual void doPositioning(QSizeF *contentSize)=0;
159 virtual void reportConflictingAnchors()=0;
160
161 class PositionedItem
162 {
163 public :
164 PositionedItem(QQuickItem *i);
165 ~PositionedItem();
166 bool operator==(const PositionedItem &other) const { return other.item == item; }
167
168 qreal itemX() const;
169 qreal itemY() const;
170
171 void moveTo(const QPointF &pos);
172
173#if QT_CONFIG(quick_viewtransitions)
174 void transitionNextReposition(QQuickItemViewTransitioner *transitioner, QQuickItemViewTransitioner::TransitionType type, bool asTarget);
175 bool prepareTransition(QQuickItemViewTransitioner *transitioner, const QRectF &viewBounds);
176 void startTransition(QQuickItemViewTransitioner *transitioner);
177#endif
178
179 void updatePadding(qreal lp, qreal tp, qreal rp, qreal bp);
180
181 QQuickItem *item;
182#if QT_CONFIG(quick_viewtransitions)
183 QQuickItemViewTransitionableItem *transitionableItem;
184#endif
185 int index;
186 bool isNew;
187 bool isVisible;
188
189 qreal topPadding;
190 qreal leftPadding;
191 qreal rightPadding;
192 qreal bottomPadding;
193 };
194
195 QPODVector<PositionedItem,8> positionedItems;
196 QPODVector<PositionedItem,8> unpositionedItems;//Still 'in' the positioner, just not positioned
197
198 void positionItem(qreal x, qreal y, PositionedItem *target);
199 void positionItemX(qreal, PositionedItem *target);
200 void positionItemY(qreal, PositionedItem *target);
201
202 void removePositionedItem(QPODVector<PositionedItem,8> *items, int index);
203 void clearPositionedItems(QPODVector<PositionedItem,8> *items);
204
205private:
206 Q_DISABLE_COPY(QQuickBasePositioner)
207 Q_DECLARE_PRIVATE(QQuickBasePositioner)
208};
209
210class Q_QUICK_PRIVATE_EXPORT QQuickColumn : public QQuickBasePositioner
211{
212 Q_OBJECT
213 QML_NAMED_ELEMENT(Column)
214 QML_ADDED_IN_VERSION(2, 0)
215public:
216 QQuickColumn(QQuickItem *parent=nullptr);
217
218protected:
219 void doPositioning(QSizeF *contentSize) override;
220 void reportConflictingAnchors() override;
221};
222
223class QQuickRowPrivate;
224class Q_QUICK_PRIVATE_EXPORT QQuickRow: public QQuickBasePositioner
225{
226 Q_OBJECT
227 Q_PROPERTY(Qt::LayoutDirection layoutDirection READ layoutDirection WRITE setLayoutDirection NOTIFY layoutDirectionChanged FINAL)
228 Q_PROPERTY(Qt::LayoutDirection effectiveLayoutDirection READ effectiveLayoutDirection NOTIFY effectiveLayoutDirectionChanged FINAL)
229 QML_NAMED_ELEMENT(Row)
230 QML_ADDED_IN_VERSION(2, 0)
231
232public:
233 QQuickRow(QQuickItem *parent=nullptr);
234
235 Qt::LayoutDirection layoutDirection() const;
236 void setLayoutDirection (Qt::LayoutDirection);
237 Qt::LayoutDirection effectiveLayoutDirection() const;
238
239Q_SIGNALS:
240 void layoutDirectionChanged();
241 void effectiveLayoutDirectionChanged();
242
243protected:
244 void doPositioning(QSizeF *contentSize) override;
245 void reportConflictingAnchors() override;
246private:
247 Q_DECLARE_PRIVATE(QQuickRow)
248};
249
250class QQuickGridPrivate;
251class Q_QUICK_PRIVATE_EXPORT QQuickGrid : public QQuickBasePositioner
252{
253 Q_OBJECT
254 Q_PROPERTY(int rows READ rows WRITE setRows NOTIFY rowsChanged FINAL)
255 Q_PROPERTY(int columns READ columns WRITE setColumns NOTIFY columnsChanged FINAL)
256 Q_PROPERTY(qreal rowSpacing READ rowSpacing WRITE setRowSpacing NOTIFY rowSpacingChanged RESET resetRowSpacing FINAL)
257 Q_PROPERTY(qreal columnSpacing READ columnSpacing WRITE setColumnSpacing NOTIFY columnSpacingChanged RESET resetColumnSpacing FINAL)
258 Q_PROPERTY(Flow flow READ flow WRITE setFlow NOTIFY flowChanged FINAL)
259 Q_PROPERTY(Qt::LayoutDirection layoutDirection READ layoutDirection WRITE setLayoutDirection NOTIFY layoutDirectionChanged FINAL)
260 Q_PROPERTY(Qt::LayoutDirection effectiveLayoutDirection READ effectiveLayoutDirection NOTIFY effectiveLayoutDirectionChanged FINAL)
261 Q_PROPERTY(HAlignment horizontalItemAlignment READ hItemAlign WRITE setHItemAlign NOTIFY horizontalAlignmentChanged REVISION(2, 1) FINAL)
262 Q_PROPERTY(HAlignment effectiveHorizontalItemAlignment READ effectiveHAlign NOTIFY effectiveHorizontalAlignmentChanged REVISION(2, 1) FINAL)
263 Q_PROPERTY(VAlignment verticalItemAlignment READ vItemAlign WRITE setVItemAlign NOTIFY verticalAlignmentChanged REVISION(2, 1) FINAL)
264 QML_NAMED_ELEMENT(Grid)
265 QML_ADDED_IN_VERSION(2, 0)
266
267public:
268 QQuickGrid(QQuickItem *parent=nullptr);
269
270 int rows() const { return m_rows; }
271 void setRows(const int rows);
272
273 int columns() const { return m_columns; }
274 void setColumns(const int columns);
275
276 qreal rowSpacing() const { return m_rowSpacing; }
277 void setRowSpacing(qreal);
278 void resetRowSpacing() { m_useRowSpacing = false; }
279
280 qreal columnSpacing() const { return m_columnSpacing; }
281 void setColumnSpacing(qreal);
282 void resetColumnSpacing() { m_useColumnSpacing = false; }
283
284 enum Flow { LeftToRight, TopToBottom };
285 Q_ENUM(Flow)
286 Flow flow() const;
287 void setFlow(Flow);
288
289 Qt::LayoutDirection layoutDirection() const;
290 void setLayoutDirection (Qt::LayoutDirection);
291 Qt::LayoutDirection effectiveLayoutDirection() const;
292
293 enum HAlignment { AlignLeft = Qt::AlignLeft,
294 AlignRight = Qt::AlignRight,
295 AlignHCenter = Qt::AlignHCenter};
296 Q_ENUM(HAlignment)
297 enum VAlignment { AlignTop = Qt::AlignTop,
298 AlignBottom = Qt::AlignBottom,
299 AlignVCenter = Qt::AlignVCenter };
300 Q_ENUM(VAlignment)
301
302 HAlignment hItemAlign() const;
303 void setHItemAlign(HAlignment align);
304 HAlignment effectiveHAlign() const;
305
306 VAlignment vItemAlign() const;
307 void setVItemAlign(VAlignment align);
308
309Q_SIGNALS:
310 void rowsChanged();
311 void columnsChanged();
312 void flowChanged();
313 void layoutDirectionChanged();
314 void effectiveLayoutDirectionChanged();
315 void rowSpacingChanged();
316 void columnSpacingChanged();
317 Q_REVISION(2, 1) void horizontalAlignmentChanged(HAlignment alignment);
318 Q_REVISION(2, 1) void effectiveHorizontalAlignmentChanged(HAlignment alignment);
319 Q_REVISION(2, 1) void verticalAlignmentChanged(VAlignment alignment);
320
321protected:
322 void doPositioning(QSizeF *contentSize) override;
323 void reportConflictingAnchors() override;
324
325private:
326 int m_rows;
327 int m_columns;
328 qreal m_rowSpacing;
329 qreal m_columnSpacing;
330 bool m_useRowSpacing;
331 bool m_useColumnSpacing;
332 Flow m_flow;
333 HAlignment m_hItemAlign;
334 VAlignment m_vItemAlign;
335 Q_DECLARE_PRIVATE(QQuickGrid)
336};
337
338class QQuickFlowPrivate;
339class Q_QUICK_PRIVATE_EXPORT QQuickFlow: public QQuickBasePositioner
340{
341 Q_OBJECT
342 Q_PROPERTY(Flow flow READ flow WRITE setFlow NOTIFY flowChanged FINAL)
343 Q_PROPERTY(Qt::LayoutDirection layoutDirection READ layoutDirection WRITE setLayoutDirection NOTIFY layoutDirectionChanged FINAL)
344 Q_PROPERTY(Qt::LayoutDirection effectiveLayoutDirection READ effectiveLayoutDirection NOTIFY effectiveLayoutDirectionChanged FINAL)
345 QML_NAMED_ELEMENT(Flow)
346 QML_ADDED_IN_VERSION(2, 0)
347public:
348 QQuickFlow(QQuickItem *parent=nullptr);
349
350 enum Flow { LeftToRight, TopToBottom };
351 Q_ENUM(Flow)
352 Flow flow() const;
353 void setFlow(Flow);
354
355 Qt::LayoutDirection layoutDirection() const;
356 void setLayoutDirection (Qt::LayoutDirection);
357 Qt::LayoutDirection effectiveLayoutDirection() const;
358
359Q_SIGNALS:
360 void flowChanged();
361 void layoutDirectionChanged();
362 void effectiveLayoutDirectionChanged();
363
364protected:
365 void doPositioning(QSizeF *contentSize) override;
366 void reportConflictingAnchors() override;
367protected:
368 QQuickFlow(QQuickFlowPrivate &dd, QQuickItem *parent);
369private:
370 Q_DECLARE_PRIVATE(QQuickFlow)
371};
372
373
374QT_END_NAMESPACE
375
376QML_DECLARE_TYPE(QQuickColumn)
377QML_DECLARE_TYPE(QQuickRow)
378QML_DECLARE_TYPE(QQuickGrid)
379QML_DECLARE_TYPE(QQuickFlow)
380
381QML_DECLARE_TYPE(QQuickBasePositioner)
382
383#endif // QQUICKPOSITIONERS_P_H
384

source code of qtdeclarative/src/quick/items/qquickpositioners_p.h