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_P_H
5#define QQUICKPOSITIONERS_P_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 "qquickpositioners_p.h"
23#include "qquickimplicitsizeitem_p_p.h"
24
25#include <private/qlazilyallocated_p.h>
26
27#include <QtCore/qobject.h>
28#include <QtCore/qstring.h>
29#include <QtCore/qtimer.h>
30
31QT_BEGIN_NAMESPACE
32
33class QQuickItemViewTransitioner;
34
35class QQuickBasePositionerPrivate : public QQuickImplicitSizeItemPrivate, public QQuickItemChangeListener
36{
37 Q_DECLARE_PUBLIC(QQuickBasePositioner)
38
39public:
40 struct ExtraData {
41 ExtraData();
42
43 qreal padding;
44 qreal topPadding;
45 qreal leftPadding;
46 qreal rightPadding;
47 qreal bottomPadding;
48 bool explicitTopPadding : 1;
49 bool explicitLeftPadding : 1;
50 bool explicitRightPadding : 1;
51 bool explicitBottomPadding : 1;
52 };
53 QLazilyAllocated<ExtraData> extra;
54
55 QQuickBasePositionerPrivate()
56 : spacing(0), type(QQuickBasePositioner::None)
57#if QT_CONFIG(quick_viewtransitions)
58 , transitioner(0)
59#endif
60 , positioningDirty(false)
61 , doingPositioning(false), anchorConflict(false), layoutDirection(Qt::LeftToRight)
62
63 {
64 }
65
66 void init(QQuickBasePositioner::PositionerType at)
67 {
68 type = at;
69 }
70
71 qreal spacing;
72
73 QQuickBasePositioner::PositionerType type;
74#if QT_CONFIG(quick_viewtransitions)
75 QQuickItemViewTransitioner *transitioner;
76#endif
77
78 void watchChanges(QQuickItem *other);
79 void unwatchChanges(QQuickItem* other);
80 void setPositioningDirty() {
81 Q_Q(QQuickBasePositioner);
82 if (!positioningDirty) {
83 positioningDirty = true;
84 q->polish();
85 }
86 }
87
88 bool positioningDirty : 1;
89 bool doingPositioning : 1;
90 bool anchorConflict : 1;
91
92 Qt::LayoutDirection layoutDirection;
93
94 void mirrorChange() override {
95 effectiveLayoutDirectionChange();
96 }
97 bool isLeftToRight() const {
98 if (type == QQuickBasePositioner::Vertical)
99 return true;
100 else
101 return effectiveLayoutMirror ? layoutDirection == Qt::RightToLeft : layoutDirection == Qt::LeftToRight;
102 }
103
104 void itemSiblingOrderChanged(QQuickItem* other) override
105 {
106 Q_UNUSED(other);
107 setPositioningDirty();
108 }
109
110 void itemGeometryChanged(QQuickItem *, QQuickGeometryChange change, const QRectF &) override
111 {
112 if (change.sizeChange())
113 setPositioningDirty();
114 }
115
116 void itemVisibilityChanged(QQuickItem *) override
117 {
118 setPositioningDirty();
119 }
120
121 void itemDestroyed(QQuickItem *item) override
122 {
123 Q_Q(QQuickBasePositioner);
124 int index = q->positionedItems.find(v: QQuickBasePositioner::PositionedItem(item));
125 if (index >= 0)
126 q->removePositionedItem(items: &q->positionedItems, index);
127 }
128
129 static Qt::LayoutDirection getLayoutDirection(const QQuickBasePositioner *positioner)
130 {
131 return positioner->d_func()->layoutDirection;
132 }
133
134 static Qt::LayoutDirection getEffectiveLayoutDirection(const QQuickBasePositioner *positioner)
135 {
136 if (positioner->d_func()->effectiveLayoutMirror)
137 return positioner->d_func()->layoutDirection == Qt::RightToLeft ? Qt::LeftToRight : Qt::RightToLeft;
138 else
139 return positioner->d_func()->layoutDirection;
140 }
141
142 virtual void effectiveLayoutDirectionChange()
143 {
144 }
145
146 inline qreal padding() const { return extra.isAllocated() ? extra->padding : 0.0; }
147 void setTopPadding(qreal value, bool reset = false);
148 void setLeftPadding(qreal value, bool reset = false);
149 void setRightPadding(qreal value, bool reset = false);
150 void setBottomPadding(qreal value, bool reset = false);
151};
152
153QT_END_NAMESPACE
154
155#endif // QQUICKPOSITIONERS_P_P_H
156

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