diff options
| author | Peter Penz <[email protected]> | 2011-12-21 23:17:13 +0100 |
|---|---|---|
| committer | Peter Penz <[email protected]> | 2011-12-21 23:18:38 +0100 |
| commit | 2c77176c9c713fcd22be36e61216083f0ae40ddd (patch) | |
| tree | d7df7a1d436b66215a924c1c97b9aec1d8b52318 /src/kitemviews/kitemlistviewlayouter.cpp | |
| parent | 965107fd024be86eb014ee360211a66b320a3b43 (diff) | |
Fix first visible index calculation
When having a row with different item-heights, the calculation of the
first visible index might have been wrong.
Diffstat (limited to 'src/kitemviews/kitemlistviewlayouter.cpp')
| -rw-r--r-- | src/kitemviews/kitemlistviewlayouter.cpp | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/src/kitemviews/kitemlistviewlayouter.cpp b/src/kitemviews/kitemlistviewlayouter.cpp index f3c14f53d..8dbbb372a 100644 --- a/src/kitemviews/kitemlistviewlayouter.cpp +++ b/src/kitemviews/kitemlistviewlayouter.cpp @@ -441,21 +441,31 @@ void KItemListViewLayouter::updateVisibleIndexes() const int maxIndex = m_model->count() - 1; - // Calculate the first visible index that is (at least partly) visible + // Calculate the first visible index that is fully visible int min = 0; int max = maxIndex; int mid = 0; do { mid = (min + max) / 2; - if (m_itemRects[mid].bottom() < m_scrollOffset) { + if (m_itemRects[mid].top() < m_scrollOffset) { min = mid + 1; } else { max = mid - 1; } } while (min <= max); - while (mid < maxIndex && m_itemRects[mid].bottom() < m_scrollOffset) { - ++mid; + if (mid > 0) { + // Include the row before the first fully visible index, as it might + // be partly visible + if (m_itemRects[mid].top() >= m_scrollOffset) { + --mid; + Q_ASSERT(m_itemRects[mid].top() < m_scrollOffset); + } + + const qreal rowTop = m_itemRects[mid].top(); + while (mid > 0 && m_itemRects[mid - 1].top() == rowTop) { + --mid; + } } m_firstVisibleIndex = mid; |
