summaryrefslogtreecommitdiffstats
path: root/src/gui/kernel/qcursor.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/kernel/qcursor.cpp')
-rw-r--r--src/gui/kernel/qcursor.cpp133
1 files changed, 58 insertions, 75 deletions
diff --git a/src/gui/kernel/qcursor.cpp b/src/gui/kernel/qcursor.cpp
index f5a794b642..8e7747559a 100644
--- a/src/gui/kernel/qcursor.cpp
+++ b/src/gui/kernel/qcursor.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qcursor.h"
@@ -150,7 +114,7 @@ QT_BEGIN_NAMESPACE
\li Qt::DragLinkCursor \li \c dnd-link or \c link
\endtable
- \sa QWidget, {fowler}{GUI Design Handbook: Cursors}
+ \sa QWidget
*/
/*!
@@ -251,7 +215,8 @@ void QCursor::setPos(QScreen *screen, int x, int y)
{
if (screen) {
if (QPlatformCursor *cursor = screen->handle()->cursor()) {
- const QPoint devicePos = QHighDpi::toNativePixels(QPoint(x, y), screen);
+ const QPoint pos(x, y);
+ const QPoint devicePos = QHighDpi::toNativePixels(pos, screen->virtualSiblingAt(pos));
// Need to check, since some X servers generate null mouse move
// events, causing looping in applications which call setPos() on
// every mouse move event.
@@ -325,7 +290,7 @@ QDataStream &operator<<(QDataStream &s, const QCursor &c)
if (isPixmap)
s << c.pixmap();
else
- s << *c.bitmap() << *c.mask();
+ s << c.bitmap() << c.mask();
s << c.hotSpot();
}
return s;
@@ -474,14 +439,12 @@ QCursor::QCursor()
QCursor::QCursor(Qt::CursorShape shape)
: d(nullptr)
{
- if (!QCursorData::initialized)
- QCursorData::initialize();
+ QCursorData::initialize();
setShape(shape);
}
/*!
- \fn bool operator==(const QCursor &lhs, const QCursor &rhs)
- \relates QCursor
+ \fn bool QCursor::operator==(const QCursor &lhs, const QCursor &rhs)
\since 5.10
Equality operator. Returns \c true if \a lhs and \a rhs
@@ -519,8 +482,7 @@ bool operator==(const QCursor &lhs, const QCursor &rhs) noexcept
}
/*!
- \fn bool operator!=(const QCursor &lhs, const QCursor &rhs)
- \relates QCursor
+ \fn bool QCursor::operator!=(const QCursor &lhs, const QCursor &rhs)
\since 5.10
Inequality operator. Returns the equivalent of !(\a lhs == \a rhs).
@@ -529,15 +491,13 @@ bool operator==(const QCursor &lhs, const QCursor &rhs) noexcept
*/
/*!
- Returns the cursor shape identifier. The return value is one of
- the \l Qt::CursorShape enum values (cast to an int).
+ Returns the cursor shape identifier.
\sa setShape()
*/
Qt::CursorShape QCursor::shape() const
{
- if (!QCursorData::initialized)
- QCursorData::initialize();
+ QCursorData::initialize();
return d->cshape;
}
@@ -550,8 +510,7 @@ Qt::CursorShape QCursor::shape() const
*/
void QCursor::setShape(Qt::CursorShape shape)
{
- if (!QCursorData::initialized)
- QCursorData::initialize();
+ QCursorData::initialize();
QCursorData *c = uint(shape) <= Qt::LastCursor ? qt_cursorTable[shape] : nullptr;
if (!c)
c = qt_cursorTable[0];
@@ -566,26 +525,55 @@ void QCursor::setShape(Qt::CursorShape shape)
}
/*!
- Returns the cursor bitmap, or \nullptr if it is one of the
+ \fn QBitmap QCursor::bitmap(Qt::ReturnByValueConstant) const
+ \since 5.15
+ \deprecated Use the overload without argument instead.
+
+ Returns the cursor bitmap, or a null bitmap if it is one of the
+ standard cursors.
+
+ Previously, Qt provided a version of \c bitmap() which returned the bitmap
+ by-pointer. That version is now removed. To maintain compatibility
+ with old code, this function was provided to differentiate between the by-pointer
+ function and the by-value function.
+*/
+
+/*!
+ Returns the cursor bitmap, or a null bitmap if it is one of the
standard cursors.
*/
-const QBitmap *QCursor::bitmap() const
+QBitmap QCursor::bitmap() const
{
- if (!QCursorData::initialized)
- QCursorData::initialize();
- return d->bm;
+ QCursorData::initialize();
+ if (d->bm)
+ return *(d->bm);
+ return QBitmap();
}
/*!
- Returns the cursor bitmap mask, or \nullptr if it is one of the
+ \fn QBitmap QCursor::mask(Qt::ReturnByValueConstant) const
+ \since 5.15
+ \deprecated Use the overload without argument instead.
+
+ Returns the cursor bitmap mask, or a null bitmap if it is one of the
standard cursors.
+
+ Previously, Qt provided a version of \c mask() which returned the bitmap
+ by-pointer. That version is now removed. To maintain compatibility
+ with old code, this function was provided to differentiate between the by-pointer
+ function and the by-value function.
*/
-const QBitmap *QCursor::mask() const
+/*!
+ Returns the cursor bitmap mask, or a null bitmap if it is one of the
+ standard cursors.
+*/
+QBitmap QCursor::mask() const
{
- if (!QCursorData::initialized)
- QCursorData::initialize();
- return d->bmm;
+ QCursorData::initialize();
+ if (d->bmm)
+ return *(d->bmm);
+ return QBitmap();
}
/*!
@@ -595,8 +583,7 @@ const QBitmap *QCursor::mask() const
QPixmap QCursor::pixmap() const
{
- if (!QCursorData::initialized)
- QCursorData::initialize();
+ QCursorData::initialize();
return d->pixmap;
}
@@ -607,8 +594,7 @@ QPixmap QCursor::pixmap() const
QPoint QCursor::hotSpot() const
{
- if (!QCursorData::initialized)
- QCursorData::initialize();
+ QCursorData::initialize();
return QPoint(d->hx, d->hy);
}
@@ -618,8 +604,7 @@ QPoint QCursor::hotSpot() const
QCursor::QCursor(const QCursor &c)
{
- if (!QCursorData::initialized)
- QCursorData::initialize();
+ QCursorData::initialize();
d = c.d;
d->ref.ref();
}
@@ -642,8 +627,7 @@ QCursor::~QCursor()
QCursor &QCursor::operator=(const QCursor &c)
{
- if (!QCursorData::initialized)
- QCursorData::initialize();
+ QCursorData::initialize();
if (c.d)
c.d->ref.ref();
if (d && !d->ref.deref())
@@ -657,7 +641,7 @@ QCursor &QCursor::operator=(const QCursor &c)
*/
QCursor::operator QVariant() const
{
- return QVariant(QVariant::Cursor, this);
+ return QVariant::fromValue(*this);
}
#ifndef QT_NO_DEBUG_STREAM
@@ -690,7 +674,7 @@ QCursorData::~QCursorData()
/*! \internal */
void QCursorData::cleanup()
{
- if(!QCursorData::initialized)
+ if (!QCursorData::initialized)
return;
for (int shape = 0; shape <= Qt::LastCursor; ++shape) {
@@ -714,8 +698,7 @@ void QCursorData::initialize()
QCursorData *QCursorData::setBitmap(const QBitmap &bitmap, const QBitmap &mask, int hotX, int hotY, qreal devicePixelRatio)
{
- if (!QCursorData::initialized)
- QCursorData::initialize();
+ QCursorData::initialize();
if (bitmap.depth() != 1 || mask.depth() != 1 || bitmap.size() != mask.size()) {
qWarning("QCursor: Cannot create bitmap cursor; invalid bitmap(s)");
QCursorData *c = qt_cursorTable[0];