diff options
author | Jocelyn Turcotte <jocelyn.turcotte@digia.com> | 2015-01-15 12:39:43 +0100 |
---|---|---|
committer | Jocelyn Turcotte <jocelyn.turcotte@digia.com> | 2015-01-23 12:10:42 +0100 |
commit | 5d1883372fe107f70a39c9cea13f584a8cc61e0b (patch) | |
tree | 51a71f2d28454620d0820c5f850e99af8c4770be /examples | |
parent | d95b9295c970401939d2779cbdc9e2a8c7965277 (diff) |
Clean the file structure of quicknanobrowser and quicktestbrowser
- Remove the unnecessary intermediate ApplicationEngine class
- Rename quickwindow.qml to BrowserWindow.qml
- Move the injected Utils QObject into utils.h
Change-Id: I3b0551e2bf477fc94640c71736de26c46c1ab633
Reviewed-by: Andras Becsi <andras.becsi@theqtcompany.com>
Diffstat (limited to 'examples')
-rw-r--r-- | examples/webengine/quicknanobrowser/BrowserWindow.qml (renamed from examples/webengine/quicknanobrowser/quickwindow.qml) | 0 | ||||
-rw-r--r-- | examples/webengine/quicknanobrowser/main.cpp | 26 | ||||
-rw-r--r-- | examples/webengine/quicknanobrowser/quicknanobrowser.pro | 8 | ||||
-rw-r--r-- | examples/webengine/quicknanobrowser/quickwindow.cpp | 66 | ||||
-rw-r--r-- | examples/webengine/quicknanobrowser/resources.qrc | 2 | ||||
-rw-r--r-- | examples/webengine/quicknanobrowser/util.h | 73 | ||||
-rw-r--r-- | examples/webengine/quicknanobrowser/utils.h (renamed from examples/webengine/quicknanobrowser/quickwindow.h) | 24 |
7 files changed, 43 insertions, 156 deletions
diff --git a/examples/webengine/quicknanobrowser/quickwindow.qml b/examples/webengine/quicknanobrowser/BrowserWindow.qml index b954629fb..b954629fb 100644 --- a/examples/webengine/quicknanobrowser/quickwindow.qml +++ b/examples/webengine/quicknanobrowser/BrowserWindow.qml diff --git a/examples/webengine/quicknanobrowser/main.cpp b/examples/webengine/quicknanobrowser/main.cpp index d5a4ade55..bcfec07c5 100644 --- a/examples/webengine/quicknanobrowser/main.cpp +++ b/examples/webengine/quicknanobrowser/main.cpp @@ -39,7 +39,8 @@ ** ****************************************************************************/ -#include "quickwindow.h" +#include "utils.h" + #ifndef QT_NO_WIDGETS #include <QtWidgets/QApplication> typedef QApplication Application; @@ -47,15 +48,36 @@ typedef QApplication Application; #include <QtGui/QGuiApplication> typedef QGuiApplication Application; #endif +#include <QtQml/QQmlApplicationEngine> +#include <QtQml/QQmlContext> #include <QtWebEngine/qtwebengineglobal.h> +static QUrl startupUrl() +{ + QUrl ret; + QStringList args(qApp->arguments()); + args.takeFirst(); + Q_FOREACH (const QString& arg, args) { + if (arg.startsWith(QLatin1Char('-'))) + continue; + ret = Utils::fromUserInput(arg); + if (ret.isValid()) + return ret; + } + return QUrl(QStringLiteral("http://qt.io/")); +} + int main(int argc, char **argv) { Application app(argc, argv); QtWebEngine::initialize(); - ApplicationEngine appEngine; + QQmlApplicationEngine appEngine; + Utils utils; + appEngine.rootContext()->setContextProperty("utils", &utils); + appEngine.load(QUrl("qrc:/BrowserWindow.qml")); + QMetaObject::invokeMethod(appEngine.rootObjects().first(), "load", Q_ARG(QVariant, startupUrl())); return app.exec(); } diff --git a/examples/webengine/quicknanobrowser/quicknanobrowser.pro b/examples/webengine/quicknanobrowser/quicknanobrowser.pro index a8e57b0a4..37df16d3c 100644 --- a/examples/webengine/quicknanobrowser/quicknanobrowser.pro +++ b/examples/webengine/quicknanobrowser/quicknanobrowser.pro @@ -3,12 +3,10 @@ requires(contains(QT_CONFIG, accessibility)) TEMPLATE = app TARGET = quicknanobrowser -HEADERS = quickwindow.h \ - util.h -SOURCES = quickwindow.cpp \ - main.cpp +HEADERS = utils.h +SOURCES = main.cpp -OTHER_FILES += quickwindow.qml +OTHER_FILES += BrowserWindow.qml RESOURCES += resources.qrc diff --git a/examples/webengine/quicknanobrowser/quickwindow.cpp b/examples/webengine/quicknanobrowser/quickwindow.cpp deleted file mode 100644 index ec7b6f94a..000000000 --- a/examples/webengine/quicknanobrowser/quickwindow.cpp +++ /dev/null @@ -1,66 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtWebEngine module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** 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 Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** 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 "quickwindow.h" - -#include "util.h" - -#include <QFileInfo> -#include <QObject> -#include <QQmlContext> -#include <QQmlEngine> -#include <QUrl> - -class Utils : public QObject { - Q_OBJECT -public: - Utils(QObject* parent = 0) : QObject(parent) { } - Q_INVOKABLE static QUrl fromUserInput(const QString& userInput) { return urlFromUserInput(userInput); } -}; - -#include "quickwindow.moc" - -ApplicationEngine::ApplicationEngine() -{ - rootContext()->setContextProperty("utils", new Utils(this)); - load(QUrl("qrc:/quickwindow.qml")); - QMetaObject::invokeMethod(rootObjects().first(), "load", Q_ARG(QVariant, startupUrl())); -} diff --git a/examples/webengine/quicknanobrowser/resources.qrc b/examples/webengine/quicknanobrowser/resources.qrc index 549207726..c95721028 100644 --- a/examples/webengine/quicknanobrowser/resources.qrc +++ b/examples/webengine/quicknanobrowser/resources.qrc @@ -1,6 +1,6 @@ <!DOCTYPE RCC><RCC version="1.0"> <qresource prefix="/"> - <file>quickwindow.qml</file> + <file>BrowserWindow.qml</file> </qresource> <qresource prefix="icons"> <file alias="go-next.png">icons/go-next.png</file> diff --git a/examples/webengine/quicknanobrowser/util.h b/examples/webengine/quicknanobrowser/util.h deleted file mode 100644 index ca0f5f1d5..000000000 --- a/examples/webengine/quicknanobrowser/util.h +++ /dev/null @@ -1,73 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtWebEngine module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** 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 Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** 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 UTIL_H -#define UTIL_H - -#include <QtCore/QCoreApplication> -#include <QtCore/QFileInfo> -#include <QtCore/QUrl> -#include <QtCore/QStringList> - -QUrl urlFromUserInput(const QString& userInput) -{ - QFileInfo fileInfo(userInput); - if (fileInfo.exists()) - return QUrl::fromLocalFile(fileInfo.absoluteFilePath()); - return QUrl::fromUserInput(userInput); -} - -QUrl startupUrl() -{ - QUrl ret; - QStringList args(qApp->arguments()); - args.takeFirst(); - Q_FOREACH (const QString& arg, args) { - if (arg.startsWith(QLatin1Char('-'))) - continue; - ret = urlFromUserInput(arg); - if (ret.isValid()) - return ret; - } - return QUrl(QStringLiteral("http://qt.io/")); -} - - -#endif // UTIL_H diff --git a/examples/webengine/quicknanobrowser/quickwindow.h b/examples/webengine/quicknanobrowser/utils.h index ed25a23b8..3cb3fec5d 100644 --- a/examples/webengine/quicknanobrowser/quickwindow.h +++ b/examples/webengine/quicknanobrowser/utils.h @@ -38,18 +38,24 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ +#ifndef UTILS_H +#define UTILS_H -#ifndef QUICKWINDOW_H -#define QUICKWINDOW_H +#include <QtCore/QFileInfo> +#include <QtCore/QUrl> -#include <QQmlApplicationEngine> - -class QWebEngineView; - -class ApplicationEngine : public QQmlApplicationEngine { +class Utils : public QObject { Q_OBJECT public: - ApplicationEngine(); + Q_INVOKABLE static QUrl fromUserInput(const QString& userInput); }; -#endif // QUICKWINDOW_H +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 |