diff options
author | Doris Verria <doris.verria@qt.io> | 2022-07-28 10:18:45 +0200 |
---|---|---|
committer | Doris Verria <doris.verria@qt.io> | 2023-12-20 01:15:17 +0100 |
commit | 173adf4fbf23d2a057d592df7c168d83165b6081 (patch) | |
tree | d50e589099ecfe323fbce76b4fd5ea76cc96738a /src/testlib | |
parent | 96740ea3fed8a7837dc282135661723858fff198 (diff) |
testlib: Add test function for simulating wheel events
Change-Id: I28fe4dff7db92fb58922948a3eec460df315318c
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'src/testlib')
-rw-r--r-- | src/testlib/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/testlib/qtest_gui.h | 1 | ||||
-rw-r--r-- | src/testlib/qtestcase.qdoc | 11 | ||||
-rw-r--r-- | src/testlib/qtestwheel.h | 72 |
4 files changed, 85 insertions, 0 deletions
diff --git a/src/testlib/CMakeLists.txt b/src/testlib/CMakeLists.txt index 34f318f26e..d0ef095970 100644 --- a/src/testlib/CMakeLists.txt +++ b/src/testlib/CMakeLists.txt @@ -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 diff --git a/src/testlib/qtest_gui.h b/src/testlib/qtest_gui.h index 879b142a69..667debb3c4 100644 --- a/src/testlib/qtest_gui.h +++ b/src/testlib/qtest_gui.h @@ -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> diff --git a/src/testlib/qtestcase.qdoc b/src/testlib/qtestcase.qdoc index baae09ee93..05cbf3f276 100644 --- a/src/testlib/qtestcase.qdoc +++ b/src/testlib/qtestcase.qdoc @@ -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 diff --git a/src/testlib/qtestwheel.h b/src/testlib/qtestwheel.h new file mode 100644 index 0000000000..564a586b4b --- /dev/null +++ b/src/testlib/qtestwheel.h @@ -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 |