From c394f166af47fed34652685531ca1811c7f7568b Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Wed, 28 Oct 2009 14:45:57 +1000 Subject: Setting the currentIndex should cancel a flick. Task-number: QT-2383 --- src/declarative/fx/qfxflickable.cpp | 9 +++++++++ src/declarative/fx/qfxflickable.h | 1 + src/declarative/fx/qfxgridview.cpp | 6 ++++-- src/declarative/fx/qfxlistview.cpp | 6 ++++-- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/declarative/fx/qfxflickable.cpp b/src/declarative/fx/qfxflickable.cpp index 659193d..0fb8474 100644 --- a/src/declarative/fx/qfxflickable.cpp +++ b/src/declarative/fx/qfxflickable.cpp @@ -889,6 +889,14 @@ void QFxFlickable::viewportMoved() } } +void QFxFlickable::cancelFlick() +{ + Q_D(QFxFlickable); + d->timeline.reset(d->_moveX); + d->timeline.reset(d->_moveY); + movementEnding(); +} + void QFxFlickablePrivate::data_removeAt(int) { // ### @@ -1257,6 +1265,7 @@ void QFxFlickable::movementEnding() emit flickEnded(); } d->horizontalVelocity.setValue(0); + d->verticalVelocity.setValue(0); } void QFxFlickablePrivate::updateVelocity() diff --git a/src/declarative/fx/qfxflickable.h b/src/declarative/fx/qfxflickable.h index 4c80e8f..3db4ca7 100644 --- a/src/declarative/fx/qfxflickable.h +++ b/src/declarative/fx/qfxflickable.h @@ -183,6 +183,7 @@ protected: bool xflick() const; bool yflick() const; + void cancelFlick(); protected: QFxFlickable(QFxFlickablePrivate &dd, QFxItem *parent); diff --git a/src/declarative/fx/qfxgridview.cpp b/src/declarative/fx/qfxgridview.cpp index 0b2a935..c07258d 100644 --- a/src/declarative/fx/qfxgridview.cpp +++ b/src/declarative/fx/qfxgridview.cpp @@ -857,10 +857,12 @@ int QFxGridView::currentIndex() const void QFxGridView::setCurrentIndex(int index) { Q_D(QFxGridView); - if (d->isValid() && index != d->currentIndex && index < d->model->count() && index >= 0) + if (d->isValid() && index != d->currentIndex && index < d->model->count() && index >= 0) { + cancelFlick(); d->updateCurrent(index); - else + } else { d->currentIndex = index; + } } QFxItem *QFxGridView::currentItem() diff --git a/src/declarative/fx/qfxlistview.cpp b/src/declarative/fx/qfxlistview.cpp index 1f1b97b..49c2d11 100644 --- a/src/declarative/fx/qfxlistview.cpp +++ b/src/declarative/fx/qfxlistview.cpp @@ -1172,10 +1172,12 @@ void QFxListView::setCurrentIndex(int index) { Q_D(QFxListView); d->moveReason = QFxListViewPrivate::Other; - if (d->isValid() && index != d->currentIndex && index < d->model->count() && index >= 0) + if (d->isValid() && index != d->currentIndex && index < d->model->count() && index >= 0) { + cancelFlick(); d->updateCurrent(index); - else + } else { d->currentIndex = index; + } } QFxItem *QFxListView::currentItem() -- cgit v0.12