OpenCoverage

qquickpinchhandler.cpp

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/quick/handlers/qquickpinchhandler.cpp
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4const QLoggingCategory &lcPinchHandler() { static const QLoggingCategory category("qt.quick.handler.pinch"); return
executed 76 times by 1 test: return category;
Executed by:
  • tst_multipointtoucharea_interop
category;
executed 76 times by 1 test: return category;
Executed by:
  • tst_multipointtoucharea_interop
}
76
5QQuickPinchHandler::QQuickPinchHandler(QObject *parent)-
6 : QQuickMultiPointHandler(parent, 2)-
7 , m_activeScale(1)-
8 , m_accumulatedScale(1)-
9 , m_activeRotation(0)-
10 , m_activeTranslation(0,0)-
11 , m_minimumScale(-qInf())-
12 , m_maximumScale(qInf())-
13 , m_minimumRotation(-qInf())-
14 , m_maximumRotation(qInf())-
15 , m_minimumX(-qInf())-
16 , m_maximumX(qInf())-
17 , m_minimumY(-qInf())-
18 , m_maximumY(qInf())-
19 , m_pinchOrigin(PinchCenter)-
20 , m_startScale(1)-
21 , m_startRotation(0)-
22{-
23}
executed 4 times by 1 test: end of block
Executed by:
  • tst_multipointtoucharea_interop
4
24-
25QQuickPinchHandler::~QQuickPinchHandler()-
26{-
27}-
28-
29-
30-
31-
32-
33-
34-
35void QQuickPinchHandler::setMinimumScale(qreal minimumScale)-
36{-
37 if (m_minimumScale == minimumScale
m_minimumScale == minimumScaleDescription
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • tst_multipointtoucharea_interop
)
0-4
38 return;
never executed: return;
0
39-
40 m_minimumScale = minimumScale;-
41 minimumScaleChanged();-
42}
executed 4 times by 1 test: end of block
Executed by:
  • tst_multipointtoucharea_interop
4
43-
44-
45-
46-
47-
48-
49-
50void QQuickPinchHandler::setMaximumScale(qreal maximumScale)-
51{-
52 if (m_maximumScale == maximumScale
m_maximumScale == maximumScaleDescription
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • tst_multipointtoucharea_interop
)
0-4
53 return;
never executed: return;
0
54-
55 m_maximumScale = maximumScale;-
56 maximumScaleChanged();-
57}
executed 4 times by 1 test: end of block
Executed by:
  • tst_multipointtoucharea_interop
