diff options
-rw-r--r-- | examples/multitouch/fingerpaint/scribblearea.cpp | 20 | ||||
-rw-r--r-- | examples/multitouch/knobs/knob.cpp | 8 | ||||
-rw-r--r-- | examples/multitouch/pinchzoom/graphicsview.cpp | 14 | ||||
-rw-r--r-- | src/testlib/qtesttouch.h | 58 |
4 files changed, 41 insertions, 59 deletions
diff --git a/examples/multitouch/fingerpaint/scribblearea.cpp b/examples/multitouch/fingerpaint/scribblearea.cpp index 71fbd19..ac7df08 100644 --- a/examples/multitouch/fingerpaint/scribblearea.cpp +++ b/examples/multitouch/fingerpaint/scribblearea.cpp @@ -176,26 +176,26 @@ bool ScribbleArea::event(QEvent *event) case QEvent::TouchUpdate: case QEvent::TouchEnd: { - QList<QTouchEvent::TouchPoint *> touchPoints = static_cast<QTouchEvent *>(event)->touchPoints(); - foreach (QTouchEvent::TouchPoint *touchPoint, touchPoints) { - switch (touchPoint->state()) { + QList<QTouchEvent::TouchPoint> touchPoints = static_cast<QTouchEvent *>(event)->touchPoints(); + foreach (const QTouchEvent::TouchPoint &touchPoint, touchPoints) { + switch (touchPoint.state()) { case Qt::TouchPointStationary: // don't do anything if this touch point hasn't moved continue; default: { - QSizeF area = touchPoint->area(); - if (area.isEmpty()) { - qreal diameter = qreal(50) * touchPoint->pressure(); - area = QSizeF(diameter, diameter); + QSizeF size= touchPoint.size(); + if (size.isEmpty()) { + qreal diameter = qreal(50) * touchPoint.pressure(); + size = QSizeF(diameter, diameter); } - QRectF rectF(QPointF(), area); - rectF.moveCenter(touchPoint->pos()); + QRectF rectF(QPointF(), size); + rectF.moveCenter(touchPoint.pos()); QRect rect = rectF.toRect(); QPainter painter(&image); painter.setPen(Qt::NoPen); - painter.setBrush(myPenColors.at(touchPoint->id())); + painter.setBrush(myPenColors.at(touchPoint.id())); painter.drawEllipse(rectF); painter.end(); diff --git a/examples/multitouch/knobs/knob.cpp b/examples/multitouch/knobs/knob.cpp index bced73c..d568167 100644 --- a/examples/multitouch/knobs/knob.cpp +++ b/examples/multitouch/knobs/knob.cpp @@ -69,11 +69,11 @@ bool Knob::sceneEvent(QEvent *event) QGraphicsSceneTouchEvent *touchEvent = static_cast<QGraphicsSceneTouchEvent *>(event); if (touchEvent->touchPoints().count() == 2) { - QGraphicsSceneTouchEvent::TouchPoint *touchPoint1 = touchEvent->touchPoints().first(); - QGraphicsSceneTouchEvent::TouchPoint *touchPoint2 = touchEvent->touchPoints().last(); + const QGraphicsSceneTouchEvent::TouchPoint &touchPoint1 = touchEvent->touchPoints().first(); + const QGraphicsSceneTouchEvent::TouchPoint &touchPoint2 = touchEvent->touchPoints().last(); - QLineF line1(touchPoint1->lastScenePos(), touchPoint2->lastScenePos()); - QLineF line2(touchPoint1->scenePos(), touchPoint2->scenePos()); + QLineF line1(touchPoint1.lastScenePos(), touchPoint2.lastScenePos()); + QLineF line2(touchPoint1.scenePos(), touchPoint2.scenePos()); rotate(line2.angleTo(line1)); } diff --git a/examples/multitouch/pinchzoom/graphicsview.cpp b/examples/multitouch/pinchzoom/graphicsview.cpp index 0856639..b72da77 100644 --- a/examples/multitouch/pinchzoom/graphicsview.cpp +++ b/examples/multitouch/pinchzoom/graphicsview.cpp @@ -57,18 +57,18 @@ bool GraphicsView::event(QEvent *event) case QEvent::TouchUpdate: case QEvent::TouchEnd: { - QList<QTouchEvent::TouchPoint *> touchPoints = static_cast<QTouchEvent *>(event)->touchPoints(); + QList<QTouchEvent::TouchPoint> touchPoints = static_cast<QTouchEvent *>(event)->touchPoints(); if (touchPoints.count() == 1) { - const QTouchEvent::TouchPoint *touchPoint = touchPoints.first(); - QPointF delta = touchPoint->pos() - touchPoint->lastPos(); + const QTouchEvent::TouchPoint &touchPoint = touchPoints.first(); + QPointF delta = touchPoint.pos() - touchPoint.lastPos(); horizontalScrollBar()->setValue(horizontalScrollBar()->value() - delta.x()); verticalScrollBar()->setValue(verticalScrollBar()->value() - delta.y()); } else if (touchPoints.count() == 2) { // determine scale factor - const QTouchEvent::TouchPoint *touchPoint0 = touchPoints.first(); - const QTouchEvent::TouchPoint *touchPoint1 = touchPoints.last(); - const qreal scaleFactor = QLineF(touchPoint0->pos(), touchPoint1->pos()).length() - / QLineF(touchPoint0->startPos(), touchPoint1->startPos()).length(); + const QTouchEvent::TouchPoint &touchPoint0 = touchPoints.first(); + const QTouchEvent::TouchPoint &touchPoint1 = touchPoints.last(); + const qreal scaleFactor = QLineF(touchPoint0.pos(), touchPoint1.pos()).length() + / QLineF(touchPoint0.startPos(), touchPoint1.startPos()).length(); setTransform(QTransform().scale(scaleFactor, scaleFactor)); } return true; diff --git a/src/testlib/qtesttouch.h b/src/testlib/qtesttouch.h index ccfaa63..50c3dd3 100644 --- a/src/testlib/qtesttouch.h +++ b/src/testlib/qtesttouch.h @@ -71,39 +71,33 @@ namespace QTest ~QTouchEventSequence() { commit(); - foreach(QTouchEvent::TouchPoint *pt, points) - delete pt; points.clear(); } QTouchEventSequence& press(int touchId, const QPoint &pt, QWidget *widget = 0) { - touchPointStates |= Qt::TouchPointPressed; - QTouchEvent::TouchPoint *p = point(touchId); - p->setScreenPos(mapToScreen(widget, pt)); - p->setState(Qt::TouchPointPressed); + QTouchEvent::TouchPoint &p = point(touchId); + p.setGlobalPos(mapToScreen(widget, pt)); + p.setState(Qt::TouchPointPressed); return *this; } QTouchEventSequence& move(int touchId, const QPoint &pt, QWidget *widget = 0) { - touchPointStates |= Qt::TouchPointMoved; - QTouchEvent::TouchPoint *p = point(touchId); - p->setScreenPos(mapToScreen(widget, pt)); - p->setState(Qt::TouchPointMoved); + QTouchEvent::TouchPoint &p = point(touchId); + p.setGlobalPos(mapToScreen(widget, pt)); + p.setState(Qt::TouchPointMoved); return *this; } QTouchEventSequence& release(int touchId, const QPoint &pt, QWidget *widget = 0) { - touchPointStates |= Qt::TouchPointReleased; - QTouchEvent::TouchPoint *p = point(touchId); - p->setScreenPos(mapToScreen(widget, pt)); - p->setState(Qt::TouchPointReleased); + QTouchEvent::TouchPoint &p = point(touchId); + p.setGlobalPos(mapToScreen(widget, pt)); + p.setState(Qt::TouchPointReleased); return *this; } QTouchEventSequence& stationary(int touchId) { - touchPointStates |= Qt::TouchPointStationary; - QTouchEvent::TouchPoint *p = point(touchId); - p->setState(Qt::TouchPointStationary); + QTouchEvent::TouchPoint &p = point(touchId); + p.setState(Qt::TouchPointStationary); return *this; } @@ -115,15 +109,11 @@ namespace QTest QTouchEventSequence(const QTouchEventSequence &v); void operator=(const QTouchEventSequence&); - QTouchEvent::TouchPoint* point(int touchId) + QTouchEvent::TouchPoint &point(int touchId) { - QTouchEvent::TouchPoint *pt = points.value(touchId, 0); - if (!pt) { - pt = new QTouchEvent::TouchPoint; - pt->setId(touchId); - points.insert(touchId, pt); - } - return pt; + if (!points.contains(touchId)) + points[touchId] = QTouchEvent::TouchPoint(touchId); + return points[touchId]; } QPoint mapToScreen(QWidget *widget, const QPoint &pt) { @@ -133,22 +123,14 @@ namespace QTest } void commit() { - QTouchEvent event(QEvent::RawTouch, Qt::NoModifier, - touchPointStates, points.values()); - QSpontaneKeyEvent::setSpontaneous(&event); - if (targetWidget) { - if (!qApp->notify(targetWidget->window(), &event)) - QTest::qWarn("Touch event not accepted by receiving widget"); - targetWidget = 0; - } else { - if (!qApp->notify(qApp, &event)) - QTest::qWarn("Touch event not accepted by receiving widget"); - } + extern Q_GUI_EXPORT bool qt_translateRawKeyEvent(const QList<QTouchEvent::TouchPoint> &touchPoints, QWidget *window); + if (!qt_translateRawKeyEvent(points.values(), targetWidget)) + QTest::qWarn("Touch event not accepted by receiving widget"); + targetWidget = 0; } - QMap<int, QTouchEvent::TouchPoint*> points; + QMap<int, QTouchEvent::TouchPoint> points; QWidget *targetWidget; - Qt::TouchPointStates touchPointStates; friend QTouchEventSequence touchEvent(QWidget*); }; |