]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/kcategorizedview.cpp
Bypass a layout issue in QListView::visualRect(), where the horizontal position of...
[dolphin.git] / src / kcategorizedview.cpp
index a3e60f1c478c39bf7a50f5521813a2bcaea7a279..4f542f9c7fc0e12849f0633d1dbe0a27f316b4f1 100644 (file)
@@ -390,6 +390,8 @@ void KCategorizedView::Private::updateScrollbars()
     int lastItemBottom = cachedRectIndex(lastIndex).top() +
                          listView->spacing() + (listView->gridSize().isEmpty() ? 0 : listView->gridSize().height()) - listView->viewport()->height();
 
+    listView->horizontalScrollBar()->setRange(0, 0);
+
     listView->verticalScrollBar()->setSingleStep(listView->viewport()->height() / 10);
     listView->verticalScrollBar()->setPageStep(listView->viewport()->height());
     listView->verticalScrollBar()->setRange(0, lastItemBottom);
@@ -422,6 +424,7 @@ void KCategorizedView::Private::layoutChanged(bool forceItemReload)
           (modelSortRole != proxyModel->sortRole()) ||
           (modelSortColumn != proxyModel->sortColumn()) ||
           (modelSortOrder != proxyModel->sortOrder()) ||
+          (modelLastRowCount != proxyModel->rowCount()) ||
           (modelCategorized != proxyModel->isCategorizedModel()))))
     {
         // Force the view to update all elements
@@ -432,6 +435,7 @@ void KCategorizedView::Private::layoutChanged(bool forceItemReload)
             modelSortRole = proxyModel->sortRole();
             modelSortColumn = proxyModel->sortColumn();
             modelSortOrder = proxyModel->sortOrder();
+            modelLastRowCount = proxyModel->rowCount();
             modelCategorized = proxyModel->isCategorizedModel();
         }
     }
@@ -526,6 +530,7 @@ void KCategorizedView::setModel(QAbstractItemModel *model)
         d->modelSortRole = d->proxyModel->sortRole();
         d->modelSortColumn = d->proxyModel->sortColumn();
         d->modelSortOrder = d->proxyModel->sortOrder();
+        d->modelLastRowCount = d->proxyModel->rowCount();
         d->modelCategorized = d->proxyModel->isCategorizedModel();
 
         QObject::connect(d->proxyModel,
@@ -743,6 +748,7 @@ void KCategorizedView::paintEvent(QPaintEvent *event)
 
     // Redraw categories
     QStyleOptionViewItem otherOption;
+    bool intersectedInThePast = false;
     foreach (const QString &category, d->categories)
     {
         otherOption = option;
@@ -751,11 +757,18 @@ void KCategorizedView::paintEvent(QPaintEvent *event)
 
         if (otherOption.rect.intersects(area))
         {
+            intersectedInThePast = true;
+
             QModelIndex indexToDraw = d->proxyModel->index(d->categoriesIndexes[category][0].row(), d->proxyModel->sortColumn());
 
             d->drawNewCategory(indexToDraw,
                                d->proxyModel->sortRole(), otherOption, &painter);
         }
+        else if (intersectedInThePast)
+        {
+            break; // the visible area has been finished, we don't need to keep asking, the rest won't intersect
+                   // this is doable because we know that categories are correctly ordered on the list
+        }
     }
 
     if (d->mouseButtonPressed && !d->isDragging)