Skip to content

Commit

Permalink
Improved transitions for Row, Column, Grid, Flow
Browse files Browse the repository at this point in the history
The view transitions functionality for ListView and GridView has been
integrated into the positioner elements. Not all of this
functionality is available for positioners, though, since they don't
have models (and thus cannot identify certain model operations) and
they don't manage the lifetime of their children.

Task-number: QTBUG-24336

Change-Id: I71588de289555d2ef5a763af11358bc0af7b31a7
Reviewed-by: Alan Alpert <alan.alpert@nokia.com>
  • Loading branch information
Bea Lam authored and Qt by Nokia committed Mar 2, 2012
1 parent 3b01983 commit 79608d6
Show file tree
Hide file tree
Showing 9 changed files with 908 additions and 183 deletions.
7 changes: 5 additions & 2 deletions doc/src/whatsnew.qdoc
Expand Up @@ -112,8 +112,11 @@ Setting Image sourceSize.width and sourceSize.height will now fit the image to t
Grid now has rowSpacing and columnSpacing properties. Spacing properties on positioners are now real numbers instead
of integers.

Positioners now have attached properties that can be used to determine a subitem's location within a
container such as Column or Row: Positioner.index, Positioner.isFirstItem, Positioner.isLastItem.
Positioner (Row, Column, Grid, Flow) improvements:
\list
\o Transitions used for \c add and \c move now have improved features: they can access a ViewTransition attached property (see the ViewTransition documentation for examples) and can now animate arbitrary item properties (instead of being restricted to animating an item's position).
\o Items in a positioner now have attached properties that can be used to determine a subitem's location: Positioner.index, Positioner.isFirstItem, Positioner.isLastItem.
\endlist

Loader improvements:
- "active" property added to Loader, to allow delaying instantiation of a Loader element's item property
Expand Down
34 changes: 31 additions & 3 deletions src/quick/items/qquickitemviewtransition.cpp
Expand Up @@ -377,6 +377,12 @@ bool QQuickViewItem::prepareTransition(const QRectF &viewBounds)
{
bool doTransition = false;

// If item is not already moving somewhere, set it to not move anywhere.
// This ensures that removed targets don't transition to the default (0,0) and that
// items set for other transition types only transition if they actually move somewhere.
if (nextTransitionType != QQuickItemViewTransitioner::NoTransition && !nextTransitionToSet)
moveTo(item->pos());

switch (nextTransitionType) {
case QQuickItemViewTransitioner::NoTransition:
{
Expand All @@ -390,7 +396,12 @@ bool QQuickViewItem::prepareTransition(const QRectF &viewBounds)
case QQuickItemViewTransitioner::RemoveTransition:
// For Add targets, do transition if item is moving into visible area
// For Remove targets, do transition if item is currently in visible area
if (isTransitionTarget) {
if (viewBounds.isNull()) {
if (isTransitionTarget)
doTransition = true;
else
doTransition = (nextTransitionTo != item->pos());
} else if (isTransitionTarget) {
doTransition = (nextTransitionType == QQuickItemViewTransitioner::AddTransition)
? viewBounds.intersects(QRectF(nextTransitionTo.x(), nextTransitionTo.y(), item->width(), item->height()))
: viewBounds.intersects(QRectF(item->x(), item->y(), item->width(), item->height()));
Expand All @@ -408,7 +419,8 @@ bool QQuickViewItem::prepareTransition(const QRectF &viewBounds)
case QQuickItemViewTransitioner::MoveTransition:
// do transition if moving from or into visible area
if (nextTransitionTo != item->pos()) {
doTransition = viewBounds.intersects(QRectF(item->x(), item->y(), item->width(), item->height()))
doTransition = viewBounds.isNull()
|| viewBounds.intersects(QRectF(item->x(), item->y(), item->width(), item->height()))
|| viewBounds.intersects(QRectF(nextTransitionTo.x(), nextTransitionTo.y(), item->width(), item->height()));
if (!doTransition)
item->setPos(nextTransitionTo);
Expand Down Expand Up @@ -503,7 +515,19 @@ QQuickViewTransitionAttached::QQuickViewTransitionAttached(QObject *parent)
generic displaced transition if specified)
\endlist
Such view transitions additionally have access to a ViewTransition attached property that
For the \l Row, \l Column, \l Grid and \l Flow positioner elements, which operate with collections of child
items rather than data models, the following properties are used instead:
\list
\o \c add - the transition to apply to items that are created for the positioner, added to
or reparented to the positioner, or items that have become \l {Item::}{visible}
\o \c move - the transition to apply to items that have moved within the positioner, including
when they are displaced due to the addition or removal of other items, or when items are otherwise
rearranged within the positioner, or when items are repositioned due to the resizing of other
items in the positioner
\endlist
View transitions have access to a ViewTransition attached property that
provides details of the items that are under transition and the operation that triggered the
transition. Since view transitions are run once per item, these details can be used to customise
each transition for each individual item.
Expand All @@ -525,6 +549,10 @@ QQuickViewTransitionAttached::QQuickViewTransitionAttached(QObject *parent)
\o ViewTransition.targetItems - the target items themselves
\endlist
(Note that for the \l Row, \l Column, \l Grid and \l Flow positioner elements, the \c move transition only
provides these two additional details when the transition is triggered by the addition of items
to a positioner.)
View transitions can be written without referring to any of the attributes listed
above. These attributes merely provide extra details that are useful for customising view
transitions.
Expand Down

0 comments on commit 79608d6

Please sign in to comment.