]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Fix drop menu position with urlnavigator drops
authorElvis Angelaccio <elvis.angelaccio@kde.org>
Wed, 12 Jul 2017 08:40:15 +0000 (10:40 +0200)
committerElvis Angelaccio <elvis.angelaccio@kde.org>
Thu, 27 Jul 2017 13:49:52 +0000 (15:49 +0200)
Commit 1e251d2f6a in kio broke drop menus when dropping on the URL
navigator (menus show up in the DolphinView rather than the URL bar).
This happens because in DolphinView::dropUrls() we set `this` as the
widget passed to KJobWidgets::setWindow() (in DragAndDropHelper::dropUrls()).

We need to replace `this` with the actual widget that received the QDropEvent
and that can mapToGlobal() the relative pos of the drop event.
Unfortunately this widget is not KUrlNavigator itself, but one of its
KUrlNavigatorButton children (private class, not exported). So
unfortunately we need a new API in KIO that exposes this child widget.

Differential Revision: https://phabricator.kde.org/D6684

src/dolphintabwidget.cpp
src/dolphinviewcontainer.cpp
src/views/dolphinview.cpp
src/views/dolphinview.h
src/views/draganddrophelper.h

index 94b7a0144ccb2540b36787a5a256b9a11243e90b..d9b7d7e13eb2176fc8bd86f49544a1869bd349c4 100644 (file)
@@ -284,7 +284,7 @@ void DolphinTabWidget::tabDropEvent(int index, QDropEvent* event)
 {
     if (index >= 0) {
         DolphinView* view = tabPageAt(index)->activeViewContainer()->view();
-        view->dropUrls(view->url(), event);
+        view->dropUrls(view->url(), event, view);
     }
 }
 
index 72ced931b709f21d95848b541372b618df8edab5..198879f377b52ec9571acc0e5a42847ad2fb834c 100644 (file)
@@ -29,6 +29,7 @@
 #include <KFilePlacesModel>
 #include <KLocalizedString>
 #include <KIO/PreviewJob>
+#include <kio_version.h>
 #include <KMessageWidget>
 #include <KShell>
 #include <QUrl>
@@ -135,8 +136,14 @@ DolphinViewContainer::DolphinViewContainer(const QUrl& url, QWidget* parent) :
             this, &DolphinViewContainer::slotUrlNavigatorLocationChanged);
     connect(m_urlNavigator, &KUrlNavigator::returnPressed,
             this, &DolphinViewContainer::slotReturnPressed);
-    connect(m_urlNavigator, &KUrlNavigator::urlsDropped,
-            m_view, &DolphinView::dropUrls);
+    connect(m_urlNavigator, &KUrlNavigator::urlsDropped, this, [=](const QUrl &destination, QDropEvent *event) {
+#if KIO_VERSION >= QT_VERSION_CHECK(5, 37, 0)
+        m_view->dropUrls(destination, event, m_urlNavigator->dropWidget());
+#else
+        // TODO: remove as soon as we can hard-depend of KF5 >= 5.37
+        m_view->dropUrls(destination, event, m_view);
+#endif
+    });
 
     // Initialize status bar
     m_statusBar = new DolphinStatusBar(this);
index bef6a8b73aa8e285a90e06ef61d09ecc4b64122d..5fcec9241217e9d1d950eecb63d827873471186b 100644 (file)
@@ -1051,14 +1051,14 @@ void DolphinView::slotItemDropEvent(int index, QGraphicsSceneDragDropEvent* even
                          event->mimeData(),
                          event->buttons(),
                          event->modifiers());
-    dropUrls(destUrl, &dropEvent);
+    dropUrls(destUrl, &dropEvent, this);
 
     setActive(true);
 }
 
-void DolphinView::dropUrls(const QUrl &destUrl, QDropEvent *dropEvent)
+void DolphinView::dropUrls(const QUrl &destUrl, QDropEvent *dropEvent, QWidget *dropWidget)
 {
-    KIO::DropJob* job = DragAndDropHelper::dropUrls(destUrl, dropEvent, this);
+    KIO::DropJob* job = DragAndDropHelper::dropUrls(destUrl, dropEvent, dropWidget);
 
     if (job) {
         connect(job, &KIO::DropJob::result, this, &DolphinView::slotPasteJobResult);
index 6b62b5da68c1f7474abff80510fc3d24508c7ddc..5c832efd1fe8acc813366ca41f02f07a312c0a3a 100644 (file)
@@ -363,9 +363,9 @@ public slots:
     void pasteIntoFolder();
 
     /**
-     * Handles a drop of @p dropEvent onto @p destUrl
+     * Handles a drop of @p dropEvent onto widget @p dropWidget and destination @p destUrl
      */
-    void dropUrls(const QUrl &destUrl, QDropEvent *dropEvent);
+    void dropUrls(const QUrl &destUrl, QDropEvent *dropEvent, QWidget *dropWidget);
 
     void stopLoading();
 
index fe77b1e6ee9bc017613bbdf77e074c9daea064c9..3153f06ef0c879faef5b03878e295a63f2baa6bd 100644 (file)
@@ -41,7 +41,7 @@ public:
      * @param destUrl   URL of the item destination. Is used only if destItem::isNull()
      *                  is true.
      * @param event     Drop event.
-     * @param window    Associated widget.
+     * @param window    Widget where the drop happened, will be used as parent of the drop menu.
      * @return          KIO::DropJob pointer
      */
     static KIO::DropJob* dropUrls(const QUrl& destUrl,