Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-16 09:06:18

0001 // Copyright (C) 2023 The Qt Company Ltd.
0002 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
0003 
0004 #ifndef QTESTWHEEL_H
0005 #define QTESTWHEEL_H
0006 
0007 #if 0
0008 // inform syncqt
0009 #pragma qt_no_master_include
0010 #endif
0011 
0012 #include <QtTest/qttestglobal.h>
0013 #include <QtTest/qtestassert.h>
0014 #include <QtTest/qtestsystem.h>
0015 #include <QtTest/qtestspontaneevent.h>
0016 #include <QtCore/qpoint.h>
0017 #include <QtCore/qstring.h>
0018 #include <QtCore/qpointer.h>
0019 #include <QtGui/qevent.h>
0020 #include <QtGui/qwindow.h>
0021 
0022 QT_BEGIN_NAMESPACE
0023 
0024 Q_GUI_EXPORT void qt_handleWheelEvent(QWindow *window, const QPointF &local,
0025                                       const QPointF &global, QPoint pixelDelta,
0026                                       QPoint angleDelta, Qt::KeyboardModifiers mods, Qt::ScrollPhase phase);
0027 
0028 namespace QTest
0029 {
0030     /*! \internal
0031         This function creates a mouse wheel event and calls
0032         QWindowSystemInterface::handleWheelEvent().
0033         \a window is the window that should be receiving the event and \a pos
0034         provides the location of the event in the window's local coordinates.
0035         \a angleDelta contains the wheel rotation angle, while \a pixelDelta
0036         contains the scrolling distance in pixels on screen.
0037         The keyboard states at the time of the event are specified by \a stateKey.
0038         The scrolling phase of the event is specified by \a phase.
0039     */
0040     [[maybe_unused]] static void wheelEvent(QWindow *window, QPointF pos,
0041                                             QPoint angleDelta, QPoint pixelDelta = QPoint(0, 0),
0042                                             Qt::KeyboardModifiers stateKey = Qt::NoModifier,
0043                                             Qt::ScrollPhase phase = Qt::NoScrollPhase)
0044     {
0045         QTEST_ASSERT(window);
0046 
0047         // pos is in window local coordinates
0048         const QSize windowSize = window->geometry().size();
0049         if (windowSize.width() <= pos.x() || windowSize.height() <= pos.y()) {
0050             qWarning("Mouse event at %d, %d occurs outside target window (%dx%d).",
0051                         static_cast<int>(pos.x()), static_cast<int>(pos.y()), windowSize.width(), windowSize.height());
0052         }
0053 
0054         if (pos.isNull())
0055             pos = QPoint(window->width() / 2, window->height() / 2);
0056 
0057         QPointF global = window->mapToGlobal(pos);
0058         QPointer<QWindow> w(window);
0059 
0060         if (angleDelta.isNull() && pixelDelta.isNull())
0061             qWarning("No angle or pixel delta specified.");
0062 
0063         qt_handleWheelEvent(w, pos, global, pixelDelta, angleDelta, stateKey, phase);
0064         qApp->processEvents();
0065     }
0066 }
0067 
0068 QT_END_NAMESPACE
0069 
0070 #endif // QTESTWHEEL_H