diff options
author | Szabolcs David <[email protected]> | 2023-03-08 15:04:07 +0100 |
---|---|---|
committer | Szabolcs David <[email protected]> | 2023-04-05 10:50:54 +0000 |
commit | 1fe0003d727bdacd30c552f01000c434971ad3ca (patch) | |
tree | 9bb8e594214e02c8230cea07387d47850bee9505 | |
parent | a09ec269e8b296d39d78b45ae251edb3d7bada41 (diff) |
Also fix an old issue: tab view now presents preview images.
Change-Id: I47eb48b626e62e53e130734c92cc7ec8ed9ecb66
Reviewed-by: Michal Klocek <[email protected]>
-rw-r--r-- | CMakeLists.txt | 56 | ||||
-rw-r--r-- | doc/src/qtwebbrowser.qdoc | 2 | ||||
-rw-r--r-- | qtwebbrowser.pro | 2 | ||||
-rw-r--r-- | src/main.cpp | 9 | ||||
-rw-r--r-- | src/navigationhistoryproxymodel.cpp | 6 | ||||
-rw-r--r-- | src/qml/BrowserWindow.qml | 23 | ||||
-rw-r--r-- | src/qml/FeaturePermissionBar.qml | 8 | ||||
-rw-r--r-- | src/qml/HomeScreen.qml | 6 | ||||
-rw-r--r-- | src/qml/Keyboard.qml | 5 | ||||
-rw-r--r-- | src/qml/Main.qml | 2 | ||||
-rw-r--r-- | src/qml/MockTouchPoint.qml | 2 | ||||
-rw-r--r-- | src/qml/NavigationBar.qml | 76 | ||||
-rw-r--r-- | src/qml/PageView.qml | 72 | ||||
-rw-r--r-- | src/qml/SettingsView.qml | 48 | ||||
-rw-r--r-- | src/qml/assets/UIButton.qml | 28 | ||||
-rw-r--r-- | src/qml/assets/UIToolBar.qml | 21 | ||||
-rw-r--r-- | src/src.pro | 6 | ||||
-rw-r--r-- | src/touchmockingapplication.cpp | 104 | ||||
-rw-r--r-- | src/touchmockingapplication.h | 5 | ||||
-rw-r--r-- | src/touchtracker.cpp | 8 |
20 files changed, 255 insertions, 234 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..2c76204 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,56 @@ +cmake_minimum_required(VERSION 3.16) +project(qtwebbrowser LANGUAGES CXX) + +set(CMAKE_AUTOMOC ON) +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +find_package(Qt6 REQUIRED COMPONENTS Core Gui Qml Quick WebEngineQuick VirtualKeyboard) + +set(SOURCES + src/appengine.cpp + src/appengine.h + src/main.cpp + src/navigationhistoryproxymodel.cpp + src/navigationhistoryproxymodel.h + src/touchtracker.cpp + src/touchtracker.h +) +if(NOT CMAKE_CROSSCOMPILING) + list(APPEND SOURCES + src/touchmockingapplication.cpp + src/touchmockingapplication.h + ) +endif() +qt_add_resources(SOURCES src/resources.qrc) + +qt_add_executable(qtwebbrowser ${SOURCES}) + +set_target_properties(qtwebbrowser PROPERTIES + WIN32_EXECUTABLE TRUE + MACOSX_BUNDLE TRUE +) + +target_link_libraries(qtwebbrowser PUBLIC + Qt::Core + Qt::Gui + Qt::Qml + Qt::Quick + Qt::WebEngineQuick + Qt::VirtualKeyboard +) +if(NOT CMAKE_CROSSCOMPILING) + target_compile_definitions(qtwebbrowser + PRIVATE DESKTOP_BUILD=1 + ) + target_link_libraries(qtwebbrowser PRIVATE + Qt::GuiPrivate + ) + if(NOT DEFINED CMAKE_INSTALL_PREFIX) + set(CMAKE_INSTALL_PREFIX "/usr/local/bin") + endif() +else() + if(NOT DEFINED CMAKE_INSTALL_PREFIX) + set(CMAKE_INSTALL_PREFIX "/data/user/qt/qtwebbrowser-app") + endif() +endif() diff --git a/doc/src/qtwebbrowser.qdoc b/doc/src/qtwebbrowser.qdoc index 08496a0..e28371a 100644 --- a/doc/src/qtwebbrowser.qdoc +++ b/doc/src/qtwebbrowser.qdoc @@ -170,7 +170,7 @@ while pressing the \c Ctrl key. Qt WebBrowser requires the \l{Qt WebEngine}, \l{Qt Quick} and -\l{Qt Virtual Keyboard} modules in version 5.7 or +\l{Qt Virtual Keyboard} modules in version 6.2 or newer. \image block-diagram.png diff --git a/qtwebbrowser.pro b/qtwebbrowser.pro index 619a237..6c5f5c9 100644 --- a/qtwebbrowser.pro +++ b/qtwebbrowser.pro @@ -4,5 +4,5 @@ SUBDIRS = \ doc \ src -requires(qtHaveModule(webengine)) +requires(qtHaveModule(webenginequick)) diff --git a/src/main.cpp b/src/main.cpp index e21440a..4d2ce08 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -39,7 +39,7 @@ #include <QQmlContext> #include <QQmlEngine> #include <QQuickView> -#include <QtWebEngine/qtwebengineglobal.h> +#include <QtWebEngineQuick> static QObject *engine_factory(QQmlEngine *engine, QJSEngine *scriptEngine) { @@ -71,6 +71,8 @@ int main(int argc, char **argv) int qAppArgCount = qargv.size(); + QtWebEngineQuick::initialize(); + #if defined(DESKTOP_BUILD) TouchMockingApplication app(qAppArgCount, qargv.data()); #else @@ -81,8 +83,6 @@ int main(int argc, char **argv) qmlRegisterType<TouchTracker>("WebBrowser", 1, 0, "TouchTracker"); qmlRegisterSingletonType<AppEngine>("WebBrowser", 1, 0, "AppEngine", engine_factory); - QtWebEngine::initialize(); - app.setOrganizationName("The Qt Company"); app.setOrganizationDomain("qt.io"); app.setApplicationName("qtwebbrowser"); @@ -98,8 +98,7 @@ int main(int argc, char **argv) #if defined(DESKTOP_BUILD) view.show(); - if (view.size().isEmpty()) - view.setGeometry(0, 0, 800, 600); + view.setGeometry(0, 0, 1024, 600); #else view.showFullScreen(); #endif diff --git a/src/navigationhistoryproxymodel.cpp b/src/navigationhistoryproxymodel.cpp index a124f76..a605dd3 100644 --- a/src/navigationhistoryproxymodel.cpp +++ b/src/navigationhistoryproxymodel.cpp @@ -40,8 +40,8 @@ bool NavigationHistoryProxyModel::filterAcceptsRow(int sourceRow, const QModelIn QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent); // Use UrlRole and TitleRole instead of DisplayRole - return (sourceModel()->data(index, Qt::UserRole + 1).toString().contains(filterRegExp()) - || sourceModel()->data(index, Qt::UserRole + 2).toString().contains(filterRegExp())); + return (sourceModel()->data(index, Qt::UserRole + 1).toString().contains(filterRegularExpression()) + || sourceModel()->data(index, Qt::UserRole + 2).toString().contains(filterRegularExpression())); } void NavigationHistoryProxyModel::setEnabled(bool enabled) @@ -63,6 +63,6 @@ void NavigationHistoryProxyModel::setSearchString(const QString &pattern) return; m_searchString = pattern; - setFilterRegExp(QRegExp(pattern, Qt::CaseInsensitive, QRegExp::FixedString)); + setFilterRegularExpression(QRegularExpression(pattern, QRegularExpression::CaseInsensitiveOption)); emit searchStringChanged(); } diff --git a/src/qml/BrowserWindow.qml b/src/qml/BrowserWindow.qml index 05ddcff..ca52cbf 100644 --- a/src/qml/BrowserWindow.qml +++ b/src/qml/BrowserWindow.qml @@ -27,14 +27,12 @@ ** ****************************************************************************/ -import QtQuick 2.5 -import QtWebEngine 1.1 +import QtQuick +import QtWebEngine +import QtQuick.Controls +import QtQuick.Layouts +import Qt.labs.platform -import QtQuick.Controls 1.0 -import QtQuick.Controls.Styles 1.0 -import QtQuick.Layouts 1.0 -import QtQuick.Controls.Private 1.0 -import QtQuick.Dialogs 1.2 import "assets" import WebBrowser 1.0 @@ -162,7 +160,7 @@ Item { z: 6 title: qsTr("Leave Full Screen Mode") visible: opacity != 0.0 - opacity: tabView.viewState == "fullscreen" ? 1.0 : 0.0 + opacity: tabView.viewState === "fullscreen" ? 1.0 : 0.0 anchors { left: parent.left right: parent.right @@ -233,22 +231,21 @@ Item { property var certErrors: [] property var currentError: null visible: certErrors.length > 0 - icon: StandardIcon.Warning - standardButtons: StandardButton.No | StandardButton.Yes + buttons: MessageDialog.No | MessageDialog.Yes title: "Server's certificate not trusted" text: "Do you wish to continue?" detailedText: "If you wish so, you may continue with an unverified certificate. " + "Accepting an unverified certificate means " + "you may not be connected with the host you tried to connect to.\n" + "Do you wish to override the security check and continue?" - onYes: { + onYesClicked: { var cert = certErrors.shift() var domain = AppEngine.domainFromString(cert.url) acceptedCertificates.acceptedUrls.push(domain) cert.ignoreCertificateError() presentError() } - onNo: reject() + onNoClicked: reject() onRejected: reject() function reject(){ @@ -304,7 +301,7 @@ Item { SearchProxyModel { id: proxy - target: navigation.webView.navigationHistory.items + target: navigation.webView.history.items searchString: urlDropDown.searchString enabled: urlDropDown.state == "enabled" } diff --git a/src/qml/FeaturePermissionBar.qml b/src/qml/FeaturePermissionBar.qml index 374c9d7..04ecb5a 100644 --- a/src/qml/FeaturePermissionBar.qml +++ b/src/qml/FeaturePermissionBar.qml @@ -27,10 +27,10 @@ ** ****************************************************************************/ -import QtQuick 2.1 -import QtQuick.Controls 1.0 -import QtWebEngine 1.1 -import QtQuick.Layouts 1.0 +import QtQuick +import QtQuick.Controls +import QtWebEngine +import QtQuick.Layouts import "assets" diff --git a/src/qml/HomeScreen.qml b/src/qml/HomeScreen.qml index 3d66e87..ebe5f92 100644 --- a/src/qml/HomeScreen.qml +++ b/src/qml/HomeScreen.qml @@ -27,8 +27,8 @@ ** ****************************************************************************/ -import QtQuick 2.5 -import WebBrowser 1.0 +import QtQuick +import WebBrowser import "assets" Rectangle { @@ -172,7 +172,7 @@ Rectangle { var margin = (parent.width - 4 * gridView.cellWidth - homeScreen.padding) / 2 var padding = gridView.page - Math.round(gridView.count % gridViewPageItemCount / 2) * gridView.cellWidth - if (padding == gridView.page) + if (padding === gridView.page) return margin return margin + padding diff --git a/src/qml/Keyboard.qml b/src/qml/Keyboard.qml index 9ea7f71..c345920 100644 --- a/src/qml/Keyboard.qml +++ b/src/qml/Keyboard.qml @@ -27,8 +27,9 @@ ** ****************************************************************************/ -import QtQuick 2.5 -import QtQuick.VirtualKeyboard 2.0 +import QtQuick +import QtQuick.VirtualKeyboard + InputPanel { id: inputPanel diff --git a/src/qml/Main.qml b/src/qml/Main.qml index 653b435..ea4d533 100644 --- a/src/qml/Main.qml +++ b/src/qml/Main.qml @@ -27,7 +27,7 @@ ** ****************************************************************************/ -import QtQuick 2.5 +import QtQuick Item { BrowserWindow{ diff --git a/src/qml/MockTouchPoint.qml b/src/qml/MockTouchPoint.qml index b47525c..9ae7420 100644 --- a/src/qml/MockTouchPoint.qml +++ b/src/qml/MockTouchPoint.qml @@ -27,7 +27,7 @@ ** ****************************************************************************/ -import QtQuick 2.0 +import QtQuick Item { id: mockTouchPoint diff --git a/src/qml/NavigationBar.qml b/src/qml/NavigationBar.qml index f6e3bea..765b00f 100644 --- a/src/qml/NavigationBar.qml +++ b/src/qml/NavigationBar.qml @@ -27,10 +27,9 @@ ** ****************************************************************************/ -import QtQuick 2.5 -import QtQuick.Controls 1.4 -import QtQuick.Controls.Styles 1.4 -import QtQuick.Layouts 1.2 +import QtQuick +import QtQuick.Controls +import QtQuick.Layouts import WebBrowser 1.0 import "assets" @@ -63,18 +62,11 @@ ToolBar { state: "enabled" - style: ToolBarStyle { - background: Rectangle { - color: uiColor - implicitHeight: toolBarSize + 3 - } - padding { - left: 0 - right: 0 - top: 0 - bottom: 0 - } + background: Rectangle { + color: uiColor + implicitHeight: toolBarSize + 3 } + padding: 0 Behavior on y { NumberAnimation { duration: animationDuration } @@ -243,24 +235,23 @@ ToolBar { urlBar.remove(urlBar.selectionStart, urlBar.selectionEnd) } } - style: TextFieldStyle { - textColor: "black" - font.family: defaultFontFamily - font.pixelSize: 28 - selectionColor: uiHighlightColor - selectedTextColor: "black" - placeholderTextColor: placeholderColor - background: Rectangle { - implicitWidth: 514 - implicitHeight: 56 - border.color: settingsView.privateBrowsingEnabled ? "black" : textFieldStrokeColor - border.width: 1 - } - padding { - left: 15 - right: reloadButton.width - } + + color: "black" + font.family: defaultFontFamily + font.pixelSize: 28 + selectionColor: uiHighlightColor + selectedTextColor: "black" + placeholderTextColor: placeholderColor + background: Rectangle { + implicitWidth: 514 + implicitHeight: 56 + border.color: settingsView.privateBrowsingEnabled ? "black" : textFieldStrokeColor + border.width: 1 } + leftPadding: 15 + rightPadding: reloadButton.width + topPadding: 10 + onAccepted: { webView.url = AppEngine.fromUserInput(text) homeScreen.state = "disabled" @@ -404,17 +395,18 @@ ToolBar { leftMargin: -10 rightMargin: -10 } - style: ProgressBarStyle { - background: Rectangle { - height: 3 - color: emptyBackgroundColor - } - progress: Rectangle { - color: settingsView.privateBrowsingEnabled ? "#46a2da" : "#317198" - } + + background: Rectangle { + height: 3 + color: emptyBackgroundColor + } + + contentItem: Rectangle { + width: progressBar.visualPosition * parent.width + color: settingsView.privateBrowsingEnabled ? "#46a2da" : "#317198" } - minimumValue: 0 - maximumValue: 100 + from: 0 + to: 100 value: (webView && webView.loadProgress < 100) ? webView.loadProgress : 0 } } diff --git a/src/qml/PageView.qml b/src/qml/PageView.qml index d20355c..32237e6 100644 --- a/src/qml/PageView.qml +++ b/src/qml/PageView.qml @@ -27,12 +27,11 @@ ** ****************************************************************************/ -import QtQuick 2.5 -import QtWebEngine 1.9 -import QtQuick.Controls 1.4 -import QtQuick.Controls.Styles 1.4 -import QtQuick.Layouts 1.2 -import QtGraphicalEffects 1.0 +import QtQuick +import QtWebEngine +import QtQuick.Controls +import QtQuick.Layouts +import Qt5Compat.GraphicalEffects import WebBrowser 1.0 import "assets" @@ -62,7 +61,6 @@ Rectangle { property QtObject defaultProfile: WebEngineProfile { storageName: "YABProfile" offTheRecord: false - useForGlobalCertificateVerification: true } Component { @@ -73,7 +71,7 @@ Rectangle { property alias title: webEngineView.title property var image: QtObject { - property var snapshot: null + property var grabberUrl: null property string url: "about:blank" } @@ -120,29 +118,25 @@ Rectangle { function takeSnapshot() { if (webEngineView.url == "" || webEngineView.url == "about:blank") { tabItem.image.url = "about:blank" - tabItem.image.snapshot = null + tabItem.image.grabberUrl = null return } - if (tabItem.image.url == webEngineView.url || tabItem.opacity != 1.0) + if (tabItem.image.url === webEngineView.url || tabItem.opacity != 1.0) return tabItem.image.url = webEngineView.url webEngineView.grabToImage(function(result) { - tabItem.image.snapshot = result; - console.log("takeSnapshot("+result.url+")") + tabItem.image.grabberUrl = result.url; }); } // Trigger a refresh to check if the new url is bookmarked. onUrlChanged: navigation.refresh() - settings.autoLoadImages: settingsView.autoLoadImages settings.javascriptEnabled: !settingsView.javaScriptDisabled - - // This should be enabled as we can switch to Qt 5.6 (i.e. import QtWebEngine 1.2) - // settings.pluginsEnabled: settingsView.pluginsEnabled + settings.pluginsEnabled: settingsView.pluginsEnabled onLoadingChanged: { if (loading) @@ -158,7 +152,7 @@ Rectangle { } } - onNewViewRequested: { + onNewWindowRequested: { webEngineView.takeSnapshot() var tab if (!request.userInitiated) { @@ -305,19 +299,18 @@ Rectangle { onAccepted: { webEngineView.findText(text) } - style: TextFieldStyle { - textColor: "black" - font.family: defaultFontFamily - font.pixelSize: 28 - selectionColor: uiHighlightColor - selectedTextColor: "black" - placeholderTextColor: placeholderColor - background: Rectangle { - implicitWidth: 514 - implicitHeight: toolBarSize / 2 - border.color: textFieldStrokeColor - border.width: 1 - } + + color: "black" + font.family: defaultFontFamily + font.pixelSize: 28 + selectionColor: uiHighlightColor + selectedTextColor: "black" + placeholderTextColor: placeholderColor + background: Rectangle { + implicitWidth: 514 + implicitHeight: toolBarSize / 2 + border.color: textFieldStrokeColor + border.width: 1 } } Rectangle { @@ -332,7 +325,7 @@ Rectangle { } UIButton { id: findBackwardButton - iconSource: "assets/icons/Btn_Back.png" + icon.source: "assets/icons/Btn_Back.png" implicitHeight: parent.height onClicked: webEngineView.findText(findTextField.text, WebEngineView.FindBackward) } @@ -343,7 +336,7 @@ Rectangle { } UIButton { id: findForwardButton - iconSource: "assets/icons/Btn_Forward.png" + icon.source: "assets/icons/Btn_Forward.png" implicitHeight: parent.height onClicked: webEngineView.findText(findTextField.text) } @@ -354,7 +347,7 @@ Rectangle { } UIButton { id: findCancelButton - iconSource: "assets/icons/Btn_Clear.png" + icon.source: "assets/icons/Btn_Clear.png" implicitHeight: parent.height onClicked: findBar.visible = false } @@ -389,7 +382,7 @@ Rectangle { var element = {"item": null } element.item = component.createObject(root, { "width": root.width, "height": root.height, "opacity": 0.0 }) - if (element.item == null) { + if (element.item === null) { console.log("PageView::add(): Error creating object"); return } @@ -498,12 +491,12 @@ Rectangle { MouseArea { enabled: pathView.interactive anchors.fill: wrapper - onClicked: { + onClicked: mouse => { mouse.accepted = true if (index < 0) return - if (index == pathView.currentIndex) { + if (index === pathView.currentIndex) { if (root.viewState == "list") root.viewState = "page" return @@ -525,6 +518,7 @@ Rectangle { width: snapshot.width height: snapshot.height } + GaussianBlur { anchors.fill: shadow source: shadow @@ -541,13 +535,13 @@ Rectangle { Image { source: { - if (!item.image.snapshot) + if (!item.image.grabberUrl) return "assets/icons/about_blank.png" - return item.image.snapshot.url + return item.image.grabberUrl } anchors.fill: parent Rectangle { - enabled: index == pathView.currentIndex && !pathView.moving && !pathView.flicking && wrapper.visibility == 1.0 + enabled: index === pathView.currentIndex && !pathView.moving && !pathView.flicking && wrapper.visibility == 1.0 opacity: enabled ? 1.0 : 0.0 visible: wrapper.visibility == 1.0 && listModel.count > 1 width: image.sourceSize.width diff --git a/src/qml/SettingsView.qml b/src/qml/SettingsView.qml index f01a5a8..925c82d 100644 --- a/src/qml/SettingsView.qml +++ b/src/qml/SettingsView.qml @@ -27,11 +27,10 @@ ** ****************************************************************************/ -import QtQuick 2.5 -import QtQuick.Layouts 1.0 -import QtQuick.Controls 1.4 -import QtQuick.Controls.Styles 1.4 -import Qt.labs.settings 1.0 +import QtQuick +import QtQuick.Layouts +import QtQuick.Controls +import Qt.labs.settings import WebBrowser 1.0 Rectangle { @@ -41,14 +40,14 @@ Rectangle { property bool httpDiskCacheEnabled: appSettings[1].active property bool autoLoadImages: appSettings[2].active property bool javaScriptDisabled: appSettings[3].active - // property bool pluginsEnabled: appSettings[4].active + property bool pluginsEnabled: appSettings[4].active property var appSettings: [ { "name": "Private Browsing", "active": false, "notify": function(v) { privateBrowsingEnabled = v; } }, { "name": "Enable HTTP Disk Cache", "active": true, "notify": function(v) { httpDiskCacheEnabled = v; } }, { "name": "Auto Load Images", "active": true, "notify": function(v) { autoLoadImages = v; } }, { "name": "Disable JavaScript", "active": false, "notify": function(v) { javaScriptDisabled = v; } }, -// { "name": "Enable Plugins", "active": false, "notify": function(v) { pluginsEnabled = v; } } + { "name": "Enable Plugins", "active": false, "notify": function(v) { pluginsEnabled = v; } } ] function save() { @@ -135,24 +134,25 @@ Rectangle { setting.active = checked setting.notify(checked) } - style: SwitchStyle { - handle: Rectangle { - width: 42 - height: 42 - radius: height / 2 - color: "white" - border.color: control.checked ? "#5caa14" : "#9b9b9b" - border.width: 1 - } - groove: Rectangle { - implicitWidth: 72 - height: 42 - radius: height / 2 - border.color: control.checked ? "#5caa14" : "#9b9b9b" - color: control.checked ? "#5cff14" : "white" - border.width: 1 - } + indicator: Rectangle { + x: sw.checked ? parent.width - width : 0 + width: 42 + height: 42 + radius: height / 2 + color: "white" + border.color: sw.checked ? "#5caa14" : "#9b9b9b" + border.width: 1 + + } + + background: Rectangle { + implicitWidth: 72 + height: 42 + radius: height / 2 + border.color: sw.checked ? "#5caa14" : "#9b9b9b" + color: sw.checked ? "#5cff14" : "white" + border.width: 1 } } } diff --git a/src/qml/assets/UIButton.qml b/src/qml/assets/UIButton.qml index 38d3e5a..ec53bb3 100644 --- a/src/qml/assets/UIButton.qml +++ b/src/qml/assets/UIButton.qml @@ -27,10 +27,9 @@ ** ****************************************************************************/ -import QtQuick 2.5 -import QtQuick.Controls 1.4 -import QtQuick.Controls.Styles 1.4 -import QtQuick.Layouts 1.2 +import QtQuick +import QtQuick.Controls +import QtQuick.Layouts ToolButton { @@ -52,17 +51,16 @@ ToolButton { font.family: defaultFontFamily font.pixelSize: 28 } - style: ButtonStyle { - background: Rectangle { - opacity: root.enabled ? 1.0 : 0.3 - color: root.pressed || root.checked ? root.highlightColor : root.color - radius: root.radius - Image { - source: root.source - width: Math.min(sourceSize.width, root.width) - height: Math.min(sourceSize.height, root.height) - anchors.centerIn: parent - } + + background: Rectangle { + opacity: root.enabled ? 1.0 : 0.3 + color: root.pressed || root.checked ? root.highlightColor : root.color + radius: root.radius + Image { + source: root.source + width: Math.min(sourceSize.width, root.width) + height: Math.min(sourceSize.height, root.height) + anchors.centerIn: parent } } } diff --git a/src/qml/assets/UIToolBar.qml b/src/qml/assets/UIToolBar.qml index caf4ec1..40aa990 100644 --- a/src/qml/assets/UIToolBar.qml +++ b/src/qml/assets/UIToolBar.qml @@ -27,10 +27,9 @@ ** ****************************************************************************/ -import QtQuick 2.5 -import QtQuick.Controls 1.0 -import QtQuick.Controls.Styles 1.0 -import QtQuick.Layouts 1.0 +import QtQuick +import QtQuick.Controls +import QtQuick.Layouts ToolBar { id: root @@ -46,18 +45,10 @@ ToolBar { signal doneClicked() height: navigation.height - - style: ToolBarStyle { - background: Rectangle { - color: toolBarFillColor - } - padding { - left: 0 - right: 0 - top: 0 - bottom: 0 - } + background: Rectangle { + color: toolBarFillColor } + padding: 0 RowLayout { spacing: 0 diff --git a/src/src.pro b/src/src.pro index f076b73..97a68b7 100644 --- a/src/src.pro +++ b/src/src.pro @@ -17,7 +17,6 @@ HEADERS = \ OTHER_FILES = \ qml/assets/UIButton.qml \ qml/assets/UIToolBar.qml \ - qml/ApplicationRoot.qml \ qml/BrowserWindow.qml \ qml/FeaturePermissionBar.qml \ qml/MockTouchPoint.qml \ @@ -25,10 +24,9 @@ OTHER_FILES = \ qml/NavigationBar.qml \ qml/HomeScreen.qml \ qml/SettingsView.qml \ - qml/Keyboard.qml \ - qml/Window.qml + qml/Keyboard.qml -QT += qml quick webengine +QT += qml quick webenginequick RESOURCES += resources.qrc diff --git a/src/touchmockingapplication.cpp b/src/touchmockingapplication.cpp index 5b56fa8..ef48566 100644 --- a/src/touchmockingapplication.cpp +++ b/src/touchmockingapplication.cpp @@ -31,22 +31,16 @@ #include "appengine.h" #include <qpa/qwindowsysteminterface.h> -#include <QtCore/QRegExp> +#include <QtCore/QRegularExpression> #include <QtCore/QEvent> #include <QtGui/QMouseEvent> #include <QtGui/QTouchEvent> +#include <QtGui/private/qeventpoint_p.h> #include <QtQuick/QQuickItem> #include <QtQuick/QQuickView> using namespace utils; -static inline QRectF touchRectForPosition(QPointF centerPoint) -{ - QRectF touchRect(0, 0, 40, 40); - touchRect.moveCenter(centerPoint); - return touchRect; -} - TouchMockingApplication::TouchMockingApplication(int& argc, char** argv) : QGuiApplication(argc, argv) , m_realTouchEventReceived(false) @@ -80,10 +74,10 @@ bool TouchMockingApplication::notify(QObject* target, QEvent* event) 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))) { - m_touchPoints[id].setState(Qt::TouchPointReleased); + QMutableEventPoint::setState(m_touchPoints[id], QEventPoint::Released); m_heldTouchPoints.remove(id); } else - m_touchPoints[id].setState(Qt::TouchPointStationary); + QMutableEventPoint::setState(m_touchPoints[id], QEventPoint::Stationary); sendTouchEvent(window, m_heldTouchPoints.isEmpty() ? QEvent::TouchEnd : QEvent::TouchUpdate, static_cast<QKeyEvent*>(event)->timestamp()); } @@ -92,18 +86,18 @@ bool TouchMockingApplication::notify(QObject* target, QEvent* event) const QMouseEvent* const mouseEvent = static_cast<QMouseEvent*>(event); QTouchEvent::TouchPoint touchPoint; - touchPoint.setPressure(1); + QMutableEventPoint::setPressure(touchPoint, 1); QEvent::Type touchType = QEvent::None; switch (mouseEvent->type()) { case QEvent::MouseButtonPress: - touchPoint.setId(mouseEvent->button()); + QMutableEventPoint::setId(touchPoint, mouseEvent->button()); if (m_touchPoints.contains(touchPoint.id())) { - touchPoint.setState(Qt::TouchPointMoved); + QMutableEventPoint::setState(touchPoint, QEventPoint::Updated); touchType = QEvent::TouchUpdate; } else { - touchPoint.setState(Qt::TouchPointPressed); + 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; @@ -121,8 +115,8 @@ bool TouchMockingApplication::notify(QObject* target, QEvent* event) return true; } touchType = QEvent::TouchUpdate; - touchPoint.setId(mouseEvent->buttons()); - touchPoint.setState(Qt::TouchPointMoved); + 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. @@ -130,8 +124,8 @@ bool TouchMockingApplication::notify(QObject* target, QEvent* event) touchType = QEvent::TouchUpdate; else touchType = QEvent::TouchEnd; - touchPoint.setId(mouseEvent->button()); - touchPoint.setState(Qt::TouchPointReleased); + 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. @@ -144,12 +138,12 @@ bool TouchMockingApplication::notify(QObject* target, QEvent* event) // 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::MidButton) - updateTouchPoint(mouseEvent, touchPoint, Qt::MidButton); + 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() == Qt::TouchPointReleased) { + 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. @@ -158,9 +152,9 @@ bool TouchMockingApplication::notify(QObject* target, QEvent* event) } // Update states for all other touch-points - for (QHash<int, QTouchEvent::TouchPoint>::iterator it = m_touchPoints.begin(), end = m_touchPoints.end(); it != end; ++it) { + for (QHash<int, QEventPoint>::iterator it = m_touchPoints.begin(), end = m_touchPoints.end(); it != end; ++it) { if (!(it.value().id() & touchPoint.id())) - it.value().setState(Qt::TouchPointStationary); + QMutableEventPoint::setState(it.value(), QEventPoint::Stationary); } Q_ASSERT(touchType != QEvent::None); @@ -182,7 +176,7 @@ void TouchMockingApplication::updateTouchPoint(const QMouseEvent* mouseEvent, QT if (!m_holdingControl && m_touchPoints.size() && !m_touchPoints.contains(mouseButton)) return; - if (m_holdingControl && touchPoint.state() == Qt::TouchPointReleased) { + if (m_holdingControl && touchPoint.state() == QEventPoint::Released) { m_heldTouchPoints.insert(mouseButton); return; } @@ -191,68 +185,69 @@ void TouchMockingApplication::updateTouchPoint(const QMouseEvent* mouseEvent, QT // 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. - touchPoint.setRect(touchRectForPosition(mouseEvent->localPos())); - touchPoint.setSceneRect(touchRectForPosition(mouseEvent->screenPos())); + QMutableEventPoint::setPosition(touchPoint, mouseEvent->position()); + QMutableEventPoint::setScenePosition(touchPoint, mouseEvent->globalPosition()); - if (touchPoint.state() == Qt::TouchPointPressed) - touchPoint.setStartScenePos(mouseEvent->screenPos()); + if (touchPoint.state() == QEventPoint::Pressed) + QMutableEventPoint::setScenePosition(touchPoint, mouseEvent->scenePosition()); else { - const QTouchEvent::TouchPoint& oldTouchPoint = m_touchPoints[mouseButton]; - touchPoint.setStartScenePos(oldTouchPoint.startScenePos()); - touchPoint.setLastPos(oldTouchPoint.pos()); - touchPoint.setLastScenePos(oldTouchPoint.scenePos()); + const QEventPoint& oldTouchPoint = m_touchPoints[mouseButton]; + QMutableEventPoint::setGlobalLastPosition(touchPoint, oldTouchPoint.globalPosition()); } // Update current touch-point. - touchPoint.setId(mouseButton); + QMutableEventPoint::setId(touchPoint, mouseButton); m_touchPoints.insert(mouseButton, touchPoint); } bool TouchMockingApplication::sendTouchEvent(QQuickView* window, QEvent::Type type, ulong timestamp) { - static QTouchDevice* device = 0; + static QPointingDevice *device = 0; if (!device) { - device = new QTouchDevice; - device->setType(QTouchDevice::TouchScreen); - QWindowSystemInterface::registerTouchDevice(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<QTouchEvent::TouchPoint>& currentTouchPoints = m_touchPoints.values(); - Qt::TouchPointStates touchPointStates = 0; - foreach (const QTouchEvent::TouchPoint& touchPoint, currentTouchPoints) - touchPointStates |= touchPoint.state(); + 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, touchPointStates, currentTouchPoints); + QTouchEvent event(type, device, Qt::NoModifier, currentTouchPoints); event.setTimestamp(timestamp); event.setAccepted(false); QGuiApplication::notify(window, &event); - updateVisualMockTouchPoints(window,m_holdingControl ? currentTouchPoints : QList<QTouchEvent::TouchPoint>()); + updateVisualMockTouchPoints(window, m_holdingControl ? currentTouchPoints : QList<QEventPoint>()); // Get rid of touch-points that are no longer valid - foreach (const QTouchEvent::TouchPoint& touchPoint, currentTouchPoints) { - if (touchPoint.state() == Qt::TouchPointReleased) + 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<QTouchEvent::TouchPoint>& touchPoints) +void TouchMockingApplication::updateVisualMockTouchPoints(QQuickView *window, const QList<QEventPoint> &touchPoints) { if (touchPoints.isEmpty()) { // Hide all touch indicator items. - foreach (QQuickItem* item, m_activeMockComponents.values()) + foreach (QQuickItem *item, m_activeMockComponents.values()) item->setProperty("pressed", false); return; } - foreach (const QTouchEvent::TouchPoint& touchPoint, touchPoints) { - QQuickItem* mockTouchPointItem = m_activeMockComponents.value(touchPoint.id()); + foreach (const QEventPoint& touchPoint, touchPoints) { + QQuickItem *mockTouchPointItem = m_activeMockComponents.value(touchPoint.id()); if (!mockTouchPointItem) { QQmlComponent touchMockPointComponent(window->engine(), QUrl("qrc:///qml/MockTouchPoint.qml")); @@ -264,11 +259,10 @@ void TouchMockingApplication::updateVisualMockTouchPoints(QQuickView* window,con mockTouchPointItem->setParentItem(window->rootObject()); } - QRectF touchRect = touchPoint.rect(); - mockTouchPointItem->setX(touchRect.center().x()); - mockTouchPointItem->setY(touchRect.center().y()); - mockTouchPointItem->setWidth(touchRect.width()); - mockTouchPointItem->setHeight(touchRect.height()); - mockTouchPointItem->setProperty("pressed", QVariant(touchPoint.state() != Qt::TouchPointReleased)); + 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/src/touchmockingapplication.h b/src/touchmockingapplication.h index d6f13ec..f2c4b5a 100644 --- a/src/touchmockingapplication.h +++ b/src/touchmockingapplication.h @@ -33,7 +33,8 @@ #include <QtCore/QHash> #include <QtCore/QUrl> #include <QtGui/QGuiApplication> -#include <QtGui/QTouchEvent> +#include <QEventPoint> +#include <QMouseEvent> QT_BEGIN_NAMESPACE class QQuickView; @@ -62,7 +63,7 @@ private: QPointF m_lastScreenPos; QPointF m_startScreenPos; - QHash<int, QTouchEvent::TouchPoint> m_touchPoints; + QHash<int, QEventPoint> m_touchPoints; QSet<int> m_heldTouchPoints; QHash<int, QQuickItem*> m_activeMockComponents; diff --git a/src/touchtracker.cpp b/src/touchtracker.cpp index bd0f132..582ccb4 100644 --- a/src/touchtracker.cpp +++ b/src/touchtracker.cpp @@ -107,9 +107,9 @@ bool TouchTracker::eventFilter(QObject *obj, QEvent *event) return QQuickItem::eventFilter(obj, event); const QTouchEvent *touch = static_cast<QTouchEvent*>(event); - const QList<QTouchEvent::TouchPoint> &points = touch->touchPoints(); + const QList<QEventPoint> &points = touch->points(); m_previousY = m_currentPoint.y(); - m_currentPoint.pos = m_target->mapToScene(points.at(0).pos()); + m_currentPoint.pos = m_target->mapToScene(points.at(0).position()); m_currentPoint.ts = QDateTime::currentMSecsSinceEpoch(); int currentDiff = m_previousY - m_currentPoint.y(); @@ -138,8 +138,8 @@ void TouchTracker::touchEvent(QTouchEvent * event) event->setAccepted(false); - const QList<QTouchEvent::TouchPoint> &points = event->touchPoints(); - m_currentPoint.pos = m_target->mapToScene(points.at(0).pos()); + const QList<QEventPoint> &points = event->points(); + m_currentPoint.pos = m_target->mapToScene(points.at(0).position()); m_currentPoint.ts = QDateTime::currentMSecsSinceEpoch(); if (event->type() == QEvent::TouchBegin) { |