X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/f208acd5f68c8516b9f6a920cc229803637e23e9..265a1495a27e4ee4b36357a1eae7ca2b17f7976a:/src/kitemviews/kitemlistcontroller.cpp diff --git a/src/kitemviews/kitemlistcontroller.cpp b/src/kitemviews/kitemlistcontroller.cpp index 1db665f47..cd60c3a41 100644 --- a/src/kitemviews/kitemlistcontroller.cpp +++ b/src/kitemviews/kitemlistcontroller.cpp @@ -64,7 +64,7 @@ KItemListController::KItemListController(KItemModelBase *model, KItemListView *v m_autoActivationTimer = new QTimer(this); m_autoActivationTimer->setSingleShot(true); - m_autoActivationTimer->setInterval(-1); + m_autoActivationTimer->setInterval(750); connect(m_autoActivationTimer, &QTimer::timeout, this, &KItemListController::slotAutoActivationTimeout); setModel(model); @@ -200,14 +200,14 @@ int KItemListController::indexCloseToMousePressedPosition() const return -1; } -void KItemListController::setAutoActivationDelay(int delay) +void KItemListController::setAutoActivationEnabled(bool enabled) { - m_autoActivationTimer->setInterval(delay); + m_autoActivationEnabled = enabled; } -int KItemListController::autoActivationDelay() const +bool KItemListController::isAutoActivationEnabled() const { - return m_autoActivationTimer->interval(); + return m_autoActivationEnabled; } void KItemListController::setSingleClickActivationEnforced(bool singleClick) @@ -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,13 +455,7 @@ bool KItemListController::keyPressEvent(QKeyEvent *event) case Qt::Key_Space: if (m_selectionBehavior == MultiSelection) { -#ifndef QT_NO_ACCESSIBILITY - // Move accessible focus to the item that is acted upon, so only the state change of this item is announced and not the whole view. - QAccessibleEvent accessibilityEvent(view(), QAccessible::Focus); - accessibilityEvent.setChild(index); - QAccessible::updateAccessibility(&accessibilityEvent); -#endif - if (controlPressed) { + if (controlPressed || m_selectionMode) { // Toggle the selection state of the current item. m_selectionManager->endAnchoredSelection(); m_selectionManager->setSelected(index, 1, KItemListSelectionManager::Toggle); @@ -509,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); } @@ -539,17 +521,23 @@ void KItemListController::slotChangeCurrentItem(const QString &text, bool search return; } int index; - if (searchFromNextItem) { - const int currentIndex = m_selectionManager->currentItem(); - index = m_model->indexForKeyboardSearch(text, (currentIndex + 1) % m_model->count()); + // In selection mode, always use the current (underlined) item, or the next item, for search start position. + if (m_selectionBehavior == NoSelection || m_selectionMode || m_selectionManager->hasSelection()) { + index = m_model->indexForKeyboardSearch(text, searchFromNextItem ? m_selectionManager->currentItem() + 1 : m_selectionManager->currentItem()); } else { 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); } @@ -869,7 +857,7 @@ bool KItemListController::dragMoveEvent(QGraphicsSceneDragDropEvent *event, cons Q_EMIT itemHovered(index); } - if (!m_autoActivationTimer->isActive() && m_autoActivationTimer->interval() >= 0 && m_model->canEnterOnHover(index)) { + if (m_autoActivationEnabled && !m_autoActivationTimer->isActive() && m_model->canEnterOnHover(index)) { m_autoActivationTimer->setProperty("index", index); m_autoActivationTimer->start(); newHoveredWidget->startActivateSoonAnimation(m_autoActivationTimer->remainingTime());