From 011a7203952d933222bf0390720f487478510d34 Mon Sep 17 00:00:00 2001 From: Christian Halaszovich Date: Fri, 6 Dec 2024 17:38:10 +0100 Subject: [PATCH 1/3] should call acceptProposedAction in drop handler, only accept copy action --- QtPMbrowser/pmbrowserwindow.cpp | 37 +++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/QtPMbrowser/pmbrowserwindow.cpp b/QtPMbrowser/pmbrowserwindow.cpp index 09d2744..ef7b736 100644 --- a/QtPMbrowser/pmbrowserwindow.cpp +++ b/QtPMbrowser/pmbrowserwindow.cpp @@ -1150,14 +1150,16 @@ void PMbrowserWindow::openPreferences() void PMbrowserWindow::dragEnterEvent(QDragEnterEvent* event) { - auto mimedata = event->mimeData(); - if (mimedata->hasUrls()) { - auto urls = mimedata->urls(); - auto& url = urls[0]; - if (url.isLocalFile()) { - auto filename = url.toLocalFile(); - if (filename.endsWith(".dat")) { - event->acceptProposedAction(); + if (event->dropAction() == Qt::CopyAction) { + auto mimedata = event->mimeData(); + if (mimedata->hasUrls()) { + auto urls = mimedata->urls(); + auto& url = urls[0]; + if (url.isLocalFile()) { + auto filename = url.toLocalFile(); + if (filename.endsWith(".dat")) { + event->acceptProposedAction(); + } } } } @@ -1165,14 +1167,17 @@ void PMbrowserWindow::dragEnterEvent(QDragEnterEvent* event) void PMbrowserWindow::dropEvent(QDropEvent* event) { - auto mimedata = event->mimeData(); - if (mimedata->hasUrls()) { - auto urls = mimedata->urls(); - auto& url = urls[0]; - if (url.isLocalFile()) { - auto filename = url.toLocalFile(); - if (filename.endsWith(".dat")) { - loadFile(filename); + if (event->dropAction() == Qt::CopyAction) { + auto mimedata = event->mimeData(); + if (mimedata->hasUrls()) { + auto urls = mimedata->urls(); + auto& url = urls[0]; + if (url.isLocalFile()) { + auto filename = url.toLocalFile(); + if (filename.endsWith(".dat")) { + loadFile(filename); + event->acceptProposedAction(); + } } } } From 3c3934cb5be9a5f65dc56771e85b6620afd570f8 Mon Sep 17 00:00:00 2001 From: Christian Halaszovich Date: Fri, 6 Dec 2024 17:48:47 +0100 Subject: [PATCH 2/3] Only accept drop of single file. --- QtPMbrowser/pmbrowserwindow.cpp | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/QtPMbrowser/pmbrowserwindow.cpp b/QtPMbrowser/pmbrowserwindow.cpp index ef7b736..af9e9c7 100644 --- a/QtPMbrowser/pmbrowserwindow.cpp +++ b/QtPMbrowser/pmbrowserwindow.cpp @@ -1154,11 +1154,13 @@ void PMbrowserWindow::dragEnterEvent(QDragEnterEvent* event) auto mimedata = event->mimeData(); if (mimedata->hasUrls()) { auto urls = mimedata->urls(); - auto& url = urls[0]; - if (url.isLocalFile()) { - auto filename = url.toLocalFile(); - if (filename.endsWith(".dat")) { - event->acceptProposedAction(); + if (urls.length() == 1) { // only accept 1 file at a time + auto& url = urls[0]; + if (url.isLocalFile()) { + auto filename = url.toLocalFile(); + if (filename.endsWith(".dat")) { + event->acceptProposedAction(); + } } } } @@ -1171,12 +1173,14 @@ void PMbrowserWindow::dropEvent(QDropEvent* event) auto mimedata = event->mimeData(); if (mimedata->hasUrls()) { auto urls = mimedata->urls(); - auto& url = urls[0]; - if (url.isLocalFile()) { - auto filename = url.toLocalFile(); - if (filename.endsWith(".dat")) { - loadFile(filename); - event->acceptProposedAction(); + if (urls.length() == 1) { + auto& url = urls[0]; + if (url.isLocalFile()) { + auto filename = url.toLocalFile(); + if (filename.endsWith(".dat")) { + loadFile(filename); + event->acceptProposedAction(); + } } } } From 41c4ad5ef648957d1d3e559eda05bc8200e98e0c Mon Sep 17 00:00:00 2001 From: Christian Halaszovich Date: Fri, 6 Dec 2024 17:58:24 +0100 Subject: [PATCH 3/3] only accept dropEvent if file was loaded --- QtPMbrowser/pmbrowserwindow.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/QtPMbrowser/pmbrowserwindow.cpp b/QtPMbrowser/pmbrowserwindow.cpp index af9e9c7..f21cf55 100644 --- a/QtPMbrowser/pmbrowserwindow.cpp +++ b/QtPMbrowser/pmbrowserwindow.cpp @@ -1179,7 +1179,8 @@ void PMbrowserWindow::dropEvent(QDropEvent* event) auto filename = url.toLocalFile(); if (filename.endsWith(".dat")) { loadFile(filename); - event->acceptProposedAction(); + // check file has been loaded: + if(datfile) event->acceptProposedAction(); } } }