X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/54b5a283765f168575f2eaeff95c93dbeca3d63d..c8d8556950005dfd96ebdb41d2f43ad90356367c:/src/kitemviews/kitemlistviewlayouter.cpp diff --git a/src/kitemviews/kitemlistviewlayouter.cpp b/src/kitemviews/kitemlistviewlayouter.cpp index 9b807aaf5..60822adc7 100644 --- a/src/kitemviews/kitemlistviewlayouter.cpp +++ b/src/kitemviews/kitemlistviewlayouter.cpp @@ -24,7 +24,7 @@ #include -#define KITEMLISTVIEWLAYOUTER_DEBUG +// #define KITEMLISTVIEWLAYOUTER_DEBUG KItemListViewLayouter::KItemListViewLayouter(QObject* parent) : QObject(parent), @@ -234,7 +234,7 @@ QRectF KItemListViewLayouter::groupHeaderRect(int index) const pos.rx() = 0; size = QSizeF(m_size.width(), m_groupHeaderHeight); } else { - size = QSizeF(firstItemRect.width(), m_groupHeaderHeight); + size = QSizeF(minimumGroupHeaderWidth(), m_groupHeaderHeight); } return QRectF(pos, size); } @@ -253,13 +253,9 @@ int KItemListViewLayouter::maximumVisibleItems() const return rows * m_columnCount; } -int KItemListViewLayouter::itemsPerOffset() const -{ - return m_columnCount; -} - bool KItemListViewLayouter::isFirstGroupItem(int itemIndex) const { + const_cast(this)->doLayout(); return m_groupItemIndexes.contains(itemIndex); } @@ -368,9 +364,9 @@ void KItemListViewLayouter::doLayout() // (in average a character requires the halve width of the font height). // // TODO: Let the group headers provide a minimum width and respect this width here - const qreal minimumGroupHeaderWidth = m_groupHeaderHeight * 15 / 2; - if (requiredItemHeight < minimumGroupHeaderWidth) { - requiredItemHeight = minimumGroupHeaderWidth; + const qreal headerWidth = minimumGroupHeaderWidth(); + if (requiredItemHeight < headerWidth) { + requiredItemHeight = headerWidth; } } @@ -395,7 +391,16 @@ void KItemListViewLayouter::doLayout() } if (itemCount > 0) { + // Calculate the maximum y-range of the last row for m_maximumScrollOffset m_maximumScrollOffset = m_itemRects.last().bottom(); + const qreal rowY = m_itemRects.last().y(); + + int index = m_itemRects.count() - 2; + while (index >= 0 && m_itemRects.at(index).bottom() >= rowY) { + m_maximumScrollOffset = qMax(m_maximumScrollOffset, m_itemRects.at(index).bottom()); + --index; + } + m_maximumItemOffset = m_columnCount * m_columnWidth; } else { m_maximumScrollOffset = 0; @@ -428,21 +433,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; @@ -493,4 +508,9 @@ bool KItemListViewLayouter::createGroupHeaders() return true; } +qreal KItemListViewLayouter::minimumGroupHeaderWidth() const +{ + return m_groupHeaderHeight * 15 / 2; +} + #include "kitemlistviewlayouter_p.moc"