X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/c68f1f6f8d6c24123c9c5df4d2e91a9d2462ceb6..b2f18e411a929665257dad8c6a51f3e2e617cee5:/src/kitemviews/kitemlistcontroller.cpp diff --git a/src/kitemviews/kitemlistcontroller.cpp b/src/kitemviews/kitemlistcontroller.cpp index 80c28f25c..4d926474b 100644 --- a/src/kitemviews/kitemlistcontroller.cpp +++ b/src/kitemviews/kitemlistcontroller.cpp @@ -13,10 +13,11 @@ #include "kitemlistview.h" #include "private/kitemlistkeyboardsearchmanager.h" #include "private/kitemlistrubberband.h" -#include "private/ktwofingerswipe.h" -#include "private/ktwofingertap.h" #include "views/draganddrophelper.h" +#include +#include + #include #include #include @@ -871,7 +872,8 @@ bool KItemListController::hoverMoveEvent(QGraphicsSceneHoverEvent* event, const newHoveredWidget->setExpansionAreaHovered(true); } else { // make sure we unhover the old one first if old!=new - if (auto oldHoveredWidget = hoveredWidget(); oldHoveredWidget && oldHoveredWidget != newHoveredWidget) { + auto oldHoveredWidget = hoveredWidget(); + if (oldHoveredWidget && oldHoveredWidget != newHoveredWidget) { oldHoveredWidget->setHovered(false); Q_EMIT itemUnhovered(oldHoveredWidget->index()); } @@ -888,9 +890,11 @@ bool KItemListController::hoverMoveEvent(QGraphicsSceneHoverEvent* event, const // (no-op in this branch for masked hover) } else { - newHoveredWidget->setHovered(true); newHoveredWidget->setHoverPosition(mappedPos); - Q_EMIT itemHovered(newHoveredWidget->index()); + if (oldHoveredWidget != newHoveredWidget) { + newHoveredWidget->setHovered(true); + Q_EMIT itemHovered(newHoveredWidget->index()); + } } } } else { @@ -1493,6 +1497,7 @@ bool KItemListController::onPress(const QPoint& screenPos, const QPointF& pos, c const bool shiftPressed = modifiers & Qt::ShiftModifier; const bool controlPressed = modifiers & Qt::ControlModifier; + const bool leftClick = buttons & Qt::LeftButton; const bool rightClick = buttons & Qt::RightButton; // The previous selection is cleared if either @@ -1521,6 +1526,12 @@ bool KItemListController::onPress(const QPoint& screenPos, const QPointF& pos, c // and short-circuit for single-click activation (it will then propagate to onRelease and activate the item) // 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); + m_selectionManager->setCurrentItem(m_pressedIndex.value()); + m_selectionManager->beginAnchoredSelection(m_pressedIndex.value()); + } return true; // event handled, don't create rubber band } } else { @@ -1568,6 +1579,7 @@ bool KItemListController::onPress(const QPoint& screenPos, const QPointF& pos, c } if (m_pressedIndex.has_value()) { + // The hover highlight area of an item is being pressed. m_selectionManager->setCurrentItem(m_pressedIndex.value()); const auto row = m_view->m_visibleItems.value(m_pressedIndex.value()); // anything outside of row.contains() will be the empty region of the row rect const bool hitTargetIsRowEmptyRegion = !row->contains(row->mapFromItem(m_view, pos)); @@ -1576,8 +1588,14 @@ bool KItemListController::onPress(const QPoint& screenPos, const QPointF& pos, c bool createRubberBand = (hitTargetIsRowEmptyRegion && m_selectionManager->selectedItems().isEmpty()); if (rightClick && hitTargetIsRowEmptyRegion) { - // we got a right click outside the text rect, default to action on the current url and not the pressed item - Q_EMIT itemContextMenuRequested(m_pressedIndex.value(), screenPos); + // We have a right click outside the icon and text rect but within the hover highlight area + // but it is unclear if this means that a selection rectangle for an item was clicked or the background of the view. + if (m_selectionManager->selectedItems().contains(m_pressedIndex.value())) { + // The selection rectangle for an item was clicked + Q_EMIT itemContextMenuRequested(m_pressedIndex.value(), screenPos); + } else { + Q_EMIT viewContextMenuRequested(screenPos); + } return true; } @@ -1590,10 +1608,21 @@ bool KItemListController::onPress(const QPoint& screenPos, const QPointF& pos, c break; case MultiSelection: - if (controlPressed && !shiftPressed) { - m_selectionManager->setSelected(m_pressedIndex.value(), 1, KItemListSelectionManager::Toggle); - m_selectionManager->beginAnchoredSelection(m_pressedIndex.value()); - createRubberBand = false; // multi selection, don't propagate any further + if (controlPressed && !shiftPressed && leftClick) { + // A left mouse button press is happening on an item while control is pressed. This either means a user wants to: + // - toggle the selection of item(s) or + // - they want to begin a drag on the item(s) to copy them. + // We rule out the latter, if the item is not clicked directly and was unselected previously. + const auto row = m_view->m_visibleItems.value(m_pressedIndex.value()); + const auto mappedPos = row->mapFromItem(m_view, pos); + if (!row->iconRect().contains(mappedPos) && !row->textRect().contains(mappedPos) && !pressedItemAlreadySelected) { + createRubberBand = true; + } else { + m_selectionManager->setSelected(m_pressedIndex.value(), 1, KItemListSelectionManager::Toggle); + m_selectionManager->beginAnchoredSelection(m_pressedIndex.value()); + createRubberBand = false; // multi selection, don't propagate any further + // This will be the start of an item drag-to-copy operation if the user now moves the mouse before releasing the mouse button. + } } 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);