/**************************************************************************** ** ** Copyright (C) 2018 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the manual tests of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in ** a written agreement between you and The Qt Company. For licensing terms ** and conditions see https://www.qt.io/terms-conditions. For further ** information use the contact form at https://www.qt.io/contact-us. ** ** GNU General Public License Usage ** Alternatively, this file may be used under the terms of the GNU ** General Public License version 3 as published by the Free Software ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT ** included in the packaging of this file. Please review the following ** information to ensure the GNU General Public License requirements will ** be met: https://www.gnu.org/licenses/gpl-3.0.html. ** ** $QT_END_LICENSE$ ** ****************************************************************************/ #include #include #include #include class MyQuickWindow : public QQuickWindow { public: MyQuickWindow() : QQuickWindow() { m_text = new QQuickText(contentItem()); } bool event(QEvent *e) override { bool acceptEvent = false; bool handleEvent = true; enum Device { TouchDevice, MouseDevice, UnknownDevice }; int device = UnknownDevice; switch (e->type()) { case QEvent::TouchBegin: log("TouchBegin"); device = TouchDevice; acceptEvent = true; break; case QEvent::TouchUpdate: log("TouchUpdate"); device = TouchDevice; acceptEvent = true; break; case QEvent::TouchEnd: log("TouchEnd"); device = TouchDevice; acceptEvent = true; break; case QEvent::MouseButtonPress: log("MouseButtonPress", ' '); device = MouseDevice; break; case QEvent::MouseMove: log("MouseMove", ' '); device = MouseDevice; break; case QEvent::MouseButtonRelease: log("MouseButtonRelease", ' '); device = MouseDevice; break; case QEvent::MouseButtonDblClick: log("MouseButtonDblClick", ' '); device = MouseDevice; break; default: return QQuickWindow::event(e); } if (device == MouseDevice) { QMouseEvent *me = static_cast(e); switch (me->source()) { case Qt::MouseEventNotSynthesized: log("(MouseEventNotSynthesized)"); break; case Qt::MouseEventSynthesizedBySystem: log("(MouseEventSynthesizedBySystem)"); break; case Qt::MouseEventSynthesizedByQt: log("(MouseEventSynthesizedByQt)"); break; case Qt::MouseEventSynthesizedByApplication: log("(MouseEventSynthesizedByApplication)"); break; } } e->setAccepted(acceptEvent); return handleEvent; } void log(const char *string, char padCharacter = '\n') { m_logline.append(string); if (padCharacter == '\n') { m_log.append(QLatin1String(m_logline)); m_log.append(QLatin1Char('\n')); m_text->setText(m_log); qDebug().noquote() << m_logline; m_logline.clear(); } else { m_logline.append(padCharacter); } } QByteArray m_logline; // for console QString m_log; // for QQuickText QQuickText *m_text; }; int main(int argc, char *argv[]) { QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QGuiApplication::setAttribute(Qt::AA_SynthesizeMouseForUnhandledTouchEvents, false); QGuiApplication app(argc, argv); MyQuickWindow window; window.resize(600,800); window.show(); return app.exec(); }