summaryrefslogtreecommitdiffstats
path: root/example
diff options
context:
space:
mode:
authorJocelyn Turcotte <jocelyn.turcotte@digia.com>2013-06-06 18:46:47 +0200
committerJocelyn Turcotte <jocelyn.turcotte@digia.com>2013-06-06 18:52:28 +0200
commit5bf14cccfe86a8f87300d3e23432aeaa150cbf81 (patch)
treef65408cc6cbc619416b919d8db96c0734705c1ea /example
parenta1c0740f25b8c519910786a47e64d2d4f71495d9 (diff)
Properly implement a QWidget and QtQuick API
This layers things properly to be able to implement the UI in the example application instead of directly in shell_qt.cpp. This is still using global variables to allow the Shell platform code to do callbacks to the API classes. This should go away once we properly implemented a WebContentsDelegate.
Diffstat (limited to 'example')
-rw-r--r--example/example.pro5
-rw-r--r--example/main.cpp27
-rw-r--r--example/quickwindow.cpp49
-rw-r--r--example/quickwindow.h55
-rw-r--r--example/quickwindow.qml108
-rw-r--r--example/widgetwindow.cpp102
-rw-r--r--example/widgetwindow.h65
7 files changed, 405 insertions, 6 deletions
diff --git a/example/example.pro b/example/example.pro
index 7c76bb9a7..33a2f6182 100644
--- a/example/example.pro
+++ b/example/example.pro
@@ -1,7 +1,8 @@
TEMPLATE = app
TARGET = example
-SOURCES = main.cpp
+HEADERS = quickwindow.h widgetwindow.h
+SOURCES = quickwindow.cpp widgetwindow.cpp main.cpp
INCLUDEPATH += ../lib
@@ -10,4 +11,4 @@ LIBPATH = $$getOutDir()/$$getConfigDir()/lib
LIBS += -L$$LIBPATH -lblinq
QMAKE_RPATHDIR += $$LIBPATH
-QT += widgets
+QT += widgets quick
diff --git a/example/main.cpp b/example/main.cpp
index 3d068303b..edd75f3ec 100644
--- a/example/main.cpp
+++ b/example/main.cpp
@@ -38,16 +38,35 @@
** $QT_END_LICENSE$
**
****************************************************************************/
-#include <QtGui>
-#include <QtWidgets>
#include <blinqapplication.h>
+#include "quickwindow.h"
+#include "widgetwindow.h"
-int main(int argc, char **argv)
+int mainWidget(int argc, char **argv)
+{
+ BlinqApplication app(argc, argv);
+
+ WidgetWindow window;
+ window.show();
+
+ return app.exec();
+}
+
+int mainQuick(int argc, char **argv)
{
- printf("main called\n");
BlinqApplication app(argc, argv);
+ QuickWindow window;
+ window.show();
+
return app.exec();
}
+int main(int argc, char **argv)
+{
+ if (qgetenv("QQUICKWEBENGINE").isNull())
+ return mainWidget(argc, argv);
+ else
+ return mainQuick(argc, argv);
+}
diff --git a/example/quickwindow.cpp b/example/quickwindow.cpp
new file mode 100644
index 000000000..92cabb9ea
--- /dev/null
+++ b/example/quickwindow.cpp
@@ -0,0 +1,49 @@
+/****************************************************************************
+**
+** 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"
+
+QuickWindow::QuickWindow()
+{
+ setSource(QUrl("example/quickwindow.qml"));
+ setResizeMode(QQuickView::SizeRootObjectToView);
+ setTitle("QQuick Example");
+}
diff --git a/example/quickwindow.h b/example/quickwindow.h
new file mode 100644
index 000000000..7218d084e
--- /dev/null
+++ b/example/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 <QQuickView>
+
+class QWebContentsView;
+
+class QuickWindow : public QQuickView {
+ Q_OBJECT
+public:
+ QuickWindow();
+};
+
+#endif // QUICKWINDOW_H
diff --git a/example/quickwindow.qml b/example/quickwindow.qml
new file mode 100644
index 000000000..b424d959c
--- /dev/null
+++ b/example/quickwindow.qml
@@ -0,0 +1,108 @@
+import QtQuick 2.0
+import QtWebEngine 1.0
+
+Item {
+ id: browserWindow
+ height: 480
+ width: 320
+
+ Rectangle {
+ id: navigationBar
+ color: "grey"
+ anchors.top: parent.top
+ anchors.left: parent.left
+ anchors.right: parent.right
+ height: 26
+
+ Rectangle {
+ id: backButton
+ color: "red"
+ anchors.top: parent.top
+ anchors.bottom: parent.bottom
+ anchors.left: parent.left
+ width: height
+
+ MouseArea {
+ anchors.fill: parent
+ onClicked: {
+ webContentsView.goBack()
+ }
+ }
+ }
+ Rectangle {
+ id: forwardButton
+ color: "green"
+ anchors.top: parent.top
+ anchors.bottom: parent.bottom
+ anchors.left: backButton.right
+ width: height
+
+ MouseArea {
+ anchors.fill: parent
+ onClicked: {
+ webContentsView.goForward()
+ }
+ }
+ }
+ Rectangle {
+ id: reloadButton
+ color: "blue"
+ anchors.top: parent.top
+ anchors.bottom: parent.bottom
+ anchors.left: forwardButton.right
+ width: height
+
+ MouseArea {
+ anchors.fill: parent
+ onClicked: {
+ webContentsView.reload()
+ }
+ }
+ }
+ TextInput {
+ id: addressBar
+ focus: true
+ anchors.top: parent.top
+ anchors.bottom: parent.bottom
+ anchors.left: reloadButton.right
+ anchors.right: parent.right
+
+ cursorVisible: true
+ persistentSelection: true
+ selectByMouse: true
+
+ onAccepted: {
+ webContentsView.url = text
+ }
+ }
+ }
+
+ WebContentsView {
+ id: webContentsView
+ focus: true
+ anchors.top: navigationBar.bottom
+ anchors.bottom: parent.bottom
+ anchors.left: parent.left
+ anchors.right: parent.right
+
+ 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/example/widgetwindow.cpp b/example/widgetwindow.cpp
new file mode 100644
index 000000000..89982e509
--- /dev/null
+++ b/example/widgetwindow.cpp
@@ -0,0 +1,102 @@
+/****************************************************************************
+**
+** 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&)));
+}
+
+WidgetWindow::~WidgetWindow()
+{
+}
+
+void WidgetWindow::loadAddressFromAddressBar()
+{
+ m_webView->load(addressLineEdit->text());
+}
+
+void WidgetWindow::setAddressBarUrl(const QUrl& url)
+{
+ addressLineEdit->setText(url.toString());
+}
+
diff --git a/example/widgetwindow.h b/example/widgetwindow.h
new file mode 100644
index 000000000..e579de271
--- /dev/null
+++ b/example/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:
+ QLineEdit* addressLineEdit;
+ QScopedPointer<QWebContentsView> m_webView;
+};
+
+#endif // WIDGETWINDOW_H