]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/kitemviews/kitemlistviewlayouter.cpp
Fix style-issues in items when not using Oxygen
[dolphin.git] / src / kitemviews / kitemlistviewlayouter.cpp
index f3c14f53d8ca360ecc5a71466c2071747c6be46b..60822adc7f1ad96301fe89206ece8ee6ced1997c 100644 (file)
@@ -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,11 +253,6 @@ int KItemListViewLayouter::maximumVisibleItems() const
     return rows * m_columnCount;
 }
 
-int KItemListViewLayouter::itemsPerOffset() const
-{
-    return m_columnCount;
-}
-
 bool KItemListViewLayouter::isFirstGroupItem(int itemIndex) const
 {
     const_cast<KItemListViewLayouter*>(this)->doLayout();
@@ -298,10 +293,7 @@ void KItemListViewLayouter::doLayout()
             // Apply the unused width equally to each column
             const qreal unusedWidth = size.width() - m_columnCount * m_columnWidth;
             if (unusedWidth > 0) {
-                // [Comment #1] A cast to int is done on purpose to prevent rounding issues when
-                // drawing pixmaps and drawing text or other graphic primitives: Qt uses a different
-                // rastering algorithm for the upper/left of pixmaps
-                const qreal columnInc = int(unusedWidth / (m_columnCount + 1));
+                const qreal columnInc = unusedWidth / (m_columnCount + 1);
                 m_columnWidth += columnInc;
                 m_xPosInc += columnInc;
             }
@@ -372,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 = int(m_groupHeaderHeight * 15 / 2); // See [Comment #1]
-                    if (requiredItemHeight < minimumGroupHeaderWidth) {
-                        requiredItemHeight = minimumGroupHeaderWidth;
+                    const qreal headerWidth = minimumGroupHeaderWidth();
+                    if (requiredItemHeight < headerWidth) {
+                        requiredItemHeight = headerWidth;
                     }
                 }
 
@@ -441,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;
 
@@ -506,4 +508,9 @@ bool KItemListViewLayouter::createGroupHeaders()
     return true;
 }
 
+qreal KItemListViewLayouter::minimumGroupHeaderWidth() const
+{
+    return m_groupHeaderHeight * 15 / 2;
+}
+
 #include "kitemlistviewlayouter_p.moc"