diff options
author | Martin Negyokru <negyokru@inf.u-szeged.hu> | 2022-05-04 14:40:33 +0200 |
---|---|---|
committer | Martin Negyokru <negyokru@inf.u-szeged.hu> | 2022-12-13 10:25:27 +0200 |
commit | c89fcec0bcb65aae737f2dd733790f74e4303114 (patch) | |
tree | 1e800c6043a52a5db9ec0b78bfe53deee9a577bb /tests/manual/touchmocking/touchmockingapplication.cpp | |
parent | f09573711c9a400dafe56536c90a54170c017699 (diff) | |
download | qtwebengine-c89fcec0bcb65aae737f2dd733790f74e4303114.tar.gz |
Implement touchbrowser for widgets
Simplify touchMockingApplication.
Let QApplication synthesize touch events.
Unify quick and widgets touchbrowser.
Fixes: QTBUG-100417
Change-Id: If43432996ca18c67f3ae13ab0767d267b27dc9a2
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'tests/manual/touchmocking/touchmockingapplication.cpp')
-rw-r--r-- | tests/manual/touchmocking/touchmockingapplication.cpp | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/tests/manual/touchmocking/touchmockingapplication.cpp b/tests/manual/touchmocking/touchmockingapplication.cpp new file mode 100644 index 000000000..feedae5cd --- /dev/null +++ b/tests/manual/touchmocking/touchmockingapplication.cpp @@ -0,0 +1,78 @@ +// Copyright (C) 2022 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only + +#include "touchmockingapplication.h" + +#include <QCursor> +#include <QEvent> +#include <QPixmap> + +#if defined(QUICK_TOUCHBROWSER) +# include <QQuickView> +#endif + +#if defined(WIDGET_TOUCHBROWSER) +# include <QMainWindow> +#endif + +static inline bool isMouseEvent(QEvent *event) +{ + switch (event->type()) { + case QEvent::MouseMove: + case QEvent::MouseButtonPress: + case QEvent::MouseButtonRelease: + return true; + default: + return false; + } +} + +TouchMockingApplication::TouchMockingApplication(int &argc, char **argv) + : Application(argc, argv), m_touchPoint(new QCursor(QPixmap(":touchpoint.png"))) +{ +} + +TouchMockingApplication::~TouchMockingApplication() +{ + delete m_touchPoint; +} + +bool TouchMockingApplication::notify(QObject *target, QEvent *event) +{ + switch (event->type()) { + case QEvent::TouchBegin: + setOverrideCursor(*m_touchPoint); + break; + case QEvent::TouchEnd: + restoreCursor(); + break; + default: + break; + } + +// All mouse events that are not accepted by the application will be translated to touch events +// instead (see Qt::AA_SynthesizeTouchForUnhandledMouseEvents). +#if defined(QUICK_TOUCHBROWSER) + if (isMouseEvent(event) && qobject_cast<QQuickView *>(target)) { + event->ignore(); + return false; + } +#elif defined(WIDGET_TOUCHBROWSER) + // Popups ignore touch evenets so we send MouseEvents directly. + if (isMouseEvent(event)) { + if (activePopupWidget()) { + restoreCursor(); + } else { + event->ignore(); + return false; + } + } +#endif + return Application::notify(target, event); +} + +void TouchMockingApplication::restoreCursor() +{ + while (overrideCursor()) + restoreOverrideCursor(); +} |