]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/kcategorizedview.cpp
Use KDirSortFilterProxyModel::naturalCompare() to prevent code duplication. DolphinSo...
[dolphin.git] / src / kcategorizedview.cpp
index 72909e8367a97f8bb9e919c1214a0de1110e3de6..d250c42c90d585c4094b5423f0964da260bad3d9 100644 (file)
@@ -98,6 +98,17 @@ const QModelIndexList &KCategorizedView::Private::intersectionSet(const QRect &r
 
     intersectedIndexes.clear();
 
+    int itemHeight;
+
+    if (listView->gridSize().isEmpty())
+    {
+        itemHeight = biggestItemSize.height();
+    }
+    else
+    {
+        itemHeight = listView->gridSize().height();
+    }
+
     // Lets find out where we should start
     int top = proxyModel->rowCount() - 1;
     int bottom = 0;
@@ -108,10 +119,13 @@ const QModelIndexList &KCategorizedView::Private::intersectionSet(const QRect &r
 
         index = elementDictionary[proxyModel->index(middle, 0)];
         indexVisualRect = visualRect(index);
+        // We need the whole height (not only the visualRect). This will help us to update
+        // all needed indexes correctly (ereslibre)
+        indexVisualRect.setHeight(indexVisualRect.height() + (itemHeight - indexVisualRect.height()));
 
         if (qMax(indexVisualRect.topLeft().y(),
                  indexVisualRect.bottomRight().y()) < qMin(rect.topLeft().y(),
-                                                        rect.bottomRight().y()))
+                                                           rect.bottomRight().y()))
         {
             bottom = middle + 1;
         }
@@ -151,8 +165,20 @@ QRect KCategorizedView::Private::visualRectInViewport(const QModelIndex &index)
 
     int viewportWidth = listView->viewport()->width() - listView->spacing();
 
-    int itemHeight = biggestItemSize.height();
-    int itemWidth = biggestItemSize.width();
+    int itemHeight;
+    int itemWidth;
+
+    if (listView->gridSize().isEmpty())
+    {
+        itemHeight = biggestItemSize.height();
+        itemWidth = biggestItemSize.width();
+    }
+    else
+    {
+        itemHeight = listView->gridSize().height();
+        itemWidth = listView->gridSize().width();
+    }
+
     int itemWidthPlusSeparation = listView->spacing() + itemWidth;
     int elementsPerRow = viewportWidth / itemWidthPlusSeparation;
     if (!elementsPerRow)
@@ -176,17 +202,39 @@ QRect KCategorizedView::Private::visualRectInViewport(const QModelIndex &index)
         if (rows - trunc(rows)) rowsInt++;
 
         retRect.setTop(retRect.top() +
-                       (rowsInt * listView->spacing()) +
                        (rowsInt * itemHeight) +
                        itemCategorizer->categoryHeight(listView->viewOptions()) +
                        listView->spacing() * 2);
+
+        if (listView->gridSize().isEmpty())
+        {
+            retRect.setTop(retRect.top() +
+                           (rowsInt * listView->spacing()));
+        }
     }
 
-    retRect.setTop(retRect.top() + row * listView->spacing() +
-                   row * itemHeight);
+
+    if (listView->gridSize().isEmpty())
+    {
+        retRect.setTop(retRect.top() + row * listView->spacing() +
+                       (row * itemHeight));
+    }
+    else
+    {
+        retRect.setTop(retRect.top() + (row * itemHeight));
+    }
 
     retRect.setWidth(itemWidth);
-    retRect.setHeight(itemHeight);
+
+    if (listView->gridSize().isEmpty())
+    {
+        retRect.setHeight(listView->sizeHintForIndex(proxyModel->mapFromSource(index)).height());
+    }
+    else
+    {
+        retRect.setHeight(qMin(listView->sizeHintForIndex(proxyModel->mapFromSource(index)).height(),
+                               listView->gridSize().height()));
+    }
 
     return retRect;
 }
