1 | // Copyright (C) 2018 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 | #include "qquickitemviewfxitem_p_p.h" |
5 | #include "qquickitem_p.h" |
6 | #include "qquickitemview_p_p.h" |
7 | |
8 | QT_BEGIN_NAMESPACE |
9 | |
10 | QQuickItemViewFxItem::QQuickItemViewFxItem(QQuickItem *item, bool ownItem, QQuickItemChangeListener* changeListener) |
11 | : item(item) |
12 | , changeListener(changeListener) |
13 | #if QT_CONFIG(quick_viewtransitions) |
14 | , transitionableItem(nullptr) |
15 | #endif |
16 | , ownItem(ownItem) |
17 | , releaseAfterTransition(false) |
18 | , trackGeom(false) |
19 | { |
20 | } |
21 | |
22 | QQuickItemViewFxItem::~QQuickItemViewFxItem() |
23 | { |
24 | #if QT_CONFIG(quick_viewtransitions) |
25 | delete transitionableItem; |
26 | transitionableItem = nullptr; |
27 | #endif |
28 | |
29 | if (ownItem && item) { |
30 | trackGeometry(track: false); |
31 | item->setParentItem(0); |
32 | item->deleteLater(); |
33 | } |
34 | } |
35 | |
36 | qreal QQuickItemViewFxItem::itemX() const |
37 | { |
38 | return |
39 | #if QT_CONFIG(quick_viewtransitions) |
40 | transitionableItem ? transitionableItem->itemX() : |
41 | #endif |
42 | (item ? item->x() : 0); |
43 | } |
44 | |
45 | qreal QQuickItemViewFxItem::itemY() const |
46 | { |
47 | return |
48 | #if QT_CONFIG(quick_viewtransitions) |
49 | transitionableItem ? transitionableItem->itemY() : |
50 | #endif |
51 | (item ? item->y() : 0); |
52 | } |
53 | |
54 | void QQuickItemViewFxItem::moveTo(const QPointF &pos, bool immediate) |
55 | { |
56 | #if QT_CONFIG(quick_viewtransitions) |
57 | if (transitionableItem) |
58 | transitionableItem->moveTo(pos, immediate); |
59 | else |
60 | #else |
61 | Q_UNUSED(immediate) |
62 | #endif |
63 | if (item) |
64 | item->setPosition(pos); |
65 | } |
66 | |
67 | void QQuickItemViewFxItem::setVisible(bool visible) |
68 | { |
69 | if (!visible |
70 | #if QT_CONFIG(quick_viewtransitions) |
71 | && transitionableItem && transitionableItem->transitionScheduledOrRunning() |
72 | #endif |
73 | ) |
74 | return; |
75 | if (item) |
76 | QQuickItemPrivate::get(item)->setCulled(!visible); |
77 | } |
78 | |
79 | void QQuickItemViewFxItem::trackGeometry(bool track) |
80 | { |
81 | if (track) { |
82 | if (!trackGeom) { |
83 | if (item) { |
84 | QQuickItemPrivate *itemPrivate = QQuickItemPrivate::get(item); |
85 | itemPrivate->addItemChangeListener(listener: changeListener, types: QQuickItemPrivate::Geometry); |
86 | } |
87 | trackGeom = true; |
88 | } |
89 | } else { |
90 | if (trackGeom) { |
91 | if (item) { |
92 | QQuickItemPrivate *itemPrivate = QQuickItemPrivate::get(item); |
93 | itemPrivate->removeItemChangeListener(changeListener, types: QQuickItemPrivate::Geometry); |
94 | } |
95 | trackGeom = false; |
96 | } |
97 | } |
98 | } |
99 | |
100 | QRectF QQuickItemViewFxItem::geometry() const |
101 | { |
102 | return QRectF(item->position(), item->size()); |
103 | } |
104 | |
105 | void QQuickItemViewFxItem::setGeometry(const QRectF &geometry) |
106 | { |
107 | item->setPosition(geometry.topLeft()); |
108 | item->setSize(geometry.size()); |
109 | } |
110 | |
111 | #if QT_CONFIG(quick_viewtransitions) |
112 | QQuickItemViewTransitioner::TransitionType QQuickItemViewFxItem::scheduledTransitionType() const |
113 | { |
114 | return transitionableItem ? transitionableItem->nextTransitionType : QQuickItemViewTransitioner::NoTransition; |
115 | } |
116 | |
117 | bool QQuickItemViewFxItem::transitionScheduledOrRunning() const |
118 | { |
119 | return transitionableItem ? transitionableItem->transitionScheduledOrRunning() : false; |
120 | } |
121 | |
122 | bool QQuickItemViewFxItem::transitionRunning() const |
123 | { |
124 | return transitionableItem ? transitionableItem->transitionRunning() : false; |
125 | } |
126 | |
127 | bool QQuickItemViewFxItem::isPendingRemoval() const |
128 | { |
129 | return transitionableItem ? transitionableItem->isPendingRemoval() : false; |
130 | } |
131 | |
132 | void QQuickItemViewFxItem::transitionNextReposition(QQuickItemViewTransitioner *transitioner, QQuickItemViewTransitioner::TransitionType type, bool asTarget) |
133 | { |
134 | if (!transitioner) |
135 | return; |
136 | if (!transitionableItem) |
137 | transitionableItem = new QQuickItemViewTransitionableItem(item); |
138 | transitioner->transitionNextReposition(item: transitionableItem, type, isTarget: asTarget); |
139 | } |
140 | |
141 | bool QQuickItemViewFxItem::prepareTransition(QQuickItemViewTransitioner *transitioner, const QRectF &viewBounds) |
142 | { |
143 | return transitionableItem ? transitionableItem->prepareTransition(transitioner, index, viewBounds) : false; |
144 | } |
145 | |
146 | void QQuickItemViewFxItem::startTransition(QQuickItemViewTransitioner *transitioner) |
147 | { |
148 | if (transitionableItem) |
149 | transitionableItem->startTransition(transitioner, index); |
150 | } |
151 | #endif |
152 | |
153 | QT_END_NAMESPACE |
154 | |
155 | |