diff options
author | Gabriel de Dietrich <gabriel.dedietrich@qt.io> | 2017-02-21 16:28:21 -0800 |
---|---|---|
committer | Gabriel de Dietrich <gabriel.dedietrich@qt.io> | 2017-03-21 17:22:41 +0000 |
commit | 6445aa4b064931cda36243aafc1600915fac093e (patch) | |
tree | 1b205a10a883951a76b1861cb032fe83f3eda9a7 /src/gui/kernel/qcursor.cpp | |
parent | 464c0a5824191a33318a5d09f0fb7a8b9c645eb1 (diff) |
QCursor: Add equality operators
[ChangeLog][QtGui][QCursor] Added equality operators.
Change-Id: Iedeab4673b2a77ad2e51a0d50297b12bba3b9505
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'src/gui/kernel/qcursor.cpp')
-rw-r--r-- | src/gui/kernel/qcursor.cpp | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/src/gui/kernel/qcursor.cpp b/src/gui/kernel/qcursor.cpp index b7035d47c4..8ae9085d9f 100644 --- a/src/gui/kernel/qcursor.cpp +++ b/src/gui/kernel/qcursor.cpp @@ -471,6 +471,54 @@ QCursor::QCursor(Qt::CursorShape shape) setShape(shape); } +/*! + \fn bool operator==(const QCursor &lhs, const QCursor &rhs) + \relates QCursor + \since 5.10 + + Equality operator. Returns \c true if \a lhs and \a rhs + have the same \l{QCursor::}{shape()} and, in the case of + \l{Qt::BitmapCursor}{bitmap cursors}, the same \l{QCursor::}{hotSpot()} + and either the same \l{QCursor::}{pixmap()} or the same + \l{QCursor::}{bitmap()} and \l{QCursor::}{mask()}. + + \note When comparing bitmap cursors, this function only + compares the bitmaps' \l{QPixmap::cacheKey()}{cache keys}, + not each pixel. + + \sa operator!=(const QCursor &lhs, const QCursor &rhs) +*/ +bool operator==(const QCursor &lhs, const QCursor &rhs) Q_DECL_NOTHROW +{ + if (lhs.d == rhs.d) + return true; // Copy or same shape + + // Check pixmaps or bitmaps cache keys. Notice that having BitmapCursor + // shape implies either non-null pixmap or non-null bitmap and mask + if (lhs.shape() == Qt::BitmapCursor && rhs.shape() == Qt::BitmapCursor + && lhs.hotSpot() == rhs.hotSpot()) { + if (!lhs.d->pixmap.isNull()) + return lhs.d->pixmap.cacheKey() == rhs.d->pixmap.cacheKey(); + + if (!rhs.d->pixmap.isNull()) + return false; + + return lhs.d->bm->cacheKey() == rhs.d->bm->cacheKey() + && lhs.d->bmm->cacheKey() == rhs.d->bmm->cacheKey(); + } + + return false; +} + +/*! + \fn bool operator!=(const QCursor &lhs, const QCursor &rhs) + \relates QCursor + \since 5.10 + + Inequality operator. Returns the equivalent of !(\a lhs == \a rhs). + + \sa operator==(const QCursor &lhs, const QCursor &rhs) +*/ /*! Returns the cursor shape identifier. The return value is one of |