OpenCoverage

qcursor.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/gui/kernel/qcursor.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2016 The Qt Company Ltd.-
4** Contact: https://www.qt.io/licensing/-
5**-
6** This file is part of the QtGui module of the Qt Toolkit.-
7**-
8** $QT_BEGIN_LICENSE:LGPL$-
9** Commercial License Usage-
10** Licensees holding valid commercial Qt licenses may use this file in-
11** accordance with the commercial license agreement provided with the-
12** Software or, alternatively, in accordance with the terms contained in-
13** a written agreement between you and The Qt Company. For licensing terms-
14** and conditions see https://www.qt.io/terms-conditions. For further-
15** information use the contact form at https://www.qt.io/contact-us.-
16**-
17** GNU Lesser General Public License Usage-
18** Alternatively, this file may be used under the terms of the GNU Lesser-
19** General Public License version 3 as published by the Free Software-
20** Foundation and appearing in the file LICENSE.LGPL3 included in the-
21** packaging of this file. Please review the following information to-
22** ensure the GNU Lesser General Public License version 3 requirements-
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.-
24**-
25** GNU General Public License Usage-
26** Alternatively, this file may be used under the terms of the GNU-
27** General Public License version 2.0 or (at your option) the GNU General-
28** Public license version 3 or any later version approved by the KDE Free-
29** Qt Foundation. The licenses are as published by the Free Software-
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3-
31** included in the packaging of this file. Please review the following-
32** information to ensure the GNU General Public License requirements will-
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and-
34** https://www.gnu.org/licenses/gpl-3.0.html.-
35**-
36** $QT_END_LICENSE$-
37**-
38****************************************************************************/-
39-
40#include "qcursor.h"-
41-
42#include <qcoreapplication.h>-
43#include <qbitmap.h>-
44#include <qimage.h>-
45#include <qdatastream.h>-
46#include <qvariant.h>-
47#include <private/qcursor_p.h>-
48#include <qdebug.h>-
49-
50#include <qpa/qplatformcursor.h>-
51#include <private/qguiapplication_p.h>-
52#include <private/qhighdpiscaling_p.h>-
53-
54QT_BEGIN_NAMESPACE-
55-
56/*!-
57 \class QCursor-
58-
59 \brief The QCursor class provides a mouse cursor with an arbitrary-
60 shape.-
61-
62 \inmodule QtGui-
63 \ingroup appearance-
64 \ingroup shared-
65-
66-
67 This class is mainly used to create mouse cursors that are-
68 associated with particular widgets and to get and set the position-
69 of the mouse cursor.-
70-
71 Qt has a number of standard cursor shapes, but you can also make-
72 custom cursor shapes based on a QBitmap, a mask and a hotspot.-
73-
74 To associate a cursor with a widget, use QWidget::setCursor(). To-
75 associate a cursor with all widgets (normally for a short period-
76 of time), use QGuiApplication::setOverrideCursor().-
77-
78 To set a cursor shape use QCursor::setShape() or use the QCursor-
79 constructor which takes the shape as argument, or you can use one-
80 of the predefined cursors defined in the \l Qt::CursorShape enum.-
81-
82 If you want to create a cursor with your own bitmap, either use-
83 the QCursor constructor which takes a bitmap and a mask or the-
84 constructor which takes a pixmap as arguments.-
85-
86 To set or get the position of the mouse cursor use the static-
87 methods QCursor::pos() and QCursor::setPos().-
88-
89 \b{Note:} It is possible to create a QCursor before-
90 QGuiApplication, but it is not useful except as a place-holder for a-
91 real QCursor created after QGuiApplication. Attempting to use a-
92 QCursor that was created before QGuiApplication will result in a-
93 crash.-
94-
95 \section1 A Note for X11 Users-
96-
97 On X11, Qt supports the \l{Xcursor}{Xcursor}-
98 library, which allows for full color icon themes. The table below-
99 shows the cursor name used for each Qt::CursorShape value. If a-
100 cursor cannot be found using the name shown below, a standard X11-
101 cursor will be used instead. Note: X11 does not provide-
102 appropriate cursors for all possible Qt::CursorShape values. It-
103 is possible that some cursors will be taken from the Xcursor-
104 theme, while others will use an internal bitmap cursor.-
105-
106 \table-
107 \header \li Shape \li Qt::CursorShape Value \li Cursor Name-
108 \li Shape \li Qt::CursorShape Value \li Cursor Name-
109 \row \li \inlineimage cursor-arrow.png-
110 \li Qt::ArrowCursor \li \c left_ptr-
111 \li \inlineimage cursor-sizev.png-
112 \li Qt::SizeVerCursor \li \c size_ver-
113 \row \li \inlineimage cursor-uparrow.png-
114 \li Qt::UpArrowCursor \li \c up_arrow-
115 \li \inlineimage cursor-sizeh.png-
116 \li Qt::SizeHorCursor \li \c size_hor-
117 \row \li \inlineimage cursor-cross.png-
118 \li Qt::CrossCursor \li \c cross-
119 \li \inlineimage cursor-sizeb.png-
120 \li Qt::SizeBDiagCursor \li \c size_bdiag-
121 \row \li \inlineimage cursor-ibeam.png-
122 \li Qt::IBeamCursor \li \c ibeam-
123 \li \inlineimage cursor-sizef.png-
124 \li Qt::SizeFDiagCursor \li \c size_fdiag-
125 \row \li \inlineimage cursor-wait.png-
126 \li Qt::WaitCursor \li \c wait-
127 \li \inlineimage cursor-sizeall.png-
128 \li Qt::SizeAllCursor \li \c size_all-
129 \row \li \inlineimage cursor-busy.png-
130 \li Qt::BusyCursor \li \c left_ptr_watch-
131 \li \inlineimage cursor-vsplit.png-
132 \li Qt::SplitVCursor \li \c split_v-
133 \row \li \inlineimage cursor-forbidden.png-
134 \li Qt::ForbiddenCursor \li \c forbidden-
135 \li \inlineimage cursor-hsplit.png-
136 \li Qt::SplitHCursor \li \c split_h-
137 \row \li \inlineimage cursor-hand.png-
138 \li Qt::PointingHandCursor \li \c pointing_hand-
139 \li \inlineimage cursor-openhand.png-
140 \li Qt::OpenHandCursor \li \c openhand-
141 \row \li \inlineimage cursor-whatsthis.png-
142 \li Qt::WhatsThisCursor \li \c whats_this-
143 \li \inlineimage cursor-closedhand.png-
144 \li Qt::ClosedHandCursor \li \c closedhand-
145 \row \li-
146 \li Qt::DragMoveCursor \li \c dnd-move or \c move-
147 \li-
148 \li Qt::DragCopyCursor \li \c dnd-copy or \c copy-
149 \row \li-
150 \li Qt::DragLinkCursor \li \c dnd-link or \c link-
151 \endtable-
152-
153 \sa QWidget, {fowler}{GUI Design Handbook: Cursors}-
154*/-
155-
156/*!-
157 \fn QCursor::QCursor(QCursor &&other)-
158 \since 5.5-
159-
160 Move-constructs a cursor from \a other. After being moved from,-
161 the only valid operations on \a other are destruction and-
162 (move and copy) assignment. The effects of calling any other-
163 member function on a moved-from instance are undefined.-
164*/-
165-
166/*!-
167 \fn QCursor &QCursor::operator=(QCursor &&other)-
168-
169 Move-assigns \a other to this QCursor instance.-
170-
171 \since 5.2-
172*/-
173-
174/*!-
175 \fn QPoint QCursor::pos(const QScreen *screen)-
176-
177 Returns the position of the cursor (hot spot) of the \a screen-
178 in global screen coordinates.-
179-
180 You can call QWidget::mapFromGlobal() to translate it to widget-
181 coordinates.-
182-
183 \sa setPos(), QWidget::mapFromGlobal(), QWidget::mapToGlobal()-
184*/-
185QPoint QCursor::pos(const QScreen *screen)-
186{-
187 if (screen) {
screenDescription
TRUEnever evaluated
FALSEnever evaluated
0
188 if (const QPlatformCursor *cursor = screen->handle()->cursor()) {
const QPlatfor...le()->cursor()Description
TRUEnever evaluated
FALSEnever evaluated
0
189 const QPlatformScreen *ps = screen->handle();-
190 QPoint nativePos = cursor->pos();-
191 ps = ps->screenForPosition(nativePos);-
192 return QHighDpi::fromNativePixels(nativePos, ps->screen());
never executed: return QHighDpi::fromNativePixels(nativePos, ps->screen());
0
193 }-
194 }
never executed: end of block
0
195 return QGuiApplicationPrivate::lastCursorPosition.toPoint();
never executed: return QGuiApplicationPrivate::lastCursorPosition.toPoint();
0
196}-
197-
198/*!-
199 \fn QPoint QCursor::pos()-
200-
201 Returns the position of the cursor (hot spot) of-
202 the primary screen in global screen coordinates.-
203-
204 You can call QWidget::mapFromGlobal() to translate it to widget-
205 coordinates.-
206-
207 \note The position is queried from the windowing system. If mouse events are generated-
208 via other means (e.g., via QWindowSystemInterface in a unit test), those fake mouse-
209 moves will not be reflected in the returned value.-
210-
211 \note On platforms where there is no windowing system or cursors are not available, the returned-
212 position is based on the mouse move events generated via QWindowSystemInterface.-
213-
214 \sa setPos(), QWidget::mapFromGlobal(), QWidget::mapToGlobal(), QGuiApplication::primaryScreen()-
215*/-
216QPoint QCursor::pos()-
217{-
218 return QCursor::pos(QGuiApplication::primaryScreen());
never executed: return QCursor::pos(QGuiApplication::primaryScreen());
0
219}-
220-
221/*!-
222 \fn void QCursor::setPos(QScreen *screen, int x, int y)-
223-
224 Moves the cursor (hot spot) of the \a screen to the global-
225 screen position (\a x, \a y).-
226-
227 You can call QWidget::mapToGlobal() to translate widget-
228 coordinates to global screen coordinates.-
229-
230 \note Calling this function results in changing the cursor position through the windowing-
231 system. The windowing system will typically respond by sending mouse events to the application's-
232 window. This means that the usage of this function should be avoided in unit tests and-
233 everywhere where fake mouse events are being injected via QWindowSystemInterface because the-
234 windowing system's mouse state (with regards to buttons for example) may not match the state in-
235 the application-generated events.-
236-
237 \note On platforms where there is no windowing system or cursors are not available, this-
238 function may do nothing.-
239-
240 \sa pos(), QWidget::mapFromGlobal(), QWidget::mapToGlobal()-
241*/-
242void QCursor::setPos(QScreen *screen, int x, int y)-
243{-
244 if (screen) {
screenDescription
TRUEnever evaluated
FALSEnever evaluated
0
245 if (QPlatformCursor *cursor = screen->handle()->cursor()) {
QPlatformCurso...le()->cursor()Description
TRUEnever evaluated
FALSEnever evaluated
0
246 const QPoint devicePos = QHighDpi::toNativePixels(QPoint(x, y), screen);-
247 // Need to check, since some X servers generate null mouse move-
248 // events, causing looping in applications which call setPos() on-
249 // every mouse move event.-
250 if (devicePos != cursor->pos())
devicePos != cursor->pos()Description
TRUEnever evaluated
FALSEnever evaluated
0
251 cursor->setPos(devicePos);
never executed: cursor->setPos(devicePos);
0
252 }
never executed: end of block
0
253 }
never executed: end of block
0
254}
never executed: end of block
0
255-
256/*!-
257 \fn void QCursor::setPos(int x, int y)-
258-
259 Moves the cursor (hot spot) of the primary screen-
260 to the global screen position (\a x, \a y).-
261-
262 You can call QWidget::mapToGlobal() to translate widget-
263 coordinates to global screen coordinates.-
264-
265 \sa pos(), QWidget::mapFromGlobal(), QWidget::mapToGlobal(), QGuiApplication::primaryScreen()-
266*/-
267void QCursor::setPos(int x, int y)-
268{-
269 QCursor::setPos(QGuiApplication::primaryScreen(), x, y);-
270}
never executed: end of block
0
271-
272#ifndef QT_NO_CURSOR-
273-
274/*!-
275 \fn void QCursor::setPos (const QPoint &p)-
276-
277 \overload-
278-
279 Moves the cursor (hot spot) to the global screen position at point-
280 \a p.-
281*/-
282-
283/*!-
284 \fn void QCursor::setPos (QScreen *screen,const QPoint &p)-
285-
286 \overload-
287-
288 Moves the cursor (hot spot) to the global screen position of the-
289 \a screen at point \a p.-
290*/-
291-
292/*****************************************************************************-
293 QCursor stream functions-
294 *****************************************************************************/-
295-
296#ifndef QT_NO_DATASTREAM-
297-
298-
299/*!-
300 \fn QDataStream &operator<<(QDataStream &stream, const QCursor &cursor)-
301 \relates QCursor-
302-
303 Writes the \a cursor to the \a stream.-
304-
305 \sa {Serializing Qt Data Types}-
306*/-
307-
308QDataStream &operator<<(QDataStream &s, const QCursor &c)-
309{-
310 s << (qint16)c.shape(); // write shape id to stream-
311 if (c.shape() == Qt::BitmapCursor) { // bitmap cursor
c.shape() == Qt::BitmapCursorDescription
TRUEnever evaluated
FALSEnever evaluated
0
312 bool isPixmap = false;-
313 if (s.version() >= 7) {
s.version() >= 7Description
TRUEnever evaluated
FALSEnever evaluated
0
314 isPixmap = !c.pixmap().isNull();-
315 s << isPixmap;-
316 }
never executed: end of block
0
317 if (isPixmap)
isPixmapDescription
TRUEnever evaluated
FALSEnever evaluated
0
318 s << c.pixmap();
never executed: s << c.pixmap();
0
319 else-
320 s << *c.bitmap() << *c.mask();
never executed: s << *c.bitmap() << *c.mask();
0
321 s << c.hotSpot();-
322 }
never executed: end of block
0
323 return s;
never executed: return s;
0
324}-
325-
326/*!-
327 \fn QDataStream &operator>>(QDataStream &stream, QCursor &cursor)-
328 \relates QCursor-
329-
330 Reads the \a cursor from the \a stream.-
331-
332 \sa {Serializing Qt Data Types}-
333*/-
334-
335QDataStream &operator>>(QDataStream &s, QCursor &c)-
336{-
337 qint16 shape;-
338 s >> shape; // read shape id from stream-
339 if (shape == Qt::BitmapCursor) { // read bitmap cursor
shape == Qt::BitmapCursorDescription
TRUEnever evaluated
FALSEnever evaluated
0
340 bool isPixmap = false;-
341 if (s.version() >= 7)
s.version() >= 7Description
TRUEnever evaluated
FALSEnever evaluated
0
342 s >> isPixmap;
never executed: s >> isPixmap;
0
343 if (isPixmap) {
isPixmapDescription
TRUEnever evaluated
FALSEnever evaluated
0
344 QPixmap pm;-
345 QPoint hot;-
346 s >> pm >> hot;-
347 c = QCursor(pm, hot.x(), hot.y());-
348 } else {
never executed: end of block
0
349 QBitmap bm, bmm;-
350 QPoint hot;-
351 s >> bm >> bmm >> hot;-
352 c = QCursor(bm, bmm, hot.x(), hot.y());-
353 }
never executed: end of block
0
354 } else {-
355 c.setShape((Qt::CursorShape)shape); // create cursor with shape-
356 }
never executed: end of block
0
357 return s;
never executed: return s;
0
358}-
359#endif // QT_NO_DATASTREAM-
360-
361-
362/*!-
363 Constructs a custom pixmap cursor.-
364-
365 \a pixmap is the image. It is usual to give it a mask (set using-
366 QPixmap::setMask()). \a hotX and \a hotY define the cursor's hot-
367 spot.-
368-
369 If \a hotX is negative, it is set to the \c{pixmap().width()/2}.-
370 If \a hotY is negative, it is set to the \c{pixmap().height()/2}.-
371-
372 Valid cursor sizes depend on the display hardware (or the-
373 underlying window system). We recommend using 32 x 32 cursors,-
374 because this size is supported on all platforms. Some platforms-
375 also support 16 x 16, 48 x 48, and 64 x 64 cursors.-
376-
377 \sa QPixmap::QPixmap(), QPixmap::setMask()-
378*/-
379-
380QCursor::QCursor(const QPixmap &pixmap, int hotX, int hotY)-
381 : d(0)-
382{-
383 QImage img = pixmap.toImage().convertToFormat(QImage::Format_Indexed8, Qt::ThresholdDither|Qt::AvoidDither);-
384 QBitmap bm = QBitmap::fromImage(img, Qt::ThresholdDither|Qt::AvoidDither);-
385 QBitmap bmm = pixmap.mask();-
386 if (!bmm.isNull()) {
!bmm.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
0
387 QBitmap nullBm;-
388 bm.setMask(nullBm);-
389 }
never executed: end of block
0
390 else if (!pixmap.mask().isNull()) {
!pixmap.mask().isNull()Description
TRUEnever evaluated
FALSEnever evaluated
0
391 QImage mimg = pixmap.mask().toImage().convertToFormat(QImage::Format_Indexed8, Qt::ThresholdDither|Qt::AvoidDither);-
392 bmm = QBitmap::fromImage(mimg, Qt::ThresholdDither|Qt::AvoidDither);-
393 }
never executed: end of block
0
394 else {-
395 bmm = QBitmap(bm.size());-
396 bmm.fill(Qt::color1);-
397 }
never executed: end of block
0
398-
399 d = QCursorData::setBitmap(bm, bmm, hotX, hotY, pixmap.devicePixelRatio());-
400 d->pixmap = pixmap;-
401}
never executed: end of block
0
402-
403-
404-
405/*!-
406 Constructs a custom bitmap cursor.-
407-
408 \a bitmap and-
409 \a mask make up the bitmap.-
410 \a hotX and-
411 \a hotY define the cursor's hot spot.-
412-
413 If \a hotX is negative, it is set to the \c{bitmap().width()/2}.-
414 If \a hotY is negative, it is set to the \c{bitmap().height()/2}.-
415-
416 The cursor \a bitmap (B) and \a mask (M) bits are combined like this:-
417 \list-
418 \li B=1 and M=1 gives black.-
419 \li B=0 and M=1 gives white.-
420 \li B=0 and M=0 gives transparent.-
421 \li B=1 and M=0 gives an XOR'd result under Windows, undefined-
422 results on all other platforms.-
423 \endlist-
424-
425 Use the global Qt color Qt::color0 to draw 0-pixels and Qt::color1 to-
426 draw 1-pixels in the bitmaps.-
427-
428 Valid cursor sizes depend on the display hardware (or the-
429 underlying window system). We recommend using 32 x 32 cursors,-
430 because this size is supported on all platforms. Some platforms-
431 also support 16 x 16, 48 x 48, and 64 x 64 cursors.-
432-
433 \sa QBitmap::QBitmap(), QBitmap::setMask()-
434*/-
435-
436QCursor::QCursor(const QBitmap &bitmap, const QBitmap &mask, int hotX, int hotY)-
437 : d(0)-
438{-
439 d = QCursorData::setBitmap(bitmap, mask, hotX, hotY, 1.0);-
440}
never executed: end of block
0
441-
442/*!-
443 Constructs a cursor with the default arrow shape.-
444*/-
445QCursor::QCursor()-
446{-
447 if (!QCursorData::initialized) {
!QCursorData::initializedDescription
TRUEnever evaluated
FALSEnever evaluated
0
448 if (QCoreApplication::startingUp()) {
QCoreApplication::startingUp()Description
TRUEnever evaluated
FALSEnever evaluated
0
449 d = 0;-
450 return;
never executed: return;
0
451 }-
452 QCursorData::initialize();-
453 }
never executed: end of block
0
454 QCursorData *c = qt_cursorTable[0];-
455 c->ref.ref();-
456 d = c;-
457}
never executed: end of block
0
458-
459/*!-
460 Constructs a cursor with the specified \a shape.-
461-
462 See \l Qt::CursorShape for a list of shapes.-
463-
464 \sa setShape()-
465*/-
466QCursor::QCursor(Qt::CursorShape shape)-
467 : d(0)-
468{-
469 if (!QCursorData::initialized)
!QCursorData::initializedDescription
TRUEnever evaluated
FALSEnever evaluated
0
470 QCursorData::initialize();
never executed: QCursorData::initialize();
0
471 setShape(shape);-
472}
never executed: end of block
0
473-
474-
475/*!-
476 Returns the cursor shape identifier. The return value is one of-
477 the \l Qt::CursorShape enum values (cast to an int).-
478-
479 \sa setShape()-
480*/-
481Qt::CursorShape QCursor::shape() const-
482{-
483 if (!QCursorData::initialized)
!QCursorData::initializedDescription
TRUEnever evaluated
FALSEnever evaluated
0
484 QCursorData::initialize();
never executed: QCursorData::initialize();
0
485 return d->cshape;
never executed: return d->cshape;
0
486}-
487-
488/*!-
489 Sets the cursor to the shape identified by \a shape.-
490-
491 See \l Qt::CursorShape for the list of cursor shapes.-
492-
493 \sa shape()-
494*/-
495void QCursor::setShape(Qt::CursorShape shape)-
496{-
497 if (!QCursorData::initialized)
!QCursorData::initializedDescription
TRUEnever evaluated
FALSEnever evaluated
0
498 QCursorData::initialize();
never executed: QCursorData::initialize();
0
499 QCursorData *c = uint(shape) <= Qt::LastCursor ? qt_cursorTable[shape] : 0;
uint(shape) <= Qt::LastCursorDescription
TRUEnever evaluated
FALSEnever evaluated
0
500 if (!c)
!cDescription
TRUEnever evaluated
FALSEnever evaluated
0
501 c = qt_cursorTable[0];
never executed: c = qt_cursorTable[0];
0
502 c->ref.ref();-
503 if (!d) {
!dDescription
TRUEnever evaluated
FALSEnever evaluated
0
504 d = c;-
505 } else {
never executed: end of block
0
506 if (!d->ref.deref())
!d->ref.deref()Description
TRUEnever evaluated
FALSEnever evaluated
0
507 delete d;
never executed: delete d;
0
508 d = c;-
509 }
never executed: end of block
0
510}-
511-
512/*!-
513 Returns the cursor bitmap, or 0 if it is one of the standard-
514 cursors.-
515*/-
516const QBitmap *QCursor::bitmap() const-
517{-
518 if (!QCursorData::initialized)
!QCursorData::initializedDescription
TRUEnever evaluated
FALSEnever evaluated
0
519 QCursorData::initialize();
never executed: QCursorData::initialize();
0
520 return d->bm;
never executed: return d->bm;
0
521}-
522-
523/*!-
524 Returns the cursor bitmap mask, or 0 if it is one of the standard-
525 cursors.-
526*/-
527-
528const QBitmap *QCursor::mask() const-
529{-
530 if (!QCursorData::initialized)
!QCursorData::initializedDescription
TRUEnever evaluated
FALSEnever evaluated
0
531 QCursorData::initialize();
never executed: QCursorData::initialize();
0
532 return d->bmm;
never executed: return d->bmm;
0
533}-
534-
535/*!-
536 Returns the cursor pixmap. This is only valid if the cursor is a-
537 pixmap cursor.-
538*/-
539-
540QPixmap QCursor::pixmap() const-
541{-
542 if (!QCursorData::initialized)
!QCursorData::initializedDescription
TRUEnever evaluated
FALSEnever evaluated
0
543 QCursorData::initialize();
never executed: QCursorData::initialize();
0
544 return d->pixmap;
never executed: return d->pixmap;
0
545}-
546-
547/*!-
548 Returns the cursor hot spot, or (0, 0) if it is one of the-
549 standard cursors.-
550*/-
551-
552QPoint QCursor::hotSpot() const-
553{-
554 if (!QCursorData::initialized)
!QCursorData::initializedDescription
TRUEnever evaluated
FALSEnever evaluated
0
555 QCursorData::initialize();
never executed: QCursorData::initialize();
0
556 return QPoint(d->hx, d->hy);
never executed: return QPoint(d->hx, d->hy);
0
557}-
558-
559/*!-
560 Constructs a copy of the cursor \a c.-
561*/-
562-
563QCursor::QCursor(const QCursor &c)-
564{-
565 if (!QCursorData::initialized)
!QCursorData::initializedDescription
TRUEnever evaluated
FALSEnever evaluated
0
566 QCursorData::initialize();
never executed: QCursorData::initialize();
0
567 d = c.d;-
568 d->ref.ref();-
569}
never executed: end of block
0
570-
571/*!-
572 Destroys the cursor.-
573*/-
574-
575QCursor::~QCursor()-
576{-
577 if (d && !d->ref.deref())
dDescription
TRUEnever evaluated
FALSEnever evaluated
!d->ref.deref()Description
TRUEnever evaluated
FALSEnever evaluated
0
578 delete d;
never executed: delete d;
0
579}
never executed: end of block
0
580-
581-
582/*!-
583 Assigns \a c to this cursor and returns a reference to this-
584 cursor.-
585*/-
586-
587QCursor &QCursor::operator=(const QCursor &c)-
588{-
589 if (!QCursorData::initialized)
!QCursorData::initializedDescription
TRUEnever evaluated
FALSEnever evaluated
0
590 QCursorData::initialize();
never executed: QCursorData::initialize();
0
591 if (c.d)
c.dDescription
TRUEnever evaluated
FALSEnever evaluated
0
592 c.d->ref.ref();
never executed: c.d->ref.ref();
0
593 if (d && !d->ref.deref())
dDescription
TRUEnever evaluated
FALSEnever evaluated
!d->ref.deref()Description
TRUEnever evaluated
FALSEnever evaluated
0
594 delete d;
never executed: delete d;
0
595 d = c.d;-
596 return *this;
never executed: return *this;
0
597}-
598-
599/*!-
600 Returns the cursor as a QVariant.-
601*/-
602QCursor::operator QVariant() const-
603{-
604 return QVariant(QVariant::Cursor, this);
never executed: return QVariant(QVariant::Cursor, this);
0
605}-
606-
607#ifndef QT_NO_DEBUG_STREAM-
608QDebug operator<<(QDebug dbg, const QCursor &c)-
609{-
610 QDebugStateSaver saver(dbg);-
611 dbg.nospace() << "QCursor(Qt::CursorShape(" << c.shape() << "))";-
612 return dbg;
never executed: return dbg;
0
613}-
614#endif-
615-
616/*****************************************************************************-
617 Internal QCursorData class-
618 *****************************************************************************/-
619-
620QCursorData *qt_cursorTable[Qt::LastCursor + 1];-
621bool QCursorData::initialized = false;-
622-
623QCursorData::QCursorData(Qt::CursorShape s)-
624 : ref(1), cshape(s), bm(0), bmm(0), hx(0), hy(0)-
625{-
626}
never executed: end of block
0
627-
628QCursorData::~QCursorData()-
629{-
630 delete bm;-
631 delete bmm;-
632}
never executed: end of block
0
633-
634/*! \internal */-
635void QCursorData::cleanup()-
636{-
637 if(!QCursorData::initialized)
!QCursorData::initializedDescription
TRUEnever evaluated
FALSEnever evaluated
0
638 return;
never executed: return;
0
639-
640 for (int shape = 0; shape <= Qt::LastCursor; ++shape) {
shape <= Qt::LastCursorDescription
TRUEnever evaluated
FALSEnever evaluated
0
641 // In case someone has a static QCursor defined with this shape-
642 if (!qt_cursorTable[shape]->ref.deref())
!qt_cursorTabl...]->ref.deref()Description
TRUEnever evaluated
FALSEnever evaluated
0
643 delete qt_cursorTable[shape];
never executed: delete qt_cursorTable[shape];
0
644 qt_cursorTable[shape] = 0;-
645 }
never executed: end of block
0
646 QCursorData::initialized = false;-
647}
never executed: end of block
0
648-
649/*! \internal */-
650void QCursorData::initialize()-
651{-
652 if (QCursorData::initialized)
QCursorData::initializedDescription
TRUEnever evaluated
FALSEnever evaluated
0
653 return;
never executed: return;
0
654 for (int shape = 0; shape <= Qt::LastCursor; ++shape)
shape <= Qt::LastCursorDescription
TRUEnever evaluated
FALSEnever evaluated
0
655 qt_cursorTable[shape] = new QCursorData((Qt::CursorShape)shape);
never executed: qt_cursorTable[shape] = new QCursorData((Qt::CursorShape)shape);
0
656 QCursorData::initialized = true;-
657}
never executed: end of block
0
658-
659QCursorData *QCursorData::setBitmap(const QBitmap &bitmap, const QBitmap &mask, int hotX, int hotY, qreal devicePixelRatio)-
660{-
661 if (!QCursorData::initialized)
!QCursorData::initializedDescription
TRUEnever evaluated
FALSEnever evaluated
0
662 QCursorData::initialize();
never executed: QCursorData::initialize();
0
663 if (bitmap.depth() != 1 || mask.depth() != 1 || bitmap.size() != mask.size()) {
bitmap.depth() != 1Description
TRUEnever evaluated
FALSEnever evaluated
mask.depth() != 1Description
TRUEnever evaluated
FALSEnever evaluated
bitmap.size() != mask.size()Description
TRUEnever evaluated
FALSEnever evaluated
0
664 qWarning("QCursor: Cannot create bitmap cursor; invalid bitmap(s)");-
665 QCursorData *c = qt_cursorTable[0];-
666 c->ref.ref();-
667 return c;
never executed: return c;
0
668 }-
669 QCursorData *d = new QCursorData;-
670 d->bm = new QBitmap(bitmap);-
671 d->bmm = new QBitmap(mask);-
672 d->cshape = Qt::BitmapCursor;-
673 d->hx = hotX >= 0 ? hotX : bitmap.width() / 2 / devicePixelRatio;
hotX >= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
674 d->hy = hotY >= 0 ? hotY : bitmap.height() / 2 / devicePixelRatio;
hotY >= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
675-
676 return d;
never executed: return d;
0
677}-
678-
679void QCursorData::update()-
680{-
681}-
682-
683QT_END_NAMESPACE-
684#endif // QT_NO_CURSOR-
685-
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9