]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Don't consider drops on a row as drops on the row's item
authorFelix Ernst <fe.a.ernst@gmail.com>
Thu, 16 Jun 2022 09:11:36 +0000 (09:11 +0000)
committerFelix Ernst <fe.a.ernst@gmail.com>
Thu, 16 Jun 2022 09:11:36 +0000 (09:11 +0000)
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
src/kitemviews/kitemlistcontroller.h

index d6d276fa44eb115c3cc0b77a7ec0f927eca5ee9c..72227a1e194bce44a1420265396fb954551391e5 100644 (file)
@@ -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 &&
index 5fe195e9f490b7411b592f2cebd01f9c79332c9c..d2e56eb64b40dc7c6bc98b8e6532c146d3959b0a 100644 (file)
@@ -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