]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Respect Shift- and Control-key for the rubberband selection
authorPeter Penz <peter.penz19@gmail.com>
Sat, 20 Aug 2011 21:11:55 +0000 (23:11 +0200)
committerPeter Penz <peter.penz19@gmail.com>
Sat, 20 Aug 2011 21:12:54 +0000 (23:12 +0200)
If the user has pressed the Shift- or Control-key during the
rubberband selection, the previous selection should not be cleared.

src/kitemviews/kitemlistcontroller.cpp

index 50c39c18bcf61e8ccd47307602b4375f59ee0bbc..92a14b23d5f37fd9917a07e0bf66e488ddee1d25 100644 (file)
@@ -26,6 +26,7 @@
 #include "kitemlistrubberband_p.h"
 #include "kitemlistselectionmanager.h"
 
+#include <QApplication>
 #include <QEvent>
 #include <QGraphicsSceneEvent>
 
@@ -576,6 +577,17 @@ void KItemListController::slotRubberBandChanged()
         rubberBandRect.translate(-m_view->offset(), 0);
     }
 
+    QSet<int> previousSelectedItems;
+    if (m_selectionManager->hasSelection()) {
+        // Don't clear the current selection in case if the user pressed the
+        // Shift- or Control-key during the rubberband selection
+        const bool shiftOrControlPressed = QApplication::keyboardModifiers() & Qt::ShiftModifier ||
+                                           QApplication::keyboardModifiers() & Qt::ControlModifier;
+        if (shiftOrControlPressed) {
+            previousSelectedItems = m_selectionManager->selectedItems();
+        }
+    }
+
     QSet<int> selectedItems;
 
     // Select all visible items that intersect with the rubberband
@@ -619,7 +631,7 @@ void KItemListController::slotRubberBandChanged()
         }
     } while (!selectionFinished);
 
-    m_selectionManager->setSelectedItems(selectedItems);
+    m_selectionManager->setSelectedItems(selectedItems + previousSelectedItems);
 }
 
 #include "kitemlistcontroller.moc"