@@ -206,8 +254,20 @@ QRect KCategorizedView::Private::visualCategoryRectInViewport(const QString &cat
 
     int viewportWidth = listView->viewport()->width() - listView->spacing();
 
-    int itemHeight = biggestItemSize.height();
-    int itemWidth = biggestItemSize.width();
+    int itemHeight;
+    int itemWidth;
+
+    if (listView->gridSize().isEmpty())
+    {
+        itemHeight = biggestItemSize.height();
+        itemWidth = biggestItemSize.width();
+    }
+    else
+    {
+        itemHeight = listView->gridSize().height();
+        itemWidth = listView->gridSize().width();
+    }
+
     int itemWidthPlusSeparation = listView->spacing() + itemWidth;
     int elementsPerRow = viewportWidth / itemWidthPlusSeparation;
 
@@ -226,10 +286,15 @@ QRect KCategorizedView::Private::visualCategoryRectInViewport(const QString &cat
         if (rows - trunc(rows)) rowsInt++;
 
         retRect.setTop(retRect.top() +
-                       (rowsInt * listView->spacing()) +
                        (rowsInt * itemHeight) +
                        itemCategorizer->categoryHeight(listView->viewOptions()) +
                        listView->spacing() * 2);
+
+        if (listView->gridSize().isEmpty())
+        {
+            retRect.setTop(retRect.top() +
+                           (rowsInt * listView->spacing()));
+        }
     }
 
     retRect.setHeight(itemCategorizer->categoryHeight(listView->viewOptions()));
@@ -323,8 +388,8 @@ void KCategorizedView::Private::drawNewCategory(const QModelIndex &index,
 
 void KCategorizedView::Private::updateScrollbars()
 {
-    int lastItemBottom = cachedRectIndex(lastIndex).bottom() +
-                           listView->spacing() - listView->viewport()->height();
+    int lastItemBottom = cachedRectIndex(lastIndex).top() +
+                         listView->spacing() + (listView->gridSize().isEmpty() ? 0 : listView->gridSize().height()) - listView->viewport()->height();
 
     listView->verticalScrollBar()->setSingleStep(listView->viewport()->height() / 10);
     listView->verticalScrollBar()->setPageStep(listView->viewport()->height());
@@ -557,6 +622,11 @@ void KCategorizedView::paintEvent(QPaintEvent *event)
 
     QStyleOptionViewItemV3 option = viewOptions();
     option.widget = this;
+    if (wordWrap())
+    {
+        option.features |= QStyleOptionViewItemV2::WrapText;
+    }
+
     QPainter painter(viewport());
     QRect area = event->rect();
     const bool focus = (hasFocus() || viewport()->hasFocus()) &&
@@ -570,7 +640,7 @@ void KCategorizedView::paintEvent(QPaintEvent *event)
     foreach (const QModelIndex &index, dirtyIndexes)
     {
         option.state = state;
-        option.rect = d->visualRect(index);
+        option.rect = visualRect(index);
 
         if (selectionModel() && selectionModel()->isSelected(index))
         {
@@ -608,7 +678,6 @@ void KCategorizedView::paintEvent(QPaintEvent *event)
     }
 
     // Redraw categories
-    int i = 0;
     QStyleOptionViewItem otherOption;
     foreach (const QString &category, d->categories)
     {
@@ -871,7 +940,7 @@ void KCategorizedView::mouseReleaseEvent(QMouseEvent *event)
     d->lastSelection = selectionModel()->selection();
 
     if (d->hovered.isValid())
-        viewport()->update(d->visualRect(d->hovered));
+        viewport()->update(visualRect(d->hovered));
     else if (!d->hoveredCategory.isEmpty())
         viewport()->update(d->categoryVisualRect(d->hoveredCategory));
 }
@@ -938,8 +1007,17 @@ QModelIndex KCategorizedView::moveCursor(CursorAction cursorAction,
     const QModelIndex current = selectionModel()->currentIndex();
 
     int viewportWidth = viewport()->width() - spacing();
-    int itemHeight = d->biggestItemSize.height();
-    int itemWidth = d->biggestItemSize.width();
+    int itemWidth;
+
+    if (gridSize().isEmpty())
+    {
+        itemWidth = d->biggestItemSize.width();
+    }
+    else
+    {
+        itemWidth = gridSize().width();
+    }
+
     int itemWidthPlusSeparation = spacing() + itemWidth;
     int elementsPerRow = viewportWidth / itemWidthPlusSeparation;