20 #include <qpa/qwindowsysteminterface.h>
21 #include <QtGui/QGuiApplication>
25 #include <TouchRegistry.h>
30 TestUtil::TestUtil(QObject *parent)
42 TestUtil::isInstanceOf(QObject *obj, QString name)
44 if (!obj)
return false;
45 bool result = obj->inherits(name.toUtf8());
47 const QMetaObject *metaObject = obj->metaObject();
48 while (!result && metaObject) {
49 const QString className = metaObject->className();
50 const QString qmlName = className.left(className.indexOf(
"_QMLTYPE_"));
51 result = qmlName == name;
52 metaObject = metaObject->superClass();
58 TouchEventSequenceWrapper *TestUtil::touchEvent()
62 ensureTouchRegistryInstalled();
64 return new TouchEventSequenceWrapper(
65 QTest::touchEvent(m_targetWindow, m_touchDevice,
false));
68 void TestUtil::ensureTargetWindow()
70 if (!m_targetWindow && !QGuiApplication::topLevelWindows().isEmpty())
71 m_targetWindow = QGuiApplication::topLevelWindows()[0];
74 void TestUtil::ensureTouchDevice()
77 m_touchDevice =
new QTouchDevice;
78 m_touchDevice->setType(QTouchDevice::TouchScreen);
79 QWindowSystemInterface::registerTouchDevice(m_touchDevice);
83 void TestUtil::ensureTouchRegistryInstalled()
85 if (TouchRegistry::instance())
93 TouchRegistry *touchRegistry =
new TouchRegistry(
this,
new FakeTimerFactory);
95 QQuickView *view = qobject_cast<QQuickView*>(m_targetWindow);
97 view->installEventFilter(touchRegistry);
98 touchRegistry->setParent(view);