]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/kitemviews/kitemlistcontroller.cpp
Mirror details view mode for right-to-left languages
[dolphin.git] / src / kitemviews / kitemlistcontroller.cpp
index 2cda2987b14c378fff91ea3011dc2a79ee40b029..5a396de61fd48f83be3144a771a36eea19fce194 100644 (file)
@@ -243,6 +243,20 @@ bool KItemListController::keyPressEvent(QKeyEvent *event)
 
     const bool horizontalScrolling = m_view->scrollOrientation() == Qt::Horizontal;
 
+    if (m_view->layoutDirection() == Qt::RightToLeft) {
+        // swap left and right arrow keys
+        switch (key) {
+        case Qt::Key_Left:
+            key = Qt::Key_Right;
+            break;
+        case Qt::Key_Right:
+            key = Qt::Key_Left;
+            break;
+        default:
+            break;
+        }
+    }
+
     // Handle the expanding/collapsing of items
     // expand / collapse all selected directories
     if (m_view->supportsItemExpanding() && m_model->isExpandable(index) && (key == Qt::Key_Right || key == Qt::Key_Left)) {
@@ -270,7 +284,9 @@ bool KItemListController::keyPressEvent(QKeyEvent *event)
     }
 
     const bool controlPressed = event->modifiers() & Qt::ControlModifier;
-    const bool shiftOrControlPressed = shiftPressed || controlPressed;
+    if (m_selectionMode && !controlPressed && !shiftPressed && (key == Qt::Key_Enter || key == Qt::Key_Return)) {
+        key = Qt::Key_Space; // In selection mode one moves around with arrow keys and toggles selection with Enter.
+    }
     const bool navigationPressed = key == Qt::Key_Home || key == Qt::Key_End || key == Qt::Key_PageUp || key == Qt::Key_PageDown || key == Qt::Key_Up
         || key == Qt::Key_Down || key == Qt::Key_Left || key == Qt::Key_Right;
 
@@ -297,34 +313,6 @@ bool KItemListController::keyPressEvent(QKeyEvent *event)
         }
     }
 
