| 1 | // Copyright (C) 2018 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | |
| 4 | #ifndef QTESTSUPPORT_GUI_H |
| 5 | #define QTESTSUPPORT_GUI_H |
| 6 | |
| 7 | #include <QtGui/qtguiglobal.h> |
| 8 | #include <QtGui/qevent.h> |
| 9 | #include <QtCore/qmap.h> |
| 10 | |
| 11 | QT_BEGIN_NAMESPACE |
| 12 | |
| 13 | class QWindow; |
| 14 | |
| 15 | Q_GUI_EXPORT void qt_handleTouchEvent(QWindow *w, const QPointingDevice *device, |
| 16 | const QList<QEventPoint> &points, |
| 17 | Qt::KeyboardModifiers mods = Qt::NoModifier); |
| 18 | |
| 19 | Q_GUI_EXPORT bool qt_handleTouchEventv2(QWindow *w, const QPointingDevice *device, |
| 20 | const QList<QEventPoint> &points, |
| 21 | Qt::KeyboardModifiers mods = Qt::NoModifier); |
| 22 | |
| 23 | namespace QTest { |
| 24 | |
| 25 | [[nodiscard]] Q_GUI_EXPORT bool qWaitForWindowActive(QWindow *window, int timeout = 5000); |
| 26 | [[nodiscard]] Q_GUI_EXPORT bool qWaitForWindowFocused(QWindow *widget, QDeadlineTimer timeout = std::chrono::seconds{5}); |
| 27 | [[nodiscard]] Q_GUI_EXPORT bool qWaitForWindowExposed(QWindow *window, int timeout = 5000); |
| 28 | |
| 29 | Q_GUI_EXPORT QPointingDevice * createTouchDevice(QInputDevice::DeviceType devType = QInputDevice::DeviceType::TouchScreen, |
| 30 | QInputDevice::Capabilities caps = QInputDevice::Capability::Position); |
| 31 | |
| 32 | class Q_GUI_EXPORT QTouchEventSequence |
| 33 | { |
| 34 | public: |
| 35 | virtual ~QTouchEventSequence(); |
| 36 | QTouchEventSequence& press(int touchId, const QPoint &pt, QWindow *window = nullptr); |
| 37 | QTouchEventSequence& move(int touchId, const QPoint &pt, QWindow *window = nullptr); |
| 38 | QTouchEventSequence& release(int touchId, const QPoint &pt, QWindow *window = nullptr); |
| 39 | virtual QTouchEventSequence& stationary(int touchId); |
| 40 | |
| 41 | virtual bool commit(bool processEvents = true); |
| 42 | |
| 43 | protected: |
| 44 | QTouchEventSequence(QWindow *window, QPointingDevice *aDevice, bool autoCommit); |
| 45 | |
| 46 | QPoint mapToScreen(QWindow *window, const QPoint &pt); |
| 47 | |
| 48 | QEventPoint &point(int touchId); |
| 49 | |
| 50 | QEventPoint &pointOrPreviousPoint(int touchId); |
| 51 | |
| 52 | QMap<int, QEventPoint> previousPoints; |
| 53 | QMap<int, QEventPoint> points; |
| 54 | QWindow *targetWindow; |
| 55 | QPointingDevice *device; |
| 56 | bool commitWhenDestroyed; |
| 57 | friend QTouchEventSequence touchEvent(QWindow *window, QPointingDevice *device, bool autoCommit); |
| 58 | }; |
| 59 | |
| 60 | } // namespace QTest |
| 61 | |
| 62 | QT_END_NAMESPACE |
| 63 | |
| 64 | #endif |
| 65 | |