1// Copyright (C) 2023 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 QTESTWHEEL_H
5#define QTESTWHEEL_H
6
7#if 0
8// inform syncqt
9#pragma qt_no_master_include
10#endif
11
12#include <QtTest/qttestglobal.h>
13#include <QtTest/qtestassert.h>
14#include <QtTest/qtestsystem.h>
15#include <QtTest/qtestspontaneevent.h>
16#include <QtCore/qpoint.h>
17#include <QtCore/qstring.h>
18#include <QtCore/qpointer.h>
19#include <QtGui/qevent.h>
20#include <QtGui/qwindow.h>
21
22#include <QtCore/QDebug>
23
24QT_BEGIN_NAMESPACE
25
26Q_GUI_EXPORT void qt_handleWheelEvent(QWindow *window, const QPointF &local,
27 const QPointF &global, QPoint pixelDelta,
28 QPoint angleDelta, Qt::KeyboardModifiers mods, Qt::ScrollPhase phase);
29
30namespace QTest
31{
32 /*! \internal
33 This function creates a mouse wheel event and calls
34 QWindowSystemInterface::handleWheelEvent().
35 \a window is the window that should be receiving the event and \a pos
36 provides the location of the event in the window's local coordinates.
37 \a angleDelta contains the wheel rotation angle, while \a pixelDelta
38 contains the scrolling distance in pixels on screen.
39 The keyboard states at the time of the event are specified by \a stateKey.
40 The scrolling phase of the event is specified by \a phase.
41 */
42 [[maybe_unused]] static void wheelEvent(QWindow *window, QPointF pos,
43 QPoint angleDelta, QPoint pixelDelta = QPoint(0, 0),
44 Qt::KeyboardModifiers stateKey = Qt::NoModifier,
45 Qt::ScrollPhase phase = Qt::NoScrollPhase)
46 {
47 QTEST_ASSERT(window);
48
49 // pos is in window local coordinates
50 const QSize windowSize = window->geometry().size();
51 if (windowSize.width() <= pos.x() || windowSize.height() <= pos.y()) {
52 qWarning(msg: "Mouse event at %d, %d occurs outside target window (%dx%d).",
53 static_cast<int>(pos.x()), static_cast<int>(pos.y()), windowSize.width(), windowSize.height());
54 }
55
56 if (pos.isNull())
57 pos = QPoint(window->width() / 2, window->height() / 2);
58
59 QPointF global = window->mapToGlobal(pos);
60 QPointer<QWindow> w(window);
61
62 if (angleDelta.isNull() && pixelDelta.isNull())
63 qWarning(msg: "No angle or pixel delta specified.");
64
65 qt_handleWheelEvent(window: w, local: pos, global, pixelDelta, angleDelta, mods: stateKey, phase);
66 qApp->processEvents();
67 }
68}
69
70QT_END_NAMESPACE
71
72#endif // QTESTWHEEL_H
73

Provided by KDAB

Privacy Policy
Learn to use CMake with our Intro Training
Find out more

source code of qtbase/src/testlib/qtestwheel.h