summaryrefslogtreecommitdiffstats
path: root/src/declarative/graphicsitems/qdeclarativelistview.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/declarative/graphicsitems/qdeclarativelistview.cpp')
-rw-r--r--src/declarative/graphicsitems/qdeclarativelistview.cpp30
1 files changed, 20 insertions, 10 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativelistview.cpp b/src/declarative/graphicsitems/qdeclarativelistview.cpp
index 845da79..d008f91 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;
@@ -1567,7 +1571,8 @@ void QDeclarativeListView::setModel(const QVariant &model)
d->moveReason = QDeclarativeListViewPrivate::SetIndex;
d->updateCurrent(d->currentIndex);
if (d->highlight && d->currentItem) {
- d->highlight->setPosition(d->currentItem->position());
+ if (d->autoHighlight)
+ d->highlight->setPosition(d->currentItem->position());
d->updateTrackedItem();
}
}
@@ -1638,7 +1643,8 @@ void QDeclarativeListView::setDelegate(QDeclarativeComponent *delegate)
d->moveReason = QDeclarativeListViewPrivate::SetIndex;
d->updateCurrent(d->currentIndex);
if (d->highlight && d->currentItem) {
- d->highlight->setPosition(d->currentItem->position());
+ if (d->autoHighlight)
+ d->highlight->setPosition(d->currentItem->position());
d->updateTrackedItem();
}
}
@@ -2628,8 +2634,10 @@ void QDeclarativeListView::positionViewAtIndex(int index, int mode)
cancelFlick();
d->setPosition(pos);
if (d->highlight) {
- d->highlight->setPosition(d->currentItem->itemPosition());
- d->highlight->setSize(d->currentItem->itemSize());
+ if (d->autoHighlight) {
+ d->highlight->setPosition(d->currentItem->itemPosition());
+ d->highlight->setSize(d->currentItem->itemSize());
+ }
d->updateHighlight();
}
}
@@ -2675,7 +2683,8 @@ void QDeclarativeListView::componentComplete()
else
d->updateCurrent(d->currentIndex);
if (d->highlight && d->currentItem) {
- d->highlight->setPosition(d->currentItem->position());
+ if (d->autoHighlight)
+ d->highlight->setPosition(d->currentItem->position());
d->updateTrackedItem();
}
d->moveReason = QDeclarativeListViewPrivate::Other;
@@ -3138,7 +3147,8 @@ void QDeclarativeListView::modelReset()
d->moveReason = QDeclarativeListViewPrivate::SetIndex;
d->updateCurrent(d->currentIndex);
if (d->highlight && d->currentItem) {
- d->highlight->setPosition(d->currentItem->position());
+ if (d->autoHighlight)
+ d->highlight->setPosition(d->currentItem->position());
d->updateTrackedItem();
}
d->moveReason = QDeclarativeListViewPrivate::Other;