summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/wasm/qwasmdrag.cpp
diff options
context:
space:
mode:
authorLorn Potter <[email protected]>2023-10-19 16:33:25 +1000
committerLorn Potter <[email protected]>2023-12-22 08:06:08 +1000
commit1f7d222cec1e8659d7bfa19ec3c1098a2bc00f35 (patch)
treec476f09ec2849c525805b9d6d714fff07b23fee4 /src/plugins/platforms/wasm/qwasmdrag.cpp
parent8cc84a1386b77701ebc9c9d4efbc1b033d0e326b (diff)
wasm: write file to storage on drop
Change-Id: Ibd1b5d623da07ad611cce577929a23ba991b6738 Pick-to: 6.7 Reviewed-by: Morten Johan Sørvig <[email protected]>
Diffstat (limited to 'src/plugins/platforms/wasm/qwasmdrag.cpp')
-rw-r--r--src/plugins/platforms/wasm/qwasmdrag.cpp42
1 files changed, 26 insertions, 16 deletions
diff --git a/src/plugins/platforms/wasm/qwasmdrag.cpp b/src/plugins/platforms/wasm/qwasmdrag.cpp
index 82f225158c8..b765fe8268d 100644
--- a/src/plugins/platforms/wasm/qwasmdrag.cpp
+++ b/src/plugins/platforms/wasm/qwasmdrag.cpp
@@ -14,6 +14,7 @@
#include <QtCore/qeventloop.h>
#include <QtCore/qmimedata.h>
#include <QtCore/qtimer.h>
+#include <QFile>
#include <functional>
#include <string>
@@ -152,22 +153,31 @@ void QWasmDrag::onNativeDrop(DragEvent *event)
const QPointF pointInTargetWindowCoords = event->targetWindow->mapFromGlobal(pointInQtScreen);
const Qt::DropActions actions = m_dragState
- ? m_dragState->drag->supportedActions()
- : (Qt::DropAction::CopyAction | Qt::DropAction::MoveAction
- | Qt::DropAction::LinkAction);
-
- auto dropResponse = std::make_shared<QPlatformDropQtResponse>(true, Qt::DropAction::CopyAction);
- QMimeData *data = event->dataTransfer.toMimeDataWithFile();
- *dropResponse = QWindowSystemInterface::handleDrop(event->targetWindow, data,
- pointInTargetWindowCoords.toPoint(), actions,
- event->mouseButton, event->modifiers);
-
- if (dropResponse->isAccepted()) {
- event->acceptDrop();
- event->dataTransfer.setDropAction(dropResponse->acceptedAction());
-
- m_dragState->dropAction = dropResponse->acceptedAction();
- }
+ ? m_dragState->drag->supportedActions()
+ : (Qt::DropAction::CopyAction | Qt::DropAction::MoveAction
+ | Qt::DropAction::LinkAction);
+ Qt::MouseButton mouseButton = event->mouseButton;
+ QFlags<Qt::KeyboardModifier> modifiers = event->modifiers;
+
+ const auto pointerCallback = std::function([&, wasmWindow, pointInTargetWindowCoords,
+ actions, mouseButton, modifiers](QMimeData &data) {
+ if (data.formats().count() == 0)
+ return;
+ auto dropResponse = std::make_shared<QPlatformDropQtResponse>(true, Qt::DropAction::CopyAction);
+
+ *dropResponse = QWindowSystemInterface::handleDrop(wasmWindow->window(), &data,
+ pointInTargetWindowCoords.toPoint(), actions,
+ mouseButton, modifiers);
+
+ if (dropResponse->isAccepted()) {
+// event->acceptDrop(); // boom
+// event->dataTransfer.setDropAction(dropResponse->acceptedAction());
+
+ m_dragState->dropAction = dropResponse->acceptedAction();
+ }
+ });
+
+ event->dataTransfer.toMimeDataWithFile(pointerCallback);
}
void QWasmDrag::onNativeDragFinished(DragEvent *event)