]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/klistview.cpp
Define variables in their context
[dolphin.git] / src / klistview.cpp
index fa78de638e3c4cb6dbc02b44ab954a425912a27d..1e9e1b013f0393dcaba2d03c3a41408923743511 100644 (file)
@@ -169,16 +169,14 @@ QRect KListView::Private::visualRectInViewport(const QModelIndex &index) const
     retRect.setLeft(retRect.left() + column * listView->spacing() +
                     column * itemWidth);
 
-    float rows;
-    int rowsInt;
     foreach (const QString &category, categories)
     {
         if (category == curCategory)
             break;
 
-        rows = (float) ((float) categoriesIndexes[category].count() /
-                        (float) elementsPerRow);
-        rowsInt = categoriesIndexes[category].count() / elementsPerRow;
+        float rows = (float) ((float) categoriesIndexes[category].count() /
+                              (float) elementsPerRow);
+        int rowsInt = categoriesIndexes[category].count() / elementsPerRow;
 
         if (rows - trunc(rows)) rowsInt++;
 
@@ -226,16 +224,14 @@ QRect KListView::Private::visualCategoryRectInViewport(const QString &category)
     if (!elementsPerRow)
         elementsPerRow++;
 
-    float rows;
-    int rowsInt;
     foreach (const QString &itCategory, categories)
     {
         if (itCategory == category)
             break;
 
-        rows = (float) ((float) categoriesIndexes[itCategory].count() /
-                        (float) elementsPerRow);
-        rowsInt = categoriesIndexes[itCategory].count() / elementsPerRow;
+        float rows = (float) ((float) categoriesIndexes[itCategory].count() /
+                              (float) elementsPerRow);
+        int rowsInt = categoriesIndexes[itCategory].count() / elementsPerRow;
 
         if (rows - trunc(rows)) rowsInt++;
 
@@ -395,18 +391,40 @@ void KListView::Private::drawDraggedItems(QPainter *painter)
 {
     QStyleOptionViewItemV3 option = listView->viewOptions();
     option.state &= ~QStyle::State_MouseOver;
+    foreach (const QModelIndex &index, listView->selectionModel()->selectedIndexes())
+    {
+        const int dx = mousePosition.x() - initialPressPosition.x() + listView->horizontalOffset();
+        const int dy = mousePosition.y() - initialPressPosition.y() + listView->verticalOffset();
+
+        option.rect = visualRect(index);
+        option.rect.adjust(dx, dy, dx, dy);
+
+        listView->itemDelegate(index)->paint(painter, option, index);
+    }
+}
+
+void KListView::Private::drawDraggedItems()
+{
     int dx;
     int dy;
+    QRect rectToUpdate;
+    QRect currentRect;
     foreach (const QModelIndex &index, listView->selectionModel()->selectedIndexes())
     {
         dx = mousePosition.x() - initialPressPosition.x() + listView->horizontalOffset();
         dy = mousePosition.y() - initialPressPosition.y() + listView->verticalOffset();
 
-        option.rect = visualRect(index);
-        option.rect.adjust(dx, dy, dx, dy);
+        currentRect = visualRect(index);
+        currentRect.adjust(dx, dy, dx, dy);
 
-        listView->itemDelegate(index)->paint(painter, option, index);
+        rectToUpdate = rectToUpdate.united(currentRect);
     }
+
+    listView->viewport()->update(lastDraggedItemsRect);
+
+    lastDraggedItemsRect = rectToUpdate;
+
+    listView->viewport()->update(rectToUpdate);
 }
 
 
@@ -613,19 +631,6 @@ void KListView::paintEvent(QPaintEvent *event)
         itemDelegate(index)->paint(&painter, option, index);
     }
 
-    // Redraw categories
-    QStyleOptionViewItem otherOption;
-    foreach (const QString &category, d->categories)
-    {
-        otherOption = option;
-        otherOption.rect = d->categoryVisualRect(category);
-
-        if (otherOption.rect.intersects(area))
-        {
-            d->drawNewCategory(category, otherOption, &painter);
-        }
-    }
-
     if (d->mouseButtonPressed && !d->isDragging)
     {
         QPoint start, end, initialPressPosition;
@@ -657,6 +662,19 @@ void KListView::paintEvent(QPaintEvent *event)
         painter.restore();
     }
 
+    // Redraw categories
+    QStyleOptionViewItem otherOption;
+    foreach (const QString &category, d->categories)
+    {
+        otherOption = option;
+        otherOption.rect = d->categoryVisualRect(category);
+
+        if (otherOption.rect.intersects(area))
+        {
+            d->drawNewCategory(category, otherOption, &painter);
+        }
+    }
+
     if (d->isDragging && !d->dragLeftViewport)
     {
         painter.setOpacity(0.5);
@@ -777,6 +795,37 @@ void KListView::mouseMoveEvent(QMouseEvent *event)
 
         viewport()->update(d->categoryVisualRect(category));
     }
+
+    QRect rect;
+    if (d->mouseButtonPressed && !d->isDragging)
+    {
+        QPoint start, end, initialPressPosition;
+
+        initialPressPosition = d->initialPressPosition;
+
+        initialPressPosition.setY(initialPressPosition.y() - verticalOffset());
+        initialPressPosition.setX(initialPressPosition.x() - horizontalOffset());
+
+        if (d->initialPressPosition.x() > d->mousePosition.x() ||
+            d->initialPressPosition.y() > d->mousePosition.y())
+        {
+            start = d->mousePosition;
+            end = initialPressPosition;
+        }
+        else
+        {
+            start = initialPressPosition;
+            end = d->mousePosition;
+        }
+
+        viewport()->update(d->lastSelectionRect);
+
+        rect = QRect(start, end).intersected(viewport()->rect().adjusted(-16, -16, 16, 16));
+
+        viewport()->update(rect);
+
+        d->lastSelectionRect = rect;
+    }
 }
 
 void KListView::mousePressEvent(QMouseEvent *event)
@@ -890,6 +939,8 @@ void KListView::dragMoveEvent(QDragMoveEvent *event)
     }
 
     d->dragLeftViewport = false;
+
+    d->drawDraggedItems();
 }
 
 void KListView::dragLeaveEvent(QDragLeaveEvent *event)
@@ -936,6 +987,8 @@ void KListView::rowsInsertedArtifficial(const QModelIndex &parent,
                                         int start,
                                         int end)
 {
+    Q_UNUSED(parent);
+
     d->lastSelection = QItemSelection();
     d->elementsInfo.clear();
     d->elementsPosition.clear();