1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3#include "qplatformcursor.h"
4
5#include <QPainter>
6#include <QBitmap>
7#include <QGuiApplication>
8#include <QScreen>
9#include <qpa/qplatformscreen.h>
10#include <private/qguiapplication_p.h>
11
12#include <QDebug>
13
14QT_BEGIN_NAMESPACE
15
16/*!
17 \class QPlatformCursor
18 \since 5.0
19 \internal
20 \preliminary
21 \ingroup qpa
22
23 \brief The QPlatformCursor class provides information about
24 pointer device events (movement, buttons), and requests to change
25 the currently displayed cursor.
26
27 Note that QPlatformCursor does not include any graphics for
28 display. An application that sets a QCursor may provide its own
29 graphics.
30
31 \sa QPlatformCursorImage
32*/
33
34/*!
35 \fn virtual void QPlatformCursor::pointerEvent(const QMouseEvent & event)
36
37 This method is called by Qt whenever a QMouseEvent is generated by the
38 underlying pointer input. \a event is a reference to the QMouseEvent in
39 question. A default do-nothing implementation is provided.
40*/
41
42/*!
43 \fn virtual void QPlatformCursor::changeCursor(QCursor * windowCursor, QWindow * window)
44
45 \brief This method is called by Qt whenever the cursor graphic should be changed.
46
47 Implementation of this method is mandatory for a subclass of QPlatformCursor.
48
49 \a windowCursor is a pointer to the QCursor that should be displayed.
50
51 To unset the cursor of \a window, \nullptr is passed. This means \a window does not have
52 a cursor set and the cursor of a the first parent window which has a cursor explicitly
53 set or the system default cursor should take effect.
54
55 \a window is a pointer to the window currently displayed at QCursor::pos(). Note
56 that this may be \nullptr if the current position is not occupied by a displayed widget.
57
58 \sa QCursor::pos()
59*/
60
61/*!
62 \enum QPlatformCursor::Capability
63 \since 5.10
64
65 \value OverrideCursor Indicates that the platform implements
66 QPlatformCursor::setOverrideCursor() and
67 QPlatformCursor::clearOverrideCursor().
68*/
69
70QPlatformCursor::Capabilities QPlatformCursor::m_capabilities = { };
71
72/*!
73 \fn QPlatformCursor::QPlatformCursor()
74
75 Constructs a QPlatformCursor.
76*/
77QPlatformCursor::QPlatformCursor()
78{
79}
80
81QPoint QPlatformCursor::pos() const
82{
83 // As a fallback return the last mouse position seen by QGuiApplication.
84 return QGuiApplicationPrivate::lastCursorPosition.toPoint();
85}
86
87void QPlatformCursor::setPos(const QPoint &pos)
88{
89 static bool firstCall = true;
90 if (firstCall) {
91 firstCall = false;
92 qWarning(msg: "This plugin does not support QCursor::setPos()"
93 "; emulating movement within the application.");
94 }
95 QWindowSystemInterface::handleMouseEvent(window: nullptr, local: pos, global: pos, state: Qt::NoButton, button: Qt::NoButton, type: QEvent::MouseMove);
96}
97
98/*!
99 Returns the size of the cursor, in native pixels.
100*/
101QSize QPlatformCursor::size() const
102{
103 return QSize(16, 16);
104}
105
106// End of display and pointer event handling code
107// Beginning of built-in cursor graphics
108// from src/gui/embedded/QGraphicsSystemCursorImage_qws.cpp
109
110/*!
111 \class QPlatformCursorImage
112 \since 5.0
113 \internal
114 \preliminary
115 \ingroup qpa
116
117 \brief The QPlatformCursorImage class provides a set of graphics
118 intended to be used as cursors.
119
120 \sa QPlatformCursor
121*/
122
123static QPlatformCursorImage *systemCursorTable[Qt::LastCursor+1];
124static bool systemCursorTableInit = false;
125
126// 16 x 16
127static const uchar cur_arrow_bits[] = {
128 0x07, 0x00, 0x39, 0x00, 0xc1, 0x01, 0x02, 0x0e, 0x02, 0x10, 0x02, 0x08,
129 0x04, 0x04, 0x04, 0x02, 0x04, 0x04, 0x88, 0x08, 0x48, 0x11, 0x28, 0x22,
130 0x10, 0x44, 0x00, 0x28, 0x00, 0x10, 0x00, 0x00 };
131static const uchar mcur_arrow_bits[] = {
132 0x07, 0x00, 0x3f, 0x00, 0xff, 0x01, 0xfe, 0x0f, 0xfe, 0x1f, 0xfe, 0x0f,
133 0xfc, 0x07, 0xfc, 0x03, 0xfc, 0x07, 0xf8, 0x0f, 0x78, 0x1f, 0x38, 0x3e,
134 0x10, 0x7c, 0x00, 0x38, 0x00, 0x10, 0x00, 0x00 };
135
136static const unsigned char cur_up_arrow_bits[] = {
137 0x80, 0x00, 0x40, 0x01, 0x40, 0x01, 0x20, 0x02, 0x20, 0x02, 0x10, 0x04,
138 0x10, 0x04, 0x08, 0x08, 0x78, 0x0f, 0x40, 0x01, 0x40, 0x01, 0x40, 0x01,
139 0x40, 0x01, 0x40, 0x01, 0x40, 0x01, 0xc0, 0x01};
140static const unsigned char mcur_up_arrow_bits[] = {
141 0x80, 0x00, 0xc0, 0x01, 0xc0, 0x01, 0xe0, 0x03, 0xe0, 0x03, 0xf0, 0x07,
142 0xf0, 0x07, 0xf8, 0x0f, 0xf8, 0x0f, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01,
143 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01};
144
145static const unsigned char cur_cross_bits[] = {
146 0xc0, 0x01, 0x40, 0x01, 0x40, 0x01, 0x40, 0x01, 0x40, 0x01, 0x40, 0x01,
147 0x7f, 0x7f, 0x01, 0x40, 0x7f, 0x7f, 0x40, 0x01, 0x40, 0x01, 0x40, 0x01,
148 0x40, 0x01, 0x40, 0x01, 0xc0, 0x01, 0x00, 0x00};
149static const unsigned char mcur_cross_bits[] = {
150 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01,
151 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01,
152 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0x00, 0x00};
153
154static const uchar cur_ibeam_bits[] = {
155 0x00, 0x00, 0xe0, 0x03, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00,
156 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00,
157 0x80, 0x00, 0xe0, 0x03, 0x00, 0x00, 0x00, 0x00 };
158static const uchar mcur_ibeam_bits[] = {
159 0xf0, 0x07, 0xf0, 0x07, 0xf0, 0x07, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01,
160 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01,
161 0xf0, 0x07, 0xf0, 0x07, 0xf0, 0x07, 0x00, 0x00 };
162
163static const uchar cur_ver_bits[] = {
164 0x00, 0x00, 0x00, 0x00, 0x80, 0x01, 0xc0, 0x03, 0xe0, 0x07, 0xf0, 0x0f,
165 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0xf0, 0x0f,
166 0xe0, 0x07, 0xc0, 0x03, 0x80, 0x01, 0x00, 0x00 };
167static const uchar mcur_ver_bits[] = {
168 0x00, 0x00, 0x80, 0x03, 0xc0, 0x07, 0xe0, 0x0f, 0xf0, 0x1f, 0xf8, 0x3f,
169 0xfc, 0x7f, 0xc0, 0x07, 0xc0, 0x07, 0xc0, 0x07, 0xfc, 0x7f, 0xf8, 0x3f,
170 0xf0, 0x1f, 0xe0, 0x0f, 0xc0, 0x07, 0x80, 0x03 };
171
172static const uchar cur_hor_bits[] = {
173 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x08, 0x30, 0x18,
174 0x38, 0x38, 0xfc, 0x7f, 0xfc, 0x7f, 0x38, 0x38, 0x30, 0x18, 0x20, 0x08,
175 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
176static const uchar mcur_hor_bits[] = {
177 0x00, 0x00, 0x00, 0x00, 0x40, 0x04, 0x60, 0x0c, 0x70, 0x1c, 0x78, 0x3c,
178 0xfc, 0x7f, 0xfe, 0xff, 0xfe, 0xff, 0xfe, 0xff, 0xfc, 0x7f, 0x78, 0x3c,
179 0x70, 0x1c, 0x60, 0x0c, 0x40, 0x04, 0x00, 0x00 };
180static const uchar cur_bdiag_bits[] = {
181 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x00, 0x3e, 0x00, 0x3c, 0x00, 0x3e,
182 0x00, 0x37, 0x88, 0x23, 0xd8, 0x01, 0xf8, 0x00, 0x78, 0x00, 0xf8, 0x00,
183 0xf8, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
184static const uchar mcur_bdiag_bits[] = {
185 0x00, 0x00, 0xc0, 0x7f, 0x80, 0x7f, 0x00, 0x7f, 0x00, 0x7e, 0x04, 0x7f,
186 0x8c, 0x7f, 0xdc, 0x77, 0xfc, 0x63, 0xfc, 0x41, 0xfc, 0x00, 0xfc, 0x01,
187 0xfc, 0x03, 0xfc, 0x07, 0x00, 0x00, 0x00, 0x00 };
188static const uchar cur_fdiag_bits[] = {
189 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x01, 0xf8, 0x00, 0x78, 0x00,
190 0xf8, 0x00, 0xd8, 0x01, 0x88, 0x23, 0x00, 0x37, 0x00, 0x3e, 0x00, 0x3c,
191 0x00, 0x3e, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x00 };
192static const uchar mcur_fdiag_bits[] = {
193 0x00, 0x00, 0x00, 0x00, 0xfc, 0x07, 0xfc, 0x03, 0xfc, 0x01, 0xfc, 0x00,
194 0xfc, 0x41, 0xfc, 0x63, 0xdc, 0x77, 0x8c, 0x7f, 0x04, 0x7f, 0x00, 0x7e,
195 0x00, 0x7f, 0x80, 0x7f, 0xc0, 0x7f, 0x00, 0x00 };
196
197// 20 x 20
198static const uchar forbidden_bits[] = {
199 0x00,0x00,0x00,0x80,0x1f,0x00,0xe0,0x7f,0x00,0xf0,0xf0,0x00,0x38,0xc0,0x01,
200 0x7c,0x80,0x03,0xec,0x00,0x03,0xce,0x01,0x07,0x86,0x03,0x06,0x06,0x07,0x06,
201 0x06,0x0e,0x06,0x06,0x1c,0x06,0x0e,0x38,0x07,0x0c,0x70,0x03,0x1c,0xe0,0x03,
202 0x38,0xc0,0x01,0xf0,0xe0,0x00,0xe0,0x7f,0x00,0x80,0x1f,0x00,0x00,0x00,0x00 };
203
204static const uchar forbiddenm_bits[] = {
205 0x80,0x1f,0x00,0xe0,0x7f,0x00,0xf0,0xff,0x00,0xf8,0xff,0x01,0xfc,0xf0,0x03,
206 0xfe,0xc0,0x07,0xfe,0x81,0x07,0xff,0x83,0x0f,0xcf,0x07,0x0f,0x8f,0x0f,0x0f,
207 0x0f,0x1f,0x0f,0x0f,0x3e,0x0f,0x1f,0xfc,0x0f,0x1e,0xf8,0x07,0x3e,0xf0,0x07,
208 0xfc,0xe0,0x03,0xf8,0xff,0x01,0xf0,0xff,0x00,0xe0,0x7f,0x00,0x80,0x1f,0x00};
209
210// 32 x 32
211static const uchar wait_data_bits[] = {
212 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
213 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x7f, 0x00,
214 0x00, 0x04, 0x40, 0x00, 0x00, 0xfc, 0x7f, 0x00, 0x00, 0x08, 0x20, 0x00,
215 0x00, 0x08, 0x20, 0x00, 0x00, 0x08, 0x20, 0x00, 0x00, 0x08, 0x20, 0x00,
216 0x00, 0x50, 0x15, 0x00, 0x00, 0xa0, 0x0a, 0x00, 0x00, 0x40, 0x05, 0x00,
217 0x00, 0x80, 0x02, 0x00, 0x00, 0x40, 0x04, 0x00, 0x00, 0x20, 0x08, 0x00,
218 0x00, 0x10, 0x10, 0x00, 0x00, 0x08, 0x21, 0x00, 0x00, 0x88, 0x22, 0x00,
219 0x00, 0x48, 0x25, 0x00, 0x00, 0xa8, 0x2a, 0x00, 0x00, 0xfc, 0x7f, 0x00,
220 0x00, 0x04, 0x40, 0x00, 0x00, 0xfc, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00,
221 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
222 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
223static const uchar wait_mask_bits[] = {
224 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
225 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x7f, 0x00,
226 0x00, 0xfc, 0x7f, 0x00, 0x00, 0xfc, 0x7f, 0x00, 0x00, 0xf8, 0x3f, 0x00,
227 0x00, 0xf8, 0x3f, 0x00, 0x00, 0xf8, 0x3f, 0x00, 0x00, 0xf8, 0x3f, 0x00,
228 0x00, 0xf0, 0x1f, 0x00, 0x00, 0xe0, 0x0f, 0x00, 0x00, 0xc0, 0x07, 0x00,
229 0x00, 0x80, 0x03, 0x00, 0x00, 0xc0, 0x07, 0x00, 0x00, 0xe0, 0x0f, 0x00,
230 0x00, 0xf0, 0x1f, 0x00, 0x00, 0xf8, 0x3f, 0x00, 0x00, 0xf8, 0x3f, 0x00,
231 0x00, 0xf8, 0x3f, 0x00, 0x00, 0xf8, 0x3f, 0x00, 0x00, 0xfc, 0x7f, 0x00,
232 0x00, 0xfc, 0x7f, 0x00, 0x00, 0xfc, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00,
233 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
234 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
235
236static const uchar hsplit_bits[] = {
237 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
238 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
239 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x02, 0x00, 0x00, 0x40, 0x02, 0x00,
240 0x00, 0x40, 0x02, 0x00, 0x00, 0x40, 0x02, 0x00, 0x00, 0x40, 0x02, 0x00,
241 0x00, 0x41, 0x82, 0x00, 0x80, 0x41, 0x82, 0x01, 0xc0, 0x7f, 0xfe, 0x03,
242 0x80, 0x41, 0x82, 0x01, 0x00, 0x41, 0x82, 0x00, 0x00, 0x40, 0x02, 0x00,
243 0x00, 0x40, 0x02, 0x00, 0x00, 0x40, 0x02, 0x00, 0x00, 0x40, 0x02, 0x00,
244 0x00, 0x40, 0x02, 0x00, 0x00, 0x40, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
245 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
246 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
247 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
248static const uchar hsplitm_bits[] = {
249 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
250 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
251 0x00, 0xe0, 0x07, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0xe0, 0x07, 0x00,
252 0x00, 0xe0, 0x07, 0x00, 0x00, 0xe2, 0x47, 0x00, 0x00, 0xe3, 0xc7, 0x00,
253 0x80, 0xe3, 0xc7, 0x01, 0xc0, 0xff, 0xff, 0x03, 0xe0, 0xff, 0xff, 0x07,
254 0xc0, 0xff, 0xff, 0x03, 0x80, 0xe3, 0xc7, 0x01, 0x00, 0xe3, 0xc7, 0x00,
255 0x00, 0xe2, 0x47, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0xe0, 0x07, 0x00,
256 0x00, 0xe0, 0x07, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
257 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
258 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
259 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
260static const uchar vsplit_bits[] = {
261 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
262 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
263 0x00, 0x80, 0x00, 0x00, 0x00, 0xc0, 0x01, 0x00, 0x00, 0xe0, 0x03, 0x00,
264 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00,
265 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0xff, 0x7f, 0x00,
266 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x7f, 0x00,
267 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00,
268 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0xe0, 0x03, 0x00,
269 0x00, 0xc0, 0x01, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
270 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
271 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
272static const uchar vsplitm_bits[] = {
273 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
274 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00,
275 0x00, 0xc0, 0x01, 0x00, 0x00, 0xe0, 0x03, 0x00, 0x00, 0xf0, 0x07, 0x00,
276 0x00, 0xf8, 0x0f, 0x00, 0x00, 0xc0, 0x01, 0x00, 0x00, 0xc0, 0x01, 0x00,
277 0x00, 0xc0, 0x01, 0x00, 0x80, 0xff, 0xff, 0x00, 0x80, 0xff, 0xff, 0x00,
278 0x80, 0xff, 0xff, 0x00, 0x80, 0xff, 0xff, 0x00, 0x80, 0xff, 0xff, 0x00,
279 0x80, 0xff, 0xff, 0x00, 0x00, 0xc0, 0x01, 0x00, 0x00, 0xc0, 0x01, 0x00,
280 0x00, 0xc0, 0x01, 0x00, 0x00, 0xf8, 0x0f, 0x00, 0x00, 0xf0, 0x07, 0x00,
281 0x00, 0xe0, 0x03, 0x00, 0x00, 0xc0, 0x01, 0x00, 0x00, 0x80, 0x00, 0x00,
282 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
283 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
284static const uchar phand_bits[] = {
285 0x00, 0x00, 0x00, 0x00, 0xfe, 0x01, 0x00, 0x00, 0x01, 0x02, 0x00, 0x00,
286 0x7e, 0x04, 0x00, 0x00, 0x08, 0x08, 0x00, 0x00, 0x70, 0x08, 0x00, 0x00,
287 0x08, 0x08, 0x00, 0x00, 0x70, 0x14, 0x00, 0x00, 0x08, 0x22, 0x00, 0x00,
288 0x30, 0x41, 0x00, 0x00, 0xc0, 0x20, 0x00, 0x00, 0x40, 0x12, 0x00, 0x00,
289 0x80, 0x08, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
290 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
291 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
292 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
293 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
294 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
295 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
296static const uchar phandm_bits[] = {
297 0xfe, 0x01, 0x00, 0x00, 0xff, 0x03, 0x00, 0x00, 0xff, 0x07, 0x00, 0x00,
298 0xff, 0x0f, 0x00, 0x00, 0xfe, 0x1f, 0x00, 0x00, 0xf8, 0x1f, 0x00, 0x00,
299 0xfc, 0x1f, 0x00, 0x00, 0xf8, 0x3f, 0x00, 0x00, 0xfc, 0x7f, 0x00, 0x00,
300 0xf8, 0xff, 0x00, 0x00, 0xf0, 0x7f, 0x00, 0x00, 0xe0, 0x3f, 0x00, 0x00,
301 0xc0, 0x1f, 0x00, 0x00, 0x80, 0x0f, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00,
302 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
303 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
304 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
305 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
306 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
307 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
308
309static const uchar size_all_data_bits[] = {
310 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
311 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
312 0x00, 0x80, 0x00, 0x00, 0x00, 0xc0, 0x01, 0x00, 0x00, 0xe0, 0x03, 0x00,
313 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00,
314 0x00, 0x80, 0x00, 0x00, 0x00, 0x81, 0x40, 0x00, 0x80, 0x81, 0xc0, 0x00,
315 0xc0, 0xff, 0xff, 0x01, 0x80, 0x81, 0xc0, 0x00, 0x00, 0x81, 0x40, 0x00,
316 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00,
317 0x00, 0x80, 0x00, 0x00, 0x00, 0xe0, 0x03, 0x00, 0x00, 0xc0, 0x01, 0x00,
318 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
319 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
320 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
321static const uchar size_all_mask_bits[] = {
322 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
323 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00,
324 0x00, 0xc0, 0x01, 0x00, 0x00, 0xe0, 0x03, 0x00, 0x00, 0xf0, 0x07, 0x00,
325 0x00, 0xf8, 0x0f, 0x00, 0x00, 0xc0, 0x01, 0x00, 0x00, 0xc2, 0x21, 0x00,
326 0x00, 0xc3, 0x61, 0x00, 0x80, 0xc3, 0xe1, 0x00, 0xc0, 0xff, 0xff, 0x01,
327 0xe0, 0xff, 0xff, 0x03, 0xc0, 0xff, 0xff, 0x01, 0x80, 0xc3, 0xe1, 0x00,
328 0x00, 0xc3, 0x61, 0x00, 0x00, 0xc2, 0x21, 0x00, 0x00, 0xc0, 0x01, 0x00,
329 0x00, 0xf8, 0x0f, 0x00, 0x00, 0xf0, 0x07, 0x00, 0x00, 0xe0, 0x03, 0x00,
330 0x00, 0xc0, 0x01, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
331 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
332 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
333
334static const uchar whatsthis_bits[] = {
335 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x05, 0xf0, 0x07, 0x00,
336 0x09, 0x18, 0x0e, 0x00, 0x11, 0x1c, 0x0e, 0x00, 0x21, 0x1c, 0x0e, 0x00,
337 0x41, 0x1c, 0x0e, 0x00, 0x81, 0x1c, 0x0e, 0x00, 0x01, 0x01, 0x07, 0x00,
338 0x01, 0x82, 0x03, 0x00, 0xc1, 0xc7, 0x01, 0x00, 0x49, 0xc0, 0x01, 0x00,
339 0x95, 0xc0, 0x01, 0x00, 0x93, 0xc0, 0x01, 0x00, 0x21, 0x01, 0x00, 0x00,
340 0x20, 0xc1, 0x01, 0x00, 0x40, 0xc2, 0x01, 0x00, 0x40, 0x02, 0x00, 0x00,
341 0x80, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
342 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
343 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
344 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
345 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, };
346static const uchar whatsthism_bits[] = {
347 0x01, 0x00, 0x00, 0x00, 0x03, 0xf0, 0x07, 0x00, 0x07, 0xf8, 0x0f, 0x00,
348 0x0f, 0xfc, 0x1f, 0x00, 0x1f, 0x3e, 0x1f, 0x00, 0x3f, 0x3e, 0x1f, 0x00,
349 0x7f, 0x3e, 0x1f, 0x00, 0xff, 0x3e, 0x1f, 0x00, 0xff, 0x9d, 0x0f, 0x00,
350 0xff, 0xc3, 0x07, 0x00, 0xff, 0xe7, 0x03, 0x00, 0x7f, 0xe0, 0x03, 0x00,
351 0xf7, 0xe0, 0x03, 0x00, 0xf3, 0xe0, 0x03, 0x00, 0xe1, 0xe1, 0x03, 0x00,
352 0xe0, 0xe1, 0x03, 0x00, 0xc0, 0xe3, 0x03, 0x00, 0xc0, 0xe3, 0x03, 0x00,
353 0x80, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
354 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
355 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
356 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
357 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, };
358
359static const uchar busy_bits[] = {
360 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00,
361 0x09, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x21, 0x00, 0x00, 0x00,
362 0x41, 0xe0, 0xff, 0x00, 0x81, 0x20, 0x80, 0x00, 0x01, 0xe1, 0xff, 0x00,
363 0x01, 0x42, 0x40, 0x00, 0xc1, 0x47, 0x40, 0x00, 0x49, 0x40, 0x55, 0x00,
364 0x95, 0x80, 0x2a, 0x00, 0x93, 0x00, 0x15, 0x00, 0x21, 0x01, 0x0a, 0x00,
365 0x20, 0x01, 0x11, 0x00, 0x40, 0x82, 0x20, 0x00, 0x40, 0x42, 0x44, 0x00,
366 0x80, 0x41, 0x4a, 0x00, 0x00, 0x40, 0x55, 0x00, 0x00, 0xe0, 0xff, 0x00,
367 0x00, 0x20, 0x80, 0x00, 0x00, 0xe0, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00,
368 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
369 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
370 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
371static const uchar busym_bits[] = {
372 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00,
373 0x0f, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x3f, 0x00, 0x00, 0x00,
374 0x7f, 0xe0, 0xff, 0x00, 0xff, 0xe0, 0xff, 0x00, 0xff, 0xe1, 0xff, 0x00,
375 0xff, 0xc3, 0x7f, 0x00, 0xff, 0xc7, 0x7f, 0x00, 0x7f, 0xc0, 0x7f, 0x00,
376 0xf7, 0x80, 0x3f, 0x00, 0xf3, 0x00, 0x1f, 0x00, 0xe1, 0x01, 0x0e, 0x00,
377 0xe0, 0x01, 0x1f, 0x00, 0xc0, 0x83, 0x3f, 0x00, 0xc0, 0xc3, 0x7f, 0x00,
378 0x80, 0xc1, 0x7f, 0x00, 0x00, 0xc0, 0x7f, 0x00, 0x00, 0xe0, 0xff, 0x00,
379 0x00, 0xe0, 0xff, 0x00, 0x00, 0xe0, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00,
380 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
381 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
382 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
383
384// 16 x 16
385static const uchar openhand_bits[] = {
386 0x80,0x01,0x58,0x0e,0x64,0x12,0x64,0x52,0x48,0xb2,0x48,0x92,
387 0x16,0x90,0x19,0x80,0x11,0x40,0x02,0x40,0x04,0x40,0x04,0x20,
388 0x08,0x20,0x10,0x10,0x20,0x10,0x00,0x00};
389static const uchar openhandm_bits[] = {
390 0x80,0x01,0xd8,0x0f,0xfc,0x1f,0xfc,0x5f,0xf8,0xff,0xf8,0xff,
391 0xfe,0xff,0xff,0xff,0xff,0x7f,0xfe,0x7f,0xfc,0x7f,0xfc,0x3f,
392 0xf8,0x3f,0xf0,0x1f,0xe0,0x1f,0x00,0x00};
393static const uchar closedhand_bits[] = {
394 0x00,0x00,0x00,0x00,0x00,0x00,0xb0,0x0d,0x48,0x32,0x08,0x50,
395 0x10,0x40,0x18,0x40,0x04,0x40,0x04,0x20,0x08,0x20,0x10,0x10,
396 0x20,0x10,0x20,0x10,0x00,0x00,0x00,0x00};
397static const uchar closedhandm_bits[] = {
398 0x00,0x00,0x00,0x00,0x00,0x00,0xb0,0x0d,0xf8,0x3f,0xf8,0x7f,
399 0xf0,0x7f,0xf8,0x7f,0xfc,0x7f,0xfc,0x3f,0xf8,0x3f,0xf0,0x1f,
400 0xe0,0x1f,0xe0,0x1f,0x00,0x00,0x00,0x00};
401
402void QPlatformCursorImage::createSystemCursor(int id)
403{
404 if (!systemCursorTableInit) {
405 for (int i = 0; i <= Qt::LastCursor; i++)
406 systemCursorTable[i] = nullptr;
407 systemCursorTableInit = true;
408 }
409 switch (id) {
410 // 16x16 cursors
411 case Qt::ArrowCursor:
412 systemCursorTable[Qt::ArrowCursor] =
413 new QPlatformCursorImage(cur_arrow_bits, mcur_arrow_bits, 16, 16, 0, 0);
414 break;
415
416 case Qt::UpArrowCursor:
417 systemCursorTable[Qt::UpArrowCursor] =
418 new QPlatformCursorImage(cur_up_arrow_bits, mcur_up_arrow_bits, 16, 16, 7, 0);
419 break;
420
421 case Qt::CrossCursor:
422 systemCursorTable[Qt::CrossCursor] =
423 new QPlatformCursorImage(cur_cross_bits, mcur_cross_bits, 16, 16, 7, 7);
424 break;
425
426 case Qt::IBeamCursor:
427 systemCursorTable[Qt::IBeamCursor] =
428 new QPlatformCursorImage(cur_ibeam_bits, mcur_ibeam_bits, 16, 16, 7, 7);
429 break;
430
431 case Qt::SizeVerCursor:
432 systemCursorTable[Qt::SizeVerCursor] =
433 new QPlatformCursorImage(cur_ver_bits, mcur_ver_bits, 16, 16, 7, 7);
434 break;
435
436 case Qt::SizeHorCursor:
437 systemCursorTable[Qt::SizeHorCursor] =
438 new QPlatformCursorImage(cur_hor_bits, mcur_hor_bits, 16, 16, 7, 7);
439 break;
440
441 case Qt::SizeBDiagCursor:
442 systemCursorTable[Qt::SizeBDiagCursor] =
443 new QPlatformCursorImage(cur_bdiag_bits, mcur_bdiag_bits, 16, 16, 7, 7);
444 break;
445
446 case Qt::SizeFDiagCursor:
447 systemCursorTable[Qt::SizeFDiagCursor] =
448 new QPlatformCursorImage(cur_fdiag_bits, mcur_fdiag_bits, 16, 16, 7, 7);
449 break;
450
451 case Qt::BlankCursor:
452 systemCursorTable[Qt::BlankCursor] =
453 new QPlatformCursorImage(nullptr, nullptr, 0, 0, 0, 0);
454 break;
455
456 // 20x20 cursors
457 case Qt::ForbiddenCursor:
458 systemCursorTable[Qt::ForbiddenCursor] =
459 new QPlatformCursorImage(forbidden_bits, forbiddenm_bits, 20, 20, 10, 10);
460 break;
461
462 // 32x32 cursors
463 case Qt::WaitCursor:
464 systemCursorTable[Qt::WaitCursor] =
465 new QPlatformCursorImage(wait_data_bits, wait_mask_bits, 32, 32, 15, 15);
466 break;
467
468 case Qt::SplitVCursor:
469 systemCursorTable[Qt::SplitVCursor] =
470 new QPlatformCursorImage(vsplit_bits, vsplitm_bits, 32, 32, 15, 15);
471 break;
472
473 case Qt::SplitHCursor:
474 systemCursorTable[Qt::SplitHCursor] =
475 new QPlatformCursorImage(hsplit_bits, hsplitm_bits, 32, 32, 15, 15);
476 break;
477
478 case Qt::SizeAllCursor:
479 systemCursorTable[Qt::SizeAllCursor] =
480 new QPlatformCursorImage(size_all_data_bits, size_all_mask_bits, 32, 32, 15, 15);
481 break;
482
483 case Qt::PointingHandCursor:
484 systemCursorTable[Qt::PointingHandCursor] =
485 new QPlatformCursorImage(phand_bits, phandm_bits, 32, 32, 0, 0);
486 break;
487
488 case Qt::WhatsThisCursor:
489 systemCursorTable[Qt::WhatsThisCursor] =
490 new QPlatformCursorImage(whatsthis_bits, whatsthism_bits, 32, 32, 0, 0);
491 break;
492 case Qt::BusyCursor:
493 systemCursorTable[Qt::BusyCursor] =
494 new QPlatformCursorImage(busy_bits, busym_bits, 32, 32, 0, 0);
495 break;
496
497 case Qt::OpenHandCursor:
498 systemCursorTable[Qt::OpenHandCursor] =
499 new QPlatformCursorImage(openhand_bits, openhandm_bits, 16, 16, 8, 8);
500 break;
501 case Qt::ClosedHandCursor:
502 systemCursorTable[Qt::ClosedHandCursor] =
503 new QPlatformCursorImage(closedhand_bits, closedhandm_bits, 16, 16, 8, 8);
504 break;
505 default:
506 qWarning(msg: "Unknown system cursor %d", id);
507 }
508}
509
510/*!
511 \fn void QPlatformCursorImage::set(Qt::CursorShape id)
512
513 \brief Calling this method sets the cursor image to the specified shape
514
515 \a id is one of the defined Qt::CursorShape values.
516
517 If id is invalid, Qt::BitmapCursor, or unknown by the implementation,
518 Qt::ArrowCursor is used instead.
519*/
520
521void QPlatformCursorImage::set(Qt::CursorShape id)
522{
523 QPlatformCursorImage *cursor = nullptr;
524 if (unsigned(id) <= unsigned(Qt::LastCursor)) {
525 if (!systemCursorTable[id])
526 createSystemCursor(id);
527 cursor = systemCursorTable[id];
528 }
529
530 if (cursor == nullptr) {
531 if (!systemCursorTable[Qt::ArrowCursor])
532 createSystemCursor(id: Qt::ArrowCursor);
533 cursor = systemCursorTable[Qt::ArrowCursor];
534 }
535 cursorImage = cursor->cursorImage;
536 hot = cursor->hot;
537}
538
539/*!
540 Sets the cursor image to the given \a image, with the hotspot at the
541 point specified by (\a hx, \a hy).
542*/
543
544void QPlatformCursorImage::set(const QImage &image, int hx, int hy)
545{
546 hot.setX(hx);
547 hot.setY(hy);
548 cursorImage = image;
549}
550
551/*!
552 \fn void QPlatformCursorImage::set(const uchar *data, const uchar *mask, int width, int height, int hx, int hy)
553
554 Sets the cursor image to the graphic represented by the combination of
555 \a data and \a mask, with dimensions given by \a width and \a height and a
556 hotspot at the point specified by (\a hx, \a hy).
557
558 The image data specified by \a data must be supplied in the format
559 described by QImage::Format_Indexed8.
560
561 The corresponding mask data specified by \a mask must be supplied in a
562 character array containing packed 1 bit per pixel format data, with any
563 padding bits at the end of the array. Bits of value 0 represent transparent
564 pixels in the image data.
565*/
566void QPlatformCursorImage::set(const uchar *data, const uchar *mask,
567 int width, int height, int hx, int hy)
568{
569 hot.setX(hx);
570 hot.setY(hy);
571
572 cursorImage = QImage(width,height, QImage::Format_Indexed8);
573
574 if (!width || !height || !data || !mask || cursorImage.isNull())
575 return;
576
577 cursorImage.setColorCount(3);
578 cursorImage.setColor(i: 0, c: 0xff000000);
579 cursorImage.setColor(i: 1, c: 0xffffffff);
580 cursorImage.setColor(i: 2, c: 0x00000000);
581
582 int bytesPerLine = (width + 7) / 8;
583 int p = 0;
584 int d, m;
585
586 int x = -1;
587
588 uchar *cursor_data = cursorImage.bits();
589 qsizetype bpl = cursorImage.bytesPerLine();
590 for (int i = 0; i < height; i++)
591 {
592 for (int j = 0; j < bytesPerLine; j++, data++, mask++)
593 {
594 for (int b = 0; b < 8 && j*8+b < width; b++)
595 {
596 d = *data & (1 << b);
597 m = *mask & (1 << b);
598 if (d && m) p = 0;
599 else if (!d && m) p = 1;
600 else p = 2;
601 cursor_data[j*8+b] = p;
602
603 // calc region
604 if (x < 0 && m)
605 x = j*8+b;
606 else if (x >= 0 && !m) {
607 x = -1;
608 }
609 }
610 }
611 if (x >= 0) {
612 x = -1;
613 }
614 cursor_data += bpl;
615 }
616
617}
618
619/*!
620 \fn QPlatformCursorImage::QPlatformCursorImage(const uchar *data, const uchar *mask, int width, int height, int hotX, int hotY)
621
622 Sets the cursor image to the graphic represented by the combination of
623 \a data and \a mask, with dimensions given by \a width and \a height and a
624 hotspot at the point specified by (\a hotX, \a hotY).
625
626 \sa set()
627*/
628
629/*!
630 \fn QImage *QPlatformCursorImage::image()
631
632 \brief Return the cursor graphic as a pointer to a QImage
633*/
634
635/*!
636 \fn QPoint QPlatformCursorImage::hotspot() const
637
638 \brief Return the cursor's hotspot
639*/
640
641#ifndef QT_NO_CURSOR
642/*!
643 Reimplement this function in subclass to set an override cursor
644 on the associated screen and return true to indicate success.
645
646 This function can be implemented on platforms where the cursor is a
647 property of the application or the screen rather than a property
648 of the window. On these platforms, the OverrideCursor capability
649 should be set.
650
651 \sa QGuiApplication::setOverrideCursor(), Capabilities
652
653 \since 5.10
654*/
655void QPlatformCursor::setOverrideCursor(const QCursor &)
656{
657}
658
659/*!
660 Reimplement this function in subclass to clear the override cursor.
661
662 \sa QGuiApplication::clearOverrideCursor(), Capabilities
663
664 \since 5.10
665*/
666void QPlatformCursor::clearOverrideCursor()
667{
668}
669#endif // QT_NO_CURSOR
670
671QT_END_NAMESPACE
672

source code of qtbase/src/gui/kernel/qplatformcursor.cpp