diff options
Diffstat (limited to 'src/plugins/platforms/wasm/qwasmwindow.cpp')
-rw-r--r-- | src/plugins/platforms/wasm/qwasmwindow.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/plugins/platforms/wasm/qwasmwindow.cpp b/src/plugins/platforms/wasm/qwasmwindow.cpp index a8f577cfea..3735c7dff4 100644 --- a/src/plugins/platforms/wasm/qwasmwindow.cpp +++ b/src/plugins/platforms/wasm/qwasmwindow.cpp @@ -84,6 +84,12 @@ QWasmWindow::QWasmWindow(QWindow *w, QWasmCompositor *compositor, QWasmBackingSt std::make_unique<qstdweb::EventCallback>(m_qtWindow, "pointerenter", callback); m_pointerLeaveCallback = std::make_unique<qstdweb::EventCallback>(m_qtWindow, "pointerleave", callback); + + m_dropCallback = std::make_unique<qstdweb::EventCallback>( + m_qtWindow, "drop", [this](emscripten::val event) { + if (processDrop(*DragEvent::fromWeb(event))) + event.call<void>("preventDefault"); + }); } QWasmWindow::~QWasmWindow() @@ -418,6 +424,30 @@ bool QWasmWindow::processPointer(const PointerEvent &event) return false; } +bool QWasmWindow::processDrop(const DragEvent &event) +{ + m_dropDataReadCancellationFlag = qstdweb::readDataTransfer( + event.dataTransfer, + [](QByteArray fileContent) { + QImage image; + image.loadFromData(fileContent, nullptr); + return image; + }, + [this, event](std::unique_ptr<QMimeData> data) { + QWindowSystemInterface::handleDrag(window(), data.get(), event.pointInPage, + event.dropAction, event.mouseButton, + event.modifiers); + + QWindowSystemInterface::handleDrop(window(), data.get(), event.pointInPage, + event.dropAction, event.mouseButton, + event.modifiers); + + QWindowSystemInterface::handleDrag(window(), nullptr, QPoint(), Qt::IgnoreAction, + {}, {}); + }); + return true; +} + QRect QWasmWindow::normalGeometry() const { return m_normalGeometry; |