diff options
author | Shawn Rutledge <shawn.rutledge@qt.io> | 2017-03-31 18:36:53 +0200 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@qt.io> | 2017-04-25 08:36:47 +0000 |
commit | f569af401aae651ea9bfa1f3a8ff68a58f8d71d1 (patch) | |
tree | 8ea20f278b3df8d8852f2633feaba4178787e329 /src/quick/handlers/qquickpointerdevicehandler.cpp | |
parent | b8dbafcae9ccfbf5c2ef7a173c51a73e57476681 (diff) |
QQuickPointerDeviceHandler: add acceptedModifiers
Sometimes you want to require holding down a key in order to enable
some interaction. As with the other "accepted" flags, it's better to
do this with a property than with Javascript.
Change-Id: Ie29880f5f9f496ddca1bee462e2c0e6dd30fa9f5
Reviewed-by: Jan Arve Sæther <jan-arve.saether@qt.io>
Diffstat (limited to 'src/quick/handlers/qquickpointerdevicehandler.cpp')
-rw-r--r-- | src/quick/handlers/qquickpointerdevicehandler.cpp | 40 |
1 files changed, 39 insertions, 1 deletions
diff --git a/src/quick/handlers/qquickpointerdevicehandler.cpp b/src/quick/handlers/qquickpointerdevicehandler.cpp index 3a320fdb32..203f712179 100644 --- a/src/quick/handlers/qquickpointerdevicehandler.cpp +++ b/src/quick/handlers/qquickpointerdevicehandler.cpp @@ -53,6 +53,7 @@ QQuickPointerDeviceHandler::QQuickPointerDeviceHandler(QObject *parent) : QQuickPointerHandler(parent) , m_acceptedDevices(QQuickPointerDevice::AllDevices) , m_acceptedPointerTypes(QQuickPointerDevice::AllPointerTypes) + , m_acceptedModifiers(Qt::KeyboardModifierMask) { } @@ -78,17 +79,54 @@ void QQuickPointerDeviceHandler::setAcceptedPointerTypes(QQuickPointerDevice::Po emit acceptedPointerTypesChanged(); } +/*! + \qmlproperty QQuickPointerDeviceHandler::acceptedModifiers + + If this property is set, it will require the given keyboard modifiers to + be pressed in order to react to pointer events, and otherwise ignore them. + + If this property is set to Qt.KeyboardModifierMask (the default value), + then the PointerHandler ignores the modifier keys. + + For example an Item could have two handlers of the same type, one of which + is enabled only if the required keyboard modifiers are pressed: + + \qml + Item { + TapHandler { + acceptedModifiers: Qt.ControlModifier + onTapped: console.log("control-tapped") + } + TapHandler { + acceptedModifiers: Qt.NoModifier + onTapped: console.log("tapped") + } + } + \endqml +*/ +void QQuickPointerDeviceHandler::setAcceptedModifiers(Qt::KeyboardModifiers acceptedModifiers) +{ + if (m_acceptedModifiers == acceptedModifiers) + return; + + m_acceptedModifiers = acceptedModifiers; + emit acceptedModifiersChanged(); +} + bool QQuickPointerDeviceHandler::wantsPointerEvent(QQuickPointerEvent *event) { if (!QQuickPointerHandler::wantsPointerEvent(event)) return false; qCDebug(lcPointerHandlerDispatch) << objectName() << "checking device type" << m_acceptedDevices - << "pointer type" << m_acceptedPointerTypes; + << "pointer type" << m_acceptedPointerTypes + << "modifiers" << m_acceptedModifiers; if ((event->device()->type() & m_acceptedDevices) == 0) return false; if ((event->device()->pointerType() & m_acceptedPointerTypes) == 0) return false; + if (m_acceptedModifiers != Qt::KeyboardModifierMask && event->modifiers() != m_acceptedModifiers) + return false; return true; } |