diff options
Diffstat (limited to 'tests/manual/quick')
28 files changed, 270 insertions, 437 deletions
diff --git a/tests/manual/quick/CMakeLists.txt b/tests/manual/quick/CMakeLists.txt index 0562237b4..d6c4b88a9 100644 --- a/tests/manual/quick/CMakeLists.txt +++ b/tests/manual/quick/CMakeLists.txt @@ -1 +1,2 @@ add_subdirectory(touchbrowser) +add_subdirectory(geopermission) diff --git a/tests/manual/quick/geopermission/CMakeLists.txt b/tests/manual/quick/geopermission/CMakeLists.txt new file mode 100644 index 000000000..088f248e1 --- /dev/null +++ b/tests/manual/quick/geopermission/CMakeLists.txt @@ -0,0 +1,63 @@ +# Copyright (C) 2023 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +if (NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_geopermission LANGUAGES CXX) + find_package(Qt6BuildInternals COMPONENTS STANDALONE_TEST) +endif() + +qt_internal_add_manual_test(tst_geopermission + SOURCES + main.cpp + LIBRARIES + Qt::Core + Qt::Gui + Qt::Qml + Qt::Quick + Qt::WebEngineQuick +) + +if(WIN32) + set_property( + TARGET tst_geopermission + APPEND PROPERTY + SOURCES tst_geopermission.exe.manifest) +endif() + +set_target_properties(tst_geopermission PROPERTIES + WIN32_EXECUTABLE TRUE + MACOSX_BUNDLE TRUE + MACOSX_BUNDLE_GUI_IDENTIFIER "io.qt.dev.webenginequick.tst_geopermission" +) + +# Resources: +set(resources_resource_files + "tst_geopermission.qml" + "geolocation.html" +) + +qt_add_resources(tst_geopermission "resources" + PREFIX + "/" + FILES + ${resources_resource_files} +) + +foreach(permission_plugin IN LISTS QT_ALL_PLUGINS_FOUND_BY_FIND_PACKAGE_permissions) + set(permission_plugin "${QT_CMAKE_EXPORT_NAMESPACE}::${permission_plugin}") + qt6_import_plugins(tst_geopermission INCLUDE ${permission_plugin}) +endforeach() + +if (APPLE) + set_target_properties(tst_geopermission PROPERTIES + MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/Info.plist" + ) + + if (NOT CMAKE_GENERATOR STREQUAL "Xcode") + # Need to sign application for location permissions to work + add_custom_command(TARGET tst_geopermission + POST_BUILD COMMAND codesign -s - tst_geopermission.app) + endif() +endif() + diff --git a/tests/manual/quick/geopermission/Info.plist b/tests/manual/quick/geopermission/Info.plist new file mode 100644 index 000000000..9853e1900 --- /dev/null +++ b/tests/manual/quick/geopermission/Info.plist @@ -0,0 +1,32 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> +<plist version="1.0"> +<dict> + <key>CFBundleInfoDictionaryVersion</key> + <string>6.0</string> + <key>CFBundlePackageType</key> + <string>APPL</string> + <key>CFBundleName</key> + <string>${MACOSX_BUNDLE_BUNDLE_NAME}</string> + <key>CFBundleIdentifier</key> + <string>${MACOSX_BUNDLE_GUI_IDENTIFIER}</string> + <key>CFBundleExecutable</key> + <string>${MACOSX_BUNDLE_EXECUTABLE_NAME}</string> + <key>CFBundleVersion</key> + <string>${MACOSX_BUNDLE_BUNDLE_VERSION}</string> + <key>CFBundleShortVersionString</key> + <string>${MACOSX_BUNDLE_SHORT_VERSION_STRING}</string> + <key>LSMinimumSystemVersion</key> + <string>${CMAKE_OSX_DEPLOYMENT_TARGET}</string> + <key>NSHumanReadableCopyright</key> + <string>${MACOSX_BUNDLE_COPYRIGHT}</string> + <key>CFBundleIconFile</key> + <string>${MACOSX_BUNDLE_ICON_FILE}</string> + <key>CFBundleDevelopmentRegion</key> + <string>English</string> + <key>NSSupportsAutomaticGraphicsSwitching</key> + <true/> + <key>NSLocationUsageDescription</key> + <string>Geolocation test would like to give web sites access to your location for demo purposes.</string> +</dict> +</plist> diff --git a/tests/manual/quick/geopermission/geolocation.html b/tests/manual/quick/geopermission/geolocation.html new file mode 100644 index 000000000..e8c54bc58 --- /dev/null +++ b/tests/manual/quick/geopermission/geolocation.html @@ -0,0 +1,32 @@ +<html> +<head> +<title>Geolocation Permission API Test</title> +<script> + +var errorMessage; +var handled = false; + +function successHandler(location) { + var message = document.getElementById("message"); + message.innerHTML = "Latitude: " + location.coords.latitude + + "<br>Longitude: " + location.coords.longitude; + + errorMessage = ""; + handled = true; +} + +function errorHandler(error) { + errorMessage = error.message; + handled = true; +} + +<!-- One shot example --> +navigator.geolocation.getCurrentPosition(successHandler, errorHandler); + +</script> +</head> +<body> +<div id="message">Location unknown</div> +</body> +</html> + diff --git a/tests/manual/quick/geopermission/main.cpp b/tests/manual/quick/geopermission/main.cpp new file mode 100644 index 000000000..b0e9a7eda --- /dev/null +++ b/tests/manual/quick/geopermission/main.cpp @@ -0,0 +1,39 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include <QtWebEngineQuick/qtwebenginequickglobal.h> + +#include <QtQml/QQmlApplicationEngine> +#include <QtQml/QQmlContext> +#include <QQuickView> + +#include <QtGui/QGuiApplication> + +#include <QtCore/QCommandLineParser> +#include <QtCore/QCommandLineOption> +#include <QtCore/QLoggingCategory> + +int main(int argc, char **argv) +{ + QCoreApplication::setApplicationName("Geopermission test"); + QCoreApplication::setOrganizationName("QtProject"); + + QtWebEngineQuick::initialize(); + + QGuiApplication app(argc, argv); + + QQuickView view; + + view.setTitle("Touch Browser"); + view.setFlags(Qt::Window | Qt::WindowTitleHint); + view.setResizeMode(QQuickView::SizeRootObjectToView); + view.setSource(QUrl("qrc:/tst_geopermission.qml")); + + QObject::connect(view.engine(), SIGNAL(quit()), &app, SLOT(quit())); + + view.show(); + if (view.size().isEmpty()) + view.setGeometry(0, 0, 800, 600); + + return app.exec(); +} diff --git a/tests/manual/quick/geopermission/tst_geopermission.qml b/tests/manual/quick/geopermission/tst_geopermission.qml new file mode 100644 index 000000000..6d6f4de8b --- /dev/null +++ b/tests/manual/quick/geopermission/tst_geopermission.qml @@ -0,0 +1,28 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +import QtQuick +import QtTest +import QtWebEngine + +WebEngineView { + id: webEngineView + width: 200 + height: 200 + url: Qt.resolvedUrl("qrc:/geolocation.html") + property bool deniedGeolocation: false + property bool geoPermissionRequested: false + + onPermissionRequested: function(perm) { + if (perm.feature === WebEnginePermission.Geolocation) { + geoPermissionRequested = true + if (deniedGeolocation) { + perm.deny() + } + else { + perm.grant() + } + } + } + +} diff --git a/tests/manual/quick/pdf/bookmarks-list.qml b/tests/manual/quick/pdf/bookmarks-list.qml index 2be0d6848..e0af43054 100644 --- a/tests/manual/quick/pdf/bookmarks-list.qml +++ b/tests/manual/quick/pdf/bookmarks-list.qml @@ -1,5 +1,5 @@ // Copyright (C) 2022 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only import QtQuick import QtQuick.Controls import QtQuick.Dialogs diff --git a/tests/manual/quick/pdf/bookmarks.qml b/tests/manual/quick/pdf/bookmarks.qml index e12629b31..86ae4e347 100644 --- a/tests/manual/quick/pdf/bookmarks.qml +++ b/tests/manual/quick/pdf/bookmarks.qml @@ -1,5 +1,5 @@ // Copyright (C) 2022 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only import QtQuick import QtQuick.Controls import QtQuick.Dialogs diff --git a/tests/manual/quick/pdf/gridview.qml b/tests/manual/quick/pdf/gridview.qml index 773e72388..69b85470d 100644 --- a/tests/manual/quick/pdf/gridview.qml +++ b/tests/manual/quick/pdf/gridview.qml @@ -1,5 +1,5 @@ // Copyright (C) 2022 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only import QtQuick import QtQuick.Pdf diff --git a/tests/manual/quick/pdf/listview.qml b/tests/manual/quick/pdf/listview.qml index d01be9e86..1c997fdce 100644 --- a/tests/manual/quick/pdf/listview.qml +++ b/tests/manual/quick/pdf/listview.qml @@ -1,5 +1,5 @@ // Copyright (C) 2022 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only import QtQuick import QtQuick.Pdf diff --git a/tests/manual/quick/pdf/multipleDocuments.qml b/tests/manual/quick/pdf/multipleDocuments.qml index 9d08178f0..7826c9a8f 100644 --- a/tests/manual/quick/pdf/multipleDocuments.qml +++ b/tests/manual/quick/pdf/multipleDocuments.qml @@ -1,5 +1,5 @@ // Copyright (C) 2022 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only import QtQuick import QtQuick.Controls import QtQuick.Dialogs @@ -44,7 +44,7 @@ ApplicationWindow { action: Action { shortcut: StandardKey.ZoomIn enabled: pageView.sourceSize.width < 10000 - icon.source: "../../../../examples/pdf/pdfviewer/resources/zoom-in.svg" + icon.source: "../../../../examples/pdf/singlepage/resources/zoom-in.svg" onTriggered: pageView.renderScale *= root.scaleStep } } @@ -52,20 +52,20 @@ ApplicationWindow { action: Action { shortcut: StandardKey.ZoomOut enabled: pageView.sourceSize.width > 50 - icon.source: "../../../../examples/pdf/pdfviewer/resources/zoom-out.svg" + icon.source: "../../../../examples/pdf/singlepage/resources/zoom-out.svg" onTriggered: pageView.renderScale /= root.scaleStep } } ToolButton { action: Action { shortcut: "Ctrl+0" - icon.source: "../../../../examples/pdf/pdfviewer/resources/zoom-original.svg" + icon.source: "../../../../examples/pdf/singlepage/resources/zoom-original.svg" onTriggered: pageView.resetScale() } } ToolButton { action: Action { - icon.source: "../../../../examples/pdf/pdfviewer/resources/go-previous-view-page.svg" + icon.source: "../../../../examples/pdf/singlepage/resources/go-previous-view-page.svg" enabled: pageView.backEnabled onTriggered: pageView.back() } @@ -84,7 +84,7 @@ ApplicationWindow { } ToolButton { action: Action { - icon.source: "../../../../examples/pdf/pdfviewer/resources/go-next-view-page.svg" + icon.source: "../../../../examples/pdf/singlepage/resources/go-next-view-page.svg" enabled: pageView.forwardEnabled onTriggered: pageView.forward() } diff --git a/tests/manual/quick/pdf/pdfPageView.qml b/tests/manual/quick/pdf/pdfPageView.qml index 475e1d608..edf3aa05b 100644 --- a/tests/manual/quick/pdf/pdfPageView.qml +++ b/tests/manual/quick/pdf/pdfPageView.qml @@ -1,5 +1,5 @@ // Copyright (C) 2022 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only import QtQuick import QtQuick.Controls import QtQuick.Dialogs @@ -24,7 +24,7 @@ ApplicationWindow { ToolButton { action: Action { shortcut: StandardKey.Open - icon.source: "../../../../examples/pdf/pdfviewer/resources/document-open.svg" + icon.source: "../../../../examples/pdf/singlepage/resources/document-open.svg" onTriggered: fileDialog.open() } } @@ -32,7 +32,7 @@ ApplicationWindow { action: Action { shortcut: StandardKey.ZoomIn enabled: pageView.sourceSize.width < 10000 - icon.source: "../../../../examples/pdf/pdfviewer/resources/zoom-in.svg" + icon.source: "../../../../examples/pdf/singlepage/resources/zoom-in.svg" onTriggered: pageView.renderScale *= root.scaleStep } } @@ -40,46 +40,46 @@ ApplicationWindow { action: Action { shortcut: StandardKey.ZoomOut enabled: pageView.sourceSize.width > 50 - icon.source: "../../../../examples/pdf/pdfviewer/resources/zoom-out.svg" + icon.source: "../../../../examples/pdf/singlepage/resources/zoom-out.svg" onTriggered: pageView.renderScale /= root.scaleStep } } ToolButton { action: Action { - icon.source: "../../../../examples/pdf/pdfviewer/resources/zoom-fit-width.svg" + icon.source: "../../../../examples/pdf/singlepage/resources/zoom-fit-width.svg" onTriggered: pageView.scaleToWidth(root.contentItem.width, root.contentItem.height) } } ToolButton { action: Action { - icon.source: "../../../../examples/pdf/pdfviewer/resources/zoom-fit-best.svg" + icon.source: "../../../../examples/pdf/singlepage/resources/zoom-fit-best.svg" onTriggered: pageView.scaleToPage(root.contentItem.width, root.contentItem.height) } } ToolButton { action: Action { shortcut: "Ctrl+0" - icon.source: "../../../../examples/pdf/pdfviewer/resources/zoom-original.svg" + icon.source: "../../../../examples/pdf/singlepage/resources/zoom-original.svg" onTriggered: pageView.resetScale() } } ToolButton { action: Action { shortcut: "Ctrl+L" - icon.source: "../../../../examples/pdf/pdfviewer/resources/rotate-left.svg" + icon.source: "../../../../examples/pdf/singlepage/resources/rotate-left.svg" onTriggered: pageView.rotation -= 90 } } ToolButton { action: Action { shortcut: "Ctrl+R" - icon.source: "../../../../examples/pdf/pdfviewer/resources/rotate-right.svg" + icon.source: "../../../../examples/pdf/singlepage/resources/rotate-right.svg" onTriggered: pageView.rotation += 90 } } ToolButton { action: Action { - icon.source: "../../../../examples/pdf/pdfviewer/resources/go-previous-view-page.svg" + icon.source: "../../../../examples/pdf/singlepage/resources/go-previous-view-page.svg" enabled: pageView.backEnabled onTriggered: pageView.back() } @@ -115,7 +115,7 @@ ApplicationWindow { } ToolButton { action: Action { - icon.source: "../../../../examples/pdf/pdfviewer/resources/go-next-view-page.svg" + icon.source: "../../../../examples/pdf//resources/go-next-view-page.svg" enabled: pageView.forwardEnabled onTriggered: pageView.forward() } @@ -126,7 +126,7 @@ ApplicationWindow { ToolButton { action: Action { shortcut: StandardKey.Copy - icon.source: "../../../../examples/pdf/pdfviewer/resources/edit-copy.svg" + icon.source: "../../../../examples/pdf/singlepage/resources/edit-copy.svg" enabled: pageView.selectedText !== "" onTriggered: pageView.copySelectionToClipboard() } @@ -246,7 +246,7 @@ ApplicationWindow { RowLayout { ToolButton { action: Action { - icon.source: "../../../../examples/pdf/pdfviewer/resources/go-up-search.svg" + icon.source: "../../../../examples/pdf/singlepage/resources/go-up-search.svg" shortcut: StandardKey.FindPrevious onTriggered: pageView.searchBack() } @@ -261,7 +261,7 @@ ApplicationWindow { Layout.fillWidth: true Image { visible: searchField.text !== "" - source: "../../../../examples/pdf/pdfviewer/resources/edit-clear.svg" + source: "../../../../examples/pdf/singlepage/resources/edit-clear.svg" anchors { right: parent.right top: parent.top @@ -276,7 +276,7 @@ ApplicationWindow { } ToolButton { action: Action { - icon.source: "../../../../examples/pdf/pdfviewer/resources/go-down-search.svg" + icon.source: "../../../../examples/pdf/singlepage/resources/go-down-search.svg" shortcut: StandardKey.FindNext onTriggered: pageView.searchForward() } diff --git a/tests/manual/quick/pdf/pessimizedListView.qml b/tests/manual/quick/pdf/pessimizedListView.qml index 1b514668e..6e1083fd3 100644 --- a/tests/manual/quick/pdf/pessimizedListView.qml +++ b/tests/manual/quick/pdf/pessimizedListView.qml @@ -1,5 +1,5 @@ // Copyright (C) 2022 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only import QtQuick import QtQuick.Controls import QtQuick.Dialogs diff --git a/tests/manual/quick/pdf/simplest.qml b/tests/manual/quick/pdf/simplest.qml index 3f39bb213..0736f38ae 100644 --- a/tests/manual/quick/pdf/simplest.qml +++ b/tests/manual/quick/pdf/simplest.qml @@ -1,5 +1,5 @@ // Copyright (C) 2022 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only import QtQuick Image { diff --git a/tests/manual/quick/pdf/underscoredLinks.qml b/tests/manual/quick/pdf/underscoredLinks.qml index 514008ca2..f23d9a5a1 100644 --- a/tests/manual/quick/pdf/underscoredLinks.qml +++ b/tests/manual/quick/pdf/underscoredLinks.qml @@ -1,5 +1,5 @@ // Copyright (C) 2022 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only import QtQuick import QtQuick.Controls import QtQuick.Dialogs diff --git a/tests/manual/quick/pdf/withdoc.qml b/tests/manual/quick/pdf/withdoc.qml index d4bf12e29..bcd1a9b58 100644 --- a/tests/manual/quick/pdf/withdoc.qml +++ b/tests/manual/quick/pdf/withdoc.qml @@ -1,5 +1,5 @@ // Copyright (C) 2022 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only import QtQuick import QtQuick.Controls import QtQuick.Dialogs @@ -19,6 +19,11 @@ Window { onPasswordRequired: function() { passwordDialog.open() } } + Component.onCompleted: { + if (Application.arguments.length > 2) + doc.source = Application.arguments[Application.arguments.length - 1] + } + FileDialog { id: fileDialog title: "Open a PDF file" @@ -85,6 +90,7 @@ Window { PdfPageImage { id: image document: doc + retainWhileLoading: true property real zoomFactor: Math.sqrt(2) @@ -120,6 +126,10 @@ Window { } } Shortcut { + sequence: StandardKey.SelectAll + onActivated: selection.selectAll() + } + Shortcut { sequence: "Ctrl+0" onActivated: image.sourceSize = undefined } diff --git a/tests/manual/quick/quick.pro b/tests/manual/quick/quick.pro deleted file mode 100644 index 8522763f8..000000000 --- a/tests/manual/quick/quick.pro +++ /dev/null @@ -1,5 +0,0 @@ -TEMPLATE = subdirs - -SUBDIRS += \ - faviconbrowser \ - touchbrowser diff --git a/tests/manual/quick/touchbrowser/AddressBar.qml b/tests/manual/quick/touchbrowser/AddressBar.qml index 6ccea3441..36a83d872 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 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..0d3275e58 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 +qt_internal_add_manual_test(touchbrowser-quick GUI SOURCES main.cpp - utils.h - ${SOURCES} + resources.qrc + ${TOUCHMOCKING_DIR}/touchmockingapplication.cpp + ${TOUCHMOCKING_DIR}/touchmockingapplication.h + ${TOUCHMOCKING_DIR}/utils.h LIBRARIES - Qt::GuiPrivate + 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..8583d934f 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. +// Copyright (C) 2022 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial 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 b63f3b31c..7db3f40a1 100644 --- a/tests/manual/quick/touchbrowser/main.cpp +++ b/tests/manual/quick/touchbrowser/main.cpp @@ -1,23 +1,21 @@ -// 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 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() { QUrl ret; QStringList args(qApp->arguments()); args.takeFirst(); - for (const QString &arg : qAsConst(args)) { + for (const QString &arg : std::as_const(args)) { if (arg.startsWith(QLatin1Char('-'))) continue; ret = Utils::fromUserInput(arg); @@ -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/main.qml b/tests/manual/quick/touchbrowser/main.qml index 83ede7d75..ed60b36e5 100644 --- a/tests/manual/quick/touchbrowser/main.qml +++ b/tests/manual/quick/touchbrowser/main.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 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only import QtQuick import QtQuick.Layouts 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 deleted file mode 100644 index 4fad86d33..000000000 --- a/tests/manual/quick/touchbrowser/touchmockingapplication.cpp +++ /dev/null @@ -1,261 +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 - -#include "touchmockingapplication.h" - -#include <qpa/qwindowsysteminterface.h> -#include <QtQuick/QQuickItem> -#include <QtQuick/QQuickView> -#include <QInputDevice> - -static inline bool isTouchEvent(const QEvent* event) -{ - switch (event->type()) { - case QEvent::TouchBegin: - case QEvent::TouchUpdate: - case QEvent::TouchEnd: - return true; - default: - return false; - } -} - -static inline bool isMouseEvent(const QEvent* event) -{ - switch (event->type()) { - case QEvent::MouseButtonPress: - case QEvent::MouseMove: - case QEvent::MouseButtonRelease: - case QEvent::MouseButtonDblClick: - return true; - default: - return false; - } -} - -TouchMockingApplication::TouchMockingApplication(int& argc, char** argv) - : QGuiApplication(argc, argv) - , m_realTouchEventReceived(false) - , m_pendingFakeTouchEventCount(0) - , m_holdingControl(false) -{ -} - -bool TouchMockingApplication::notify(QObject* target, QEvent* event) -{ - // We try to be smart, if we received real touch event, we are probably on a device - // with touch screen, and we should not have touch mocking. - - if (!event->spontaneous() || m_realTouchEventReceived) - return QGuiApplication::notify(target, event); - - if (isTouchEvent(event)) { - if (m_pendingFakeTouchEventCount) - --m_pendingFakeTouchEventCount; - else - m_realTouchEventReceived = true; - return QGuiApplication::notify(target, event); - } - - QQuickView* window = qobject_cast<QQuickView*>(target); - if (!window) - return QGuiApplication::notify(target, event); - - m_holdingControl = QGuiApplication::keyboardModifiers().testFlag(Qt::ControlModifier); - - if (event->type() == QEvent::KeyRelease && static_cast<QKeyEvent*>(event)->key() == Qt::Key_Control) { - foreach (int id, m_heldTouchPoints) - if (m_touchPoints.contains(id) && !QGuiApplication::mouseButtons().testFlag(Qt::MouseButton(id))) { - QMutableEventPoint::setState(m_touchPoints[id], QEventPoint::Released); - m_heldTouchPoints.remove(id); - } else - QMutableEventPoint::setState(m_touchPoints[id], QEventPoint::Stationary); - - sendTouchEvent(window, m_heldTouchPoints.isEmpty() ? QEvent::TouchEnd : QEvent::TouchUpdate, static_cast<QKeyEvent*>(event)->timestamp()); - } - - if (isMouseEvent(event)) { - const QMouseEvent* const mouseEvent = static_cast<QMouseEvent*>(event); - - QEventPoint touchPoint; - QMutableEventPoint::setPressure(touchPoint, 1); - - QEvent::Type touchType = QEvent::None; - - switch (mouseEvent->type()) { - case QEvent::MouseButtonPress: - QMutableEventPoint::setId(touchPoint, mouseEvent->button()); - if (m_touchPoints.contains(touchPoint.id())) { - QMutableEventPoint::setState(touchPoint, QEventPoint::Updated); - touchType = QEvent::TouchUpdate; - } else { - QMutableEventPoint::setState(touchPoint, QEventPoint::Pressed); - // Check if more buttons are held down than just the event triggering one. - if (mouseEvent->buttons() > mouseEvent->button()) - touchType = QEvent::TouchUpdate; - else - touchType = QEvent::TouchBegin; - } - break; - case QEvent::MouseMove: - if (!mouseEvent->buttons()) { - // We have to swallow the event instead of propagating it, - // since we avoid sending the mouse release events and if the - // Flickable is the mouse grabber it would receive the event - // and would move the content. - event->accept(); - return true; - } - touchType = QEvent::TouchUpdate; - QMutableEventPoint::setId(touchPoint, mouseEvent->buttons()); - QMutableEventPoint::setState(touchPoint, QEventPoint::Updated); - break; - case QEvent::MouseButtonRelease: - // Check if any buttons are still held down after this event. - if (mouseEvent->buttons()) - touchType = QEvent::TouchUpdate; - else - touchType = QEvent::TouchEnd; - QMutableEventPoint::setId(touchPoint, mouseEvent->button()); - QMutableEventPoint::setState(touchPoint, QEventPoint::Released); - break; - case QEvent::MouseButtonDblClick: - // Eat double-clicks, their accompanying press event is all we need. - event->accept(); - return true; - default: - Q_ASSERT_X(false, "multi-touch mocking", "unhandled event type"); - } - - // A move can have resulted in multiple buttons, so we need check them individually. - if (touchPoint.id() & Qt::LeftButton) - updateTouchPoint(mouseEvent, touchPoint, Qt::LeftButton); - if (touchPoint.id() & Qt::MiddleButton) - updateTouchPoint(mouseEvent, touchPoint, Qt::MiddleButton); - if (touchPoint.id() & Qt::RightButton) - updateTouchPoint(mouseEvent, touchPoint, Qt::RightButton); - - if (m_holdingControl && touchPoint.state() == QEventPoint::Released) { - // We avoid sending the release event because the Flickable is - // listening to mouse events and would start a bounce-back - // animation if it received a mouse release. - event->accept(); - return true; - } - - // Update states for all other touch-points - for (QHash<int, QEventPoint>::iterator it = m_touchPoints.begin(), end = m_touchPoints.end(); it != end; ++it) { - if (!(it.value().id() & touchPoint.id())) - QMutableEventPoint::setState(it.value(), QEventPoint::Stationary); - } - - Q_ASSERT(touchType != QEvent::None); - - if (!sendTouchEvent(window, touchType, mouseEvent->timestamp())) - return QGuiApplication::notify(target, event); - - event->accept(); - return true; - } - - return QGuiApplication::notify(target, event); -} - -void TouchMockingApplication::updateTouchPoint(const QMouseEvent* mouseEvent, QEventPoint touchPoint, Qt::MouseButton mouseButton) -{ - // Ignore inserting additional touch points if Ctrl isn't held because it produces - // inconsistent touch events and results in assers in the gesture recognizers. - if (!m_holdingControl && m_touchPoints.size() && !m_touchPoints.contains(mouseButton)) - return; - - if (m_holdingControl && touchPoint.state() == QEventPoint::Released) { - m_heldTouchPoints.insert(mouseButton); - return; - } - - // Gesture recognition uses the screen position for the initial threshold - // but since the canvas translates touch events we actually need to pass - // the screen position as the scene position to deliver the appropriate - // coordinates to the target. - QMutableEventPoint::setPosition(touchPoint, mouseEvent->position()); - QMutableEventPoint::setScenePosition(touchPoint, mouseEvent->globalPosition()); - - if (touchPoint.state() == QEventPoint::Pressed) - QMutableEventPoint::setScenePosition(touchPoint, mouseEvent->scenePosition()); - else { - const QEventPoint& oldTouchPoint = m_touchPoints[mouseButton]; - QMutableEventPoint::setGlobalLastPosition(touchPoint, oldTouchPoint.globalPosition()); - } - - // Update current touch-point. - QMutableEventPoint::setId(touchPoint, mouseButton); - m_touchPoints.insert(mouseButton, touchPoint); -} - -bool TouchMockingApplication::sendTouchEvent(QQuickView* window, QEvent::Type type, ulong timestamp) -{ - static QPointingDevice* device = 0; - if (!device) { - device = new QPointingDevice(QStringLiteral("MockTouchDevice"), 1, - QPointingDevice::DeviceType::TouchScreen, - QPointingDevice::PointerType::AllPointerTypes, - QInputDevice::Capability::All, 3, 3, - QString(), QPointingDeviceUniqueId(), window->rootObject()); - - QWindowSystemInterface::registerInputDevice(device); - } - - m_pendingFakeTouchEventCount++; - - const QList<QEventPoint>& currentTouchPoints = m_touchPoints.values(); - QEventPoint::States touchPointStates = QEventPoint::States(); - foreach (const QEventPoint& touchPoint, currentTouchPoints) - touchPointStates |= touchPoint.state(); - - QTouchEvent event(type, device, Qt::NoModifier, currentTouchPoints); - event.setTimestamp(timestamp); - event.setAccepted(false); - - QGuiApplication::notify(window, &event); - - updateVisualMockTouchPoints(window, m_holdingControl ? currentTouchPoints : QList<QEventPoint>()); - - // Get rid of touch-points that are no longer valid - foreach (const QEventPoint& touchPoint, currentTouchPoints) { - if (touchPoint.state() == QEventPoint::Released) - m_touchPoints.remove(touchPoint.id()); - } - - return event.isAccepted(); -} - -void TouchMockingApplication::updateVisualMockTouchPoints(QQuickView* window,const QList<QEventPoint>& touchPoints) -{ - if (touchPoints.isEmpty()) { - // Hide all touch indicator items. - foreach (QQuickItem* item, m_activeMockComponents.values()) - item->setProperty("pressed", false); - - return; - } - - foreach (const QEventPoint& touchPoint, touchPoints) { - QQuickItem* mockTouchPointItem = m_activeMockComponents.value(touchPoint.id()); - - if (!mockTouchPointItem) { - QQmlComponent touchMockPointComponent(window->engine(), QUrl("qrc:///MockTouchPoint.qml")); - mockTouchPointItem = qobject_cast<QQuickItem*>(touchMockPointComponent.create()); - Q_ASSERT(mockTouchPointItem); - m_activeMockComponents.insert(touchPoint.id(), mockTouchPointItem); - mockTouchPointItem->setProperty("pointId", QVariant(touchPoint.id())); - mockTouchPointItem->setParent(window->rootObject()); - mockTouchPointItem->setParentItem(window->rootObject()); - } - - mockTouchPointItem->setX(touchPoint.position().x()); - mockTouchPointItem->setY(touchPoint.position().y()); - mockTouchPointItem->setWidth(touchPoint.ellipseDiameters().width()); - mockTouchPointItem->setHeight(touchPoint.ellipseDiameters().height()); - mockTouchPointItem->setProperty("pressed", QVariant(touchPoint.state() != QEventPoint::Released)); - } -} 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/touchpoint.png b/tests/manual/quick/touchbrowser/touchpoint.png Binary files differdeleted file mode 100644 index 7649ee991..000000000 --- a/tests/manual/quick/touchbrowser/touchpoint.png +++ /dev/null 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 |