| 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 | #include <QtCore/qtestsupport_core.h> |
| 11 | |
| 12 | QT_BEGIN_NAMESPACE |
| 13 | |
| 14 | class QWindow; |
| 15 | |
| 16 | Q_GUI_EXPORT void qt_handleTouchEvent(QWindow *w, const QPointingDevice *device, |
| 17 | const QList<QEventPoint> &points, |
| 18 | Qt::KeyboardModifiers mods = Qt::NoModifier); |
| 19 | |
| 20 | Q_GUI_EXPORT bool qt_handleTouchEventv2(QWindow *w, const QPointingDevice *device, |
| 21 | const QList<QEventPoint> &points, |
| 22 | Qt::KeyboardModifiers mods = Qt::NoModifier); |
| 23 | |
| 24 | namespace QTest { |
| 25 | |
| 26 | [[nodiscard]] Q_GUI_EXPORT bool qWaitForWindowActive(QWindow *window, int timeout); |
| 27 | [[nodiscard]] Q_GUI_EXPORT bool qWaitForWindowActive(QWindow *window, QDeadlineTimer timeout); |
| 28 | [[nodiscard]] Q_GUI_EXPORT bool qWaitForWindowActive(QWindow *window); |
| 29 | |
| 30 | [[nodiscard]] Q_GUI_EXPORT bool qWaitForWindowFocused(QWindow *window, QDeadlineTimer timeout); |
| 31 | [[nodiscard]] Q_GUI_EXPORT bool qWaitForWindowFocused(QWindow *window); |
| 32 | |
| 33 | [[nodiscard]] Q_GUI_EXPORT bool qWaitForWindowExposed(QWindow *window, int timeout); |
| 34 | [[nodiscard]] Q_GUI_EXPORT bool qWaitForWindowExposed(QWindow *window, QDeadlineTimer timeout); |
| 35 | [[nodiscard]] Q_GUI_EXPORT bool qWaitForWindowExposed(QWindow *window); |
| 36 | |
| 37 | Q_GUI_EXPORT QPointingDevice * createTouchDevice(QInputDevice::DeviceType devType = QInputDevice::DeviceType::TouchScreen, |
| 38 | QInputDevice::Capabilities caps = QInputDevice::Capability::Position); |
| 39 | |
| 40 | class Q_GUI_EXPORT QTouchEventSequence |
| 41 | { |
| 42 | public: |
| 43 | virtual ~QTouchEventSequence(); |
| 44 | QTouchEventSequence& press(int touchId, const QPoint &pt, QWindow *window = nullptr); |
| 45 | QTouchEventSequence& move(int touchId, const QPoint &pt, QWindow *window = nullptr); |
| 46 | QTouchEventSequence& release(int touchId, const QPoint &pt, QWindow *window = nullptr); |
| 47 | virtual QTouchEventSequence& stationary(int touchId); |
| 48 | |
| 49 | virtual bool commit(bool processEvents = true); |
| 50 | |
| 51 | protected: |
| 52 | QTouchEventSequence(QWindow *window, QPointingDevice *aDevice, bool autoCommit); |
| 53 | |
| 54 | QPoint mapToScreen(QWindow *window, const QPoint &pt); |
| 55 | |
| 56 | QEventPoint &point(int touchId); |
| 57 | |
| 58 | QEventPoint &pointOrPreviousPoint(int touchId); |
| 59 | |
| 60 | QMap<int, QEventPoint> previousPoints; |
| 61 | QMap<int, QEventPoint> points; |
| 62 | QWindow *targetWindow; |
| 63 | QPointingDevice *device; |
| 64 | bool commitWhenDestroyed; |
| 65 | friend QTouchEventSequence touchEvent(QWindow *window, QPointingDevice *device, bool autoCommit); |
| 66 | }; |
| 67 | |
| 68 | } // namespace QTest |
| 69 | |
| 70 | // |
| 71 | // W A R N I N G |
| 72 | // ------------- |
| 73 | // |
| 74 | // The QtGuiTest namespace is not part of the Qt API. It exists purely as an |
| 75 | // implementation detail. It may change from version to version without notice, |
| 76 | // or even be removed. |
| 77 | // |
| 78 | // We mean it. |
| 79 | // |
| 80 | |
| 81 | #if QT_CONFIG(test_gui) |
| 82 | namespace QtGuiTest |
| 83 | { |
| 84 | Q_GUI_EXPORT void setKeyboardModifiers(Qt::KeyboardModifiers modifiers); |
| 85 | Q_GUI_EXPORT void setCursorPosition(const QPoint &position); |
| 86 | Q_GUI_EXPORT void synthesizeExtendedKeyEvent(QEvent::Type type, int key, Qt::KeyboardModifiers modifiers, |
| 87 | quint32 nativeScanCode, quint32 nativeVirtualKey, |
| 88 | const QString &text); |
| 89 | Q_GUI_EXPORT bool synthesizeKeyEvent(QWindow *window, QEvent::Type t, int k, Qt::KeyboardModifiers mods, |
| 90 | const QString & text = QString(), bool autorep = false, |
| 91 | ushort count = 1); |
| 92 | |
| 93 | Q_GUI_EXPORT void synthesizeMouseEvent(const QPointF &position, Qt::MouseButtons state, |
| 94 | Qt::MouseButton button, QEvent::Type type, |
| 95 | Qt::KeyboardModifiers modifiers); |
| 96 | |
| 97 | Q_GUI_EXPORT void synthesizeWheelEvent(int rollCount, Qt::KeyboardModifiers modifiers); |
| 98 | |
| 99 | Q_GUI_EXPORT qint64 eventTimeElapsed(); |
| 100 | |
| 101 | Q_GUI_EXPORT void postFakeWindowActivation(QWindow *window); |
| 102 | |
| 103 | Q_GUI_EXPORT QPoint toNativePixels(const QPoint &value, const QWindow *window); |
| 104 | Q_GUI_EXPORT QRect toNativePixels(const QRect &value, const QWindow *window); |
| 105 | Q_GUI_EXPORT qreal scaleFactor(const QWindow *window); |
| 106 | |
| 107 | Q_GUI_EXPORT void setEventPointId(QEventPoint &p, int arg); |
| 108 | Q_GUI_EXPORT void setEventPointPressure(QEventPoint &p, qreal arg); |
| 109 | Q_GUI_EXPORT void setEventPointState(QEventPoint &p, QEventPoint::State arg); |
| 110 | Q_GUI_EXPORT void setEventPointPosition(QEventPoint &p, QPointF arg); |
| 111 | Q_GUI_EXPORT void setEventPointGlobalPosition(QEventPoint &p, QPointF arg); |
| 112 | Q_GUI_EXPORT void setEventPointScenePosition(QEventPoint &p, QPointF arg); |
| 113 | Q_GUI_EXPORT void setEventPointEllipseDiameters(QEventPoint &p, QSizeF arg); |
| 114 | } // namespace QtGuiTest |
| 115 | |
| 116 | #endif // #if QT_CONFIG(test_gui) |
| 117 | |
| 118 | QT_END_NAMESPACE |
| 119 | |
| 120 | #endif // #ifndef QTESTSUPPORT_GUI_H |
| 121 | |