qcursor.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/gui/kernel/qcursor.cpp
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4-
5QPoint QCursor::pos(const QScreen *screen)-
6{-
7 if (screen
screenDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
8 if (const
const QPlatfor...le()->cursor()Description
TRUEnever evaluated
FALSEnever evaluated
QPlatformCursor *cursor = screen->handle()->cursor()
const QPlatfor...le()->cursor()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
9 const QPlatformScreen *ps = screen->handle();-
10 QPoint nativePos = cursor->pos();-
11 ps = ps->screenForPosition(nativePos);-
12 return
never executed: return QHighDpi::fromNativePixels(nativePos, ps->screen());
QHighDpi::fromNativePixels(nativePos, ps->screen());
never executed: return QHighDpi::fromNativePixels(nativePos, ps->screen());
0
13 }-
14 }
never executed: end of block
0
15 return
never executed: return QGuiApplicationPrivate::lastCursorPosition.toPoint();
QGuiApplicationPrivate::lastCursorPosition.toPoint();
never executed: return QGuiApplicationPrivate::lastCursorPosition.toPoint();
0
16}-
17QPoint QCursor::pos()-
18{-
19 return
never executed: return QCursor::pos(QGuiApplication::primaryScreen());
QCursor::pos(QGuiApplication::primaryScreen());
never executed: return QCursor::pos(QGuiApplication::primaryScreen());
0
20}-
21void QCursor::setPos(QScreen *screen, int x, int y)-
22{-
23 if (screen
screenDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
24 if (QPlatformCursor *cursor = screen->handle()->cursor()
QPlatformCurso...le()->cursor()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
25 const QPoint devicePos = QHighDpi::toNativePixels(QPoint(x, y), screen);-
26-
27-
28-
29 if (devicePos != cursor->pos()
devicePos != cursor->pos()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
30 cursor->setPos(devicePos);
never executed: cursor->setPos(devicePos);
0
31 }
never executed: end of block
0
32 }
never executed: end of block
0
33}
never executed: end of block
0
34void QCursor::setPos(int x, int y)-
35{-
36 QCursor::setPos(QGuiApplication::primaryScreen(), x, y);-
37}
never executed: end of block
0
38QDataStream &operator<<(QDataStream &s, const QCursor &c)-
39{-
40 s << (qint16)c.shape();-
41 if (c.shape() == Qt::BitmapCursor
c.shape() == Qt::BitmapCursorDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
42 bool isPixmap = false;-
43 if (s.version() >= 7
s.version() >= 7Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
44 isPixmap = !c.pixmap().isNull();-
45 s << isPixmap;-
46 }
never executed: end of block
0
47 if (isPixmap
isPixmapDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
48 s << c.pixmap();
never executed: s << c.pixmap();
0
49 else-
50 s << *c.bitmap() << *c.mask();
never executed: s << *c.bitmap() << *c.mask();
0
51 s << c.hotSpot();-
52 }
never executed: end of block
0
53 return
never executed: return s;
s;
never executed: return s;
0
54}-
55QDataStream &operator>>(QDataStream &s, QCursor &c)-
56{-
57 qint16 shape;-
58 s >> shape;-
59 if (shape == Qt::BitmapCursor
shape == Qt::BitmapCursorDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
60 bool isPixmap = false;-
61 if (s.version() >= 7
s.version() >= 7Description
TRUEnever evaluated
FALSEnever evaluated
)
0
62 s >> isPixmap;
never executed: s >> isPixmap;
0
63 if (isPixmap
isPixmapDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
64 QPixmap pm;-
65 QPoint hot;-
66 s >> pm >> hot;-
67 c = QCursor(pm, hot.x(), hot.y());-
68 }
never executed: end of block
else {
0
69 QBitmap bm, bmm;-
70 QPoint hot;-
71 s >> bm >> bmm >> hot;-
72 c = QCursor(bm, bmm, hot.x(), hot.y());-
73 }
never executed: end of block
0
74 } else {-
75 c.setShape((Qt::CursorShape)shape);-
76 }
never executed: end of block
0
77 return
never executed: return s;
s;
never executed: return s;
0
78}-
79QCursor::QCursor(const QPixmap &pixmap, int hotX, int hotY)-
80 : d(0)-
81{-
82 QImage img = pixmap.toImage().convertToFormat(QImage::Format_Indexed8, Qt::ThresholdDither|Qt::AvoidDither);-
83 QBitmap bm = QBitmap::fromImage(img, Qt::ThresholdDither|Qt::AvoidDither);-
84 QBitmap bmm = pixmap.mask();-
85 if (!bmm.isNull()
!bmm.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
86 QBitmap nullBm;-
87 bm.setMask(nullBm);-
88 }
never executed: end of block
0
89 else if (!pixmap.mask().isNull()
!pixmap.mask().isNull()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
90 QImage mimg = pixmap.mask().toImage().convertToFormat(QImage::Format_Indexed8, Qt::ThresholdDither|Qt::AvoidDither);-
91 bmm = QBitmap::fromImage(mimg, Qt::ThresholdDither|Qt::AvoidDither);-
92 }
never executed: end of block
0
93 else {-
94 bmm = QBitmap(bm.size());-
95 bmm.fill(Qt::color1);-
96 }
never executed: end of block
0
97-
98 d = QCursorData::setBitmap(bm, bmm, hotX, hotY, pixmap.devicePixelRatio());-
99 d->pixmap = pixmap;-
100}
never executed: end of block
0
101QCursor::QCursor(const QBitmap &bitmap, const QBitmap &mask, int hotX, int hotY)-
102 : d(0)-
103{-
104 d = QCursorData::setBitmap(bitmap, mask, hotX, hotY, 1.0);-
105}
never executed: end of block
0
106-
107-
108-
109-
110QCursor::QCursor()-
111{-
112 if (!QCursorData::initialized
!QCursorData::initializedDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
113 if (QCoreApplication::startingUp()
QCoreApplication::startingUp()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
114 d = 0;-
115 return;
never executed: return;
0
116 }-
117 QCursorData::initialize();-
118 }
never executed: end of block
0
119 QCursorData *c = qt_cursorTable[0];-
120 c->ref.ref();-
121 d = c;-
122}
never executed: end of block
0
123QCursor::QCursor(Qt::CursorShape shape)-
124 : d(0)-
125{-
126 if (!QCursorData::initialized
!QCursorData::initializedDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
127 QCursorData::initialize();
never executed: QCursorData::initialize();
0
128 setShape(shape);-
129}
never executed: end of block
0
130Qt::CursorShape QCursor::shape() const-
131{-
132 if (!QCursorData::initialized
!QCursorData::initializedDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
133 QCursorData::initialize();
never executed: QCursorData::initialize();
0
134 return
never executed: return d->cshape;
d->cshape;
never executed: return d->cshape;
0
135}-
136void QCursor::setShape(Qt::CursorShape shape)-
137{-
138 if (!QCursorData::initialized
!QCursorData::initializedDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
139 QCursorData::initialize();
never executed: QCursorData::initialize();
0
140 QCursorData *c = uint(shape) <= Qt::LastCursor
uint(shape) <= Qt::LastCursorDescription
TRUEnever evaluated
FALSEnever evaluated
? qt_cursorTable[shape] : 0;
0
141 if (!c
!cDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
142 c = qt_cursorTable[0];
never executed: c = qt_cursorTable[0];
0
143 c->ref.ref();-
144 if (!d
!dDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
145 d = c;-
146 }
never executed: end of block
else {
0
147 if (!d->ref.deref()
!d->ref.deref()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
148 delete d;
never executed: delete d;
0
149 d = c;-
150 }
never executed: end of block
0
151}-
152-
153-
154-
155-
156-
157const QBitmap *QCursor::bitmap() const-
158{-
159 if (!QCursorData::initialized
!QCursorData::initializedDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
160 QCursorData::initialize();
never executed: QCursorData::initialize();
0
161 return
never executed: return d->bm;
d->bm;
never executed: return d->bm;
0
162}-
163-
164-
165-
166-
167-
168-
169const QBitmap *QCursor::mask() const-
170{-
171 if (!QCursorData::initialized
!QCursorData::initializedDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
172 QCursorData::initialize();
never executed: QCursorData::initialize();
0
173 return
never executed: return d->bmm;
d->bmm;
never executed: return d->bmm;
0
174}-
175-
176-
177-
178-
179-
180-
181QPixmap QCursor::pixmap() const-
182{-
183 if (!QCursorData::initialized
!QCursorData::initializedDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
184 QCursorData::initialize();
never executed: QCursorData::initialize();
0
185 return
never executed: return d->pixmap;
d->pixmap;
never executed: return d->pixmap;
0
186}-
187-
188-
189-
190-
191-
192-
193QPoint QCursor::hotSpot() const-
194{-
195 if (!QCursorData::initialized
!QCursorData::initializedDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
196 QCursorData::initialize();
never executed: QCursorData::initialize();
0
197 return
never executed: return QPoint(d->hx, d->hy);
QPoint(d->hx, d->hy);
never executed: return QPoint(d->hx, d->hy);
0
198}-
199-
200-
201-
202-
203-
204QCursor::QCursor(const QCursor &c)-
205{-
206 if (!QCursorData::initialized
!QCursorData::initializedDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
207 QCursorData::initialize();
never executed: QCursorData::initialize();
0
208 d = c.d;-
209 d->ref.ref();-
210}
never executed: end of block
0
211-
212-
213-
214-
215-
216QCursor::~QCursor()-
217{-
218 if (d
dDescription
TRUEnever evaluated
FALSEnever evaluated
&& !d->ref.deref()
!d->ref.deref()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
219 delete d;
never executed: delete d;
0
220}
never executed: end of block
0
221-
222-
223-
224-
225-
226-
227-
228QCursor &QCursor::operator=(const QCursor &c)-
229{-
230 if (!QCursorData::initialized
!QCursorData::initializedDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
231 QCursorData::initialize();
never executed: QCursorData::initialize();
0
232 if (c.d
c.dDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
233 c.d->ref.ref();
never executed: c.d->ref.ref();
0
234 if (d
dDescription
TRUEnever evaluated
FALSEnever evaluated
&& !d->ref.deref()
!d->ref.deref()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
235 delete d;
never executed: delete d;
0
236 d = c.d;-
237 return
never executed: return *this;
*this;
never executed: return *this;
0
238}-
239-
240-
241-
242-
243QCursor::operator QVariant() const-
244{-
245 return
never executed: return QVariant(QVariant::Cursor, this);
QVariant(QVariant::Cursor, this);
never executed: return QVariant(QVariant::Cursor, this);
0
246}-
247-
248-
249QDebug operator<<(QDebug dbg, const QCursor &c)-
250{-
251 QDebugStateSaver saver(dbg);-
252 dbg.nospace() << "QCursor(Qt::CursorShape(" << c.shape() << "))";-
253 return
never executed: return dbg;
dbg;
never executed: return dbg;
0
254}-
255-
256-
257-
258-
259-
260-
261QCursorData *qt_cursorTable[Qt::LastCursor + 1];-
262bool QCursorData::initialized = false;-
263-
264QCursorData::QCursorData(Qt::CursorShape s)-
265 : ref(1), cshape(s), bm(0), bmm(0), hx(0), hy(0)-
266{-
267}
never executed: end of block
0
268-
269QCursorData::~QCursorData()-
270{-
271 delete bm;-
272 delete bmm;-
273}
never executed: end of block
0
274-
275-
276void QCursorData::cleanup()-
277{-
278 if(!QCursorData::initialized
!QCursorData::initializedDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
279 return;
never executed: return;
0
280-
281 for (int shape = 0; shape <= Qt::LastCursor
shape <= Qt::LastCursorDescription
TRUEnever evaluated
FALSEnever evaluated
; ++shape) {
0
282-
283 if (!qt_cursorTable[shape]->ref.deref()
!qt_cursorTabl...]->ref.deref()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
284 delete qt_cursorTable[shape];
never executed: delete qt_cursorTable[shape];
0
285 qt_cursorTable[shape] = 0;-
286 }
never executed: end of block
0
287 QCursorData::initialized = false;-
288}
never executed: end of block
0
289-
290-
291void QCursorData::initialize()-
292{-
293 if (QCursorData::initialized
QCursorData::initializedDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
294 return;
never executed: return;
0
295 for (int shape = 0; shape <= Qt::LastCursor
shape <= Qt::LastCursorDescription
TRUEnever evaluated
FALSEnever evaluated
; ++shape)
0
296 qt_cursorTable[shape] = new QCursorData((Qt::CursorShape)shape);
never executed: qt_cursorTable[shape] = new QCursorData((Qt::CursorShape)shape);
0
297 QCursorData::initialized = true;-
298}
never executed: end of block
0
299-
300QCursorData *QCursorData::setBitmap(const QBitmap &bitmap, const QBitmap &mask, int hotX, int hotY, qreal devicePixelRatio)-
301{-
302 if (!QCursorData::initialized
!QCursorData::initializedDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
303 QCursorData::initialize();
never executed: QCursorData::initialize();
0
304 if (bitmap.depth() != 1
bitmap.depth() != 1Description
TRUEnever evaluated
FALSEnever evaluated
|| mask.depth() != 1
mask.depth() != 1Description
TRUEnever evaluated
FALSEnever evaluated
|| bitmap.size() != mask.size()
bitmap.size() != mask.size()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
305 QMessageLogger(__FILE__, 664, __PRETTY_FUNCTION__).warning("QCursor: Cannot create bitmap cursor; invalid bitmap(s)");-
306 QCursorData *c = qt_cursorTable[0];-
307 c->ref.ref();-
308 return
never executed: return c;
c;
never executed: return c;
0
309 }-
310 QCursorData *d = new QCursorData;-
311 d->bm = new QBitmap(bitmap);-
312 d->bmm = new QBitmap(mask);-
313 d->cshape = Qt::BitmapCursor;-
314 d->hx = hotX >= 0
hotX >= 0Description
TRUEnever evaluated
FALSEnever evaluated
? hotX : bitmap.width() / 2 / devicePixelRatio;
0
315 d->hy = hotY >= 0
hotY >= 0Description
TRUEnever evaluated
FALSEnever evaluated
? hotY : bitmap.height() / 2 / devicePixelRatio;
0
316-
317 return
never executed: return d;
d;
never executed: return d;
0
318}-
319-
320void QCursorData::update()-
321{-
322}-
323-
324-
Switch to Source codePreprocessed file

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