summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/testlib/qtesttouch.h50
-rw-r--r--tests/auto/gestures/tst_gestures.cpp53
2 files changed, 76 insertions, 27 deletions
diff --git a/src/testlib/qtesttouch.h b/src/testlib/qtesttouch.h
index f9ed994..ccfaa63 100644
--- a/src/testlib/qtesttouch.h
+++ b/src/testlib/qtesttouch.h
@@ -75,38 +75,27 @@ namespace QTest
delete pt;
points.clear();
}
- QTouchEventSequence& press(int touchId, const QPoint &pt)
+ QTouchEventSequence& press(int touchId, const QPoint &pt, QWidget *widget = 0)
{
touchPointStates |= Qt::TouchPointPressed;
QTouchEvent::TouchPoint *p = point(touchId);
- p->setStartPos(pt);
- p->setStartScreenPos(widget->mapToGlobal(pt));
- p->setLastPos(pt);
- p->setLastScreenPos(widget->mapToGlobal(pt));
- p->setPos(pt);
- p->setScreenPos(widget->mapToGlobal(pt));
+ p->setScreenPos(mapToScreen(widget, pt));
p->setState(Qt::TouchPointPressed);
return *this;
}
- QTouchEventSequence& move(int touchId, const QPoint &pt)
+ QTouchEventSequence& move(int touchId, const QPoint &pt, QWidget *widget = 0)
{
touchPointStates |= Qt::TouchPointMoved;
QTouchEvent::TouchPoint *p = point(touchId);
- p->setLastPos(p->pos());
- p->setLastScreenPos(widget->mapToGlobal(p->pos().toPoint()));
- p->setPos(pt);
- p->setScreenPos(widget->mapToGlobal(pt));
+ p->setScreenPos(mapToScreen(widget, pt));
p->setState(Qt::TouchPointMoved);
return *this;
}
- QTouchEventSequence& release(int touchId, const QPoint &pt)
+ QTouchEventSequence& release(int touchId, const QPoint &pt, QWidget *widget = 0)
{
touchPointStates |= Qt::TouchPointReleased;
QTouchEvent::TouchPoint *p = point(touchId);
- p->setLastPos(p->pos());
- p->setLastScreenPos(widget->mapToGlobal(p->pos().toPoint()));
- p->setPos(pt);
- p->setScreenPos(widget->mapToGlobal(pt));
+ p->setScreenPos(mapToScreen(widget, pt));
p->setState(Qt::TouchPointReleased);
return *this;
}
@@ -120,7 +109,7 @@ namespace QTest
private:
QTouchEventSequence(QWidget *widget)
- : widget(widget)
+ : targetWidget(widget)
{
}
QTouchEventSequence(const QTouchEventSequence &v);
@@ -136,25 +125,34 @@ namespace QTest
}
return pt;
}
+ QPoint mapToScreen(QWidget *widget, const QPoint &pt)
+ {
+ if (widget)
+ return widget->mapToGlobal(pt);
+ return targetWidget ? targetWidget->mapToGlobal(pt) : pt;
+ }
void commit()
{
- if (widget) {
- QTouchEvent event(QEvent::RawTouch, Qt::NoModifier,
- touchPointStates, points.values());
- QSpontaneKeyEvent::setSpontaneous(&event);
- if (!qApp->notify(widget, &event))
+ 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");
- widget = 0;
}
}
QMap<int, QTouchEvent::TouchPoint*> points;
- QWidget *widget;
+ QWidget *targetWidget;
Qt::TouchPointStates touchPointStates;
friend QTouchEventSequence touchEvent(QWidget*);
};
- QTouchEventSequence touchEvent(QWidget *widget)
+ QTouchEventSequence touchEvent(QWidget *widget = 0)
{
return QTouchEventSequence(widget);
}
diff --git a/tests/auto/gestures/tst_gestures.cpp b/tests/auto/gestures/tst_gestures.cpp
index a649004..0061506 100644
--- a/tests/auto/gestures/tst_gestures.cpp
+++ b/tests/auto/gestures/tst_gestures.cpp
@@ -240,6 +240,7 @@ public:
bool shouldAcceptPanGesture;
GestureState gesture;
+ TouchState touch;
void reset()
{
@@ -248,11 +249,20 @@ public:
shouldAcceptSecondFingerGesture = true;
shouldAcceptPanGesture = true;
gesture.reset();
+ touch.reset();
}
protected:
bool event(QEvent *event)
{
- if (event->type() == QEvent::Gesture) {
+ if (event->type() == QEvent::TouchBegin) {
+ event->accept();
+ ++touch.seenTouchBeginEvent;
+ return true;
+ } else if (event->type() == QEvent::TouchUpdate) {
+ ++touch.seenTouchUpdateEvent;
+ } else if (event->type() == QEvent::TouchEnd) {
+ ++touch.seenTouchEndEvent;
+ } else if (event->type() == QEvent::Gesture) {
QGestureEvent *e = static_cast<QGestureEvent*>(event);
++gesture.seenGestureEvent;
if (SingleshotGesture *g = (SingleshotGesture*)e->gesture(SingleshotGestureRecognizer::Name)) {
@@ -490,6 +500,8 @@ private slots:
void touch();
+ void panOnWidgets();
+
private:
SingleshotGestureRecognizer *singleshotRecognizer;
PinchGestureRecognizer *pinchRecognizer;
@@ -835,5 +847,44 @@ void tst_Gestures::touch()
QVERIFY(item->touch.seenTouchEndEvent);
}
+void tst_Gestures::panOnWidgets()
+{
+ GestureWidget leftWidget(GestureWidget::GrabPan);
+ leftWidget.setObjectName("leftWidget");
+ leftWidget.setAttribute(Qt::WA_AcceptTouchEvents);
+ GestureWidget rightWidget(GestureWidget::GrabPan);
+ rightWidget.setObjectName("rightWidget");
+ rightWidget.setAttribute(Qt::WA_AcceptTouchEvents);
+ delete mainWidget->layout();
+ (void)new QHBoxLayout(mainWidget);
+ mainWidget->layout()->addWidget(&leftWidget);
+ mainWidget->layout()->addWidget(&rightWidget);
+ QApplication::processEvents();
+
+ QTest::touchEvent()
+ .press(0, QPoint(10, 10), &leftWidget);
+ QTest::touchEvent()
+ .move(0, QPoint(12, 30), &leftWidget);
+ QTest::touchEvent()
+ .stationary(0)
+ .press(1, QPoint(15, 15), &rightWidget);
+ QTest::touchEvent()
+ .move(0, QPoint(10, 35), &leftWidget)
+ .press(1, QPoint(15, 15), &rightWidget);
+ QTest::touchEvent()
+ .move(0, QPoint(10, 40), &leftWidget)
+ .move(1, QPoint(20, 50), &rightWidget);
+ QTest::touchEvent()
+ .release(0, QPoint(10, 40), &leftWidget)
+ .release(1, QPoint(20, 50), &rightWidget);
+ QVERIFY(!mainWidget->touch.seenTouchBeginEvent);
+ QVERIFY(leftWidget.touch.seenTouchBeginEvent);
+ QVERIFY(leftWidget.touch.seenTouchUpdateEvent);
+ QVERIFY(leftWidget.touch.seenTouchEndEvent);
+ QVERIFY(rightWidget.touch.seenTouchBeginEvent);
+ QVERIFY(rightWidget.touch.seenTouchUpdateEvent);
+ QVERIFY(rightWidget.touch.seenTouchEndEvent);
+}
+
QTEST_MAIN(tst_Gestures)
#include "tst_gestures.moc"