From: Bea Lam Date: Fri, 17 Feb 2012 02:38:53 +0000 (+1000) Subject: Take QDeclarativeTransition::enabled() into account X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=dbaccf95532eec3a2b68a0cf5b4ba824ee084706;p=konrad%2Fqtdeclarative.git Take QDeclarativeTransition::enabled() into account Don't run transitions if enabled() is false Change-Id: I1df5479f8415b12837df8d54aa3902e072c73037 Reviewed-by: Martin Jones --- diff --git a/src/quick/items/qquickgridview.cpp b/src/quick/items/qquickgridview.cpp index 39c7eab..d7f4b80 100644 --- a/src/quick/items/qquickgridview.cpp +++ b/src/quick/items/qquickgridview.cpp @@ -485,7 +485,7 @@ bool QQuickGridViewPrivate::addVisibleItems(qreal fillFrom, qreal fillTo, bool d #endif if (!(item = static_cast(createItem(modelIndex, doBuffer)))) break; - if (!(usePopulateTransition && populateTransition)) // pos will be set by layoutVisibleItems() + if (!canTransition(FxViewItemTransitionManager::PopulateTransition, true)) // pos will be set by layoutVisibleItems() item->setPosition(colPos, rowPos); item->item->setVisible(!doBuffer); visibleItems.append(item); @@ -523,7 +523,7 @@ bool QQuickGridViewPrivate::addVisibleItems(qreal fillFrom, qreal fillTo, bool d if (!(item = static_cast(createItem(visibleIndex-1, doBuffer)))) break; --visibleIndex; - if (!(usePopulateTransition && populateTransition)) // pos will be set by layoutVisibleItems() + if (!canTransition(FxViewItemTransitionManager::PopulateTransition, true)) // pos will be set by layoutVisibleItems() item->setPosition(colPos, rowPos); item->item->setVisible(!doBuffer); visibleItems.prepend(item); @@ -2176,7 +2176,7 @@ bool QQuickGridViewPrivate::applyInsertionChange(const QDeclarativeChangeSet::In if (change.isMove()) { // we know this is a move target, since move displaced items that are // shuffled into view due to a move would be added in refill() - if (moveTransition && newItem) + if (canTransition(FxViewItemTransitionManager::MoveTransition, true) && newItem) movingIntoView->append(MovedItem(item, change.moveKey(item->index))); } else { addedItems->append(item); diff --git a/src/quick/items/qquickitemview.cpp b/src/quick/items/qquickitemview.cpp index eee1504..57b3521 100644 --- a/src/quick/items/qquickitemview.cpp +++ b/src/quick/items/qquickitemview.cpp @@ -1464,51 +1464,61 @@ void QQuickItemViewPrivate::applyPendingChanges() layout(); } -bool QQuickItemViewPrivate::hasItemTransitions() const -{ - return populateTransition - || addTransition || addDisplacedTransition - || moveTransition || moveDisplacedTransition - || removeTransition || removeDisplacedTransition; -} - -void QQuickItemViewPrivate::transitionNextReposition(FxViewItem *item, FxViewItemTransitionManager::TransitionType type, bool isTarget) +bool QQuickItemViewPrivate::canTransition(FxViewItemTransitionManager::TransitionType type, bool asTarget) const { switch (type) { case FxViewItemTransitionManager::NoTransition: - return; + return false; case FxViewItemTransitionManager::PopulateTransition: - if (populateTransition) { - item->setNextTransition(FxViewItemTransitionManager::PopulateTransition, isTarget); - return; - } - break; + return usePopulateTransition + && populateTransition && populateTransition->enabled(); case FxViewItemTransitionManager::AddTransition: - if (!usePopulateTransition) { - if ((isTarget && addTransition) || (!isTarget && addDisplacedTransition)) { - item->setNextTransition(type, isTarget); - return; - } - } - break; + if (asTarget) + return addTransition && addTransition->enabled(); + else + return addDisplacedTransition && addDisplacedTransition->enabled(); case FxViewItemTransitionManager::MoveTransition: - if ((isTarget && moveTransition) || (!isTarget && moveDisplacedTransition)) { - item->setNextTransition(type, isTarget); - return; - } - break; + if (asTarget) + return moveTransition && moveTransition->enabled(); + else + return moveDisplacedTransition && moveDisplacedTransition->enabled(); case FxViewItemTransitionManager::RemoveTransition: - if ((isTarget && removeTransition) || (!isTarget && removeDisplacedTransition)) { - item->setNextTransition(type, isTarget); - return; - } - break; + if (asTarget) + return removeTransition && removeTransition->enabled(); + else + return removeDisplacedTransition && removeDisplacedTransition->enabled(); } +} - // the requested transition type is not valid, but the item is scheduled/in another - // transition, so cancel it to allow the item to move directly to the correct pos - if (item->transitionScheduledOrRunning()) - item->stopTransition(); +bool QQuickItemViewPrivate::hasItemTransitions() const +{ + return canTransition(FxViewItemTransitionManager::PopulateTransition, true) + || canTransition(FxViewItemTransitionManager::AddTransition, true) + || canTransition(FxViewItemTransitionManager::AddTransition, false) + || canTransition(FxViewItemTransitionManager::MoveTransition, true) + || canTransition(FxViewItemTransitionManager::MoveTransition, false) + || canTransition(FxViewItemTransitionManager::RemoveTransition, true) + || canTransition(FxViewItemTransitionManager::RemoveTransition, false); +} + +void QQuickItemViewPrivate::transitionNextReposition(FxViewItem *item, FxViewItemTransitionManager::TransitionType type, bool isTarget) +{ + bool matchedTransition = false; + if (type == FxViewItemTransitionManager::AddTransition) { + // don't run add transitions for added items while populating + matchedTransition = !usePopulateTransition && canTransition(type, isTarget); + } else { + matchedTransition = canTransition(type, isTarget); + } + + if (matchedTransition) { + item->setNextTransition(type, isTarget); + } else { + // the requested transition type is not valid, but the item is scheduled/in another + // transition, so cancel it to allow the item to move directly to the correct pos + if (item->transitionScheduledOrRunning()) + item->stopTransition(); + } } int QQuickItemViewPrivate::findMoveKeyIndex(QDeclarativeChangeSet::MoveKey key, const QVector &changes) const @@ -1590,7 +1600,7 @@ void QQuickItemView::destroyRemoved() it != d->visibleItems.end();) { FxViewItem *item = *it; if (item->index == -1 && item->attached->delayRemove() == false) { - if (d->removeTransition) { + if (d->canTransition(FxViewItemTransitionManager::RemoveTransition, true)) { // don't remove from visibleItems until next layout() d->runDelayedRemoveTransition = true; QObject::disconnect(item->attached, SIGNAL(delayRemoveChanged()), this, SLOT(destroyRemoved())); @@ -2253,7 +2263,7 @@ void QQuickItemViewPrivate::layout() return; } - if (runDelayedRemoveTransition && removeDisplacedTransition) { + if (runDelayedRemoveTransition && canTransition(FxViewItemTransitionManager::RemoveTransition, false)) { // assume that any items moving now are moving due to the remove - if they schedule // a different transition, that will override this one anyway for (int i=0; i= 0) { @@ -2618,13 +2630,10 @@ void QQuickItemViewPrivate::prepareVisibleItemTransitions() void QQuickItemViewPrivate::prepareRemoveTransitions(QHash *removedItems) { - if (!removeTransition && !removeDisplacedTransition) - return; - removeTransitionIndexes.clear(); removeTransitionTargets.clear(); - if (removeTransition) { + if (canTransition(FxViewItemTransitionManager::RemoveTransition, true)) { for (QHash::Iterator it = removedItems->begin(); it != removedItems->end(); ) { bool isRemove = it.key().moveId < 0; diff --git a/src/quick/items/qquickitemview_p_p.h b/src/quick/items/qquickitemview_p_p.h index 6768149..05927c0 100644 --- a/src/quick/items/qquickitemview_p_p.h +++ b/src/quick/items/qquickitemview_p_p.h @@ -247,6 +247,7 @@ public: void prepareRemoveTransitions(QHash *removedItems); bool prepareNonVisibleItemTransition(FxViewItem *item, const QRectF &viewBounds); + bool canTransition(FxViewItemTransitionManager::TransitionType type, bool asTarget) const; bool hasItemTransitions() const; void transitionNextReposition(FxViewItem *item, FxViewItemTransitionManager::TransitionType type, bool isTarget); int findMoveKeyIndex(QDeclarativeChangeSet::MoveKey key, const QVector &changes) const; diff --git a/src/quick/items/qquicklistview.cpp b/src/quick/items/qquicklistview.cpp index 03be177..906b9b3 100644 --- a/src/quick/items/qquicklistview.cpp +++ b/src/quick/items/qquicklistview.cpp @@ -629,7 +629,7 @@ bool QQuickListViewPrivate::addVisibleItems(qreal fillFrom, qreal fillTo, bool d #endif if (!(item = static_cast(createItem(modelIndex, doBuffer)))) break; - if (!(usePopulateTransition && populateTransition)) // pos will be set by layoutVisibleItems() + if (!canTransition(FxViewItemTransitionManager::PopulateTransition, true)) // pos will be set by layoutVisibleItems() item->setPosition(pos); item->item->setVisible(!doBuffer); pos += item->size() + spacing; @@ -649,7 +649,7 @@ bool QQuickListViewPrivate::addVisibleItems(qreal fillFrom, qreal fillTo, bool d break; --visibleIndex; visiblePos -= item->size() + spacing; - if (!(usePopulateTransition && populateTransition)) // pos will be set by layoutVisibleItems() + if (!canTransition(FxViewItemTransitionManager::PopulateTransition, true)) // pos will be set by layoutVisibleItems() item->setPosition(visiblePos); item->item->setVisible(!doBuffer); visibleItems.prepend(item); @@ -2755,7 +2755,7 @@ bool QQuickListViewPrivate::applyInsertionChange(const QDeclarativeChangeSet::In if (change.isMove()) { // we know this is a move target, since move displaced items that are // shuffled into view due to a move would be added in refill() - if (moveTransition && newItem) + if (canTransition(FxViewItemTransitionManager::MoveTransition, true) && newItem) movingIntoView->append(MovedItem(item, change.moveKey(item->index))); } else { addedItems->append(item);