diff options
author | Martin Jones <martin.jones@nokia.com> | 2010-11-03 06:18:11 (GMT) |
---|---|---|
committer | Martin Jones <martin.jones@nokia.com> | 2010-11-03 06:18:11 (GMT) |
commit | 648eb76c22762c510815305e9e495db2aee9d2ad (patch) | |
tree | c2992d21c3f26e8b6da59052e83e9dc507a8ae60 /src | |
parent | 13eebf835df3d8fec88a68b571d33e73da929413 (diff) | |
download | Qt-648eb76c22762c510815305e9e495db2aee9d2ad.zip Qt-648eb76c22762c510815305e9e495db2aee9d2ad.tar.gz Qt-648eb76c22762c510815305e9e495db2aee9d2ad.tar.bz2 |
Combining ListView.StrictlyEnforceRange and resizing currentItem stalls.
There were two problems. 1) layout() called fixup() was called while
the view was being flicked. 2) the snapping code was incorrect (and
duplicated).
Task-number: QTBUG-14821
Reviewed-by: Michael Brasser
Diffstat (limited to 'src')
3 files changed, 31 insertions, 43 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativeflickable.cpp b/src/declarative/graphicsitems/qdeclarativeflickable.cpp index b737785..01a8585 100644 --- a/src/declarative/graphicsitems/qdeclarativeflickable.cpp +++ b/src/declarative/graphicsitems/qdeclarativeflickable.cpp @@ -53,9 +53,6 @@ QT_BEGIN_NAMESPACE // before we perform a flick. static const int FlickThreshold = 20; -// Really slow flicks can be annoying. -static const int MinimumFlickVelocity = 75; - QDeclarativeFlickableVisibleArea::QDeclarativeFlickableVisibleArea(QDeclarativeFlickable *parent) : QObject(parent), flickable(parent), m_xPosition(0.), m_widthRatio(0.) , m_yPosition(0.), m_heightRatio(0.) @@ -990,8 +987,8 @@ void QDeclarativeFlickable::viewportMoved() { Q_D(QDeclarativeFlickable); - qreal prevY = d->lastFlickablePosition.x(); - qreal prevX = d->lastFlickablePosition.y(); + qreal prevX = d->lastFlickablePosition.x(); + qreal prevY = d->lastFlickablePosition.y(); d->velocityTimeline.clear(); if (d->pressed || d->calcVelocity) { int elapsed = QDeclarativeItemPrivate::restart(d->velocityTime); @@ -1012,7 +1009,7 @@ void QDeclarativeFlickable::viewportMoved() } } - d->lastFlickablePosition = QPointF(d->vData.move.value(), d->hData.move.value()); + d->lastFlickablePosition = QPointF(d->hData.move.value(), d->vData.move.value()); d->vTime = d->timeline.time(); d->updateBeginningEnd(); diff --git a/src/declarative/graphicsitems/qdeclarativeflickable_p_p.h b/src/declarative/graphicsitems/qdeclarativeflickable_p_p.h index afefde2..92cf748 100644 --- a/src/declarative/graphicsitems/qdeclarativeflickable_p_p.h +++ b/src/declarative/graphicsitems/qdeclarativeflickable_p_p.h @@ -66,6 +66,9 @@ QT_BEGIN_NAMESPACE +// Really slow flicks can be annoying. +const qreal MinimumFlickVelocity = 75.0; + class QDeclarativeFlickableVisibleArea; class QDeclarativeFlickablePrivate : public QDeclarativeItemPrivate, public QDeclarativeItemChangeListener { diff --git a/src/declarative/graphicsitems/qdeclarativelistview.cpp b/src/declarative/graphicsitems/qdeclarativelistview.cpp index 38a4839..eab66d8 100644 --- a/src/declarative/graphicsitems/qdeclarativelistview.cpp +++ b/src/declarative/graphicsitems/qdeclarativelistview.cpp @@ -334,28 +334,9 @@ public: return model && model->count() && model->isValid(); } - int snapIndex() { - int index = currentIndex; - for (int i = 0; i < visibleItems.count(); ++i) { - FxListItem *item = visibleItems[i]; - if (item->index == -1) - continue; - qreal itemTop = item->position(); - if (itemTop >= highlight->position()-item->size()/2 && itemTop < highlight->position()+item->size()/2) - return item->index; - } - return index; - } - qreal snapPosAt(qreal pos) { - for (int i = 0; i < visibleItems.count(); ++i) { - FxListItem *item = visibleItems[i]; - if (item->index == -1) - continue; - qreal itemTop = item->position(); - if (itemTop+item->size()/2 >= pos && itemTop <= pos) - return item->position(); - } + if (FxListItem *snapItem = snapItemAt(pos)) + return snapItem->position(); if (visibleItems.count()) { qreal firstPos = visibleItems.first()->position(); qreal endPos = visibleItems.last()->position(); @@ -368,17 +349,18 @@ public: } FxListItem *snapItemAt(qreal pos) { + FxListItem *snapItem = 0; for (int i = 0; i < visibleItems.count(); ++i) { FxListItem *item = visibleItems[i]; if (item->index == -1) continue; qreal itemTop = item->position(); - if (item->index == model->count()-1 || (itemTop+item->size()/2 >= pos)) + if (highlight && itemTop >= pos && item->endPosition() <= pos + highlight->size() - 1) return item; + if (itemTop+item->size()/2 >= pos && itemTop-item->size()/2 < pos) + snapItem = item; } - if (visibleItems.count() && visibleItems.first()->position() <= pos) - return visibleItems.first(); - return 0; + return snapItem; } int lastVisibleIndex() const { @@ -768,8 +750,10 @@ void QDeclarativeListViewPrivate::layout() minExtentDirty = true; maxExtentDirty = true; updateHighlight(); - fixupPosition(); - q->refill(); + if (!q->isMoving() && !q->isFlicking()) { + fixupPosition(); + q->refill(); + } if (header) updateHeader(); if (footer) @@ -1350,12 +1334,15 @@ void QDeclarativeListViewPrivate::flick(AxisData &data, qreal minExtent, qreal m qreal newtarget = data.flickTarget; if (snapMode != QDeclarativeListView::NoSnap || highlightRange == QDeclarativeListView::StrictlyEnforceRange) newtarget = -snapPosAt(-(data.flickTarget - highlightRangeStart)) + highlightRangeStart; - if (velocity < 0 && newtarget < maxExtent) - newtarget = maxExtent; - else if (velocity > 0 && newtarget > minExtent) - newtarget = minExtent; - if (newtarget == data.flickTarget) // boundary unchanged - nothing to do + if (velocity < 0 && newtarget <= maxExtent) + newtarget = maxExtent - overshootDist; + else if (velocity > 0 && newtarget >= minExtent) + newtarget = minExtent + overshootDist; + if (newtarget == data.flickTarget) { // boundary unchanged - nothing to do + if (qAbs(velocity) < MinimumFlickVelocity) + correctFlick = false; return; + } data.flickTarget = newtarget; qreal dist = -newtarget + data.move.value(); if ((v < 0 && dist < 0) || (v > 0 && dist > 0)) { @@ -1365,7 +1352,7 @@ void QDeclarativeListViewPrivate::flick(AxisData &data, qreal minExtent, qreal m return; } timeline.reset(data.move); - timeline.accelDistance(data.move, v, -dist + (v < 0 ? -overshootDist : overshootDist)); + timeline.accelDistance(data.move, v, -dist); timeline.callback(QDeclarativeTimeLineCallback(&data.move, fixupCallback, this)); } } else { @@ -1696,7 +1683,7 @@ void QDeclarativeListView::setCurrentIndex(int index) if (isComponentComplete() && d->isValid()) { d->moveReason = QDeclarativeListViewPrivate::SetIndex; d->updateCurrent(index); - } else { + } else if (d->currentIndex != index) { d->currentIndex = index; emit currentIndexChanged(); } @@ -2323,9 +2310,10 @@ void QDeclarativeListView::viewportMoved() d->highlight->setPosition(qRound(pos)); // update current index - int idx = d->snapIndex(); - if (idx >= 0 && idx != d->currentIndex) - d->updateCurrent(idx); + if (FxListItem *snapItem = d->snapItemAt(d->highlight->position())) { + if (snapItem->index >= 0 && snapItem->index != d->currentIndex) + d->updateCurrent(snapItem->index); + } } } |