diff options
Diffstat (limited to 'src/declarative/graphicsitems/qdeclarativelistview.cpp')
-rw-r--r-- | src/declarative/graphicsitems/qdeclarativelistview.cpp | 36 |
1 files changed, 22 insertions, 14 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativelistview.cpp b/src/declarative/graphicsitems/qdeclarativelistview.cpp index e519bd9..91e9995 100644 --- a/src/declarative/graphicsitems/qdeclarativelistview.cpp +++ b/src/declarative/graphicsitems/qdeclarativelistview.cpp @@ -1547,6 +1547,10 @@ void QDeclarativeListView::setModel(const QVariant &model) } else { d->moveReason = QDeclarativeListViewPrivate::SetIndex; d->updateCurrent(d->currentIndex); + if (d->highlight && d->currentItem) { + d->highlight->setPosition(d->currentItem->position()); + d->updateTrackedItem(); + } } } connect(d->model, SIGNAL(itemsInserted(int,int)), this, SLOT(itemsInserted(int,int))); @@ -1610,6 +1614,10 @@ void QDeclarativeListView::setDelegate(QDeclarativeComponent *delegate) refill(); d->moveReason = QDeclarativeListViewPrivate::SetIndex; d->updateCurrent(d->currentIndex); + if (d->highlight && d->currentItem) { + d->highlight->setPosition(d->currentItem->position()); + d->updateTrackedItem(); + } } } emit delegateChanged(); @@ -1636,7 +1644,6 @@ void QDeclarativeListView::setCurrentIndex(int index) return; if (isComponentComplete() && d->isValid() && index != d->currentIndex && index < d->model->count() && index >= 0) { d->moveReason = QDeclarativeListViewPrivate::SetIndex; - cancelFlick(); d->updateCurrent(index); } else if (index != d->currentIndex) { d->currentIndex = index; @@ -1720,7 +1727,7 @@ void QDeclarativeListView::setHighlight(QDeclarativeComponent *highlight) highlight is not moved by the view, and any movement must be implemented by the highlight. - Here is a highlight with its motion defined by a \l {SpringFollow} item: + Here is a highlight with its motion defined by a \l {SpringAniamtion} item: \snippet doc/src/snippets/declarative/listview/listview.qml highlightFollowsCurrentItem @@ -2439,7 +2446,6 @@ void QDeclarativeListView::incrementCurrentIndex() if (currentIndex() < d->model->count() - 1 || d->wrap) { d->moveReason = QDeclarativeListViewPrivate::SetIndex; int index = currentIndex()+1; - cancelFlick(); d->updateCurrent(index < d->model->count() ? index : 0); } } @@ -2458,7 +2464,6 @@ void QDeclarativeListView::decrementCurrentIndex() if (currentIndex() > 0 || d->wrap) { d->moveReason = QDeclarativeListViewPrivate::SetIndex; int index = currentIndex()-1; - cancelFlick(); d->updateCurrent(index >= 0 ? index : d->model->count()-1); } } @@ -2591,7 +2596,7 @@ void QDeclarativeListView::componentComplete() d->updateCurrent(0); else d->updateCurrent(d->currentIndex); - if (d->highlight) { + if (d->highlight && d->currentItem) { d->highlight->setPosition(d->currentItem->position()); d->updateTrackedItem(); } @@ -2611,20 +2616,17 @@ void QDeclarativeListView::trackedPositionChanged() Q_D(QDeclarativeListView); if (!d->trackedItem || !d->currentItem) return; - if (!d->flickingHorizontally && !d->flickingVertically && !d->movingHorizontally && !d->movingVertically - && d->moveReason == QDeclarativeListViewPrivate::SetIndex) { + if (d->moveReason == QDeclarativeListViewPrivate::SetIndex) { const qreal trackedPos = qCeil(d->trackedItem->position()); const qreal viewPos = d->position(); + qreal pos = viewPos; if (d->haveHighlightRange) { if (d->highlightRange == StrictlyEnforceRange) { - qreal pos = viewPos; if (trackedPos > pos + d->highlightRangeEnd - d->trackedItem->size()) pos = trackedPos - d->highlightRangeEnd + d->trackedItem->size(); if (trackedPos < pos + d->highlightRangeStart) pos = trackedPos - d->highlightRangeStart; - d->setPosition(pos); } else { - qreal pos = viewPos; if (trackedPos < d->startPosition() + d->highlightRangeStart) { pos = d->startPosition(); } else if (d->trackedItem->endPosition() > d->endPosition() - d->size() + d->highlightRangeEnd) { @@ -2638,14 +2640,12 @@ void QDeclarativeListView::trackedPositionChanged() pos = trackedPos - d->highlightRangeEnd + d->trackedItem->size(); } } - d->setPosition(pos); } } else { if (trackedPos < viewPos && d->currentItem->position() < viewPos) { - d->setPosition(d->currentItem->position() < trackedPos ? trackedPos : d->currentItem->position()); + pos = d->currentItem->position() < trackedPos ? trackedPos : d->currentItem->position(); } else if (d->trackedItem->endPosition() > viewPos + d->size() && d->currentItem->endPosition() > viewPos + d->size()) { - qreal pos; if (d->trackedItem->endPosition() < d->currentItem->endPosition()) { pos = d->trackedItem->endPosition() - d->size(); if (d->trackedItem->size() > d->size()) @@ -2655,9 +2655,12 @@ void QDeclarativeListView::trackedPositionChanged() if (d->currentItem->size() > d->size()) pos = d->currentItem->position(); } - d->setPosition(pos); } } + if (viewPos != pos) { + cancelFlick(); + d->setPosition(pos); + } } } @@ -3021,6 +3024,11 @@ void QDeclarativeListView::modelReset() refill(); d->moveReason = QDeclarativeListViewPrivate::SetIndex; d->updateCurrent(d->currentIndex); + if (d->highlight && d->currentItem) { + d->highlight->setPosition(d->currentItem->position()); + d->updateTrackedItem(); + } + d->moveReason = QDeclarativeListViewPrivate::Other; emit countChanged(); } |