7#include <QtQuick/qquickwindow.h>
9#include <QtGui/qtguiglobal.h>
10#include <QtGui/qtestsupport_gui.h>
11#include <QtGui/qwindow.h>
15Q_GUI_EXPORT
void qt_handleMouseEvent(
16 QWindow *window,
const QPointF &local,
const QPointF &global, Qt::MouseButtons state,
17 Qt::MouseButton button, QEvent::Type type, Qt::KeyboardModifiers mods,
int timestamp);
20 QWindow *w, QEvent::Type t,
int k, Qt::KeyboardModifiers mods,
21 const QString &text = QString(),
bool autorep =
false, ushort count = 1);
24 QWindow *window,
const QPointF &local,
const QPointF &global, QPoint pixelDelta,
25 QPoint angleDelta, Qt::KeyboardModifiers mods, Qt::ScrollPhase phase);
28 : QQuickEventReplayService(1, parent)
36 QQmlDebugPacket stream(message);
37 QQuickProfilerData data;
39 stream >> data.time >> data.messageType >> data.detailType;
41 if (data.messageType != Message::Event)
44 switch (data.detailType) {
46 case EventType::Mouse:
52 stream >> data.inputType >> data.inputA >> data.inputB;
54 bool isFirstEvent =
false;
56 QMutexLocker lock(&m_dataMutex);
57 isFirstEvent = m_data.isEmpty();
58 m_data.enqueue(std::move(data));
68 if (QWindow *focusWindow = QGuiApplication::focusWindow())
73 QWindow *found =
nullptr;
74 const QWindowList windowList = QGuiApplication::allWindows();
75 for (QWindow *window : windowList) {
76 if (!qobject_cast<QQuickWindow *>(window))
88 if (!targetWindow()) {
89 qWarning() <<
"Cannot determine target window for event replay. "
90 "Focus a window to use it.";
92 qApp, &QGuiApplication::focusWindowChanged,
93 this, &QQuickEventReplayServiceImpl::start,
94 Qt::SingleShotConnection);
99 &m_schedule, &QTimer::timeout,
100 this, &QQuickEventReplayServiceImpl::sendNextEvent);
101 QObject::connect(
this, &QQuickEventReplayServiceImpl::dataAvailable,
this, [
this]() {
102 QMutexLocker lock(&m_dataMutex);
103 scheduleNextEvent(m_data.head());
106 QMutexLocker lock(&m_dataMutex);
107 if (!m_data.isEmpty())
108 scheduleNextEvent(m_data.head());
113 using InputEventType = QQmlProfilerDefinitions::InputEventType;
114 switch (profilerEventType) {
115 case InputEventType::InputKeyPress:
116 return QEvent::KeyPress;
117 case InputEventType::InputKeyRelease:
118 return QEvent::KeyRelease;
119 case InputEventType::InputMousePress:
120 return QEvent::MouseButtonPress;
121 case InputEventType::InputMouseDoubleClick:
122 return QEvent::MouseButtonDblClick;
123 case InputEventType::InputMouseMove:
124 return QEvent::MouseMove;
125 case InputEventType::InputMouseRelease:
126 return QEvent::MouseButtonRelease;
127 case InputEventType::InputMouseWheel:
128 return QEvent::Wheel;
136 QMutexLocker lock(&m_dataMutex);
137 const QQuickProfilerData data = m_data.dequeue();
138 if (!m_data.isEmpty())
139 scheduleNextEvent(m_data.head());
147 QWindow *window = targetWindow();
149 qWarning() <<
"Target window has disappeared during event replay";
153 const QQuickProfilerData data = takeNextEvent();
154 Q_ASSERT(data.messageType == Message::Event);
156 const QEvent::Type type = eventType(data.inputType);
157 switch (data.detailType) {
158 case EventType::Key: {
159 qt_handleKeyEvent(window, type, data.inputA, Qt::KeyboardModifiers(data.inputB));
162 case EventType::Mouse: {
163 switch (data.inputType) {
164 case InputEventType::InputMouseMove: {
165 m_currentPos = QPoint(data.inputA, data.inputB);
167 window, m_currentPos, window->mapToGlobal(m_currentPos), m_currentButtons,
168 Qt::NoButton, type, m_currentModifiers, m_elapsed.elapsed());
171 case InputEventType::InputMouseWheel: {
173 window, m_currentPos, window->mapToGlobal(m_currentPos), QPoint(),
174 QPoint(data.inputA, data.inputB), m_currentModifiers, Qt::ScrollUpdate);
178 m_currentButtons = Qt::MouseButtons(data.inputB);
180 window, m_currentPos, window->mapToGlobal(m_currentPos), m_currentButtons,
181 Qt::MouseButton(data.inputA), type, m_currentModifiers, m_elapsed.elapsed());
196 m_schedule.start(std::max((nextEvent.time - m_elapsed.nsecsElapsed()) / 1000000ll, 1ll));
void messageReceived(const QByteArray &) override
Combined button and popup list for selecting options.
static QWindow * targetWindow()
Q_GUI_EXPORT void qt_handleKeyEvent(QWindow *w, QEvent::Type t, int k, Qt::KeyboardModifiers mods, const QString &text=QString(), bool autorep=false, ushort count=1)
static QEvent::Type eventType(int profilerEventType)
Q_GUI_EXPORT void qt_handleWheelEvent(QWindow *window, const QPointF &local, const QPointF &global, QPoint pixelDelta, QPoint angleDelta, Qt::KeyboardModifiers mods, Qt::ScrollPhase phase)