From 60a8ef724c11c35413d42ef1ccd118e9c4f6c3c9 Mon Sep 17 00:00:00 2001 From: Michal Klocek Date: Fri, 15 Jan 2016 18:37:02 +0100 Subject: [PATCH] Clean up the application after integration for b2qt * put plugin.cpp into b2qt demo repository * use resource file * use AppEngine instead of WebEngine, WebEngine is already registered with QtWebEgnine * remove BrowserWindow class * fix warnings and undefined errors in qml * rename engine to appengine, qml name collision with launcherengine Change-Id: I36b682a6a5e3c8f1453c9511c52561d0ff511e71 Reviewed-by: Joerg Bornemann --- qtwebbrowser.pro | 1 - src/app/app.pro | 53 -------- src/app/browserwindow.cpp | 120 ------------------ src/app/browserwindow.h | 64 ---------- src/{app/engine.cpp => appengine.cpp} | 21 +-- src/{app/engine.h => appengine.h} | 23 ++-- src/imports/imports.pro | 17 --- src/imports/plugin.cpp | 81 ------------ src/imports/qmldir | 4 - src/{app => }/main.cpp | 56 +++++--- src/{app => }/navigationhistoryproxymodel.cpp | 0 src/{app => }/navigationhistoryproxymodel.h | 0 src/{app => }/qml/BrowserWindow.qml | 14 +- src/{app => }/qml/FeaturePermissionBar.qml | 0 src/{app => }/qml/HomeScreen.qml | 4 +- src/{app => }/qml/MockTouchPoint.qml | 0 src/{app => }/qml/NavigationBar.qml | 7 +- src/{app => }/qml/PageView.qml | 0 src/{app => }/qml/SettingsView.qml | 4 +- src/{app => }/qml/Utils.js | 0 src/{app => }/qml/assets/UIButton.qml | 0 src/{app => }/qml/assets/UIToolBar.qml | 0 .../qml/assets/icons/AppLogoColor.png | Bin .../qml/assets/icons/AppLogoGrey.png | Bin src/{app => }/qml/assets/icons/Btn_Add.png | Bin src/{app => }/qml/assets/icons/Btn_Back.png | Bin .../qml/assets/icons/Btn_Bookmark_Checked.png | Bin .../assets/icons/Btn_Bookmark_Indicator.png | Bin .../qml/assets/icons/Btn_Bookmarks.png | Bin src/{app => }/qml/assets/icons/Btn_Clear.png | Bin src/{app => }/qml/assets/icons/Btn_Delete.png | Bin .../qml/assets/icons/Btn_Forward.png | Bin src/{app => }/qml/assets/icons/Btn_Home.png | Bin src/{app => }/qml/assets/icons/Btn_Reload.png | Bin src/{app => }/qml/assets/icons/Btn_Search.png | Bin .../qml/assets/icons/Btn_Settings.png | Bin src/{app => }/qml/assets/icons/Btn_Tabs.png | Bin src/{app => }/qml/assets/icons/Btn_Up.png | Bin src/{app => }/qml/assets/icons/Error_Icon.png | Bin .../assets/icons/LightWebBrowser_Icons.svg | 0 .../qml/assets/icons/about_blank.png | Bin src/{app => }/qml/assets/icons/qt.png | Bin src/{app => }/qml/assets/icons/touchpoint.png | Bin src/{app => }/resources.qrc | 0 src/src.pro | 45 ++++++- src/{app => }/touchmockingapplication.cpp | 51 ++++++-- src/{app => }/touchmockingapplication.h | 23 ++-- src/{app => }/touchtracker.cpp | 3 +- src/{app => }/touchtracker.h | 0 49 files changed, 171 insertions(+), 420 deletions(-) delete mode 100644 src/app/app.pro delete mode 100644 src/app/browserwindow.cpp delete mode 100644 src/app/browserwindow.h rename src/{app/engine.cpp => appengine.cpp} (87%) rename src/{app/engine.h => appengine.h} (92%) delete mode 100644 src/imports/imports.pro delete mode 100644 src/imports/plugin.cpp delete mode 100644 src/imports/qmldir rename src/{app => }/main.cpp (76%) rename src/{app => }/navigationhistoryproxymodel.cpp (100%) rename src/{app => }/navigationhistoryproxymodel.h (100%) rename src/{app => }/qml/BrowserWindow.qml (97%) rename src/{app => }/qml/FeaturePermissionBar.qml (100%) rename src/{app => }/qml/HomeScreen.qml (99%) rename src/{app => }/qml/MockTouchPoint.qml (100%) rename src/{app => }/qml/NavigationBar.qml (99%) rename src/{app => }/qml/PageView.qml (100%) rename src/{app => }/qml/SettingsView.qml (98%) rename src/{app => }/qml/Utils.js (100%) rename src/{app => }/qml/assets/UIButton.qml (100%) rename src/{app => }/qml/assets/UIToolBar.qml (100%) rename src/{app => }/qml/assets/icons/AppLogoColor.png (100%) rename src/{app => }/qml/assets/icons/AppLogoGrey.png (100%) rename src/{app => }/qml/assets/icons/Btn_Add.png (100%) rename src/{app => }/qml/assets/icons/Btn_Back.png (100%) rename src/{app => }/qml/assets/icons/Btn_Bookmark_Checked.png (100%) rename src/{app => }/qml/assets/icons/Btn_Bookmark_Indicator.png (100%) rename src/{app => }/qml/assets/icons/Btn_Bookmarks.png (100%) rename src/{app => }/qml/assets/icons/Btn_Clear.png (100%) rename src/{app => }/qml/assets/icons/Btn_Delete.png (100%) rename src/{app => }/qml/assets/icons/Btn_Forward.png (100%) rename src/{app => }/qml/assets/icons/Btn_Home.png (100%) rename src/{app => }/qml/assets/icons/Btn_Reload.png (100%) rename src/{app => }/qml/assets/icons/Btn_Search.png (100%) rename src/{app => }/qml/assets/icons/Btn_Settings.png (100%) rename src/{app => }/qml/assets/icons/Btn_Tabs.png (100%) rename src/{app => }/qml/assets/icons/Btn_Up.png (100%) rename src/{app => }/qml/assets/icons/Error_Icon.png (100%) rename src/{app => }/qml/assets/icons/LightWebBrowser_Icons.svg (100%) rename src/{app => }/qml/assets/icons/about_blank.png (100%) rename src/{app => }/qml/assets/icons/qt.png (100%) rename src/{app => }/qml/assets/icons/touchpoint.png (100%) rename src/{app => }/resources.qrc (100%) rename src/{app => }/touchmockingapplication.cpp (83%) rename src/{app => }/touchmockingapplication.h (78%) rename src/{app => }/touchtracker.cpp (99%) rename src/{app => }/touchtracker.h (100%) diff --git a/qtwebbrowser.pro b/qtwebbrowser.pro index be734fb..65d9262 100644 --- a/qtwebbrowser.pro +++ b/qtwebbrowser.pro @@ -1,3 +1,2 @@ TEMPLATE = subdirs - SUBDIRS = src diff --git a/src/app/app.pro b/src/app/app.pro deleted file mode 100644 index 7b9b8a2..0000000 --- a/src/app/app.pro +++ /dev/null @@ -1,53 +0,0 @@ -TARGET = qtwebbrowser - -DESTDIR = ../ -CONFIG += c++11 -CONFIG -= app_bundle - -SOURCES = main.cpp \ - browserwindow.cpp \ - engine.cpp - -HEADERS = browserwindow.h \ - engine.h - -OTHER_FILES = \ - qml/assets/UIButton.qml \ - qml/assets/UIToolBar.qml \ - qml/ApplicationRoot.qml \ - qml/BrowserWindow.qml \ - qml/FeaturePermissionBar.qml \ - qml/MockTouchPoint.qml \ - qml/PageView.qml \ - qml/NavigationBar.qml \ - qml/HomeScreen.qml \ - qml/SettingsView.qml \ - -QT += qml quick webengine - -RESOURCES += resources.qrc - -!cross_compile { - DEFINES += HOST_BUILD - SOURCES += touchmockingapplication.cpp \ - navigationhistoryproxymodel.cpp \ - touchtracker.cpp - - HEADERS += touchmockingapplication.h \ - navigationhistoryproxymodel.h \ - touchtracker.h - - QT_PRIVATE += quick-private gui-private core-private -} -else { - DESTPATH = /data/user/qt/qtwebbrowser - - content.files = qml/* - content.path = $$DESTPATH - target.path = $$DESTPATH - - INSTALLS += target content -} - - - diff --git a/src/app/browserwindow.cpp b/src/app/browserwindow.cpp deleted file mode 100644 index 41d8d2a..0000000 --- a/src/app/browserwindow.cpp +++ /dev/null @@ -1,120 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the QtBrowser project. -** -** $QT_BEGIN_LICENSE:GPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPLv2 included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/gpl-2.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "browserwindow.h" - -#include -#include -#include -#include -#include -#include -#include - -#include "engine.h" - -void BrowserWindow::ensureProfileInstance() -{ - if (m_lazyProfileInstance) - return; - QQmlComponent *component = new QQmlComponent(engine(), this); - - component->setData( - QByteArrayLiteral("import QtQuick 2.0\n" - "import QtWebEngine 1.1\n" - "WebEngineProfile {\n" - " storageName: \"YABProfile\"\n" - "}") - , QUrl()); - m_lazyProfileInstance = component->create(engine()->rootContext()); - Q_ASSERT(m_lazyProfileInstance); - QQmlEngine::setObjectOwnership(m_lazyProfileInstance, QQmlEngine::JavaScriptOwnership); -} - -QObject *BrowserWindow::defaultProfile() -{ - ensureProfileInstance(); - return m_lazyProfileInstance; -} - -BrowserWindow::BrowserWindow(QWindow *) - : m_lazyProfileInstance(0) -{ - setTitle("Yet Another Browser"); - setFlags(Qt::Window | Qt::WindowTitleHint); - setResizeMode(QQuickView::SizeRootObjectToView); - setColor(Qt::black); - - engine()->rootContext()->setContextProperty("WebEngine", new Engine(this)); - setSource(QUrl("qrc:///qml/BrowserWindow.qml")); -} - -BrowserWindow::~BrowserWindow() -{ -} - -void BrowserWindow::updateVisualMockTouchPoints(const QList& touchPoints) -{ - if (touchPoints.isEmpty()) { - // Hide all touch indicator items. - foreach (QQuickItem* item, m_activeMockComponents.values()) - item->setProperty("pressed", false); - - return; - } - - foreach (const QTouchEvent::TouchPoint& touchPoint, touchPoints) { - QQuickItem* mockTouchPointItem = m_activeMockComponents.value(touchPoint.id()); - - if (!mockTouchPointItem) { - QQmlComponent touchMockPointComponent(engine(), QUrl("qrc:///qml/MockTouchPoint.qml")); - mockTouchPointItem = qobject_cast(touchMockPointComponent.create()); - Q_ASSERT(mockTouchPointItem); - m_activeMockComponents.insert(touchPoint.id(), mockTouchPointItem); - mockTouchPointItem->setProperty("pointId", QVariant(touchPoint.id())); - mockTouchPointItem->setParent(rootObject()); - mockTouchPointItem->setParentItem(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)); - } -} diff --git a/src/app/browserwindow.h b/src/app/browserwindow.h deleted file mode 100644 index 1d055bf..0000000 --- a/src/app/browserwindow.h +++ /dev/null @@ -1,64 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the QtBrowser project. -** -** $QT_BEGIN_LICENSE:GPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPLv2 included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/gpl-2.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef BROWSERWINDOW_H -#define BROWSERWINDOW_H - -#include -#include -#include -#include - -class BrowserWindow : public QQuickView -{ - Q_OBJECT - - QHash m_activeMockComponents; - QObject *m_lazyProfileInstance; - - void ensureProfileInstance(); -public: - BrowserWindow(QWindow *parent = 0); - ~BrowserWindow(); - - void updateVisualMockTouchPoints(const QList& touchPoints); - -public Q_SLOTS: - QObject *defaultProfile(); -}; - -#endif // BROWSERWINDOW_H diff --git a/src/app/engine.cpp b/src/appengine.cpp similarity index 87% rename from src/app/engine.cpp rename to src/appengine.cpp index 3c8d0d0..7be0e5b 100644 --- a/src/app/engine.cpp +++ b/src/appengine.cpp @@ -35,14 +35,14 @@ ** ****************************************************************************/ -#include "engine.h" +#include "appengine.h" #include #include #include #include -Engine::Engine(QObject *parent) +AppEngine::AppEngine(QObject *parent) : QObject(parent) , m_settings(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) % QDir::separator() % "settings.ini", QSettings::IniFormat, this) { @@ -57,17 +57,17 @@ Engine::Engine(QObject *parent) } } -QString Engine::settingsPath() +QString AppEngine::settingsPath() { return m_settings.fileName(); } -QString Engine::initialUrl() const +QString AppEngine::initialUrl() const { return m_initialUrl; } -QUrl Engine::fromUserInput(const QString& userInput) +QUrl AppEngine::fromUserInput(const QString& userInput) { QFileInfo fileInfo(userInput); if (fileInfo.exists()) @@ -75,7 +75,7 @@ QUrl Engine::fromUserInput(const QString& userInput) return QUrl::fromUserInput(userInput); } -bool Engine::isUrl(const QString& userInput) +bool AppEngine::isUrl(const QString& userInput) { if (userInput.startsWith(QStringLiteral("www.")) || userInput.startsWith(QStringLiteral("http")) @@ -86,12 +86,12 @@ bool Engine::isUrl(const QString& userInput) return false; } -QString Engine::domainFromString(const QString& urlString) +QString AppEngine::domainFromString(const QString& urlString) { return QUrl::fromUserInput(urlString).host(); } -QString Engine::fallbackColor() +QString AppEngine::fallbackColor() { static QList colors = QList() << QStringLiteral("#46a2da") << QStringLiteral("#18394c") @@ -103,12 +103,13 @@ QString Engine::fallbackColor() return colors[index]; } -QString Engine::restoreSetting(const QString &name, const QString &defaultValue) +QString AppEngine::restoreSetting(const QString &name, const QString &defaultValue) { return m_settings.value(name, defaultValue).toString(); } -void Engine::saveSetting(const QString &name, const QString &value) +void AppEngine::saveSetting(const QString &name, const QString &value) { m_settings.setValue(name, value); } + diff --git a/src/app/engine.h b/src/appengine.h similarity index 92% rename from src/app/engine.h rename to src/appengine.h index af60dad..808f3b7 100644 --- a/src/app/engine.h +++ b/src/appengine.h @@ -35,8 +35,8 @@ ** ****************************************************************************/ -#ifndef ENGINE_H -#define ENGINE_H +#ifndef APPENGINE_H +#define APPENGINE_H #include #include @@ -73,22 +73,15 @@ inline bool isMouseEvent(const QEvent* event) } -class Engine : public QObject { +class AppEngine : public QObject { Q_OBJECT - Q_PROPERTY(QObject * rootWindow READ rootWindow FINAL CONSTANT) Q_PROPERTY(QString settingsPath READ settingsPath FINAL CONSTANT) Q_PROPERTY(QString initialUrl READ initialUrl FINAL CONSTANT) - QSettings m_settings; - QString m_initialUrl; - public: - Engine(QObject *parent = 0); - QObject *rootWindow() - { - return parent(); - } + AppEngine(QObject *parent = 0); + QString settingsPath(); QString initialUrl() const; @@ -98,6 +91,10 @@ public: Q_INVOKABLE QString fallbackColor(); Q_INVOKABLE QString restoreSetting(const QString &name, const QString &defaultValue = QString()); Q_INVOKABLE void saveSetting(const QString &name, const QString &value); + +private: + QSettings m_settings; + QString m_initialUrl; }; -#endif // ENGINE_H +#endif // APPENGINE_H diff --git a/src/imports/imports.pro b/src/imports/imports.pro deleted file mode 100644 index 22f5ec1..0000000 --- a/src/imports/imports.pro +++ /dev/null @@ -1,17 +0,0 @@ -CXX_MODULE = qml -TARGET = webbrowser -TARGETPATH = WebBrowser -QT += qml quick -CONFIG += qt - -SOURCES += \ - plugin.cpp - -load(qml_plugin) - -target.path += /data/user/qt/qmlplugins/WebBrowser -INSTALLS += target - - - - diff --git a/src/imports/plugin.cpp b/src/imports/plugin.cpp deleted file mode 100644 index ebd59c1..0000000 --- a/src/imports/plugin.cpp +++ /dev/null @@ -1,81 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the QtBrowser project. -** -** $QT_BEGIN_LICENSE:GPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPLv2 included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/gpl-2.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include -#include "../app/touchtracker.h" -#include "../app/navigationhistoryproxymodel.h" - -#include -#include "../app/engine.cpp" -#include -#include -#include -#include - -QT_BEGIN_NAMESPACE - -static QObject *engine_factory(QQmlEngine *engine, QJSEngine *scriptEngine) -{ - Q_UNUSED(engine); - Q_UNUSED(scriptEngine); - Engine *eng = new Engine(); - return eng; -} - -class WebBrowser : public QQmlExtensionPlugin -{ - Q_OBJECT - Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface/1.0") -public: - virtual void registerTypes(const char *uri) - { - Q_ASSERT(QLatin1String(uri) == QLatin1String("WebBrowser")); - qmlRegisterType(uri, 1, 0, "TouchTracker"); - qmlRegisterType(uri, 1, 0, "SearchProxyModel"); - qmlRegisterSingletonType(uri, 1, 0, "WebEngine", engine_factory); - } - - virtual void initializeEngine(QQmlEngine *engine, const char *uri) - { - Q_UNUSED(uri); - } -}; - -QT_END_NAMESPACE - -#include "plugin.moc" - diff --git a/src/imports/qmldir b/src/imports/qmldir deleted file mode 100644 index 89b8c78..0000000 --- a/src/imports/qmldir +++ /dev/null @@ -1,4 +0,0 @@ -module WebBrowser -plugin webbrowser -class WebBrowser - diff --git a/src/app/main.cpp b/src/main.cpp similarity index 76% rename from src/app/main.cpp rename to src/main.cpp index f4fbf5d..79cb41b 100644 --- a/src/app/main.cpp +++ b/src/main.cpp @@ -35,22 +35,35 @@ ** ****************************************************************************/ +#include "appengine.h" +#include "navigationhistoryproxymodel.h" +#include "touchtracker.h" + +#if defined(DESKTOP_BUILD) +#include "touchmockingapplication.h" +#endif + #include #include #include #include #include -#include "browserwindow.h" +static QObject *engine_factory(QQmlEngine *engine, QJSEngine *scriptEngine) +{ + Q_UNUSED(engine); + Q_UNUSED(scriptEngine); + AppEngine *eng = new AppEngine(); + return eng; +} -#if defined(HOST_BUILD) -#include "touchmockingapplication.h" -#include "navigationhistoryproxymodel.h" -#include "touchtracker.h" -#endif int main(int argc, char **argv) { qputenv("QT_IM_MODULE", QByteArray("qtvirtualkeyboard")); + + //do not use any plugins installed on the device + qputenv("QML2_IMPORT_PATH", QByteArray()); + // We use touch mocking on desktop and apply all the mobile switches. QByteArrayList args = QByteArrayList() << QByteArrayLiteral("--enable-embedded-switches") @@ -65,29 +78,38 @@ int main(int argc, char **argv) qargv[i] = argv[i - args.size()]; int qAppArgCount = qargv.size(); -#if defined(HOST_BUILD) - TouchMockingApplication app(qAppArgCount, qargv.data()); - qmlRegisterType("WebBrowser", 1, 0, "TouchTracker"); - qmlRegisterType("WebBrowser", 1, 0, "SearchProxyModel"); +#if defined(DESKTOP_BUILD) + TouchMockingApplication app(qAppArgCount, qargv.data()); #else QGuiApplication app(qAppArgCount, qargv.data()); #endif + + qmlRegisterType("WebBrowser", 1, 0, "SearchProxyModel"); + qmlRegisterType("WebBrowser", 1, 0, "TouchTracker"); + qmlRegisterSingletonType("WebBrowser", 1, 0, "AppEngine", engine_factory); + QtWebEngine::initialize(); app.setOrganizationName("The Qt Company"); app.setOrganizationDomain("qt.io"); app.setApplicationName("qtwebbrowser"); - BrowserWindow window; - QObject::connect(window.rootContext()->engine(), SIGNAL(quit()), &app, SLOT(quit())); + QQuickView view; + view.setTitle("Yet Another Browser"); + view.setFlags(Qt::Window | Qt::WindowTitleHint); + view.setResizeMode(QQuickView::SizeRootObjectToView); + view.setColor(Qt::black); + view.setSource(QUrl("qrc:///qml/BrowserWindow.qml")); + + QObject::connect(view.engine(), SIGNAL(quit()), &app, SLOT(quit())); -#if defined(HOST_BUILD) - window.show(); - if (window.size().isEmpty()) - window.setGeometry(0, 0, 800, 600); +#if defined(DESKTOP_BUILD) + view.show(); + if (view.size().isEmpty()) + view.setGeometry(0, 0, 800, 600); #else - window.showFullScreen(); + view.showFullScreen(); #endif app.exec(); diff --git a/src/app/navigationhistoryproxymodel.cpp b/src/navigationhistoryproxymodel.cpp similarity index 100% rename from src/app/navigationhistoryproxymodel.cpp rename to src/navigationhistoryproxymodel.cpp diff --git a/src/app/navigationhistoryproxymodel.h b/src/navigationhistoryproxymodel.h similarity index 100% rename from src/app/navigationhistoryproxymodel.h rename to src/navigationhistoryproxymodel.h diff --git a/src/app/qml/BrowserWindow.qml b/src/qml/BrowserWindow.qml similarity index 97% rename from src/app/qml/BrowserWindow.qml rename to src/qml/BrowserWindow.qml index 6f6f07c..c639340 100644 --- a/src/app/qml/BrowserWindow.qml +++ b/src/qml/BrowserWindow.qml @@ -215,7 +215,9 @@ Item { return navigation.webView = tab.webView - navigation.load(WebEngine.initialUrl); + var url = AppEngine.initialUrl + + navigation.load(); } onCurrentIndexChanged: { if (!tabView.get(tabView.currentIndex)) @@ -230,7 +232,7 @@ Item { property var acceptedUrls : [] function shouldAutoAccept(certificateError){ - var domain = WebEngine.domainFromString(certificateError.url) + var domain = AppEngine.domainFromString(certificateError.url) return acceptedUrls.indexOf(domain) >= 0 } } @@ -251,7 +253,7 @@ Item { "Do you wish to override the security check and continue?" onYes: { var cert = certErrors.shift() - var domain = WebEngine.domainFromString(cert.url) + var domain = AppEngine.domainFromString(cert.url) acceptedCertificates.acceptedUrls.push(domain) cert.ignoreCertificateError() presentError() @@ -398,10 +400,10 @@ Item { onClicked: { var string = urlDropDown.searchString var constructedUrl = "" - if (WebEngine.isUrl(string)) { - constructedUrl = WebEngine.fromUserInput(string) + if (AppEngine.isUrl(string)) { + constructedUrl = AppEngine.fromUserInput(string) } else { - constructedUrl = WebEngine.fromUserInput(googleSearchQuery + string) + constructedUrl = AppEngine.fromUserInput(googleSearchQuery + string) } navigation.webView.url = constructedUrl navigation.webView.forceActiveFocus() diff --git a/src/app/qml/FeaturePermissionBar.qml b/src/qml/FeaturePermissionBar.qml similarity index 100% rename from src/app/qml/FeaturePermissionBar.qml rename to src/qml/FeaturePermissionBar.qml diff --git a/src/app/qml/HomeScreen.qml b/src/qml/HomeScreen.qml similarity index 99% rename from src/app/qml/HomeScreen.qml rename to src/qml/HomeScreen.qml index 2510025..d1ac349 100644 --- a/src/app/qml/HomeScreen.qml +++ b/src/qml/HomeScreen.qml @@ -129,7 +129,7 @@ Rectangle { Component.onCompleted: { listModel.clear() - var string = WebEngine.restoreSetting("bookmarks", defaultBookmarks) + var string = AppEngine.restoreSetting("bookmarks", defaultBookmarks) if (!string) return var list = JSON.parse(string) @@ -143,7 +143,7 @@ Rectangle { for (var i = 0; i < listModel.count; ++i) { list[i] = listModel.get(i) } - WebEngine.saveSetting("bookmarks", JSON.stringify(list)) + AppEngine.saveSetting("bookmarks", JSON.stringify(list)) } } diff --git a/src/app/qml/MockTouchPoint.qml b/src/qml/MockTouchPoint.qml similarity index 100% rename from src/app/qml/MockTouchPoint.qml rename to src/qml/MockTouchPoint.qml diff --git a/src/app/qml/NavigationBar.qml b/src/qml/NavigationBar.qml similarity index 99% rename from src/app/qml/NavigationBar.qml rename to src/qml/NavigationBar.qml index 140ec91..fe85326 100644 --- a/src/app/qml/NavigationBar.qml +++ b/src/qml/NavigationBar.qml @@ -56,7 +56,8 @@ ToolBar { opacity: tabView.viewState == "page" ? 1.0 : 0.0 function load(url) { - webView.url = url + if (url) + webView.url = url homeScreen.state = "disabled" } @@ -277,7 +278,7 @@ ToolBar { } } onAccepted: { - webView.url = WebEngine.fromUserInput(text) + webView.url = AppEngine.fromUserInput(text) homeScreen.state = "disabled" tabView.viewState = "page" } @@ -400,7 +401,7 @@ ToolBar { return } var count = homeScreen.count - homeScreen.add(webView.title, webView.url, icon, WebEngine.fallbackColor()) + homeScreen.add(webView.title, webView.url, icon, AppEngine.fallbackColor()) if (count < homeScreen.count) bookmarked = true } diff --git a/src/app/qml/PageView.qml b/src/qml/PageView.qml similarity index 100% rename from src/app/qml/PageView.qml rename to src/qml/PageView.qml diff --git a/src/app/qml/SettingsView.qml b/src/qml/SettingsView.qml similarity index 98% rename from src/app/qml/SettingsView.qml rename to src/qml/SettingsView.qml index 8ae6f64..b801bcf 100644 --- a/src/app/qml/SettingsView.qml +++ b/src/qml/SettingsView.qml @@ -67,7 +67,7 @@ Rectangle { // Do not persist private browsing mode if (setting.name === "Private Browsing") continue - WebEngine.saveSetting(setting.name, setting.active) + AppEngine.saveSetting(setting.name, setting.active) } } @@ -170,7 +170,7 @@ Rectangle { Component.onCompleted: { for (var i = 0; i < appSettings.length; ++i) { var setting = appSettings[i] - var active = JSON.parse(WebEngine.restoreSetting(setting.name, setting.active)) + var active = JSON.parse(AppEngine.restoreSetting(setting.name, setting.active)) if (setting.active !== active) { setting.active = active setting.notify(active) diff --git a/src/app/qml/Utils.js b/src/qml/Utils.js similarity index 100% rename from src/app/qml/Utils.js rename to src/qml/Utils.js diff --git a/src/app/qml/assets/UIButton.qml b/src/qml/assets/UIButton.qml similarity index 100% rename from src/app/qml/assets/UIButton.qml rename to src/qml/assets/UIButton.qml diff --git a/src/app/qml/assets/UIToolBar.qml b/src/qml/assets/UIToolBar.qml similarity index 100% rename from src/app/qml/assets/UIToolBar.qml rename to src/qml/assets/UIToolBar.qml diff --git a/src/app/qml/assets/icons/AppLogoColor.png b/src/qml/assets/icons/AppLogoColor.png similarity index 100% rename from src/app/qml/assets/icons/AppLogoColor.png rename to src/qml/assets/icons/AppLogoColor.png diff --git a/src/app/qml/assets/icons/AppLogoGrey.png b/src/qml/assets/icons/AppLogoGrey.png similarity index 100% rename from src/app/qml/assets/icons/AppLogoGrey.png rename to src/qml/assets/icons/AppLogoGrey.png diff --git a/src/app/qml/assets/icons/Btn_Add.png b/src/qml/assets/icons/Btn_Add.png similarity index 100% rename from src/app/qml/assets/icons/Btn_Add.png rename to src/qml/assets/icons/Btn_Add.png diff --git a/src/app/qml/assets/icons/Btn_Back.png b/src/qml/assets/icons/Btn_Back.png similarity index 100% rename from src/app/qml/assets/icons/Btn_Back.png rename to src/qml/assets/icons/Btn_Back.png diff --git a/src/app/qml/assets/icons/Btn_Bookmark_Checked.png b/src/qml/assets/icons/Btn_Bookmark_Checked.png similarity index 100% rename from src/app/qml/assets/icons/Btn_Bookmark_Checked.png rename to src/qml/assets/icons/Btn_Bookmark_Checked.png diff --git a/src/app/qml/assets/icons/Btn_Bookmark_Indicator.png b/src/qml/assets/icons/Btn_Bookmark_Indicator.png similarity index 100% rename from src/app/qml/assets/icons/Btn_Bookmark_Indicator.png rename to src/qml/assets/icons/Btn_Bookmark_Indicator.png diff --git a/src/app/qml/assets/icons/Btn_Bookmarks.png b/src/qml/assets/icons/Btn_Bookmarks.png similarity index 100% rename from src/app/qml/assets/icons/Btn_Bookmarks.png rename to src/qml/assets/icons/Btn_Bookmarks.png diff --git a/src/app/qml/assets/icons/Btn_Clear.png b/src/qml/assets/icons/Btn_Clear.png similarity index 100% rename from src/app/qml/assets/icons/Btn_Clear.png rename to src/qml/assets/icons/Btn_Clear.png diff --git a/src/app/qml/assets/icons/Btn_Delete.png b/src/qml/assets/icons/Btn_Delete.png similarity index 100% rename from src/app/qml/assets/icons/Btn_Delete.png rename to src/qml/assets/icons/Btn_Delete.png diff --git a/src/app/qml/assets/icons/Btn_Forward.png b/src/qml/assets/icons/Btn_Forward.png similarity index 100% rename from src/app/qml/assets/icons/Btn_Forward.png rename to src/qml/assets/icons/Btn_Forward.png diff --git a/src/app/qml/assets/icons/Btn_Home.png b/src/qml/assets/icons/Btn_Home.png similarity index 100% rename from src/app/qml/assets/icons/Btn_Home.png rename to src/qml/assets/icons/Btn_Home.png diff --git a/src/app/qml/assets/icons/Btn_Reload.png b/src/qml/assets/icons/Btn_Reload.png similarity index 100% rename from src/app/qml/assets/icons/Btn_Reload.png rename to src/qml/assets/icons/Btn_Reload.png diff --git a/src/app/qml/assets/icons/Btn_Search.png b/src/qml/assets/icons/Btn_Search.png similarity index 100% rename from src/app/qml/assets/icons/Btn_Search.png rename to src/qml/assets/icons/Btn_Search.png diff --git a/src/app/qml/assets/icons/Btn_Settings.png b/src/qml/assets/icons/Btn_Settings.png similarity index 100% rename from src/app/qml/assets/icons/Btn_Settings.png rename to src/qml/assets/icons/Btn_Settings.png diff --git a/src/app/qml/assets/icons/Btn_Tabs.png b/src/qml/assets/icons/Btn_Tabs.png similarity index 100% rename from src/app/qml/assets/icons/Btn_Tabs.png rename to src/qml/assets/icons/Btn_Tabs.png diff --git a/src/app/qml/assets/icons/Btn_Up.png b/src/qml/assets/icons/Btn_Up.png similarity index 100% rename from src/app/qml/assets/icons/Btn_Up.png rename to src/qml/assets/icons/Btn_Up.png diff --git a/src/app/qml/assets/icons/Error_Icon.png b/src/qml/assets/icons/Error_Icon.png similarity index 100% rename from src/app/qml/assets/icons/Error_Icon.png rename to src/qml/assets/icons/Error_Icon.png diff --git a/src/app/qml/assets/icons/LightWebBrowser_Icons.svg b/src/qml/assets/icons/LightWebBrowser_Icons.svg similarity index 100% rename from src/app/qml/assets/icons/LightWebBrowser_Icons.svg rename to src/qml/assets/icons/LightWebBrowser_Icons.svg diff --git a/src/app/qml/assets/icons/about_blank.png b/src/qml/assets/icons/about_blank.png similarity index 100% rename from src/app/qml/assets/icons/about_blank.png rename to src/qml/assets/icons/about_blank.png diff --git a/src/app/qml/assets/icons/qt.png b/src/qml/assets/icons/qt.png similarity index 100% rename from src/app/qml/assets/icons/qt.png rename to src/qml/assets/icons/qt.png diff --git a/src/app/qml/assets/icons/touchpoint.png b/src/qml/assets/icons/touchpoint.png similarity index 100% rename from src/app/qml/assets/icons/touchpoint.png rename to src/qml/assets/icons/touchpoint.png diff --git a/src/app/resources.qrc b/src/resources.qrc similarity index 100% rename from src/app/resources.qrc rename to src/resources.qrc diff --git a/src/src.pro b/src/src.pro index b5ae676..22762f9 100644 --- a/src/src.pro +++ b/src/src.pro @@ -1,8 +1,41 @@ -TEMPLATE = subdirs -SUBDIRS += \ - app +TARGET = qtwebbrowser -cross_compile { - SUBDIRS += \ - imports +CONFIG += c++11 +CONFIG -= app_bundle + +SOURCES = \ + appengine.cpp \ + main.cpp \ + navigationhistoryproxymodel.cpp \ + touchtracker.cpp + +HEADERS = \ + appengine.h \ + navigationhistoryproxymodel.h \ + touchtracker.h \ + +OTHER_FILES = \ + qml/assets/UIButton.qml \ + qml/assets/UIToolBar.qml \ + qml/ApplicationRoot.qml \ + qml/BrowserWindow.qml \ + qml/FeaturePermissionBar.qml \ + qml/MockTouchPoint.qml \ + qml/PageView.qml \ + qml/NavigationBar.qml \ + qml/HomeScreen.qml \ + qml/SettingsView.qml \ + +QT += qml quick webengine + +RESOURCES += resources.qrc + +!cross_compile { + DEFINES += DESKTOP_BUILD + SOURCES += touchmockingapplication.cpp + HEADERS += touchmockingapplication.h + QT += gui-private +} else { + target.path =/data/user/qt/qtwebbrowser-app + INSTALLS += target } diff --git a/src/app/touchmockingapplication.cpp b/src/touchmockingapplication.cpp similarity index 83% rename from src/app/touchmockingapplication.cpp rename to src/touchmockingapplication.cpp index 4819b01..256c45e 100644 --- a/src/app/touchmockingapplication.cpp +++ b/src/touchmockingapplication.cpp @@ -36,15 +36,15 @@ ****************************************************************************/ #include "touchmockingapplication.h" +#include "appengine.h" #include - -#include -#include -#include -#include - -#include "engine.h" +#include +#include +#include +#include +#include +#include using namespace utils; @@ -79,7 +79,7 @@ bool TouchMockingApplication::notify(QObject* target, QEvent* event) return QGuiApplication::notify(target, event); } - BrowserWindow* window = qobject_cast(target); + QQuickView* window = qobject_cast(target); if (!window) return QGuiApplication::notify(target, event); @@ -216,7 +216,7 @@ void TouchMockingApplication::updateTouchPoint(const QMouseEvent* mouseEvent, QT m_touchPoints.insert(mouseButton, touchPoint); } -bool TouchMockingApplication::sendTouchEvent(BrowserWindow* window, QEvent::Type type, ulong timestamp) +bool TouchMockingApplication::sendTouchEvent(QQuickView* window, QEvent::Type type, ulong timestamp) { static QTouchDevice* device = 0; if (!device) { @@ -238,7 +238,7 @@ bool TouchMockingApplication::sendTouchEvent(BrowserWindow* window, QEvent::Type QGuiApplication::notify(window, &event); - window->updateVisualMockTouchPoints(m_holdingControl ? currentTouchPoints : QList()); + updateVisualMockTouchPoints(window,m_holdingControl ? currentTouchPoints : QList()); // Get rid of touch-points that are no longer valid foreach (const QTouchEvent::TouchPoint& touchPoint, currentTouchPoints) { @@ -249,3 +249,34 @@ bool TouchMockingApplication::sendTouchEvent(BrowserWindow* window, QEvent::Type return event.isAccepted(); } +void TouchMockingApplication::updateVisualMockTouchPoints(QQuickView* window,const QList& touchPoints) +{ + if (touchPoints.isEmpty()) { + // Hide all touch indicator items. + foreach (QQuickItem* item, m_activeMockComponents.values()) + item->setProperty("pressed", false); + + return; + } + + foreach (const QTouchEvent::TouchPoint& touchPoint, touchPoints) { + QQuickItem* mockTouchPointItem = m_activeMockComponents.value(touchPoint.id()); + + if (!mockTouchPointItem) { + QQmlComponent touchMockPointComponent(window->engine(), QUrl("qrc:///qml/MockTouchPoint.qml")); + mockTouchPointItem = qobject_cast(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()); + } + + 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)); + } +} diff --git a/src/app/touchmockingapplication.h b/src/touchmockingapplication.h similarity index 78% rename from src/app/touchmockingapplication.h rename to src/touchmockingapplication.h index 6350436..88c5e20 100644 --- a/src/app/touchmockingapplication.h +++ b/src/touchmockingapplication.h @@ -38,25 +38,29 @@ #ifndef TOUCHMOCKINGAPPLICATION_H #define TOUCHMOCKINGAPPLICATION_H -#include "browserwindow.h" +#include +#include +#include +#include -#include -#include -#include -#include +QT_BEGIN_NAMESPACE +class QQuickView; +class QQuickItem; +QT_END_NAMESPACE class TouchMockingApplication : public QGuiApplication { Q_OBJECT public: - TouchMockingApplication(int &argc, char** argv); + TouchMockingApplication(int &argc, char **argv); - virtual bool notify(QObject*, QEvent*) override; + virtual bool notify(QObject *, QEvent *) override; private: - void updateTouchPoint(const QMouseEvent*, QTouchEvent::TouchPoint, Qt::MouseButton); - bool sendTouchEvent(BrowserWindow *, QEvent::Type, ulong timestamp); + void updateTouchPoint(const QMouseEvent *, QTouchEvent::TouchPoint, Qt::MouseButton); + bool sendTouchEvent(QQuickView *, QEvent::Type, ulong timestamp); + void updateVisualMockTouchPoints(QQuickView *,const QList &touchPoints); private: bool m_realTouchEventReceived; @@ -68,6 +72,7 @@ private: QHash m_touchPoints; QSet m_heldTouchPoints; + QHash m_activeMockComponents; bool m_holdingControl; }; diff --git a/src/app/touchtracker.cpp b/src/touchtracker.cpp similarity index 99% rename from src/app/touchtracker.cpp rename to src/touchtracker.cpp index 16b57c1..52a028a 100644 --- a/src/app/touchtracker.cpp +++ b/src/touchtracker.cpp @@ -36,11 +36,10 @@ ****************************************************************************/ #include "touchtracker.h" +#include "appengine.h" #include -#include "engine.h" - using namespace utils; TouchTracker::TouchTracker(QQuickItem *parent) diff --git a/src/app/touchtracker.h b/src/touchtracker.h similarity index 100% rename from src/app/touchtracker.h rename to src/touchtracker.h -- 2.39.2