diff options
| author | Shawn Rutledge <shawn.rutledge@qt.io> | 2020-01-16 13:45:15 +0100 |
|---|---|---|
| committer | Jan Arve Sæther <jan-arve.saether@qt.io> | 2020-01-31 11:13:26 +0100 |
| commit | 1c44804600ad3dbeb60d1f5209ce9cf937d30ab3 (patch) | |
| tree | cfa4c668cb527d89ae666ea1c2290a1cab4bc256 /src/quick/handlers/qquickpointerhandler.cpp | |
| parent | a6e661d25bf7ebeb8f4e58925aa9375f5ca10ef3 (diff) | |
Add PointerHandler.cursorShape property
Also, QQuickItemPrivate::setHasCursorInChild() was unable to check
the QQuickItemPrivate::hasCursor variable, because the function
argument hasCursor was shadowing that, even though the comment
"nope! sorry, I have a cursor myself" hints that the intention
was to check that. So this change exposed a problem there, and
we have to fix that too, in order to keep the tst_qquickwindow::cursor()
test passing.
[ChangeLog][Event Handlers] Pointer Handlers now have a cursorShape
property to set the cursor when the handler is active and the mouse is
hovering, and restore to the previous cursor when the mouse leaves.
Fixes: QTBUG-68073
Change-Id: Ib5c66bd59c4691c4210ee5465e1c95e7bdcf5ae1
Reviewed-by: Jan Arve Sæther <jan-arve.saether@qt.io>
Diffstat (limited to 'src/quick/handlers/qquickpointerhandler.cpp')
| -rw-r--r-- | src/quick/handlers/qquickpointerhandler.cpp | 84 |
1 files changed, 83 insertions, 1 deletions
diff --git a/src/quick/handlers/qquickpointerhandler.cpp b/src/quick/handlers/qquickpointerhandler.cpp index c498c96454..adb753e000 100644 --- a/src/quick/handlers/qquickpointerhandler.cpp +++ b/src/quick/handlers/qquickpointerhandler.cpp @@ -51,7 +51,6 @@ Q_LOGGING_CATEGORY(lcPointerHandlerActive, "qt.quick.handler.active") \qmltype PointerHandler \qmlabstract \since 5.10 - \preliminary \instantiates QQuickPointerHandler \inqmlmodule QtQuick \brief Abstract handler for pointer events. @@ -154,6 +153,87 @@ void QQuickPointerHandler::resetDragThreshold() } /*! + \since 5.15 + \qmlproperty Qt::CursorShape PointerHandler::cursorShape + This property holds the cursor shape that will appear whenever the mouse is + hovering over the \l parentItem while \l active is \c true. + + The available cursor shapes are: + \list + \li Qt.ArrowCursor + \li Qt.UpArrowCursor + \li Qt.CrossCursor + \li Qt.WaitCursor + \li Qt.IBeamCursor + \li Qt.SizeVerCursor + \li Qt.SizeHorCursor + \li Qt.SizeBDiagCursor + \li Qt.SizeFDiagCursor + \li Qt.SizeAllCursor + \li Qt.BlankCursor + \li Qt.SplitVCursor + \li Qt.SplitHCursor + \li Qt.PointingHandCursor + \li Qt.ForbiddenCursor + \li Qt.WhatsThisCursor + \li Qt.BusyCursor + \li Qt.OpenHandCursor + \li Qt.ClosedHandCursor + \li Qt.DragCopyCursor + \li Qt.DragMoveCursor + \li Qt.DragLinkCursor + \endlist + + The default value is not set, which allows the \l {QQuickItem::cursor()}{cursor} + of \l parentItem to appear. This property can be reset to the same initial + condition by setting it to undefined. + + \note When this property has not been set, or has been set to \c undefined, + if you read the value it will return \c Qt.ArrowCursor. + + \sa Qt::CursorShape, QQuickItem::cursor(), HoverHandler::cursorShape +*/ +#if QT_CONFIG(cursor) +Qt::CursorShape QQuickPointerHandler::cursorShape() const +{ + Q_D(const QQuickPointerHandler); + return d->cursorShape; +} + +void QQuickPointerHandler::setCursorShape(Qt::CursorShape shape) +{ + Q_D(QQuickPointerHandler); + if (d->cursorSet && shape == d->cursorShape) + return; + d->cursorShape = shape; + d->cursorSet = true; + QQuickItemPrivate *itemPriv = QQuickItemPrivate::get(parentItem()); + itemPriv->hasCursorHandler = true; + itemPriv->setHasCursorInChild(true); + emit cursorShapeChanged(); +} + +void QQuickPointerHandler::resetCursorShape() +{ + Q_D(QQuickPointerHandler); + if (!d->cursorSet) + return; + d->cursorShape = Qt::ArrowCursor; + d->cursorSet = false; + QQuickItemPrivate *itemPriv = QQuickItemPrivate::get(parentItem()); + itemPriv->hasCursorHandler = false; + itemPriv->setHasCursorInChild(itemPriv->hasCursor); + emit cursorShapeChanged(); +} + +bool QQuickPointerHandler::isCursorShapeExplicitlySet() const +{ + Q_D(const QQuickPointerHandler); + return d->cursorSet; +} +#endif + +/*! Notification that the grab has changed in some way which is relevant to this handler. The \a grabber (subject) will be the Input Handler whose state is changing, or null if the state change regards an Item. @@ -597,11 +677,13 @@ QQuickPointerHandlerPrivate::QQuickPointerHandlerPrivate() : grabPermissions(QQuickPointerHandler::CanTakeOverFromItems | QQuickPointerHandler::CanTakeOverFromHandlersOfDifferentType | QQuickPointerHandler::ApprovesTakeOverByAnything) + , cursorShape(Qt::ArrowCursor) , enabled(true) , active(false) , targetExplicitlySet(false) , hadKeepMouseGrab(false) , hadKeepTouchGrab(false) + , cursorSet(false) { } |
