]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Fix rubberband-issue in combination with Shift- and Control-key
authorPeter Penz <peter.penz19@gmail.com>
Sat, 20 Aug 2011 21:26:07 +0000 (23:26 +0200)
committerPeter Penz <peter.penz19@gmail.com>
Sat, 20 Aug 2011 21:27:23 +0000 (23:27 +0200)
The old selection must be remembered before starting the rubberband
selection, otherwise it would not be possible anymore to deselect
items that have been selected by the rubberband itself.

src/kitemviews/kitemlistcontroller.cpp
src/kitemviews/kitemlistcontroller.h

index 92a14b23d5f37fd9917a07e0bf66e488ddee1d25..beb5b5c0a51d91a65218082c12bde9d4522523c3 100644 (file)
@@ -38,7 +38,8 @@ KItemListController::KItemListController(QObject* parent) :
     m_model(0),
     m_view(0),
     m_selectionManager(new KItemListSelectionManager(this)),
-    m_pressedIndex(-1)
+    m_pressedIndex(-1),
+    m_oldSelection()
 {
 }
 
@@ -294,6 +295,8 @@ bool KItemListController::mousePressEvent(QGraphicsSceneMouseEvent* event, const
         } else {
             startPos.rx() += m_view->offset();
         }
+
+        m_oldSelection = m_selectionManager->selectedItems();
         rubberBand->setStartPosition(startPos);
         rubberBand->setEndPosition(startPos);
         rubberBand->setActive(true);
@@ -338,6 +341,7 @@ bool KItemListController::mouseReleaseEvent(QGraphicsSceneMouseEvent* event, con
     if (rubberBand->isActive()) {
         disconnect(rubberBand, SIGNAL(endPositionChanged(QPointF,QPointF)), this, SLOT(slotRubberBandChanged()));
         rubberBand->setActive(false);
+        m_oldSelection.clear();
         m_pressedIndex = -1;
         return false;
     }
@@ -577,14 +581,13 @@ 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
+    if (!m_oldSelection.isEmpty()) {
+        // Clear the old selection that was available before the rubberband has
+        // been activated in case if no Shift- or Control-key are pressed
         const bool shiftOrControlPressed = QApplication::keyboardModifiers() & Qt::ShiftModifier ||
                                            QApplication::keyboardModifiers() & Qt::ControlModifier;
-        if (shiftOrControlPressed) {
-            previousSelectedItems = m_selectionManager->selectedItems();
+        if (!shiftOrControlPressed) {
+            m_oldSelection.clear();
         }
     }
 
@@ -631,7 +634,7 @@ void KItemListController::slotRubberBandChanged()
         }
     } while (!selectionFinished);
 
-    m_selectionManager->setSelectedItems(selectedItems + previousSelectedItems);
+    m_selectionManager->setSelectedItems(selectedItems + m_oldSelection);
 }
 
 #include "kitemlistcontroller.moc"
index 49442c643ff74de9107c73704d79fa091ae37780..90850bae175f3876c78af38d358f65c179c22087 100644 (file)
@@ -26,6 +26,7 @@
 #include <libdolphin_export.h>
 
 #include <QObject>
+#include <QSet>
 
 class KItemModelBase;
 class KItemListSelectionManager;
@@ -134,6 +135,14 @@ private:
     KItemListView* m_view;
     KItemListSelectionManager* m_selectionManager;
     int m_pressedIndex;
+
+    /**
+     * When starting a rubberband selection during a Shift- or Control-key has been
+     * pressed the current selection should never be deleted. To be able to restore
+     * the current selection it is remembered in m_oldSelection before
+     * rubberband gets activated.
+     */
+    QSet<int> m_oldSelection;
 };
 
 #endif