4
58-
59-
60-
61-
62-
63-
64-
65void QQuickPinchHandler::setMinimumRotation(qreal minimumRotation)-
66{-
67 if (m_minimumRotation == minimumRotation
m_minimumRotat...inimumRotationDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
68 return;
never executed: return;
0
69-
70 m_minimumRotation = minimumRotation;-
71 minimumRotationChanged();-
72}
never executed: end of block
0
73-
74-
75-
76-
77-
78-
79-
80void QQuickPinchHandler::setMaximumRotation(qreal maximumRotation)-
81{-
82 if (m_maximumRotation == maximumRotation
m_maximumRotat...aximumRotationDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
83 return;
never executed: return;
0
84-
85 m_maximumRotation = maximumRotation;-
86 maximumRotationChanged();-
87}
never executed: end of block
0
88void QQuickPinchHandler::setPinchOrigin(QQuickPinchHandler::PinchOrigin pinchOrigin)-
89{-
90 if (m_pinchOrigin == pinchOrigin
m_pinchOrigin == pinchOriginDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
91 return;
never executed: return;
0
92-
93 m_pinchOrigin = pinchOrigin;-
94 pinchOriginChanged();-
95}
never executed: end of block
0
96-
97-
98-
99-
100-
101-
102void QQuickPinchHandler::setMinimumX(qreal minX)-
103{-
104 if (m_minimumX == minX
m_minimumX == minXDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
105 return;
never executed: return;
0
106 m_minimumX = minX;-
107 minimumXChanged();-
108}
never executed: end of block
0
109-
110-
111-
112-
113-
114-
115void QQuickPinchHandler::setMaximumX(qreal maxX)-
116{-
117 if (m_maximumX == maxX
m_maximumX == maxXDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
118 return;
never executed: return;
0
119 m_maximumX = maxX;-
120 maximumXChanged();-
121}
never executed: end of block
0
122-
123-
124-
125-
126-
127-
128void QQuickPinchHandler::setMinimumY(qreal minY)-
129{-
130 if (m_minimumY == minY
m_minimumY == minYDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
131 return;
never executed: return;
0
132 m_minimumY = minY;-
133 minimumYChanged();-
134}
never executed: end of block
0
135-
136-
137-
138-
139-
140-
141void QQuickPinchHandler::setMaximumY(qreal maxY)-
142{-
143 if (m_maximumY == maxY
m_maximumY == maxYDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
144 return;
never executed: return;
0
145 m_maximumY = maxY;-
146 maximumYChanged();-
147}
never executed: end of block
0
148-
149bool QQuickPinchHandler::wantsPointerEvent(QQuickPointerEvent *event)-
150{-
151 if (!QQuickMultiPointHandler::wantsPointerEvent(event)
!QQuickMultiPo...erEvent(event)Description
TRUEevaluated 52 times by 1 test
Evaluated by:
  • tst_multipointtoucharea_interop
FALSEevaluated 31 times by 1 test
Evaluated by:
  • tst_multipointtoucharea_interop
)
31-52
152 return
executed 52 times by 1 test: return false;
Executed by:
  • tst_multipointtoucharea_interop
false;
executed 52 times by 1 test: return false;
Executed by:
  • tst_multipointtoucharea_interop
52
153-
154-
155 if (const
const auto ges...GestureEvent()Description
TRUEnever evaluated
FALSEevaluated 31 times by 1 test
Evaluated by:
  • tst_multipointtoucharea_interop
auto gesture = event->asPointerNativeGestureEvent()
const auto ges...GestureEvent()Description
TRUEnever evaluated
FALSEevaluated 31 times by 1 test
Evaluated by:
  • tst_multipointtoucharea_interop
) {
0-31
156 if (minimumPointCount() == 2
minimumPointCount() == 2Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
157 switch (gesture->type()) {-
158 case
never executed: case Qt::BeginNativeGesture:
Qt::BeginNativeGesture:
never executed: case Qt::BeginNativeGesture:
0
159 case
never executed: case Qt::EndNativeGesture:
Qt::EndNativeGesture:
never executed: case Qt::EndNativeGesture:
0
160 case
never executed: case Qt::ZoomNativeGesture:
Qt::ZoomNativeGesture:
never executed: case Qt::ZoomNativeGesture:
0
161 case
never executed: case Qt::RotateNativeGesture:
Qt::RotateNativeGesture:
never executed: case Qt::RotateNativeGesture:
0
162 return
never executed: return parentContains(event->point(0));
parentContains(event->point(0));
never executed: return parentContains(event->point(0));
0
163 default
never executed: default:
:
never executed: default:
0
164 return
never executed: return false;
false;
never executed: return false;
0
165 }-
166 } else {-
167 return
never executed: return false;
false;
never executed: return false;
0
168 }-
169 }-
170-
171-
172 return
executed 31 times by 1 test: return true;
Executed by:
  • tst_multipointtoucharea_interop
true;
executed 31 times by 1 test: return true;
Executed by:
  • tst_multipointtoucharea_interop
31
173}-
174void QQuickPinchHandler::onActiveChanged()-
175{-
176 QQuickMultiPointHandler::onActiveChanged();-
177 if (active()
active()Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • tst_multipointtoucharea_interop
FALSEevaluated 4 times by 1 test
Evaluated by:
  • tst_multipointtoucharea_interop
) {
4
178 m_startMatrix = QMatrix4x4();-
179 m_startAngles = angles(m_centroid.sceneGrabPosition());-
180 m_startDistance = averageTouchPointDistance(m_centroid.sceneGrabPosition());-
181 m_activeRotation = 0;-
182 m_activeTranslation = QVector2D();-
183 if (const
const QQuickItem *t = target()Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • tst_multipointtoucharea_interop
FALSEnever evaluated
QQuickItem *t = target()
const QQuickItem *t = target()Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • tst_multipointtoucharea_interop
FALSEnever evaluated
) {
0-4
184 m_startScale = t->scale();-
185 m_startRotation = t->rotation();-
186 QVector3D xformOrigin(t->transformOriginPoint());-
187 m_startMatrix.translate(t->x(), t->y());-
188 m_startMatrix.translate(xformOrigin);-
189 m_startMatrix.scale(m_startScale);-
190 m_startMatrix.rotate(m_startRotation, 0, 0, -1);-
191 m_startMatrix.translate(-xformOrigin);-
192 }
executed 4 times by 1 test: end of block
Executed by:
  • tst_multipointtoucharea_interop
else {
4
193 m_startScale = m_accumulatedScale;-
194 m_startRotation = 0;-
195 }
never executed: end of block
0
196 for (bool qt_category_enabled = lcPinchHandler().isInfoEnabled(); qt_category_enabled
qt_category_enabledDescription
TRUEevaluated 4 times by 1 test
Evaluated by:
  • tst_multipointtoucharea_interop
FALSEevaluated 4 times by 1 test
Evaluated by:
  • tst_multipointtoucharea_interop
; qt_category_enabled = false) QMessageLogger(__FILE__, 311, __PRETTY_FUNCTION__, lcPinchHandler().categoryName()).info() << "activated with starting scale" << m_startScale << "rotation" << m_startRotation;
executed 4 times by 1 test: QMessageLogger(__FILE__, 311, __PRETTY_FUNCTION__, lcPinchHandler().categoryName()).info() << "activated with starting scale" << m_startScale << "rotation" << m_startRotation;
Executed by:
  • tst_multipointtoucharea_interop
4
197 }
executed 4 times by 1 test: end of block
Executed by:
  • tst_multipointtoucharea_interop
else {
4
198 for (bool qt_category_enabled = lcPinchHandler().isInfoEnabled(); qt_category_enabled
qt_category_enabledDescription
TRUEevaluated 4 times by 1 test
Evaluated by:
  • tst_multipointtoucharea_interop
FALSEevaluated 4 times by 1 test
Evaluated by:
  • tst_multipointtoucharea_interop
; qt_category_enabled = false) QMessageLogger(__FILE__, 313, __PRETTY_FUNCTION__, lcPinchHandler().categoryName()).info() << "deactivated with scale" << m_activeScale << "rotation" << m_activeRotation;
executed 4 times by 1 test: QMessageLogger(__FILE__, 313, __PRETTY_FUNCTION__, lcPinchHandler().categoryName()).info() << "deactivated with scale" << m_activeScale << "rotation" << m_activeRotation;
Executed by:
  • tst_multipointtoucharea_interop
4
199 }
executed 4 times by 1 test: end of block
Executed by:
  • tst_multipointtoucharea_interop
4
200}-
201-
202void QQuickPinchHandler::handlePointerEventImpl(QQuickPointerEvent *event)-
203{-
204 if (__builtin_expect(!!(lcPinchHandler().isDebugEnabled()), false)
__builtin_expe...led()), false)Description
TRUEnever evaluated
FALSEevaluated 31 times by 1 test
Evaluated by:
  • tst_multipointtoucharea_interop
) {
0-31
205 for (QQuickEventPoint *point : qAsConst(m_currentPoints))-
206 for (bool qt_category_enabled = lcPinchHandler().isDebugEnabled(); qt_category_enabled
qt_category_enabledDescription
TRUEnever evaluated
FALSEnever evaluated
; qt_category_enabled = false) QMessageLogger(__FILE__, 321, __PRETTY_FUNCTION__, lcPinchHandler().categoryName()).debug() << point->state() << point->sceneGrabPosition() << "->" << point->scenePosition();
never executed: QMessageLogger(__FILE__, 321, __PRETTY_FUNCTION__, lcPinchHandler().categoryName()).debug() << point->state() << point->sceneGrabPosition() << "->" << point->scenePosition();
0
207 }
never executed: end of block
0
208 QQuickMultiPointHandler::handlePointerEventImpl(event);-
209-
210 qreal dist = 0;-
211-
212 if (const
const auto ges...GestureEvent()Description
TRUEnever evaluated
FALSEevaluated 31 times by 1 test
Evaluated by:
  • tst_multipointtoucharea_interop
auto gesture = event->asPointerNativeGestureEvent()
const auto ges...GestureEvent()Description
TRUEnever evaluated
FALSEevaluated 31 times by 1 test
Evaluated by:
  • tst_multipointtoucharea_interop
) {
0-31
213 switch (gesture->type()) {-
214 case
never executed: case Qt::EndNativeGesture:
Qt::EndNativeGesture:
never executed: case Qt::EndNativeGesture:
0
215 m_activeScale = 1;-
216 m_activeRotation = 0;-
217 m_activeTranslation = QVector2D();-
218 m_centroid.reset();-
219 setActive(false);-
220 updated();-
221 return;
never executed: return;
0
222 case
never executed: case Qt::ZoomNativeGesture:
Qt::ZoomNativeGesture:
never executed: case Qt::ZoomNativeGesture:
0
223 m_activeScale *= 1 + gesture->value();-
224 break;
never executed: break;
0
225 case
never executed: case Qt::RotateNativeGesture:
Qt::RotateNativeGesture:
never executed: case Qt::RotateNativeGesture:
0
226 m_activeRotation += gesture->value();-
227 break;
never executed: break;
0
228 default
never executed: default:
:
never executed: default:
0
229-
230 return;
never executed: return;
0
231 }-
232 if (!active()
!active()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
233 setActive(true);-
234-
235-
236 m_activeTranslation = QVector2D();-
237 }
never executed: end of block
0
238 }
never executed: end of block
else
0
239-
240 {-
241 bool containsReleasedPoints = event->isReleaseEvent();-
242 if (!active()
!active()Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • tst_multipointtoucharea_interop
FALSEevaluated 25 times by 1 test
Evaluated by:
  • tst_multipointtoucharea_interop
) {
6-25
243-
244 for (QQuickEventPoint *point : qAsConst(m_currentPoints)) {-
245 if (!containsReleasedPoints
!containsReleasedPointsDescription
TRUEevaluated 4 times by 1 test
Evaluated by:
  • tst_multipointtoucharea_interop
FALSEevaluated 6 times by 1 test
Evaluated by:
  • tst_multipointtoucharea_interop
&& QQuickWindowPrivate::dragOverThreshold(point)
QQuickWindowPr...reshold(point)Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • tst_multipointtoucharea_interop
FALSEnever evaluated
&& grabPoints(m_currentPoints)
grabPoints(m_currentPoints)Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • tst_multipointtoucharea_interop
FALSEnever evaluated
) {
0-6
246 setActive(true);-
247 break;
executed 4 times by 1 test: break;
Executed by:
  • tst_multipointtoucharea_interop
4
248 } else {-
249 setPassiveGrab(point);-
250 }
executed 6 times by 1 test: end of block
Executed by:
  • tst_multipointtoucharea_interop
6
251 if (point->state() == QQuickEventPoint::Pressed
point->state()...Point::PressedDescription
TRUEnever evaluated
FALSEevaluated 6 times by 1 test
Evaluated by:
  • tst_multipointtoucharea_interop
) {
0-6
252 point->setAccepted(false);-
253 setPassiveGrab(point);-
254 }
never executed: end of block
0
255 }
executed 6 times by 1 test: end of block
Executed by:
  • tst_multipointtoucharea_interop
6
256 if (!active()
!active()Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_multipointtoucharea_interop
FALSEevaluated 4 times by 1 test
Evaluated by:
  • tst_multipointtoucharea_interop
)
2-4
257 return;
executed 2 times by 1 test: return;
Executed by:
  • tst_multipointtoucharea_interop
2
258 }
executed 4 times by 1 test: end of block
Executed by:
  • tst_multipointtoucharea_interop
4
259-
260-
261-
262-
263 dist = averageTouchPointDistance(m_centroid.scenePosition());-
264 m_activeScale = dist / m_startDistance;-
265 m_activeScale = qBound(m_minimumScale/m_startScale, m_activeScale, m_maximumScale/m_startScale);-
266-
267-
268 QVector<PointData> newAngles = angles(m_centroid.scenePosition());-
269 const qreal angleDelta = averageAngleDelta(m_startAngles, newAngles);-
270 m_activeRotation += angleDelta;-
271 m_startAngles = std::move(newAngles);-
272-
273 if (!containsReleasedPoints
!containsReleasedPointsDescription
TRUEevaluated 29 times by 1 test
Evaluated by:
  • tst_multipointtoucharea_interop
FALSEnever evaluated
)
0-29
274 acceptPoints(m_currentPoints);
executed 29 times by 1 test: acceptPoints(m_currentPoints);
Executed by:
  • tst_multipointtoucharea_interop
29
275 }
executed 29 times by 1 test: end of block
Executed by:
  • tst_multipointtoucharea_interop
29
276-
277 QPointF centroidParentPos;-
278 QRectF bounds(m_minimumX, m_minimumY, m_maximumX - m_minimumX, m_maximumY - m_minimumY);-
279 if (target()
target()Description
TRUEevaluated 29 times by 1 test
Evaluated by:
  • tst_multipointtoucharea_interop
FALSEnever evaluated
&& target()->parentItem()
target()->parentItem()Description
TRUEevaluated 29 times by 1 test
Evaluated by:
  • tst_multipointtoucharea_interop
FALSEnever evaluated
) {
0-29
280 centroidParentPos = target()->parentItem()->mapFromScene(m_centroid.scenePosition());-
281 centroidParentPos = QPointF(qBound(bounds.left(), centroidParentPos.x(), bounds.right()),-
282 qBound(bounds.top(), centroidParentPos.y(), bounds.bottom()));-
283 }
executed 29 times by 1 test: end of block
Executed by:
  • tst_multipointtoucharea_interop
29
284 const qreal totalRotation = m_startRotation + m_activeRotation;-
285 const qreal rotation = qBound(m_minimumRotation, totalRotation, m_maximumRotation);-
286 m_activeRotation += (rotation - totalRotation);-
287 m_accumulatedScale = m_startScale * m_activeScale;-
288-
289 if (target()
target()Description
TRUEevaluated 29 times by 1 test
Evaluated by:
  • tst_multipointtoucharea_interop
FALSEnever evaluated
&& target()->parentItem()
target()->parentItem()Description
TRUEevaluated 29 times by 1 test
Evaluated by:
  • tst_multipointtoucharea_interop
FALSEnever evaluated
) {
0-29
290-
291 const QPointF centroidStartParentPos = target()->parentItem()->mapFromScene(m_centroid.sceneGrabPosition());-
292 m_activeTranslation = QVector2D(centroidParentPos - centroidStartParentPos);-
293-
294 QMatrix4x4 mat;-
295-
296 const QVector3D centroidParentVector(centroidParentPos);-
297 mat.translate(centroidParentVector);-
298 mat.rotate(m_activeRotation, 0, 0, 1);-
299 mat.scale(m_activeScale);-
300 mat.translate(-centroidParentVector);-
301 mat.translate(QVector3D(m_activeTranslation));-
302-
303 mat = mat * m_startMatrix;-
304-
305 QPointF xformOriginPoint = target()->transformOriginPoint();-
306 QPointF pos = mat * xformOriginPoint;-
307 pos -= xformOriginPoint;-
308-
309 target()->setPosition(pos);-
310 target()->setRotation(rotation);-
311 target()->setScale(m_accumulatedScale);-
312-
313-
314 }
executed 29 times by 1 test: end of block
Executed by:
  • tst_multipointtoucharea_interop
else {
29
315 m_activeTranslation = QVector2D(m_centroid.scenePosition() - m_centroid.scenePressPosition());-
316 }
never executed: end of block
0
317-
318 for (bool qt_category_enabled = lcPinchHandler().isDebugEnabled(); qt_category_enabled
qt_category_enabledDescription
TRUEnever evaluated
FALSEevaluated 29 times by 1 test
Evaluated by:
  • tst_multipointtoucharea_interop
; qt_category_enabled = false) QMessageLogger(__FILE__, 433, __PRETTY_FUNCTION__, lcPinchHandler().categoryName()).debug() << "centroid" << m_centroid.scenePressPosition() << "->" << m_centroid.scenePosition()
never executed: QMessageLogger(__FILE__, 433, __PRETTY_FUNCTION__, lcPinchHandler().categoryName()).debug() << "centroid" << m_centroid.scenePressPosition() << "->" << m_centroid.scenePosition() << ", distance" << m_startDistance << "->" << dist << ", startScale" << m_startScale << "->" << m_accumulatedScale << ", activeRotation" << m_activeRotation << ", rotation" << rotation << " from " << event->device()->type();
0-29
319 << ", distance" << m_startDistance << "->" << dist
never executed: QMessageLogger(__FILE__, 433, __PRETTY_FUNCTION__, lcPinchHandler().categoryName()).debug() << "centroid" << m_centroid.scenePressPosition() << "->" << m_centroid.scenePosition() << ", distance" << m_startDistance << "->" << dist << ", startScale" << m_startScale << "->" << m_accumulatedScale << ", activeRotation" << m_activeRotation << ", rotation" << rotation << " from " << event->device()->type();
0
320 << ", startScale" << m_startScale << "->" << m_accumulatedScale
never executed: QMessageLogger(__FILE__, 433, __PRETTY_FUNCTION__, lcPinchHandler().categoryName()).debug() << "centroid" << m_centroid.scenePressPosition() << "->" << m_centroid.scenePosition() << ", distance" << m_startDistance << "->" << dist << ", startScale" << m_startScale << "->" << m_accumulatedScale << ", activeRotation" << m_activeRotation << ", rotation" << rotation << " from " << event->device()->type();
0
321 << ", activeRotation" << m_activeRotation
never executed: QMessageLogger(__FILE__, 433, __PRETTY_FUNCTION__, lcPinchHandler().categoryName()).debug() << "centroid" << m_centroid.scenePressPosition() << "->" << m_centroid.scenePosition() << ", distance" << m_startDistance << "->" << dist << ", startScale" << m_startScale << "->" << m_accumulatedScale << ", activeRotation" << m_activeRotation << ", rotation" << rotation << " from " << event->device()->type();
0
322 << ", rotation" << rotation
never executed: QMessageLogger(__FILE__, 433, __PRETTY_FUNCTION__, lcPinchHandler().categoryName()).debug() << "centroid" << m_centroid.scenePressPosition() << "->" << m_centroid.scenePosition() << ", distance" << m_startDistance << "->" << dist << ", startScale" << m_startScale << "->" << m_accumulatedScale << ", activeRotation" << m_activeRotation << ", rotation" << rotation << " from " << event->device()->type();
0
323 << " from " << event->device()->type();
never executed: QMessageLogger(__FILE__, 433, __PRETTY_FUNCTION__, lcPinchHandler().categoryName()).debug() << "centroid" << m_centroid.scenePressPosition() << "->" << m_centroid.scenePosition() << ", distance" << m_startDistance << "->" << dist << ", startScale" << m_startScale << "->" << m_accumulatedScale << ", activeRotation" << m_activeRotation << ", rotation" << rotation << " from " << event->device()->type();
0
324-
325 updated();-
326}
executed 29 times by 1 test: end of block
Executed by:
  • tst_multipointtoucharea_interop
29
327-
Switch to Source codePreprocessed file

Generated by Squish Coco 4.2.0