| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/quick/handlers/qquicksinglepointhandler.cpp |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /**************************************************************************** | - | ||||||||||||||||||
| 2 | ** | - | ||||||||||||||||||
| 3 | ** Copyright (C) 2018 The Qt Company Ltd. | - | ||||||||||||||||||
| 4 | ** Contact: https://www.qt.io/licensing/ | - | ||||||||||||||||||
| 5 | ** | - | ||||||||||||||||||
| 6 | ** This file is part of the QtQuick module of the Qt Toolkit. | - | ||||||||||||||||||
| 7 | ** | - | ||||||||||||||||||
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ | - | ||||||||||||||||||
| 9 | ** Commercial License Usage | - | ||||||||||||||||||
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||||||||
| 11 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||||||||
| 12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||||||||
| 13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||||||||
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||
| 15 | ** information use the contact form at https://www.qt.io/contact-us. | - | ||||||||||||||||||
| 16 | ** | - | ||||||||||||||||||
| 17 | ** GNU Lesser General Public License Usage | - | ||||||||||||||||||
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||||||||
| 19 | ** General Public License version 3 as published by the Free Software | - | ||||||||||||||||||
| 20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | - | ||||||||||||||||||
| 21 | ** packaging of this file. Please review the following information to | - | ||||||||||||||||||
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements | - | ||||||||||||||||||
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | - | ||||||||||||||||||
| 24 | ** | - | ||||||||||||||||||
| 25 | ** GNU General Public License Usage | - | ||||||||||||||||||
| 26 | ** Alternatively, this file may be used under the terms of the GNU | - | ||||||||||||||||||
| 27 | ** General Public License version 2.0 or (at your option) the GNU General | - | ||||||||||||||||||
| 28 | ** Public license version 3 or any later version approved by the KDE Free | - | ||||||||||||||||||
| 29 | ** Qt Foundation. The licenses are as published by the Free Software | - | ||||||||||||||||||
| 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | - | ||||||||||||||||||
| 31 | ** included in the packaging of this file. Please review the following | - | ||||||||||||||||||
| 32 | ** information to ensure the GNU General Public License requirements will | - | ||||||||||||||||||
| 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | - | ||||||||||||||||||
| 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. | - | ||||||||||||||||||
| 35 | ** | - | ||||||||||||||||||
| 36 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||
| 37 | ** | - | ||||||||||||||||||
| 38 | ****************************************************************************/ | - | ||||||||||||||||||
| 39 | - | |||||||||||||||||||
| 40 | #include "qquicksinglepointhandler_p.h" | - | ||||||||||||||||||
| 41 | - | |||||||||||||||||||
| 42 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||
| 43 | Q_DECLARE_LOGGING_CATEGORY(DBG_TOUCH_TARGET) | - | ||||||||||||||||||
| 44 | - | |||||||||||||||||||
| 45 | /*! | - | ||||||||||||||||||
| 46 | \qmltype SinglePointHandler | - | ||||||||||||||||||
| 47 | \qmlabstract | - | ||||||||||||||||||
| 48 | \preliminary | - | ||||||||||||||||||
| 49 | \instantiates QQuickSinglePointHandler | - | ||||||||||||||||||
| 50 | \inherits PointerDeviceHandler | - | ||||||||||||||||||
| 51 | \inqmlmodule Qt.labs.handlers | - | ||||||||||||||||||
| 52 | \ingroup qtquick-handlers | - | ||||||||||||||||||
| 53 | \brief Abstract handler for single-point Pointer Events. | - | ||||||||||||||||||
| 54 | - | |||||||||||||||||||
| 55 | An intermediate class (not registered as a QML type) | - | ||||||||||||||||||
| 56 | for the most common handlers: those which expect only a single point. | - | ||||||||||||||||||
| 57 | wantsPointerEvent() will choose the first point which is inside the | - | ||||||||||||||||||
| 58 | \l target item, and return true as long as the event contains that point. | - | ||||||||||||||||||
| 59 | Override handleEventPoint() to implement a single-point handler. | - | ||||||||||||||||||
| 60 | */ | - | ||||||||||||||||||
| 61 | - | |||||||||||||||||||
| 62 | QQuickSinglePointHandler::QQuickSinglePointHandler(QObject *parent) | - | ||||||||||||||||||
| 63 | : QQuickPointerDeviceHandler(parent) | - | ||||||||||||||||||
| 64 | , m_ignoreAdditionalPoints(false) | - | ||||||||||||||||||
| 65 | { | - | ||||||||||||||||||
| 66 | } executed 1000 times by 5 tests: end of blockExecuted by:
| 1000 | ||||||||||||||||||
| 67 | - | |||||||||||||||||||
| 68 | bool QQuickSinglePointHandler::wantsPointerEvent(QQuickPointerEvent *event) | - | ||||||||||||||||||
| 69 | { | - | ||||||||||||||||||
| 70 | if (!QQuickPointerDeviceHandler::wantsPointerEvent(event))
| 0-2605 | ||||||||||||||||||
| 71 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 72 | if (event->device()->pointerType() != QQuickPointerDevice::Finger &&
| 310-2295 | ||||||||||||||||||
| 73 | (event->buttons() & acceptedButtons()) == 0 && (event->button() & acceptedButtons()) == 0)
| 0-252 | ||||||||||||||||||
| 74 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 75 | - | |||||||||||||||||||
| 76 | if (m_pointInfo.m_id) {
| 1035-1570 | ||||||||||||||||||
| 77 | // We already know which one we want, so check whether it's there. | - | ||||||||||||||||||
| 78 | // It's expected to be an update or a release. | - | ||||||||||||||||||
| 79 | // If we no longer want it, cancel the grab. | - | ||||||||||||||||||
| 80 | int candidatePointCount = 0; | - | ||||||||||||||||||
| 81 | bool missing = true; | - | ||||||||||||||||||
| 82 | QQuickEventPoint *point = nullptr; | - | ||||||||||||||||||
| 83 | int c = event->pointCount(); | - | ||||||||||||||||||
| 84 | for (int i = 0; i < c; ++i) {
| 1570-2532 | ||||||||||||||||||
| 85 | QQuickEventPoint *p = event->point(i); | - | ||||||||||||||||||
| 86 | const bool found = (p->pointId() == m_pointInfo.m_id); | - | ||||||||||||||||||
| 87 | if (found)
| 962-1570 | ||||||||||||||||||
| 88 | missing = false; executed 1570 times by 4 tests: missing = false;Executed by:
| 1570 | ||||||||||||||||||
| 89 | if (wantsEventPoint(p)) {
| 1184-1348 | ||||||||||||||||||
| 90 | ++candidatePointCount; | - | ||||||||||||||||||
| 91 | if (found)
| 62-1286 | ||||||||||||||||||
| 92 | point = p; executed 1286 times by 4 tests: point = p;Executed by:
| 1286 | ||||||||||||||||||
| 93 | } executed 1348 times by 4 tests: end of blockExecuted by:
| 1348 | ||||||||||||||||||
| 94 | } executed 2532 times by 4 tests: end of blockExecuted by:
| 2532 | ||||||||||||||||||
| 95 | if (missing)
| 0-1570 | ||||||||||||||||||
| 96 | qCWarning(DBG_TOUCH_TARGET) << this << "pointId" << hex << m_pointInfo.m_id never executed: QMessageLogger(__FILE__, 96, __PRETTY_FUNCTION__, DBG_TOUCH_TARGET().categoryName()).warning() << this << "pointId" << hex << m_pointInfo.m_id << "is missing from current event, but was neither canceled nor released";
| 0 | ||||||||||||||||||
| 97 | << "is missing from current event, but was neither canceled nor released"; never executed: QMessageLogger(__FILE__, 96, __PRETTY_FUNCTION__, DBG_TOUCH_TARGET().categoryName()).warning() << this << "pointId" << hex << m_pointInfo.m_id << "is missing from current event, but was neither canceled nor released"; | 0 | ||||||||||||||||||
| 98 | if (point) {
| 284-1286 | ||||||||||||||||||
| 99 | if (candidatePointCount == 1 || (candidatePointCount > 1 && m_ignoreAdditionalPoints)) {
| 0-1260 | ||||||||||||||||||
| 100 | point->setAccepted(); | - | ||||||||||||||||||
| 101 | return true; executed 1260 times by 4 tests: return true;Executed by:
| 1260 | ||||||||||||||||||
| 102 | } else { | - | ||||||||||||||||||
| 103 | point->cancelAllGrabs(this); | - | ||||||||||||||||||
| 104 | } executed 26 times by 2 tests: end of blockExecuted by:
| 26 | ||||||||||||||||||
| 105 | } else { | - | ||||||||||||||||||
| 106 | return false; executed 284 times by 3 tests: return false;Executed by:
| 284 | ||||||||||||||||||
| 107 | } | - | ||||||||||||||||||
| 108 | } else { | - | ||||||||||||||||||
| 109 | // We have not yet chosen a point; choose the first one for which wantsEventPoint() returns true. | - | ||||||||||||||||||
| 110 | int candidatePointCount = 0; | - | ||||||||||||||||||
| 111 | int c = event->pointCount(); | - | ||||||||||||||||||
| 112 | QQuickEventPoint *chosen = nullptr; | - | ||||||||||||||||||
| 113 | for (int i = 0; i < c; ++i) {
| 1035-1937 | ||||||||||||||||||
| 114 | QQuickEventPoint *p = event->point(i); | - | ||||||||||||||||||
| 115 | if (!p->exclusiveGrabber() && wantsEventPoint(p)) {
| 431-1506 | ||||||||||||||||||
| 116 | if (!chosen)
| 264-592 | ||||||||||||||||||
| 117 | chosen = p; executed 592 times by 4 tests: chosen = p;Executed by:
| 592 | ||||||||||||||||||
| 118 | ++candidatePointCount; | - | ||||||||||||||||||
| 119 | } executed 856 times by 4 tests: end of blockExecuted by:
| 856 | ||||||||||||||||||
| 120 | } executed 1937 times by 4 tests: end of blockExecuted by:
| 1937 | ||||||||||||||||||
| 121 | if (chosen && candidatePointCount == 1) {
| 140-592 | ||||||||||||||||||
| 122 | setPointId(chosen->pointId()); | - | ||||||||||||||||||
| 123 | chosen->setAccepted(); | - | ||||||||||||||||||
| 124 | } executed 452 times by 4 tests: end of blockExecuted by:
| 452 | ||||||||||||||||||
| 125 | } executed 1035 times by 4 tests: end of blockExecuted by:
| 1035 | ||||||||||||||||||
| 126 | return m_pointInfo.m_id; executed 1061 times by 4 tests: return m_pointInfo.m_id;Executed by:
| 1061 | ||||||||||||||||||
| 127 | } | - | ||||||||||||||||||
| 128 | - | |||||||||||||||||||
| 129 | void QQuickSinglePointHandler::handlePointerEventImpl(QQuickPointerEvent *event) | - | ||||||||||||||||||
| 130 | { | - | ||||||||||||||||||
| 131 | QQuickPointerDeviceHandler::handlePointerEventImpl(event); | - | ||||||||||||||||||
| 132 | QQuickEventPoint *currentPoint = event->pointById(m_pointInfo.m_id); | - | ||||||||||||||||||
| 133 | Q_ASSERT(currentPoint); | - | ||||||||||||||||||
| 134 | if (!m_pointInfo.m_id || !currentPoint->isAccepted()) {
| 0-1712 | ||||||||||||||||||
| 135 | reset(); | - | ||||||||||||||||||
| 136 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 137 | m_pointInfo.reset(currentPoint); | - | ||||||||||||||||||
| 138 | handleEventPoint(currentPoint); | - | ||||||||||||||||||
| 139 | if (currentPoint->state() == QQuickEventPoint::Released) {
| 200-1512 | ||||||||||||||||||
| 140 | setExclusiveGrab(currentPoint, false); | - | ||||||||||||||||||
| 141 | reset(); | - | ||||||||||||||||||
| 142 | } executed 200 times by 4 tests: end of blockExecuted by:
| 200 | ||||||||||||||||||
| 143 | emit pointChanged(); | - | ||||||||||||||||||
| 144 | } executed 1712 times by 4 tests: end of blockExecuted by:
| 1712 | ||||||||||||||||||
| 145 | } | - | ||||||||||||||||||
| 146 | - | |||||||||||||||||||
| 147 | void QQuickSinglePointHandler::onGrabChanged(QQuickPointerHandler *grabber, QQuickEventPoint::GrabState stateChange, QQuickEventPoint *point) | - | ||||||||||||||||||
| 148 | { | - | ||||||||||||||||||
| 149 | if (grabber != this)
| 22-498 | ||||||||||||||||||
| 150 | return; executed 22 times by 2 tests: return;Executed by:
| 22 | ||||||||||||||||||
| 151 | switch (stateChange) { | - | ||||||||||||||||||
| 152 | case QQuickEventPoint::GrabExclusive: executed 124 times by 4 tests: case QQuickEventPoint::GrabExclusive:Executed by:
| 124 | ||||||||||||||||||
| 153 | m_pointInfo.m_sceneGrabPosition = point->sceneGrabPosition(); | - | ||||||||||||||||||
| 154 | setActive(true); | - | ||||||||||||||||||
| 155 | QQuickPointerHandler::onGrabChanged(grabber, stateChange, point); | - | ||||||||||||||||||
| 156 | break; executed 124 times by 4 tests: break;Executed by:
| 124 | ||||||||||||||||||
| 157 | case QQuickEventPoint::GrabPassive: executed 176 times by 4 tests: case QQuickEventPoint::GrabPassive:Executed by:
| 176 | ||||||||||||||||||
| 158 | m_pointInfo.m_sceneGrabPosition = point->sceneGrabPosition(); | - | ||||||||||||||||||
| 159 | QQuickPointerHandler::onGrabChanged(grabber, stateChange, point); | - | ||||||||||||||||||
| 160 | break; executed 176 times by 4 tests: break;Executed by:
| 176 | ||||||||||||||||||
| 161 | case QQuickEventPoint::OverrideGrabPassive: executed 50 times by 2 tests: case QQuickEventPoint::OverrideGrabPassive:Executed by:
| 50 | ||||||||||||||||||
| 162 | return; // don't emit executed 50 times by 2 tests: return;Executed by:
| 50 | ||||||||||||||||||
| 163 | case QQuickEventPoint::UngrabPassive: never executed: case QQuickEventPoint::UngrabPassive: | 0 | ||||||||||||||||||
| 164 | case QQuickEventPoint::UngrabExclusive: executed 114 times by 4 tests: case QQuickEventPoint::UngrabExclusive:Executed by:
| 114 | ||||||||||||||||||
| 165 | case QQuickEventPoint::CancelGrabPassive: executed 26 times by 2 tests: case QQuickEventPoint::CancelGrabPassive:Executed by:
| 26 | ||||||||||||||||||
| 166 | case QQuickEventPoint::CancelGrabExclusive: executed 8 times by 1 test: case QQuickEventPoint::CancelGrabExclusive:Executed by:
| 8 | ||||||||||||||||||
| 167 | // the grab is lost or relinquished, so the point is no longer relevant | - | ||||||||||||||||||
| 168 | QQuickPointerHandler::onGrabChanged(grabber, stateChange, point); | - | ||||||||||||||||||
| 169 | reset(); | - | ||||||||||||||||||
| 170 | break; executed 148 times by 4 tests: break;Executed by:
| 148 | ||||||||||||||||||
| 171 | } | - | ||||||||||||||||||
| 172 | emit singlePointGrabChanged(); | - | ||||||||||||||||||
| 173 | } executed 448 times by 4 tests: end of blockExecuted by:
| 448 | ||||||||||||||||||
| 174 | - | |||||||||||||||||||
| 175 | void QQuickSinglePointHandler::setIgnoreAdditionalPoints(bool v) | - | ||||||||||||||||||
| 176 | { | - | ||||||||||||||||||
| 177 | m_ignoreAdditionalPoints = v; | - | ||||||||||||||||||
| 178 | } never executed: end of block | 0 | ||||||||||||||||||
| 179 | - | |||||||||||||||||||
| 180 | void QQuickSinglePointHandler::moveTarget(QPointF pos, QQuickEventPoint *point) | - | ||||||||||||||||||
| 181 | { | - | ||||||||||||||||||
| 182 | target()->setPosition(pos); | - | ||||||||||||||||||
| 183 | m_pointInfo.m_scenePosition = point->scenePosition(); | - | ||||||||||||||||||
| 184 | m_pointInfo.m_position = target()->mapFromScene(m_pointInfo.m_scenePosition); | - | ||||||||||||||||||
| 185 | } executed 372 times by 3 tests: end of blockExecuted by:
| 372 | ||||||||||||||||||
| 186 | - | |||||||||||||||||||
| 187 | void QQuickSinglePointHandler::setPointId(int id) | - | ||||||||||||||||||
| 188 | { | - | ||||||||||||||||||
| 189 | m_pointInfo.m_id = id; | - | ||||||||||||||||||
| 190 | } executed 452 times by 4 tests: end of blockExecuted by:
| 452 | ||||||||||||||||||
| 191 | - | |||||||||||||||||||
| 192 | void QQuickSinglePointHandler::reset() | - | ||||||||||||||||||
| 193 | { | - | ||||||||||||||||||
| 194 | setActive(false); | - | ||||||||||||||||||
| 195 | m_pointInfo.reset(); | - | ||||||||||||||||||
| 196 | } executed 348 times by 4 tests: end of blockExecuted by:
| 348 | ||||||||||||||||||
| 197 | - | |||||||||||||||||||
| 198 | /*! | - | ||||||||||||||||||
| 199 | \readonly | - | ||||||||||||||||||
| 200 | \qmlproperty HandlerPoint QtQuick::SinglePointHandler::point | - | ||||||||||||||||||
| 201 | - | |||||||||||||||||||
| 202 | The event point currently being handled. When no point is currently being | - | ||||||||||||||||||
| 203 | handled, this object is reset to default values (all coordinates are 0). | - | ||||||||||||||||||
| 204 | */ | - | ||||||||||||||||||
| 205 | - | |||||||||||||||||||
| 206 | QT_END_NAMESPACE | - | ||||||||||||||||||
| Source code | Switch to Preprocessed file |