Qt 6.x
The Qt SDK
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
4#include "qwasmcursor.h"
5#include "qwasmscreen.h"
6#include "qwasmwindow.h"
7
8#include <QtCore/qdebug.h>
9#include <QtGui/qwindow.h>
10
11#include <emscripten/emscripten.h>
12#include <emscripten/bind.h>
13
15using namespace emscripten;
16
17namespace {
18QByteArray cursorShapeToCss(Qt::CursorShape shape)
19{
20 QByteArray cursorName;
21
22 switch (shape) {
23 case Qt::ArrowCursor:
24 return "default";
26 return "n-resize";
27 case Qt::CrossCursor:
28 return "crosshair";
29 case Qt::WaitCursor:
30 return "wait";
31 case Qt::IBeamCursor:
32 return "text";
34 return "ns-resize";
36 return "ew-resize";
38 return "nesw-resize";
40 return "nwse-resize";
42 return "move";
43 case Qt::BlankCursor:
44 return "none";
46 return "row-resize";
48 return "col-resize";
50 return "pointer";
52 return "not-allowed";
54 return "help";
55 case Qt::BusyCursor:
56 return "progress";
58 return "grab";
60 return "grabbing";
62 return "copy";
64 return "default";
66 return "alias";
67 default:
68 static_assert(Qt::BitmapCursor == 24 && Qt::CustomCursor == 25,
69 "New cursor type added, handle it");
70 qWarning() << "QWasmCursor: " << shape << " unsupported";
71 return "default";
72 }
73}
74} // namespace
75
77{
78 if (!window)
79 return;
80 if (QWasmWindow *wasmWindow = static_cast<QWasmWindow *>(window->handle()))
81 wasmWindow->setWindowCursor(windowCursor ? cursorShapeToCss(windowCursor->shape()) : "default");
82}
83
\inmodule QtCore
Definition qbytearray.h:57
The QCursor class provides a mouse cursor with an arbitrary shape.
Definition qcursor.h:45
Qt::CursorShape shape() const
Returns the cursor shape identifier.
Definition qcursor.cpp:499
void changeCursor(QCursor *windowCursor, QWindow *window) override
This method is called by Qt whenever the cursor graphic should be changed.
\inmodule QtGui
Definition qwindow.h:63
Combined button and popup list for selecting options.
CursorShape
@ BlankCursor
@ CrossCursor
@ DragCopyCursor
@ BitmapCursor
@ PointingHandCursor
@ SizeHorCursor
@ SizeAllCursor
@ CustomCursor
@ WaitCursor
@ SizeVerCursor
@ DragLinkCursor
@ OpenHandCursor
@ SizeFDiagCursor
@ WhatsThisCursor
@ ArrowCursor
@ SplitVCursor
@ UpArrowCursor
@ ClosedHandCursor
@ DragMoveCursor
@ IBeamCursor
@ SizeBDiagCursor
@ ForbiddenCursor
@ BusyCursor
@ SplitHCursor
#define qWarning
Definition qlogging.h:162
aWidget window() -> setWindowTitle("New Window Title")
[2]