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 | |
parent | f09573711c9a400dafe56536c90a54170c017699 (diff) |
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')
19 files changed, 289 insertions, 143 deletions
diff --git a/tests/manual/quick/touchbrowser/AddressBar.qml b/tests/manual/quick/touchbrowser/AddressBar.qml index 6ccea3441..42188c94e 100644 --- a/tests/manual/quick/touchbrowser/AddressBar.qml +++ b/tests/manual/quick/touchbrowser/AddressBar.qml @@ -1,5 +1,5 @@ -// Copyright (C) 2018 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// 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 import QtQuick import QtQuick.Controls diff --git a/tests/manual/quick/touchbrowser/CMakeLists.txt b/tests/manual/quick/touchbrowser/CMakeLists.txt index d4064c05e..c3e9fd895 100644 --- a/tests/manual/quick/touchbrowser/CMakeLists.txt +++ b/tests/manual/quick/touchbrowser/CMakeLists.txt @@ -2,40 +2,30 @@ # SPDX-License-Identifier: BSD-3-Clause if (NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) - cmake_minimum_required(VERSION 3.16) + cmake_minimum_required(VERSION 3.19) project(touchbrowser LANGUAGES CXX) find_package(Qt6BuildInternals COMPONENTS STANDALONE_TEST) endif() -if(NOT CMAKE_CROSSCOMPILING) - add_definitions(-DDESKTOP_BUILD) - set(SOURCES "touchmockingapplication.cpp") -endif() +set(CMAKE_AUTORCC ON) +set(TOUCHMOCKING_DIR "../../touchmocking") + +include_directories(${TOUCHMOCKING_DIR}) +add_definitions(-DQUICK_TOUCHBROWSER) qt_internal_add_manual_test(touchbrowser GUI SOURCES main.cpp - utils.h - ${SOURCES} - LIBRARIES - Qt::GuiPrivate + resources.qrc + ${TOUCHMOCKING_DIR}/touchmockingapplication.cpp + ${TOUCHMOCKING_DIR}/touchmockingapplication.h + ${TOUCHMOCKING_DIR}/utils.h + PUBLIC_LIBRARIES + Qt::Core Qt::Quick Qt::WebEngineQuick ENABLE_AUTOGEN_TOOLS moc ) -set(touchbrowser_resource_files - "AddressBar.qml" - "main.qml" - "MockTouchPoint.qml" - "touchpoint.png" -) - -qt_add_resources(touchbrowser "touchbrowser" - PREFIX - "/" - FILES - ${touchbrowser_resource_files} -) diff --git a/tests/manual/quick/touchbrowser/MockTouchPoint.qml b/tests/manual/quick/touchbrowser/MockTouchPoint.qml index bdce0555c..895e12e70 100644 --- a/tests/manual/quick/touchbrowser/MockTouchPoint.qml +++ b/tests/manual/quick/touchbrowser/MockTouchPoint.qml @@ -1,6 +1,5 @@ -// Copyright (C) 2021 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only - +// 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 import QtQuick Item { diff --git a/tests/manual/quick/touchbrowser/main.cpp b/tests/manual/quick/touchbrowser/main.cpp index 7b222038e..1f4d7d869 100644 --- a/tests/manual/quick/touchbrowser/main.cpp +++ b/tests/manual/quick/touchbrowser/main.cpp @@ -1,16 +1,14 @@ -// Copyright (C) 2018 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// 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 -#if defined(DESKTOP_BUILD) #include "touchmockingapplication.h" -#endif #include "utils.h" -#include <QtGui/QGuiApplication> -#include <QtQml/QQmlApplicationEngine> -#include <QtQml/QQmlContext> -#include <QtQuick/QQuickView> -#include <QtWebEngineQuick/qtwebenginequickglobal.h> +#include <QGuiApplication> +#include <QQmlApplicationEngine> +#include <QQmlContext> +#include <QQuickView> +#include <QtWebEngineQuick> static QUrl startupUrl() { @@ -29,31 +27,10 @@ static QUrl startupUrl() int main(int argc, char **argv) { - QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); - QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts); - - // We use touch mocking on desktop and apply all the mobile switches. - QByteArrayList args = QByteArrayList() - << QByteArrayLiteral("--enable-embedded-switches") - << QByteArrayLiteral("--log-level=0"); - const int count = args.size() + argc; - QList<char*> qargv(count); - - qargv[0] = argv[0]; - for (int i = 0; i < args.size(); ++i) - qargv[i + 1] = args[i].data(); - for (int i = args.size() + 1; i < count; ++i) - qargv[i] = argv[i - args.size()]; - - int qAppArgCount = qargv.size(); - QtWebEngineQuick::initialize(); -#if defined(DESKTOP_BUILD) - TouchMockingApplication app(qAppArgCount, qargv.data()); -#else - QGuiApplication app(qAppArgCount, qargv.data()); -#endif + TouchMockingApplication app(argc, argv); + app.setAttribute(Qt::AA_SynthesizeTouchForUnhandledMouseEvents, true); QQuickView view; Utils utils; diff --git a/tests/manual/quick/touchbrowser/qml.qrc b/tests/manual/quick/touchbrowser/resources.qrc index 5c384502e..87d655a27 100644 --- a/tests/manual/quick/touchbrowser/qml.qrc +++ b/tests/manual/quick/touchbrowser/resources.qrc @@ -2,7 +2,6 @@ <qresource prefix="/"> <file>main.qml</file> <file>AddressBar.qml</file> - <file>MockTouchPoint.qml</file> - <file>touchpoint.png</file> + <file alias="touchpoint.png">../../touchmocking/touchpoint.png</file> </qresource> </RCC> diff --git a/tests/manual/quick/touchbrowser/touchbrowser.pro b/tests/manual/quick/touchbrowser/touchbrowser.pro index 92e4e6703..710584df8 100644 --- a/tests/manual/quick/touchbrowser/touchbrowser.pro +++ b/tests/manual/quick/touchbrowser/touchbrowser.pro @@ -1,19 +1,15 @@ TEMPLATE = app -QT += quick webenginequick -CONFIG += c++11 +DEFINES += QUICK_TOUCHBROWSER +QT += core gui quick webenginequick -SOURCES += \ - main.cpp +INCLUDEPATH += ../../touchmocking +SOURCES += \ + main.cpp \ + ../../touchmocking/touchmockingapplication.cpp HEADERS += \ - utils.h - -RESOURCES += qml.qrc + ../../touchmocking/touchmockingapplication.h \ + ../../touchmocking/utils.h -!cross_compile { - DEFINES += DESKTOP_BUILD - SOURCES += touchmockingapplication.cpp - HEADERS += touchmockingapplication.h - QT += gui-private -} +RESOURCES += resources.qrc diff --git a/tests/manual/quick/touchbrowser/touchmockingapplication.cpp b/tests/manual/quick/touchbrowser/touchmockingapplication.cpp index 4fad86d33..e958d21cd 100644 --- a/tests/manual/quick/touchbrowser/touchmockingapplication.cpp +++ b/tests/manual/quick/touchbrowser/touchmockingapplication.cpp @@ -1,5 +1,5 @@ -// Copyright (C) 2018 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// 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" diff --git a/tests/manual/quick/touchbrowser/touchmockingapplication.h b/tests/manual/quick/touchbrowser/touchmockingapplication.h deleted file mode 100644 index 3264d5a0c..000000000 --- a/tests/manual/quick/touchbrowser/touchmockingapplication.h +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright (C) 2018 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 - -#ifndef TOUCHMOCKINGAPPLICATION_H -#define TOUCHMOCKINGAPPLICATION_H - -#include <QtGui/QGuiApplication> -#include <QtGui/private/qeventpoint_p.h> -#include <QtGui/QEventPoint> - -#include <private/qevent_p.h> - -QT_BEGIN_NAMESPACE -class QQuickView; -class QQuickItem; -QT_END_NAMESPACE - -class TouchMockingApplication : public QGuiApplication -{ - Q_OBJECT - -public: - TouchMockingApplication(int &argc, char **argv); - - virtual bool notify(QObject *, QEvent *) override; - -private: - void updateTouchPoint(const QMouseEvent *, QEventPoint, Qt::MouseButton); - bool sendTouchEvent(QQuickView *, QEvent::Type, ulong timestamp); - void updateVisualMockTouchPoints(QQuickView *,const QList<QEventPoint> &touchPoints); - -private: - bool m_realTouchEventReceived; - int m_pendingFakeTouchEventCount; - - QHash<int, QEventPoint> m_touchPoints; - QSet<int> m_heldTouchPoints; - QHash<int, QQuickItem*> m_activeMockComponents; - - bool m_holdingControl; -}; - -#endif // TOUCHMOCKINGAPPLICATION_H diff --git a/tests/manual/quick/touchbrowser/utils.h b/tests/manual/quick/touchbrowser/utils.h deleted file mode 100644 index 605ebf23d..000000000 --- a/tests/manual/quick/touchbrowser/utils.h +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright (C) 2018 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 - -#ifndef UTILS_H -#define UTILS_H - -#include <QtCore/QFileInfo> -#include <QtCore/QUrl> - -class Utils : public QObject { - Q_OBJECT -public: - Q_INVOKABLE static QUrl fromUserInput(const QString& userInput); -}; - -inline QUrl Utils::fromUserInput(const QString& userInput) -{ - QFileInfo fileInfo(userInput); - if (fileInfo.exists()) - return QUrl::fromLocalFile(fileInfo.absoluteFilePath()); - return QUrl::fromUserInput(userInput); -} - -#endif // UTILS_H 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(); +} diff --git a/tests/manual/touchmocking/touchmockingapplication.h b/tests/manual/touchmocking/touchmockingapplication.h new file mode 100644 index 000000000..4f6e744fc --- /dev/null +++ b/tests/manual/touchmocking/touchmockingapplication.h @@ -0,0 +1,35 @@ +// 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 + +#ifndef TOUCHMOCKINGAPPLICATION_H +#define TOUCHMOCKINGAPPLICATION_H + +#if defined(QUICK_TOUCHBROWSER) +# include <QGuiApplication> +using Application = QGuiApplication; +#elif defined(WIDGET_TOUCHBROWSER) +# include <QApplication> +using Application = QApplication; +#endif + +QT_BEGIN_NAMESPACE +class QCursor; +QT_END_NAMESPACE + +class TouchMockingApplication : public Application +{ + Q_OBJECT + +public: + TouchMockingApplication(int &argc, char **argv); + ~TouchMockingApplication(); + + virtual bool notify(QObject *, QEvent *) override; + +private: + void restoreCursor(); + + QCursor *m_touchPoint; +}; + +#endif // TOUCHMOCKINGAPPLICATION_H diff --git a/tests/manual/quick/touchbrowser/touchpoint.png b/tests/manual/touchmocking/touchpoint.png Binary files differindex 7649ee991..7649ee991 100644 --- a/tests/manual/quick/touchbrowser/touchpoint.png +++ b/tests/manual/touchmocking/touchpoint.png diff --git a/tests/manual/touchmocking/utils.h b/tests/manual/touchmocking/utils.h new file mode 100644 index 000000000..12d493d3f --- /dev/null +++ b/tests/manual/touchmocking/utils.h @@ -0,0 +1,25 @@ +// 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 + +#ifndef UTILS_H +#define UTILS_H + +#include <QFileInfo> +#include <QUrl> + +class Utils : public QObject +{ + Q_OBJECT +public: + Q_INVOKABLE static QUrl fromUserInput(const QString &userInput); +}; + +inline QUrl Utils::fromUserInput(const QString &userInput) +{ + QFileInfo fileInfo(userInput); + if (fileInfo.exists()) + return QUrl::fromLocalFile(fileInfo.absoluteFilePath()); + return QUrl::fromUserInput(userInput); +} + +#endif // UTILS_H diff --git a/tests/manual/widgets/CMakeLists.txt b/tests/manual/widgets/CMakeLists.txt index 4e619f066..1153e7763 100644 --- a/tests/manual/widgets/CMakeLists.txt +++ b/tests/manual/widgets/CMakeLists.txt @@ -1,2 +1,3 @@ add_subdirectory(inputmethods) +add_subdirectory(touchbrowser) add_subdirectory(webgl) diff --git a/tests/manual/widgets/touchbrowser/CMakeLists.txt b/tests/manual/widgets/touchbrowser/CMakeLists.txt new file mode 100644 index 000000000..2ecad1193 --- /dev/null +++ b/tests/manual/widgets/touchbrowser/CMakeLists.txt @@ -0,0 +1,30 @@ +# 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 + +if (NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.19) + project(touchbrowser LANGUAGES CXX) + find_package(Qt6BuildInternals COMPONENTS STANDALONE_TEST) +endif() + +set(CMAKE_AUTORCC ON) +set(TOUCHMOCKING_DIR "../../touchmocking") + +include_directories(${TOUCHMOCKING_DIR}) +add_definitions(-DWIDGET_TOUCHBROWSER) + +qt_internal_add_manual_test(touchbrowser + GUI + SOURCES + main.cpp + resources.qrc + ${TOUCHMOCKING_DIR}/touchmockingapplication.cpp + ${TOUCHMOCKING_DIR}/touchmockingapplication.h + ${TOUCHMOCKING_DIR}/utils.h + PUBLIC_LIBRARIES + Qt::Core + Qt::Gui + Qt::WebEngineWidgets + ENABLE_AUTOGEN_TOOLS + moc +) diff --git a/tests/manual/widgets/touchbrowser/main.cpp b/tests/manual/widgets/touchbrowser/main.cpp new file mode 100644 index 000000000..8c6b45279 --- /dev/null +++ b/tests/manual/widgets/touchbrowser/main.cpp @@ -0,0 +1,62 @@ +// 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 "utils.h" + +#include <QApplication> +#include <QLineEdit> +#include <QMainWindow> +#include <QToolBar> +#include <QWebEngineView> + + +static QUrl startupUrl() +{ + QUrl ret; + QStringList args(qApp->arguments()); + args.takeFirst(); + for (const QString &arg : qAsConst(args)) { + if (arg.startsWith(QLatin1Char('-'))) + continue; + ret = Utils::fromUserInput(arg); + if (ret.isValid()) + return ret; + } + return QUrl(QStringLiteral("https://www.qt.io/")); +} + +int main(int argc, char **argv) +{ + TouchMockingApplication app(argc, argv); + app.setAttribute(Qt::AA_SynthesizeTouchForUnhandledMouseEvents, true); + + QMainWindow window; + QWebEngineView view(&window); + QToolBar addressBar("AddressBar", &window); + QLineEdit lineEdit(&addressBar); + + view.setAttribute(Qt::WA_AcceptTouchEvents, true); + view.setUrl(startupUrl()); + window.resize(1024, 750); + window.setCentralWidget(&view); + + addressBar.setAttribute(Qt::WA_AcceptTouchEvents, true); + addressBar.setMovable(false); + addressBar.toggleViewAction()->setEnabled(false); + + lineEdit.setAttribute(Qt::WA_AcceptTouchEvents, true); + lineEdit.setClearButtonEnabled(true); + + addressBar.addWidget(&lineEdit); + QObject::connect(&lineEdit, &QLineEdit::returnPressed, [&]() { + QUrl url = Utils::fromUserInput(lineEdit.text()); + lineEdit.setText(url.toDisplayString()); + view.setUrl(url); + }); + + window.addToolBar(&addressBar); + window.show(); + + return app.exec(); +} diff --git a/tests/manual/widgets/touchbrowser/resources.qrc b/tests/manual/widgets/touchbrowser/resources.qrc new file mode 100644 index 000000000..b621823ea --- /dev/null +++ b/tests/manual/widgets/touchbrowser/resources.qrc @@ -0,0 +1,5 @@ +<RCC> + <qresource prefix="/"> + <file alias="touchpoint.png">../../touchmocking/touchpoint.png</file> + </qresource> +</RCC> diff --git a/tests/manual/widgets/touchbrowser/touchbrowser.pro b/tests/manual/widgets/touchbrowser/touchbrowser.pro new file mode 100644 index 000000000..1587f390a --- /dev/null +++ b/tests/manual/widgets/touchbrowser/touchbrowser.pro @@ -0,0 +1,15 @@ +TEMPLATE = app + +DEFINES += WIDGET_TOUCHBROWSER +QT += core gui webenginewidgets + +INCLUDEPATH += ../../touchmocking + +SOURCES += \ + main.cpp \ + ../../touchmocking/touchmockingapplication.cpp +HEADERS += \ + ../../touchmocking/touchmockingapplication.h \ + ../../touchmocking/utils.h + +RESOURCES += resources.qrc diff --git a/tests/manual/widgets/widgets.pro b/tests/manual/widgets/widgets.pro index 34e88f0e3..5c80cc585 100644 --- a/tests/manual/widgets/widgets.pro +++ b/tests/manual/widgets/widgets.pro @@ -2,4 +2,5 @@ TEMPLATE= subdirs SUBDIRS += \ inputmethods \ + touchbrowser \ webgl |