]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/kcategorizedview.cpp
Clarify some adjectives.
[dolphin.git] / src / kcategorizedview.cpp
index 133fe5d39cbaeadd61aef199a9e425b8ce77045d..214fa39d236ea23df61ed2ad273673df03b1f12a 100644 (file)
@@ -78,6 +78,7 @@ private:
 KCategorizedView::Private::Private(KCategorizedView *listView)
     : listView(listView)
     , itemCategorizer(0)
+    , biggestItemSize(QSize(0, 0))
     , mouseButtonPressed(false)
     , isDragging(false)
     , dragLeftViewport(false)
@@ -97,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;
@@ -107,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;
         }
@@ -150,14 +165,20 @@ QRect KCategorizedView::Private::visualRectInViewport(const QModelIndex &index)
 
     int viewportWidth = listView->viewport()->width() - listView->spacing();
 
-    // We really need all items to be of same size. Otherwise we cannot do this
-    // (ereslibre)
-    // QSize itemSize =
-    //             listView->sizeHintForIndex(proxyModel->mapFromSource(index));
-    // int itemHeight = itemSize.height();
-    // int itemWidth = itemSize.width();*/
-    int itemHeight = 107;
-    int itemWidth = 130;
+    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)
@@ -181,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;
 }
@@ -211,13 +254,20 @@ QRect KCategorizedView::Private::visualCategoryRectInViewport(const QString &cat
 
     int viewportWidth = listView->viewport()->width() - listView->spacing();
 
-    // We really need all items to be of same size. Otherwise we cannot do this
-    // (ereslibre)
-    // QSize itemSize = listView->sizeHintForIndex(index);
-    // int itemHeight = itemSize.height();
-    // int itemWidth = itemSize.width();
-    int itemHeight = 107;
-    int itemWidth = 130;
+    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;
 
@@ -236,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()));
@@ -333,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());
@@ -552,6 +607,7 @@ void KCategorizedView::reset()
     d->intersectedIndexes.clear();
     d->sourceModelIndexList.clear();
     d->hovered = QModelIndex();
+    d->biggestItemSize = QSize(0, 0);
     d->mouseButtonPressed = false;
 }
 
@@ -617,7 +673,6 @@ void KCategorizedView::paintEvent(QPaintEvent *event)
     }
 
     // Redraw categories
-    int i = 0;
     QStyleOptionViewItem otherOption;
     foreach (const QString &category, d->categories)
     {
@@ -947,13 +1002,17 @@ QModelIndex KCategorizedView::moveCursor(CursorAction cursorAction,
     const QModelIndex current = selectionModel()->currentIndex();
 
     int viewportWidth = viewport()->width() - spacing();
-    // We really need all items to be of same size. Otherwise we cannot do this
-    // (ereslibre)
-    // QSize itemSize = listView->sizeHintForIndex(index);
-    // int itemHeight = itemSize.height();
-    // int itemWidth = itemSize.width();
-    int itemHeight = 107;
-    int itemWidth = 130;
+    int itemWidth;
+
+    if (gridSize().isEmpty())
+    {
+        itemWidth = d->biggestItemSize.width();
+    }
+    else
+    {
+        itemWidth = gridSize().width();
+    }
+
     int itemWidthPlusSeparation = spacing() + itemWidth;
     int elementsPerRow = viewportWidth / itemWidthPlusSeparation;
 
@@ -1082,6 +1141,7 @@ void KCategorizedView::rowsInserted(const QModelIndex &parent,
         d->intersectedIndexes.clear();
         d->sourceModelIndexList.clear();
         d->hovered = QModelIndex();
+        d->biggestItemSize = QSize(0, 0);
         d->mouseButtonPressed = false;
 
         return;
@@ -1109,6 +1169,7 @@ void KCategorizedView::rowsInsertedArtifficial(const QModelIndex &parent,
     d->intersectedIndexes.clear();
     d->sourceModelIndexList.clear();
     d->hovered = QModelIndex();
+    d->biggestItemSize = QSize(0, 0);
     d->mouseButtonPressed = false;
 
     if (start > end || end < 0 || start < 0 || !d->proxyModel->rowCount())
@@ -1119,6 +1180,11 @@ void KCategorizedView::rowsInsertedArtifficial(const QModelIndex &parent,
     // Add all elements mapped to the source model
     for (int k = 0; k < d->proxyModel->rowCount(); k++)
     {
+        d->biggestItemSize = QSize(qMax(sizeHintForIndex(d->proxyModel->index(k, 0)).width(),
+                                        d->biggestItemSize.width()),
+                                   qMax(sizeHintForIndex(d->proxyModel->index(k, 0)).height(),
+                                        d->biggestItemSize.height()));
+
         d->sourceModelIndexList <<
                          d->proxyModel->mapToSource(d->proxyModel->index(k, 0));
     }