diff options
author | Kevin Keating <kevin.keating@schrodinger.com> | 2023-10-24 11:48:25 -0400 |
---|---|---|
committer | Lorn Potter <lorn.potter@gmail.com> | 2024-02-08 23:55:51 +0000 |
commit | 38c62c58514d574f44caf799e5568a2e9eebffeb (patch) | |
tree | bc01103c30868a9fa5e88a76879764ec6e70ed1a /src/plugins/platforms | |
parent | 1d6bb23f6285252f7fa6cac87003cbe0f33f51af (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.5 6.6 6.7
Change-Id: Idd9aa4d458a36452fd5b49f72cc595756fc50923
Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
Diffstat (limited to 'src/plugins/platforms')
-rw-r--r-- | src/plugins/platforms/wasm/qwasmcursor.cpp | 27 |
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 |