diff options
author | Qt Forward Merge Bot <qt_forward_merge_bot@qt-project.org> | 2019-10-04 01:00:22 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2019-10-04 11:29:16 +0200 |
commit | 9c7121df1579d38c7f4136da6146d7acae8fedcc (patch) | |
tree | 0917e293d83b4c1ce635cf65185e6ad98fe66519 /src/quick/handlers | |
parent | f529d38103a6c1c5c7b76ad92e0e5641719e369e (diff) | |
parent | c211b93bb87308601fe1c808634eb648d1949c40 (diff) |
Merge remote-tracking branch 'origin/5.14' into 5.15
Conflicts:
src/imports/qtquick2/plugins.qmltypes
src/quick/items/qquickitemsmodule.cpp
Change-Id: I841c65c9c131354788b4f3fcfe3d7ed27be316d5
Diffstat (limited to 'src/quick/handlers')
-rw-r--r-- | src/quick/handlers/qquickhoverhandler.cpp | 35 | ||||
-rw-r--r-- | src/quick/handlers/qquickpointerdevicehandler.cpp | 51 | ||||
-rw-r--r-- | src/quick/handlers/qquicktaphandler.cpp | 10 |
3 files changed, 82 insertions, 14 deletions
diff --git a/src/quick/handlers/qquickhoverhandler.cpp b/src/quick/handlers/qquickhoverhandler.cpp index d7566f0cd8..79cb288af8 100644 --- a/src/quick/handlers/qquickhoverhandler.cpp +++ b/src/quick/handlers/qquickhoverhandler.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2018 The Qt Company Ltd. +** Copyright (C) 2019 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtQuick module of the Qt Toolkit. @@ -47,14 +47,24 @@ Q_LOGGING_CATEGORY(lcHoverHandler, "qt.quick.handler.hover") /*! \qmltype HoverHandler \instantiates QQuickHoverHandler + \inherits SinglePointHandler \inqmlmodule QtQuick \ingroup qtquick-input-handlers \brief Handler for mouse and tablet hover. - HoverHandler detects a hovering cursor. Since touchscreens don't generally - offer hover events, in practice it detects a hovering mouse or tablet stylus. + HoverHandler detects a hovering mouse or tablet stylus cursor. - \sa MouseArea + A binding to the \l hovered property is the easiest way to react when the + cursor enters or leaves the \l {PointerHandler::parent}{parent} Item. + The \l {SinglePointHandler::point}{point} property provides more detail, + including the cursor position. The + \l {PointerDeviceHandler::acceptedDevices}{acceptedDevices}, + \l {PointerDeviceHandler::acceptedPointerTypes}{acceptedPointerTypes}, + and \l {PointerDeviceHandler::acceptedModifiers}{acceptedModifiers} + properties can be used to narrow the behavior to detect hovering of + specific kinds of devices or while holding a modifier key. + + \sa MouseArea, PointHandler */ QQuickHoverHandler::QQuickHoverHandler(QQuickItem *parent) @@ -62,9 +72,6 @@ QQuickHoverHandler::QQuickHoverHandler(QQuickItem *parent) { // Tell QQuickPointerDeviceHandler::wantsPointerEvent() to ignore button state d_func()->acceptedButtons = Qt::NoButton; - // Rule out the touchscreen for now (can be overridden in QML in case a hover-detecting touchscreen exists) - setAcceptedDevices(static_cast<QQuickPointerDevice::DeviceType>( - static_cast<int>(QQuickPointerDevice::AllDevices) ^ static_cast<int>(QQuickPointerDevice::TouchScreen))); } QQuickHoverHandler::~QQuickHoverHandler() @@ -93,10 +100,22 @@ bool QQuickHoverHandler::wantsPointerEvent(QQuickPointerEvent *event) void QQuickHoverHandler::handleEventPoint(QQuickEventPoint *point) { - setHovered(true); + bool hovered = true; + if (point->state() == QQuickEventPoint::Released && + point->pointerEvent()->device()->pointerType() == QQuickPointerDevice::Finger) + hovered = false; + setHovered(hovered); setPassiveGrab(point); } +/*! + \qmlproperty bool QtQuick::HoverHandler::hovered + \readonly + + Holds true whenever any pointing device cursor (mouse or tablet) is within + the bounds of the \c parent Item, extended by the + \l {PointerHandler::margin}{margin}, if any. +*/ void QQuickHoverHandler::setHovered(bool hovered) { if (m_hovered != hovered) { diff --git a/src/quick/handlers/qquickpointerdevicehandler.cpp b/src/quick/handlers/qquickpointerdevicehandler.cpp index 449d726b78..90f31bf9fd 100644 --- a/src/quick/handlers/qquickpointerdevicehandler.cpp +++ b/src/quick/handlers/qquickpointerdevicehandler.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2019 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtQuick module of the Qt Toolkit. @@ -230,6 +230,55 @@ void QQuickPointerDeviceHandler::setAcceptedPointerTypes(QQuickPointerDevice::Po } } \endqml + + If you set \c acceptedModifiers to an OR combination of modifier keys, + it means \e all of those modifiers must be pressed to activate the handler: + + \qml + Item { + TapHandler { + acceptedModifiers: Qt.ControlModifier | Qt.AltModifier | Qt.ShiftModifier + onTapped: console.log("control-alt-shift-tapped") + } + } + \endqml + + The available modifiers are as follows: + + \value NoModifier No modifier key is allowed. + \value ShiftModifier A Shift key on the keyboard must be pressed. + \value ControlModifier A Ctrl key on the keyboard must be pressed. + \value AltModifier An Alt key on the keyboard must be pressed. + \value MetaModifier A Meta key on the keyboard must be pressed. + \value KeypadModifier A keypad button must be pressed. + \value GroupSwitchModifier X11 only (unless activated on Windows by a command line argument). + A Mode_switch key on the keyboard must be pressed. + \value KeyboardModifierMask The handler does not care which modifiers are pressed. + + If you need even more complex behavior than can be achieved with + combinations of multiple handlers with multiple modifier flags, you can + check the modifiers in JavaScript code: + + \qml + Item { + TapHandler { + onTapped: + switch (point.modifiers) { + case Qt.ControlModifier | Qt.AltModifier: + console.log("CTRL+ALT"); + break; + case Qt.ControlModifier | Qt.AltModifier | Qt.MetaModifier: + console.log("CTRL+META+ALT"); + break; + default: + console.log("other modifiers", point.modifiers); + break; + } + } + } + \endqml + + \sa Qt::KeyboardModifier */ void QQuickPointerDeviceHandler::setAcceptedModifiers(Qt::KeyboardModifiers acceptedModifiers) { diff --git a/src/quick/handlers/qquicktaphandler.cpp b/src/quick/handlers/qquicktaphandler.cpp index 5f9d2151d7..272ebe6b63 100644 --- a/src/quick/handlers/qquicktaphandler.cpp +++ b/src/quick/handlers/qquicktaphandler.cpp @@ -379,7 +379,7 @@ void QQuickTapHandler::updateTimeHeld() That is, if you press and release a touchpoint or button within a time period less than \l longPressThreshold, while any movement does not exceed the drag threshold, then the \c tapped signal will be emitted at the time - of release. The \c eventPoint signal parameter contains information + of release. The \a eventPoint signal parameter contains information from the release event about the point that was tapped: \snippet pointerHandlers/tapHandlerOnTapped.qml 0 @@ -392,7 +392,7 @@ void QQuickTapHandler::updateTimeHeld() This signal is emitted when the \c parent Item is tapped once. After an amount of time greater than QStyleHints::mouseDoubleClickInterval, it can be tapped again; but if the time until the next tap is less, - \l tapCount will increase. The \c eventPoint signal parameter contains + \l tapCount will increase. The \a eventPoint signal parameter contains information from the release event about the point that was tapped. */ @@ -404,13 +404,13 @@ void QQuickTapHandler::updateTimeHeld() short span of time (QStyleHints::mouseDoubleClickInterval()) and distance (QStyleHints::mouseDoubleClickDistance() or QStyleHints::touchDoubleTapDistance()). This signal always occurs after - \l singleTapped, \l tapped, and \l tapCountChanged. The \c eventPoint + \l singleTapped, \l tapped, and \l tapCountChanged. The \a eventPoint signal parameter contains information from the release event about the point that was tapped. */ /*! - \qmlsignal QtQuick::TapHandler::longPressed + \qmlsignal QtQuick::TapHandler::longPressed() This signal is emitted when the \c parent Item is pressed and held for a time period greater than \l longPressThreshold. That is, if you press and @@ -420,7 +420,7 @@ void QQuickTapHandler::updateTimeHeld() */ /*! - \qmlsignal QtQuick::TapHandler::tapCountChanged + \qmlsignal QtQuick::TapHandler::tapCountChanged() This signal is emitted when the \c parent Item is tapped once or more (within a specified time and distance span) and when the present \c tapCount differs |