| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/quick/handlers/qquickhandlerpoint.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 "qquickhandlerpoint_p.h" | - | ||||||
| 41 | #include "private/qquickevents_p_p.h" | - | ||||||
| 42 | - | |||||||
| 43 | QT_BEGIN_NAMESPACE | - | ||||||
| 44 | Q_DECLARE_LOGGING_CATEGORY(DBG_TOUCH_TARGET) | - | ||||||
| 45 | - | |||||||
| 46 | /*! | - | ||||||
| 47 | \qmltype HandlerPoint | - | ||||||
| 48 | \instantiates QQuickHandlerPoint | - | ||||||
| 49 | \inqmlmodule Qt.labs.handlers | - | ||||||
| 50 | \ingroup qtquick-handlers | - | ||||||
| 51 | \brief An event point. | - | ||||||
| 52 | - | |||||||
| 53 | A QML representation of a QQuickEventPoint. | - | ||||||
| 54 | - | |||||||
| 55 | It's possible to make bindings to properties of a \l SinglePointHandler's | - | ||||||
| 56 | current point. For example: | - | ||||||
| 57 | - | |||||||
| 58 | \snippet pointerHandlers/dragHandlerNullTarget.qml 0 | - | ||||||
| 59 | - | |||||||
| 60 | The point is kept up-to-date when the DragHandler is actively responding to | - | ||||||
| 61 | an EventPoint; but when the point is released, or the current point is | - | ||||||
| 62 | being handled by a different handler, \c position.x and \c position.y are 0. | - | ||||||
| 63 | - | |||||||
| 64 | \note This is practically identical to QtQuick::EventPoint; however an | - | ||||||
| 65 | EventPoint is a long-lived QObject which is invalidated between gestures | - | ||||||
| 66 | and reused for subsequent event deliveries. Continuous bindings to its | - | ||||||
| 67 | properties are not possible, and an individual handler cannot rely on it | - | ||||||
| 68 | outside the period when that point is part of an active gesture which that | - | ||||||
| 69 | handler is handling. HandlerPoint is a Q_GADGET that the handler owns. | - | ||||||
| 70 | This allows you to make lifetime bindings to its properties. | - | ||||||
| 71 | - | |||||||
| 72 | \sa SinglePointHandler::point | - | ||||||
| 73 | */ | - | ||||||
| 74 | - | |||||||
| 75 | QQuickHandlerPoint::QQuickHandlerPoint() | - | ||||||
| 76 | : m_id(0) | - | ||||||
| 77 | , m_rotation(0) | - | ||||||
| 78 | , m_pressure(0) | - | ||||||
| 79 | {} executed 3062 times by 5 tests: end of blockExecuted by:
| 3062 | ||||||
| 80 | - | |||||||
| 81 | void QQuickHandlerPoint::reset() | - | ||||||
| 82 | { | - | ||||||
| 83 | m_id = 0; | - | ||||||
| 84 | m_uniqueId = QPointingDeviceUniqueId(); | - | ||||||
| 85 | m_position = QPointF(); | - | ||||||
| 86 | m_scenePosition = QPointF(); | - | ||||||
| 87 | m_pressPosition = QPointF(); | - | ||||||
| 88 | m_scenePressPosition = QPointF(); | - | ||||||
| 89 | m_sceneGrabPosition = QPointF(); | - | ||||||
| 90 | m_velocity = QVector2D(); | - | ||||||
| 91 | m_rotation = 0; | - | ||||||
| 92 | m_pressure = 0; | - | ||||||
| 93 | m_ellipseDiameters = QSizeF(); | - | ||||||
| 94 | m_pressedButtons = Qt::NoButton; | - | ||||||
| 95 | m_pressedModifiers = Qt::NoModifier; | - | ||||||
| 96 | } executed 548 times by 4 tests: end of blockExecuted by:
| 548 | ||||||
| 97 | - | |||||||
| 98 | void QQuickHandlerPoint::reset(const QQuickEventPoint *point) | - | ||||||
| 99 | { | - | ||||||
| 100 | m_id = point->pointId(); | - | ||||||
| 101 | const QQuickPointerEvent *event = point->pointerEvent(); | - | ||||||
| 102 | switch (point->state()) { | - | ||||||
| 103 | case QQuickEventPoint::Pressed: executed 234 times by 4 tests: case QQuickEventPoint::Pressed:Executed by:
| 234 | ||||||
| 104 | m_pressPosition = point->position(); | - | ||||||
| 105 | m_scenePressPosition = point->scenePosition(); | - | ||||||
| 106 | m_pressedButtons = event->buttons(); | - | ||||||
| 107 | break; executed 234 times by 4 tests: break;Executed by:
| 234 | ||||||
| 108 | case QQuickEventPoint::Released: executed 200 times by 4 tests: case QQuickEventPoint::Released:Executed by:
| 200 | ||||||
| 109 | reset(); | - | ||||||
| 110 | return; executed 200 times by 4 tests: return;Executed by:
| 200 | ||||||
| 111 | default: executed 1278 times by 4 tests: default:Executed by:
| 1278 | ||||||
| 112 | m_pressedButtons = event->buttons(); | - | ||||||
| 113 | break; executed 1278 times by 4 tests: break;Executed by:
| 1278 | ||||||
| 114 | } | - | ||||||
| 115 | m_pressedModifiers = event->modifiers(); | - | ||||||
| 116 | if (event->asPointerTouchEvent()) {
| 192-1320 | ||||||
| 117 | const QQuickEventTouchPoint *tp = static_cast<const QQuickEventTouchPoint *>(point); | - | ||||||
| 118 | m_uniqueId = tp->uniqueId(); | - | ||||||
| 119 | m_rotation = tp->rotation(); | - | ||||||
| 120 | m_pressure = tp->pressure(); | - | ||||||
| 121 | m_ellipseDiameters = tp->ellipseDiameters(); | - | ||||||
| 122 | } else if (event->asPointerTabletEvent()) { executed 1320 times by 4 tests: end of blockExecuted by:
| 0-1320 | ||||||
| 123 | // TODO | - | ||||||
| 124 | } else { never executed: end of block | 0 | ||||||
| 125 | m_uniqueId = event->device()->uniqueId(); | - | ||||||
| 126 | m_rotation = 0; | - | ||||||
| 127 | m_pressure = event->buttons() ? 1 : 0;
| 0-192 | ||||||
| 128 | m_ellipseDiameters = QSizeF(); | - | ||||||
| 129 | } executed 192 times by 3 tests: end of blockExecuted by:
| 192 | ||||||
| 130 | m_position = point->position(); | - | ||||||
| 131 | m_scenePosition = point->scenePosition(); | - | ||||||
| 132 | if (point->state() == QQuickEventPoint::Updated)
| 246-1266 | ||||||
| 133 | m_velocity = point->velocity(); executed 1266 times by 4 tests: m_velocity = point->velocity();Executed by:
| 1266 | ||||||
| 134 | } executed 1512 times by 4 tests: end of blockExecuted by:
| 1512 | ||||||
| 135 | - | |||||||
| 136 | void QQuickHandlerPoint::reset(const QVector<QQuickEventPoint *> &points) | - | ||||||
| 137 | { | - | ||||||
| 138 | if (points.isEmpty()) {
| 0-31 | ||||||
| 139 | qWarning("reset: no points"); | - | ||||||
| 140 | return; never executed: return; | 0 | ||||||
| 141 | } | - | ||||||
| 142 | if (points.count() == 1) {
| 0-31 | ||||||
| 143 | reset(points.first()); | - | ||||||
| 144 | return; never executed: return; | 0 | ||||||
| 145 | } | - | ||||||
| 146 | // all points are required to be from the same event | - | ||||||
| 147 | const QQuickPointerEvent *event = points.first()->pointerEvent(); | - | ||||||
| 148 | QPointF posSum; | - | ||||||
| 149 | QPointF scenePosSum; | - | ||||||
| 150 | QVector2D velocitySum; | - | ||||||
| 151 | qreal pressureSum = 0; | - | ||||||
| 152 | QSizeF ellipseDiameterSum; | - | ||||||
| 153 | bool press = false; | - | ||||||
| 154 | const QQuickPointerTouchEvent *touchEvent = event->asPointerTouchEvent(); | - | ||||||
| 155 | for (const QQuickEventPoint *point : qAsConst(points)) { | - | ||||||
| 156 | posSum += point->position(); | - | ||||||
| 157 | scenePosSum += point->scenePosition(); | - | ||||||
| 158 | velocitySum += point->velocity(); | - | ||||||
| 159 | if (touchEvent) {
| 0-93 | ||||||
| 160 | pressureSum += static_cast<const QQuickEventTouchPoint *>(point)->pressure(); | - | ||||||
| 161 | ellipseDiameterSum += static_cast<const QQuickEventTouchPoint *>(point)->ellipseDiameters(); | - | ||||||
| 162 | } executed 93 times by 1 test: end of blockExecuted by:
| 93 | ||||||
| 163 | if (point->state() == QQuickEventPoint::Pressed)
| 2-91 | ||||||
| 164 | press = true; executed 2 times by 1 test: press = true;Executed by:
| 2 | ||||||
| 165 | } executed 93 times by 1 test: end of blockExecuted by:
| 93 | ||||||
| 166 | m_id = 0; | - | ||||||
| 167 | m_uniqueId = QPointingDeviceUniqueId(); | - | ||||||
| 168 | m_pressedButtons = event->buttons(); | - | ||||||
| 169 | m_pressedModifiers = event->modifiers(); | - | ||||||
| 170 | m_position = posSum / points.size(); | - | ||||||
| 171 | m_scenePosition = scenePosSum / points.size(); | - | ||||||
| 172 | if (press) {
| 2-29 | ||||||
| 173 | m_pressPosition = m_position; | - | ||||||
| 174 | m_scenePressPosition = m_scenePosition; | - | ||||||
| 175 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||
| 176 | m_velocity = velocitySum / points.size(); | - | ||||||
| 177 | m_rotation = 0; // averaging the rotations of all the points isn't very sensible | - | ||||||
| 178 | m_pressure = pressureSum / points.size(); | - | ||||||
| 179 | m_ellipseDiameters = ellipseDiameterSum / points.size(); | - | ||||||
| 180 | } executed 31 times by 1 test: end of blockExecuted by:
| 31 | ||||||
| 181 | - | |||||||
| 182 | /*! | - | ||||||
| 183 | \readonly | - | ||||||
| 184 | \qmlproperty int QtQuick::HandlerPoint::id | - | ||||||
| 185 | \brief The ID number of the point | - | ||||||
| 186 | - | |||||||
| 187 | During a touch gesture, from the time that the first finger is pressed | - | ||||||
| 188 | until the last finger is released, each touchpoint will have a unique ID | - | ||||||
| 189 | number. Likewise, if input from multiple devices occurs (for example | - | ||||||
| 190 | simultaneous mouse and touch presses), all the current event points from | - | ||||||
| 191 | all the devices will have unique IDs. | - | ||||||
| 192 | - | |||||||
| 193 | \note Do not assume that id numbers start at zero or that they are | - | ||||||
| 194 | sequential. Such an assumption is often false due to the way the underlying | - | ||||||
| 195 | drivers work. | - | ||||||
| 196 | - | |||||||
| 197 | \sa QTouchEvent::TouchPoint::id | - | ||||||
| 198 | */ | - | ||||||
| 199 | - | |||||||
| 200 | /*! | - | ||||||
| 201 | \readonly | - | ||||||
| 202 | \qmlproperty PointingDeviceUniqueId QtQuick::HandlerPoint::uniqueId | - | ||||||
| 203 | \brief The unique ID of the point, if any | - | ||||||
| 204 | - | |||||||
| 205 | This is normally empty, because touchscreens cannot uniquely identify fingers. | - | ||||||
| 206 | - | |||||||
| 207 | On some types of touchscreens, especially those using TUIO drivers, | - | ||||||
| 208 | it's possible to use recognizable physical tokens (fiducial objects) | - | ||||||
| 209 | in addition to fingers. So if this point is a touch point, and | - | ||||||
| 210 | uniqueId is set, it is the identifier for such an object. | - | ||||||
| 211 | - | |||||||
| 212 | On a graphics tablet, each type of stylus or other tool often has a unique | - | ||||||
| 213 | ID or serial number, which can be useful to respond in different ways to | - | ||||||
| 214 | different tools. | - | ||||||
| 215 | - | |||||||
| 216 | Interpreting the contents of this ID requires knowledge of the hardware and | - | ||||||
| 217 | drivers in use. | - | ||||||
| 218 | - | |||||||
| 219 | \sa QTabletEvent::uniqueId, QtQuick::TouchPoint::uniqueId, QtQuick::EventTouchPoint::uniqueId | - | ||||||
| 220 | */ | - | ||||||
| 221 | - | |||||||
| 222 | /*! | - | ||||||
| 223 | \readonly | - | ||||||
| 224 | \qmlproperty QPointF QtQuick::HandlerPoint::position | - | ||||||
| 225 | \brief The position within the \c parent Item | - | ||||||
| 226 | - | |||||||
| 227 | This is the position of the event point relative to the bounds of | - | ||||||
| 228 | the \l {PointerHandler::parent} {parent}. | - | ||||||
| 229 | */ | - | ||||||
| 230 | - | |||||||
| 231 | /*! | - | ||||||
| 232 | \readonly | - | ||||||
| 233 | \qmlproperty QPointF QtQuick::HandlerPoint::scenePosition | - | ||||||
| 234 | \brief The position within the scene | - | ||||||
| 235 | - | |||||||
| 236 | This is the position of the event point relative to the bounds of the Qt | - | ||||||
| 237 | Quick scene (typically the whole window). | - | ||||||
| 238 | */ | - | ||||||
| 239 | - | |||||||
| 240 | /*! | - | ||||||
| 241 | \readonly | - | ||||||
| 242 | \qmlproperty QPointF QtQuick::HandlerPoint::pressPosition | - | ||||||
| 243 | \brief The pressed position within the \c parent Item | - | ||||||
| 244 | - | |||||||
| 245 | This is the position at which this point was pressed, relative to the | - | ||||||
| 246 | bounds of the \l {PointerHandler::parent} {parent}. | - | ||||||
| 247 | */ | - | ||||||
| 248 | - | |||||||
| 249 | /*! | - | ||||||
| 250 | \readonly | - | ||||||
| 251 | \qmlproperty QPointF QtQuick::HandlerPoint::scenePressPosition | - | ||||||
| 252 | \brief The pressed position within the scene | - | ||||||
| 253 | - | |||||||
| 254 | This is the position at which this point was pressed, in the coordinate | - | ||||||
| 255 | system of the \l {Qt Quick Scene Graph}{scene graph}. | - | ||||||
| 256 | */ | - | ||||||
| 257 | - | |||||||
| 258 | /*! | - | ||||||
| 259 | \readonly | - | ||||||
| 260 | \qmlproperty QPointF QtQuick::HandlerPoint::sceneGrabPosition | - | ||||||
| 261 | \brief The grabbed position within the scene | - | ||||||
| 262 | - | |||||||
| 263 | If this point has been grabbed by a Pointer Handler or an Item, it means | - | ||||||
| 264 | that object has taken sole responsibility for handling the movement and the | - | ||||||
| 265 | release if this point. In that case, this is the position at which the grab | - | ||||||
| 266 | occurred, in the coordinate system of the \l {Qt Quick Scene Graph}{scene graph}. | - | ||||||
| 267 | */ | - | ||||||
| 268 | - | |||||||
| 269 | /*! | - | ||||||
| 270 | \readonly | - | ||||||
| 271 | \qmlproperty enum QtQuick::HandlerPoint::pressedButtons | - | ||||||
| 272 | \brief Which mouse or stylus buttons are currently pressed | - | ||||||
| 273 | - | |||||||
| 274 | \sa MouseArea::pressedButtons | - | ||||||
| 275 | */ | - | ||||||
| 276 | - | |||||||
| 277 | /*! | - | ||||||
| 278 | \readonly | - | ||||||
| 279 | \qmlproperty enum QtQuick::HandlerPoint::modifiers | - | ||||||
| 280 | \brief Which modifier keys are currently pressed | - | ||||||
| 281 | - | |||||||
| 282 | This property holds the keyboard modifiers that were pressed at the time | - | ||||||
| 283 | the event occurred. | - | ||||||
| 284 | - | |||||||
| 285 | \sa MouseArea::modifiers | - | ||||||
| 286 | */ | - | ||||||
| 287 | - | |||||||
| 288 | /*! | - | ||||||
| 289 | \readonly | - | ||||||
| 290 | \qmlproperty QVector2D QtQuick::HandlerPoint::velocity | - | ||||||
| 291 | \brief A vector representing the average speed and direction of movement | - | ||||||
| 292 | - | |||||||
| 293 | This is a velocity vector pointing in the direction of movement, in logical | - | ||||||
| 294 | pixels per second. It has x and y components, at least one of which will be | - | ||||||
| 295 | nonzero when this point is in motion. It holds the average recent velocity: | - | ||||||
| 296 | how fast and in which direction the event point has been moving recently. | - | ||||||
| 297 | - | |||||||
| 298 | \sa QtQuick::EventPoint::velocity, QtQuick::TouchPoint::velocity, QTouchEvent::TouchPoint::velocity | - | ||||||
| 299 | */ | - | ||||||
| 300 | - | |||||||
| 301 | /*! | - | ||||||
| 302 | \readonly | - | ||||||
| 303 | \qmlproperty qreal QtQuick::HandlerPoint::rotation | - | ||||||
| 304 | - | |||||||
| 305 | This property holds the rotation angle of the stylus on a graphics tablet | - | ||||||
| 306 | or the contact patch of a touchpoint on a touchscreen. | - | ||||||
| 307 | - | |||||||
| 308 | It is valid only with certain tablet stylus devices and touchscreens that | - | ||||||
| 309 | can measure the rotation angle. Otherwise, it will be zero. | - | ||||||
| 310 | */ | - | ||||||
| 311 | - | |||||||
| 312 | /*! | - | ||||||
| 313 | \readonly | - | ||||||
| 314 | \qmlproperty qreal QtQuick::HandlerPoint::pressure | - | ||||||
| 315 | - | |||||||
| 316 | This property tells how hard the user is pressing the stylus on a graphics | - | ||||||
| 317 | tablet or the finger against a touchscreen, in the range from \c 0 (no | - | ||||||
| 318 | measurable pressure) to \c 1.0 (maximum pressure which the device can | - | ||||||
| 319 | measure). | - | ||||||
| 320 | - | |||||||
| 321 | It is valid only with certain tablets and touchscreens that can measure | - | ||||||
| 322 | pressure. Otherwise, it will be zero. | - | ||||||
| 323 | */ | - | ||||||
| 324 | - | |||||||
| 325 | /*! | - | ||||||
| 326 | \readonly | - | ||||||
| 327 | \qmlproperty size QtQuick::HandlerPoint::ellipseDiameters | - | ||||||
| 328 | - | |||||||
| 329 | This property holds the diameters of the contact patch, if the event | - | ||||||
| 330 | comes from a touchpoint and the device provides this information. | - | ||||||
| 331 | - | |||||||
| 332 | A touchpoint is modeled as an elliptical area where the finger is pressed | - | ||||||
| 333 | against the touchscreen. (In fact, it could also be modeled as a bitmap; | - | ||||||
| 334 | but in that case we expect an elliptical bounding estimate to be fitted to | - | ||||||
| 335 | the contact patch before the event is sent.) The harder the user presses, | - | ||||||
| 336 | the larger the contact patch; so, these diameters provide an alternate way | - | ||||||
| 337 | of detecting pressure, in case the device does not include a separate | - | ||||||
| 338 | pressure sensor. The ellipse is centered on \l scenePosition (\l position | - | ||||||
| 339 | in the PointerHandler's Item's local coordinates). The \l rotation property | - | ||||||
| 340 | provides the rotation of the ellipse, if known. It is expected that if the | - | ||||||
| 341 | \l rotation is zero, the \l {QSize::height}{height} is the larger dimension | - | ||||||
| 342 | (the major axis), because of the usual hand position, reaching upward or | - | ||||||
| 343 | outward across the surface. | - | ||||||
| 344 | - | |||||||
| 345 | If the contact patch is unknown, or the device is not a touchscreen, | - | ||||||
| 346 | these values will be zero. | - | ||||||
| 347 | - | |||||||
| 348 | \sa QtQuick::EventTouchPoint::ellipseDiameters, QtQuick::TouchPoint::ellipseDiameters, QTouchEvent::TouchPoint::ellipseDiameters | - | ||||||
| 349 | */ | - | ||||||
| 350 | - | |||||||
| 351 | QT_END_NAMESPACE | - | ||||||
| Source code | Switch to Preprocessed file |