X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/8d7e600f63a1961294dfe2c278a710b4ce0716e9..40cc5f665d:/src/kitemviews/kitemlistcontroller.cpp diff --git a/src/kitemviews/kitemlistcontroller.cpp b/src/kitemviews/kitemlistcontroller.cpp index 3d83bc914..955e418e8 100644 --- a/src/kitemviews/kitemlistcontroller.cpp +++ b/src/kitemviews/kitemlistcontroller.cpp @@ -33,6 +33,7 @@ KItemListController::KItemListController(KItemModelBase* model, KItemListView* view, QObject* parent) : QObject(parent), m_singleClickActivationEnforced(false), + m_selectionMode(false), m_selectionTogglePressed(false), m_clearSelectionIfItemsAreNotDragged(false), m_isSwipeGesture(false), @@ -220,6 +221,16 @@ bool KItemListController::singleClickActivationEnforced() const return m_singleClickActivationEnforced; } +void KItemListController::setSelectionModeEnabled(bool enabled) +{ + m_selectionMode = enabled; +} + +bool KItemListController::selectionMode() const +{ + return m_selectionMode; +} + bool KItemListController::keyPressEvent(QKeyEvent* event) { int index = m_selectionManager->currentItem(); @@ -408,7 +419,9 @@ bool KItemListController::keyPressEvent(QKeyEvent* event) } case Qt::Key_Escape: - if (m_selectionBehavior != SingleSelection) { + if (m_selectionMode) { + Q_EMIT selectionModeChangeRequested(false); + } else if (m_selectionBehavior != SingleSelection) { m_selectionManager->clearSelection(); } m_keyboardManager->cancelSearch(); @@ -576,10 +589,11 @@ bool KItemListController::mouseMoveEvent(QGraphicsSceneMouseEvent* event, const return false; } + const QPointF pos = transform.map(event->pos()); + if (m_pressedIndex.has_value() && !m_view->rubberBand()->isActive()) { // Check whether a dragging should be started if (event->buttons() & Qt::LeftButton) { - const QPointF pos = transform.map(event->pos()); if ((pos - m_pressedMousePos).manhattanLength() >= QApplication::startDragDistance()) { if (!m_selectionManager->isSelected(m_pressedIndex.value())) { // Always assure that the dragged item gets selected. Usually this is already @@ -1028,8 +1042,6 @@ void KItemListController::tapTriggered(QTapGesture* tap, const QTransform& trans m_pressedIndex = m_view->itemAt(m_pressedMousePos); if (m_dragActionOrRightClick) { - onPress(tap->hotSpot().toPoint(), tap->position().toPoint(), Qt::NoModifier, Qt::RightButton); - onRelease(transform.map(tap->position()), Qt::NoModifier, Qt::RightButton, false); m_dragActionOrRightClick = false; } else { @@ -1060,6 +1072,9 @@ void KItemListController::tapAndHoldTriggered(QGestureEvent* event, const QTrans if (m_pressedIndex.has_value() && !m_selectionManager->isSelected(m_pressedIndex.value())) { m_selectionManager->clearSelection(); m_selectionManager->setSelected(m_pressedIndex.value()); + if (!m_selectionMode) { + Q_EMIT selectionModeChangeRequested(true); + } } else if (!m_pressedIndex.has_value()) { m_selectionManager->clearSelection(); startRubberBand(); @@ -1247,7 +1262,7 @@ void KItemListController::slotRubberBandChanged() // 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) { + if (!shiftOrControlPressed && !m_selectionMode) { m_oldSelection.clear(); } } @@ -1296,7 +1311,7 @@ void KItemListController::slotRubberBandChanged() } } while (!selectionFinished); - if (QApplication::keyboardModifiers() & Qt::ControlModifier) { + if ((QApplication::keyboardModifiers() & Qt::ControlModifier) || m_selectionMode) { // If Control is pressed, the selection state of all items in the rubberband is toggled. // Therefore, the new selection contains: // 1. All previously selected items which are not inside the rubberband, and @@ -1518,7 +1533,8 @@ bool KItemListController::onPress(const QPoint& screenPos, const QPointF& pos, c } const bool shiftPressed = modifiers & Qt::ShiftModifier; - const bool controlPressed = modifiers & Qt::ControlModifier; + const bool controlPressed = (modifiers & Qt::ControlModifier) || m_selectionMode; // Keeping selectionMode similar to pressing control will hopefully + // simplify the overall logic and possibilities both for users and devs. const bool leftClick = buttons & Qt::LeftButton; const bool rightClick = buttons & Qt::RightButton; @@ -1565,7 +1581,7 @@ bool KItemListController::onPress(const QPoint& screenPos, const QPointF& pos, c return false; } } - } else if (pressedItemAlreadySelected && !shiftOrControlPressed && (buttons & Qt::LeftButton)) { + } else if (pressedItemAlreadySelected && !shiftOrControlPressed && leftClick) { // 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. @@ -1747,7 +1763,7 @@ bool KItemListController::onRelease(const QPointF& pos, const Qt::KeyboardModifi } else { const bool singleClickActivation = m_view->style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick) || m_singleClickActivationEnforced; if (!singleClickActivation) { - emitItemActivated = touch; + emitItemActivated = touch && !m_selectionMode; } else { // activate on single click only if we didn't come from a rubber band release emitItemActivated = !rubberBandRelease;