diff options
author | Venugopal Shivashankar <venugopal.shivashankar@digia.com> | 2014-11-20 12:56:59 +0100 |
---|---|---|
committer | Venugopal Shivashankar <venugopal.shivashankar@digia.com> | 2014-11-21 15:05:53 +0100 |
commit | 85d5f57ebe5ee44a9171cae2c8141d6ed2a0f979 (patch) | |
tree | f9fd2b8dbca9658f4ba760f9829381e513bfd820 /examples/webview/minibrowser | |
parent | 5e33c08b025f40cd032daa4c947140bfc41b8ad6 (diff) |
Doc: Renamed the webview example
- Updated the subdirs project file referring the example
- Updated the examples page with the new name
- Moved the qtwebview-example group page to doc/src
Change-Id: I53ba49103ad2bfff21a230dded456be1e88231f2
Reviewed-by: Christian Stromme <christian.stromme@digia.com>
Diffstat (limited to 'examples/webview/minibrowser')
-rw-r--r-- | examples/webview/minibrowser/deployment.pri | 27 | ||||
-rw-r--r-- | examples/webview/minibrowser/doc/images/webview-example.png | bin | 0 -> 69522 bytes | |||
-rw-r--r-- | examples/webview/minibrowser/doc/src/minibrowser.qdoc | 40 | ||||
-rw-r--r-- | examples/webview/minibrowser/images/left-32.png | bin | 0 -> 1799 bytes | |||
-rw-r--r-- | examples/webview/minibrowser/images/right-32.png | bin | 0 -> 1804 bytes | |||
-rw-r--r-- | examples/webview/minibrowser/main.cpp | 107 | ||||
-rw-r--r-- | examples/webview/minibrowser/main.qml | 108 | ||||
-rw-r--r-- | examples/webview/minibrowser/minibrowser.pro | 18 | ||||
-rw-r--r-- | examples/webview/minibrowser/qml.qrc | 7 |
9 files changed, 307 insertions, 0 deletions
diff --git a/examples/webview/minibrowser/deployment.pri b/examples/webview/minibrowser/deployment.pri new file mode 100644 index 0000000..5441b63 --- /dev/null +++ b/examples/webview/minibrowser/deployment.pri @@ -0,0 +1,27 @@ +android-no-sdk { + target.path = /data/user/qt + export(target.path) + INSTALLS += target +} else:android { + x86 { + target.path = /libs/x86 + } else: armeabi-v7a { + target.path = /libs/armeabi-v7a + } else { + target.path = /libs/armeabi + } + export(target.path) + INSTALLS += target +} else:unix { + isEmpty(target.path) { + qnx { + target.path = /tmp/$${TARGET}/bin + } else { + target.path = /opt/$${TARGET}/bin + } + export(target.path) + } + INSTALLS += target +} + +export(INSTALLS) diff --git a/examples/webview/minibrowser/doc/images/webview-example.png b/examples/webview/minibrowser/doc/images/webview-example.png Binary files differnew file mode 100644 index 0000000..ea7e219 --- /dev/null +++ b/examples/webview/minibrowser/doc/images/webview-example.png diff --git a/examples/webview/minibrowser/doc/src/minibrowser.qdoc b/examples/webview/minibrowser/doc/src/minibrowser.qdoc new file mode 100644 index 0000000..e7dec3e --- /dev/null +++ b/examples/webview/minibrowser/doc/src/minibrowser.qdoc @@ -0,0 +1,40 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** 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 Free Documentation License Usage +** Alternatively, this file may be used under the terms of the GNU Free +** Documentation License version 1.3 as published by the Free Software +** Foundation and appearing in the file included in the packaging of +** this file. Please review the following information to ensure +** the GNU Free Documentation License version 1.3 requirements +** will be met: http://www.gnu.org/copyleft/fdl.html. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*! + \title Qt WebView Examples - Minibrowser + \example minibrowser + \brief Minibrowser example demonstrates how to use the Qt WebView module with Qt Quick. + \image webview-example.png + \ingroup qtwebview-examples + + Minibrowser uses Qt Quick Controls and Qt WebView to provide basic + browsing experience. Besides the addressbar for the URL, it has a + couple of controls to navigate through the browsing history. + + \include examples-run.qdocinc +*/ diff --git a/examples/webview/minibrowser/images/left-32.png b/examples/webview/minibrowser/images/left-32.png Binary files differnew file mode 100644 index 0000000..ec4107b --- /dev/null +++ b/examples/webview/minibrowser/images/left-32.png diff --git a/examples/webview/minibrowser/images/right-32.png b/examples/webview/minibrowser/images/right-32.png Binary files differnew file mode 100644 index 0000000..0f6ba86 --- /dev/null +++ b/examples/webview/minibrowser/images/right-32.png diff --git a/examples/webview/minibrowser/main.cpp b/examples/webview/minibrowser/main.cpp new file mode 100644 index 0000000..4598b3f --- /dev/null +++ b/examples/webview/minibrowser/main.cpp @@ -0,0 +1,107 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names +** of its contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtCore/QUrl> +#include <QtCore/QCommandLineOption> +#include <QtCore/QCommandLineParser> +#include <QGuiApplication> +#include <QStyleHints> +#include <QScreen> +#include <QQmlApplicationEngine> +#include <QtQml/QQmlContext> + +#ifdef QT_WEBVIEW_WEBENGINE_BACKEND +#include <QtWebEngine> +#endif // QT_WEBVIEW_WEBENGINE_BACKEND + +// Workaround: As of Qt 5.4 QtQuick does not expose QUrl::fromUserInput. +class Utils : public QObject { + Q_OBJECT +public: + Utils(QObject* parent = 0) : QObject(parent) { } + Q_INVOKABLE static QUrl fromUserInput(const QString& userInput); +}; + +QUrl Utils::fromUserInput(const QString& userInput) +{ + if (userInput.isEmpty()) + return QUrl::fromUserInput("about:blank"); + const QUrl result = QUrl::fromUserInput(userInput); + return result.isValid() ? result : QUrl::fromUserInput("about:blank"); +} + +#include "main.moc" + +int main(int argc, char *argv[]) +{ + QGuiApplication app(argc, argv); +#ifdef QT_WEBVIEW_WEBENGINE_BACKEND + QtWebEngine::initialize(); +#endif // QT_WEBVIEW_WEBENGINE_BACKEND + QCommandLineParser parser; + QCoreApplication::setApplicationVersion(QT_VERSION_STR); + parser.setApplicationDescription("QtWebView Browser Example"); + parser.addHelpOption(); + parser.addVersionOption(); + parser.addPositionalArgument("url", "The initial URL to open."); + parser.process(app); + const QString initialUrl = parser.positionalArguments().isEmpty() ? + QStringLiteral("qt.io") : parser.positionalArguments().first(); + + QQmlApplicationEngine engine; + QQmlContext *context = engine.rootContext(); + context->setContextProperty(QStringLiteral("utils"), new Utils(&engine)); + context->setContextProperty(QStringLiteral("initialUrl"), + Utils::fromUserInput(initialUrl)); + QRect geometry = QGuiApplication::primaryScreen()->availableGeometry(); + if (!QGuiApplication::styleHints()->showIsFullScreen()) { + const QSize size = geometry.size() * 4 / 5; + const QSize offset = (geometry.size() - size) / 2; + const QPoint pos = geometry.topLeft() + QPoint(offset.width(), offset.height()); + geometry = QRect(pos, size); + } + context->setContextProperty(QStringLiteral("initialX"), geometry.x()); + context->setContextProperty(QStringLiteral("initialY"), geometry.y()); + context->setContextProperty(QStringLiteral("initialWidth"), geometry.width()); + context->setContextProperty(QStringLiteral("initialHeight"), geometry.height()); + engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); + + return app.exec(); +} diff --git a/examples/webview/minibrowser/main.qml b/examples/webview/minibrowser/main.qml new file mode 100644 index 0000000..728323f --- /dev/null +++ b/examples/webview/minibrowser/main.qml @@ -0,0 +1,108 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names +** of its contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.2 +import QtQuick.Controls 1.1 +import QtWebView 1.0 +import QtQuick.Layouts 1.1 + +ApplicationWindow { + visible: true + x: initialX + y: initialY + width: initialWidth + height: initialHeight + title: qsTr("QtWebView Example") + + toolBar: ToolBar { + id: navigationBar + RowLayout { + anchors.fill: parent + + ToolButton { + id: backButton + text: qsTr("Back") + iconSource: "qrc:/images/left-32.png" + onClicked: webView.goBack() + enabled: webView.canGoBack + } + + ToolButton { + id: forwardButton + text: qsTr("Forward") + iconSource: "qrc:/images/right-32.png" + onClicked: webView.goForward() + enabled: webView.canGoForward + } + + TextField { + Layout.fillWidth: true + id: urlField + inputMethodHints: Qt.ImhUrlCharactersOnly | Qt.ImhPreferLowercase + text: webView.url + onEditingFinished: { + webView.url = utils.fromUserInput(urlField.text); + } + } + + ToolButton { + id: goButton + text: qsTr("Go") + onClicked: { + webView.url = utils.fromUserInput(urlField.text) + } + } + } + } + + statusBar: StatusBar { + id: statusBar + RowLayout { + anchors.fill: parent + Label { text: webView.loadProgress == 100 ? qsTr("Done") : qsTr("Loading: ") + webView.loadProgress + "%" } + } + } + + WebView { + id: webView + anchors.fill: parent + url: initialUrl + } +} diff --git a/examples/webview/minibrowser/minibrowser.pro b/examples/webview/minibrowser/minibrowser.pro new file mode 100644 index 0000000..e02757c --- /dev/null +++ b/examples/webview/minibrowser/minibrowser.pro @@ -0,0 +1,18 @@ +TEMPLATE = app + +QT += qml quick + +qtHaveModule(webengine) { + QT += webengine + DEFINES += QT_WEBVIEW_WEBENGINE_BACKEND +} + +SOURCES += main.cpp + +RESOURCES += qml.qrc + +# Additional import path used to resolve QML modules in Qt Creator's code model +QML_IMPORT_PATH = + +# Default rules for deployment. +include(deployment.pri) diff --git a/examples/webview/minibrowser/qml.qrc b/examples/webview/minibrowser/qml.qrc new file mode 100644 index 0000000..16da66e --- /dev/null +++ b/examples/webview/minibrowser/qml.qrc @@ -0,0 +1,7 @@ +<RCC> + <qresource prefix="/"> + <file>main.qml</file> + <file>images/left-32.png</file> + <file>images/right-32.png</file> + </qresource> +</RCC> |