summaryrefslogtreecommitdiffstats
path: root/src/widgets
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@qt.io>2020-09-03 13:32:55 +0200
committerShawn Rutledge <shawn.rutledge@qt.io>2020-09-08 08:02:15 +0200
commit0e475eeea65305efd94e38bff8fc806b7cfddd72 (patch)
tree2664f9326e9242a6c56adee5f4bc669ddf924b9b /src/widgets
parent2f0f74498a3eb00950688750baccc846d4e11f6b (diff)
Refactor testlib touch functions into qtestsupport_gui and _widgets
Because we removed public setters from QTouchEvent and QEventPoint in 4e400369c08db251cd489fec1229398c224d02b4 and now it's proposed to give QEventPoint a d-pointer again, the implementation of QTouchEventSequence needs to start using QMutableEventPoint: being a friend will no longer be enough, because the member variables won't be accessible in the future. But because we have separate test libs for Gui and Widgets, it needs to be further refactored into two classes. Change-Id: I0bfc0978fc4187348ac872e1330d95259d557b69 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/widgets')
-rw-r--r--src/widgets/kernel/qtestsupport_widgets.cpp70
-rw-r--r--src/widgets/kernel/qtestsupport_widgets.h27
2 files changed, 96 insertions, 1 deletions
diff --git a/src/widgets/kernel/qtestsupport_widgets.cpp b/src/widgets/kernel/qtestsupport_widgets.cpp
index c014579ea8..c9116fcef6 100644
--- a/src/widgets/kernel/qtestsupport_widgets.cpp
+++ b/src/widgets/kernel/qtestsupport_widgets.cpp
@@ -42,7 +42,10 @@
#include "qwidget.h"
#include <QtGui/qwindow.h>
+#include <QtCore/qtestsupport_core.h>
+#include <QtCore/qthread.h>
#include <QtGui/qtestsupport_gui.h>
+#include <QtGui/private/qevent_p.h>
QT_BEGIN_NAMESPACE
@@ -87,4 +90,71 @@ Q_WIDGETS_EXPORT bool QTest::qWaitForWindowExposed(QWidget *widget, int timeout)
return false;
}
+namespace QTest {
+
+QTouchEventWidgetSequence::~QTouchEventWidgetSequence()
+{
+ if (commitWhenDestroyed)
+ commit();
+}
+
+QTouchEventWidgetSequence& QTouchEventWidgetSequence::press(int touchId, const QPoint &pt, QWidget *widget)
+{
+ auto &p = QMutableEventPoint::from(point(touchId));
+ p.setGlobalPosition(mapToScreen(widget, pt));
+ p.setState(QEventPoint::State::Pressed);
+ return *this;
+}
+QTouchEventWidgetSequence& QTouchEventWidgetSequence::move(int touchId, const QPoint &pt, QWidget *widget)
+{
+ auto &p = QMutableEventPoint::from(point(touchId));
+ p.setGlobalPosition(mapToScreen(widget, pt));
+ p.setState(QEventPoint::State::Updated);
+ return *this;
+}
+QTouchEventWidgetSequence& QTouchEventWidgetSequence::release(int touchId, const QPoint &pt, QWidget *widget)
+{
+ auto &p = QMutableEventPoint::from(point(touchId));
+ p.setGlobalPosition(mapToScreen(widget, pt));
+ p.setState(QEventPoint::State::Released);
+ return *this;
+}
+
+QTouchEventWidgetSequence& QTouchEventWidgetSequence::stationary(int touchId)
+{
+ auto &p = QMutableEventPoint::from(pointOrPreviousPoint(touchId));
+ p.setState(QEventPoint::State::Stationary);
+ return *this;
+}
+
+void QTouchEventWidgetSequence::commit(bool processEvents)
+{
+ if (points.isEmpty())
+ return;
+ QThread::msleep(1);
+ if (targetWindow) {
+ qt_handleTouchEvent(targetWindow, device, points.values());
+ } else if (targetWidget) {
+ qt_handleTouchEvent(targetWidget->windowHandle(), device, points.values());
+ }
+ if (processEvents)
+ QCoreApplication::processEvents();
+ previousPoints = points;
+ points.clear();
+}
+
+QTest::QTouchEventWidgetSequence::QTouchEventWidgetSequence(QWidget *widget, QPointingDevice *aDevice, bool autoCommit)
+ : QTouchEventSequence(nullptr, aDevice, autoCommit), targetWidget(widget)
+{
+}
+
+QPoint QTouchEventWidgetSequence::mapToScreen(QWidget *widget, const QPoint &pt)
+{
+ if (widget)
+ return widget->mapToGlobal(pt);
+ return targetWidget ? targetWidget->mapToGlobal(pt) : pt;
+}
+
+} // namespace QTest
+
QT_END_NAMESPACE
diff --git a/src/widgets/kernel/qtestsupport_widgets.h b/src/widgets/kernel/qtestsupport_widgets.h
index 5b4f7e59ba..032cab10a8 100644
--- a/src/widgets/kernel/qtestsupport_widgets.h
+++ b/src/widgets/kernel/qtestsupport_widgets.h
@@ -41,15 +41,40 @@
#define QTESTSUPPORT_WIDGETS_H
#include <QtWidgets/qtwidgetsglobal.h>
+#include <QtGui/qtestsupport_gui.h>
QT_BEGIN_NAMESPACE
+class QPointingDevice;
class QWidget;
namespace QTest {
+
Q_REQUIRED_RESULT Q_WIDGETS_EXPORT bool qWaitForWindowActive(QWidget *widget, int timeout = 5000);
Q_REQUIRED_RESULT Q_WIDGETS_EXPORT bool qWaitForWindowExposed(QWidget *widget, int timeout = 5000);
-}
+
+class Q_WIDGETS_EXPORT QTouchEventWidgetSequence : public QTouchEventSequence
+{
+public:
+ ~QTouchEventWidgetSequence() override;
+ QTouchEventWidgetSequence& press(int touchId, const QPoint &pt, QWidget *widget = nullptr);
+ QTouchEventWidgetSequence& move(int touchId, const QPoint &pt, QWidget *widget = nullptr);
+ QTouchEventWidgetSequence& release(int touchId, const QPoint &pt, QWidget *widget = nullptr);
+ QTouchEventWidgetSequence& stationary(int touchId) override;
+
+ void commit(bool processEvents = true) override;
+
+private:
+ QTouchEventWidgetSequence(QWidget *widget, QPointingDevice *aDevice, bool autoCommit);
+
+ QPoint mapToScreen(QWidget *widget, const QPoint &pt);
+
+ QWidget *targetWidget = nullptr;
+
+ friend QTouchEventWidgetSequence touchEvent(QWidget *widget, QPointingDevice *device, bool autoCommit);
+};
+
+} // namespace QTest
QT_END_NAMESPACE