From 5ebf2065d525160a29f1d7aeef41541c6033bccf Mon Sep 17 00:00:00 2001 From: Felix Ernst Date: Thu, 16 Jun 2022 09:11:36 +0000 Subject: [PATCH] Don't consider drops on a row as drops on the row's item Since d3839617193e92463806580699caa595c892b8a6 in details view mode clicking anywhere within the row is considered a click on the item. That commit also changed it so that dropping files anywhere inside a row would make it so the files are received by the folder of that row. This commit reverts the drop behaviour to be identical to the old one. I am having trouble explaining why this is better because one can look at it in different ways. Bottom line is that one doesn't really feel like one is dropping files inside a folder unless the mouse cursor is actually directly above a folder's icon or name. Another argument is that it is normal behaviour to just throw files onto an application and the files then being opened by it. Having potentially large parts of the view area covered by the rows of folders means that there has to be more of a conscious effort to not drop the files inside one of the folders by accident while with this commit one has to aim precisely onto a folder to do it intentionally. CCBUG: 453700 --- src/kitemviews/kitemlistcontroller.cpp | 24 ++++++++++++++++++++++-- src/kitemviews/kitemlistcontroller.h | 9 +++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/kitemviews/kitemlistcontroller.cpp b/src/kitemviews/kitemlistcontroller.cpp index d6d276fa44..72227a1e19 100644 --- a/src/kitemviews/kitemlistcontroller.cpp +++ b/src/kitemviews/kitemlistcontroller.cpp @@ -724,7 +724,7 @@ bool KItemListController::dragMoveEvent(QGraphicsSceneDragDropEvent* event, cons KItemListWidget* oldHoveredWidget = hoveredWidget(); const QPointF pos = transform.map(event->pos()); - KItemListWidget* newHoveredWidget = widgetForPos(pos); + KItemListWidget* newHoveredWidget = widgetForDropPos(pos); if (oldHoveredWidget != newHoveredWidget) { m_autoActivationTimer->stop(); @@ -806,7 +806,12 @@ bool KItemListController::dropEvent(QGraphicsSceneDragDropEvent* event, const QT Q_EMIT aboveItemDropEvent(dropAboveIndex, event); } else if (!event->mimeData()->hasFormat(m_model->blacklistItemDropEventMimeType())) { // Something has been dropped on an item or on an empty part of the view. - Q_EMIT itemDropEvent(m_view->itemAt(pos).value_or(-1), event); + const KItemListWidget *receivingWidget = widgetForDropPos(pos); + if (receivingWidget) { + Q_EMIT itemDropEvent(receivingWidget->index(), event); + } else { + Q_EMIT itemDropEvent(-1, event); + } } QAccessibleEvent accessibilityEvent(view(), QAccessible::DragDropEnd); @@ -1364,6 +1369,21 @@ KItemListWidget* KItemListController::widgetForPos(const QPointF& pos) const return nullptr; } +KItemListWidget* KItemListController::widgetForDropPos(const QPointF& pos) const +{ + Q_ASSERT(m_view); + + const auto widgets = m_view->visibleItemListWidgets(); + for (KItemListWidget* widget : widgets) { + const QPointF mappedPos = widget->mapFromItem(m_view, pos); + if (widget->contains(mappedPos)) { + return widget; + } + } + + return nullptr; +} + void KItemListController::updateKeyboardAnchor() { const bool validAnchor = m_keyboardAnchorIndex >= 0 && diff --git a/src/kitemviews/kitemlistcontroller.h b/src/kitemviews/kitemlistcontroller.h index 5fe195e9f4..d2e56eb64b 100644 --- a/src/kitemviews/kitemlistcontroller.h +++ b/src/kitemviews/kitemlistcontroller.h @@ -253,6 +253,15 @@ private: */ KItemListWidget* widgetForPos(const QPointF& pos) const; + /** + * @return Widget that should receive a drop event if an item is dropped at \a pos. 0 is returned + * if no widget should receive a drop event at the position. + * + * While widgetForPos() returns a widget if \a pos is anywhere inside the hover highlight area of the widget, + * widgetForDropPos() only returns a widget if \a pos is directly above the widget (widget->contains(pos) == true). + */ + KItemListWidget* widgetForDropPos(const QPointF& pos) const; + /** * Updates m_keyboardAnchorIndex and m_keyboardAnchorPos. If no anchor is * set, it will be adjusted to the current item. If it is set it will be