summaryrefslogtreecommitdiffstats
path: root/tests/auto/qapplication/tst_qapplication.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/qapplication/tst_qapplication.cpp')
-rw-r--r--tests/auto/qapplication/tst_qapplication.cpp143
1 files changed, 143 insertions, 0 deletions
diff --git a/tests/auto/qapplication/tst_qapplication.cpp b/tests/auto/qapplication/tst_qapplication.cpp
index a11b159..2fa7584 100644
--- a/tests/auto/qapplication/tst_qapplication.cpp
+++ b/tests/auto/qapplication/tst_qapplication.cpp
@@ -48,6 +48,7 @@
#include "qabstracteventdispatcher.h"
#include <QtGui>
+#include "private/qapplication_p.h"
#include "private/qstylesheetstyle_p.h"
#ifdef Q_OS_WINCE
#include <windows.h>
@@ -117,6 +118,8 @@ private slots:
void windowsCommandLine_data();
void windowsCommandLine();
+
+ void touchEventPropagation();
};
class MyInputContext : public QInputContext
@@ -1773,6 +1776,146 @@ void tst_QApplication::windowsCommandLine()
#endif
}
+class TouchEventPropagationTestWidget : public QWidget
+{
+ Q_OBJECT
+
+public:
+ bool seenTouchEvent, acceptTouchEvent, seenMouseEvent, acceptMouseEvent;
+
+ TouchEventPropagationTestWidget(QWidget *parent = 0)
+ : QWidget(parent), seenTouchEvent(false), acceptTouchEvent(false), seenMouseEvent(false), acceptMouseEvent(false)
+ { }
+
+ void reset()
+ {
+ seenTouchEvent = acceptTouchEvent = seenMouseEvent = acceptMouseEvent = false;
+ }
+
+ bool event(QEvent *event)
+ {
+ switch (event->type()) {
+ case QEvent::MouseButtonPress:
+ case QEvent::MouseMove:
+ case QEvent::MouseButtonRelease:
+ // qDebug() << objectName() << "seenMouseEvent = true";
+ seenMouseEvent = true;
+ event->setAccepted(acceptMouseEvent);
+ break;
+ case QEvent::TouchBegin:
+ case QEvent::TouchUpdate:
+ case QEvent::TouchEnd:
+ // qDebug() << objectName() << "seenTouchEvent = true";
+ seenTouchEvent = true;
+ event->setAccepted(acceptTouchEvent);
+ break;
+ default:
+ return QWidget::event(event);
+ }
+ return true;
+ }
+};
+
+void tst_QApplication::touchEventPropagation()
+{
+ int argc = 1;
+ QApplication app(argc, &argv0, QApplication::GuiServer);
+ QTouchEvent::TouchPoint touchPoint(0);
+ QTouchEvent touchEvent(QEvent::TouchBegin, Qt::NoModifier, QList<QTouchEvent::TouchPoint *>() << (&touchPoint));
+
+ {
+ // touch event behavior on a window
+ TouchEventPropagationTestWidget window;
+ window.setObjectName("1. window");
+
+ QApplicationPrivate::sendTouchEvent(&window, &touchEvent);
+ QVERIFY(!window.seenTouchEvent);
+ QVERIFY(window.seenMouseEvent);
+
+ window.reset();
+ window.setAttribute(Qt::WA_AcceptsTouchEvents);
+ QApplicationPrivate::sendTouchEvent(&window, &touchEvent);
+ QVERIFY(window.seenTouchEvent);
+ QVERIFY(window.seenMouseEvent);
+
+ window.reset();
+ window.acceptTouchEvent = true;
+ QApplicationPrivate::sendTouchEvent(&window, &touchEvent);
+ QVERIFY(window.seenTouchEvent);
+ QVERIFY(!window.seenMouseEvent);
+ }
+
+ {
+ // touch event behavior on a window with a child widget
+ TouchEventPropagationTestWidget window;
+ window.setObjectName("2. window");
+ TouchEventPropagationTestWidget widget(&window);
+ widget.setObjectName("2. widget");
+
+ QApplicationPrivate::sendTouchEvent(&widget, &touchEvent);
+ QVERIFY(!widget.seenTouchEvent);
+ QVERIFY(widget.seenMouseEvent);
+ QVERIFY(!window.seenTouchEvent);
+ QVERIFY(window.seenMouseEvent);
+
+ window.reset();
+ widget.reset();
+ widget.setAttribute(Qt::WA_AcceptsTouchEvents);
+ QApplicationPrivate::sendTouchEvent(&widget, &touchEvent);
+ QVERIFY(widget.seenTouchEvent);
+ QVERIFY(widget.seenMouseEvent);
+ QVERIFY(!window.seenTouchEvent);
+ QVERIFY(window.seenMouseEvent);
+
+ window.reset();
+ widget.reset();
+ widget.acceptMouseEvent = true;
+ QApplicationPrivate::sendTouchEvent(&widget, &touchEvent);
+ QVERIFY(widget.seenTouchEvent);
+ QVERIFY(widget.seenMouseEvent);
+ QVERIFY(!window.seenTouchEvent);
+ QVERIFY(!window.seenMouseEvent);
+
+ window.reset();
+ widget.reset();
+ widget.acceptTouchEvent = true;
+ QApplicationPrivate::sendTouchEvent(&widget, &touchEvent);
+ QVERIFY(widget.seenTouchEvent);
+ QVERIFY(!widget.seenMouseEvent);
+ QVERIFY(!window.seenTouchEvent);
+ QVERIFY(!window.seenMouseEvent);
+
+ window.reset();
+ widget.reset();
+ widget.setAttribute(Qt::WA_AcceptsTouchEvents, false);
+ window.setAttribute(Qt::WA_AcceptsTouchEvents);
+ QApplicationPrivate::sendTouchEvent(&widget, &touchEvent);
+ QVERIFY(!widget.seenTouchEvent);
+ QVERIFY(widget.seenMouseEvent);
+ QVERIFY(window.seenTouchEvent);
+ QVERIFY(window.seenMouseEvent);
+
+ window.reset();
+ widget.reset();
+ window.acceptTouchEvent = true;
+ QApplicationPrivate::sendTouchEvent(&widget, &touchEvent);
+ QVERIFY(!widget.seenTouchEvent);
+ QVERIFY(!widget.seenMouseEvent);
+ QVERIFY(window.seenTouchEvent);
+ QVERIFY(!window.seenMouseEvent);
+
+ window.reset();
+ widget.reset();
+ widget.acceptMouseEvent = true; // doesn't matter, touch events are propagated first
+ window.acceptTouchEvent = true;
+ QApplicationPrivate::sendTouchEvent(&widget, &touchEvent);
+ QVERIFY(!widget.seenTouchEvent);
+ QVERIFY(!widget.seenMouseEvent);
+ QVERIFY(window.seenTouchEvent);
+ QVERIFY(!window.seenMouseEvent);
+ }
+}
+
//QTEST_APPLESS_MAIN(tst_QApplication)
int main(int argc, char *argv[])
{