Port examples away from deprecated QTouchEvent APIs

Use the QEventPoints API instead.

Change-Id: I7310fd34df110cad508f6188a41ad452a3cf848d
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
This commit is contained in:
Volker Hilsheimer 2021-04-16 11:29:12 +02:00
parent 7709463b55
commit 6a4aa096e9
5 changed files with 35 additions and 35 deletions

View File

@ -622,11 +622,11 @@ bool PathStrokeRenderer::event(QEvent *e)
case QEvent::TouchUpdate: case QEvent::TouchUpdate:
{ {
const QTouchEvent *const event = static_cast<const QTouchEvent*>(e); const QTouchEvent *const event = static_cast<const QTouchEvent*>(e);
const QList<QTouchEvent::TouchPoint> points = event->touchPoints(); const auto points = event->points();
for (const QTouchEvent::TouchPoint &touchPoint : points) { for (const auto &point : points) {
const int id = touchPoint.id(); const int id = point.id();
switch (touchPoint.state()) { switch (point.state()) {
case Qt::TouchPointPressed: case QEventPoint::Pressed:
{ {
// find the point, move it // find the point, move it
const auto mappedPoints = m_fingerPointMapping.values(); const auto mappedPoints = m_fingerPointMapping.values();
@ -638,32 +638,32 @@ bool PathStrokeRenderer::event(QEvent *e)
if (activePoints.contains(i)) if (activePoints.contains(i))
continue; continue;
qreal d = QLineF(touchPoint.position(), m_points.at(i)).length(); qreal d = QLineF(point.position(), m_points.at(i)).length();
if ((distance < 0 && d < 12 * m_pointSize) || d < distance) { if ((distance < 0 && d < 12 * m_pointSize) || d < distance) {
distance = d; distance = d;
activePoint = i; activePoint = i;
} }
} }
if (activePoint != -1) { if (activePoint != -1) {
m_fingerPointMapping.insert(touchPoint.id(), activePoint); m_fingerPointMapping.insert(point.id(), activePoint);
m_points[activePoint] = touchPoint.position(); m_points[activePoint] = point.position();
} }
break; break;
} }
case Qt::TouchPointReleased: case QEventPoint::Released:
{ {
// move the point and release // move the point and release
QHash<int,int>::iterator it = m_fingerPointMapping.find(id); QHash<int,int>::iterator it = m_fingerPointMapping.find(id);
m_points[it.value()] = touchPoint.position(); m_points[it.value()] = point.position();
m_fingerPointMapping.erase(it); m_fingerPointMapping.erase(it);
break; break;
} }
case Qt::TouchPointMoved: case QEventPoint::Updated:
{ {
// move the point // move the point
const int pointIdx = m_fingerPointMapping.value(id, -1); const int pointIdx = m_fingerPointMapping.value(id, -1);
if (pointIdx >= 0) if (pointIdx >= 0)
m_points[pointIdx] = touchPoint.position(); m_points[pointIdx] = point.position();
break; break;
} }
default: default:

View File

@ -176,12 +176,12 @@ bool HoverPoints::eventFilter(QObject *object, QEvent *event)
case QEvent::TouchUpdate: case QEvent::TouchUpdate:
{ {
const QTouchEvent *const touchEvent = static_cast<const QTouchEvent*>(event); const QTouchEvent *const touchEvent = static_cast<const QTouchEvent*>(event);
const QList<QTouchEvent::TouchPoint> points = touchEvent->touchPoints(); const auto points = touchEvent->points();
const qreal pointSize = qMax(m_pointSize.width(), m_pointSize.height()); const qreal pointSize = qMax(m_pointSize.width(), m_pointSize.height());
for (const QTouchEvent::TouchPoint &touchPoint : points) { for (const auto &point : points) {
const int id = touchPoint.id(); const int id = point.id();
switch (touchPoint.state()) { switch (point.state()) {
case Qt::TouchPointPressed: case QEventPoint::Pressed:
{ {
// find the point, move it // find the point, move it
const auto mappedPoints = m_fingerPointMapping.values(); const auto mappedPoints = m_fingerPointMapping.values();
@ -197,7 +197,7 @@ bool HoverPoints::eventFilter(QObject *object, QEvent *event)
if (activePoints.contains(i)) if (activePoints.contains(i))
continue; continue;
qreal d = QLineF(touchPoint.position(), m_points.at(i)).length(); qreal d = QLineF(point.position(), m_points.at(i)).length();
if ((distance < 0 && d < 12 * pointSize) || d < distance) { if ((distance < 0 && d < 12 * pointSize) || d < distance) {
distance = d; distance = d;
activePoint = i; activePoint = i;
@ -206,25 +206,25 @@ bool HoverPoints::eventFilter(QObject *object, QEvent *event)
} }
} }
if (activePoint != -1) { if (activePoint != -1) {
m_fingerPointMapping.insert(touchPoint.id(), activePoint); m_fingerPointMapping.insert(point.id(), activePoint);
movePoint(activePoint, touchPoint.position()); movePoint(activePoint, point.position());
} }
} }
break; break;
case Qt::TouchPointReleased: case QEventPoint::Released:
{ {
// move the point and release // move the point and release
QHash<int,int>::iterator it = m_fingerPointMapping.find(id); QHash<int,int>::iterator it = m_fingerPointMapping.find(id);
movePoint(it.value(), touchPoint.position()); movePoint(it.value(), point.position());
m_fingerPointMapping.erase(it); m_fingerPointMapping.erase(it);
} }
break; break;
case Qt::TouchPointMoved: case QEventPoint::Updated:
{ {
// move the point // move the point
const int pointIdx = m_fingerPointMapping.value(id, -1); const int pointIdx = m_fingerPointMapping.value(id, -1);
if (pointIdx >= 0) // do we track this point? if (pointIdx >= 0) // do we track this point?
movePoint(pointIdx, touchPoint.position()); movePoint(pointIdx, point.position());
} }
break; break;
default: default:

View File

@ -196,11 +196,11 @@ bool ScribbleArea::event(QEvent *event)
case QEvent::TouchEnd: case QEvent::TouchEnd:
{ {
const QTouchEvent *touch = static_cast<QTouchEvent *>(event); const QTouchEvent *touch = static_cast<QTouchEvent *>(event);
const QList<QTouchEvent::TouchPoint> touchPoints = static_cast<QTouchEvent *>(event)->touchPoints(); const auto touchPoints = static_cast<QTouchEvent *>(event)->points();
for (const QTouchEvent::TouchPoint &touchPoint : touchPoints) { for (const QTouchEvent::TouchPoint &touchPoint : touchPoints) {
switch (touchPoint.state()) { switch (touchPoint.state()) {
case Qt::TouchPointStationary: case QEventPoint::Stationary:
case Qt::TouchPointReleased: case QEventPoint::Released:
// don't do anything if this touch point hasn't moved or has been released // don't do anything if this touch point hasn't moved or has been released
continue; continue;
default: default:

View File

@ -77,11 +77,11 @@ bool Knob::sceneEvent(QEvent *event)
{ {
QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event); QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event);
if (touchEvent->touchPoints().count() == 2) { if (touchEvent->points().count() == 2) {
const QTouchEvent::TouchPoint &touchPoint1 = touchEvent->touchPoints().first(); const QEventPoint &touchPoint1 = touchEvent->points().first();
const QTouchEvent::TouchPoint &touchPoint2 = touchEvent->touchPoints().last(); const QEventPoint &touchPoint2 = touchEvent->points().last();
QLineF line1(touchPoint1.lastScenePos(), touchPoint2.lastScenePos()); QLineF line1(touchPoint1.sceneLastPosition(), touchPoint2.sceneLastPosition());
QLineF line2(touchPoint1.scenePosition(), touchPoint2.scenePosition()); QLineF line2(touchPoint1.scenePosition(), touchPoint2.scenePosition());
setTransform(QTransform().rotate(line2.angleTo(line1)), true); setTransform(QTransform().rotate(line2.angleTo(line1)), true);

View File

@ -68,15 +68,15 @@ bool GraphicsView::viewportEvent(QEvent *event)
case QEvent::TouchEnd: case QEvent::TouchEnd:
{ {
QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event); QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event);
QList<QTouchEvent::TouchPoint> touchPoints = touchEvent->touchPoints(); const auto touchPoints = touchEvent->points();
if (touchPoints.count() == 2) { if (touchPoints.count() == 2) {
// determine scale factor // determine scale factor
const QTouchEvent::TouchPoint &touchPoint0 = touchPoints.first(); const QEventPoint &touchPoint0 = touchPoints.first();
const QTouchEvent::TouchPoint &touchPoint1 = touchPoints.last(); const QEventPoint &touchPoint1 = touchPoints.last();
qreal currentScaleFactor = qreal currentScaleFactor =
QLineF(touchPoint0.position(), touchPoint1.position()).length() QLineF(touchPoint0.position(), touchPoint1.position()).length()
/ QLineF(touchPoint0.pressPosition(), touchPoint1.pressPosition()).length(); / QLineF(touchPoint0.pressPosition(), touchPoint1.pressPosition()).length();
if (touchEvent->touchPointStates() & Qt::TouchPointReleased) { if (touchEvent->touchPointStates() & QEventPoint::Released) {
// if one of the fingers is released, remember the current scale // if one of the fingers is released, remember the current scale
// factor so that adding another finger later will continue zooming // factor so that adding another finger later will continue zooming
// by adding new scale factor to the existing remembered value. // by adding new scale factor to the existing remembered value.