File indexing completed on 2024-05-19 15:09:23
0001 /* 0002 SPDX-FileCopyrightText: 2015 Eike Hein <hein@kde.org> 0003 SPDX-FileCopyrightText: 2015 Marco Martin <notmart@gmail.com> 0004 0005 SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 #ifndef EventGenerator_H 0009 #define EventGenerator_H 0010 0011 #include <QObject> 0012 0013 class QQuickItem; 0014 0015 class EventGenerator : public QObject 0016 { 0017 Q_OBJECT 0018 0019 public: 0020 enum MouseEvent { 0021 MouseButtonPress, 0022 MouseButtonRelease, 0023 MouseMove, 0024 }; 0025 Q_ENUM(MouseEvent) 0026 0027 enum GrabEvent { 0028 GrabMouse, 0029 UngrabMouse, 0030 }; 0031 Q_ENUM(GrabEvent) 0032 0033 EventGenerator(QObject *parent = nullptr); 0034 ~EventGenerator() override; 0035 0036 /** 0037 * Send a mouse event of @type to the given @item 0038 */ 0039 Q_INVOKABLE void 0040 sendMouseEvent(QQuickItem *item, EventGenerator::MouseEvent type, int x, int y, int button, Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers); 0041 0042 /** 0043 * Send a mouse event of @type to the given @item, all its children and descendants 0044 */ 0045 Q_INVOKABLE void sendMouseEventRecursive(QQuickItem *item, 0046 EventGenerator::MouseEvent type, 0047 int x, 0048 int y, 0049 int button, 0050 Qt::MouseButtons buttons, 0051 Qt::KeyboardModifiers modifiers); 0052 0053 /** 0054 * Send a wheel event to the given @item 0055 * 0056 * @since 5.16 0057 */ 0058 Q_INVOKABLE void sendWheelEvent(QQuickItem *item, 0059 int x, 0060 int y, 0061 const QPoint &pixelDelta, 0062 const QPoint &angleDelta, 0063 Qt::MouseButtons buttons, 0064 Qt::KeyboardModifiers modifiers); 0065 0066 /** 0067 * Send a wheel event to the given @item, all its children and descendants 0068 * 0069 * @since 5.16 0070 */ 0071 Q_INVOKABLE void sendWheelEventRecursive(QQuickItem *item, 0072 int x, 0073 int y, 0074 const QPoint &pixelDelta, 0075 const QPoint &angleDelta, 0076 Qt::MouseButtons buttons, 0077 Qt::KeyboardModifiers modifiers); 0078 0079 /** 0080 * Send a mouse grab event of @type (grab or ungrab) to the given @item 0081 */ 0082 Q_INVOKABLE void sendGrabEvent(QQuickItem *item, EventGenerator::GrabEvent type); 0083 0084 /** 0085 * Send a mouse grab event of @type (grab or ungrab) to the given @item, all its children and descendants 0086 */ 0087 Q_INVOKABLE void sendGrabEventRecursive(QQuickItem *item, EventGenerator::GrabEvent type); 0088 0089 private: 0090 static QList<QQuickItem *> allChildItemsRecursive(QQuickItem *parentItem); 0091 }; 0092 0093 #endif