summaryrefslogtreecommitdiffstats
path: root/src/declarative
diff options
context:
space:
mode:
authorMartin Jones <martin.jones@nokia.com>2010-02-17 04:52:24 (GMT)
committerMartin Jones <martin.jones@nokia.com>2010-02-17 04:52:24 (GMT)
commit7f6317c25e6c1ec457971ab70c850d4d2bbe4cd2 (patch)
treed9900be18b830199b5e659a23215ae9019556884 /src/declarative
parent130e3a93094f1e05759d3adae03042b876ed2d1f (diff)
downloadQt-7f6317c25e6c1ec457971ab70c850d4d2bbe4cd2.zip
Qt-7f6317c25e6c1ec457971ab70c850d4d2bbe4cd2.tar.gz
Qt-7f6317c25e6c1ec457971ab70c850d4d2bbe4cd2.tar.bz2
Fix currentIndex after itemsMoved()
Ensure fixupPosition() positions properly for StrictlyEnforceRange highlight mode. Update visibleIndex after itemsMoved().
Diffstat (limited to 'src/declarative')
-rw-r--r--src/declarative/graphicsitems/qmlgraphicslistview.cpp54
1 files changed, 46 insertions, 8 deletions
diff --git a/src/declarative/graphicsitems/qmlgraphicslistview.cpp b/src/declarative/graphicsitems/qmlgraphicslistview.cpp
index db0afe1..da6f8e0 100644
--- a/src/declarative/graphicsitems/qmlgraphicslistview.cpp
+++ b/src/declarative/graphicsitems/qmlgraphicslistview.cpp
@@ -1069,9 +1069,13 @@ void QmlGraphicsListViewPrivate::fixupY()
fixupDuration = moveReason == Mouse ? fixupDuration : 0;
if (haveHighlightRange && highlightRange == QmlGraphicsListView::StrictlyEnforceRange) {
- if (currentItem && highlight && currentItem->position() != highlight->position()) {
+ if (currentItem && currentItem->position() - position() != highlightRangeStart) {
+ qreal pos = currentItem->position() - highlightRangeStart;
timeline.reset(_moveY);
- timeline.move(_moveY, -(currentItem->position() - highlightRangeStart), QEasingCurve(QEasingCurve::InOutQuad), fixupDuration);
+ if (fixupDuration)
+ timeline.move(_moveY, -pos, QEasingCurve(QEasingCurve::InOutQuad), fixupDuration);
+ else
+ _moveY.setValue(-pos);
vTime = timeline.time();
}
} else if (snapMode != QmlGraphicsListView::NoSnap) {
@@ -1080,7 +1084,10 @@ void QmlGraphicsListViewPrivate::fixupY()
qreal dist = qAbs(_moveY + pos);
if (dist > 0) {
timeline.reset(_moveY);
- timeline.move(_moveY, -pos, QEasingCurve(QEasingCurve::InOutQuad), fixupDuration);
+ if (fixupDuration)
+ timeline.move(_moveY, -pos, QEasingCurve(QEasingCurve::InOutQuad), fixupDuration);
+ else
+ _moveY.setValue(-pos);
vTime = timeline.time();
}
}
@@ -1102,9 +1109,13 @@ void QmlGraphicsListViewPrivate::fixupX()
fixupDuration = moveReason == Mouse ? fixupDuration : 0;
if (haveHighlightRange && highlightRange == QmlGraphicsListView::StrictlyEnforceRange) {
- if (currentItem && highlight && currentItem->position() != highlight->position()) {
+ if (currentItem && currentItem->position() - position() != highlightRangeStart) {
+ qreal pos = currentItem->position() - highlightRangeStart;
timeline.reset(_moveX);
- timeline.move(_moveX, -(currentItem->position() - highlightRangeStart), QEasingCurve(QEasingCurve::InOutQuad), fixupDuration);
+ if (fixupDuration)
+ timeline.move(_moveX, -pos, QEasingCurve(QEasingCurve::InOutQuad), fixupDuration);
+ else
+ _moveX.setValue(-pos);
vTime = timeline.time();
}
} else if (snapMode != QmlGraphicsListView::NoSnap) {
@@ -1113,7 +1124,10 @@ void QmlGraphicsListViewPrivate::fixupX()
qreal dist = qAbs(_moveX + pos);
if (dist > 0) {
timeline.reset(_moveX);
- timeline.move(_moveX, -pos, QEasingCurve(QEasingCurve::InOutQuad), fixupDuration);
+ if (fixupDuration)
+ timeline.move(_moveX, -pos, QEasingCurve(QEasingCurve::InOutQuad), fixupDuration);
+ else
+ _moveX.setValue(-pos);
vTime = timeline.time();
}
}
@@ -2261,6 +2275,7 @@ void QmlGraphicsListView::positionViewAtIndex(int index)
for (int i = 0; i < oldVisible.count(); ++i)
d->releaseItem(oldVisible.at(i));
}
+ d->fixupPosition();
}
@@ -2633,9 +2648,32 @@ void QmlGraphicsListView::itemsMoved(int from, int to, int count)
++endIndex;
}
+ // update visibleIndex
+ for (it = d->visibleItems.begin(); it != d->visibleItems.end(); ++it) {
+ if ((*it)->index != -1) {
+ d->visibleIndex = (*it)->index;
+ break;
+ }
+ }
+
+ // Fix current index
+ if (d->currentIndex >= 0 && d->currentItem) {
+ int oldCurrent = d->currentIndex;
+ d->currentIndex = d->model->indexOf(d->currentItem->item, this);
+ if (oldCurrent != d->currentIndex) {
+ d->currentItem->index = d->currentIndex;
+ emit currentIndexChanged();
+ }
+ }
+
// Whatever moved items remain are no longer visible items.
- while (moved.count())
- d->releaseItem(moved.take(moved.begin().key()));
+ while (moved.count()) {
+ int idx = moved.begin().key();
+ FxListItem *item = moved.take(idx);
+ if (item->item == d->currentItem->item)
+ item->setPosition(d->positionAt(idx));
+ d->releaseItem(item);
+ }
// Ensure we don't cause an ugly list scroll.
d->visibleItems.first()->setPosition(d->visibleItems.first()->position() + moveBy);