diff options
author | Bea Lam <bea.lam@nokia.com> | 2011-09-23 11:40:25 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-10-03 01:38:02 +0200 |
commit | 54da515e5e5f65e7ae253280038aad912780de12 (patch) | |
tree | 183f92b4978b613db9fb139b87a8ad3d4019de3b /src | |
parent | 3176222ad06478b3aae752f59e14d63ffcd952c7 (diff) |
Don't move content forwards when items are moved down
Previously, if items moved down within a view, the content position
would effectively drop down. E.g. for a (0,5,3) move that moved 3
items from 0 to 5, the content y would move to the position of index
3, since it became the new first item. However, this makes it
difficult to move transitions for move() operations in these cases
since these items do not move (since the content position moves
instead). With this fix, the content position does not move, and items
will always move if they are moved.
Note this behaviour was previously implemented for backwards
movements, e.g. a (5,0,3) move but was not enabled for a forwards
(0,5,3) move.
Change-Id: I1c5a19e3c36347a4aa0cf6e31c975967a7eeada9
Reviewed-on: http://codereview.qt-project.org/5576
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Martin Jones <martin.jones@nokia.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/declarative/items/qsggridview.cpp | 2 | ||||
-rw-r--r-- | src/declarative/items/qsgitemview.cpp | 15 | ||||
-rw-r--r-- | src/declarative/items/qsglistview.cpp | 2 |
3 files changed, 17 insertions, 2 deletions
diff --git a/src/declarative/items/qsggridview.cpp b/src/declarative/items/qsggridview.cpp index dfcd1b200c..099d62ee45 100644 --- a/src/declarative/items/qsggridview.cpp +++ b/src/declarative/items/qsggridview.cpp @@ -574,6 +574,8 @@ void QSGGridViewPrivate::repositionPackageItemAt(QSGItem *item, int index) void QSGGridViewPrivate::resetItemPosition(FxViewItem *item, FxViewItem *toItem) { + if (item == toItem) + return; FxGridItemSG *toGridItem = static_cast<FxGridItemSG*>(toItem); static_cast<FxGridItemSG*>(item)->setPosition(toGridItem->colPos(), toGridItem->rowPos()); } diff --git a/src/declarative/items/qsgitemview.cpp b/src/declarative/items/qsgitemview.cpp index 63040c1a51..666b47198a 100644 --- a/src/declarative/items/qsgitemview.cpp +++ b/src/declarative/items/qsgitemview.cpp @@ -1489,16 +1489,27 @@ bool QSGItemViewPrivate::applyModelChanges() for (int i=0; i<addedItems.count(); ++i) addedItems.at(i)->attached->emitAdd(); - // if first visible item is moving but another item is moving up to replace it, - // do this positioning now to avoid shifting all content forwards + // if the first visible item has moved, ensure another one takes its place + // so that we avoid shifting all content forwards + // (don't use items from removedBeforeFirstVisible - if an item is removed from + // before the first visible, the first visible should not move upwards) if (firstVisible && firstItemIndex >= 0) { + bool found = false; for (int i=0; i<movedBackwards.count(); i++) { if (movedBackwards[i]->index == firstItemIndex) { + // an item has moved backwards up to the first visible's position resetItemPosition(movedBackwards[i], firstVisible); movedBackwards.removeAt(i); + found = true; break; } } + if (!found) { + // first visible item has moved forward, another item takes its place + FxViewItem *item = visibleItem(firstItemIndex); + if (item) + resetItemPosition(item, firstVisible); + } } // Ensure we don't cause an ugly list scroll diff --git a/src/declarative/items/qsglistview.cpp b/src/declarative/items/qsglistview.cpp index 4aaf131ece..7f9ce3ac8b 100644 --- a/src/declarative/items/qsglistview.cpp +++ b/src/declarative/items/qsglistview.cpp @@ -716,6 +716,8 @@ void QSGListViewPrivate::repositionPackageItemAt(QSGItem *item, int index) void QSGListViewPrivate::resetItemPosition(FxViewItem *item, FxViewItem *toItem) { + if (item == toItem) + return; static_cast<FxListItemSG*>(item)->setPosition(toItem->position()); } |