aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/items/qquickgridview.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/quick/items/qquickgridview.cpp')
-rw-r--r--src/quick/items/qquickgridview.cpp163
1 files changed, 111 insertions, 52 deletions
diff --git a/src/quick/items/qquickgridview.cpp b/src/quick/items/qquickgridview.cpp
index a57d0ee778..45fbc9f93e 100644
--- a/src/quick/items/qquickgridview.cpp
+++ b/src/quick/items/qquickgridview.cpp
@@ -127,9 +127,6 @@ public:
return (x >= itemX() && x < itemX() + view->cellWidth() &&
y >= itemY() && y < itemY() + view->cellHeight());
}
- QQuickItemView *itemView() const {
- return view;
- }
QQuickGridView *view;
@@ -485,7 +482,7 @@ bool QQuickGridViewPrivate::addVisibleItems(qreal fillFrom, qreal fillTo, bool d
#endif
if (!(item = static_cast<FxGridItemSG*>(createItem(modelIndex, doBuffer))))
break;
- if (!canTransition(FxViewItemTransitionManager::PopulateTransition, true)) // pos will be set by layoutVisibleItems()
+ if (!transitioner || !transitioner->canTransition(QQuickItemViewTransitioner::PopulateTransition, true)) // pos will be set by layoutVisibleItems()
item->setPosition(colPos, rowPos);
item->item->setVisible(!doBuffer);
visibleItems.append(item);
@@ -523,7 +520,7 @@ bool QQuickGridViewPrivate::addVisibleItems(qreal fillFrom, qreal fillTo, bool d
if (!(item = static_cast<FxGridItemSG*>(createItem(visibleIndex-1, doBuffer))))
break;
--visibleIndex;
- if (!canTransition(FxViewItemTransitionManager::PopulateTransition, true)) // pos will be set by layoutVisibleItems()
+ if (!transitioner || !transitioner->canTransition(QQuickItemViewTransitioner::PopulateTransition, true)) // pos will be set by layoutVisibleItems()
item->setPosition(colPos, rowPos);
item->item->setVisible(!doBuffer);
visibleItems.prepend(item);
@@ -1586,10 +1583,11 @@ void QQuickGridView::setSnapMode(SnapMode mode)
/*!
\qmlproperty Transition QtQuick2::GridView::populate
- This property holds the transition to apply to items that are initially created for a
- view.
- This transition is applied to all the items that are created when:
+ This property holds the transition to apply to the items that are initially created
+ for a view.
+
+ It is applied to all items that are created when:
\list
\o The view is first created
@@ -1619,10 +1617,10 @@ void QQuickGridView::setSnapMode(SnapMode mode)
/*!
\qmlproperty Transition QtQuick2::GridView::add
- This property holds the transition to apply to items that are added within the view.
- The transition is applied to items that have been added to the visible area of the view. For
- example, here is a view that specifies such a transition:
+ This property holds the transition to apply to items that are added to the view.
+
+ For example, here is a view that specifies such a transition:
\code
GridView {
@@ -1636,8 +1634,8 @@ void QQuickGridView::setSnapMode(SnapMode mode)
Whenever an item is added to the above view, the item will be animated from the position (100,100)
to its final x,y position within the view, over one second. The transition only applies to
the new items that are added to the view; it does not apply to the items below that are
- displaced by the addition of the new items. To animate the displaced items, set the \l
- addDisplaced property.
+ displaced by the addition of the new items. To animate the displaced items, set the \l displaced
+ or \l addDisplaced properties.
For more details and examples on how to use view transitions, see the ViewTransition
documentation.
@@ -1651,11 +1649,11 @@ void QQuickGridView::setSnapMode(SnapMode mode)
/*!
\qmlproperty Transition QtQuick2::GridView::addDisplaced
- This property holds the transition to apply to items in the view that are displaced by other
- items that have been added to the view.
- The transition is applied to items that are currently visible and have been displaced by newly
- added items. For example, here is a view that specifies such a transition:
+ This property holds the transition to apply to items within the view that are displaced by
+ the addition of other items to the view.
+
+ For example, here is a view that specifies such a transition:
\code
GridView {
@@ -1673,6 +1671,11 @@ void QQuickGridView::setSnapMode(SnapMode mode)
the new item that has been added to the view; to animate the added items, set the \l add
property.
+ If an item is displaced by multiple types of operations at the same time, it is not defined as to
+ whether the addDisplaced, moveDisplaced or removeDisplaced transition will be applied. Additionally,
+ if it is not necessary to specify different transitions depending on whether an item is displaced
+ by an add, move or remove operation, consider setting the \l displaced property instead.
+
For more details and examples on how to use view transitions, see the ViewTransition
documentation.
@@ -1680,15 +1683,15 @@ void QQuickGridView::setSnapMode(SnapMode mode)
populated, or when the view's \l model changes. In those cases, the \l populate transition is
applied instead.
- \sa add, populate, ViewTransition
+ \sa displaced, add, populate, ViewTransition
*/
/*!
\qmlproperty Transition QtQuick2::GridView::move
- This property holds the transition to apply to items in the view that are moved by a move
- operation.
- The transition is applied to items that are moving within the view or are moving
- into the view as a result of a move operation in the view's model. For example:
+ This property holds the transition to apply to items in the view that are being moved due
+ to a move operation in the view's \l model.
+
+ For example, here is a view that specifies such a transition:
\code
GridView {
@@ -1699,10 +1702,11 @@ void QQuickGridView::setSnapMode(SnapMode mode)
}
\endcode
- Whenever an item is moved within the above view, the item will be animated to its new position in
- the view over one second. The transition only applies to the items that are the subject of the
- move operation in the model; it does not apply to the items below them that are displaced by
- the move operation. To animate the displaced items, set the \l moveDisplaced property.
+ Whenever the \l model performs a move operation to move a particular set of indexes, the
+ respective items in the view will be animated to their new positions in the view over one
+ second. The transition only applies to the items that are the subject of the move operation
+ in the model; it does not apply to items below them that are displaced by the move operation.
+ To animate the displaced items, set the \l displaced or \l moveDisplaced properties.
For more details and examples on how to use view transitions, see the ViewTransition
documentation.
@@ -1712,11 +1716,11 @@ void QQuickGridView::setSnapMode(SnapMode mode)
/*!
\qmlproperty Transition QtQuick2::GridView::moveDisplaced
- This property holds the transition to apply to items in the view that are displaced by a
- move operation in the view.
- The transition is applied to items that are currently visible and have been displaced following
- a move operation in the view's model. For example, here is a view that specifies such a transition:
+ This property holds the transition to apply to items that are displaced by a move operation in
+ the view's \l model.
+
+ For example, here is a view that specifies such a transition:
\code
GridView {
@@ -1727,25 +1731,31 @@ void QQuickGridView::setSnapMode(SnapMode mode)
}
\endcode
- Whenever an item moves within (or moves into) the above view, all items beneath it are
- displaced, causing them to move upwards (or sideways, if horizontally orientated) within the
- view. As this displacement occurs, the items' movement to their new x,y positions within the
- view will be animated by a NumberAnimation over one second, as specified. This transition is
- not applied to the item that are actually the subject of the move operation; to animate the
- moved items, set the \l move property.
+ Whenever the \l model performs a move operation to move a particular set of indexes, the items
+ between the source and destination indexes of the move operation are displaced, causing them
+ to move upwards or downwards (or sideways, if horizontally orientated) within the view. As this
+ displacement occurs, the items' movement to their new x,y positions within the view will be
+ animated by a NumberAnimation over one second, as specified. This transition is not applied to
+ the items that are the actual subjects of the move operation; to animate the moved items, set
+ the \l move property.
+
+ If an item is displaced by multiple types of operations at the same time, it is not defined as to
+ whether the addDisplaced, moveDisplaced or removeDisplaced transition will be applied. Additionally,
+ if it is not necessary to specify different transitions depending on whether an item is displaced
+ by an add, move or remove operation, consider setting the \l displaced property instead.
For more details and examples on how to use view transitions, see the ViewTransition
documentation.
- \sa move, ViewTransition
+ \sa displaced, move, ViewTransition
*/
/*!
\qmlproperty Transition QtQuick2::GridView::remove
+
This property holds the transition to apply to items that are removed from the view.
- The transition is applied to items that have been removed from the visible area of the view. For
- example:
+ For example, here is a view that specifies such a transition:
\code
GridView {
@@ -1762,8 +1772,8 @@ void QQuickGridView::setSnapMode(SnapMode mode)
Whenever an item is removed from the above view, the item will be animated to the position (100,100)
over one second, and in parallel will also change its opacity to 0. The transition
only applies to the items that are removed from the view; it does not apply to the items below
- them that are displaced by the removal of the items. To animate the displaced items, set the \l
- removeDisplaced property.
+ them that are displaced by the removal of the items. To animate the displaced items, set the
+ \l displaced or \l removeDisplaced properties.
Note that by the time the transition is applied, the item has already been removed from the
model; any references to the model data for the removed index will not be valid.
@@ -1779,11 +1789,11 @@ void QQuickGridView::setSnapMode(SnapMode mode)
/*!
\qmlproperty Transition QtQuick2::GridView::removeDisplaced
+
This property holds the transition to apply to items in the view that are displaced by the
removal of other items in the view.
- The transition is applied to items that are currently visible and have been displaced by
- the removal of items. For example, here is a view that specifies such a transition:
+ For example, here is a view that specifies such a transition:
\code
GridView {
@@ -1801,11 +1811,53 @@ void QQuickGridView::setSnapMode(SnapMode mode)
the item that has actually been removed from the view; to animate the removed items, set the
\l remove property.
+ If an item is displaced by multiple types of operations at the same time, it is not defined as to
+ whether the addDisplaced, moveDisplaced or removeDisplaced transition will be applied. Additionally,
+ if it is not necessary to specify different transitions depending on whether an item is displaced
+ by an add, move or remove operation, consider setting the \l displaced property instead.
+
For more details and examples on how to use view transitions, see the ViewTransition
documentation.
- \sa remove, ViewTransition
+ \sa displaced, remove, ViewTransition
*/
+
+/*!
+ \qmlproperty Transition QtQuick2::GridView::displaced
+ This property holds the generic transition to apply to items that have been displaced by
+ any model operation that affects the view.
+
+ This is a convenience for specifying a generic transition for items that are displaced
+ by add, move or remove operations, without having to specify the individual addDisplaced,
+ moveDisplaced and removeDisplaced properties. For example, here is a view that specifies
+ a displaced transition:
+
+ \code
+ GridView {
+ ...
+ displaced: Transition {
+ NumberAnimation { properties: "x,y"; duration: 1000 }
+ }
+ }
+ \endcode
+
+ When any item is added, moved or removed within the above view, the items below it are
+ displaced, causing them to move down (or sideways, if horizontally orientated) within the
+ view. As this displacement occurs, the items' movement to their new x,y positions within
+ the view will be animated by a NumberAnimation over one second, as specified.
+
+ If a view specifies this generic displaced transition as well as a specific addDisplaced,
+ moveDisplaced or removeDisplaced transition, the more specific transition will be used
+ instead of the generic displaced transition when the relevant operation occurs, providing that
+ the more specific transition has not been disabled (by setting \l {Transition::enabled}{enabled}
+ to false). If it has indeed been disabled, the generic displaced transition is applied instead.
+
+ For more details and examples on how to use view transitions, see the ViewTransition
+ documentation.
+
+ \sa addDisplaced, moveDisplaced, removeDisplaced, ViewTransition
+*/
+
void QQuickGridView::viewportMoved()
{
Q_D(QQuickGridView);
@@ -2109,10 +2161,12 @@ bool QQuickGridViewPrivate::applyInsertionChange(const QQuickChangeSet::Insert &
FxViewItem *item = visibleItems.at(i);
if (item->index != -1 && item->index >= modelIndex) {
item->index += count;
- if (change.isMove())
- transitionNextReposition(item, FxViewItemTransitionManager::MoveTransition, false);
- else
- transitionNextReposition(item, FxViewItemTransitionManager::AddTransition, false);
+ if (transitioner) {
+ if (change.isMove())
+ transitioner->transitionNextReposition(item, QQuickItemViewTransitioner::MoveTransition, false);
+ else
+ transitioner->transitionNextReposition(item, QQuickItemViewTransitioner::AddTransition, false);
+ }
}
}
@@ -2143,7 +2197,8 @@ bool QQuickGridViewPrivate::applyInsertionChange(const QQuickChangeSet::Insert &
insertResult->changedFirstItem = true;
if (!change.isMove()) {
addedItems->append(item);
- transitionNextReposition(item, FxViewItemTransitionManager::AddTransition, true);
+ if (transitioner)
+ transitioner->transitionNextReposition(item, QQuickItemViewTransitioner::AddTransition, true);
}
insertResult->sizeChangesBeforeVisiblePos += rowSize();
}
@@ -2176,11 +2231,12 @@ bool QQuickGridViewPrivate::applyInsertionChange(const QQuickChangeSet::Insert &
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 (canTransition(FxViewItemTransitionManager::MoveTransition, true) && newItem)
+ if (newItem && transitioner && transitioner->canTransition(QQuickItemViewTransitioner::MoveTransition, true))
movingIntoView->append(MovedItem(item, change.moveKey(item->index)));
} else {
addedItems->append(item);
- transitionNextReposition(item, FxViewItemTransitionManager::AddTransition, true);
+ if (transitioner)
+ transitioner->transitionNextReposition(item, QQuickItemViewTransitioner::AddTransition, true);
}
insertResult->sizeChangesAfterVisiblePos += rowSize();
@@ -2201,6 +2257,9 @@ bool QQuickGridViewPrivate::applyInsertionChange(const QQuickChangeSet::Insert &
void QQuickGridViewPrivate::translateAndTransitionItemsAfter(int afterModelIndex, const ChangeResult &insertionResult, const ChangeResult &removalResult)
{
+ if (!transitioner)
+ return;
+
int markerItemIndex = -1;
for (int i=0; i<visibleItems.count(); i++) {
if (visibleItems[i]->index == afterModelIndex) {
@@ -2228,7 +2287,7 @@ void QQuickGridViewPrivate::translateAndTransitionItemsAfter(int afterModelIndex
qreal origColPos = gridItem->rowPos();
int indexDiff = gridItem->index - countItemsRemoved;
gridItem->setPosition((indexDiff % columns) * colSize(), (indexDiff / columns) * rowSize());
- transitionNextReposition(gridItem, FxViewItemTransitionManager::RemoveTransition, false);
+ transitioner->transitionNextReposition(gridItem, QQuickItemViewTransitioner::RemoveTransition, false);
gridItem->setPosition(origRowPos, origColPos);
}
}