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/widgets | |
parent | 4a08bd334b661d00a9fd908d054728ab9e9a5d8d (diff) |
Split out the example into two distinct ones
Cleaner than deciding on startup with an env variable
Diffstat (limited to 'examples/widgets')
-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 |
4 files changed, 231 insertions, 0 deletions
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 |