Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qtestwheel.h
Go to the documentation of this file.
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
23
24Q_GUI_EXPORT void qt_handleWheelEvent(QWindow *window, const QPointF &local,
25 const QPointF &global, QPoint pixelDelta,
26 QPoint angleDelta, Qt::KeyboardModifiers mods, Qt::ScrollPhase phase);
27
28namespace QTest
29{
30 /*! \internal
31 This function creates a mouse wheel event and calls
32 QWindowSystemInterface::handleWheelEvent().
33 \a window is the window that should be receiving the event and \a pos
34 provides the location of the event in the window's local coordinates.
35 \a angleDelta contains the wheel rotation angle, while \a pixelDelta
36 contains the scrolling distance in pixels on screen.
37 The keyboard states at the time of the event are specified by \a stateKey.
38 The scrolling phase of the event is specified by \a phase.
39 */
40 [[maybe_unused]] static void wheelEvent(QWindow *window, QPointF pos,
41 QPoint angleDelta, QPoint pixelDelta = QPoint(0, 0),
42 Qt::KeyboardModifiers stateKey = Qt::NoModifier,
43 Qt::ScrollPhase phase = Qt::NoScrollPhase)
44 {
45 QTEST_ASSERT(window);
46
47 // pos is in window local coordinates
48 const QSize windowSize = window->geometry().size();
49 if (windowSize.width() <= pos.x() || windowSize.height() <= pos.y()) {
50 qWarning("Mouse event at %d, %d occurs outside target window (%dx%d).",
51 static_cast<int>(pos.x()), static_cast<int>(pos.y()), windowSize.width(), windowSize.height());
52 }
53
54 if (pos.isNull())
55 pos = QPoint(window->width() / 2, window->height() / 2);
56
57 QPointF global = window->mapToGlobal(pos);
58 QPointer<QWindow> w(window);
59
60 if (angleDelta.isNull() && pixelDelta.isNull())
61 qWarning("No angle or pixel delta specified.");
62
63 qt_handleWheelEvent(w, pos, global, pixelDelta, angleDelta, stateKey, phase);
64 qApp->processEvents();
65 }
66}
67
68QT_END_NAMESPACE
69
70#endif // QTESTWHEEL_H
static void wheelEvent(QWindow *window, QPointF pos, QPoint angleDelta, QPoint pixelDelta=QPoint(0, 0), Qt::KeyboardModifiers stateKey=Qt::NoModifier, Qt::ScrollPhase phase=Qt::NoScrollPhase)
Definition qtestwheel.h:40
QDebug Q_GUI_EXPORT & operator<<(QDebug &s, const QVectorPath &path)
Q_GUI_EXPORT void qt_handleWheelEvent(QWindow *window, const QPointF &local, const QPointF &global, QPoint pixelDelta, QPoint angleDelta, Qt::KeyboardModifiers mods, Qt::ScrollPhase phase)