summaryrefslogtreecommitdiffstats
path: root/src/testlib/qtesttouch.h
diff options
context:
space:
mode:
authorDenis Dzyubenko <denis.dzyubenko@nokia.com>2009-06-03 17:25:02 (GMT)
committerDenis Dzyubenko <denis.dzyubenko@nokia.com>2009-06-03 17:33:06 (GMT)
commitf26f5b230e614faecce33cf52af0a0d62dcaddaa (patch)
treeff42696653d6100d53c04049487814846555e5fa /src/testlib/qtesttouch.h
parent0afecb87783b54dc1647be86387beca0b5725535 (diff)
downloadQt-f26f5b230e614faecce33cf52af0a0d62dcaddaa.zip
Qt-f26f5b230e614faecce33cf52af0a0d62dcaddaa.tar.gz
Qt-f26f5b230e614faecce33cf52af0a0d62dcaddaa.tar.bz2
Improved touch event emulation code in testlib.
* Added a context for the touch positions in press(), move(), release() functions. * Sending RawTouch events to QApplication object if the target widget is not specified.
Diffstat (limited to 'src/testlib/qtesttouch.h')
-rw-r--r--src/testlib/qtesttouch.h50
1 files changed, 24 insertions, 26 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);
}