Commit c3de8676 authored by Elvis Angelaccio's avatar Elvis Angelaccio

Fix drop menu position with urlnavigator drops

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:
parent cf273cd8
......@@ -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);
......@@ -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) {
m_view->dropUrls(destination, event, m_urlNavigator->dropWidget());
// TODO: remove as soon as we can hard-depend of KF5 >= 5.37
m_view->dropUrls(destination, event, m_view);
// Initialize status bar
m_statusBar = new DolphinStatusBar(this);
......@@ -1051,14 +1051,14 @@ void DolphinView::slotItemDropEvent(int index, QGraphicsSceneDragDropEvent* even
dropUrls(destUrl, &dropEvent);
dropUrls(destUrl, &dropEvent, this);
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);
......@@ -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();
......@@ -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,
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment