20 #include <qpa/qwindowsysteminterface.h>
21 #include <QtGui/QGuiApplication>
25 #include <TouchRegistry.h>
30 TestUtil::TestUtil(QObject *parent)
34 , m_putFakeTimerFactoryInTouchRegistry(false)
43 TestUtil::isInstanceOf(QObject *obj, QString name)
45 if (!obj)
return false;
46 bool result = obj->inherits(name.toUtf8());
48 const QMetaObject *metaObject = obj->metaObject();
49 while (!result && metaObject) {
50 const QString className = metaObject->className();
51 const QString qmlName = className.left(className.indexOf(
"_QMLTYPE_"));
52 result = qmlName == name;
53 metaObject = metaObject->superClass();
59 TouchEventSequenceWrapper *TestUtil::touchEvent(QQuickItem *item)
66 if (!m_putFakeTimerFactoryInTouchRegistry) {
67 TouchRegistry::instance()->setTimerFactory(
new FakeTimerFactory);
68 m_putFakeTimerFactoryInTouchRegistry =
true;
71 return new TouchEventSequenceWrapper(
72 QTest::touchEvent(m_targetWindow, m_touchDevice,
false), item);
75 void TestUtil::ensureTargetWindow()
77 if (!m_targetWindow && !QGuiApplication::topLevelWindows().isEmpty())
78 m_targetWindow = QGuiApplication::topLevelWindows()[0];
81 void TestUtil::ensureTouchDevice()
84 m_touchDevice =
new QTouchDevice;
85 m_touchDevice->setType(QTouchDevice::TouchScreen);
86 QWindowSystemInterface::registerTouchDevice(m_touchDevice);