summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Jones <martin.jones@nokia.com>2010-07-06 05:04:15 (GMT)
committerMartin Jones <martin.jones@nokia.com>2010-07-06 05:11:33 (GMT)
commitc09f58965e772064ca952892f2e7969082f03855 (patch)
tree2edbb77c5505be81aa8cae18df33bb097e08cb46
parentb43f46fdc4fede579b512624c03df5c19893288a (diff)
downloadQt-c09f58965e772064ca952892f2e7969082f03855.zip
Qt-c09f58965e772064ca952892f2e7969082f03855.tar.gz
Qt-c09f58965e772064ca952892f2e7969082f03855.tar.bz2
Changing currentIndex shouldn't cancel a flick unnecessarily.
If the new currentIndex is in view, then there is no need to cancel a flick that is in progress. Task-number: QTBUG-11405
-rw-r--r--src/declarative/graphicsitems/qdeclarativegridview.cpp35
-rw-r--r--src/declarative/graphicsitems/qdeclarativelistview.cpp34
2 files changed, 45 insertions, 24 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativegridview.cpp b/src/declarative/graphicsitems/qdeclarativegridview.cpp
index cb99129..3efb9ad 100644
--- a/src/declarative/graphicsitems/qdeclarativegridview.cpp
+++ b/src/declarative/graphicsitems/qdeclarativegridview.cpp
@@ -1216,6 +1216,11 @@ void QDeclarativeGridView::setModel(const QVariant &model)
} else {
d->moveReason = QDeclarativeGridViewPrivate::SetIndex;
d->updateCurrent(d->currentIndex);
+ if (d->highlight && d->currentItem) {
+ d->highlight->setPosition(d->currentItem->colPos(), d->currentItem->rowPos());
+ d->updateTrackedItem();
+ }
+ d->moveReason = QDeclarativeGridViewPrivate::Other;
}
}
connect(d->model, SIGNAL(itemsInserted(int,int)), this, SLOT(itemsInserted(int,int)));
@@ -1274,6 +1279,11 @@ void QDeclarativeGridView::setDelegate(QDeclarativeComponent *delegate)
refill();
d->moveReason = QDeclarativeGridViewPrivate::SetIndex;
d->updateCurrent(d->currentIndex);
+ if (d->highlight && d->currentItem) {
+ d->highlight->setPosition(d->currentItem->colPos(), d->currentItem->rowPos());
+ d->updateTrackedItem();
+ }
+ d->moveReason = QDeclarativeGridViewPrivate::Other;
}
emit delegateChanged();
}
@@ -1300,7 +1310,6 @@ void QDeclarativeGridView::setCurrentIndex(int index)
return;
if (isComponentComplete() && d->isValid() && index != d->currentIndex && index < d->model->count() && index >= 0) {
d->moveReason = QDeclarativeGridViewPrivate::SetIndex;
- cancelFlick();
d->updateCurrent(index);
} else if (index != d->currentIndex) {
d->currentIndex = index;
@@ -2158,7 +2167,7 @@ void QDeclarativeGridView::componentComplete()
d->updateCurrent(0);
else
d->updateCurrent(d->currentIndex);
- if (d->highlight) {
+ if (d->highlight && d->currentItem) {
d->highlight->setPosition(d->currentItem->colPos(), d->currentItem->rowPos());
d->updateTrackedItem();
}
@@ -2172,20 +2181,17 @@ void QDeclarativeGridView::trackedPositionChanged()
Q_D(QDeclarativeGridView);
if (!d->trackedItem || !d->currentItem)
return;
- if (!d->flickingHorizontally && !d->flickingVertically && !d->movingHorizontally && !d->movingVertically
- && d->moveReason == QDeclarativeGridViewPrivate::SetIndex) {
+ if (d->moveReason == QDeclarativeGridViewPrivate::SetIndex) {
const qreal trackedPos = d->trackedItem->rowPos();
const qreal viewPos = d->position();
+ qreal pos = viewPos;
if (d->haveHighlightRange) {
if (d->highlightRange == StrictlyEnforceRange) {
- qreal pos = viewPos;
if (trackedPos > pos + d->highlightRangeEnd - d->rowSize())
pos = trackedPos - d->highlightRangeEnd + d->rowSize();
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->endRowPos() > d->endPosition() - d->size() + d->highlightRangeEnd) {
@@ -2199,14 +2205,12 @@ void QDeclarativeGridView::trackedPositionChanged()
pos = trackedPos - d->highlightRangeEnd + d->rowSize();
}
}
- d->setPosition(pos);
}
} else {
if (trackedPos < viewPos && d->currentItem->rowPos() < viewPos) {
- d->setPosition(d->currentItem->rowPos() < trackedPos ? trackedPos : d->currentItem->rowPos());
+ pos = d->currentItem->rowPos() < trackedPos ? trackedPos : d->currentItem->rowPos();
} else if (d->trackedItem->endRowPos() > viewPos + d->size()
&& d->currentItem->endRowPos() > viewPos + d->size()) {
- qreal pos;
if (d->trackedItem->endRowPos() < d->currentItem->endRowPos()) {
pos = d->trackedItem->endRowPos() - d->size();
if (d->rowSize() > d->size())
@@ -2216,9 +2220,12 @@ void QDeclarativeGridView::trackedPositionChanged()
if (d->rowSize() > d->size())
pos = d->currentItem->rowPos();
}
- d->setPosition(pos);
}
}
+ if (viewPos != pos) {
+ cancelFlick();
+ d->setPosition(pos);
+ }
}
}
@@ -2563,6 +2570,12 @@ void QDeclarativeGridView::modelReset()
refill();
d->moveReason = QDeclarativeGridViewPrivate::SetIndex;
d->updateCurrent(d->currentIndex);
+ if (d->highlight && d->currentItem) {
+ d->highlight->setPosition(d->currentItem->colPos(), d->currentItem->rowPos());
+ d->updateTrackedItem();
+ }
+ d->moveReason = QDeclarativeGridViewPrivate::Other;
+
emit countChanged();
}
diff --git a/src/declarative/graphicsitems/qdeclarativelistview.cpp b/src/declarative/graphicsitems/qdeclarativelistview.cpp
index e519bd9..9497cb7 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;
@@ -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();
}