| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2018 The Qt Company Ltd. |
| 4 | ** Contact: https://www.qt.io/licensing/ |
| 5 | ** |
| 6 | ** This file is part of the QtQuick module of the Qt Toolkit. |
| 7 | ** |
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ |
| 9 | ** Commercial License Usage |
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
| 11 | ** accordance with the commercial license agreement provided with the |
| 12 | ** Software or, alternatively, in accordance with the terms contained in |
| 13 | ** a written agreement between you and The Qt Company. For licensing terms |
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
| 15 | ** information use the contact form at https://www.qt.io/contact-us. |
| 16 | ** |
| 17 | ** GNU Lesser General Public License Usage |
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
| 19 | ** General Public License version 3 as published by the Free Software |
| 20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
| 21 | ** packaging of this file. Please review the following information to |
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements |
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
| 24 | ** |
| 25 | ** GNU General Public License Usage |
| 26 | ** Alternatively, this file may be used under the terms of the GNU |
| 27 | ** General Public License version 2.0 or (at your option) the GNU General |
| 28 | ** Public license version 3 or any later version approved by the KDE Free |
| 29 | ** Qt Foundation. The licenses are as published by the Free Software |
| 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
| 31 | ** included in the packaging of this file. Please review the following |
| 32 | ** information to ensure the GNU General Public License requirements will |
| 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
| 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
| 35 | ** |
| 36 | ** $QT_END_LICENSE$ |
| 37 | ** |
| 38 | ****************************************************************************/ |
| 39 | |
| 40 | #include "qquickitemviewfxitem_p_p.h" |
| 41 | #include "qquickitem_p.h" |
| 42 | #include "qquickitemview_p_p.h" |
| 43 | |
| 44 | QT_BEGIN_NAMESPACE |
| 45 | |
| 46 | QQuickItemViewFxItem::QQuickItemViewFxItem(QQuickItem *item, bool ownItem, QQuickItemChangeListener* changeListener) |
| 47 | : item(item) |
| 48 | , changeListener(changeListener) |
| 49 | , transitionableItem(nullptr) |
| 50 | , ownItem(ownItem) |
| 51 | , releaseAfterTransition(false) |
| 52 | , trackGeom(false) |
| 53 | { |
| 54 | } |
| 55 | |
| 56 | QQuickItemViewFxItem::~QQuickItemViewFxItem() |
| 57 | { |
| 58 | delete transitionableItem; |
| 59 | transitionableItem = nullptr; |
| 60 | |
| 61 | if (ownItem && item) { |
| 62 | trackGeometry(track: false); |
| 63 | item->setParentItem(0); |
| 64 | item->deleteLater(); |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | qreal QQuickItemViewFxItem::itemX() const |
| 69 | { |
| 70 | return transitionableItem ? transitionableItem->itemX() : (item ? item->x() : 0); |
| 71 | } |
| 72 | |
| 73 | qreal QQuickItemViewFxItem::itemY() const |
| 74 | { |
| 75 | return transitionableItem ? transitionableItem->itemY() : (item ? item->y() : 0); |
| 76 | } |
| 77 | |
| 78 | void QQuickItemViewFxItem::moveTo(const QPointF &pos, bool immediate) |
| 79 | { |
| 80 | if (transitionableItem) |
| 81 | transitionableItem->moveTo(pos, immediate); |
| 82 | else if (item) |
| 83 | item->setPosition(pos); |
| 84 | } |
| 85 | |
| 86 | void QQuickItemViewFxItem::setVisible(bool visible) |
| 87 | { |
| 88 | if (!visible && transitionableItem && transitionableItem->transitionScheduledOrRunning()) |
| 89 | return; |
| 90 | if (item) |
| 91 | QQuickItemPrivate::get(item)->setCulled(!visible); |
| 92 | } |
| 93 | |
| 94 | void QQuickItemViewFxItem::trackGeometry(bool track) |
| 95 | { |
| 96 | if (track) { |
| 97 | if (!trackGeom) { |
| 98 | if (item) { |
| 99 | QQuickItemPrivate *itemPrivate = QQuickItemPrivate::get(item); |
| 100 | itemPrivate->addItemChangeListener(listener: changeListener, types: QQuickItemPrivate::Geometry); |
| 101 | } |
| 102 | trackGeom = true; |
| 103 | } |
| 104 | } else { |
| 105 | if (trackGeom) { |
| 106 | if (item) { |
| 107 | QQuickItemPrivate *itemPrivate = QQuickItemPrivate::get(item); |
| 108 | itemPrivate->removeItemChangeListener(changeListener, types: QQuickItemPrivate::Geometry); |
| 109 | } |
| 110 | trackGeom = false; |
| 111 | } |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | QRectF QQuickItemViewFxItem::geometry() const |
| 116 | { |
| 117 | return QRectF(item->position(), item->size()); |
| 118 | } |
| 119 | |
| 120 | void QQuickItemViewFxItem::setGeometry(const QRectF &geometry) |
| 121 | { |
| 122 | item->setPosition(geometry.topLeft()); |
| 123 | item->setSize(geometry.size()); |
| 124 | } |
| 125 | |
| 126 | QQuickItemViewTransitioner::TransitionType QQuickItemViewFxItem::scheduledTransitionType() const |
| 127 | { |
| 128 | return transitionableItem ? transitionableItem->nextTransitionType : QQuickItemViewTransitioner::NoTransition; |
| 129 | } |
| 130 | |
| 131 | bool QQuickItemViewFxItem::transitionScheduledOrRunning() const |
| 132 | { |
| 133 | return transitionableItem ? transitionableItem->transitionScheduledOrRunning() : false; |
| 134 | } |
| 135 | |
| 136 | bool QQuickItemViewFxItem::transitionRunning() const |
| 137 | { |
| 138 | return transitionableItem ? transitionableItem->transitionRunning() : false; |
| 139 | } |
| 140 | |
| 141 | bool QQuickItemViewFxItem::isPendingRemoval() const |
| 142 | { |
| 143 | return transitionableItem ? transitionableItem->isPendingRemoval() : false; |
| 144 | } |
| 145 | |
| 146 | void QQuickItemViewFxItem::transitionNextReposition(QQuickItemViewTransitioner *transitioner, QQuickItemViewTransitioner::TransitionType type, bool asTarget) |
| 147 | { |
| 148 | if (!transitioner) |
| 149 | return; |
| 150 | if (!transitionableItem) |
| 151 | transitionableItem = new QQuickItemViewTransitionableItem(item); |
| 152 | transitioner->transitionNextReposition(item: transitionableItem, type, isTarget: asTarget); |
| 153 | } |
| 154 | |
| 155 | bool QQuickItemViewFxItem::prepareTransition(QQuickItemViewTransitioner *transitioner, const QRectF &viewBounds) |
| 156 | { |
| 157 | return transitionableItem ? transitionableItem->prepareTransition(transitioner, index, viewBounds) : false; |
| 158 | } |
| 159 | |
| 160 | void QQuickItemViewFxItem::startTransition(QQuickItemViewTransitioner *transitioner) |
| 161 | { |
| 162 | if (transitionableItem) |
| 163 | transitionableItem->startTransition(transitioner, index); |
| 164 | } |
| 165 | |
| 166 | QT_END_NAMESPACE |
| 167 | |
| 168 | |