diff options
author | Pierre Rossi <pierre.rossi@digia.com> | 2013-06-17 18:20:39 +0200 |
---|---|---|
committer | Pierre Rossi <pierre.rossi@digia.com> | 2013-06-17 18:26:20 +0200 |
commit | c6144131d1f97bcd69682bb733a54f2cd777f127 (patch) | |
tree | f44ff4d3c2955636ceb811bd59ed90ed22a1a58f /examples | |
parent | 4a08bd334b661d00a9fd908d054728ab9e9a5d8d (diff) |
Split out the example into two distinct ones
Cleaner than deciding on startup with an env variable
Diffstat (limited to 'examples')
-rw-r--r-- | examples/common.pri | 10 | ||||
-rw-r--r-- | examples/examples.pro | 4 | ||||
-rw-r--r-- | examples/qtquick/icons/go-next.png | bin | 0 -> 930 bytes | |||
-rw-r--r-- | examples/qtquick/icons/go-previous.png | bin | 0 -> 955 bytes | |||
-rw-r--r-- | examples/qtquick/icons/process-stop.png | bin | 0 -> 1272 bytes | |||
-rw-r--r-- | examples/qtquick/icons/view-refresh.png | bin | 0 -> 1364 bytes | |||
-rw-r--r-- | examples/qtquick/main.cpp | 55 | ||||
-rw-r--r-- | examples/qtquick/qtquick.pro | 12 | ||||
-rw-r--r-- | examples/qtquick/quickwindow.cpp | 69 | ||||
-rw-r--r-- | examples/qtquick/quickwindow.h | 55 | ||||
-rw-r--r-- | examples/qtquick/quickwindow.qml | 71 | ||||
-rw-r--r-- | examples/widgets/main.cpp | 53 | ||||
-rw-r--r-- | examples/widgets/widgets.pro | 9 | ||||
-rw-r--r-- | examples/widgets/widgetwindow.cpp | 104 | ||||
-rw-r--r-- | examples/widgets/widgetwindow.h | 65 |
15 files changed, 507 insertions, 0 deletions
diff --git a/examples/common.pri b/examples/common.pri new file mode 100644 index 000000000..b85159ce8 --- /dev/null +++ b/examples/common.pri @@ -0,0 +1,10 @@ +INCLUDEPATH += $$absolute_path(../lib, $$PWD) + +LIBPATH = $$getOutDir()/$$getConfigDir()/lib + +LIBS += -L$$LIBPATH -lQt5WebEngine +QMAKE_RPATHDIR += $$LIBPATH + +# Quick hack for now as we mess with that for the gyp generation step. +MOC_DIR=$$PWD/.moc + diff --git a/examples/examples.pro b/examples/examples.pro new file mode 100644 index 000000000..4613dc8d8 --- /dev/null +++ b/examples/examples.pro @@ -0,0 +1,4 @@ +TEMPLATE=subdirs + +SUBDIRS += qtquick \ + widgets diff --git a/examples/qtquick/icons/go-next.png b/examples/qtquick/icons/go-next.png Binary files differnew file mode 100644 index 000000000..6f3f65d33 --- /dev/null +++ b/examples/qtquick/icons/go-next.png diff --git a/examples/qtquick/icons/go-previous.png b/examples/qtquick/icons/go-previous.png Binary files differnew file mode 100644 index 000000000..93be3d1ee --- /dev/null +++ b/examples/qtquick/icons/go-previous.png diff --git a/examples/qtquick/icons/process-stop.png b/examples/qtquick/icons/process-stop.png Binary files differnew file mode 100644 index 000000000..b68290bf1 --- /dev/null +++ b/examples/qtquick/icons/process-stop.png diff --git a/examples/qtquick/icons/view-refresh.png b/examples/qtquick/icons/view-refresh.png Binary files differnew file mode 100644 index 000000000..cab4d02c7 --- /dev/null +++ b/examples/qtquick/icons/view-refresh.png diff --git a/examples/qtquick/main.cpp b/examples/qtquick/main.cpp new file mode 100644 index 000000000..ca92eb72c --- /dev/null +++ b/examples/qtquick/main.cpp @@ -0,0 +1,55 @@ +/**************************************************************************** +** +** 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 "qquickwebcontentsview.h" +#include <QApplication> + +int main(int argc, char **argv) +{ + QApplication app(argc, argv); + + QQuickWebContentsView::registerType(); + + ApplicationEngine appEngine; + + return app.exec(); +} diff --git a/examples/qtquick/qtquick.pro b/examples/qtquick/qtquick.pro new file mode 100644 index 000000000..6d3e8a62e --- /dev/null +++ b/examples/qtquick/qtquick.pro @@ -0,0 +1,12 @@ +TEMPLATE = app +TARGET = qtquick-nano-browser + +include(../common.pri) + +HEADERS = quickwindow.h +SOURCES = quickwindow.cpp main.cpp + +OTHER_FILES += quickwindow.qml + +QT += quick \ + widgets # QApplication is required to get native styling with QtQuickControls diff --git a/examples/qtquick/quickwindow.cpp b/examples/qtquick/quickwindow.cpp new file mode 100644 index 000000000..fed881fc0 --- /dev/null +++ b/examples/qtquick/quickwindow.cpp @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** 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 <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) + { + QFileInfo fileInfo(userInput); + if (fileInfo.exists()) + return QUrl(fileInfo.absoluteFilePath()); + return QUrl::fromUserInput(userInput); + } +}; + +#include "quickwindow.moc" + +ApplicationEngine::ApplicationEngine() +{ + rootContext()->setContextProperty("utils", new Utils(this)); + load(QUrl("quickwindow.qml")); +} diff --git a/examples/qtquick/quickwindow.h b/examples/qtquick/quickwindow.h new file mode 100644 index 000000000..3f1f944ca --- /dev/null +++ b/examples/qtquick/quickwindow.h @@ -0,0 +1,55 @@ +/**************************************************************************** +** +** 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 QUICKWINDOW_H +#define QUICKWINDOW_H + +#include <QQmlApplicationEngine> + +class QWebContentsView; + +class ApplicationEngine : public QQmlApplicationEngine { + Q_OBJECT +public: + ApplicationEngine(); +}; + +#endif // QUICKWINDOW_H diff --git a/examples/qtquick/quickwindow.qml b/examples/qtquick/quickwindow.qml new file mode 100644 index 000000000..3fe0389bf --- /dev/null +++ b/examples/qtquick/quickwindow.qml @@ -0,0 +1,71 @@ +import QtQuick 2.0 +import QtWebEngine 1.0 +import QtQuick.Controls 1.0 +import QtQuick.Layouts 1.0 + +ApplicationWindow { + id: browserWindow + height: 600 + width: 800 + visible: true + + toolBar: ToolBar { + id: navigationBar + RowLayout { + anchors.fill: parent + + ToolButton { + id: backButton + iconName: "go-previous" + iconSource: "icons/go-previous.png" + onClicked: webContentsView.goBack() + } + ToolButton { + id: forwardButton + iconName: "go-next" + iconSource: "icons/go-next.png" + onClicked: webContentsView.goForward() + } + ToolButton { + id: reloadButton + iconName: "view-refresh" + iconSource: "icons/view-refresh.png" + onClicked: webContentsView.reload() + } + TextField { + id: addressBar + focus: true + Layout.fillWidth: true + + onAccepted: webContentsView.url = utils.fromUserInput(text) + } + } + } + + WebContentsView { + id: webContentsView + focus: true + anchors.fill: parent + url: "http://qt-project.org/" + + Binding { + target: webContentsView.children[0] + property: 'anchors.fill' + value: webContentsView + when: webContentsView.children.length > 0 + } + + onUrlChanged: addressBar.text = url + } + + Text { + id: info + anchors.top: parent.top + anchors.right: parent.right + horizontalAlignment: "AlignRight" + width: 100 + height: 100 + + text: viewContainer.children[0].width + "x" + viewContainer.children[0].height + } +} diff --git a/examples/widgets/main.cpp b/examples/widgets/main.cpp new file mode 100644 index 000000000..f6c9a37b0 --- /dev/null +++ b/examples/widgets/main.cpp @@ -0,0 +1,53 @@ +/**************************************************************************** +** +** 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 "widgetwindow.h" +#include <QApplication> + +int main(int argc, char **argv) +{ + QApplication app(argc, argv); + + WidgetWindow window; + window.show(); + + return app.exec(); +} diff --git a/examples/widgets/widgets.pro b/examples/widgets/widgets.pro new file mode 100644 index 000000000..3d0d17d7f --- /dev/null +++ b/examples/widgets/widgets.pro @@ -0,0 +1,9 @@ +TEMPLATE = app +TARGET = widget-nano-browser + +include(../common.pri) + +HEADERS = widgetwindow.h +SOURCES = widgetwindow.cpp main.cpp + +QT += widgets diff --git a/examples/widgets/widgetwindow.cpp b/examples/widgets/widgetwindow.cpp new file mode 100644 index 000000000..159952715 --- /dev/null +++ b/examples/widgets/widgetwindow.cpp @@ -0,0 +1,104 @@ +/**************************************************************************** +** +** 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 "widgetwindow.h" + +#include "qwebcontentsview.h" + +WidgetWindow::WidgetWindow() +: m_webView(new QWebContentsView) +, addressLineEdit(0) +{ + // Use oxygen as a fallback. + if (QIcon::themeName().isEmpty()) + QIcon::setThemeName("oxygen"); + + setGeometry(0, 0, 1024, 768); + + QVBoxLayout* layout = new QVBoxLayout; + + // Create a widget based address bar. + QHBoxLayout* addressBar = new QHBoxLayout; + + QToolButton* backButton = new QToolButton; + backButton->setIcon(QIcon::fromTheme("go-previous")); + addressBar->addWidget(backButton); + + QToolButton* forwardButton = new QToolButton; + forwardButton->setIcon(QIcon::fromTheme("go-next")); + addressBar->addWidget(forwardButton); + + QToolButton* reloadButton = new QToolButton; + reloadButton->setIcon(QIcon::fromTheme("view-refresh")); + addressBar->addWidget(reloadButton); + + addressLineEdit = new QLineEdit; + addressBar->addWidget(addressLineEdit); + + layout->addLayout(addressBar); + layout->addWidget(m_webView.data()); + + setLayout(layout); + + connect(addressLineEdit, SIGNAL(returnPressed()), SLOT(loadAddressFromAddressBar())); + connect(backButton, SIGNAL(clicked()), m_webView.data(), SLOT(back())); + connect(forwardButton, SIGNAL(clicked()), m_webView.data(), SLOT(forward())); + connect(reloadButton, SIGNAL(clicked()), m_webView.data(), SLOT(reload())); + connect(m_webView.data(), SIGNAL(titleChanged(const QString&)), SLOT(setWindowTitle(const QString&))); + connect(m_webView.data(), SIGNAL(urlChanged(const QUrl&)), SLOT(setAddressBarUrl(const QUrl&))); + + m_webView->load(QUrl(QStringLiteral("http://qt-project.org/"))); +} + +WidgetWindow::~WidgetWindow() +{ +} + +void WidgetWindow::loadAddressFromAddressBar() +{ + m_webView->load(addressLineEdit->text()); +} + +void WidgetWindow::setAddressBarUrl(const QUrl& url) +{ + addressLineEdit->setText(url.toString()); +} + diff --git a/examples/widgets/widgetwindow.h b/examples/widgets/widgetwindow.h new file mode 100644 index 000000000..334f815ea --- /dev/null +++ b/examples/widgets/widgetwindow.h @@ -0,0 +1,65 @@ +/**************************************************************************** +** +** 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 WIDGETWINDOW_H +#define WIDGETWINDOW_H + +#include <QtWidgets> +#include <QScopedPointer> + +class QWebContentsView; + +class WidgetWindow : public QWidget { + Q_OBJECT +public: + WidgetWindow(); + ~WidgetWindow(); + +private Q_SLOTS: + void loadAddressFromAddressBar(); + void setAddressBarUrl(const QUrl& url); + +private: + QScopedPointer<QWebContentsView> m_webView; + QLineEdit* addressLineEdit; +}; + +#endif // WIDGETWINDOW_H |