| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/quick/items/qquickpincharea.cpp |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /**************************************************************************** | - | ||||||||||||||||||
| 2 | ** | - | ||||||||||||||||||
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. | - | ||||||||||||||||||
| 4 | ** Contact: https://www.qt.io/licensing/ | - | ||||||||||||||||||
| 5 | ** | - | ||||||||||||||||||
| 6 | ** This file is part of the QtSG 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 "qquickpincharea_p_p.h" | - | ||||||||||||||||||
| 41 | #include "qquickwindow.h" | - | ||||||||||||||||||
| 42 | - | |||||||||||||||||||
| 43 | #include <QtCore/qmath.h> | - | ||||||||||||||||||
| 44 | #include <QtGui/qevent.h> | - | ||||||||||||||||||
| 45 | #include <QtGui/qguiapplication.h> | - | ||||||||||||||||||
| 46 | #include <QtGui/qstylehints.h> | - | ||||||||||||||||||
| 47 | #include <qpa/qplatformintegration.h> | - | ||||||||||||||||||
| 48 | #include <qpa/qplatformnativeinterface.h> | - | ||||||||||||||||||
| 49 | #include <private/qguiapplication_p.h> | - | ||||||||||||||||||
| 50 | #include <QVariant> | - | ||||||||||||||||||
| 51 | - | |||||||||||||||||||
| 52 | #include <float.h> | - | ||||||||||||||||||
| 53 | - | |||||||||||||||||||
| 54 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||
| 55 | - | |||||||||||||||||||
| 56 | /*! | - | ||||||||||||||||||
| 57 | \qmltype PinchEvent | - | ||||||||||||||||||
| 58 | \instantiates QQuickPinchEvent | - | ||||||||||||||||||
| 59 | \inqmlmodule QtQuick | - | ||||||||||||||||||
| 60 | \ingroup qtquick-input-events | - | ||||||||||||||||||
| 61 | \brief For specifying information about a pinch event. | - | ||||||||||||||||||
| 62 | - | |||||||||||||||||||
| 63 | \b {The PinchEvent type was added in QtQuick 1.1} | - | ||||||||||||||||||
| 64 | - | |||||||||||||||||||
| 65 | The \c center, \c startCenter, \c previousCenter properties provide the center position between the two touch points. | - | ||||||||||||||||||
| 66 | - | |||||||||||||||||||
| 67 | The \c scale and \c previousScale properties provide the scale factor. | - | ||||||||||||||||||
| 68 | - | |||||||||||||||||||
| 69 | The \c angle, \c previousAngle and \c rotation properties provide the angle between the two points and the amount of rotation. | - | ||||||||||||||||||
| 70 | - | |||||||||||||||||||
| 71 | The \c point1, \c point2, \c startPoint1, \c startPoint2 properties provide the positions of the touch points. | - | ||||||||||||||||||
| 72 | - | |||||||||||||||||||
| 73 | The \c accepted property may be set to false in the \c onPinchStarted handler if the gesture should not | - | ||||||||||||||||||
| 74 | be handled. | - | ||||||||||||||||||
| 75 | - | |||||||||||||||||||
| 76 | \sa PinchArea | - | ||||||||||||||||||
| 77 | */ | - | ||||||||||||||||||
| 78 | - | |||||||||||||||||||
| 79 | /*! | - | ||||||||||||||||||
| 80 | \qmlproperty QPointF QtQuick::PinchEvent::center | - | ||||||||||||||||||
| 81 | \qmlproperty QPointF QtQuick::PinchEvent::startCenter | - | ||||||||||||||||||
| 82 | \qmlproperty QPointF QtQuick::PinchEvent::previousCenter | - | ||||||||||||||||||
| 83 | - | |||||||||||||||||||
| 84 | These properties hold the position of the center point between the two touch points. | - | ||||||||||||||||||
| 85 | - | |||||||||||||||||||
| 86 | \list | - | ||||||||||||||||||
| 87 | \li \c center is the current center point | - | ||||||||||||||||||
| 88 | \li \c previousCenter is the center point of the previous event. | - | ||||||||||||||||||
| 89 | \li \c startCenter is the center point when the gesture began | - | ||||||||||||||||||
| 90 | \endlist | - | ||||||||||||||||||
| 91 | */ | - | ||||||||||||||||||
| 92 | - | |||||||||||||||||||
| 93 | /*! | - | ||||||||||||||||||
| 94 | \qmlproperty real QtQuick::PinchEvent::scale | - | ||||||||||||||||||
| 95 | \qmlproperty real QtQuick::PinchEvent::previousScale | - | ||||||||||||||||||
| 96 | - | |||||||||||||||||||
| 97 | These properties hold the scale factor determined by the change in distance between the two touch points. | - | ||||||||||||||||||
| 98 | - | |||||||||||||||||||
| 99 | \list | - | ||||||||||||||||||
| 100 | \li \c scale is the current scale factor. | - | ||||||||||||||||||
| 101 | \li \c previousScale is the scale factor of the previous event. | - | ||||||||||||||||||
| 102 | \endlist | - | ||||||||||||||||||
| 103 | - | |||||||||||||||||||
| 104 | When a pinch gesture is started, the scale is \c 1.0. | - | ||||||||||||||||||
| 105 | */ | - | ||||||||||||||||||
| 106 | - | |||||||||||||||||||
| 107 | /*! | - | ||||||||||||||||||
| 108 | \qmlproperty real QtQuick::PinchEvent::angle | - | ||||||||||||||||||
| 109 | \qmlproperty real QtQuick::PinchEvent::previousAngle | - | ||||||||||||||||||
| 110 | \qmlproperty real QtQuick::PinchEvent::rotation | - | ||||||||||||||||||
| 111 | - | |||||||||||||||||||
| 112 | These properties hold the angle between the two touch points. | - | ||||||||||||||||||
| 113 | - | |||||||||||||||||||
| 114 | \list | - | ||||||||||||||||||
| 115 | \li \c angle is the current angle between the two points in the range -180 to 180. | - | ||||||||||||||||||
| 116 | \li \c previousAngle is the angle of the previous event. | - | ||||||||||||||||||
| 117 | \li \c rotation is the total rotation since the pinch gesture started. | - | ||||||||||||||||||
| 118 | \endlist | - | ||||||||||||||||||
| 119 | - | |||||||||||||||||||
| 120 | When a pinch gesture is started, the rotation is \c 0.0. | - | ||||||||||||||||||
| 121 | */ | - | ||||||||||||||||||
| 122 | - | |||||||||||||||||||
| 123 | /*! | - | ||||||||||||||||||
| 124 | \qmlproperty QPointF QtQuick::PinchEvent::point1 | - | ||||||||||||||||||
| 125 | \qmlproperty QPointF QtQuick::PinchEvent::startPoint1 | - | ||||||||||||||||||
| 126 | \qmlproperty QPointF QtQuick::PinchEvent::point2 | - | ||||||||||||||||||
| 127 | \qmlproperty QPointF QtQuick::PinchEvent::startPoint2 | - | ||||||||||||||||||
| 128 | - | |||||||||||||||||||
| 129 | These properties provide the actual touch points generating the pinch. | - | ||||||||||||||||||
| 130 | - | |||||||||||||||||||
| 131 | \list | - | ||||||||||||||||||
| 132 | \li \c point1 and \c point2 hold the current positions of the points. | - | ||||||||||||||||||
| 133 | \li \c startPoint1 and \c startPoint2 hold the positions of the points when the second point was touched. | - | ||||||||||||||||||
| 134 | \endlist | - | ||||||||||||||||||
| 135 | */ | - | ||||||||||||||||||
| 136 | - | |||||||||||||||||||
| 137 | /*! | - | ||||||||||||||||||
| 138 | \qmlproperty bool QtQuick::PinchEvent::accepted | - | ||||||||||||||||||
| 139 | - | |||||||||||||||||||
| 140 | Setting this property to false in the \c PinchArea::onPinchStarted handler | - | ||||||||||||||||||
| 141 | will result in no further pinch events being generated, and the gesture | - | ||||||||||||||||||
| 142 | ignored. | - | ||||||||||||||||||
| 143 | */ | - | ||||||||||||||||||
| 144 | - | |||||||||||||||||||
| 145 | /*! | - | ||||||||||||||||||
| 146 | \qmlproperty int QtQuick::PinchEvent::pointCount | - | ||||||||||||||||||
| 147 | - | |||||||||||||||||||
| 148 | Holds the number of points currently touched. The PinchArea will not react | - | ||||||||||||||||||
| 149 | until two touch points have initited a gesture, but will remain active until | - | ||||||||||||||||||
| 150 | all touch points have been released. | - | ||||||||||||||||||
| 151 | */ | - | ||||||||||||||||||
| 152 | - | |||||||||||||||||||
| 153 | QQuickPinch::QQuickPinch() | - | ||||||||||||||||||
| 154 | : m_target(nullptr), m_minScale(1.0), m_maxScale(1.0) | - | ||||||||||||||||||
| 155 | , m_minRotation(0.0), m_maxRotation(0.0) | - | ||||||||||||||||||
| 156 | , m_axis(NoDrag), m_xmin(-FLT_MAX), m_xmax(FLT_MAX) | - | ||||||||||||||||||
| 157 | , m_ymin(-FLT_MAX), m_ymax(FLT_MAX), m_active(false) | - | ||||||||||||||||||
| 158 | { | - | ||||||||||||||||||
| 159 | } executed 30 times by 2 tests: end of blockExecuted by:
| 30 | ||||||||||||||||||
| 160 | - | |||||||||||||||||||
| 161 | QQuickPinchAreaPrivate::~QQuickPinchAreaPrivate() | - | ||||||||||||||||||
| 162 | { | - | ||||||||||||||||||
| 163 | delete pinch; | - | ||||||||||||||||||
| 164 | } executed 32 times by 3 tests: end of blockExecuted by:
| 32 | ||||||||||||||||||
| 165 | - | |||||||||||||||||||
| 166 | /*! | - | ||||||||||||||||||
| 167 | \qmltype PinchArea | - | ||||||||||||||||||
| 168 | \instantiates QQuickPinchArea | - | ||||||||||||||||||
| 169 | \inqmlmodule QtQuick | - | ||||||||||||||||||
| 170 | \ingroup qtquick-input | - | ||||||||||||||||||
| 171 | \inherits Item | - | ||||||||||||||||||
| 172 | \brief Enables simple pinch gesture handling. | - | ||||||||||||||||||
| 173 | - | |||||||||||||||||||
| 174 | \b {The PinchArea type was added in QtQuick 1.1} | - | ||||||||||||||||||
| 175 | - | |||||||||||||||||||
| 176 | A PinchArea is an invisible item that is typically used in conjunction with | - | ||||||||||||||||||
| 177 | a visible item in order to provide pinch gesture handling for that item. | - | ||||||||||||||||||
| 178 | - | |||||||||||||||||||
| 179 | The \l enabled property is used to enable and disable pinch handling for | - | ||||||||||||||||||
| 180 | the proxied item. When disabled, the pinch area becomes transparent to | - | ||||||||||||||||||
| 181 | mouse/touch events. | - | ||||||||||||||||||
| 182 | - | |||||||||||||||||||
| 183 | PinchArea can be used in two ways: | - | ||||||||||||||||||
| 184 | - | |||||||||||||||||||
| 185 | \list | - | ||||||||||||||||||
| 186 | \li setting a \c pinch.target to provide automatic interaction with an item | - | ||||||||||||||||||
| 187 | \li using the onPinchStarted, onPinchUpdated and onPinchFinished handlers | - | ||||||||||||||||||
| 188 | \endlist | - | ||||||||||||||||||
| 189 | - | |||||||||||||||||||
| 190 | Since Qt 5.5, PinchArea can react to native pinch gesture events from the | - | ||||||||||||||||||
| 191 | operating system if available; otherwise it reacts only to touch events. | - | ||||||||||||||||||
| 192 | - | |||||||||||||||||||
| 193 | \sa PinchEvent, QNativeGestureEvent, QTouchEvent | - | ||||||||||||||||||
| 194 | */ | - | ||||||||||||||||||
| 195 | - | |||||||||||||||||||
| 196 | /*! | - | ||||||||||||||||||
| 197 | \qmlsignal QtQuick::PinchArea::pinchStarted() | - | ||||||||||||||||||
| 198 | - | |||||||||||||||||||
| 199 | This signal is emitted when the pinch area detects that a pinch gesture has | - | ||||||||||||||||||
| 200 | started: two touch points (fingers) have been detected, and they have moved | - | ||||||||||||||||||
| 201 | beyond the \l {QStyleHints}{startDragDistance} threshold for the gesture to begin. | - | ||||||||||||||||||
| 202 | - | |||||||||||||||||||
| 203 | The \l {PinchEvent}{pinch} parameter (not the same as the \l {PinchArea}{pinch} | - | ||||||||||||||||||
| 204 | property) provides information about the pinch gesture, including the scale, | - | ||||||||||||||||||
| 205 | center and angle of the pinch. At the time of the \c pinchStarted signal, | - | ||||||||||||||||||
| 206 | these values are reset to the default values, regardless of the results | - | ||||||||||||||||||
| 207 | from previous gestures: pinch.scale will be \c 1.0 and pinch.rotation will be \c 0.0. | - | ||||||||||||||||||
| 208 | As the gesture progresses, \l pinchUpdated will report the deviation from those | - | ||||||||||||||||||
| 209 | defaults. | - | ||||||||||||||||||
| 210 | - | |||||||||||||||||||
| 211 | To ignore this gesture set the \c pinch.accepted property to false. The gesture | - | ||||||||||||||||||
| 212 | will be canceled and no further events will be sent. | - | ||||||||||||||||||
| 213 | - | |||||||||||||||||||
| 214 | The corresponding handler is \c onPinchStarted. | - | ||||||||||||||||||
| 215 | */ | - | ||||||||||||||||||
| 216 | - | |||||||||||||||||||
| 217 | /*! | - | ||||||||||||||||||
| 218 | \qmlsignal QtQuick::PinchArea::pinchUpdated() | - | ||||||||||||||||||
| 219 | - | |||||||||||||||||||
| 220 | This signal is emitted when the pinch area detects that a pinch gesture has changed. | - | ||||||||||||||||||
| 221 | - | |||||||||||||||||||
| 222 | The \l {PinchEvent}{pinch} parameter provides information about the pinch | - | ||||||||||||||||||
| 223 | gesture, including the scale, center and angle of the pinch. These values | - | ||||||||||||||||||
| 224 | reflect changes only since the beginning of the current gesture, and | - | ||||||||||||||||||
| 225 | therefore are not limited by the minimum and maximum limits in the | - | ||||||||||||||||||
| 226 | \l {PinchArea}{pinch} property. | - | ||||||||||||||||||
| 227 | - | |||||||||||||||||||
| 228 | The corresponding handler is \c onPinchUpdated. | - | ||||||||||||||||||
| 229 | */ | - | ||||||||||||||||||
| 230 | - | |||||||||||||||||||
| 231 | /*! | - | ||||||||||||||||||
| 232 | \qmlsignal QtQuick::PinchArea::pinchFinished() | - | ||||||||||||||||||
| 233 | - | |||||||||||||||||||
| 234 | This signal is emitted when the pinch area detects that a pinch gesture has finished. | - | ||||||||||||||||||
| 235 | - | |||||||||||||||||||
| 236 | The \l {PinchEvent}{pinch} parameter (not the same as the \l {PinchArea}{pinch} | - | ||||||||||||||||||
| 237 | property) provides information about the pinch gesture, including the | - | ||||||||||||||||||
| 238 | scale, center and angle of the pinch. | - | ||||||||||||||||||
| 239 | - | |||||||||||||||||||
| 240 | The corresponding handler is \c onPinchFinished. | - | ||||||||||||||||||
| 241 | */ | - | ||||||||||||||||||
| 242 | - | |||||||||||||||||||
| 243 | /*! | - | ||||||||||||||||||
| 244 | \qmlsignal QtQuick::PinchArea::smartZoom() | - | ||||||||||||||||||
| 245 | \since 5.5 | - | ||||||||||||||||||
| 246 | - | |||||||||||||||||||
| 247 | This signal is emitted when the pinch area detects the smart zoom gesture. | - | ||||||||||||||||||
| 248 | This gesture occurs only on certain operating systems such as \macos. | - | ||||||||||||||||||
| 249 | - | |||||||||||||||||||
| 250 | The \l {PinchEvent}{pinch} parameter provides information about the pinch | - | ||||||||||||||||||
| 251 | gesture, including the location where the gesture occurred. \c pinch.scale | - | ||||||||||||||||||
| 252 | will be greater than zero when the gesture indicates that the user wishes to | - | ||||||||||||||||||
| 253 | enter smart zoom, and zero when exiting (even though typically the same gesture | - | ||||||||||||||||||
| 254 | is used to toggle between the two states). | - | ||||||||||||||||||
| 255 | - | |||||||||||||||||||
| 256 | The corresponding handler is \c onSmartZoom. | - | ||||||||||||||||||
| 257 | */ | - | ||||||||||||||||||
| 258 | - | |||||||||||||||||||
| 259 | - | |||||||||||||||||||
| 260 | /*! | - | ||||||||||||||||||
| 261 | \qmlpropertygroup QtQuick::PinchArea::pinch | - | ||||||||||||||||||
| 262 | \qmlproperty Item QtQuick::PinchArea::pinch.target | - | ||||||||||||||||||
| 263 | \qmlproperty bool QtQuick::PinchArea::pinch.active | - | ||||||||||||||||||
| 264 | \qmlproperty real QtQuick::PinchArea::pinch.minimumScale | - | ||||||||||||||||||
| 265 | \qmlproperty real QtQuick::PinchArea::pinch.maximumScale | - | ||||||||||||||||||
| 266 | \qmlproperty real QtQuick::PinchArea::pinch.minimumRotation | - | ||||||||||||||||||
| 267 | \qmlproperty real QtQuick::PinchArea::pinch.maximumRotation | - | ||||||||||||||||||
| 268 | \qmlproperty enumeration QtQuick::PinchArea::pinch.dragAxis | - | ||||||||||||||||||
| 269 | \qmlproperty real QtQuick::PinchArea::pinch.minimumX | - | ||||||||||||||||||
| 270 | \qmlproperty real QtQuick::PinchArea::pinch.maximumX | - | ||||||||||||||||||
| 271 | \qmlproperty real QtQuick::PinchArea::pinch.minimumY | - | ||||||||||||||||||
| 272 | \qmlproperty real QtQuick::PinchArea::pinch.maximumY | - | ||||||||||||||||||
| 273 | - | |||||||||||||||||||
| 274 | \c pinch provides a convenient way to make an item react to pinch gestures. | - | ||||||||||||||||||
| 275 | - | |||||||||||||||||||
| 276 | \list | - | ||||||||||||||||||
| 277 | \li \c pinch.target specifies the id of the item to drag. | - | ||||||||||||||||||
| 278 | \li \c pinch.active specifies if the target item is currently being dragged. | - | ||||||||||||||||||
| 279 | \li \c pinch.minimumScale and \c pinch.maximumScale limit the range of the Item.scale property, but not the \c PinchEvent \l {PinchEvent}{scale} property. | - | ||||||||||||||||||
| 280 | \li \c pinch.minimumRotation and \c pinch.maximumRotation limit the range of the Item.rotation property, but not the \c PinchEvent \l {PinchEvent}{rotation} property. | - | ||||||||||||||||||
| 281 | \li \c pinch.dragAxis specifies whether dragging in not allowed (\c Pinch.NoDrag), can be done horizontally (\c Pinch.XAxis), vertically (\c Pinch.YAxis), or both (\c Pinch.XAndYAxis) | - | ||||||||||||||||||
| 282 | \li \c pinch.minimum and \c pinch.maximum limit how far the target can be dragged along the corresponding axes. | - | ||||||||||||||||||
| 283 | \endlist | - | ||||||||||||||||||
| 284 | */ | - | ||||||||||||||||||
| 285 | - | |||||||||||||||||||
| 286 | QQuickPinchArea::QQuickPinchArea(QQuickItem *parent) | - | ||||||||||||||||||
| 287 | : QQuickItem(*(new QQuickPinchAreaPrivate), parent) | - | ||||||||||||||||||
| 288 | { | - | ||||||||||||||||||
| 289 | Q_D(QQuickPinchArea); | - | ||||||||||||||||||
| 290 | d->init(); | - | ||||||||||||||||||
| 291 | setAcceptTouchEvents(true); | - | ||||||||||||||||||
| 292 | #ifdef Q_OS_OSX | - | ||||||||||||||||||
| 293 | setAcceptHoverEvents(true); // needed to enable touch events on mouse hover. | - | ||||||||||||||||||
| 294 | #endif | - | ||||||||||||||||||
| 295 | } executed 32 times by 3 tests: end of blockExecuted by:
| 32 | ||||||||||||||||||
| 296 | - | |||||||||||||||||||
| 297 | QQuickPinchArea::~QQuickPinchArea() | - | ||||||||||||||||||
| 298 | { | - | ||||||||||||||||||
| 299 | } | - | ||||||||||||||||||
| 300 | /*! | - | ||||||||||||||||||
| 301 | \qmlproperty bool QtQuick::PinchArea::enabled | - | ||||||||||||||||||
| 302 | This property holds whether the item accepts pinch gestures. | - | ||||||||||||||||||
| 303 | - | |||||||||||||||||||
| 304 | This property defaults to true. | - | ||||||||||||||||||
| 305 | */ | - | ||||||||||||||||||
| 306 | bool QQuickPinchArea::isEnabled() const | - | ||||||||||||||||||
| 307 | { | - | ||||||||||||||||||
| 308 | Q_D(const QQuickPinchArea); | - | ||||||||||||||||||
| 309 | return d->enabled; never executed: return d->enabled; | 0 | ||||||||||||||||||
| 310 | } | - | ||||||||||||||||||
| 311 | - | |||||||||||||||||||
| 312 | void QQuickPinchArea::setEnabled(bool a) | - | ||||||||||||||||||
| 313 | { | - | ||||||||||||||||||
| 314 | Q_D(QQuickPinchArea); | - | ||||||||||||||||||
| 315 | if (a != d->enabled) {
| 0 | ||||||||||||||||||
| 316 | d->enabled = a; | - | ||||||||||||||||||
| 317 | emit enabledChanged(); | - | ||||||||||||||||||
| 318 | } never executed: end of block | 0 | ||||||||||||||||||
| 319 | } never executed: end of block | 0 | ||||||||||||||||||
| 320 | - | |||||||||||||||||||
| 321 | void QQuickPinchArea::touchEvent(QTouchEvent *event) | - | ||||||||||||||||||
| 322 | { | - | ||||||||||||||||||
| 323 | Q_D(QQuickPinchArea); | - | ||||||||||||||||||
| 324 | if (!d->enabled || !isVisible()) {
| 0-88 | ||||||||||||||||||
| 325 | QQuickItem::touchEvent(event); | - | ||||||||||||||||||
| 326 | return; never executed: return; | 0 | ||||||||||||||||||
| 327 | } | - | ||||||||||||||||||
| 328 | - | |||||||||||||||||||
| 329 | // A common non-trivial starting scenario is the user puts down one finger, | - | ||||||||||||||||||
| 330 | // then that finger remains stationary while putting down a second one. | - | ||||||||||||||||||
| 331 | // However QQuickWindow will not send TouchUpdates for TouchPoints which | - | ||||||||||||||||||
| 332 | // were not initially accepted; that would be inefficient and noisy. | - | ||||||||||||||||||
| 333 | // So even if there is only one touchpoint so far, it's important to accept it | - | ||||||||||||||||||
| 334 | // in order to get updates later on (and it's accepted by default anyway). | - | ||||||||||||||||||
| 335 | // If the user puts down one finger, we're waiting for the other finger to drop. | - | ||||||||||||||||||
| 336 | // Therefore updatePinch() must do the right thing for any combination of | - | ||||||||||||||||||
| 337 | // points and states that may occur, and there is no reason to ignore any event. | - | ||||||||||||||||||
| 338 | // One consequence though is that if PinchArea is on top of something else, | - | ||||||||||||||||||
| 339 | // it's always going to accept the touches, and that means the item underneath | - | ||||||||||||||||||
| 340 | // will not get them (unless the PA's parent is doing parent filtering, | - | ||||||||||||||||||
| 341 | // as the Flickable does, for example). | - | ||||||||||||||||||
| 342 | switch (event->type()) { | - | ||||||||||||||||||
| 343 | case QEvent::TouchBegin: executed 16 times by 1 test: case QEvent::TouchBegin:Executed by:
| 16 | ||||||||||||||||||
| 344 | case QEvent::TouchUpdate: executed 54 times by 1 test: case QEvent::TouchUpdate:Executed by:
| 54 | ||||||||||||||||||
| 345 | d->touchPoints.clear(); | - | ||||||||||||||||||
| 346 | for (int i = 0; i < event->touchPoints().count(); ++i) {
| 70-122 | ||||||||||||||||||
| 347 | if (!(event->touchPoints().at(i).state() & Qt::TouchPointReleased)) {
| 2-120 | ||||||||||||||||||
| 348 | d->touchPoints << event->touchPoints().at(i); | - | ||||||||||||||||||
| 349 | } executed 120 times by 1 test: end of blockExecuted by:
| 120 | ||||||||||||||||||
| 350 | } executed 122 times by 1 test: end of blockExecuted by:
| 122 | ||||||||||||||||||
| 351 | updatePinch(); | - | ||||||||||||||||||
| 352 | break; executed 70 times by 1 test: break;Executed by:
| 70 | ||||||||||||||||||
| 353 | case QEvent::TouchEnd: executed 14 times by 1 test: case QEvent::TouchEnd:Executed by:
| 14 | ||||||||||||||||||
| 354 | clearPinch(); | - | ||||||||||||||||||
| 355 | break; executed 14 times by 1 test: break;Executed by:
| 14 | ||||||||||||||||||
| 356 | case QEvent::TouchCancel: executed 4 times by 1 test: case QEvent::TouchCancel:Executed by:
| 4 | ||||||||||||||||||
| 357 | cancelPinch(); | - | ||||||||||||||||||
| 358 | break; executed 4 times by 1 test: break;Executed by:
| 4 | ||||||||||||||||||
| 359 | default: never executed: default: | 0 | ||||||||||||||||||
| 360 | QQuickItem::touchEvent(event); | - | ||||||||||||||||||
| 361 | } never executed: end of block | 0 | ||||||||||||||||||
| 362 | } | - | ||||||||||||||||||
| 363 | - | |||||||||||||||||||
| 364 | void QQuickPinchArea::clearPinch() | - | ||||||||||||||||||
| 365 | { | - | ||||||||||||||||||
| 366 | Q_D(QQuickPinchArea); | - | ||||||||||||||||||
| 367 | - | |||||||||||||||||||
| 368 | d->touchPoints.clear(); | - | ||||||||||||||||||
| 369 | if (d->inPinch) {
| 2-12 | ||||||||||||||||||
| 370 | d->inPinch = false; | - | ||||||||||||||||||
| 371 | QPointF pinchCenter = mapFromScene(d->sceneLastCenter); | - | ||||||||||||||||||
| 372 | QQuickPinchEvent pe(pinchCenter, d->pinchLastScale, d->pinchLastAngle, d->pinchRotation); | - | ||||||||||||||||||
| 373 | pe.setStartCenter(d->pinchStartCenter); | - | ||||||||||||||||||
| 374 | pe.setPreviousCenter(pinchCenter); | - | ||||||||||||||||||
| 375 | pe.setPreviousAngle(d->pinchLastAngle); | - | ||||||||||||||||||
| 376 | pe.setPreviousScale(d->pinchLastScale); | - | ||||||||||||||||||
| 377 | pe.setStartPoint1(mapFromScene(d->sceneStartPoint1)); | - | ||||||||||||||||||
| 378 | pe.setStartPoint2(mapFromScene(d->sceneStartPoint2)); | - | ||||||||||||||||||
| 379 | pe.setPoint1(mapFromScene(d->lastPoint1)); | - | ||||||||||||||||||
| 380 | pe.setPoint2(mapFromScene(d->lastPoint2)); | - | ||||||||||||||||||
| 381 | emit pinchFinished(&pe); | - | ||||||||||||||||||
| 382 | if (d->pinch && d->pinch->target())
| 0-12 | ||||||||||||||||||
| 383 | d->pinch->setActive(false); executed 12 times by 1 test: d->pinch->setActive(false);Executed by:
| 12 | ||||||||||||||||||
| 384 | } executed 12 times by 1 test: end of blockExecuted by:
| 12 | ||||||||||||||||||
| 385 | d->pinchStartDist = 0; | - | ||||||||||||||||||
| 386 | d->pinchActivated = false; | - | ||||||||||||||||||
| 387 | d->initPinch = false; | - | ||||||||||||||||||
| 388 | d->pinchRejected = false; | - | ||||||||||||||||||
| 389 | d->stealMouse = false; | - | ||||||||||||||||||
| 390 | d->id1 = -1; | - | ||||||||||||||||||
| 391 | QQuickWindow *win = window(); | - | ||||||||||||||||||
| 392 | if (win && win->mouseGrabberItem() == this)
| 0-14 | ||||||||||||||||||
| 393 | ungrabMouse(); executed 12 times by 1 test: ungrabMouse();Executed by:
| 12 | ||||||||||||||||||
| 394 | setKeepMouseGrab(false); | - | ||||||||||||||||||
| 395 | } executed 14 times by 1 test: end of blockExecuted by:
| 14 | ||||||||||||||||||
| 396 | - | |||||||||||||||||||
| 397 | void QQuickPinchArea::cancelPinch() | - | ||||||||||||||||||
| 398 | { | - | ||||||||||||||||||
| 399 | Q_D(QQuickPinchArea); | - | ||||||||||||||||||
| 400 | - | |||||||||||||||||||
| 401 | d->touchPoints.clear(); | - | ||||||||||||||||||
| 402 | if (d->inPinch) {
| 2 | ||||||||||||||||||
| 403 | d->inPinch = false; | - | ||||||||||||||||||
| 404 | QPointF pinchCenter = mapFromScene(d->sceneLastCenter); | - | ||||||||||||||||||
| 405 | QQuickPinchEvent pe(d->pinchStartCenter, d->pinchStartScale, d->pinchStartAngle, d->pinchStartRotation); | - | ||||||||||||||||||
| 406 | pe.setStartCenter(d->pinchStartCenter); | - | ||||||||||||||||||
| 407 | pe.setPreviousCenter(pinchCenter); | - | ||||||||||||||||||
| 408 | pe.setPreviousAngle(d->pinchLastAngle); | - | ||||||||||||||||||
| 409 | pe.setPreviousScale(d->pinchLastScale); | - | ||||||||||||||||||
| 410 | pe.setStartPoint1(mapFromScene(d->sceneStartPoint1)); | - | ||||||||||||||||||
| 411 | pe.setStartPoint2(mapFromScene(d->sceneStartPoint2)); | - | ||||||||||||||||||
| 412 | pe.setPoint1(pe.startPoint1()); | - | ||||||||||||||||||
| 413 | pe.setPoint2(pe.startPoint2()); | - | ||||||||||||||||||
| 414 | emit pinchFinished(&pe); | - | ||||||||||||||||||
| 415 | - | |||||||||||||||||||
| 416 | d->pinchLastScale = d->pinchStartScale; | - | ||||||||||||||||||
| 417 | d->sceneLastCenter = d->sceneStartCenter; | - | ||||||||||||||||||
| 418 | d->pinchLastAngle = d->pinchStartAngle; | - | ||||||||||||||||||
| 419 | d->lastPoint1 = pe.startPoint1(); | - | ||||||||||||||||||
| 420 | d->lastPoint2 = pe.startPoint2(); | - | ||||||||||||||||||
| 421 | updatePinchTarget(); | - | ||||||||||||||||||
| 422 | - | |||||||||||||||||||
| 423 | if (d->pinch && d->pinch->target())
| 0-2 | ||||||||||||||||||
| 424 | d->pinch->setActive(false); executed 2 times by 1 test: d->pinch->setActive(false);Executed by:
| 2 | ||||||||||||||||||
| 425 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||
| 426 | d->pinchStartDist = 0; | - | ||||||||||||||||||
| 427 | d->pinchActivated = false; | - | ||||||||||||||||||
| 428 | d->initPinch = false; | - | ||||||||||||||||||
| 429 | d->pinchRejected = false; | - | ||||||||||||||||||
| 430 | d->stealMouse = false; | - | ||||||||||||||||||
| 431 | d->id1 = -1; | - | ||||||||||||||||||
| 432 | QQuickWindow *win = window(); | - | ||||||||||||||||||
| 433 | if (win && win->mouseGrabberItem() == this)
| 0-4 | ||||||||||||||||||
| 434 | ungrabMouse(); never executed: ungrabMouse(); | 0 | ||||||||||||||||||
| 435 | setKeepMouseGrab(false); | - | ||||||||||||||||||
| 436 | } executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||||||||||||||
| 437 | - | |||||||||||||||||||
| 438 | void QQuickPinchArea::updatePinch() | - | ||||||||||||||||||
| 439 | { | - | ||||||||||||||||||
| 440 | Q_D(QQuickPinchArea); | - | ||||||||||||||||||
| 441 | - | |||||||||||||||||||
| 442 | QQuickWindow *win = window(); | - | ||||||||||||||||||
| 443 | - | |||||||||||||||||||
| 444 | if (d->touchPoints.count() < 2) {
| 20-50 | ||||||||||||||||||
| 445 | setKeepMouseGrab(false); | - | ||||||||||||||||||
| 446 | QQuickWindow *c = window(); | - | ||||||||||||||||||
| 447 | if (c && c->mouseGrabberItem() == this)
| 0-20 | ||||||||||||||||||
| 448 | ungrabMouse(); executed 2 times by 1 test: ungrabMouse();Executed by:
| 2 | ||||||||||||||||||
| 449 | } executed 20 times by 1 test: end of blockExecuted by:
| 20 | ||||||||||||||||||
| 450 | - | |||||||||||||||||||
| 451 | if (d->touchPoints.count() == 0) {
| 0-70 | ||||||||||||||||||
| 452 | if (d->inPinch) {
| 0 | ||||||||||||||||||
| 453 | d->inPinch = false; | - | ||||||||||||||||||
| 454 | QPointF pinchCenter = mapFromScene(d->sceneLastCenter); | - | ||||||||||||||||||
| 455 | QQuickPinchEvent pe(pinchCenter, d->pinchLastScale, d->pinchLastAngle, d->pinchRotation); | - | ||||||||||||||||||
| 456 | pe.setStartCenter(d->pinchStartCenter); | - | ||||||||||||||||||
| 457 | pe.setPreviousCenter(pinchCenter); | - | ||||||||||||||||||
| 458 | pe.setPreviousAngle(d->pinchLastAngle); | - | ||||||||||||||||||
| 459 | pe.setPreviousScale(d->pinchLastScale); | - | ||||||||||||||||||
| 460 | pe.setStartPoint1(mapFromScene(d->sceneStartPoint1)); | - | ||||||||||||||||||
| 461 | pe.setStartPoint2(mapFromScene(d->sceneStartPoint2)); | - | ||||||||||||||||||
| 462 | pe.setPoint1(mapFromScene(d->lastPoint1)); | - | ||||||||||||||||||
| 463 | pe.setPoint2(mapFromScene(d->lastPoint2)); | - | ||||||||||||||||||
| 464 | emit pinchFinished(&pe); | - | ||||||||||||||||||
| 465 | d->pinchStartDist = 0; | - | ||||||||||||||||||
| 466 | d->pinchActivated = false; | - | ||||||||||||||||||
| 467 | if (d->pinch && d->pinch->target())
| 0 | ||||||||||||||||||
| 468 | d->pinch->setActive(false); never executed: d->pinch->setActive(false); | 0 | ||||||||||||||||||
| 469 | } never executed: end of block | 0 | ||||||||||||||||||
| 470 | d->initPinch = false; | - | ||||||||||||||||||
| 471 | d->pinchRejected = false; | - | ||||||||||||||||||
| 472 | d->stealMouse = false; | - | ||||||||||||||||||
| 473 | return; never executed: return; | 0 | ||||||||||||||||||
| 474 | } | - | ||||||||||||||||||
| 475 | - | |||||||||||||||||||
| 476 | QTouchEvent::TouchPoint touchPoint1 = d->touchPoints.at(0); | - | ||||||||||||||||||
| 477 | QTouchEvent::TouchPoint touchPoint2 = d->touchPoints.at(d->touchPoints. count() >= 2 ? 1 : 0); | - | ||||||||||||||||||
| 478 | - | |||||||||||||||||||
| 479 | if (touchPoint1.state() == Qt::TouchPointPressed)
| 16-54 | ||||||||||||||||||
| 480 | d->sceneStartPoint1 = touchPoint1.scenePos(); executed 16 times by 1 test: d->sceneStartPoint1 = touchPoint1.scenePos();Executed by:
| 16 | ||||||||||||||||||
| 481 | - | |||||||||||||||||||
| 482 | if (touchPoint2.state() == Qt::TouchPointPressed)
| 32-38 | ||||||||||||||||||
| 483 | d->sceneStartPoint2 = touchPoint2.scenePos(); executed 32 times by 1 test: d->sceneStartPoint2 = touchPoint2.scenePos();Executed by:
| 32 | ||||||||||||||||||
| 484 | - | |||||||||||||||||||
| 485 | QRectF bounds = clipRect(); | - | ||||||||||||||||||
| 486 | // Pinch is not started unless there are exactly two touch points | - | ||||||||||||||||||
| 487 | // AND one or more of the points has just now been pressed (wasn't pressed already) | - | ||||||||||||||||||
| 488 | // AND both points are inside the bounds. | - | ||||||||||||||||||
| 489 | if (d->touchPoints.count() == 2
| 20-50 | ||||||||||||||||||
| 490 | && (touchPoint1.state() & Qt::TouchPointPressed || touchPoint2.state() & Qt::TouchPointPressed) &&
| 0-50 | ||||||||||||||||||
| 491 | bounds.contains(touchPoint1.pos()) && bounds.contains(touchPoint2.pos())) {
| 0-16 | ||||||||||||||||||
| 492 | d->id1 = touchPoint1.id(); | - | ||||||||||||||||||
| 493 | d->pinchActivated = true; | - | ||||||||||||||||||
| 494 | d->initPinch = true; | - | ||||||||||||||||||
| 495 | - | |||||||||||||||||||
| 496 | int touchMouseId = QQuickWindowPrivate::get(win)->touchMouseId; | - | ||||||||||||||||||
| 497 | if (touchPoint1.id() == touchMouseId || touchPoint2.id() == touchMouseId) {
| 0-16 | ||||||||||||||||||
| 498 | if (win && win->mouseGrabberItem() != this) {
| 0 | ||||||||||||||||||
| 499 | grabMouse(); | - | ||||||||||||||||||
| 500 | } never executed: end of block | 0 | ||||||||||||||||||
| 501 | } never executed: end of block | 0 | ||||||||||||||||||
| 502 | } executed 16 times by 1 test: end of blockExecuted by:
| 16 | ||||||||||||||||||
| 503 | if (d->pinchActivated && !d->pinchRejected) {
| 0-52 | ||||||||||||||||||
| 504 | const int dragThreshold = QGuiApplication::styleHints()->startDragDistance(); | - | ||||||||||||||||||
| 505 | QPointF p1 = touchPoint1.scenePos(); | - | ||||||||||||||||||
| 506 | QPointF p2 = touchPoint2.scenePos(); | - | ||||||||||||||||||
| 507 | qreal dx = p1.x() - p2.x(); | - | ||||||||||||||||||
| 508 | qreal dy = p1.y() - p2.y(); | - | ||||||||||||||||||
| 509 | qreal dist = qSqrt(dx*dx + dy*dy); | - | ||||||||||||||||||
| 510 | QPointF sceneCenter = (p1 + p2)/2; | - | ||||||||||||||||||
| 511 | qreal angle = QLineF(p1, p2).angle(); | - | ||||||||||||||||||
| 512 | if (d->touchPoints.count() == 1) {
| 2-50 | ||||||||||||||||||
| 513 | // If we only have one point then just move the center | - | ||||||||||||||||||
| 514 | if (d->id1 == touchPoint1.id())
| 0-2 | ||||||||||||||||||
| 515 | sceneCenter = d->sceneLastCenter + touchPoint1.scenePos() - d->lastPoint1; executed 2 times by 1 test: sceneCenter = d->sceneLastCenter + touchPoint1.scenePos() - d->lastPoint1;Executed by:
| 2 | ||||||||||||||||||
| 516 | else | - | ||||||||||||||||||
| 517 | sceneCenter = d->sceneLastCenter + touchPoint2.scenePos() - d->lastPoint2; never executed: sceneCenter = d->sceneLastCenter + touchPoint2.scenePos() - d->lastPoint2; | 0 | ||||||||||||||||||
| 518 | angle = d->pinchLastAngle; | - | ||||||||||||||||||
| 519 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||
| 520 | d->id1 = touchPoint1.id(); | - | ||||||||||||||||||
| 521 | if (angle > 180)
| 10-42 | ||||||||||||||||||
| 522 | angle -= 360; executed 42 times by 1 test: angle -= 360;Executed by:
| 42 | ||||||||||||||||||
| 523 | if (!d->inPinch || d->initPinch) {
| 2-30 | ||||||||||||||||||
| 524 | if (d->touchPoints.count() >= 2) {
| 0-32 | ||||||||||||||||||
| 525 | if (d->initPinch) {
| 16 | ||||||||||||||||||
| 526 | if (!d->inPinch)
| 2-14 | ||||||||||||||||||
| 527 | d->pinchStartDist = dist; executed 14 times by 1 test: d->pinchStartDist = dist;Executed by:
| 14 | ||||||||||||||||||
| 528 | d->initPinch = false; | - | ||||||||||||||||||
| 529 | } executed 16 times by 1 test: end of blockExecuted by:
| 16 | ||||||||||||||||||
| 530 | d->sceneStartCenter = sceneCenter; | - | ||||||||||||||||||
| 531 | d->sceneLastCenter = sceneCenter; | - | ||||||||||||||||||
| 532 | d->pinchStartCenter = mapFromScene(sceneCenter); | - | ||||||||||||||||||
| 533 | d->pinchStartAngle = angle; | - | ||||||||||||||||||
| 534 | d->pinchLastScale = 1.0; | - | ||||||||||||||||||
| 535 | d->pinchLastAngle = angle; | - | ||||||||||||||||||
| 536 | d->pinchRotation = 0.0; | - | ||||||||||||||||||
| 537 | d->lastPoint1 = p1; | - | ||||||||||||||||||
| 538 | d->lastPoint2 = p2; | - | ||||||||||||||||||
| 539 | if (qAbs(dist - d->pinchStartDist) >= dragThreshold ||
| 12-20 | ||||||||||||||||||
| 540 | (pinch()->axis() != QQuickPinch::NoDrag &&
| 0-20 | ||||||||||||||||||
| 541 | (qAbs(p1.x()-d->sceneStartPoint1.x()) >= dragThreshold
| 2-18 | ||||||||||||||||||
| 542 | || qAbs(p1.y()-d->sceneStartPoint1.y()) >= dragThreshold
| 0-18 | ||||||||||||||||||
| 543 | || qAbs(p2.x()-d->sceneStartPoint2.x()) >= dragThreshold
| 2-16 | ||||||||||||||||||
| 544 | || qAbs(p2.y()-d->sceneStartPoint2.y()) >= dragThreshold))) {
| 0-16 | ||||||||||||||||||
| 545 | QQuickPinchEvent pe(d->pinchStartCenter, 1.0, angle, 0.0); | - | ||||||||||||||||||
| 546 | d->pinchStartDist = dist; | - | ||||||||||||||||||
| 547 | pe.setStartCenter(d->pinchStartCenter); | - | ||||||||||||||||||
| 548 | pe.setPreviousCenter(d->pinchStartCenter); | - | ||||||||||||||||||
| 549 | pe.setPreviousAngle(d->pinchLastAngle); | - | ||||||||||||||||||
| 550 | pe.setPreviousScale(d->pinchLastScale); | - | ||||||||||||||||||
| 551 | pe.setStartPoint1(mapFromScene(d->sceneStartPoint1)); | - | ||||||||||||||||||
| 552 | pe.setStartPoint2(mapFromScene(d->sceneStartPoint2)); | - | ||||||||||||||||||
| 553 | pe.setPoint1(mapFromScene(d->lastPoint1)); | - | ||||||||||||||||||
| 554 | pe.setPoint2(mapFromScene(d->lastPoint2)); | - | ||||||||||||||||||
| 555 | pe.setPointCount(d->touchPoints.count()); | - | ||||||||||||||||||
| 556 | emit pinchStarted(&pe); | - | ||||||||||||||||||
| 557 | if (pe.accepted()) {
| 0-16 | ||||||||||||||||||
| 558 | d->inPinch = true; | - | ||||||||||||||||||
| 559 | d->stealMouse = true; | - | ||||||||||||||||||
| 560 | if (win && win->mouseGrabberItem() != this)
| 0-16 | ||||||||||||||||||
| 561 | grabMouse(); executed 16 times by 1 test: grabMouse();Executed by:
| 16 | ||||||||||||||||||
| 562 | setKeepMouseGrab(true); | - | ||||||||||||||||||
| 563 | grabTouchPoints(QVector<int>() << touchPoint1.id() << touchPoint2.id()); | - | ||||||||||||||||||
| 564 | d->inPinch = true; | - | ||||||||||||||||||
| 565 | d->stealMouse = true; | - | ||||||||||||||||||
| 566 | if (d->pinch && d->pinch->target()) {
| 0-16 | ||||||||||||||||||
| 567 | d->pinchStartPos = pinch()->target()->position(); | - | ||||||||||||||||||
| 568 | d->pinchStartScale = d->pinch->target()->scale(); | - | ||||||||||||||||||
| 569 | d->pinchStartRotation = d->pinch->target()->rotation(); | - | ||||||||||||||||||
| 570 | d->pinch->setActive(true); | - | ||||||||||||||||||
| 571 | } executed 16 times by 1 test: end of blockExecuted by:
| 16 | ||||||||||||||||||
| 572 | } else { executed 16 times by 1 test: end of blockExecuted by:
| 16 | ||||||||||||||||||
| 573 | d->pinchRejected = true; | - | ||||||||||||||||||
| 574 | } never executed: end of block | 0 | ||||||||||||||||||
| 575 | } | - | ||||||||||||||||||
| 576 | } executed 32 times by 1 test: end of blockExecuted by:
| 32 | ||||||||||||||||||
| 577 | } else if (d->pinchStartDist > 0) { executed 32 times by 1 test: end of blockExecuted by:
| 0-32 | ||||||||||||||||||
| 578 | qreal scale = dist ? dist / d->pinchStartDist : d->pinchLastScale;
| 2-18 | ||||||||||||||||||
| 579 | qreal da = d->pinchLastAngle - angle; | - | ||||||||||||||||||
| 580 | if (da > 180)
| 0-20 | ||||||||||||||||||
| 581 | da -= 360; never executed: da -= 360; | 0 | ||||||||||||||||||
| 582 | else if (da < -180)
| 0-20 | ||||||||||||||||||
| 583 | da += 360; never executed: da += 360; | 0 | ||||||||||||||||||
| 584 | d->pinchRotation += da; | - | ||||||||||||||||||
| 585 | QPointF pinchCenter = mapFromScene(sceneCenter); | - | ||||||||||||||||||
| 586 | QQuickPinchEvent pe(pinchCenter, scale, angle, d->pinchRotation); | - | ||||||||||||||||||
| 587 | pe.setStartCenter(d->pinchStartCenter); | - | ||||||||||||||||||
| 588 | pe.setPreviousCenter(mapFromScene(d->sceneLastCenter)); | - | ||||||||||||||||||
| 589 | pe.setPreviousAngle(d->pinchLastAngle); | - | ||||||||||||||||||
| 590 | pe.setPreviousScale(d->pinchLastScale); | - | ||||||||||||||||||
| 591 | pe.setStartPoint1(mapFromScene(d->sceneStartPoint1)); | - | ||||||||||||||||||
| 592 | pe.setStartPoint2(mapFromScene(d->sceneStartPoint2)); | - | ||||||||||||||||||
| 593 | pe.setPoint1(touchPoint1.pos()); | - | ||||||||||||||||||
| 594 | pe.setPoint2(touchPoint2.pos()); | - | ||||||||||||||||||
| 595 | pe.setPointCount(d->touchPoints.count()); | - | ||||||||||||||||||
| 596 | d->pinchLastScale = scale; | - | ||||||||||||||||||
| 597 | d->sceneLastCenter = sceneCenter; | - | ||||||||||||||||||
| 598 | d->pinchLastAngle = angle; | - | ||||||||||||||||||
| 599 | d->lastPoint1 = touchPoint1.scenePos(); | - | ||||||||||||||||||
| 600 | d->lastPoint2 = touchPoint2.scenePos(); | - | ||||||||||||||||||
| 601 | emit pinchUpdated(&pe); | - | ||||||||||||||||||
| 602 | updatePinchTarget(); | - | ||||||||||||||||||
| 603 | } executed 20 times by 1 test: end of blockExecuted by:
| 20 | ||||||||||||||||||
| 604 | } executed 52 times by 1 test: end of blockExecuted by:
| 52 | ||||||||||||||||||
| 605 | } executed 70 times by 1 test: end of blockExecuted by:
| 70 | ||||||||||||||||||
| 606 | - | |||||||||||||||||||
| 607 | void QQuickPinchArea::updatePinchTarget() | - | ||||||||||||||||||
| 608 | { | - | ||||||||||||||||||
| 609 | Q_D(QQuickPinchArea); | - | ||||||||||||||||||
| 610 | if (d->pinch && d->pinch->target()) {
| 0-22 | ||||||||||||||||||
| 611 | qreal s = d->pinchStartScale * d->pinchLastScale; | - | ||||||||||||||||||
| 612 | s = qMin(qMax(pinch()->minimumScale(),s), pinch()->maximumScale()); | - | ||||||||||||||||||
| 613 | pinch()->target()->setScale(s); | - | ||||||||||||||||||
| 614 | QPointF pos = d->sceneLastCenter - d->sceneStartCenter + d->pinchStartPos; | - | ||||||||||||||||||
| 615 | if (pinch()->axis() & QQuickPinch::XAxis) {
| 0-22 | ||||||||||||||||||
| 616 | qreal x = pos.x(); | - | ||||||||||||||||||
| 617 | if (x < pinch()->xmin())
| 0-22 | ||||||||||||||||||
| 618 | x = pinch()->xmin(); never executed: x = pinch()->xmin(); | 0 | ||||||||||||||||||
| 619 | else if (x > pinch()->xmax())
| 2-20 | ||||||||||||||||||
| 620 | x = pinch()->xmax(); executed 2 times by 1 test: x = pinch()->xmax();Executed by:
| 2 | ||||||||||||||||||
| 621 | pinch()->target()->setX(x); | - | ||||||||||||||||||
| 622 | } executed 22 times by 1 test: end of blockExecuted by:
| 22 | ||||||||||||||||||
| 623 | if (pinch()->axis() & QQuickPinch::YAxis) {
| 0-22 | ||||||||||||||||||
| 624 | qreal y = pos.y(); | - | ||||||||||||||||||
| 625 | if (y < pinch()->ymin())
| 0-22 | ||||||||||||||||||
| 626 | y = pinch()->ymin(); never executed: y = pinch()->ymin(); | 0 | ||||||||||||||||||
| 627 | else if (y > pinch()->ymax())
| 0-22 | ||||||||||||||||||
| 628 | y = pinch()->ymax(); never executed: y = pinch()->ymax(); | 0 | ||||||||||||||||||
| 629 | pinch()->target()->setY(y); | - | ||||||||||||||||||
| 630 | } executed 22 times by 1 test: end of blockExecuted by:
| 22 | ||||||||||||||||||
| 631 | if (d->pinchStartRotation >= pinch()->minimumRotation()
| 0-22 | ||||||||||||||||||
| 632 | && d->pinchStartRotation <= pinch()->maximumRotation()) {
| 0-22 | ||||||||||||||||||
| 633 | qreal r = d->pinchRotation + d->pinchStartRotation; | - | ||||||||||||||||||
| 634 | r = qMin(qMax(pinch()->minimumRotation(),r), pinch()->maximumRotation()); | - | ||||||||||||||||||
| 635 | pinch()->target()->setRotation(r); | - | ||||||||||||||||||
| 636 | } executed 22 times by 1 test: end of blockExecuted by:
| 22 | ||||||||||||||||||
| 637 | } executed 22 times by 1 test: end of blockExecuted by:
| 22 | ||||||||||||||||||
| 638 | } executed 22 times by 1 test: end of blockExecuted by:
| 22 | ||||||||||||||||||
| 639 | - | |||||||||||||||||||
| 640 | bool QQuickPinchArea::childMouseEventFilter(QQuickItem *i, QEvent *e) | - | ||||||||||||||||||
| 641 | { | - | ||||||||||||||||||
| 642 | Q_D(QQuickPinchArea); | - | ||||||||||||||||||
| 643 | if (!d->enabled || !isVisible())
| 0 | ||||||||||||||||||
| 644 | return QQuickItem::childMouseEventFilter(i, e); never executed: return QQuickItem::childMouseEventFilter(i, e); | 0 | ||||||||||||||||||
| 645 | switch (e->type()) { | - | ||||||||||||||||||
| 646 | case QEvent::TouchBegin: never executed: case QEvent::TouchBegin: | 0 | ||||||||||||||||||
| 647 | clearPinch(); | - | ||||||||||||||||||
| 648 | Q_FALLTHROUGH(); | - | ||||||||||||||||||
| 649 | case QEvent::TouchUpdate: { code before this statement never executed: case QEvent::TouchUpdate:never executed: case QEvent::TouchUpdate: | 0 | ||||||||||||||||||
| 650 | QTouchEvent *touch = static_cast<QTouchEvent*>(e); | - | ||||||||||||||||||
| 651 | d->touchPoints.clear(); | - | ||||||||||||||||||
| 652 | for (int i = 0; i < touch->touchPoints().count(); ++i)
| 0 | ||||||||||||||||||
| 653 | if (!(touch->touchPoints().at(i).state() & Qt::TouchPointReleased))
| 0 | ||||||||||||||||||
| 654 | d->touchPoints << touch->touchPoints().at(i); never executed: d->touchPoints << touch->touchPoints().at(i); | 0 | ||||||||||||||||||
| 655 | updatePinch(); | - | ||||||||||||||||||
| 656 | } | - | ||||||||||||||||||
| 657 | e->setAccepted(d->inPinch); | - | ||||||||||||||||||
| 658 | return d->inPinch; never executed: return d->inPinch; | 0 | ||||||||||||||||||
| 659 | case QEvent::TouchEnd: never executed: case QEvent::TouchEnd: | 0 | ||||||||||||||||||
| 660 | clearPinch(); | - | ||||||||||||||||||
| 661 | break; never executed: break; | 0 | ||||||||||||||||||
| 662 | default: never executed: default: | 0 | ||||||||||||||||||
| 663 | break; never executed: break; | 0 | ||||||||||||||||||
| 664 | } | - | ||||||||||||||||||
| 665 | - | |||||||||||||||||||
| 666 | return QQuickItem::childMouseEventFilter(i, e); never executed: return QQuickItem::childMouseEventFilter(i, e); | 0 | ||||||||||||||||||
| 667 | } | - | ||||||||||||||||||
| 668 | - | |||||||||||||||||||
| 669 | void QQuickPinchArea::geometryChanged(const QRectF &newGeometry, | - | ||||||||||||||||||
| 670 | const QRectF &oldGeometry) | - | ||||||||||||||||||
| 671 | { | - | ||||||||||||||||||
| 672 | QQuickItem::geometryChanged(newGeometry, oldGeometry); | - | ||||||||||||||||||
| 673 | } executed 36 times by 3 tests: end of blockExecuted by:
| 36 | ||||||||||||||||||
| 674 | - | |||||||||||||||||||
| 675 | void QQuickPinchArea::itemChange(ItemChange change, const ItemChangeData &value) | - | ||||||||||||||||||
| 676 | { | - | ||||||||||||||||||
| 677 | QQuickItem::itemChange(change, value); | - | ||||||||||||||||||
| 678 | } executed 134 times by 3 tests: end of blockExecuted by:
| 134 | ||||||||||||||||||
| 679 | - | |||||||||||||||||||
| 680 | bool QQuickPinchArea::event(QEvent *event) | - | ||||||||||||||||||
| 681 | { | - | ||||||||||||||||||
| 682 | Q_D(QQuickPinchArea); | - | ||||||||||||||||||
| 683 | if (!d->enabled || !isVisible())
| 0-88 | ||||||||||||||||||
| 684 | return QQuickItem::event(event); never executed: return QQuickItem::event(event); | 0 | ||||||||||||||||||
| 685 | - | |||||||||||||||||||
| 686 | switch (event->type()) { | - | ||||||||||||||||||
| 687 | #if QT_CONFIG(gestures) | - | ||||||||||||||||||
| 688 | case QEvent::NativeGesture: { never executed: case QEvent::NativeGesture: | 0 | ||||||||||||||||||
| 689 | QNativeGestureEvent *gesture = static_cast<QNativeGestureEvent *>(event); | - | ||||||||||||||||||
| 690 | switch (gesture->gestureType()) { | - | ||||||||||||||||||
| 691 | case Qt::BeginNativeGesture: never executed: case Qt::BeginNativeGesture: | 0 | ||||||||||||||||||
| 692 | clearPinch(); // probably not necessary; JIC | - | ||||||||||||||||||
| 693 | d->pinchStartCenter = gesture->localPos(); | - | ||||||||||||||||||
| 694 | d->pinchStartAngle = 0.0; | - | ||||||||||||||||||
| 695 | d->pinchStartRotation = 0.0; | - | ||||||||||||||||||
| 696 | d->pinchRotation = 0.0; | - | ||||||||||||||||||
| 697 | d->pinchStartScale = 1.0; | - | ||||||||||||||||||
| 698 | d->pinchLastAngle = 0.0; | - | ||||||||||||||||||
| 699 | d->pinchLastScale = 1.0; | - | ||||||||||||||||||
| 700 | d->sceneStartPoint1 = gesture->windowPos(); | - | ||||||||||||||||||
| 701 | d->sceneStartPoint2 = gesture->windowPos(); // TODO we never really know | - | ||||||||||||||||||
| 702 | d->lastPoint1 = gesture->windowPos(); | - | ||||||||||||||||||
| 703 | d->lastPoint2 = gesture->windowPos(); // TODO we never really know | - | ||||||||||||||||||
| 704 | if (d->pinch && d->pinch->target()) {
| 0 | ||||||||||||||||||
| 705 | d->pinchStartPos = d->pinch->target()->position(); | - | ||||||||||||||||||
| 706 | d->pinchStartScale = d->pinch->target()->scale(); | - | ||||||||||||||||||
| 707 | d->pinchStartRotation = d->pinch->target()->rotation(); | - | ||||||||||||||||||
| 708 | d->pinch->setActive(true); | - | ||||||||||||||||||
| 709 | } never executed: end of block | 0 | ||||||||||||||||||
| 710 | break; never executed: break; | 0 | ||||||||||||||||||
| 711 | case Qt::EndNativeGesture: never executed: case Qt::EndNativeGesture: | 0 | ||||||||||||||||||
| 712 | clearPinch(); | - | ||||||||||||||||||
| 713 | break; never executed: break; | 0 | ||||||||||||||||||
| 714 | case Qt::ZoomNativeGesture: { never executed: case Qt::ZoomNativeGesture: | 0 | ||||||||||||||||||
| 715 | qreal scale = d->pinchLastScale * (1.0 + gesture->value()); | - | ||||||||||||||||||
| 716 | QQuickPinchEvent pe(d->pinchStartCenter, scale, d->pinchLastAngle, 0.0); | - | ||||||||||||||||||
| 717 | pe.setStartCenter(d->pinchStartCenter); | - | ||||||||||||||||||
| 718 | pe.setPreviousCenter(d->pinchStartCenter); | - | ||||||||||||||||||
| 719 | pe.setPreviousAngle(d->pinchLastAngle); | - | ||||||||||||||||||
| 720 | pe.setPreviousScale(d->pinchLastScale); | - | ||||||||||||||||||
| 721 | pe.setStartPoint1(mapFromScene(d->sceneStartPoint1)); | - | ||||||||||||||||||
| 722 | pe.setStartPoint2(mapFromScene(d->sceneStartPoint2)); | - | ||||||||||||||||||
| 723 | pe.setPoint1(mapFromScene(d->lastPoint1)); | - | ||||||||||||||||||
| 724 | pe.setPoint2(mapFromScene(d->lastPoint2)); | - | ||||||||||||||||||
| 725 | pe.setPointCount(2); | - | ||||||||||||||||||
| 726 | d->pinchLastScale = scale; | - | ||||||||||||||||||
| 727 | if (d->inPinch)
| 0 | ||||||||||||||||||
| 728 | emit pinchUpdated(&pe); never executed: pinchUpdated(&pe); | 0 | ||||||||||||||||||
| 729 | else | - | ||||||||||||||||||
| 730 | emit pinchStarted(&pe); never executed: pinchStarted(&pe); | 0 | ||||||||||||||||||
| 731 | d->inPinch = true; | - | ||||||||||||||||||
| 732 | updatePinchTarget(); | - | ||||||||||||||||||
| 733 | } break; never executed: break; | 0 | ||||||||||||||||||
| 734 | case Qt::SmartZoomNativeGesture: { never executed: case Qt::SmartZoomNativeGesture: | 0 | ||||||||||||||||||
| 735 | if (gesture->value() > 0.0 && d->pinch && d->pinch->target()) {
| 0 | ||||||||||||||||||
| 736 | d->pinchStartPos = pinch()->target()->position(); | - | ||||||||||||||||||
| 737 | d->pinchStartCenter = mapToItem(pinch()->target()->parentItem(), pinch()->target()->boundingRect().center()); | - | ||||||||||||||||||
| 738 | d->pinchStartScale = d->pinch->target()->scale(); | - | ||||||||||||||||||
| 739 | d->pinchStartRotation = d->pinch->target()->rotation(); | - | ||||||||||||||||||
| 740 | d->pinchLastScale = d->pinchStartScale = d->pinch->target()->scale(); | - | ||||||||||||||||||
| 741 | d->pinchLastAngle = d->pinchStartRotation = d->pinch->target()->rotation(); | - | ||||||||||||||||||
| 742 | } never executed: end of block | 0 | ||||||||||||||||||
| 743 | QQuickPinchEvent pe(gesture->localPos(), gesture->value(), d->pinchLastAngle, 0.0); | - | ||||||||||||||||||
| 744 | pe.setStartCenter(gesture->localPos()); | - | ||||||||||||||||||
| 745 | pe.setPreviousCenter(d->pinchStartCenter); | - | ||||||||||||||||||
| 746 | pe.setPreviousAngle(d->pinchLastAngle); | - | ||||||||||||||||||
| 747 | pe.setPreviousScale(d->pinchLastScale); | - | ||||||||||||||||||
| 748 | pe.setStartPoint1(gesture->localPos()); | - | ||||||||||||||||||
| 749 | pe.setStartPoint2(gesture->localPos()); | - | ||||||||||||||||||
| 750 | pe.setPoint1(mapFromScene(gesture->windowPos())); | - | ||||||||||||||||||
| 751 | pe.setPoint2(mapFromScene(gesture->windowPos())); | - | ||||||||||||||||||
| 752 | pe.setPointCount(2); | - | ||||||||||||||||||
| 753 | emit smartZoom(&pe); | - | ||||||||||||||||||
| 754 | } break; never executed: break; | 0 | ||||||||||||||||||
| 755 | case Qt::RotateNativeGesture: { never executed: case Qt::RotateNativeGesture: | 0 | ||||||||||||||||||
| 756 | qreal angle = d->pinchLastAngle + gesture->value(); | - | ||||||||||||||||||
| 757 | QQuickPinchEvent pe(d->pinchStartCenter, d->pinchLastScale, angle, 0.0); | - | ||||||||||||||||||
| 758 | pe.setStartCenter(d->pinchStartCenter); | - | ||||||||||||||||||
| 759 | pe.setPreviousCenter(d->pinchStartCenter); | - | ||||||||||||||||||
| 760 | pe.setPreviousAngle(d->pinchLastAngle); | - | ||||||||||||||||||
| 761 | pe.setPreviousScale(d->pinchLastScale); | - | ||||||||||||||||||
| 762 | pe.setStartPoint1(mapFromScene(d->sceneStartPoint1)); | - | ||||||||||||||||||
| 763 | pe.setStartPoint2(mapFromScene(d->sceneStartPoint2)); | - | ||||||||||||||||||
| 764 | pe.setPoint1(mapFromScene(d->lastPoint1)); | - | ||||||||||||||||||
| 765 | pe.setPoint2(mapFromScene(d->lastPoint2)); | - | ||||||||||||||||||
| 766 | pe.setPointCount(2); | - | ||||||||||||||||||
| 767 | d->pinchLastAngle = angle; | - | ||||||||||||||||||
| 768 | if (d->inPinch)
| 0 | ||||||||||||||||||
| 769 | emit pinchUpdated(&pe); never executed: pinchUpdated(&pe); | 0 | ||||||||||||||||||
| 770 | else | - | ||||||||||||||||||
| 771 | emit pinchStarted(&pe); never executed: pinchStarted(&pe); | 0 | ||||||||||||||||||
| 772 | d->inPinch = true; | - | ||||||||||||||||||
| 773 | d->pinchRotation = angle; | - | ||||||||||||||||||
| 774 | updatePinchTarget(); | - | ||||||||||||||||||
| 775 | } break; never executed: break; | 0 | ||||||||||||||||||
| 776 | default: never executed: default: | 0 | ||||||||||||||||||
| 777 | return QQuickItem::event(event); never executed: return QQuickItem::event(event); | 0 | ||||||||||||||||||
| 778 | } | - | ||||||||||||||||||
| 779 | } break; never executed: break; | 0 | ||||||||||||||||||
| 780 | #endif // gestures | - | ||||||||||||||||||
| 781 | case QEvent::Wheel: never executed: case QEvent::Wheel: | 0 | ||||||||||||||||||
| 782 | event->ignore(); | - | ||||||||||||||||||
| 783 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 784 | default: executed 88 times by 1 test: default:Executed by:
| 88 | ||||||||||||||||||
| 785 | return QQuickItem::event(event); executed 88 times by 1 test: return QQuickItem::event(event);Executed by:
| 88 | ||||||||||||||||||
| 786 | } | - | ||||||||||||||||||
| 787 | - | |||||||||||||||||||
| 788 | return true; never executed: return true; | 0 | ||||||||||||||||||
| 789 | } | - | ||||||||||||||||||
| 790 | - | |||||||||||||||||||
| 791 | QQuickPinch *QQuickPinchArea::pinch() | - | ||||||||||||||||||
| 792 | { | - | ||||||||||||||||||
| 793 | Q_D(QQuickPinchArea); | - | ||||||||||||||||||
| 794 | if (!d->pinch)
| 30-400 | ||||||||||||||||||
| 795 | d->pinch = new QQuickPinch; executed 30 times by 2 tests: d->pinch = new QQuickPinch;Executed by:
| 30 | ||||||||||||||||||
| 796 | return d->pinch; executed 430 times by 2 tests: return d->pinch;Executed by:
| 430 | ||||||||||||||||||
| 797 | } | - | ||||||||||||||||||
| 798 | - | |||||||||||||||||||
| 799 | QT_END_NAMESPACE | - | ||||||||||||||||||
| 800 | - | |||||||||||||||||||
| 801 | #include "moc_qquickpincharea_p.cpp" | - | ||||||||||||||||||
| Source code | Switch to Preprocessed file |