-    if (m_view->layoutDirection() == Qt::RightToLeft) {
-        if (horizontalScrolling) {
-            // swap up and down arrow keys
-            switch (key) {
-            case Qt::Key_Up:
-                key = Qt::Key_Down;
-                break;
-            case Qt::Key_Down:
-                key = Qt::Key_Up;
-                break;
-            default:
-                break;
-            }
-        } else if (!m_view->supportsItemExpanding()) {
-            // swap left and right arrow keys
-            switch (key) {
-            case Qt::Key_Left:
-                key = Qt::Key_Right;
-                break;
-            case Qt::Key_Right:
-                key = Qt::Key_Left;
-                break;
-            default:
-                break;
-            }
-        }
-    }
-
     const bool selectSingleItem = m_selectionBehavior != NoSelection && itemCount == 1 && navigationPressed;
 
     if (selectSingleItem) {
@@ -467,7 +455,7 @@ bool KItemListController::keyPressEvent(QKeyEvent *event)
 
     case Qt::Key_Space:
         if (m_selectionBehavior == MultiSelection) {
-            if (controlPressed) {
+            if (controlPressed || m_selectionMode) {
                 // Toggle the selection state of the current item.
                 m_selectionManager->endAnchoredSelection();
                 m_selectionManager->setSelected(index, 1, KItemListSelectionManager::Toggle);
@@ -503,13 +491,13 @@ bool KItemListController::keyPressEvent(QKeyEvent *event)
             break;
 
         case MultiSelection:
-            if (controlPressed) {
+            if (controlPressed || (m_selectionMode && !shiftPressed)) {
                 m_selectionManager->endAnchoredSelection();
             }
 
             m_selectionManager->setCurrentItem(index);
 
-            if (!shiftOrControlPressed) {
+            if (!shiftPressed && !controlPressed && !m_selectionMode) {
                 m_selectionManager->clearSelection();
                 m_selectionManager->setSelected(index, 1);
             }
@@ -540,10 +528,16 @@ void KItemListController::slotChangeCurrentItem(const QString &text, bool search
         index = m_model->indexForKeyboardSearch(text, 0);
     }
     if (index >= 0) {
+        if (m_selectionMode) {
+            m_selectionManager->endAnchoredSelection();
+        }
+
         m_selectionManager->setCurrentItem(index);
 
         if (m_selectionBehavior != NoSelection) {
-            m_selectionManager->replaceSelection(index);
+            if (!m_selectionMode) { // Don't clear the selection in selection mode.
+                m_selectionManager->replaceSelection(index);
+            }
             m_selectionManager->beginAnchoredSelection(index);
         }
 
@@ -700,6 +694,20 @@ bool KItemListController::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event,
     const QPointF pos = transform.map(event->pos());
     const std::optional<int> index = m_view->itemAt(pos);
 
+    if (event->button() & (Qt::ForwardButton | Qt::BackButton)) {
+        // "Forward" and "Back" are reserved for quickly navigating through the
+        // history. Double-clicking those buttons should be interpreted as two
+        // separate button presses. We arrive here for the second click, which
+        // we now react to just as we would for a singular click
+        Q_EMIT mouseButtonPressed(index.value_or(-1), event->button());
+        return false;
+    }
+
+    if (!index.has_value()) {
+        Q_EMIT doubleClickViewBackground(event->button());
+        return false;
+    }
+
     // Expand item if desired - See Bug 295573
     if (m_mouseDoubleClickAction != ActivateItemOnly) {
         if (m_view && m_model && m_view->supportsItemExpanding() && m_model->isExpandable(index.value_or(-1))) {
@@ -708,7 +716,7 @@ bool KItemListController::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event,
         }
     }
 
-    if (event->button() & Qt::RightButton) {
+    if (event->button() & ~Qt::LeftButton) {
         return false;
     }
 
@@ -718,6 +726,9 @@ bool KItemListController::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event,
 
     const bool emitItemActivated = index.has_value() && index.value() < m_model->count() && !m_view->isAboveExpansionToggle(index.value(), pos);
     if (emitItemActivated) {
+        if (!QApplication::keyboardModifiers()) {
+            m_selectionManager->clearSelection(); // The user does not want to manage/manipulate the item currently, only activate it.
+        }
         Q_EMIT itemActivated(index.value());
     }
     return false;
@@ -1656,10 +1667,14 @@ bool KItemListController::onPress(const QPointF &pos, const Qt::KeyboardModifier
                 // or we just keep going for double-click activation
                 if (m_view->style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick) || m_singleClickActivationEnforced) {
                     if (!pressedItemAlreadySelected) {
-                        // An unselected item was clicked directly while deselecting multiple other items so we select it.
-                        m_selectionManager->setSelected(m_pressedIndex.value(), 1, KItemListSelectionManager::Toggle);
+                        // An unselected item was clicked directly while deselecting multiple other items so we mark it "current".
                         m_selectionManager->setCurrentItem(m_pressedIndex.value());
                         m_selectionManager->beginAnchoredSelection(m_pressedIndex.value());
+                        if (!leftClick) {
+                            // We select the item here because this press is not meant to directly activate the item.
+                            // We do not want to select items unless the user wants to edit them.
+                            m_selectionManager->setSelected(m_pressedIndex.value(), 1, KItemListSelectionManager::Toggle);
+                        }
                     }
                     return true; // event handled, don't create rubber band
                 }
@@ -1726,7 +1741,10 @@ bool KItemListController::onPress(const QPointF &pos, const Qt::KeyboardModifier
             break;
 
         case SingleSelection:
-            m_selectionManager->setSelected(m_pressedIndex.value());
+            if (!leftClick || shiftOrControlPressed
+                || (!m_view->style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick) && !m_singleClickActivationEnforced)) {
+                m_selectionManager->setSelected(m_pressedIndex.value());
+            }
             break;
 
         case MultiSelection:
@@ -1747,7 +1765,10 @@ bool KItemListController::onPress(const QPointF &pos, const Qt::KeyboardModifier
                 }
             } else if (!shiftPressed || !m_selectionManager->isAnchoredSelectionActive()) {
                 // Select the pressed item and start a new anchored selection
-                m_selectionManager->setSelected(m_pressedIndex.value(), 1, KItemListSelectionManager::Select);
+                if (!leftClick || shiftOrControlPressed
+                    || (!m_view->style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick) && !m_singleClickActivationEnforced)) {
+                    m_selectionManager->setSelected(m_pressedIndex.value(), 1, KItemListSelectionManager::Select);
+                }
                 m_selectionManager->beginAnchoredSelection(m_pressedIndex.value());
             }
             break;