diff options
Diffstat (limited to 'src/quick/handlers/qquicksinglepointhandler.cpp')
-rw-r--r-- | src/quick/handlers/qquicksinglepointhandler.cpp | 77 |
1 files changed, 30 insertions, 47 deletions
diff --git a/src/quick/handlers/qquicksinglepointhandler.cpp b/src/quick/handlers/qquicksinglepointhandler.cpp index aa650654eb..d2c38179a3 100644 --- a/src/quick/handlers/qquicksinglepointhandler.cpp +++ b/src/quick/handlers/qquicksinglepointhandler.cpp @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtQuick 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) 2018 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 "qquicksinglepointhandler_p.h" #include "qquicksinglepointhandler_p_p.h" @@ -93,9 +57,21 @@ bool QQuickSinglePointHandler::wantsPointerEvent(QPointerEvent *event) point = &p; } } - if (missing) - qCWarning(lcTouchTarget) << this << "pointId" << Qt::hex << d->pointInfo.id() - << "is missing from current event, but was neither canceled nor released"; + if (missing) { + // Received a stray touch begin event => reset and start over. + if (event->type() == QEvent::TouchBegin && event->points().count() == 1) { + const QEventPoint &point = event->point(0); + qCDebug(lcTouchTarget) << this << "pointId" << Qt::hex << point.id() + << "was received as a stray TouchBegin event. Canceling existing gesture" + " and starting over."; + d->pointInfo.reset(event, point); + return true; + } else { + qCWarning(lcTouchTarget) << this << "pointId" << Qt::hex << d->pointInfo.id() + << "is missing from current event, but was neither canceled nor released." + " Ignoring:" << event->type(); + } + } if (point) { if (candidatePointCount == 1 || (candidatePointCount > 1 && d->ignoreAdditionalPoints)) { point->setAccepted(); @@ -141,11 +117,16 @@ void QQuickSinglePointHandler::handlePointerEventImpl(QPointerEvent *event) void QQuickSinglePointHandler::handleEventPoint(QPointerEvent *event, QEventPoint &point) { - if (point.state() != QEventPoint::Released) - return; + if (point.state() == QEventPoint::Released) { + // If it's a mouse or tablet event, with buttons, + // do not deactivate unless all acceptable buttons are released. + if (event->isSinglePointEvent()) { + const Qt::MouseButtons releasedButtons = static_cast<QSinglePointEvent *>(event)->buttons(); + if ((releasedButtons & acceptedButtons()) != Qt::NoButton) + return; + } - const Qt::MouseButtons releasedButtons = static_cast<QSinglePointEvent *>(event)->buttons(); - if ((releasedButtons & acceptedButtons()) == Qt::NoButton) { + // Deactivate this handler on release setExclusiveGrab(event, point, false); d_func()->reset(); } @@ -207,9 +188,9 @@ QQuickHandlerPoint QQuickSinglePointHandler::point() const /*! \readonly - \qmlproperty HandlerPoint QtQuick::SinglePointHandler::point + \qmlproperty handlerPoint QtQuick::SinglePointHandler::point - The event point currently being handled. When no point is currently being + The \l eventPoint currently being handled. When no point is currently being handled, this object is reset to default values (all coordinates are 0). */ @@ -226,3 +207,5 @@ void QQuickSinglePointHandlerPrivate::reset() } QT_END_NAMESPACE + +#include "moc_qquicksinglepointhandler_p.cpp" |