From: Martin Jones Date: Fri, 5 Aug 2011 03:44:38 +0000 (+1000) Subject: ListView with StrictlyEnforceRange skips over items X-Git-Tag: qt-v5.0.0-alpha1~1965 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ab4cac7453c5da79f356bdac4b15d876dde97938;p=profile%2Fivi%2Fqtdeclarative.git ListView with StrictlyEnforceRange skips over items When list item size varies smaller items next to larger items may not be able to become the current item. Ensure the snap item is found using the correct range, i.e. half of previous item above snap pos and half of next item below. Change-Id: I52ae235e6b801bda48fcb636bb4150ab643715e8 Fixes: QTBUG-20745 Reviewed-on: http://codereview.qt.nokia.com/2650 Reviewed-by: Qt Sanity Bot Reviewed-by: Bea Lam --- diff --git a/src/declarative/items/qsglistview.cpp b/src/declarative/items/qsglistview.cpp index e162339..c8e8817 100644 --- a/src/declarative/items/qsglistview.cpp +++ b/src/declarative/items/qsglistview.cpp @@ -434,6 +434,7 @@ qreal QSGListViewPrivate::snapPosAt(qreal pos) FxViewItem *QSGListViewPrivate::snapItemAt(qreal pos) { FxViewItem *snapItem = 0; + qreal prevItemSize = 0; for (int i = 0; i < visibleItems.count(); ++i) { FxViewItem *item = visibleItems.at(i); if (item->index == -1) @@ -441,8 +442,9 @@ FxViewItem *QSGListViewPrivate::snapItemAt(qreal pos) qreal itemTop = item->position(); if (highlight && itemTop >= pos && item->endPosition() <= pos + highlight->size()) return item; - if (itemTop+item->size()/2 >= pos && itemTop-item->size()/2 < pos) + if (itemTop+item->size()/2 >= pos && itemTop-prevItemSize/2 < pos) snapItem = item; + prevItemSize = item->size(); } return snapItem; } diff --git a/src/qtquick1/graphicsitems/qdeclarativelistview.cpp b/src/qtquick1/graphicsitems/qdeclarativelistview.cpp index 244a2b8..bc06f9b 100644 --- a/src/qtquick1/graphicsitems/qdeclarativelistview.cpp +++ b/src/qtquick1/graphicsitems/qdeclarativelistview.cpp @@ -446,6 +446,7 @@ public: FxListItem1 *snapItemAt(qreal pos) { FxListItem1 *snapItem = 0; + qreal prevItemSize = 0; for (int i = 0; i < visibleItems.count(); ++i) { FxListItem1 *item = visibleItems[i]; if (item->index == -1) @@ -453,8 +454,9 @@ public: qreal itemTop = item->position(); if (highlight && itemTop >= pos && item->endPosition() <= pos + highlight->size() - 1) return item; - if (itemTop+item->size()/2 >= pos && itemTop-item->size()/2 < pos) + if (itemTop+item->size()/2 >= pos && itemTop-prevItemSize/2 < pos) snapItem = item; + prevItemSize = item->size(); } return snapItem; }