| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/gui/kernel/qcursor.cpp |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||||||||||||||
| 2 | - | |||||||||||||||||||
| 3 | - | |||||||||||||||||||
| 4 | - | |||||||||||||||||||
| 5 | QPoint QCursor::pos(const QScreen *screen) | - | ||||||||||||||||||
| 6 | { | - | ||||||||||||||||||
| 7 | if (screen
| 0 | ||||||||||||||||||
| 8 | if (const
| 0 | ||||||||||||||||||
| 9 | const QPlatformScreen *ps = screen->handle(); | - | ||||||||||||||||||
| 10 | QPoint nativePos = cursor->pos(); | - | ||||||||||||||||||
| 11 | ps = ps->screenForPosition(nativePos); | - | ||||||||||||||||||
| 12 | return never executed: QHighDpi::fromNativePixels(nativePos, ps->screen());return 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: QGuiApplicationPrivate::lastCursorPosition.toPoint();return QGuiApplicationPrivate::lastCursorPosition.toPoint();never executed: return QGuiApplicationPrivate::lastCursorPosition.toPoint(); | 0 | ||||||||||||||||||
| 16 | } | - | ||||||||||||||||||
| 17 | QPoint QCursor::pos() | - | ||||||||||||||||||
| 18 | { | - | ||||||||||||||||||
| 19 | return never executed: QCursor::pos(QGuiApplication::primaryScreen());return QCursor::pos(QGuiApplication::primaryScreen());never executed: return QCursor::pos(QGuiApplication::primaryScreen()); | 0 | ||||||||||||||||||
| 20 | } | - | ||||||||||||||||||
| 21 | void QCursor::setPos(QScreen *screen, int x, int y) | - | ||||||||||||||||||
| 22 | { | - | ||||||||||||||||||
| 23 | if (screen
| 0 | ||||||||||||||||||
| 24 | if (QPlatformCursor *cursor = screen->handle()->cursor()
| 0 | ||||||||||||||||||
| 25 | const QPoint devicePos = QHighDpi::toNativePixels(QPoint(x, y), screen); | - | ||||||||||||||||||
| 26 | - | |||||||||||||||||||
| 27 | - | |||||||||||||||||||
| 28 | - | |||||||||||||||||||
| 29 | if (devicePos != cursor->pos()
| 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 | ||||||||||||||||||
| 34 | void QCursor::setPos(int x, int y) | - | ||||||||||||||||||
| 35 | { | - | ||||||||||||||||||
| 36 | QCursor::setPos(QGuiApplication::primaryScreen(), x, y); | - | ||||||||||||||||||
| 37 | } never executed: end of block | 0 | ||||||||||||||||||
| 38 | QDataStream &operator<<(QDataStream &s, const QCursor &c) | - | ||||||||||||||||||
| 39 | { | - | ||||||||||||||||||
| 40 | s << (qint16)c.shape(); | - | ||||||||||||||||||
| 41 | if (c.shape() == Qt::BitmapCursor
| 0 | ||||||||||||||||||
| 42 | bool isPixmap = false; | - | ||||||||||||||||||
| 43 | if (s.version() >= 7
| 0 | ||||||||||||||||||
| 44 | isPixmap = !c.pixmap().isNull(); | - | ||||||||||||||||||
| 45 | s << isPixmap; | - | ||||||||||||||||||
| 46 | } never executed: end of block | 0 | ||||||||||||||||||
| 47 | if (isPixmap
| 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: s;return s;never executed: return s; | 0 | ||||||||||||||||||
| 54 | } | - | ||||||||||||||||||
| 55 | QDataStream &operator>>(QDataStream &s, QCursor &c) | - | ||||||||||||||||||
| 56 | { | - | ||||||||||||||||||
| 57 | qint16 shape; | - | ||||||||||||||||||
| 58 | s >> shape; | - | ||||||||||||||||||
| 59 | if (shape == Qt::BitmapCursor
| 0 | ||||||||||||||||||
| 60 | bool isPixmap = false; | - | ||||||||||||||||||
| 61 | if (s.version() >= 7
| 0 | ||||||||||||||||||
| 62 | s >> isPixmap; never executed: s >> isPixmap; | 0 | ||||||||||||||||||
| 63 | if (isPixmap
| 0 | ||||||||||||||||||
| 64 | QPixmap pm; | - | ||||||||||||||||||
| 65 | QPoint hot; | - | ||||||||||||||||||
| 66 | s >> pm >> hot; | - | ||||||||||||||||||
| 67 | c = QCursor(pm, hot.x(), hot.y()); | - | ||||||||||||||||||
| 68 | } never executed: else {end of block | 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: s;return s;never executed: return s; | 0 | ||||||||||||||||||
| 78 | } | - | ||||||||||||||||||
| 79 | QCursor::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()
| 0 | ||||||||||||||||||
| 86 | QBitmap nullBm; | - | ||||||||||||||||||
| 87 | bm.setMask(nullBm); | - | ||||||||||||||||||
| 88 | } never executed: end of block | 0 | ||||||||||||||||||
| 89 | else if (!pixmap.mask().isNull()
| 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 | ||||||||||||||||||
| 101 | QCursor::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 | - | |||||||||||||||||||
| 110 | QCursor::QCursor() | - | ||||||||||||||||||
| 111 | { | - | ||||||||||||||||||
| 112 | if (!QCursorData::initialized
| 0 | ||||||||||||||||||
| 113 | if (QCoreApplication::startingUp()
| 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 | ||||||||||||||||||
| 123 | QCursor::QCursor(Qt::CursorShape shape) | - | ||||||||||||||||||
| 124 | : d(0) | - | ||||||||||||||||||
| 125 | { | - | ||||||||||||||||||
| 126 | if (!QCursorData::initialized
| 0 | ||||||||||||||||||
| 127 | QCursorData::initialize(); never executed: QCursorData::initialize(); | 0 | ||||||||||||||||||
| 128 | setShape(shape); | - | ||||||||||||||||||
| 129 | } never executed: end of block | 0 | ||||||||||||||||||
| 130 | Qt::CursorShape QCursor::shape() const | - | ||||||||||||||||||
| 131 | { | - | ||||||||||||||||||
| 132 | if (!QCursorData::initialized
| 0 | ||||||||||||||||||
| 133 | QCursorData::initialize(); never executed: QCursorData::initialize(); | 0 | ||||||||||||||||||
| 134 | return never executed: d->cshape;return d->cshape;never executed: return d->cshape; | 0 | ||||||||||||||||||
| 135 | } | - | ||||||||||||||||||
| 136 | void QCursor::setShape(Qt::CursorShape shape) | - | ||||||||||||||||||
| 137 | { | - | ||||||||||||||||||
| 138 | if (!QCursorData::initialized
| 0 | ||||||||||||||||||
| 139 | QCursorData::initialize(); never executed: QCursorData::initialize(); | 0 | ||||||||||||||||||
| 140 | QCursorData *c = uint(shape) <= Qt::LastCursor
| 0 | ||||||||||||||||||
| 141 | if (!c
| 0 | ||||||||||||||||||
| 142 | c = qt_cursorTable[0]; never executed: c = qt_cursorTable[0]; | 0 | ||||||||||||||||||
| 143 | c->ref.ref(); | - | ||||||||||||||||||
| 144 | if (!d
| 0 | ||||||||||||||||||
| 145 | d = c; | - | ||||||||||||||||||
| 146 | } never executed: else {end of block | 0 | ||||||||||||||||||
| 147 | if (!d->ref.deref()
| 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 | - | |||||||||||||||||||
| 157 | const QBitmap *QCursor::bitmap() const | - | ||||||||||||||||||
| 158 | { | - | ||||||||||||||||||
| 159 | if (!QCursorData::initialized
| 0 | ||||||||||||||||||
| 160 | QCursorData::initialize(); never executed: QCursorData::initialize(); | 0 | ||||||||||||||||||
| 161 | return never executed: d->bm;return d->bm;never executed: return d->bm; | 0 | ||||||||||||||||||
| 162 | } | - | ||||||||||||||||||
| 163 | - | |||||||||||||||||||
| 164 | - | |||||||||||||||||||
| 165 | - | |||||||||||||||||||
| 166 | - | |||||||||||||||||||
| 167 | - | |||||||||||||||||||
| 168 | - | |||||||||||||||||||
| 169 | const QBitmap *QCursor::mask() const | - | ||||||||||||||||||
| 170 | { | - | ||||||||||||||||||
| 171 | if (!QCursorData::initialized
| 0 | ||||||||||||||||||
| 172 | QCursorData::initialize(); never executed: QCursorData::initialize(); | 0 | ||||||||||||||||||
| 173 | return never executed: d->bmm;return d->bmm;never executed: return d->bmm; | 0 | ||||||||||||||||||
| 174 | } | - | ||||||||||||||||||
| 175 | - | |||||||||||||||||||
| 176 | - | |||||||||||||||||||
| 177 | - | |||||||||||||||||||
| 178 | - | |||||||||||||||||||
| 179 | - | |||||||||||||||||||
| 180 | - | |||||||||||||||||||
| 181 | QPixmap QCursor::pixmap() const | - | ||||||||||||||||||
| 182 | { | - | ||||||||||||||||||
| 183 | if (!QCursorData::initialized
| 0 | ||||||||||||||||||
| 184 | QCursorData::initialize(); never executed: QCursorData::initialize(); | 0 | ||||||||||||||||||
| 185 | return never executed: d->pixmap;return d->pixmap;never executed: return d->pixmap; | 0 | ||||||||||||||||||
| 186 | } | - | ||||||||||||||||||
| 187 | - | |||||||||||||||||||
| 188 | - | |||||||||||||||||||
| 189 | - | |||||||||||||||||||
| 190 | - | |||||||||||||||||||
| 191 | - | |||||||||||||||||||
| 192 | - | |||||||||||||||||||
| 193 | QPoint QCursor::hotSpot() const | - | ||||||||||||||||||
| 194 | { | - | ||||||||||||||||||
| 195 | if (!QCursorData::initialized
| 0 | ||||||||||||||||||
| 196 | QCursorData::initialize(); never executed: QCursorData::initialize(); | 0 | ||||||||||||||||||
| 197 | return never executed: QPoint(d->hx, d->hy);return QPoint(d->hx, d->hy);never executed: return QPoint(d->hx, d->hy); | 0 | ||||||||||||||||||
| 198 | } | - | ||||||||||||||||||
| 199 | - | |||||||||||||||||||
| 200 | - | |||||||||||||||||||
| 201 | - | |||||||||||||||||||
| 202 | - | |||||||||||||||||||
| 203 | - | |||||||||||||||||||
| 204 | QCursor::QCursor(const QCursor &c) | - | ||||||||||||||||||
| 205 | { | - | ||||||||||||||||||
| 206 | if (!QCursorData::initialized
| 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 | - | |||||||||||||||||||
| 216 | QCursor::~QCursor() | - | ||||||||||||||||||
| 217 | { | - | ||||||||||||||||||
| 218 | if (d
| 0 | ||||||||||||||||||
| 219 | delete d; never executed: delete d; | 0 | ||||||||||||||||||
| 220 | } never executed: end of block | 0 | ||||||||||||||||||
| 221 | - | |||||||||||||||||||
| 222 | - | |||||||||||||||||||
| 223 | - | |||||||||||||||||||
| 224 | - | |||||||||||||||||||
| 225 | - | |||||||||||||||||||
| 226 | - | |||||||||||||||||||
| 227 | - | |||||||||||||||||||
| 228 | QCursor &QCursor::operator=(const QCursor &c) | - | ||||||||||||||||||
| 229 | { | - | ||||||||||||||||||
| 230 | if (!QCursorData::initialized
| 0 | ||||||||||||||||||
| 231 | QCursorData::initialize(); never executed: QCursorData::initialize(); | 0 | ||||||||||||||||||
| 232 | if (c.d
| 0 | ||||||||||||||||||
| 233 | c.d->ref.ref(); never executed: c.d->ref.ref(); | 0 | ||||||||||||||||||
| 234 | if (d
| 0 | ||||||||||||||||||
| 235 | delete d; never executed: delete d; | 0 | ||||||||||||||||||
| 236 | d = c.d; | - | ||||||||||||||||||
| 237 | return never executed: *this;return *this;never executed: return *this; | 0 | ||||||||||||||||||
| 238 | } | - | ||||||||||||||||||
| 239 | - | |||||||||||||||||||
| 240 | - | |||||||||||||||||||
| 241 | - | |||||||||||||||||||
| 242 | - | |||||||||||||||||||
| 243 | QCursor::operator QVariant() const | - | ||||||||||||||||||
| 244 | { | - | ||||||||||||||||||
| 245 | return never executed: QVariant(QVariant::Cursor, this);return QVariant(QVariant::Cursor, this);never executed: return QVariant(QVariant::Cursor, this); | 0 | ||||||||||||||||||
| 246 | } | - | ||||||||||||||||||
| 247 | - | |||||||||||||||||||
| 248 | - | |||||||||||||||||||
| 249 | QDebug operator<<(QDebug dbg, const QCursor &c) | - | ||||||||||||||||||
| 250 | { | - | ||||||||||||||||||
| 251 | QDebugStateSaver saver(dbg); | - | ||||||||||||||||||
| 252 | dbg.nospace() << "QCursor(Qt::CursorShape(" << c.shape() << "))"; | - | ||||||||||||||||||
| 253 | return never executed: dbg;return dbg;never executed: return dbg; | 0 | ||||||||||||||||||
| 254 | } | - | ||||||||||||||||||
| 255 | - | |||||||||||||||||||
| 256 | - | |||||||||||||||||||
| 257 | - | |||||||||||||||||||
| 258 | - | |||||||||||||||||||
| 259 | - | |||||||||||||||||||
| 260 | - | |||||||||||||||||||
| 261 | QCursorData *qt_cursorTable[Qt::LastCursor + 1]; | - | ||||||||||||||||||
| 262 | bool QCursorData::initialized = false; | - | ||||||||||||||||||
| 263 | - | |||||||||||||||||||
| 264 | QCursorData::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 | - | |||||||||||||||||||
| 269 | QCursorData::~QCursorData() | - | ||||||||||||||||||
| 270 | { | - | ||||||||||||||||||
| 271 | delete bm; | - | ||||||||||||||||||
| 272 | delete bmm; | - | ||||||||||||||||||
| 273 | } never executed: end of block | 0 | ||||||||||||||||||
| 274 | - | |||||||||||||||||||
| 275 | - | |||||||||||||||||||
| 276 | void QCursorData::cleanup() | - | ||||||||||||||||||
| 277 | { | - | ||||||||||||||||||
| 278 | if(!QCursorData::initialized
| 0 | ||||||||||||||||||
| 279 | return; never executed: return; | 0 | ||||||||||||||||||
| 280 | - | |||||||||||||||||||
| 281 | for (int shape = 0; shape <= Qt::LastCursor
| 0 | ||||||||||||||||||
| 282 | - | |||||||||||||||||||
| 283 | if (!qt_cursorTable[shape]->ref.deref()
| 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 | - | |||||||||||||||||||
| 291 | void QCursorData::initialize() | - | ||||||||||||||||||
| 292 | { | - | ||||||||||||||||||
| 293 | if (QCursorData::initialized
| 0 | ||||||||||||||||||
| 294 | return; never executed: return; | 0 | ||||||||||||||||||
| 295 | for (int shape = 0; shape <= Qt::LastCursor
| 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 | - | |||||||||||||||||||
| 300 | QCursorData *QCursorData::setBitmap(const QBitmap &bitmap, const QBitmap &mask, int hotX, int hotY, qreal devicePixelRatio) | - | ||||||||||||||||||
| 301 | { | - | ||||||||||||||||||
| 302 | if (!QCursorData::initialized
| 0 | ||||||||||||||||||
| 303 | QCursorData::initialize(); never executed: QCursorData::initialize(); | 0 | ||||||||||||||||||
| 304 | if (bitmap.depth() != 1
| 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: c;return 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
| 0 | ||||||||||||||||||
| 315 | d->hy = hotY >= 0
| 0 | ||||||||||||||||||
| 316 | - | |||||||||||||||||||
| 317 | return never executed: d;return d;never executed: return d; | 0 | ||||||||||||||||||
| 318 | } | - | ||||||||||||||||||
| 319 | - | |||||||||||||||||||
| 320 | void QCursorData::update() | - | ||||||||||||||||||
| 321 | { | - | ||||||||||||||||||
| 322 | } | - | ||||||||||||||||||
| 323 | - | |||||||||||||||||||
| 324 | - | |||||||||||||||||||
| Switch to Source code | Preprocessed file |