| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/quick/items/qquickpincharea.cpp |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||||||||||||||
| 2 | - | |||||||||||||||||||
| 3 | - | |||||||||||||||||||
| 4 | - | |||||||||||||||||||
| 5 | - | |||||||||||||||||||
| 6 | - | |||||||||||||||||||
| 7 | QQuickPinch::QQuickPinch() | - | ||||||||||||||||||
| 8 | : m_target(nullptr), m_minScale(1.0), m_maxScale(1.0) | - | ||||||||||||||||||
| 9 | , m_minRotation(0.0), m_maxRotation(0.0) | - | ||||||||||||||||||
| 10 | , m_axis(NoDrag), m_xmin(-3.40282346638528859812e+38F), m_xmax(3.40282346638528859812e+38F) | - | ||||||||||||||||||
| 11 | , m_ymin(-3.40282346638528859812e+38F), m_ymax(3.40282346638528859812e+38F), m_active(false) | - | ||||||||||||||||||
| 12 | { | - | ||||||||||||||||||
| 13 | } executed 30 times by 2 tests: end of blockExecuted by:
| 30 | ||||||||||||||||||
| 14 | - | |||||||||||||||||||
| 15 | QQuickPinchAreaPrivate::~QQuickPinchAreaPrivate() | - | ||||||||||||||||||
| 16 | { | - | ||||||||||||||||||
| 17 | delete pinch; | - | ||||||||||||||||||
| 18 | } executed 32 times by 3 tests: end of blockExecuted by:
| 32 | ||||||||||||||||||
| 19 | QQuickPinchArea::QQuickPinchArea(QQuickItem *parent) | - | ||||||||||||||||||
| 20 | : QQuickItem(*(new QQuickPinchAreaPrivate), parent) | - | ||||||||||||||||||
| 21 | { | - | ||||||||||||||||||
| 22 | QQuickPinchAreaPrivate * const d = d_func(); | - | ||||||||||||||||||
| 23 | d->init(); | - | ||||||||||||||||||
| 24 | setAcceptTouchEvents(true); | - | ||||||||||||||||||
| 25 | - | |||||||||||||||||||
| 26 | - | |||||||||||||||||||
| 27 | - | |||||||||||||||||||
| 28 | } executed 32 times by 3 tests: end of blockExecuted by:
| 32 | ||||||||||||||||||
| 29 | - | |||||||||||||||||||
| 30 | QQuickPinchArea::~QQuickPinchArea() | - | ||||||||||||||||||
| 31 | { | - | ||||||||||||||||||
| 32 | } | - | ||||||||||||||||||
| 33 | - | |||||||||||||||||||
| 34 | - | |||||||||||||||||||
| 35 | - | |||||||||||||||||||
| 36 | - | |||||||||||||||||||
| 37 | - | |||||||||||||||||||
| 38 | - | |||||||||||||||||||
| 39 | bool QQuickPinchArea::isEnabled() const | - | ||||||||||||||||||
| 40 | { | - | ||||||||||||||||||
| 41 | const QQuickPinchAreaPrivate * const d = d_func(); | - | ||||||||||||||||||
| 42 | return never executed: d->enabled;return d->enabled;never executed: return d->enabled; | 0 | ||||||||||||||||||
| 43 | } | - | ||||||||||||||||||
| 44 | - | |||||||||||||||||||
| 45 | void QQuickPinchArea::setEnabled(bool a) | - | ||||||||||||||||||
| 46 | { | - | ||||||||||||||||||
| 47 | QQuickPinchAreaPrivate * const d = d_func(); | - | ||||||||||||||||||
| 48 | if (a != d->enabled
| 0 | ||||||||||||||||||
| 49 | d->enabled = a; | - | ||||||||||||||||||
| 50 | enabledChanged(); | - | ||||||||||||||||||
| 51 | } never executed: end of block | 0 | ||||||||||||||||||
| 52 | } never executed: end of block | 0 | ||||||||||||||||||
| 53 | - | |||||||||||||||||||
| 54 | void QQuickPinchArea::touchEvent(QTouchEvent *event) | - | ||||||||||||||||||
| 55 | { | - | ||||||||||||||||||
| 56 | QQuickPinchAreaPrivate * const d = d_func(); | - | ||||||||||||||||||
| 57 | if (!d->enabled
| 0-88 | ||||||||||||||||||
| 58 | QQuickItem::touchEvent(event); | - | ||||||||||||||||||
| 59 | return; never executed: return; | 0 | ||||||||||||||||||
| 60 | } | - | ||||||||||||||||||
| 61 | switch (event->type()) { | - | ||||||||||||||||||
| 62 | case executed 16 times by 1 test: QEvent::TouchBegin:case QEvent::TouchBegin:Executed by:
executed 16 times by 1 test: case QEvent::TouchBegin:Executed by:
| 16 | ||||||||||||||||||
| 63 | case executed 54 times by 1 test: QEvent::TouchUpdate:case QEvent::TouchUpdate:Executed by:
executed 54 times by 1 test: case QEvent::TouchUpdate:Executed by:
| 54 | ||||||||||||||||||
| 64 | d->touchPoints.clear(); | - | ||||||||||||||||||
| 65 | for (int i = 0; i < event->touchPoints().count()
| 70-122 | ||||||||||||||||||
| 66 | if (!(event->touchPoints().at(i).state() & Qt::TouchPointReleased)
| 2-120 | ||||||||||||||||||
| 67 | d->touchPoints << event->touchPoints().at(i); | - | ||||||||||||||||||
| 68 | } executed 120 times by 1 test: end of blockExecuted by:
| 120 | ||||||||||||||||||
| 69 | } executed 122 times by 1 test: end of blockExecuted by:
| 122 | ||||||||||||||||||
| 70 | updatePinch(); | - | ||||||||||||||||||
| 71 | break; executed 70 times by 1 test: break;Executed by:
| 70 | ||||||||||||||||||
| 72 | case executed 14 times by 1 test: QEvent::TouchEnd:case QEvent::TouchEnd:Executed by:
executed 14 times by 1 test: case QEvent::TouchEnd:Executed by:
| 14 | ||||||||||||||||||
| 73 | clearPinch(); | - | ||||||||||||||||||
| 74 | break; executed 14 times by 1 test: break;Executed by:
| 14 | ||||||||||||||||||
| 75 | case executed 4 times by 1 test: QEvent::TouchCancel:case QEvent::TouchCancel:Executed by:
executed 4 times by 1 test: case QEvent::TouchCancel:Executed by:
| 4 | ||||||||||||||||||
| 76 | cancelPinch(); | - | ||||||||||||||||||
| 77 | break; executed 4 times by 1 test: break;Executed by:
| 4 | ||||||||||||||||||
| 78 | default never executed: :default:never executed: default: | 0 | ||||||||||||||||||
| 79 | QQuickItem::touchEvent(event); | - | ||||||||||||||||||
| 80 | } never executed: end of block | 0 | ||||||||||||||||||
| 81 | } | - | ||||||||||||||||||
| 82 | - | |||||||||||||||||||
| 83 | void QQuickPinchArea::clearPinch() | - | ||||||||||||||||||
| 84 | { | - | ||||||||||||||||||
| 85 | QQuickPinchAreaPrivate * const d = d_func(); | - | ||||||||||||||||||
| 86 | - | |||||||||||||||||||
| 87 | d->touchPoints.clear(); | - | ||||||||||||||||||
| 88 | if (d->inPinch
| 2-12 | ||||||||||||||||||
| 89 | d->inPinch = false; | - | ||||||||||||||||||
| 90 | QPointF pinchCenter = mapFromScene(d->sceneLastCenter); | - | ||||||||||||||||||
| 91 | QQuickPinchEvent pe(pinchCenter, d->pinchLastScale, d->pinchLastAngle, d->pinchRotation); | - | ||||||||||||||||||
| 92 | pe.setStartCenter(d->pinchStartCenter); | - | ||||||||||||||||||
| 93 | pe.setPreviousCenter(pinchCenter); | - | ||||||||||||||||||
| 94 | pe.setPreviousAngle(d->pinchLastAngle); | - | ||||||||||||||||||
| 95 | pe.setPreviousScale(d->pinchLastScale); | - | ||||||||||||||||||
| 96 | pe.setStartPoint1(mapFromScene(d->sceneStartPoint1)); | - | ||||||||||||||||||
| 97 | pe.setStartPoint2(mapFromScene(d->sceneStartPoint2)); | - | ||||||||||||||||||
| 98 | pe.setPoint1(mapFromScene(d->lastPoint1)); | - | ||||||||||||||||||
| 99 | pe.setPoint2(mapFromScene(d->lastPoint2)); | - | ||||||||||||||||||
| 100 | pinchFinished(&pe); | - | ||||||||||||||||||
| 101 | if (d->pinch
| 0-12 | ||||||||||||||||||
| 102 | d->pinch->setActive(false); executed 12 times by 1 test: d->pinch->setActive(false);Executed by:
| 12 | ||||||||||||||||||
| 103 | } executed 12 times by 1 test: end of blockExecuted by:
| 12 | ||||||||||||||||||
| 104 | d->pinchStartDist = 0; | - | ||||||||||||||||||
| 105 | d->pinchActivated = false; | - | ||||||||||||||||||
| 106 | d->initPinch = false; | - | ||||||||||||||||||
| 107 | d->pinchRejected = false; | - | ||||||||||||||||||
| 108 | d->stealMouse = false; | - | ||||||||||||||||||
| 109 | d->id1 = -1; | - | ||||||||||||||||||
| 110 | QQuickWindow *win = window(); | - | ||||||||||||||||||
| 111 | if (win
| 0-14 | ||||||||||||||||||
| 112 | ungrabMouse(); executed 12 times by 1 test: ungrabMouse();Executed by:
| 12 | ||||||||||||||||||
| 113 | setKeepMouseGrab(false); | - | ||||||||||||||||||
| 114 | } executed 14 times by 1 test: end of blockExecuted by:
| 14 | ||||||||||||||||||
| 115 | - | |||||||||||||||||||
| 116 | void QQuickPinchArea::cancelPinch() | - | ||||||||||||||||||
| 117 | { | - | ||||||||||||||||||
| 118 | QQuickPinchAreaPrivate * const d = d_func(); | - | ||||||||||||||||||
| 119 | - | |||||||||||||||||||
| 120 | d->touchPoints.clear(); | - | ||||||||||||||||||
| 121 | if (d->inPinch
| 2 | ||||||||||||||||||
| 122 | d->inPinch = false; | - | ||||||||||||||||||
| 123 | QPointF pinchCenter = mapFromScene(d->sceneLastCenter); | - | ||||||||||||||||||
| 124 | QQuickPinchEvent pe(d->pinchStartCenter, d->pinchStartScale, d->pinchStartAngle, d->pinchStartRotation); | - | ||||||||||||||||||
| 125 | pe.setStartCenter(d->pinchStartCenter); | - | ||||||||||||||||||
| 126 | pe.setPreviousCenter(pinchCenter); | - | ||||||||||||||||||
| 127 | pe.setPreviousAngle(d->pinchLastAngle); | - | ||||||||||||||||||
| 128 | pe.setPreviousScale(d->pinchLastScale); | - | ||||||||||||||||||
| 129 | pe.setStartPoint1(mapFromScene(d->sceneStartPoint1)); | - | ||||||||||||||||||
| 130 | pe.setStartPoint2(mapFromScene(d->sceneStartPoint2)); | - | ||||||||||||||||||
| 131 | pe.setPoint1(pe.startPoint1()); | - | ||||||||||||||||||
| 132 | pe.setPoint2(pe.startPoint2()); | - | ||||||||||||||||||
| 133 | pinchFinished(&pe); | - | ||||||||||||||||||
| 134 | - | |||||||||||||||||||
| 135 | d->pinchLastScale = d->pinchStartScale; | - | ||||||||||||||||||
| 136 | d->sceneLastCenter = d->sceneStartCenter; | - | ||||||||||||||||||
| 137 | d->pinchLastAngle = d->pinchStartAngle; | - | ||||||||||||||||||
| 138 | d->lastPoint1 = pe.startPoint1(); | - | ||||||||||||||||||
| 139 | d->lastPoint2 = pe.startPoint2(); | - | ||||||||||||||||||
| 140 | updatePinchTarget(); | - | ||||||||||||||||||
| 141 | - | |||||||||||||||||||
| 142 | if (d->pinch
| 0-2 | ||||||||||||||||||
| 143 | d->pinch->setActive(false); executed 2 times by 1 test: d->pinch->setActive(false);Executed by:
| 2 | ||||||||||||||||||
| 144 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||
| 145 | d->pinchStartDist = 0; | - | ||||||||||||||||||
| 146 | d->pinchActivated = false; | - | ||||||||||||||||||
| 147 | d->initPinch = false; | - | ||||||||||||||||||
| 148 | d->pinchRejected = false; | - | ||||||||||||||||||
| 149 | d->stealMouse = false; | - | ||||||||||||||||||
| 150 | d->id1 = -1; | - | ||||||||||||||||||
| 151 | QQuickWindow *win = window(); | - | ||||||||||||||||||
| 152 | if (win
| 0-4 | ||||||||||||||||||
| 153 | ungrabMouse(); never executed: ungrabMouse(); | 0 | ||||||||||||||||||
| 154 | setKeepMouseGrab(false); | - | ||||||||||||||||||
| 155 | } executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||||||||||||||
| 156 | - | |||||||||||||||||||
| 157 | void QQuickPinchArea::updatePinch() | - | ||||||||||||||||||
| 158 | { | - | ||||||||||||||||||
| 159 | QQuickPinchAreaPrivate * const d = d_func(); | - | ||||||||||||||||||
| 160 | - | |||||||||||||||||||
| 161 | QQuickWindow *win = window(); | - | ||||||||||||||||||
| 162 | - | |||||||||||||||||||
| 163 | if (d->touchPoints.count() < 2
| 20-50 | ||||||||||||||||||
| 164 | setKeepMouseGrab(false); | - | ||||||||||||||||||
| 165 | QQuickWindow *c = window(); | - | ||||||||||||||||||
| 166 | if (c
| 0-20 | ||||||||||||||||||
| 167 | ungrabMouse(); executed 2 times by 1 test: ungrabMouse();Executed by:
| 2 | ||||||||||||||||||
| 168 | } executed 20 times by 1 test: end of blockExecuted by:
| 20 | ||||||||||||||||||
| 169 | - | |||||||||||||||||||
| 170 | if (d->touchPoints.count() == 0
| 0-70 | ||||||||||||||||||
| 171 | if (d->inPinch
| 0 | ||||||||||||||||||
| 172 | d->inPinch = false; | - | ||||||||||||||||||
| 173 | QPointF pinchCenter = mapFromScene(d->sceneLastCenter); | - | ||||||||||||||||||
| 174 | QQuickPinchEvent pe(pinchCenter, d->pinchLastScale, d->pinchLastAngle, d->pinchRotation); | - | ||||||||||||||||||
| 175 | pe.setStartCenter(d->pinchStartCenter); | - | ||||||||||||||||||
| 176 | pe.setPreviousCenter(pinchCenter); | - | ||||||||||||||||||
| 177 | pe.setPreviousAngle(d->pinchLastAngle); | - | ||||||||||||||||||
| 178 | pe.setPreviousScale(d->pinchLastScale); | - | ||||||||||||||||||
| 179 | pe.setStartPoint1(mapFromScene(d->sceneStartPoint1)); | - | ||||||||||||||||||
| 180 | pe.setStartPoint2(mapFromScene(d->sceneStartPoint2)); | - | ||||||||||||||||||
| 181 | pe.setPoint1(mapFromScene(d->lastPoint1)); | - | ||||||||||||||||||
| 182 | pe.setPoint2(mapFromScene(d->lastPoint2)); | - | ||||||||||||||||||
| 183 | pinchFinished(&pe); | - | ||||||||||||||||||
| 184 | d->pinchStartDist = 0; | - | ||||||||||||||||||
| 185 | d->pinchActivated = false; | - | ||||||||||||||||||
| 186 | if (d->pinch
| 0 | ||||||||||||||||||
| 187 | d->pinch->setActive(false); never executed: d->pinch->setActive(false); | 0 | ||||||||||||||||||
| 188 | } never executed: end of block | 0 | ||||||||||||||||||
| 189 | d->initPinch = false; | - | ||||||||||||||||||
| 190 | d->pinchRejected = false; | - | ||||||||||||||||||
| 191 | d->stealMouse = false; | - | ||||||||||||||||||
| 192 | return; never executed: return; | 0 | ||||||||||||||||||
| 193 | } | - | ||||||||||||||||||
| 194 | - | |||||||||||||||||||
| 195 | QTouchEvent::TouchPoint touchPoint1 = d->touchPoints.at(0); | - | ||||||||||||||||||
| 196 | QTouchEvent::TouchPoint touchPoint2 = d->touchPoints.at(d->touchPoints. count() >= 2 ? 1 : 0); | - | ||||||||||||||||||
| 197 | - | |||||||||||||||||||
| 198 | if (touchPoint1.state() == Qt::TouchPointPressed
| 16-54 | ||||||||||||||||||
| 199 | d->sceneStartPoint1 = touchPoint1.scenePos(); executed 16 times by 1 test: d->sceneStartPoint1 = touchPoint1.scenePos();Executed by:
| 16 | ||||||||||||||||||
| 200 | - | |||||||||||||||||||
| 201 | if (touchPoint2.state() == Qt::TouchPointPressed
| 32-38 | ||||||||||||||||||
| 202 | d->sceneStartPoint2 = touchPoint2.scenePos(); executed 32 times by 1 test: d->sceneStartPoint2 = touchPoint2.scenePos();Executed by:
| 32 | ||||||||||||||||||
| 203 | - | |||||||||||||||||||
| 204 | QRectF bounds = clipRect(); | - | ||||||||||||||||||
| 205 | - | |||||||||||||||||||
| 206 | - | |||||||||||||||||||
| 207 | - | |||||||||||||||||||
| 208 | if (d->touchPoints.count() == 2
| 20-50 | ||||||||||||||||||
| 209 | && (touchPoint1.state() & Qt::TouchPointPressed
| 0-50 | ||||||||||||||||||
| 210 | bounds.contains(touchPoint1.pos())
| 0-16 | ||||||||||||||||||
| 211 | d->id1 = touchPoint1.id(); | - | ||||||||||||||||||
| 212 | d->pinchActivated = true; | - | ||||||||||||||||||
| 213 | d->initPinch = true; | - | ||||||||||||||||||
| 214 | - | |||||||||||||||||||
| 215 | int touchMouseId = QQuickWindowPrivate::get(win)->touchMouseId; | - | ||||||||||||||||||
| 216 | if (touchPoint1.id() == touchMouseId
| 0-16 | ||||||||||||||||||
| 217 | if (win
| 0 | ||||||||||||||||||
| 218 | grabMouse(); | - | ||||||||||||||||||
| 219 | } never executed: end of block | 0 | ||||||||||||||||||
| 220 | } never executed: end of block | 0 | ||||||||||||||||||
| 221 | } executed 16 times by 1 test: end of blockExecuted by:
| 16 | ||||||||||||||||||
| 222 | if (d->pinchActivated
| 0-52 | ||||||||||||||||||
| 223 | const int dragThreshold = QGuiApplication::styleHints()->startDragDistance(); | - | ||||||||||||||||||
| 224 | QPointF p1 = touchPoint1.scenePos(); | - | ||||||||||||||||||
| 225 | QPointF p2 = touchPoint2.scenePos(); | - | ||||||||||||||||||
| 226 | qreal dx = p1.x() - p2.x(); | - | ||||||||||||||||||
| 227 | qreal dy = p1.y() - p2.y(); | - | ||||||||||||||||||
| 228 | qreal dist = qSqrt(dx*dx + dy*dy); | - | ||||||||||||||||||
| 229 | QPointF sceneCenter = (p1 + p2)/2; | - | ||||||||||||||||||
| 230 | qreal angle = QLineF(p1, p2).angle(); | - | ||||||||||||||||||
| 231 | if (d->touchPoints.count() == 1
| 2-50 | ||||||||||||||||||
| 232 | - | |||||||||||||||||||
| 233 | if (d->id1 == touchPoint1.id()
| 0-2 | ||||||||||||||||||
| 234 | sceneCenter = d->sceneLastCenter + touchPoint1.scenePos() - d->lastPoint1; executed 2 times by 1 test: sceneCenter = d->sceneLastCenter + touchPoint1.scenePos() - d->lastPoint1;Executed by:
| 2 | ||||||||||||||||||
| 235 | else | - | ||||||||||||||||||
| 236 | sceneCenter = d->sceneLastCenter + touchPoint2.scenePos() - d->lastPoint2; never executed: sceneCenter = d->sceneLastCenter + touchPoint2.scenePos() - d->lastPoint2; | 0 | ||||||||||||||||||
| 237 | angle = d->pinchLastAngle; | - | ||||||||||||||||||
| 238 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||
| 239 | d->id1 = touchPoint1.id(); | - | ||||||||||||||||||
| 240 | if (angle > 180
| 10-42 | ||||||||||||||||||
| 241 | angle -= 360; executed 42 times by 1 test: angle -= 360;Executed by:
| 42 | ||||||||||||||||||
| 242 | if (!d->inPinch
| 2-30 | ||||||||||||||||||
| 243 | if (d->touchPoints.count() >= 2
| 0-32 | ||||||||||||||||||
| 244 | if (d->initPinch
| 16 | ||||||||||||||||||
| 245 | if (!d->inPinch
| 2-14 | ||||||||||||||||||
| 246 | d->pinchStartDist = dist; executed 14 times by 1 test: d->pinchStartDist = dist;Executed by:
| 14 | ||||||||||||||||||
| 247 | d->initPinch = false; | - | ||||||||||||||||||
| 248 | } executed 16 times by 1 test: end of blockExecuted by:
| 16 | ||||||||||||||||||
| 249 | d->sceneStartCenter = sceneCenter; | - | ||||||||||||||||||
| 250 | d->sceneLastCenter = sceneCenter; | - | ||||||||||||||||||
| 251 | d->pinchStartCenter = mapFromScene(sceneCenter); | - | ||||||||||||||||||
| 252 | d->pinchStartAngle = angle; | - | ||||||||||||||||||
| 253 | d->pinchLastScale = 1.0; | - | ||||||||||||||||||
| 254 | d->pinchLastAngle = angle; | - | ||||||||||||||||||
| 255 | d->pinchRotation = 0.0; | - | ||||||||||||||||||
| 256 | d->lastPoint1 = p1; | - | ||||||||||||||||||
| 257 | d->lastPoint2 = p2; | - | ||||||||||||||||||
| 258 | if (qAbs(dist - d->pinchStartDist) >= dragThreshold
| 12-20 | ||||||||||||||||||
| 259 | (pinch()->axis() != QQuickPinch::NoDrag
| 0-20 | ||||||||||||||||||
| 260 | (qAbs(p1.x()-d->sceneStartPoint1.x()) >= dragThreshold
| 2-18 | ||||||||||||||||||
| 261 | || qAbs(p1.y()-d->sceneStartPoint1.y()) >= dragThreshold
| 0-18 | ||||||||||||||||||
| 262 | || qAbs(p2.x()-d->sceneStartPoint2.x()) >= dragThreshold
| 2-16 | ||||||||||||||||||
| 263 | || qAbs(p2.y()-d->sceneStartPoint2.y()) >= dragThreshold
| 0-16 | ||||||||||||||||||
| 264 | QQuickPinchEvent pe(d->pinchStartCenter, 1.0, angle, 0.0); | - | ||||||||||||||||||
| 265 | d->pinchStartDist = dist; | - | ||||||||||||||||||
| 266 | pe.setStartCenter(d->pinchStartCenter); | - | ||||||||||||||||||
| 267 | pe.setPreviousCenter(d->pinchStartCenter); | - | ||||||||||||||||||
| 268 | pe.setPreviousAngle(d->pinchLastAngle); | - | ||||||||||||||||||
| 269 | pe.setPreviousScale(d->pinchLastScale); | - | ||||||||||||||||||
| 270 | pe.setStartPoint1(mapFromScene(d->sceneStartPoint1)); | - | ||||||||||||||||||
| 271 | pe.setStartPoint2(mapFromScene(d->sceneStartPoint2)); | - | ||||||||||||||||||
| 272 | pe.setPoint1(mapFromScene(d->lastPoint1)); | - | ||||||||||||||||||
| 273 | pe.setPoint2(mapFromScene(d->lastPoint2)); | - | ||||||||||||||||||
| 274 | pe.setPointCount(d->touchPoints.count()); | - | ||||||||||||||||||
| 275 | pinchStarted(&pe); | - | ||||||||||||||||||
| 276 | if (pe.accepted()
| 0-16 | ||||||||||||||||||
| 277 | d->inPinch = true; | - | ||||||||||||||||||
| 278 | d->stealMouse = true; | - | ||||||||||||||||||
| 279 | if (win
| 0-16 | ||||||||||||||||||
| 280 | grabMouse(); executed 16 times by 1 test: grabMouse();Executed by:
| 16 | ||||||||||||||||||
| 281 | setKeepMouseGrab(true); | - | ||||||||||||||||||
| 282 | grabTouchPoints(QVector<int>() << touchPoint1.id() << touchPoint2.id()); | - | ||||||||||||||||||
| 283 | d->inPinch = true; | - | ||||||||||||||||||
| 284 | d->stealMouse = true; | - | ||||||||||||||||||
| 285 | if (d->pinch
| 0-16 | ||||||||||||||||||
| 286 | d->pinchStartPos = pinch()->target()->position(); | - | ||||||||||||||||||
| 287 | d->pinchStartScale = d->pinch->target()->scale(); | - | ||||||||||||||||||
| 288 | d->pinchStartRotation = d->pinch->target()->rotation(); | - | ||||||||||||||||||
| 289 | d->pinch->setActive(true); | - | ||||||||||||||||||
| 290 | } executed 16 times by 1 test: end of blockExecuted by:
| 16 | ||||||||||||||||||
| 291 | } executed 16 times by 1 test: else {end of blockExecuted by:
| 16 | ||||||||||||||||||
| 292 | d->pinchRejected = true; | - | ||||||||||||||||||
| 293 | } never executed: end of block | 0 | ||||||||||||||||||
| 294 | } | - | ||||||||||||||||||
| 295 | } executed 32 times by 1 test: end of blockExecuted by:
| 32 | ||||||||||||||||||
| 296 | } executed 32 times by 1 test: else if (d->pinchStartDist > 0end of blockExecuted by:
| 0-32 | ||||||||||||||||||
| 297 | qreal scale = dist
| 2-18 | ||||||||||||||||||
| 298 | qreal da = d->pinchLastAngle - angle; | - | ||||||||||||||||||
| 299 | if (da > 180
| 0-20 | ||||||||||||||||||
| 300 | da -= 360; never executed: da -= 360; | 0 | ||||||||||||||||||
| 301 | else if (da < -180
| 0-20 | ||||||||||||||||||
| 302 | da += 360; never executed: da += 360; | 0 | ||||||||||||||||||
| 303 | d->pinchRotation += da; | - | ||||||||||||||||||
| 304 | QPointF pinchCenter = mapFromScene(sceneCenter); | - | ||||||||||||||||||
| 305 | QQuickPinchEvent pe(pinchCenter, scale, angle, d->pinchRotation); | - | ||||||||||||||||||
| 306 | pe.setStartCenter(d->pinchStartCenter); | - | ||||||||||||||||||
| 307 | pe.setPreviousCenter(mapFromScene(d->sceneLastCenter)); | - | ||||||||||||||||||
| 308 | pe.setPreviousAngle(d->pinchLastAngle); | - | ||||||||||||||||||
| 309 | pe.setPreviousScale(d->pinchLastScale); | - | ||||||||||||||||||
| 310 | pe.setStartPoint1(mapFromScene(d->sceneStartPoint1)); | - | ||||||||||||||||||
| 311 | pe.setStartPoint2(mapFromScene(d->sceneStartPoint2)); | - | ||||||||||||||||||
| 312 | pe.setPoint1(touchPoint1.pos()); | - | ||||||||||||||||||
| 313 | pe.setPoint2(touchPoint2.pos()); | - | ||||||||||||||||||
| 314 | pe.setPointCount(d->touchPoints.count()); | - | ||||||||||||||||||
| 315 | d->pinchLastScale = scale; | - | ||||||||||||||||||
| 316 | d->sceneLastCenter = sceneCenter; | - | ||||||||||||||||||
| 317 | d->pinchLastAngle = angle; | - | ||||||||||||||||||
| 318 | d->lastPoint1 = touchPoint1.scenePos(); | - | ||||||||||||||||||
| 319 | d->lastPoint2 = touchPoint2.scenePos(); | - | ||||||||||||||||||
| 320 | pinchUpdated(&pe); | - | ||||||||||||||||||
| 321 | updatePinchTarget(); | - | ||||||||||||||||||
| 322 | } executed 20 times by 1 test: end of blockExecuted by:
| 20 | ||||||||||||||||||
| 323 | } executed 52 times by 1 test: end of blockExecuted by:
| 52 | ||||||||||||||||||
| 324 | } executed 70 times by 1 test: end of blockExecuted by:
| 70 | ||||||||||||||||||
| 325 | - | |||||||||||||||||||
| 326 | void QQuickPinchArea::updatePinchTarget() | - | ||||||||||||||||||
| 327 | { | - | ||||||||||||||||||
| 328 | QQuickPinchAreaPrivate * const d = d_func(); | - | ||||||||||||||||||
| 329 | if (d->pinch
| 0-22 | ||||||||||||||||||
| 330 | qreal s = d->pinchStartScale * d->pinchLastScale; | - | ||||||||||||||||||
| 331 | s = qMin(qMax(pinch()->minimumScale(),s), pinch()->maximumScale()); | - | ||||||||||||||||||
| 332 | pinch()->target()->setScale(s); | - | ||||||||||||||||||
| 333 | QPointF pos = d->sceneLastCenter - d->sceneStartCenter + d->pinchStartPos; | - | ||||||||||||||||||
| 334 | if (pinch()->axis() & QQuickPinch::XAxis
| 0-22 | ||||||||||||||||||
| 335 | qreal x = pos.x(); | - | ||||||||||||||||||
| 336 | if (x < pinch()->xmin()
| 0-22 | ||||||||||||||||||
| 337 | x = pinch()->xmin(); never executed: x = pinch()->xmin(); | 0 | ||||||||||||||||||
| 338 | else if (x > pinch()->xmax()
| 2-20 | ||||||||||||||||||
| 339 | x = pinch()->xmax(); executed 2 times by 1 test: x = pinch()->xmax();Executed by:
| 2 | ||||||||||||||||||
| 340 | pinch()->target()->setX(x); | - | ||||||||||||||||||
| 341 | } executed 22 times by 1 test: end of blockExecuted by:
| 22 | ||||||||||||||||||
| 342 | if (pinch()->axis() & QQuickPinch::YAxis
| 0-22 | ||||||||||||||||||
| 343 | qreal y = pos.y(); | - | ||||||||||||||||||
| 344 | if (y < pinch()->ymin()
| 0-22 | ||||||||||||||||||
| 345 | y = pinch()->ymin(); never executed: y = pinch()->ymin(); | 0 | ||||||||||||||||||
| 346 | else if (y > pinch()->ymax()
| 0-22 | ||||||||||||||||||
| 347 | y = pinch()->ymax(); never executed: y = pinch()->ymax(); | 0 | ||||||||||||||||||
| 348 | pinch()->target()->setY(y); | - | ||||||||||||||||||
| 349 | } executed 22 times by 1 test: end of blockExecuted by:
| 22 | ||||||||||||||||||
| 350 | if (d->pinchStartRotation >= pinch()->minimumRotation()
| 0-22 | ||||||||||||||||||
| 351 | && d->pinchStartRotation <= pinch()->maximumRotation()
| 0-22 | ||||||||||||||||||
| 352 | qreal r = d->pinchRotation + d->pinchStartRotation; | - | ||||||||||||||||||
| 353 | r = qMin(qMax(pinch()->minimumRotation(),r), pinch()->maximumRotation()); | - | ||||||||||||||||||
| 354 | pinch()->target()->setRotation(r); | - | ||||||||||||||||||
| 355 | } executed 22 times by 1 test: end of blockExecuted by:
| 22 | ||||||||||||||||||
| 356 | } executed 22 times by 1 test: end of blockExecuted by:
| 22 | ||||||||||||||||||
| 357 | } executed 22 times by 1 test: end of blockExecuted by:
| 22 | ||||||||||||||||||
| 358 | - | |||||||||||||||||||
| 359 | bool QQuickPinchArea::childMouseEventFilter(QQuickItem *i, QEvent *e) | - | ||||||||||||||||||
| 360 | { | - | ||||||||||||||||||
| 361 | QQuickPinchAreaPrivate * const d = d_func(); | - | ||||||||||||||||||
| 362 | if (!d->enabled
| 0 | ||||||||||||||||||
| 363 | return never executed: QQuickItem::childMouseEventFilter(i, e);return QQuickItem::childMouseEventFilter(i, e);never executed: return QQuickItem::childMouseEventFilter(i, e); | 0 | ||||||||||||||||||
| 364 | switch (e->type()) { | - | ||||||||||||||||||
| 365 | case never executed: QEvent::TouchBegin:case QEvent::TouchBegin:never executed: case QEvent::TouchBegin: | 0 | ||||||||||||||||||
| 366 | clearPinch(); | - | ||||||||||||||||||
| 367 | (void)0; | - | ||||||||||||||||||
| 368 | case never executed: QEvent::TouchUpdate:case QEvent::TouchUpdate:never executed: case QEvent::TouchUpdate:code before this statement never executed: {case QEvent::TouchUpdate: | 0 | ||||||||||||||||||
| 369 | QTouchEvent *touch = static_cast<QTouchEvent*>(e); | - | ||||||||||||||||||
| 370 | d->touchPoints.clear(); | - | ||||||||||||||||||
| 371 | for (int i = 0; i < touch->touchPoints().count()
| 0 | ||||||||||||||||||
| 372 | if (!(touch->touchPoints().at(i).state() & Qt::TouchPointReleased)
| 0 | ||||||||||||||||||
| 373 | d->touchPoints << touch->touchPoints().at(i); never executed: d->touchPoints << touch->touchPoints().at(i); | 0 | ||||||||||||||||||
| 374 | updatePinch(); | - | ||||||||||||||||||
| 375 | } | - | ||||||||||||||||||
| 376 | e->setAccepted(d->inPinch); | - | ||||||||||||||||||
| 377 | return never executed: d->inPinch;return d->inPinch;never executed: return d->inPinch; | 0 | ||||||||||||||||||
| 378 | case never executed: QEvent::TouchEnd:case QEvent::TouchEnd:never executed: case QEvent::TouchEnd: | 0 | ||||||||||||||||||
| 379 | clearPinch(); | - | ||||||||||||||||||
| 380 | break; never executed: break; | 0 | ||||||||||||||||||
| 381 | default never executed: :default:never executed: default: | 0 | ||||||||||||||||||
| 382 | break; never executed: break; | 0 | ||||||||||||||||||
| 383 | } | - | ||||||||||||||||||
| 384 | - | |||||||||||||||||||
| 385 | return never executed: QQuickItem::childMouseEventFilter(i, e);return QQuickItem::childMouseEventFilter(i, e);never executed: return QQuickItem::childMouseEventFilter(i, e); | 0 | ||||||||||||||||||
| 386 | } | - | ||||||||||||||||||
| 387 | - | |||||||||||||||||||
| 388 | void QQuickPinchArea::geometryChanged(const QRectF &newGeometry, | - | ||||||||||||||||||
| 389 | const QRectF &oldGeometry) | - | ||||||||||||||||||
| 390 | { | - | ||||||||||||||||||
| 391 | QQuickItem::geometryChanged(newGeometry, oldGeometry); | - | ||||||||||||||||||
| 392 | } executed 36 times by 3 tests: end of blockExecuted by:
| 36 | ||||||||||||||||||
| 393 | - | |||||||||||||||||||
| 394 | void QQuickPinchArea::itemChange(ItemChange change, const ItemChangeData &value) | - | ||||||||||||||||||
| 395 | { | - | ||||||||||||||||||
| 396 | QQuickItem::itemChange(change, value); | - | ||||||||||||||||||
| 397 | } executed 134 times by 3 tests: end of blockExecuted by:
| 134 | ||||||||||||||||||
| 398 | - | |||||||||||||||||||
| 399 | bool QQuickPinchArea::event(QEvent *event) | - | ||||||||||||||||||
| 400 | { | - | ||||||||||||||||||
| 401 | QQuickPinchAreaPrivate * const d = d_func(); | - | ||||||||||||||||||
| 402 | if (!d->enabled
| 0-88 | ||||||||||||||||||
| 403 | return never executed: QQuickItem::event(event);return QQuickItem::event(event);never executed: return QQuickItem::event(event); | 0 | ||||||||||||||||||
| 404 | - | |||||||||||||||||||
| 405 | switch (event->type()) { | - | ||||||||||||||||||
| 406 | - | |||||||||||||||||||
| 407 | case never executed: QEvent::NativeGesture:case QEvent::NativeGesture:never executed: {case QEvent::NativeGesture: | 0 | ||||||||||||||||||
| 408 | QNativeGestureEvent *gesture = static_cast<QNativeGestureEvent *>(event); | - | ||||||||||||||||||
| 409 | switch (gesture->gestureType()) { | - | ||||||||||||||||||
| 410 | case never executed: Qt::BeginNativeGesture:case Qt::BeginNativeGesture:never executed: case Qt::BeginNativeGesture: | 0 | ||||||||||||||||||
| 411 | clearPinch(); | - | ||||||||||||||||||
| 412 | d->pinchStartCenter = gesture->localPos(); | - | ||||||||||||||||||
| 413 | d->pinchStartAngle = 0.0; | - | ||||||||||||||||||
| 414 | d->pinchStartRotation = 0.0; | - | ||||||||||||||||||
| 415 | d->pinchRotation = 0.0; | - | ||||||||||||||||||
| 416 | d->pinchStartScale = 1.0; | - | ||||||||||||||||||
| 417 | d->pinchLastAngle = 0.0; | - | ||||||||||||||||||
| 418 | d->pinchLastScale = 1.0; | - | ||||||||||||||||||
| 419 | d->sceneStartPoint1 = gesture->windowPos(); | - | ||||||||||||||||||
| 420 | d->sceneStartPoint2 = gesture->windowPos(); | - | ||||||||||||||||||
| 421 | d->lastPoint1 = gesture->windowPos(); | - | ||||||||||||||||||
| 422 | d->lastPoint2 = gesture->windowPos(); | - | ||||||||||||||||||
| 423 | if (d->pinch
| 0 | ||||||||||||||||||
| 424 | d->pinchStartPos = d->pinch->target()->position(); | - | ||||||||||||||||||
| 425 | d->pinchStartScale = d->pinch->target()->scale(); | - | ||||||||||||||||||
| 426 | d->pinchStartRotation = d->pinch->target()->rotation(); | - | ||||||||||||||||||
| 427 | d->pinch->setActive(true); | - | ||||||||||||||||||
| 428 | } never executed: end of block | 0 | ||||||||||||||||||
| 429 | break; never executed: break; | 0 | ||||||||||||||||||
| 430 | case never executed: Qt::EndNativeGesture:case Qt::EndNativeGesture:never executed: case Qt::EndNativeGesture: | 0 | ||||||||||||||||||
| 431 | clearPinch(); | - | ||||||||||||||||||
| 432 | break; never executed: break; | 0 | ||||||||||||||||||
| 433 | case never executed: Qt::ZoomNativeGesture:case Qt::ZoomNativeGesture:never executed: {case Qt::ZoomNativeGesture: | 0 | ||||||||||||||||||
| 434 | qreal scale = d->pinchLastScale * (1.0 + gesture->value()); | - | ||||||||||||||||||
| 435 | QQuickPinchEvent pe(d->pinchStartCenter, scale, d->pinchLastAngle, 0.0); | - | ||||||||||||||||||
| 436 | pe.setStartCenter(d->pinchStartCenter); | - | ||||||||||||||||||
| 437 | pe.setPreviousCenter(d->pinchStartCenter); | - | ||||||||||||||||||
| 438 | pe.setPreviousAngle(d->pinchLastAngle); | - | ||||||||||||||||||
| 439 | pe.setPreviousScale(d->pinchLastScale); | - | ||||||||||||||||||
| 440 | pe.setStartPoint1(mapFromScene(d->sceneStartPoint1)); | - | ||||||||||||||||||
| 441 | pe.setStartPoint2(mapFromScene(d->sceneStartPoint2)); | - | ||||||||||||||||||
| 442 | pe.setPoint1(mapFromScene(d->lastPoint1)); | - | ||||||||||||||||||
| 443 | pe.setPoint2(mapFromScene(d->lastPoint2)); | - | ||||||||||||||||||
| 444 | pe.setPointCount(2); | - | ||||||||||||||||||
| 445 | d->pinchLastScale = scale; | - | ||||||||||||||||||
| 446 | if (d->inPinch
| 0 | ||||||||||||||||||
| 447 | pinchUpdated(&pe); never executed: pinchUpdated(&pe); | 0 | ||||||||||||||||||
| 448 | else | - | ||||||||||||||||||
| 449 | pinchStarted(&pe); never executed: pinchStarted(&pe); | 0 | ||||||||||||||||||
| 450 | d->inPinch = true; | - | ||||||||||||||||||
| 451 | updatePinchTarget(); | - | ||||||||||||||||||
| 452 | } break; never executed: break; | 0 | ||||||||||||||||||
| 453 | case never executed: Qt::SmartZoomNativeGesture:case Qt::SmartZoomNativeGesture:never executed: {case Qt::SmartZoomNativeGesture: | 0 | ||||||||||||||||||
| 454 | if (gesture->value() > 0.0
| 0 | ||||||||||||||||||
| 455 | d->pinchStartPos = pinch()->target()->position(); | - | ||||||||||||||||||
| 456 | d->pinchStartCenter = mapToItem(pinch()->target()->parentItem(), pinch()->target()->boundingRect().center()); | - | ||||||||||||||||||
| 457 | d->pinchStartScale = d->pinch->target()->scale(); | - | ||||||||||||||||||
| 458 | d->pinchStartRotation = d->pinch->target()->rotation(); | - | ||||||||||||||||||
| 459 | d->pinchLastScale = d->pinchStartScale = d->pinch->target()->scale(); | - | ||||||||||||||||||
| 460 | d->pinchLastAngle = d->pinchStartRotation = d->pinch->target()->rotation(); | - | ||||||||||||||||||
| 461 | } never executed: end of block | 0 | ||||||||||||||||||
| 462 | QQuickPinchEvent pe(gesture->localPos(), gesture->value(), d->pinchLastAngle, 0.0); | - | ||||||||||||||||||
| 463 | pe.setStartCenter(gesture->localPos()); | - | ||||||||||||||||||
| 464 | pe.setPreviousCenter(d->pinchStartCenter); | - | ||||||||||||||||||
| 465 | pe.setPreviousAngle(d->pinchLastAngle); | - | ||||||||||||||||||
| 466 | pe.setPreviousScale(d->pinchLastScale); | - | ||||||||||||||||||
| 467 | pe.setStartPoint1(gesture->localPos()); | - | ||||||||||||||||||
| 468 | pe.setStartPoint2(gesture->localPos()); | - | ||||||||||||||||||
| 469 | pe.setPoint1(mapFromScene(gesture->windowPos())); | - | ||||||||||||||||||
| 470 | pe.setPoint2(mapFromScene(gesture->windowPos())); | - | ||||||||||||||||||
| 471 | pe.setPointCount(2); | - | ||||||||||||||||||
| 472 | smartZoom(&pe); | - | ||||||||||||||||||
| 473 | } break; never executed: break; | 0 | ||||||||||||||||||
| 474 | case never executed: Qt::RotateNativeGesture:case Qt::RotateNativeGesture:never executed: {case Qt::RotateNativeGesture: | 0 | ||||||||||||||||||
| 475 | qreal angle = d->pinchLastAngle + gesture->value(); | - | ||||||||||||||||||
| 476 | QQuickPinchEvent pe(d->pinchStartCenter, d->pinchLastScale, angle, 0.0); | - | ||||||||||||||||||
| 477 | pe.setStartCenter(d->pinchStartCenter); | - | ||||||||||||||||||
| 478 | pe.setPreviousCenter(d->pinchStartCenter); | - | ||||||||||||||||||
| 479 | pe.setPreviousAngle(d->pinchLastAngle); | - | ||||||||||||||||||
| 480 | pe.setPreviousScale(d->pinchLastScale); | - | ||||||||||||||||||
| 481 | pe.setStartPoint1(mapFromScene(d->sceneStartPoint1)); | - | ||||||||||||||||||
| 482 | pe.setStartPoint2(mapFromScene(d->sceneStartPoint2)); | - | ||||||||||||||||||
| 483 | pe.setPoint1(mapFromScene(d->lastPoint1)); | - | ||||||||||||||||||
| 484 | pe.setPoint2(mapFromScene(d->lastPoint2)); | - | ||||||||||||||||||
| 485 | pe.setPointCount(2); | - | ||||||||||||||||||
| 486 | d->pinchLastAngle = angle; | - | ||||||||||||||||||
| 487 | if (d->inPinch
| 0 | ||||||||||||||||||
| 488 | pinchUpdated(&pe); never executed: pinchUpdated(&pe); | 0 | ||||||||||||||||||
| 489 | else | - | ||||||||||||||||||
| 490 | pinchStarted(&pe); never executed: pinchStarted(&pe); | 0 | ||||||||||||||||||
| 491 | d->inPinch = true; | - | ||||||||||||||||||
| 492 | d->pinchRotation = angle; | - | ||||||||||||||||||
| 493 | updatePinchTarget(); | - | ||||||||||||||||||
| 494 | } break; never executed: break; | 0 | ||||||||||||||||||
| 495 | default never executed: :default:never executed: default: | 0 | ||||||||||||||||||
| 496 | return never executed: QQuickItem::event(event);return QQuickItem::event(event);never executed: return QQuickItem::event(event); | 0 | ||||||||||||||||||
| 497 | } | - | ||||||||||||||||||
| 498 | } break; never executed: break; | 0 | ||||||||||||||||||
| 499 | - | |||||||||||||||||||
| 500 | case never executed: QEvent::Wheel:case QEvent::Wheel:never executed: case QEvent::Wheel: | 0 | ||||||||||||||||||
| 501 | event->ignore(); | - | ||||||||||||||||||
| 502 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||
| 503 | default executed 88 times by 1 test: :default:Executed by:
executed 88 times by 1 test: default:Executed by:
| 88 | ||||||||||||||||||
| 504 | return executed 88 times by 1 test: QQuickItem::event(event);return QQuickItem::event(event);Executed by:
executed 88 times by 1 test: return QQuickItem::event(event);Executed by:
| 88 | ||||||||||||||||||
| 505 | } | - | ||||||||||||||||||
| 506 | - | |||||||||||||||||||
| 507 | return never executed: true;return true;never executed: return true; | 0 | ||||||||||||||||||
| 508 | } | - | ||||||||||||||||||
| 509 | - | |||||||||||||||||||
| 510 | QQuickPinch *QQuickPinchArea::pinch() | - | ||||||||||||||||||
| 511 | { | - | ||||||||||||||||||
| 512 | QQuickPinchAreaPrivate * const d = d_func(); | - | ||||||||||||||||||
| 513 | if (!d->pinch
| 30-400 | ||||||||||||||||||
| 514 | d->pinch = new QQuickPinch; executed 30 times by 2 tests: d->pinch = new QQuickPinch;Executed by:
| 30 | ||||||||||||||||||
| 515 | return executed 430 times by 2 tests: d->pinch;return d->pinch;Executed by:
executed 430 times by 2 tests: return d->pinch;Executed by:
| 430 | ||||||||||||||||||
| 516 | } | - | ||||||||||||||||||
| 517 | - | |||||||||||||||||||
| 518 | - | |||||||||||||||||||
| 519 | - | |||||||||||||||||||
| Switch to Source code | Preprocessed file |