summaryrefslogtreecommitdiffstats
path: root/tests/auto/gui/kernel
diff options
context:
space:
mode:
authorLaszlo Agocs <laszlo.p.agocs@nokia.com>2011-12-12 17:24:33 +0200
committerQt by Nokia <qt-info@nokia.com>2011-12-12 17:27:19 +0100
commit91b48208f57b10f1b0378d1888fb96af73bc9fa3 (patch)
treea64535b90c91bc1b94caf3d0b0896f213f75b226 /tests/auto/gui/kernel
parent0319f13f1a9bdd5570977952f7b206a910bbb7a4 (diff)
Add touchEvent() virtual to QWindow.
Unlike keyPressEvent(), mousePressEvent(), etc. the touch events had no equivalent so one had to fall back to reimplementing event() or using an event filter. This is now corrected by introducing touchEvent(). Touch events are finally becoming a first-class citizen in Qt 5. Change-Id: Ia2044030154fd5b1b5384f08a3cb1749b798435f Reviewed-by: Samuel Rødal <samuel.rodal@nokia.com>
Diffstat (limited to 'tests/auto/gui/kernel')
-rw-r--r--tests/auto/gui/kernel/qwindow/tst_qwindow.cpp82
1 files changed, 82 insertions, 0 deletions
diff --git a/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp b/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp
index 4171f0f797..13b196c039 100644
--- a/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp
+++ b/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp
@@ -43,6 +43,8 @@
#include <QtTest/QtTest>
+#include <QEvent>
+
class tst_QWindow: public QObject
{
Q_OBJECT
@@ -51,6 +53,7 @@ private slots:
void mapGlobal();
void positioning();
void isActive();
+ void testInputEvents();
};
@@ -221,5 +224,84 @@ void tst_QWindow::isActive()
QVERIFY(child.isActive());
}
+class InputTestWindow : public QWindow
+{
+public:
+ void keyPressEvent(QKeyEvent *event) {
+ keyPressCode = event->key();
+ }
+ void keyReleaseEvent(QKeyEvent *event) {
+ keyReleaseCode = event->key();
+ }
+ void mousePressEvent(QMouseEvent *event) {
+ mousePressButton = event->button();
+ }
+ void mouseReleaseEvent(QMouseEvent *event) {
+ mouseReleaseButton = event->button();
+ }
+ void touchEvent(QTouchEvent *event) {
+ QList<QTouchEvent::TouchPoint> points = event->touchPoints();
+ for (int i = 0; i < points.count(); ++i) {
+ switch (points.at(i).state()) {
+ case Qt::TouchPointPressed:
+ ++touchPressedCount;
+ break;
+ case Qt::TouchPointReleased:
+ ++touchReleasedCount;
+ break;
+ }
+ }
+ }
+
+ InputTestWindow() {
+ keyPressCode = keyReleaseCode = 0;
+ mousePressButton = mouseReleaseButton = 0;
+ touchPressedCount = touchReleasedCount = 0;
+ }
+
+ int keyPressCode, keyReleaseCode;
+ int mousePressButton, mouseReleaseButton;
+ int touchPressedCount, touchReleasedCount;
+};
+
+void tst_QWindow::testInputEvents()
+{
+ InputTestWindow window;
+ window.setGeometry(80, 80, 40, 40);
+ window.show();
+ QTest::qWaitForWindowShown(&window);
+
+ QWindowSystemInterface::handleKeyEvent(&window, QEvent::KeyPress, Qt::Key_A, Qt::NoModifier);
+ QWindowSystemInterface::handleKeyEvent(&window, QEvent::KeyRelease, Qt::Key_A, Qt::NoModifier);
+ QCoreApplication::processEvents();
+ QCOMPARE(window.keyPressCode, int(Qt::Key_A));
+ QCOMPARE(window.keyReleaseCode, int(Qt::Key_A));
+
+ QPointF local(12, 34);
+ QWindowSystemInterface::handleMouseEvent(&window, local, local, Qt::LeftButton);
+ QWindowSystemInterface::handleMouseEvent(&window, local, local, Qt::NoButton);
+ QCoreApplication::processEvents();
+ QCOMPARE(window.mousePressButton, int(Qt::LeftButton));
+ QCOMPARE(window.mouseReleaseButton, int(Qt::LeftButton));
+
+ QTouchDevice *device = new QTouchDevice;
+ device->setType(QTouchDevice::TouchScreen);
+ QWindowSystemInterface::registerTouchDevice(device);
+ QList<QWindowSystemInterface::TouchPoint> points;
+ QWindowSystemInterface::TouchPoint tp1, tp2;
+ tp1.id = 1;
+ tp1.state = Qt::TouchPointPressed;
+ tp2.id = 2;
+ tp2.state = Qt::TouchPointPressed;
+ points << tp1 << tp2;
+ QWindowSystemInterface::handleTouchEvent(&window, device, points);
+ points[0].state = Qt::TouchPointReleased;
+ points[1].state = Qt::TouchPointReleased;
+ QWindowSystemInterface::handleTouchEvent(&window, device, points);
+ QCoreApplication::processEvents();
+ QCOMPARE(window.touchPressedCount, 2);
+ QCOMPARE(window.touchReleasedCount, 2);
+}
+
#include <tst_qwindow.moc>
QTEST_MAIN(tst_QWindow);