]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/kitemviews/kitemlistcontroller.cpp
Icon-rectangle and selection-toggle optimizations
[dolphin.git] / src / kitemviews / kitemlistcontroller.cpp
index 0f22d70bbc4653e2cb9832df866be6195c493d59..69320247a8e0198c31061b2d5ea6c6c348bf98cb 100644 (file)
@@ -203,7 +203,8 @@ bool KItemListController::keyPressEvent(QKeyEvent* event)
         }
     }
     
-    const bool selectSingleItem = itemCount == 1 &&
+    const bool selectSingleItem = m_selectionBehavior != NoSelection &&
+                                  itemCount == 1 &&
                                   (key == Qt::Key_Home || key == Qt::Key_End  ||
                                    key == Qt::Key_Up   || key == Qt::Key_Down ||
                                    key == Qt::Key_Left || key == Qt::Key_Right);
@@ -216,10 +217,14 @@ bool KItemListController::keyPressEvent(QKeyEvent* event)
     switch (key) {
     case Qt::Key_Home:
         index = 0;
+        m_keyboardAnchorIndex = index;
+        m_keyboardAnchorPos = keyboardAnchorPos(index);
         break;
 
     case Qt::Key_End:
         index = itemCount - 1;
+        m_keyboardAnchorIndex = index;
+        m_keyboardAnchorPos = keyboardAnchorPos(index);
         break;
 
     case Qt::Key_Left:
@@ -318,13 +323,15 @@ bool KItemListController::keyPressEvent(QKeyEvent* event)
     }
 
     case Qt::Key_Space:
-        if (controlPressed) {
-            m_selectionManager->endAnchoredSelection();
-            m_selectionManager->setSelected(index, 1, KItemListSelectionManager::Toggle);
-            m_selectionManager->beginAnchoredSelection(index);
-        } else {
-            const int current = m_selectionManager->currentItem();
-            m_selectionManager->setSelected(current);
+        if (m_selectionBehavior == MultiSelection) {
+            if (controlPressed) {
+                m_selectionManager->endAnchoredSelection();
+                m_selectionManager->setSelected(index, 1, KItemListSelectionManager::Toggle);
+                m_selectionManager->beginAnchoredSelection(index);
+            } else {
+                const int current = m_selectionManager->currentItem();
+                m_selectionManager->setSelected(current);
+            }
         }
         break;
 
@@ -357,19 +364,33 @@ bool KItemListController::keyPressEvent(QKeyEvent* event)
     }
 
     if (m_selectionManager->currentItem() != index) {
-        if (controlPressed) {
-            m_selectionManager->endAnchoredSelection();
-        }
-
-        m_selectionManager->setCurrentItem(index);
+        switch (m_selectionBehavior) {
+        case NoSelection:
+            m_selectionManager->setCurrentItem(index);
+            break;
 
-        if (!shiftOrControlPressed || m_selectionBehavior == SingleSelection) {
+        case SingleSelection:
+            m_selectionManager->setCurrentItem(index);
             m_selectionManager->clearSelection();
             m_selectionManager->setSelected(index, 1);
-        }
+            break;
+
+        case MultiSelection:
+            if (controlPressed) {
+                m_selectionManager->endAnchoredSelection();
+            }
 
-        if (!shiftPressed) {
-            m_selectionManager->beginAnchoredSelection(index);
+            m_selectionManager->setCurrentItem(index);
+
+            if (!shiftOrControlPressed) {
+                m_selectionManager->clearSelection();
+                m_selectionManager->setSelected(index, 1);
+            }
+
+            if (!shiftPressed) {
+                m_selectionManager->beginAnchoredSelection(index);
+            }
+            break;
         }
 
         m_view->scrollToItem(index);
@@ -471,7 +492,7 @@ bool KItemListController::mousePressEvent(QGraphicsSceneMouseEvent* event, const
                                 (!shiftOrControlPressed && !pressedItemAlreadySelected);
     if (clearSelection) {
         m_selectionManager->clearSelection();
-    } else if (pressedItemAlreadySelected && (event->buttons() & Qt::LeftButton)) {
+    } else if (pressedItemAlreadySelected && !shiftOrControlPressed && (event->buttons() & Qt::LeftButton)) {
         // The user might want to start dragging multiple items, but if he clicks the item
         // in order to trigger it instead, the other selected items must be deselected.
         // However, we do not know yet what the user is going to do.
@@ -710,6 +731,12 @@ bool KItemListController::dragLeaveEvent(QGraphicsSceneDragDropEvent* event, con
 {
     Q_UNUSED(event);
     Q_UNUSED(transform);
+
+    KItemListWidget* widget = hoveredWidget();
+    if (widget) {
+        widget->setHovered(false);
+        emit itemUnhovered(widget->index());
+    }
     return false;
 }