From 6445aa4b064931cda36243aafc1600915fac093e Mon Sep 17 00:00:00 2001 From: Gabriel de Dietrich Date: Tue, 21 Feb 2017 16:28:21 -0800 Subject: QCursor: Add equality operators [ChangeLog][QtGui][QCursor] Added equality operators. Change-Id: Iedeab4673b2a77ad2e51a0d50297b12bba3b9505 Reviewed-by: Marc Mutz Reviewed-by: Edward Welbourne --- src/gui/kernel/qcursor.cpp | 48 ++++++++++++++++++++++++++++++++++++++++++++++ src/gui/kernel/qcursor.h | 4 ++++ 2 files changed, 52 insertions(+) (limited to 'src/gui') 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 diff --git a/src/gui/kernel/qcursor.h b/src/gui/kernel/qcursor.h index c7e9188e5b..ccce3d84ef 100644 --- a/src/gui/kernel/qcursor.h +++ b/src/gui/kernel/qcursor.h @@ -112,10 +112,14 @@ public: inline static void setPos(QScreen *screen, const QPoint &p) { setPos(screen, p.x(), p.y()); } private: + friend Q_GUI_EXPORT bool operator==(const QCursor &lhs, const QCursor &rhs) Q_DECL_NOTHROW; QCursorData *d; }; Q_DECLARE_SHARED_NOT_MOVABLE_UNTIL_QT6(QCursor) +Q_GUI_EXPORT bool operator==(const QCursor &lhs, const QCursor &rhs) Q_DECL_NOTHROW; +inline bool operator!=(const QCursor &lhs, const QCursor &rhs) Q_DECL_NOTHROW { return !(lhs == rhs); } + /***************************************************************************** QCursor stream functions *****************************************************************************/ -- cgit v1.2.3