testlib: Add test function for simulating wheel events

Change-Id: I28fe4dff7db92fb58922948a3eec460df315318c
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
This commit is contained in:
Doris Verria 2022-07-28 10:18:45 +02:00
parent 96740ea3fe
commit 173adf4fbf
5 changed files with 92 additions and 0 deletions

View File

@ -1205,6 +1205,13 @@ Q_GUI_EXPORT bool qt_sendShortcutOverrideEvent(QObject *o, ulong timestamp, int
#endif
}
Q_GUI_EXPORT void qt_handleWheelEvent(QWindow *window, const QPointF &local, const QPointF &global,
QPoint pixelDelta, QPoint angleDelta, Qt::KeyboardModifiers mods,
Qt::ScrollPhase phase)
{
QWindowSystemInterface::handleWheelEvent(window, local, global, pixelDelta, angleDelta, mods, phase);
}
namespace QTest
{
Q_GUI_EXPORT QPointingDevice * createTouchDevice(QInputDevice::DeviceType devType,

View File

@ -55,6 +55,7 @@ qt_internal_add_module(Test
qtestsystem.h
qtesttable.cpp qtesttable_p.h
qtesttouch.h
qtestwheel.h
qttestglobal.h
qxmltestlogger.cpp qxmltestlogger_p.h
DEFINES

View File

@ -17,6 +17,7 @@
#include <QtTest/qtestevent.h>
#include <QtTest/qtestmouse.h>
#include <QtTest/qtesttouch.h>
#include <QtTest/qtestwheel.h>
#include <QtTest/qtestkeyboard.h>
#include <QtGui/qcolor.h>

View File

@ -1363,6 +1363,17 @@
moving the mouse pointer.
*/
/*! \fn void QTest::wheelEvent(QWindow *window, QPointF pos, QPoint angleDelta, QPoint pixelDelta = QPoint(0, 0), Qt::KeyboardModifiers stateKey = Qt::NoModifier, Qt::ScrollPhase phase = Qt::NoScrollPhase)
\since 6.8
Simulates a wheel event within \a window at position \a pos in local
window coordinates. \a angleDelta contains the wheel rotation angle.
A positive value means forward rotation, and a negative one means backward.
\a pixelDelta contains the scrolling distance in pixels on screen. This value can be null.
The keyboard states at the time of the event are specified by \a stateKey.
The scrolling phase of the event is specified by \a phase.
*/
/*!
\fn template <typename T1, typename T2> char *QTest::toString(const std::pair<T1, T2> &pair)
\overload

72
src/testlib/qtestwheel.h Normal file
View File

@ -0,0 +1,72 @@
// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QTESTWHEEL_H
#define QTESTWHEEL_H
#if 0
// inform syncqt
#pragma qt_no_master_include
#endif
#include <QtTest/qttestglobal.h>
#include <QtTest/qtestassert.h>
#include <QtTest/qtestsystem.h>
#include <QtTest/qtestspontaneevent.h>
#include <QtCore/qpoint.h>
#include <QtCore/qstring.h>
#include <QtCore/qpointer.h>
#include <QtGui/qevent.h>
#include <QtGui/qwindow.h>
#include <QtCore/QDebug>
QT_BEGIN_NAMESPACE
Q_GUI_EXPORT void qt_handleWheelEvent(QWindow *window, const QPointF &local,
const QPointF &global, QPoint pixelDelta,
QPoint angleDelta, Qt::KeyboardModifiers mods, Qt::ScrollPhase phase);
namespace QTest
{
/*! \internal
This function creates a mouse wheel event and calls
QWindowSystemInterface::handleWheelEvent().
\a window is the window that should be receiving the event and \a pos
provides the location of the event in the window's local coordinates.
\a angleDelta contains the wheel rotation angle, while \a pixelDelta
contains the scrolling distance in pixels on screen.
The keyboard states at the time of the event are specified by \a stateKey.
The scrolling phase of the event is specified by \a phase.
*/
[[maybe_unused]] static void wheelEvent(QWindow *window, QPointF pos,
QPoint angleDelta, QPoint pixelDelta = QPoint(0, 0),
Qt::KeyboardModifiers stateKey = Qt::NoModifier,
Qt::ScrollPhase phase = Qt::NoScrollPhase)
{
QTEST_ASSERT(window);
// pos is in window local coordinates
const QSize windowSize = window->geometry().size();
if (windowSize.width() <= pos.x() || windowSize.height() <= pos.y()) {
qWarning("Mouse event at %d, %d occurs outside target window (%dx%d).",
static_cast<int>(pos.x()), static_cast<int>(pos.y()), windowSize.width(), windowSize.height());
}
if (pos.isNull())
pos = QPoint(window->width() / 2, window->height() / 2);
QPointF global = window->mapToGlobal(pos);
QPointer<QWindow> w(window);
if (angleDelta.isNull() && pixelDelta.isNull())
qWarning("No angle or pixel delta specified.");
qt_handleWheelEvent(w, pos, global, pixelDelta, angleDelta, stateKey, phase);
qApp->processEvents();
}
}
QT_END_NAMESPACE
#endif // QTESTWHEEL_H