diff options
author | Martin Jones <martin.jones@nokia.com> | 2010-12-08 06:22:04 (GMT) |
---|---|---|
committer | Martin Jones <martin.jones@nokia.com> | 2010-12-08 06:22:04 (GMT) |
commit | ddeae91ab54bb92b813304778ab8dc4037937274 (patch) | |
tree | 288fe02be046450333d963d0a74071cce06f9c60 /src | |
parent | f3a7c4e458edb40957186e52012f15767eb8c1f4 (diff) | |
download | Qt-ddeae91ab54bb92b813304778ab8dc4037937274.zip Qt-ddeae91ab54bb92b813304778ab8dc4037937274.tar.gz Qt-ddeae91ab54bb92b813304778ab8dc4037937274.tar.bz2 |
ListView: Fix calculation of currentItem position when out of view.
The calculation of position of currentItem when it is out of the
visible area was bogus.
Task-number: QTBUG-15525
Reviewed-by: Bea Lam
Diffstat (limited to 'src')
-rw-r--r-- | src/declarative/graphicsitems/qdeclarativelistview.cpp | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativelistview.cpp b/src/declarative/graphicsitems/qdeclarativelistview.cpp index 845da79..2dfee3b 100644 --- a/src/declarative/graphicsitems/qdeclarativelistview.cpp +++ b/src/declarative/graphicsitems/qdeclarativelistview.cpp @@ -739,16 +739,20 @@ void QDeclarativeListViewPrivate::layout() return; } if (!visibleItems.isEmpty()) { - qreal oldEnd = visibleItems.last()->endPosition(); + bool fixedCurrent = currentItem && visibleItems.first()->item == currentItem->item; + qreal sum = visibleItems.first()->size(); qreal pos = visibleItems.first()->position() + visibleItems.first()->size() + spacing; for (int i=1; i < visibleItems.count(); ++i) { FxListItem *item = visibleItems.at(i); item->setPosition(pos); pos += item->size() + spacing; + sum += item->size(); + fixedCurrent = fixedCurrent || (currentItem && item->item == currentItem->item); } - // move current item if it is after the visible items. - if (currentItem && currentIndex > lastVisibleIndex()) - currentItem->setPosition(currentItem->position() + (visibleItems.last()->endPosition() - oldEnd)); + averageSize = qRound(sum / visibleItems.count()); + // move current item if it is not a visible item. + if (currentIndex >= 0 && currentItem && !fixedCurrent) + currentItem->setPosition(positionAt(currentIndex)); } q->refill(); minExtentDirty = true; |