summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Keating <kevin.keating@schrodinger.com>2023-10-24 11:48:25 -0400
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2024-02-09 09:32:20 +0000
commit737dbc8c7855a918d094081d4d0cab517472926a (patch)
treeffdda33bddb1583c8819e75310b94c8d661594be
parent07059d4d1d167b21fb83b27f85af3668f6587146 (diff)
WASM builds now handle bitmap and pixmap cursors
[ChangeLog][QtGui][Platform Specific Changes][wasm] Previously, bitmap and pixmap cursors were nonfunctional in wasm builds and would trigger warnings. These cursors now work as expected. Fixes: QTBUG-116796 Pick-to: 6.6 6.5 Change-Id: Idd9aa4d458a36452fd5b49f72cc595756fc50923 Reviewed-by: Lorn Potter <lorn.potter@gmail.com> (cherry picked from commit 38c62c58514d574f44caf799e5568a2e9eebffeb) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/plugins/platforms/wasm/qwasmcursor.cpp27
1 files changed, 22 insertions, 5 deletions
diff --git a/src/plugins/platforms/wasm/qwasmcursor.cpp b/src/plugins/platforms/wasm/qwasmcursor.cpp
index b341a31b0c..c258befa77 100644
--- a/src/plugins/platforms/wasm/qwasmcursor.cpp
+++ b/src/plugins/platforms/wasm/qwasmcursor.cpp
@@ -5,7 +5,9 @@
#include "qwasmscreen.h"
#include "qwasmwindow.h"
+#include <QtCore/qbuffer.h>
#include <QtCore/qdebug.h>
+#include <QtCore/qstring.h>
#include <QtGui/qwindow.h>
#include <emscripten/emscripten.h>
@@ -15,10 +17,9 @@ QT_BEGIN_NAMESPACE
using namespace emscripten;
namespace {
-QByteArray cursorShapeToCss(Qt::CursorShape shape)
+QByteArray cursorToCss(const QCursor *cursor)
{
- QByteArray cursorName;
-
+ auto shape = cursor->shape();
switch (shape) {
case Qt::ArrowCursor:
return "default";
@@ -64,8 +65,24 @@ QByteArray cursorShapeToCss(Qt::CursorShape shape)
return "default";
case Qt::DragLinkCursor:
return "alias";
+ case Qt::BitmapCursor: {
+ auto pixmap = cursor->pixmap();
+ QByteArray cursorAsPng;
+ QBuffer buffer(&cursorAsPng);
+ buffer.open(QBuffer::WriteOnly);
+ pixmap.save(&buffer, "PNG");
+ buffer.close();
+ auto cursorAsBase64 = cursorAsPng.toBase64();
+ auto hotSpot = cursor->hotSpot();
+ auto encodedCursor =
+ QString("url(data:image/png;base64,%1) %2 %3, auto")
+ .arg(QString::fromUtf8(cursorAsBase64),
+ QString::number(hotSpot.x()),
+ QString::number(hotSpot.y()));
+ return encodedCursor.toUtf8();
+ }
default:
- static_assert(Qt::BitmapCursor == 24 && Qt::CustomCursor == 25,
+ static_assert(Qt::CustomCursor == 25,
"New cursor type added, handle it");
qWarning() << "QWasmCursor: " << shape << " unsupported";
return "default";
@@ -78,7 +95,7 @@ void QWasmCursor::changeCursor(QCursor *windowCursor, QWindow *window)
if (!window)
return;
if (QWasmWindow *wasmWindow = static_cast<QWasmWindow *>(window->handle()))
- wasmWindow->setWindowCursor(windowCursor ? cursorShapeToCss(windowCursor->shape()) : "default");
+ wasmWindow->setWindowCursor(windowCursor ? cursorToCss(windowCursor) : "default");
}
QT_END_NAMESPACE