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