File indexing completed on 2025-01-26 05:06:20
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 #include "eventgenerator.h" 0009 0010 #include <QGuiApplication> 0011 #include <QQuickItem> 0012 #include <QQuickWindow> 0013 0014 EventGenerator::EventGenerator(QObject *parent) 0015 : QObject(parent) 0016 { 0017 } 0018 0019 EventGenerator::~EventGenerator() 0020 { 0021 } 0022 0023 void EventGenerator::sendMouseEvent(QQuickItem *item, 0024 EventGenerator::MouseEvent type, 0025 int x, 0026 int y, 0027 int button, 0028 Qt::MouseButtons buttons, 0029 Qt::KeyboardModifiers modifiers) 0030 { 0031 if (!item) { 0032 return; 0033 } 0034 0035 QEvent::Type eventType; 0036 switch (type) { 0037 case MouseButtonPress: 0038 eventType = QEvent::MouseButtonPress; 0039 break; 0040 case MouseButtonRelease: 0041 eventType = QEvent::MouseButtonRelease; 0042 break; 0043 case MouseMove: 0044 eventType = QEvent::MouseMove; 0045 break; 0046 default: 0047 return; 0048 } 0049 QMouseEvent ev(eventType, QPointF(x, y), static_cast<Qt::MouseButton>(button), buttons, modifiers); 0050 0051 QGuiApplication::sendEvent(item, &ev); 0052 } 0053 0054 #include "moc_eventgenerator.cpp"