Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qwasmcursor.cpp
Go to the documentation of this file.
1// Copyright (C) 2018 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
5#include "qwasmcursor.h"
6#include "qwasmscreen.h"
7#include "qwasmwindow.h"
8
9#include <QtCore/qbuffer.h>
10#include <QtCore/qdebug.h>
11#include <QtCore/qstring.h>
12#include <QtGui/qwindow.h>
13
14#include <emscripten/emscripten.h>
15#include <emscripten/bind.h>
16
18using namespace emscripten;
19
20namespace {
21QByteArray cursorToCss(const QCursor *cursor)
22{
23 auto shape = cursor->shape();
24 switch (shape) {
25 case Qt::ArrowCursor:
26 return "default";
27 case Qt::UpArrowCursor:
28 return "n-resize";
29 case Qt::CrossCursor:
30 return "crosshair";
31 case Qt::WaitCursor:
32 return "wait";
33 case Qt::IBeamCursor:
34 return "text";
35 case Qt::SizeVerCursor:
36 return "ns-resize";
37 case Qt::SizeHorCursor:
38 return "ew-resize";
39 case Qt::SizeBDiagCursor:
40 return "nesw-resize";
41 case Qt::SizeFDiagCursor:
42 return "nwse-resize";
43 case Qt::SizeAllCursor:
44 return "move";
45 case Qt::BlankCursor:
46 return "none";
47 case Qt::SplitVCursor:
48 return "row-resize";
49 case Qt::SplitHCursor:
50 return "col-resize";
51 case Qt::PointingHandCursor:
52 return "pointer";
53 case Qt::ForbiddenCursor:
54 return "not-allowed";
55 case Qt::WhatsThisCursor:
56 return "help";
57 case Qt::BusyCursor:
58 return "progress";
59 case Qt::OpenHandCursor:
60 return "grab";
61 case Qt::ClosedHandCursor:
62 return "grabbing";
63 case Qt::DragCopyCursor:
64 return "copy";
65 case Qt::DragMoveCursor:
66 return "default";
67 case Qt::DragLinkCursor:
68 return "alias";
69 case Qt::BitmapCursor: {
70 auto pixmap = cursor->pixmap();
71 QByteArray cursorAsPng;
72 QBuffer buffer(&cursorAsPng);
73 buffer.open(QBuffer::WriteOnly);
74 pixmap.save(&buffer, "PNG");
75 buffer.close();
76 auto cursorAsBase64 = cursorAsPng.toBase64();
77 auto hotSpot = cursor->hotSpot();
78 auto encodedCursor =
79 QString("url(data:image/png;base64,%1) %2 %3, auto")
80 .arg(QString::fromUtf8(cursorAsBase64),
81 QString::number(hotSpot.x()),
82 QString::number(hotSpot.y()));
83 return encodedCursor.toUtf8();
84 }
85 default:
86 static_assert(Qt::CustomCursor == 25,
87 "New cursor type added, handle it");
88 qWarning() << "QWasmCursor: " << shape << " unsupported";
89 return "default";
90 }
91}
92} // namespace
93
94void QWasmCursor::changeCursor(QCursor *windowCursor, QWindow *window)
95{
96 if (!window)
97 return;
98 if (QWasmWindow *wasmWindow = static_cast<QWasmWindow *>(window->handle()))
99 wasmWindow->setWindowCursor(windowCursor ? cursorToCss(windowCursor) : "default");
100}
101
102QT_END_NAMESPACE
friend class QWasmCompositor
Combined button and popup list for selecting options.