Add simplebrowser from official example
|
@ -5,6 +5,9 @@
|
|||
*/build/*
|
||||
*/build_mingw/*
|
||||
|
||||
# Qt Build Directory
|
||||
build*
|
||||
|
||||
#Visual Studio Build Directory
|
||||
*/Debug/*
|
||||
*/Release/*
|
||||
|
|
|
@ -172,12 +172,12 @@ void Drawing::drag_begin(double x, double y)
|
|||
void Drawing::drag_progress(double x, double y)
|
||||
{
|
||||
// Progress and end
|
||||
draw_brush(x + start_x, y + start_y);
|
||||
draw_brush(x + start_x, y + start_y, DrawProcess::Update);
|
||||
}
|
||||
|
||||
void Drawing::drag_end(double x, double y){
|
||||
// Progress and end
|
||||
draw_brush(x + start_x, y + start_y);
|
||||
draw_brush(x + start_x, y + start_y, DrawProcess::End);
|
||||
}
|
||||
|
||||
void Drawing::color_set()
|
||||
|
|
|
@ -0,0 +1,92 @@
|
|||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of the examples of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:BSD$
|
||||
** 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 The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** BSD License Usage
|
||||
** Alternatively, 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 The Qt Company Ltd 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 "browser.h"
|
||||
#include "browserwindow.h"
|
||||
|
||||
Browser::Browser()
|
||||
{
|
||||
// Quit application if the download manager window is the only remaining window
|
||||
m_downloadManagerWidget.setAttribute(Qt::WA_QuitOnClose, false);
|
||||
|
||||
QObject::connect(
|
||||
QWebEngineProfile::defaultProfile(), &QWebEngineProfile::downloadRequested,
|
||||
&m_downloadManagerWidget, &DownloadManagerWidget::downloadRequested);
|
||||
}
|
||||
|
||||
BrowserWindow *Browser::createWindow(bool offTheRecord)
|
||||
{
|
||||
if (offTheRecord && !m_otrProfile) {
|
||||
m_otrProfile.reset(new QWebEngineProfile);
|
||||
QObject::connect(
|
||||
m_otrProfile.get(), &QWebEngineProfile::downloadRequested,
|
||||
&m_downloadManagerWidget, &DownloadManagerWidget::downloadRequested);
|
||||
}
|
||||
auto profile = offTheRecord ? m_otrProfile.get() : QWebEngineProfile::defaultProfile();
|
||||
auto mainWindow = new BrowserWindow(this, profile, false);
|
||||
m_windows.append(mainWindow);
|
||||
QObject::connect(mainWindow, &QObject::destroyed, [this, mainWindow]() {
|
||||
m_windows.removeOne(mainWindow);
|
||||
});
|
||||
mainWindow->show();
|
||||
return mainWindow;
|
||||
}
|
||||
|
||||
BrowserWindow *Browser::createDevToolsWindow()
|
||||
{
|
||||
auto profile = QWebEngineProfile::defaultProfile();
|
||||
auto mainWindow = new BrowserWindow(this, profile, true);
|
||||
m_windows.append(mainWindow);
|
||||
QObject::connect(mainWindow, &QObject::destroyed, [this, mainWindow]() {
|
||||
m_windows.removeOne(mainWindow);
|
||||
});
|
||||
mainWindow->show();
|
||||
return mainWindow;
|
||||
}
|
|
@ -0,0 +1,78 @@
|
|||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of the examples of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:BSD$
|
||||
** 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 The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** BSD License Usage
|
||||
** Alternatively, 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 The Qt Company Ltd 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$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef BROWSER_H
|
||||
#define BROWSER_H
|
||||
|
||||
#include "downloadmanagerwidget.h"
|
||||
|
||||
#include <QVector>
|
||||
#include <QWebEngineProfile>
|
||||
|
||||
class BrowserWindow;
|
||||
|
||||
class Browser
|
||||
{
|
||||
public:
|
||||
Browser();
|
||||
|
||||
QVector<BrowserWindow*> windows() { return m_windows; }
|
||||
|
||||
BrowserWindow *createWindow(bool offTheRecord = false);
|
||||
BrowserWindow *createDevToolsWindow();
|
||||
|
||||
DownloadManagerWidget &downloadManagerWidget() { return m_downloadManagerWidget; }
|
||||
|
||||
private:
|
||||
QVector<BrowserWindow*> m_windows;
|
||||
DownloadManagerWidget m_downloadManagerWidget;
|
||||
QScopedPointer<QWebEngineProfile> m_otrProfile;
|
||||
};
|
||||
#endif // BROWSER_H
|
|
@ -0,0 +1,551 @@
|
|||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of the examples of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:BSD$
|
||||
** 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 The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** BSD License Usage
|
||||
** Alternatively, 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 The Qt Company Ltd 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 "browser.h"
|
||||
#include "browserwindow.h"
|
||||
#include "downloadmanagerwidget.h"
|
||||
#include "tabwidget.h"
|
||||
#include "webview.h"
|
||||
#include <QApplication>
|
||||
#include <QCloseEvent>
|
||||
#include <QDesktopWidget>
|
||||
#include <QEvent>
|
||||
#include <QFileDialog>
|
||||
#include <QInputDialog>
|
||||
#include <QMenuBar>
|
||||
#include <QMessageBox>
|
||||
#include <QProgressBar>
|
||||
#include <QScreen>
|
||||
#include <QStatusBar>
|
||||
#include <QToolBar>
|
||||
#include <QVBoxLayout>
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
|
||||
#include <QWebEngineFindTextResult>
|
||||
#endif
|
||||
#include <QWebEngineProfile>
|
||||
|
||||
BrowserWindow::BrowserWindow(Browser *browser, QWebEngineProfile *profile, bool forDevTools)
|
||||
: m_browser(browser)
|
||||
, m_profile(profile)
|
||||
, m_tabWidget(new TabWidget(profile, this))
|
||||
, m_progressBar(nullptr)
|
||||
, m_historyBackAction(nullptr)
|
||||
, m_historyForwardAction(nullptr)
|
||||
, m_stopAction(nullptr)
|
||||
, m_reloadAction(nullptr)
|
||||
, m_stopReloadAction(nullptr)
|
||||
, m_urlLineEdit(nullptr)
|
||||
, m_favAction(nullptr)
|
||||
{
|
||||
setAttribute(Qt::WA_DeleteOnClose, true);
|
||||
setFocusPolicy(Qt::ClickFocus);
|
||||
|
||||
if (!forDevTools) {
|
||||
m_progressBar = new QProgressBar(this);
|
||||
|
||||
QToolBar *toolbar = createToolBar();
|
||||
addToolBar(toolbar);
|
||||
menuBar()->addMenu(createFileMenu(m_tabWidget));
|
||||
menuBar()->addMenu(createEditMenu());
|
||||
menuBar()->addMenu(createViewMenu(toolbar));
|
||||
menuBar()->addMenu(createWindowMenu(m_tabWidget));
|
||||
menuBar()->addMenu(createHelpMenu());
|
||||
}
|
||||
|
||||
QWidget *centralWidget = new QWidget(this);
|
||||
QVBoxLayout *layout = new QVBoxLayout;
|
||||
layout->setSpacing(0);
|
||||
layout->setContentsMargins(0, 0, 0, 0);
|
||||
if (!forDevTools) {
|
||||
addToolBarBreak();
|
||||
|
||||
m_progressBar->setMaximumHeight(1);
|
||||
m_progressBar->setTextVisible(false);
|
||||
m_progressBar->setStyleSheet(QStringLiteral("QProgressBar {border: 0px} QProgressBar::chunk {background-color: #da4453}"));
|
||||
|
||||
layout->addWidget(m_progressBar);
|
||||
}
|
||||
|
||||
layout->addWidget(m_tabWidget);
|
||||
centralWidget->setLayout(layout);
|
||||
setCentralWidget(centralWidget);
|
||||
|
||||
connect(m_tabWidget, &TabWidget::titleChanged, this, &BrowserWindow::handleWebViewTitleChanged);
|
||||
if (!forDevTools) {
|
||||
connect(m_tabWidget, &TabWidget::linkHovered, [this](const QString& url) {
|
||||
statusBar()->showMessage(url);
|
||||
});
|
||||
connect(m_tabWidget, &TabWidget::loadProgress, this, &BrowserWindow::handleWebViewLoadProgress);
|
||||
connect(m_tabWidget, &TabWidget::webActionEnabledChanged, this, &BrowserWindow::handleWebActionEnabledChanged);
|
||||
connect(m_tabWidget, &TabWidget::urlChanged, [this](const QUrl &url) {
|
||||
m_urlLineEdit->setText(url.toDisplayString());
|
||||
});
|
||||
connect(m_tabWidget, &TabWidget::favIconChanged, m_favAction, &QAction::setIcon);
|
||||
connect(m_tabWidget, &TabWidget::devToolsRequested, this, &BrowserWindow::handleDevToolsRequested);
|
||||
connect(m_urlLineEdit, &QLineEdit::returnPressed, [this]() {
|
||||
m_tabWidget->setUrl(QUrl::fromUserInput(m_urlLineEdit->text()));
|
||||
});
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
|
||||
connect(m_tabWidget, &TabWidget::findTextFinished, this, &BrowserWindow::handleFindTextFinished);
|
||||
#endif
|
||||
|
||||
QAction *focusUrlLineEditAction = new QAction(this);
|
||||
addAction(focusUrlLineEditAction);
|
||||
focusUrlLineEditAction->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_L));
|
||||
connect(focusUrlLineEditAction, &QAction::triggered, this, [this] () {
|
||||
m_urlLineEdit->setFocus(Qt::ShortcutFocusReason);
|
||||
});
|
||||
}
|
||||
|
||||
handleWebViewTitleChanged(QString());
|
||||
m_tabWidget->createTab();
|
||||
}
|
||||
|
||||
QSize BrowserWindow::sizeHint() const
|
||||
{
|
||||
QRect desktopRect = QApplication::primaryScreen()->geometry();
|
||||
QSize size = desktopRect.size() * qreal(0.9);
|
||||
return size;
|
||||
}
|
||||
|
||||
QMenu *BrowserWindow::createFileMenu(TabWidget *tabWidget)
|
||||
{
|
||||
QMenu *fileMenu = new QMenu(tr("&File"));
|
||||
fileMenu->addAction(tr("&New Window"), this, &BrowserWindow::handleNewWindowTriggered, QKeySequence::New);
|
||||
fileMenu->addAction(tr("New &Incognito Window"), this, &BrowserWindow::handleNewIncognitoWindowTriggered);
|
||||
|
||||
QAction *newTabAction = new QAction(tr("New &Tab"), this);
|
||||
newTabAction->setShortcuts(QKeySequence::AddTab);
|
||||
connect(newTabAction, &QAction::triggered, this, [this]() {
|
||||
m_tabWidget->createTab();
|
||||
m_urlLineEdit->setFocus();
|
||||
});
|
||||
fileMenu->addAction(newTabAction);
|
||||
|
||||
fileMenu->addAction(tr("&Open File..."), this, &BrowserWindow::handleFileOpenTriggered, QKeySequence::Open);
|
||||
fileMenu->addSeparator();
|
||||
|
||||
QAction *closeTabAction = new QAction(tr("&Close Tab"), this);
|
||||
closeTabAction->setShortcuts(QKeySequence::Close);
|
||||
connect(closeTabAction, &QAction::triggered, [tabWidget]() {
|
||||
tabWidget->closeTab(tabWidget->currentIndex());
|
||||
});
|
||||
fileMenu->addAction(closeTabAction);
|
||||
|
||||
QAction *closeAction = new QAction(tr("&Quit"),this);
|
||||
closeAction->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_Q));
|
||||
connect(closeAction, &QAction::triggered, this, &QWidget::close);
|
||||
fileMenu->addAction(closeAction);
|
||||
|
||||
connect(fileMenu, &QMenu::aboutToShow, [this, closeAction]() {
|
||||
if (m_browser->windows().count() == 1)
|
||||
closeAction->setText(tr("&Quit"));
|
||||
else
|
||||
closeAction->setText(tr("&Close Window"));
|
||||
});
|
||||
return fileMenu;
|
||||
}
|
||||
|
||||
QMenu *BrowserWindow::createEditMenu()
|
||||
{
|
||||
QMenu *editMenu = new QMenu(tr("&Edit"));
|
||||
QAction *findAction = editMenu->addAction(tr("&Find"));
|
||||
findAction->setShortcuts(QKeySequence::Find);
|
||||
connect(findAction, &QAction::triggered, this, &BrowserWindow::handleFindActionTriggered);
|
||||
|
||||
QAction *findNextAction = editMenu->addAction(tr("Find &Next"));
|
||||
findNextAction->setShortcut(QKeySequence::FindNext);
|
||||
connect(findNextAction, &QAction::triggered, [this]() {
|
||||
if (!currentTab() || m_lastSearch.isEmpty())
|
||||
return;
|
||||
currentTab()->findText(m_lastSearch);
|
||||
});
|
||||
|
||||
QAction *findPreviousAction = editMenu->addAction(tr("Find &Previous"));
|
||||
findPreviousAction->setShortcut(QKeySequence::FindPrevious);
|
||||
connect(findPreviousAction, &QAction::triggered, [this]() {
|
||||
if (!currentTab() || m_lastSearch.isEmpty())
|
||||
return;
|
||||
currentTab()->findText(m_lastSearch, QWebEnginePage::FindBackward);
|
||||
});
|
||||
|
||||
return editMenu;
|
||||
}
|
||||
|
||||
QMenu *BrowserWindow::createViewMenu(QToolBar *toolbar)
|
||||
{
|
||||
QMenu *viewMenu = new QMenu(tr("&View"));
|
||||
m_stopAction = viewMenu->addAction(tr("&Stop"));
|
||||
QList<QKeySequence> shortcuts;
|
||||
shortcuts.append(QKeySequence(Qt::CTRL | Qt::Key_Period));
|
||||
shortcuts.append(Qt::Key_Escape);
|
||||
m_stopAction->setShortcuts(shortcuts);
|
||||
connect(m_stopAction, &QAction::triggered, [this]() {
|
||||
m_tabWidget->triggerWebPageAction(QWebEnginePage::Stop);
|
||||
});
|
||||
|
||||
m_reloadAction = viewMenu->addAction(tr("Reload Page"));
|
||||
m_reloadAction->setShortcuts(QKeySequence::Refresh);
|
||||
connect(m_reloadAction, &QAction::triggered, [this]() {
|
||||
m_tabWidget->triggerWebPageAction(QWebEnginePage::Reload);
|
||||
});
|
||||
|
||||
QAction *zoomIn = viewMenu->addAction(tr("Zoom &In"));
|
||||
zoomIn->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_Plus));
|
||||
connect(zoomIn, &QAction::triggered, [this]() {
|
||||
if (currentTab())
|
||||
currentTab()->setZoomFactor(currentTab()->zoomFactor() + 0.1);
|
||||
});
|
||||
|
||||
QAction *zoomOut = viewMenu->addAction(tr("Zoom &Out"));
|
||||
zoomOut->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_Minus));
|
||||
connect(zoomOut, &QAction::triggered, [this]() {
|
||||
if (currentTab())
|
||||
currentTab()->setZoomFactor(currentTab()->zoomFactor() - 0.1);
|
||||
});
|
||||
|
||||
QAction *resetZoom = viewMenu->addAction(tr("Reset &Zoom"));
|
||||
resetZoom->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_0));
|
||||
connect(resetZoom, &QAction::triggered, [this]() {
|
||||
if (currentTab())
|
||||
currentTab()->setZoomFactor(1.0);
|
||||
});
|
||||
|
||||
|
||||
viewMenu->addSeparator();
|
||||
QAction *viewToolbarAction = new QAction(tr("Hide Toolbar"),this);
|
||||
viewToolbarAction->setShortcut(tr("Ctrl+|"));
|
||||
connect(viewToolbarAction, &QAction::triggered, [toolbar,viewToolbarAction]() {
|
||||
if (toolbar->isVisible()) {
|
||||
viewToolbarAction->setText(tr("Show Toolbar"));
|
||||
toolbar->close();
|
||||
} else {
|
||||
viewToolbarAction->setText(tr("Hide Toolbar"));
|
||||
toolbar->show();
|
||||
}
|
||||
});
|
||||
viewMenu->addAction(viewToolbarAction);
|
||||
|
||||
QAction *viewStatusbarAction = new QAction(tr("Hide Status Bar"), this);
|
||||
viewStatusbarAction->setShortcut(tr("Ctrl+/"));
|
||||
connect(viewStatusbarAction, &QAction::triggered, [this, viewStatusbarAction]() {
|
||||
if (statusBar()->isVisible()) {
|
||||
viewStatusbarAction->setText(tr("Show Status Bar"));
|
||||
statusBar()->close();
|
||||
} else {
|
||||
viewStatusbarAction->setText(tr("Hide Status Bar"));
|
||||
statusBar()->show();
|
||||
}
|
||||
});
|
||||
viewMenu->addAction(viewStatusbarAction);
|
||||
return viewMenu;
|
||||
}
|
||||
|
||||
QMenu *BrowserWindow::createWindowMenu(TabWidget *tabWidget)
|
||||
{
|
||||
QMenu *menu = new QMenu(tr("&Window"));
|
||||
|
||||
QAction *nextTabAction = new QAction(tr("Show Next Tab"), this);
|
||||
QList<QKeySequence> shortcuts;
|
||||
shortcuts.append(QKeySequence(Qt::CTRL | Qt::Key_BraceRight));
|
||||
shortcuts.append(QKeySequence(Qt::CTRL | Qt::Key_PageDown));
|
||||
shortcuts.append(QKeySequence(Qt::CTRL | Qt::Key_BracketRight));
|
||||
shortcuts.append(QKeySequence(Qt::CTRL | Qt::Key_Less));
|
||||
nextTabAction->setShortcuts(shortcuts);
|
||||
connect(nextTabAction, &QAction::triggered, tabWidget, &TabWidget::nextTab);
|
||||
|
||||
QAction *previousTabAction = new QAction(tr("Show Previous Tab"), this);
|
||||
shortcuts.clear();
|
||||
shortcuts.append(QKeySequence(Qt::CTRL | Qt::Key_BraceLeft));
|
||||
shortcuts.append(QKeySequence(Qt::CTRL | Qt::Key_PageUp));
|
||||
shortcuts.append(QKeySequence(Qt::CTRL | Qt::Key_BracketLeft));
|
||||
shortcuts.append(QKeySequence(Qt::CTRL | Qt::Key_Greater));
|
||||
previousTabAction->setShortcuts(shortcuts);
|
||||
connect(previousTabAction, &QAction::triggered, tabWidget, &TabWidget::previousTab);
|
||||
|
||||
connect(menu, &QMenu::aboutToShow, [this, menu, nextTabAction, previousTabAction]() {
|
||||
menu->clear();
|
||||
menu->addAction(nextTabAction);
|
||||
menu->addAction(previousTabAction);
|
||||
menu->addSeparator();
|
||||
|
||||
QVector<BrowserWindow*> windows = m_browser->windows();
|
||||
int index(-1);
|
||||
for (auto window : windows) {
|
||||
QAction *action = menu->addAction(window->windowTitle(), this, &BrowserWindow::handleShowWindowTriggered);
|
||||
action->setData(++index);
|
||||
action->setCheckable(true);
|
||||
if (window == this)
|
||||
action->setChecked(true);
|
||||
}
|
||||
});
|
||||
return menu;
|
||||
}
|
||||
|
||||
QMenu *BrowserWindow::createHelpMenu()
|
||||
{
|
||||
QMenu *helpMenu = new QMenu(tr("&Help"));
|
||||
helpMenu->addAction(tr("About &Qt"), qApp, QApplication::aboutQt);
|
||||
return helpMenu;
|
||||
}
|
||||
|
||||
QToolBar *BrowserWindow::createToolBar()
|
||||
{
|
||||
QToolBar *navigationBar = new QToolBar(tr("Navigation"));
|
||||
navigationBar->setMovable(false);
|
||||
navigationBar->toggleViewAction()->setEnabled(false);
|
||||
|
||||
m_historyBackAction = new QAction(this);
|
||||
QList<QKeySequence> backShortcuts = QKeySequence::keyBindings(QKeySequence::Back);
|
||||
for (auto it = backShortcuts.begin(); it != backShortcuts.end();) {
|
||||
// Chromium already handles navigate on backspace when appropriate.
|
||||
if ((*it)[0] == Qt::Key_Backspace)
|
||||
it = backShortcuts.erase(it);
|
||||
else
|
||||
++it;
|
||||
}
|
||||
// For some reason Qt doesn't bind the dedicated Back key to Back.
|
||||
backShortcuts.append(QKeySequence(Qt::Key_Back));
|
||||
m_historyBackAction->setShortcuts(backShortcuts);
|
||||
m_historyBackAction->setIconVisibleInMenu(false);
|
||||
m_historyBackAction->setIcon(QIcon(QStringLiteral(":go-previous.png")));
|
||||
m_historyBackAction->setToolTip(tr("Go back in history"));
|
||||
connect(m_historyBackAction, &QAction::triggered, [this]() {
|
||||
m_tabWidget->triggerWebPageAction(QWebEnginePage::Back);
|
||||
});
|
||||
navigationBar->addAction(m_historyBackAction);
|
||||
|
||||
m_historyForwardAction = new QAction(this);
|
||||
QList<QKeySequence> fwdShortcuts = QKeySequence::keyBindings(QKeySequence::Forward);
|
||||
for (auto it = fwdShortcuts.begin(); it != fwdShortcuts.end();) {
|
||||
if (((*it)[0] & Qt::Key_unknown) == Qt::Key_Backspace)
|
||||
it = fwdShortcuts.erase(it);
|
||||
else
|
||||
++it;
|
||||
}
|
||||
fwdShortcuts.append(QKeySequence(Qt::Key_Forward));
|
||||
m_historyForwardAction->setShortcuts(fwdShortcuts);
|
||||
m_historyForwardAction->setIconVisibleInMenu(false);
|
||||
m_historyForwardAction->setIcon(QIcon(QStringLiteral(":go-next.png")));
|
||||
m_historyForwardAction->setToolTip(tr("Go forward in history"));
|
||||
connect(m_historyForwardAction, &QAction::triggered, [this]() {
|
||||
m_tabWidget->triggerWebPageAction(QWebEnginePage::Forward);
|
||||
});
|
||||
navigationBar->addAction(m_historyForwardAction);
|
||||
|
||||
m_stopReloadAction = new QAction(this);
|
||||
connect(m_stopReloadAction, &QAction::triggered, [this]() {
|
||||
m_tabWidget->triggerWebPageAction(QWebEnginePage::WebAction(m_stopReloadAction->data().toInt()));
|
||||
});
|
||||
navigationBar->addAction(m_stopReloadAction);
|
||||
|
||||
m_urlLineEdit = new QLineEdit(this);
|
||||
m_favAction = new QAction(this);
|
||||
m_urlLineEdit->addAction(m_favAction, QLineEdit::LeadingPosition);
|
||||
m_urlLineEdit->setClearButtonEnabled(true);
|
||||
navigationBar->addWidget(m_urlLineEdit);
|
||||
|
||||
auto downloadsAction = new QAction(this);
|
||||
downloadsAction->setIcon(QIcon(QStringLiteral(":go-bottom.png")));
|
||||
downloadsAction->setToolTip(tr("Show downloads"));
|
||||
navigationBar->addAction(downloadsAction);
|
||||
connect(downloadsAction, &QAction::triggered, [this]() {
|
||||
m_browser->downloadManagerWidget().show();
|
||||
});
|
||||
|
||||
return navigationBar;
|
||||
}
|
||||
|
||||
void BrowserWindow::handleWebActionEnabledChanged(QWebEnginePage::WebAction action, bool enabled)
|
||||
{
|
||||
switch (action) {
|
||||
case QWebEnginePage::Back:
|
||||
m_historyBackAction->setEnabled(enabled);
|
||||
break;
|
||||
case QWebEnginePage::Forward:
|
||||
m_historyForwardAction->setEnabled(enabled);
|
||||
break;
|
||||
case QWebEnginePage::Reload:
|
||||
m_reloadAction->setEnabled(enabled);
|
||||
break;
|
||||
case QWebEnginePage::Stop:
|
||||
m_stopAction->setEnabled(enabled);
|
||||
break;
|
||||
default:
|
||||
qWarning("Unhandled webActionChanged signal");
|
||||
}
|
||||
}
|
||||
|
||||
void BrowserWindow::handleWebViewTitleChanged(const QString &title)
|
||||
{
|
||||
QString suffix = m_profile->isOffTheRecord()
|
||||
? tr("Qt Simple Browser (Incognito)")
|
||||
: tr("Qt Simple Browser");
|
||||
|
||||
if (title.isEmpty())
|
||||
setWindowTitle(suffix);
|
||||
else
|
||||
setWindowTitle(title + " - " + suffix);
|
||||
}
|
||||
|
||||
void BrowserWindow::handleNewWindowTriggered()
|
||||
{
|
||||
BrowserWindow *window = m_browser->createWindow();
|
||||
window->m_urlLineEdit->setFocus();
|
||||
}
|
||||
|
||||
void BrowserWindow::handleNewIncognitoWindowTriggered()
|
||||
{
|
||||
BrowserWindow *window = m_browser->createWindow(/* offTheRecord: */ true);
|
||||
window->m_urlLineEdit->setFocus();
|
||||
}
|
||||
|
||||
void BrowserWindow::handleFileOpenTriggered()
|
||||
{
|
||||
QUrl url = QFileDialog::getOpenFileUrl(this, tr("Open Web Resource"), QString(),
|
||||
tr("Web Resources (*.html *.htm *.svg *.png *.gif *.svgz);;All files (*.*)"));
|
||||
if (url.isEmpty())
|
||||
return;
|
||||
currentTab()->setUrl(url);
|
||||
}
|
||||
|
||||
void BrowserWindow::handleFindActionTriggered()
|
||||
{
|
||||
if (!currentTab())
|
||||
return;
|
||||
bool ok = false;
|
||||
QString search = QInputDialog::getText(this, tr("Find"),
|
||||
tr("Find:"), QLineEdit::Normal,
|
||||
m_lastSearch, &ok);
|
||||
if (ok && !search.isEmpty()) {
|
||||
m_lastSearch = search;
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
|
||||
currentTab()->findText(m_lastSearch);
|
||||
#else
|
||||
currentTab()->findText(m_lastSearch, 0, [this](bool found) {
|
||||
if (!found)
|
||||
statusBar()->showMessage(tr("\"%1\" not found.").arg(m_lastSearch));
|
||||
});
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void BrowserWindow::closeEvent(QCloseEvent *event)
|
||||
{
|
||||
if (m_tabWidget->count() > 1) {
|
||||
int ret = QMessageBox::warning(this, tr("Confirm close"),
|
||||
tr("Are you sure you want to close the window ?\n"
|
||||
"There are %1 tabs open.").arg(m_tabWidget->count()),
|
||||
QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
|
||||
if (ret == QMessageBox::No) {
|
||||
event->ignore();
|
||||
return;
|
||||
}
|
||||
}
|
||||
event->accept();
|
||||
deleteLater();
|
||||
}
|
||||
|
||||
TabWidget *BrowserWindow::tabWidget() const
|
||||
{
|
||||
return m_tabWidget;
|
||||
}
|
||||
|
||||
WebView *BrowserWindow::currentTab() const
|
||||
{
|
||||
return m_tabWidget->currentWebView();
|
||||
}
|
||||
|
||||
void BrowserWindow::handleWebViewLoadProgress(int progress)
|
||||
{
|
||||
static QIcon stopIcon(QStringLiteral(":process-stop.png"));
|
||||
static QIcon reloadIcon(QStringLiteral(":view-refresh.png"));
|
||||
|
||||
if (0 < progress && progress < 100) {
|
||||
m_stopReloadAction->setData(QWebEnginePage::Stop);
|
||||
m_stopReloadAction->setIcon(stopIcon);
|
||||
m_stopReloadAction->setToolTip(tr("Stop loading the current page"));
|
||||
m_progressBar->setValue(progress);
|
||||
} else {
|
||||
m_stopReloadAction->setData(QWebEnginePage::Reload);
|
||||
m_stopReloadAction->setIcon(reloadIcon);
|
||||
m_stopReloadAction->setToolTip(tr("Reload the current page"));
|
||||
m_progressBar->setValue(0);
|
||||
}
|
||||
}
|
||||
|
||||
void BrowserWindow::handleShowWindowTriggered()
|
||||
{
|
||||
if (QAction *action = qobject_cast<QAction*>(sender())) {
|
||||
int offset = action->data().toInt();
|
||||
QVector<BrowserWindow*> windows = m_browser->windows();
|
||||
windows.at(offset)->activateWindow();
|
||||
windows.at(offset)->currentTab()->setFocus();
|
||||
}
|
||||
}
|
||||
|
||||
void BrowserWindow::handleDevToolsRequested(QWebEnginePage *source)
|
||||
{
|
||||
source->setDevToolsPage(m_browser->createDevToolsWindow()->currentTab()->page());
|
||||
source->triggerAction(QWebEnginePage::InspectElement);
|
||||
}
|
||||
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
|
||||
void BrowserWindow::handleFindTextFinished(const QWebEngineFindTextResult &result)
|
||||
{
|
||||
if (result.numberOfMatches() == 0) {
|
||||
statusBar()->showMessage(tr("\"%1\" not found.").arg(m_lastSearch));
|
||||
} else {
|
||||
statusBar()->showMessage(tr("\"%1\" found: %2/%3").arg(m_lastSearch,
|
||||
QString::number(result.activeMatch()),
|
||||
QString::number(result.numberOfMatches())));
|
||||
}
|
||||
}
|
||||
#endif
|
|
@ -0,0 +1,118 @@
|
|||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of the examples of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:BSD$
|
||||
** 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 The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** BSD License Usage
|
||||
** Alternatively, 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 The Qt Company Ltd 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$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef BROWSERWINDOW_H
|
||||
#define BROWSERWINDOW_H
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QTime>
|
||||
#include <QWebEnginePage>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QLineEdit;
|
||||
class QProgressBar;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
class Browser;
|
||||
class TabWidget;
|
||||
class WebView;
|
||||
|
||||
class BrowserWindow : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
BrowserWindow(Browser *browser, QWebEngineProfile *profile, bool forDevTools = false);
|
||||
QSize sizeHint() const override;
|
||||
TabWidget *tabWidget() const;
|
||||
WebView *currentTab() const;
|
||||
Browser *browser() { return m_browser; }
|
||||
|
||||
protected:
|
||||
void closeEvent(QCloseEvent *event) override;
|
||||
|
||||
private slots:
|
||||
void handleNewWindowTriggered();
|
||||
void handleNewIncognitoWindowTriggered();
|
||||
void handleFileOpenTriggered();
|
||||
void handleFindActionTriggered();
|
||||
void handleShowWindowTriggered();
|
||||
void handleWebViewLoadProgress(int);
|
||||
void handleWebViewTitleChanged(const QString &title);
|
||||
void handleWebActionEnabledChanged(QWebEnginePage::WebAction action, bool enabled);
|
||||
void handleDevToolsRequested(QWebEnginePage *source);
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
|
||||
void handleFindTextFinished(const QWebEngineFindTextResult &result);
|
||||
#endif
|
||||
|
||||
private:
|
||||
QMenu *createFileMenu(TabWidget *tabWidget);
|
||||
QMenu *createEditMenu();
|
||||
QMenu *createViewMenu(QToolBar *toolBar);
|
||||
QMenu *createWindowMenu(TabWidget *tabWidget);
|
||||
QMenu *createHelpMenu();
|
||||
QToolBar *createToolBar();
|
||||
|
||||
private:
|
||||
Browser *m_browser;
|
||||
QWebEngineProfile *m_profile;
|
||||
TabWidget *m_tabWidget;
|
||||
QProgressBar *m_progressBar;
|
||||
QAction *m_historyBackAction;
|
||||
QAction *m_historyForwardAction;
|
||||
QAction *m_stopAction;
|
||||
QAction *m_reloadAction;
|
||||
QAction *m_stopReloadAction;
|
||||
QLineEdit *m_urlLineEdit;
|
||||
QAction *m_favAction;
|
||||
QString m_lastSearch;
|
||||
};
|
||||
|
||||
#endif // BROWSERWINDOW_H
|
|
@ -0,0 +1,133 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>CertificateErrorDialog</class>
|
||||
<widget class="QDialog" name="CertificateErrorDialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>370</width>
|
||||
<height>141</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Dialog</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<property name="leftMargin">
|
||||
<number>20</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>20</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="m_iconLabel">
|
||||
<property name="text">
|
||||
<string>Icon</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="m_errorLabel">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Error</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="m_infoLabel">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>If you wish so, you may continue with an unverified certificate. Accepting an unverified certificate mean you may not be connected with the host you tried to connect to.
|
||||
|
||||
Do you wish to override the security check and continue ? </string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>16</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::No|QDialogButtonBox::Yes</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>CertificateErrorDialog</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>CertificateErrorDialog</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
|
@ -0,0 +1 @@
|
|||
The icons in this repository are herefore released into the Public Domain.
|
After Width: | Height: | Size: 1.6 KiB |
After Width: | Height: | Size: 1.6 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 1.9 KiB |
|
@ -0,0 +1,24 @@
|
|||
{
|
||||
"Id": "simplebrowser-tango",
|
||||
"Name": "Tango Icon Library",
|
||||
"QDocModule": "qtwebengine",
|
||||
"QtUsage": "Used in WebEngine SimpleBrowser example.",
|
||||
|
||||
"QtParts": [ "examples" ],
|
||||
"Description": "Selected icons from the Tango Icon Library",
|
||||
"Homepage": "http://tango.freedesktop.org/Tango_Icon_Library",
|
||||
"Version": "0.8.90",
|
||||
"DownloadLocation": "http://tango.freedesktop.org/releases/tango-icon-theme-0.8.90.tar.gz",
|
||||
"LicenseId": "DocumentRef-PublicDomain",
|
||||
"License": "Public Domain",
|
||||
"LicenseFile": "COPYING",
|
||||
"Copyright": "Ulisse Perusin <uli.peru@gmail.com>
|
||||
Steven Garrity <sgarrity@silverorange.com>
|
||||
Lapo Calamandrei <calamandrei@gmail.com>
|
||||
Ryan Collier <rcollier@novell.com>
|
||||
Rodney Dawes <dobey@novell.com>
|
||||
Andreas Nilsson <nisses.mail@home.se>
|
||||
Tuomas Kuosmanen <tigert@tigert.com>
|
||||
Garrett LeSage <garrett@novell.com>
|
||||
Jakub Steiner <jimmac@novell.com>"
|
||||
}
|
After Width: | Height: | Size: 1.7 KiB |
After Width: | Height: | Size: 2.0 KiB |
After Width: | Height: | Size: 6.0 KiB |
After Width: | Height: | Size: 1.6 KiB |
|
@ -0,0 +1,16 @@
|
|||
<RCC>
|
||||
<qresource prefix="/">
|
||||
<file>AppLogoColor.png</file>
|
||||
<file>ninja.png</file>
|
||||
</qresource>
|
||||
<qresource prefix="/">
|
||||
<file alias="dialog-error.png">3rdparty/dialog-error.png</file>
|
||||
<file alias="edit-clear.png">3rdparty/edit-clear.png</file>
|
||||
<file alias="go-bottom.png">3rdparty/go-bottom.png</file>
|
||||
<file alias="go-next.png">3rdparty/go-next.png</file>
|
||||
<file alias="go-previous.png">3rdparty/go-previous.png</file>
|
||||
<file alias="process-stop.png">3rdparty/process-stop.png</file>
|
||||
<file alias="text-html.png">3rdparty/text-html.png</file>
|
||||
<file alias="view-refresh.png">3rdparty/view-refresh.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
After Width: | Height: | Size: 10 KiB |
After Width: | Height: | Size: 46 KiB |
|
@ -0,0 +1,938 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<qmt>
|
||||
<project>
|
||||
<uid>{fa2cc127-337e-4194-b272-fc8bb6c1e3b0}</uid>
|
||||
<root-package>
|
||||
<instance>
|
||||
<MPackage>
|
||||
<base-MObject>
|
||||
<MObject>
|
||||
<base-MElement>
|
||||
<MElement>
|
||||
<uid>{4ffa8932-4330-4845-af33-c26f0fcdecd7}</uid>
|
||||
</MElement>
|
||||
</base-MElement>
|
||||
<name>simplebrowser-model</name>
|
||||
<children>
|
||||
<handles>
|
||||
<handles>
|
||||
<qlist>
|
||||
<item>
|
||||
<handle>
|
||||
<uid>{de670101-4064-4a81-bdf0-885b4cb09526}</uid>
|
||||
<target>
|
||||
<instance type="MCanvasDiagram">
|
||||
<MCanvasDiagram>
|
||||
<base-MDiagram>
|
||||
<MDiagram>
|
||||
<base-MObject>
|
||||
<MObject>
|
||||
<base-MElement>
|
||||
<MElement>
|
||||
<uid>{de670101-4064-4a81-bdf0-885b4cb09526}</uid>
|
||||
</MElement>
|
||||
</base-MElement>
|
||||
<name>simplebrowser-model</name>
|
||||
</MObject>
|
||||
</base-MObject>
|
||||
<elements>
|
||||
<qlist>
|
||||
<item>
|
||||
<instance type="DClass">
|
||||
<DClass>
|
||||
<base-DObject>
|
||||
<DObject>
|
||||
<base-DElement>
|
||||
<DElement>
|
||||
<uid>{b7b131f9-5e56-484a-ba8b-c7a5fc34fb7b}</uid>
|
||||
</DElement>
|
||||
</base-DElement>
|
||||
<object>{ee93b67f-4caf-4d92-9303-f6c2582bf1b9}</object>
|
||||
<name>BrowserWindow</name>
|
||||
<pos>x:190;y:100</pos>
|
||||
<rect>x:-55;y:-30;w:110;h:60</rect>
|
||||
<auto-sized>false</auto-sized>
|
||||
<visual-role>0</visual-role>
|
||||
</DObject>
|
||||
</base-DObject>
|
||||
</DClass>
|
||||
</instance>
|
||||
</item>
|
||||
<item>
|
||||
<instance type="DClass">
|
||||
<DClass>
|
||||
<base-DObject>
|
||||
<DObject>
|
||||
<base-DElement>
|
||||
<DElement>
|
||||
<uid>{8d3e6a00-ffa6-497a-a5a2-f1ba13deee76}</uid>
|
||||
</DElement>
|
||||
</base-DElement>
|
||||
<object>{72a2b731-3aad-430f-a76c-f43dd9b36462}</object>
|
||||
<name>Browser</name>
|
||||
<pos>x:5;y:100</pos>
|
||||
<rect>x:-55;y:-30;w:110;h:60</rect>
|
||||
<auto-sized>false</auto-sized>
|
||||
<visual-role>0</visual-role>
|
||||
</DObject>
|
||||
</base-DObject>
|
||||
</DClass>
|
||||
</instance>
|
||||
</item>
|
||||
<item>
|
||||
<instance type="DAssociation">
|
||||
<DAssociation>
|
||||
<base-DRelation>
|
||||
<DRelation>
|
||||
<base-DElement>
|
||||
<DElement>
|
||||
<uid>{5ab59ef4-3509-4ea3-900e-20d1cea16af1}</uid>
|
||||
</DElement>
|
||||
</base-DElement>
|
||||
<object>{e878ee71-b5d1-4943-b081-466851b0f721}</object>
|
||||
<a>{8d3e6a00-ffa6-497a-a5a2-f1ba13deee76}</a>
|
||||
<b>{b7b131f9-5e56-484a-ba8b-c7a5fc34fb7b}</b>
|
||||
</DRelation>
|
||||
</base-DRelation>
|
||||
<a>
|
||||
<DAssociationEnd>
|
||||
<cradinality>1..*</cradinality>
|
||||
<kind>2</kind>
|
||||
</DAssociationEnd>
|
||||
</a>
|
||||
<b>
|
||||
<DAssociationEnd>
|
||||
<cradinality>1</cradinality>
|
||||
</DAssociationEnd>
|
||||
</b>
|
||||
</DAssociation>
|
||||
</instance>
|
||||
</item>
|
||||
<item>
|
||||
<instance type="DClass">
|
||||
<DClass>
|
||||
<base-DObject>
|
||||
<DObject>
|
||||
<base-DElement>
|
||||
<DElement>
|
||||
<uid>{487d395c-3f8b-422c-9568-d70a5d50a9d4}</uid>
|
||||
</DElement>
|
||||
</base-DElement>
|
||||
<object>{1ab2b778-127b-4661-ba2d-8f329f44d859}</object>
|
||||
<name>TabWidget</name>
|
||||
<pos>x:360;y:100</pos>
|
||||
<rect>x:-55;y:-30;w:110;h:60</rect>
|
||||
<auto-sized>false</auto-sized>
|
||||
<visual-role>0</visual-role>
|
||||
</DObject>
|
||||
</base-DObject>
|
||||
</DClass>
|
||||
</instance>
|
||||
</item>
|
||||
<item>
|
||||
<instance type="DAssociation">
|
||||
<DAssociation>
|
||||
<base-DRelation>
|
||||
<DRelation>
|
||||
<base-DElement>
|
||||
<DElement>
|
||||
<uid>{cc9dee75-9f9c-4599-acf8-35e14f75cd78}</uid>
|
||||
</DElement>
|
||||
</base-DElement>
|
||||
<object>{ee3a86b4-773d-4ea5-81c1-552501061629}</object>
|
||||
<a>{b7b131f9-5e56-484a-ba8b-c7a5fc34fb7b}</a>
|
||||
<b>{487d395c-3f8b-422c-9568-d70a5d50a9d4}</b>
|
||||
</DRelation>
|
||||
</base-DRelation>
|
||||
<a>
|
||||
<DAssociationEnd>
|
||||
<cradinality>1</cradinality>
|
||||
</DAssociationEnd>
|
||||
</a>
|
||||
<b>
|
||||
<DAssociationEnd>
|
||||
<cradinality>1</cradinality>
|
||||
</DAssociationEnd>
|
||||
</b>
|
||||
</DAssociation>
|
||||
</instance>
|
||||
</item>
|
||||
<item>
|
||||
<instance type="DClass">
|
||||
<DClass>
|
||||
<base-DObject>
|
||||
<DObject>
|
||||
<base-DElement>
|
||||
<DElement>
|
||||
<uid>{9d909ab7-02a8-4582-89cd-b31bb794bc40}</uid>
|
||||
</DElement>
|
||||
</base-DElement>
|
||||
<object>{b8a281e2-4ee3-42cd-bb3d-d075a54ad358}</object>
|
||||
<name>WebView</name>
|
||||
<pos>x:550;y:100</pos>
|
||||
<rect>x:-55;y:-30;w:110;h:60</rect>
|
||||
<auto-sized>false</auto-sized>
|
||||
<visual-role>0</visual-role>
|
||||
</DObject>
|
||||
</base-DObject>
|
||||
</DClass>
|
||||
</instance>
|
||||
</item>
|
||||
<item>
|
||||
<instance type="DAssociation">
|
||||
<DAssociation>
|
||||
<base-DRelation>
|
||||
<DRelation>
|
||||
<base-DElement>
|
||||
<DElement>
|
||||
<uid>{1e82e3ce-c835-4b7a-99ec-ae40e07f0185}</uid>
|
||||
</DElement>
|
||||
</base-DElement>
|
||||
<object>{97fd8235-200e-4448-b173-51add1df8edc}</object>
|
||||
<a>{487d395c-3f8b-422c-9568-d70a5d50a9d4}</a>
|
||||
<b>{9d909ab7-02a8-4582-89cd-b31bb794bc40}</b>
|
||||
</DRelation>
|
||||
</base-DRelation>
|
||||
<a>
|
||||
<DAssociationEnd>
|
||||
<cradinality>1..*</cradinality>
|
||||
<kind>2</kind>
|
||||
</DAssociationEnd>
|
||||
</a>
|
||||
<b>
|
||||
<DAssociationEnd>
|
||||
<cradinality>1</cradinality>
|
||||
</DAssociationEnd>
|
||||
</b>
|
||||
</DAssociation>
|
||||
</instance>
|
||||
</item>
|
||||
<item>
|
||||
<instance type="DClass">
|
||||
<DClass>
|
||||
<base-DObject>
|
||||
<DObject>
|
||||
<base-DElement>
|
||||
<DElement>
|
||||
<uid>{ed0a94cd-0abd-49f6-ac98-3da13fef9dff}</uid>
|
||||
</DElement>
|
||||
</base-DElement>
|
||||
<object>{320f3a48-12de-4bcb-b7f5-47b12c77dbee}</object>
|
||||
<name>WebPage</name>
|
||||
<pos>x:720;y:100</pos>
|
||||
<rect>x:-55;y:-30;w:110;h:60</rect>
|
||||
<auto-sized>false</auto-sized>
|
||||
<visual-role>0</visual-role>
|
||||
</DObject>
|
||||
</base-DObject>
|
||||
</DClass>
|
||||
</instance>
|
||||
</item>
|
||||
<item>
|
||||
<instance type="DAssociation">
|
||||
<DAssociation>
|
||||
<base-DRelation>
|
||||
<DRelation>
|
||||
<base-DElement>
|
||||
<DElement>
|
||||
<uid>{06ce5b46-b043-45b8-8718-0054d7baf939}</uid>
|
||||
</DElement>
|
||||
</base-DElement>
|
||||
<object>{772227ff-d0df-4ecd-97ea-89d1bd10a96f}</object>
|
||||
<a>{9d909ab7-02a8-4582-89cd-b31bb794bc40}</a>
|
||||
<b>{ed0a94cd-0abd-49f6-ac98-3da13fef9dff}</b>
|
||||
</DRelation>
|
||||
</base-DRelation>
|
||||
<a>
|
||||
<DAssociationEnd>
|
||||
<cradinality>1</cradinality>
|
||||
</DAssociationEnd>
|
||||
</a>
|
||||
<b>
|
||||
<DAssociationEnd>
|
||||
<cradinality>1</cradinality>
|
||||
</DAssociationEnd>
|
||||
</b>
|
||||
</DAssociation>
|
||||
</instance>
|
||||
</item>
|
||||
<item>
|
||||
<instance type="DClass">
|
||||
<DClass>
|
||||
<base-DObject>
|
||||
<DObject>
|
||||
<base-DElement>
|
||||
<DElement>
|
||||
<uid>{cb588414-35d6-482f-a9df-2dddb7d72af1}</uid>
|
||||
</DElement>
|
||||
</base-DElement>
|
||||
<object>{9b91aa7b-0fa3-4c78-9e8d-e1bfdfce9f7f}</object>
|
||||
<name>QWebEngineView</name>
|
||||
<pos>x:550;y:0</pos>
|
||||
<rect>x:-55;y:-30;w:110;h:60</rect>
|
||||
<auto-sized>false</auto-sized>
|
||||
<visual-role>0</visual-role>
|
||||
</DObject>
|
||||
</base-DObject>
|
||||
</DClass>
|
||||
</instance>
|
||||
</item>
|
||||
<item>
|
||||
<instance type="DClass">
|
||||
<DClass>
|
||||
<base-DObject>
|
||||
<DObject>
|
||||
<base-DElement>
|
||||
<DElement>
|
||||
<uid>{c9755d3b-0ed4-4821-95d3-64f4f4cdb458}</uid>
|
||||
</DElement>
|
||||
</base-DElement>
|
||||
<object>{6659de40-605d-4744-8654-73ae959dcb8a}</object>
|
||||
<name>QWebEnginePage</name>
|
||||
<pos>x:720;y:0</pos>
|
||||
<rect>x:-50;y:-30;w:100;h:60</rect>
|
||||
<visual-role>0</visual-role>
|
||||
</DObject>
|
||||
</base-DObject>
|
||||
</DClass>
|
||||
</instance>
|
||||
</item>
|
||||
<item>
|
||||
<instance type="DInheritance">
|
||||
<DInheritance>
|
||||
<base-DRelation>
|
||||
<DRelation>
|
||||
<base-DElement>
|
||||
<DElement>
|
||||
<uid>{6bdcd7e9-fa78-417d-9024-47796596e18d}</uid>
|
||||
</DElement>
|
||||
</base-DElement>
|
||||
<object>{1176aee6-be27-4b21-be22-33bca908a71e}</object>
|
||||
<a>{9d909ab7-02a8-4582-89cd-b31bb794bc40}</a>
|
||||
<b>{cb588414-35d6-482f-a9df-2dddb7d72af1}</b>
|
||||
</DRelation>
|
||||
</base-DRelation>
|
||||
</DInheritance>
|
||||
</instance>
|
||||
</item>
|
||||
<item>
|
||||
<instance type="DInheritance">
|
||||
<DInheritance>
|
||||
<base-DRelation>
|
||||
<DRelation>
|
||||
<base-DElement>
|
||||
<DElement>
|
||||
<uid>{30abce68-7fa1-4b0c-8620-9f96c7392be7}</uid>
|
||||
</DElement>
|
||||
</base-DElement>
|
||||
<object>{20788ccc-cab0-406b-8cf4-d8062570085e}</object>
|
||||
<a>{ed0a94cd-0abd-49f6-ac98-3da13fef9dff}</a>
|
||||
<b>{c9755d3b-0ed4-4821-95d3-64f4f4cdb458}</b>
|
||||
</DRelation>
|
||||
</base-DRelation>
|
||||
</DInheritance>
|
||||
</instance>
|
||||
</item>
|
||||
<item>
|
||||
<instance type="DClass">
|
||||
<DClass>
|
||||
<base-DObject>
|
||||
<DObject>
|
||||
<base-DElement>
|
||||
<DElement>
|
||||
<uid>{a372397b-316a-48c0-b99f-724372413a64}</uid>
|
||||
</DElement>
|
||||
</base-DElement>
|
||||
<object>{32e677d2-4bfb-4f5d-93dc-67fdb1a0c8a1}</object>
|
||||
<name>QTabWidget</name>
|
||||
<pos>x:360;y:0</pos>
|
||||
<rect>x:-55;y:-30;w:110;h:60</rect>
|
||||
<auto-sized>false</auto-sized>
|
||||
<visual-role>0</visual-role>
|
||||
</DObject>
|
||||
</base-DObject>
|
||||
</DClass>
|
||||
</instance>
|
||||
</item>
|
||||
<item>
|
||||
<instance type="DInheritance">
|
||||
<DInheritance>
|
||||
<base-DRelation>
|
||||
<DRelation>
|
||||
<base-DElement>
|
||||
<DElement>
|
||||
<uid>{dce2499c-fdef-40e3-ba77-29b94f8beb1b}</uid>
|
||||
</DElement>
|
||||
</base-DElement>
|
||||
<object>{66fd2699-e4ea-4312-990a-7488c75fc850}</object>
|
||||
<a>{487d395c-3f8b-422c-9568-d70a5d50a9d4}</a>
|
||||
<b>{a372397b-316a-48c0-b99f-724372413a64}</b>
|
||||
</DRelation>
|
||||
</base-DRelation>
|
||||
</DInheritance>
|
||||
</instance>
|
||||
</item>
|
||||
<item>
|
||||
<instance type="DClass">
|
||||
<DClass>
|
||||
<base-DObject>
|
||||
<DObject>
|
||||
<base-DElement>
|
||||
<DElement>
|
||||
<uid>{35e8a91e-8192-4e17-b6c7-e44b3ba3a138}</uid>
|
||||
</DElement>
|
||||
</base-DElement>
|
||||
<object>{988c1b8e-1e9a-4d03-b9b4-75ba5dcac6d7}</object>
|
||||
<name>QMainWindow</name>
|
||||
<pos>x:190;y:0</pos>
|
||||
<rect>x:-55;y:-30;w:110;h:60</rect>
|
||||
<auto-sized>false</auto-sized>
|
||||
<visual-role>0</visual-role>
|
||||
</DObject>
|
||||
</base-DObject>
|
||||
</DClass>
|
||||
</instance>
|
||||
</item>
|
||||
<item>
|
||||
<instance type="DInheritance">
|
||||
<DInheritance>
|
||||
<base-DRelation>
|
||||
<DRelation>
|
||||
<base-DElement>
|
||||
<DElement>
|
||||
<uid>{7dd17b0c-4256-463f-8852-c4faf0614997}</uid>
|
||||
</DElement>
|
||||
</base-DElement>
|
||||
<object>{9f29593e-b0b5-4488-ae5d-2378857535a0}</object>
|
||||
<a>{b7b131f9-5e56-484a-ba8b-c7a5fc34fb7b}</a>
|
||||
<b>{35e8a91e-8192-4e17-b6c7-e44b3ba3a138}</b>
|
||||
</DRelation>
|
||||
</base-DRelation>
|
||||
</DInheritance>
|
||||
</instance>
|
||||
</item>
|
||||
</qlist>
|
||||
</elements>
|
||||
<last-modified>1456935246527</last-modified>
|
||||
</MDiagram>
|
||||
</base-MDiagram>
|
||||
</MCanvasDiagram>
|
||||
</instance>
|
||||
</target>
|
||||
</handle>
|
||||
</item>
|
||||
<item>
|
||||
<handle>
|
||||
<uid>{72a2b731-3aad-430f-a76c-f43dd9b36462}</uid>
|
||||
<target>
|
||||
<instance type="MClass">
|
||||
<MClass>
|
||||
<base-MObject>
|
||||
<MObject>
|
||||
<base-MElement>
|
||||
<MElement>
|
||||
<uid>{72a2b731-3aad-430f-a76c-f43dd9b36462}</uid>
|
||||
<flags>1</flags>
|
||||
</MElement>
|
||||
</base-MElement>
|
||||
<name>Browser</name>
|
||||
<relations>
|
||||
<handles>
|
||||
<handles>
|
||||
<qlist>
|
||||
<item>
|
||||
<handle>
|
||||
<uid>{736a9cc9-35f1-47c1-bdc4-c3033d14a33d}</uid>
|
||||
<target>
|
||||
<instance type="MDependency">
|
||||
<MDependency>
|
||||
<base-MRelation>
|
||||
<MRelation>
|
||||
<base-MElement>
|
||||
<MElement>
|
||||
<uid>{736a9cc9-35f1-47c1-bdc4-c3033d14a33d}</uid>
|
||||
</MElement>
|
||||
</base-MElement>
|
||||
<a>{72a2b731-3aad-430f-a76c-f43dd9b36462}</a>
|
||||
<b>{ee93b67f-4caf-4d92-9303-f6c2582bf1b9}</b>
|
||||
</MRelation>
|
||||
</base-MRelation>
|
||||
</MDependency>
|
||||
</instance>
|
||||
</target>
|
||||
</handle>
|
||||
</item>
|
||||
<item>
|
||||
<handle>
|
||||
<uid>{e878ee71-b5d1-4943-b081-466851b0f721}</uid>
|
||||
<target>
|
||||
<instance type="MAssociation">
|
||||
<MAssociation>
|
||||
<base-MRelation>
|
||||
<MRelation>
|
||||
<base-MElement>
|
||||
<MElement>
|
||||
<uid>{e878ee71-b5d1-4943-b081-466851b0f721}</uid>
|
||||
</MElement>
|
||||
</base-MElement>
|
||||
<a>{72a2b731-3aad-430f-a76c-f43dd9b36462}</a>
|
||||
<b>{ee93b67f-4caf-4d92-9303-f6c2582bf1b9}</b>
|
||||
</MRelation>
|
||||
</base-MRelation>
|
||||
<a>
|
||||
<MAssociationEnd>
|
||||
<cardinality>1..*</cardinality>
|
||||
<kind>2</kind>
|
||||
</MAssociationEnd>
|
||||
</a>
|
||||
<b>
|
||||
<MAssociationEnd>
|
||||
<cardinality>1</cardinality>
|
||||
</MAssociationEnd>
|
||||
</b>
|
||||
</MAssociation>
|
||||
</instance>
|
||||
</target>
|
||||
</handle>
|
||||
</item>
|
||||
</qlist>
|
||||
</handles>
|
||||
</handles>
|
||||
</relations>
|
||||
</MObject>
|
||||
</base-MObject>
|
||||
</MClass>
|
||||
</instance>
|
||||
</target>
|
||||
</handle>
|
||||
</item>
|
||||
<item>
|
||||
<handle>
|
||||
<uid>{ee93b67f-4caf-4d92-9303-f6c2582bf1b9}</uid>
|
||||
<target>
|
||||
<instance type="MClass">
|
||||
<MClass>
|
||||
<base-MObject>
|
||||
<MObject>
|
||||
<base-MElement>
|
||||
<MElement>
|
||||
<uid>{ee93b67f-4caf-4d92-9303-f6c2582bf1b9}</uid>
|
||||
<flags>1</flags>
|
||||
</MElement>
|
||||
</base-MElement>
|
||||
<name>BrowserWindow</name>
|
||||
<relations>
|
||||
<handles>
|
||||
<handles>
|
||||
<qlist>
|
||||
<item>
|
||||
<handle>
|
||||
<uid>{ee3a86b4-773d-4ea5-81c1-552501061629}</uid>
|
||||
<target>
|
||||
<instance type="MAssociation">
|
||||
<MAssociation>
|
||||
<base-MRelation>
|
||||
<MRelation>
|
||||
<base-MElement>
|
||||
<MElement>
|
||||
<uid>{ee3a86b4-773d-4ea5-81c1-552501061629}</uid>
|
||||
</MElement>
|
||||
</base-MElement>
|
||||
<a>{ee93b67f-4caf-4d92-9303-f6c2582bf1b9}</a>
|
||||
<b>{1ab2b778-127b-4661-ba2d-8f329f44d859}</b>
|
||||
</MRelation>
|
||||
</base-MRelation>
|
||||
<a>
|
||||
<MAssociationEnd>
|
||||
<cardinality>1</cardinality>
|
||||
</MAssociationEnd>
|
||||
</a>
|
||||
<b>
|
||||
<MAssociationEnd>
|
||||
<cardinality>1</cardinality>
|
||||
</MAssociationEnd>
|
||||
</b>
|
||||
</MAssociation>
|
||||
</instance>
|
||||
</target>
|
||||
</handle>
|
||||
</item>
|
||||
<item>
|
||||
<handle>
|
||||
<uid>{9f29593e-b0b5-4488-ae5d-2378857535a0}</uid>
|
||||
<target>
|
||||
<instance type="MInheritance">
|
||||
<MInheritance>
|
||||
<base-MRelation>
|
||||
<MRelation>
|
||||
<base-MElement>
|
||||
<MElement>
|
||||
<uid>{9f29593e-b0b5-4488-ae5d-2378857535a0}</uid>
|
||||
</MElement>
|
||||
</base-MElement>
|
||||
<a>{ee93b67f-4caf-4d92-9303-f6c2582bf1b9}</a>
|
||||
<b>{988c1b8e-1e9a-4d03-b9b4-75ba5dcac6d7}</b>
|
||||
</MRelation>
|
||||
</base-MRelation>
|
||||
</MInheritance>
|
||||
</instance>
|
||||
</target>
|
||||
</handle>
|
||||
</item>
|
||||
</qlist>
|
||||
</handles>
|
||||
</handles>
|
||||
</relations>
|
||||
</MObject>
|
||||
</base-MObject>
|
||||
</MClass>
|
||||
</instance>
|
||||
</target>
|
||||
</handle>
|
||||
</item>
|
||||
<item>
|
||||
<handle>
|
||||
<uid>{1ab2b778-127b-4661-ba2d-8f329f44d859}</uid>
|
||||
<target>
|
||||
<instance type="MClass">
|
||||
<MClass>
|
||||
<base-MObject>
|
||||
<MObject>
|
||||
<base-MElement>
|
||||
<MElement>
|
||||
<uid>{1ab2b778-127b-4661-ba2d-8f329f44d859}</uid>
|
||||
<flags>1</flags>
|
||||
</MElement>
|
||||
</base-MElement>
|
||||
<name>TabWidget</name>
|
||||
<relations>
|
||||
<handles>
|
||||
<handles>
|
||||
<qlist>
|
||||
<item>
|
||||
<handle>
|
||||
<uid>{97fd8235-200e-4448-b173-51add1df8edc}</uid>
|
||||
<target>
|
||||
<instance type="MAssociation">
|
||||
<MAssociation>
|
||||
<base-MRelation>
|
||||
<MRelation>
|
||||
<base-MElement>
|
||||
<MElement>
|
||||
<uid>{97fd8235-200e-4448-b173-51add1df8edc}</uid>
|
||||
</MElement>
|
||||
</base-MElement>
|
||||
<a>{1ab2b778-127b-4661-ba2d-8f329f44d859}</a>
|
||||
<b>{b8a281e2-4ee3-42cd-bb3d-d075a54ad358}</b>
|
||||
</MRelation>
|
||||
</base-MRelation>
|
||||
<a>
|
||||
<MAssociationEnd>
|
||||
<cardinality>1..*</cardinality>
|
||||
<kind>2</kind>
|
||||
</MAssociationEnd>
|
||||
</a>
|
||||
<b>
|
||||
<MAssociationEnd>
|
||||
<cardinality>1</cardinality>
|
||||
</MAssociationEnd>
|
||||
</b>
|
||||
</MAssociation>
|
||||
</instance>
|
||||
</target>
|
||||
</handle>
|
||||
</item>
|
||||
<item>
|
||||
<handle>
|
||||
<uid>{66fd2699-e4ea-4312-990a-7488c75fc850}</uid>
|
||||
<target>
|
||||
<instance type="MInheritance">
|
||||
<MInheritance>
|
||||
<base-MRelation>
|
||||
<MRelation>
|
||||
<base-MElement>
|
||||
<MElement>
|
||||
<uid>{66fd2699-e4ea-4312-990a-7488c75fc850}</uid>
|
||||
</MElement>
|
||||
</base-MElement>
|
||||
<a>{1ab2b778-127b-4661-ba2d-8f329f44d859}</a>
|
||||
<b>{32e677d2-4bfb-4f5d-93dc-67fdb1a0c8a1}</b>
|
||||
</MRelation>
|
||||
</base-MRelation>
|
||||
</MInheritance>
|
||||
</instance>
|
||||
</target>
|
||||
</handle>
|
||||
</item>
|
||||
</qlist>
|
||||
</handles>
|
||||
</handles>
|
||||
</relations>
|
||||
</MObject>
|
||||
</base-MObject>
|
||||
</MClass>
|
||||
</instance>
|
||||
</target>
|
||||
</handle>
|
||||
</item>
|
||||
<item>
|
||||
<handle>
|
||||
<uid>{320f3a48-12de-4bcb-b7f5-47b12c77dbee}</uid>
|
||||
<target>
|
||||
<instance type="MClass">
|
||||
<MClass>
|
||||
<base-MObject>
|
||||
<MObject>
|
||||
<base-MElement>
|
||||
<MElement>
|
||||
<uid>{320f3a48-12de-4bcb-b7f5-47b12c77dbee}</uid>
|
||||
<flags>1</flags>
|
||||
</MElement>
|
||||
</base-MElement>
|
||||
<name>WebPage</name>
|
||||
<relations>
|
||||
<handles>
|
||||
<handles>
|
||||
<qlist>
|
||||
<item>
|
||||
<handle>
|
||||
<uid>{20788ccc-cab0-406b-8cf4-d8062570085e}</uid>
|
||||
<target>
|
||||
<instance type="MInheritance">
|
||||
<MInheritance>
|
||||
<base-MRelation>
|
||||
<MRelation>
|
||||
<base-MElement>
|
||||
<MElement>
|
||||
<uid>{20788ccc-cab0-406b-8cf4-d8062570085e}</uid>
|
||||
</MElement>
|
||||
</base-MElement>
|
||||
<a>{320f3a48-12de-4bcb-b7f5-47b12c77dbee}</a>
|
||||
<b>{6659de40-605d-4744-8654-73ae959dcb8a}</b>
|
||||
</MRelation>
|
||||
</base-MRelation>
|
||||
</MInheritance>
|
||||
</instance>
|
||||
</target>
|
||||
</handle>
|
||||
</item>
|
||||
</qlist>
|
||||
</handles>
|
||||
</handles>
|
||||
</relations>
|
||||
</MObject>
|
||||
</base-MObject>
|
||||
</MClass>
|
||||
</instance>
|
||||
</target>
|
||||
</handle>
|
||||
</item>
|
||||
<item>
|
||||
<handle>
|
||||
<uid>{b8a281e2-4ee3-42cd-bb3d-d075a54ad358}</uid>
|
||||
<target>
|
||||
<instance type="MClass">
|
||||
<MClass>
|
||||
<base-MObject>
|
||||
<MObject>
|
||||
<base-MElement>
|
||||
<MElement>
|
||||
<uid>{b8a281e2-4ee3-42cd-bb3d-d075a54ad358}</uid>
|
||||
<flags>1</flags>
|
||||
</MElement>
|
||||
</base-MElement>
|
||||
<name>WebView</name>
|
||||
<relations>
|
||||
<handles>
|
||||
<handles>
|
||||
<qlist>
|
||||
<item>
|
||||
<handle>
|
||||
<uid>{772227ff-d0df-4ecd-97ea-89d1bd10a96f}</uid>
|
||||
<target>
|
||||
<instance type="MAssociation">
|
||||
<MAssociation>
|
||||
<base-MRelation>
|
||||
<MRelation>
|
||||
<base-MElement>
|
||||
<MElement>
|
||||
<uid>{772227ff-d0df-4ecd-97ea-89d1bd10a96f}</uid>
|
||||
</MElement>
|
||||
</base-MElement>
|
||||
<a>{b8a281e2-4ee3-42cd-bb3d-d075a54ad358}</a>
|
||||
<b>{320f3a48-12de-4bcb-b7f5-47b12c77dbee}</b>
|
||||
</MRelation>
|
||||
</base-MRelation>
|
||||
<a>
|
||||
<MAssociationEnd>
|
||||
<cardinality>1</cardinality>
|
||||
</MAssociationEnd>
|
||||
</a>
|
||||
<b>
|
||||
<MAssociationEnd>
|
||||
<cardinality>1</cardinality>
|
||||
</MAssociationEnd>
|
||||
</b>
|
||||
</MAssociation>
|
||||
</instance>
|
||||
</target>
|
||||
</handle>
|
||||
</item>
|
||||
<item>
|
||||
<handle>
|
||||
<uid>{1176aee6-be27-4b21-be22-33bca908a71e}</uid>
|
||||
<target>
|
||||
<instance type="MInheritance">
|
||||
<MInheritance>
|
||||
<base-MRelation>
|
||||
<MRelation>
|
||||
<base-MElement>
|
||||
<MElement>
|
||||
<uid>{1176aee6-be27-4b21-be22-33bca908a71e}</uid>
|
||||
</MElement>
|
||||
</base-MElement>
|
||||
<a>{b8a281e2-4ee3-42cd-bb3d-d075a54ad358}</a>
|
||||
<b>{9b91aa7b-0fa3-4c78-9e8d-e1bfdfce9f7f}</b>
|
||||
</MRelation>
|
||||
</base-MRelation>
|
||||
</MInheritance>
|
||||
</instance>
|
||||
</target>
|
||||
</handle>
|
||||
</item>
|
||||
</qlist>
|
||||
</handles>
|
||||
</handles>
|
||||
</relations>
|
||||
</MObject>
|
||||
</base-MObject>
|
||||
</MClass>
|
||||
</instance>
|
||||
</target>
|
||||
</handle>
|
||||
</item>
|
||||
<item>
|
||||
<handle>
|
||||
<uid>{9b91aa7b-0fa3-4c78-9e8d-e1bfdfce9f7f}</uid>
|
||||
<target>
|
||||
<instance type="MClass">
|
||||
<MClass>
|
||||
<base-MObject>
|
||||
<MObject>
|
||||
<base-MElement>
|
||||
<MElement>
|
||||
<uid>{9b91aa7b-0fa3-4c78-9e8d-e1bfdfce9f7f}</uid>
|
||||
</MElement>
|
||||
</base-MElement>
|
||||
<name>QWebEngineView</name>
|
||||
<relations>
|
||||
<handles>
|
||||
<handles>
|
||||
<qlist>
|
||||
<item>
|
||||
<handle>
|
||||
<uid>{5124d95d-73fb-4d70-aa89-1135f2202c2f}</uid>
|
||||
<target>
|
||||
<instance type="MInheritance">
|
||||
<MInheritance>
|
||||
<base-MRelation>
|
||||
<MRelation>
|
||||
<base-MElement>
|
||||
<MElement>
|
||||
<uid>{5124d95d-73fb-4d70-aa89-1135f2202c2f}</uid>
|
||||
</MElement>
|
||||
</base-MElement>
|
||||
<a>{9b91aa7b-0fa3-4c78-9e8d-e1bfdfce9f7f}</a>
|
||||
<b>{b8a281e2-4ee3-42cd-bb3d-d075a54ad358}</b>
|
||||
</MRelation>
|
||||
</base-MRelation>
|
||||
</MInheritance>
|
||||
</instance>
|
||||
</target>
|
||||
</handle>
|
||||
</item>
|
||||
</qlist>
|
||||
</handles>
|
||||
</handles>
|
||||
</relations>
|
||||
</MObject>
|
||||
</base-MObject>
|
||||
</MClass>
|
||||
</instance>
|
||||
</target>
|
||||
</handle>
|
||||
</item>
|
||||
<item>
|
||||
<handle>
|
||||
<uid>{6659de40-605d-4744-8654-73ae959dcb8a}</uid>
|
||||
<target>
|
||||
<instance type="MClass">
|
||||
<MClass>
|
||||
<base-MObject>
|
||||
<MObject>
|
||||
<base-MElement>
|
||||
<MElement>
|
||||
<uid>{6659de40-605d-4744-8654-73ae959dcb8a}</uid>
|
||||
</MElement>
|
||||
</base-MElement>
|
||||
<name>QWebEnginePage</name>
|
||||
</MObject>
|
||||
</base-MObject>
|
||||
</MClass>
|
||||
</instance>
|
||||
</target>
|
||||
</handle>
|
||||
</item>
|
||||
<item>
|
||||
<handle>
|
||||
<uid>{32e677d2-4bfb-4f5d-93dc-67fdb1a0c8a1}</uid>
|
||||
<target>
|
||||
<instance type="MClass">
|
||||
<MClass>
|
||||
<base-MObject>
|
||||
<MObject>
|
||||
<base-MElement>
|
||||
<MElement>
|
||||
<uid>{32e677d2-4bfb-4f5d-93dc-67fdb1a0c8a1}</uid>
|
||||
</MElement>
|
||||
</base-MElement>
|
||||
<name>QTabWidget</name>
|
||||
</MObject>
|
||||
</base-MObject>
|
||||
</MClass>
|
||||
</instance>
|
||||
</target>
|
||||
</handle>
|
||||
</item>
|
||||
<item>
|
||||
<handle>
|
||||
<uid>{988c1b8e-1e9a-4d03-b9b4-75ba5dcac6d7}</uid>
|
||||
<target>
|
||||
<instance type="MClass">
|
||||
<MClass>
|
||||
<base-MObject>
|
||||
<MObject>
|
||||
<base-MElement>
|
||||
<MElement>
|
||||
<uid>{988c1b8e-1e9a-4d03-b9b4-75ba5dcac6d7}</uid>
|
||||
</MElement>
|
||||
</base-MElement>
|
||||
<name>QMainWindow</name>
|
||||
</MObject>
|
||||
</base-MObject>
|
||||
</MClass>
|
||||
</instance>
|
||||
</target>
|
||||
</handle>
|
||||
</item>
|
||||
</qlist>
|
||||
</handles>
|
||||
</handles>
|
||||
</children>
|
||||
</MObject>
|
||||
</base-MObject>
|
||||
</MPackage>
|
||||
</instance>
|
||||
</root-package>
|
||||
</project>
|
||||
</qmt>
|
|
@ -0,0 +1,348 @@
|
|||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** 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 The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/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: https://www.gnu.org/licenses/fdl-1.3.html.
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
/*!
|
||||
\example webenginewidgets/simplebrowser
|
||||
\title WebEngine Widgets Simple Browser Example
|
||||
\ingroup webengine-widgetexamples
|
||||
\brief A simple browser based on \QWE Widgets.
|
||||
|
||||
\image simplebrowser.png
|
||||
|
||||
\e {Simple Browser} demonstrates how to use the
|
||||
\l{Qt WebEngine Widgets C++ Classes}{Qt WebEngine C++ classes} to develop a
|
||||
small Web browser application that contains the following elements:
|
||||
|
||||
\list
|
||||
\li Menu bar for opening stored pages and managing windows and tabs.
|
||||
\li Navigation bar for entering a URL and for moving backward and
|
||||
forward in the web page browsing history.
|
||||
\li Multi-tab area for displaying web content within tabs.
|
||||
\li Status bar for displaying hovered links.
|
||||
\li A simple download manager.
|
||||
\endlist
|
||||
|
||||
The web content can be opened in new tabs or separate windows. HTTP and
|
||||
proxy authentication can be used for accessing web pages.
|
||||
|
||||
\include examples-run.qdocinc
|
||||
|
||||
\section1 Class Hierarchy
|
||||
|
||||
We start with sketching a diagram of the main classes that we are going to
|
||||
implement:
|
||||
|
||||
\image simplebrowser-model.png
|
||||
|
||||
\list
|
||||
\li \c{Browser} is a class managing the application windows.
|
||||
\li \c{BrowserWindow} is a \l QMainWindow showing the menu, a navigation
|
||||
bar, \c {TabWidget}, and a status bar.
|
||||
\li \c{TabWidget} is a \l QTabWidget and contains one or multiple
|
||||
browser tabs.
|
||||
\li \c{WebView} is a \l QWebEngineView, provides a view for \c{WebPage},
|
||||
and is added as a tab in \c{TabWidget}.
|
||||
\li \c{WebPage} is a \l QWebEnginePage that represents website content.
|
||||
\endlist
|
||||
|
||||
Additionally, we will implement some auxiliary classes:
|
||||
|
||||
\list
|
||||
\li \c{WebPopupWindow} is a \l QWidget for showing popup windows.
|
||||
\li \c{DownloadManagerWidget} is a \l QWidget implementing the downloads
|
||||
list.
|
||||
\endlist
|
||||
|
||||
\section1 Creating the Browser Main Window
|
||||
|
||||
This example supports multiple main windows that are owned by a \c Browser
|
||||
object. This class also owns the \c DownloadManagerWidget and could be used
|
||||
for further functionality, such as bookmarks and history managers.
|
||||
|
||||
In \c main.cpp, we create the first \c BrowserWindow instance and add it
|
||||
to the \c Browser object. If no arguments are passed on the command line,
|
||||
we open the \l{Qt Homepage}:
|
||||
|
||||
\quotefromfile webenginewidgets/simplebrowser/main.cpp
|
||||
\skipto main
|
||||
\printuntil }
|
||||
|
||||
\section1 Creating Tabs
|
||||
|
||||
The \c BrowserWindow constructor initializes all the necessary user interface
|
||||
related objects. The \c centralWidget of \c BrowserWindow contains an instance of
|
||||
\c TabWidget. The \c TabWidget contains one or several \c WebView instances as tabs,
|
||||
and delegates it's signals and slots to the currently selected one:
|
||||
|
||||
\quotefromfile webenginewidgets/simplebrowser/tabwidget.h
|
||||
\skipto TabWidget :
|
||||
\printuntil {
|
||||
\dots
|
||||
\skipto signals
|
||||
\printuntil triggerWebPageAction
|
||||
\skipto }
|
||||
\dots
|
||||
\printline };
|
||||
|
||||
Each tab contains an instance of \c WebView:
|
||||
|
||||
\quotefromfile webenginewidgets/simplebrowser/tabwidget.cpp
|
||||
\skipto TabWidget::createTab(
|
||||
\printuntil }
|
||||
\skipto TabWidget::createBackgroundTab(
|
||||
\printuntil }
|
||||
|
||||
In \c TabWidget::setupView(), we make sure that the \c TabWidget always forwards
|
||||
the signals of the currently selected \c WebView:
|
||||
|
||||
\quotefromfile webenginewidgets/simplebrowser/tabwidget.cpp
|
||||
\skipto TabWidget::setupView
|
||||
\printuntil /^\}/
|
||||
|
||||
\section1 Implementing WebView Functionality
|
||||
|
||||
The \c WebView is derived from QWebEngineView to support the following
|
||||
functionality:
|
||||
|
||||
\list
|
||||
\li Displaying error messages in case \c renderProcess dies
|
||||
\li Handling \c createWindow requests
|
||||
\li Adding custom menu items to context menus
|
||||
\endlist
|
||||
|
||||
First, we create the WebView with the necessary methods and signals:
|
||||
|
||||
\quotefromfile webenginewidgets/simplebrowser/webview.h
|
||||
\skipto WebView :
|
||||
\printuntil WebView(
|
||||
\dots
|
||||
\skipto protected:
|
||||
\printuntil webActionEnabledChanged
|
||||
\skipto }
|
||||
\dots
|
||||
\printline };
|
||||
|
||||
\section2 Displaying Error Messages
|
||||
|
||||
If the render process is terminated, we display a QMessageBox with an error
|
||||
code, and then we reload the page:
|
||||
|
||||
\quotefromfile webenginewidgets/simplebrowser/webview.cpp
|
||||
\skipto WebView::WebView(QWidget *parent)
|
||||
\printuntil {
|
||||
\skipto renderProcessTerminated
|
||||
\dots
|
||||
\printuntil QTimer
|
||||
\printline });
|
||||
\printline }
|
||||
|
||||
\section2 Managing WebWindows
|
||||
|
||||
The loaded page might want to create windows of the type
|
||||
QWebEnginePage::WebWindowType, for example, when a JavaScript program
|
||||
requests to open a document in a new window or dialog.
|
||||
This is handled by overriding \c QWebView::createWindow():
|
||||
|
||||
\skipto WebView::createWindow(
|
||||
\printuntil return nullptr;
|
||||
\printuntil }
|
||||
|
||||
In case of \c QWebEnginePage::WebDialog, we create an instance of a custom \c WebPopupWindow class:
|
||||
|
||||
\quotefromfile webenginewidgets/simplebrowser/webpopupwindow.h
|
||||
\skipto class WebPopupWindow
|
||||
\printuntil };
|
||||
|
||||
\section2 Adding Context Menu Items
|
||||
|
||||
We add a menu item to the context menu, so that users can right-click to have an inspector
|
||||
opened in a new window. We override QWebEngineView::contextMenuEvent and use
|
||||
QWebEnginePage::createStandardContextMenu to create a default QMenu with a
|
||||
default list of QWebEnginePage::WebAction actions.
|
||||
|
||||
The default name for QWebEnginePage::InspectElement action is
|
||||
\uicontrol Inspect. For clarity, we rename it to \uicontrol {Open Inspector In New Window} when
|
||||
there is no Inspector present yet,
|
||||
and \uicontrol {Inspect Element} when it's already created.
|
||||
|
||||
We also check if the QWebEnginePage::ViewSource action is in the menu, because if it's not
|
||||
we have to add a separator as well.
|
||||
|
||||
\quotefromfile webenginewidgets/simplebrowser/webview.cpp
|
||||
\skipto WebView::contextMenuEvent(
|
||||
\printuntil menu->popup
|
||||
\printline }
|
||||
|
||||
\section1 Implementing WebPage Functionality
|
||||
|
||||
We implement \c WebPage as a subclass of QWebEnginePage to enable HTTP,
|
||||
proxy authentication, and ignoring SSL certificate errors when accessing web
|
||||
pages:
|
||||
|
||||
\quotefromfile webenginewidgets/simplebrowser/webpage.h
|
||||
\skipto WebPage :
|
||||
\printuntil }
|
||||
|
||||
In all the cases above, we display the appropriate dialog to the user. In
|
||||
case of authentication, we need to set the correct credential values on the
|
||||
QAuthenticator object:
|
||||
|
||||
\quotefromfile webenginewidgets/simplebrowser/webpage.cpp
|
||||
\skipto WebPage::handleAuthenticationRequired(
|
||||
\printuntil }
|
||||
\printuntil }
|
||||
\printline }
|
||||
|
||||
The \c handleProxyAuthenticationRequired signal handler implements the very same
|
||||
steps for the authentication of HTTP proxies.
|
||||
|
||||
In case of SSL errors, we just need to return a boolean value indicating
|
||||
whether the certificate should be ignored.
|
||||
|
||||
\quotefromfile webenginewidgets/simplebrowser/webpage.cpp
|
||||
\skipto WebPage::certificateError(
|
||||
\printuntil }
|
||||
\printuntil }
|
||||
|
||||
\section1 Opening a Web Page
|
||||
|
||||
This section describes the workflow for opening a new page. When the user
|
||||
enters a URL in the navigation bar and presses \uicontrol Enter, the \c
|
||||
QLineEdit::returnPressed signal is emitted and the new URL is then handed
|
||||
over to \c TabWidget::setUrl:
|
||||
|
||||
\quotefromfile webenginewidgets/simplebrowser/browserwindow.cpp
|
||||
\skipto BrowserWindow::BrowserWindow
|
||||
\printline BrowserWindow::BrowserWindow
|
||||
\skipto /^\{/
|
||||
\printline /^\{/
|
||||
\dots
|
||||
\skipto connect(m_urlLineEdit
|
||||
\printuntil });
|
||||
\dots
|
||||
\skipto /^\}/
|
||||
\printline /^\}/
|
||||
|
||||
The call is forwarded to the currently selected tab:
|
||||
|
||||
\quotefromfile webenginewidgets/simplebrowser/tabwidget.cpp
|
||||
\skipto TabWidget::setUrl(
|
||||
\printuntil }
|
||||
\printuntil }
|
||||
|
||||
The \c setUrl() method of \c WebView just forwards the \c url to the associated \c WebPage,
|
||||
which in turn starts the downloading of the page's content in the background.
|
||||
|
||||
\section1 Implementing Private Browsing
|
||||
|
||||
\e{Private browsing}, \e{incognito mode}, or \e{off-the-record mode} is a
|
||||
feature of many browsers where normally persistent data, such as cookies,
|
||||
the HTTP cache, or browsing history, is kept only in memory, leaving no
|
||||
trace on disk. In this example we will implement private browsing on the
|
||||
window level with tabs in one window all in either normal or private mode.
|
||||
Alternatively we could implement private browsing on the tab-level, with
|
||||
some tabs in a window in normal mode, others in private mode.
|
||||
|
||||
Implementing private browsing is quite easy using \QWE. All one has
|
||||
to do is to create a new \l{QWebEngineProfile} and use it in the
|
||||
\l{QWebEnginePage} instead of the default profile. In the example this new
|
||||
profile is owned by the \c Browser object:
|
||||
|
||||
\quotefromfile webenginewidgets/simplebrowser/browser.h
|
||||
\skipto /^class Browser$/
|
||||
\printuntil public:
|
||||
\dots
|
||||
\skipto createWindow
|
||||
\printline createWindow
|
||||
\skipto private:
|
||||
\printline private:
|
||||
\dots
|
||||
\skipto m_otrProfile
|
||||
\printline m_otrProfile
|
||||
\printline /^\};$/
|
||||
|
||||
Required profile for \e{private browsing} is created together with its
|
||||
first window. The default constructor for \l{QWebEngineProfile} already
|
||||
puts it in \e{off-the-record} mode.
|
||||
|
||||
\quotefromfile webenginewidgets/simplebrowser/browser.cpp
|
||||
|
||||
\skipto Browser::createWindow
|
||||
\printuntil m_otrProfile.reset
|
||||
\dots
|
||||
|
||||
All that is left to do is to pass the appropriate profile down to the
|
||||
appropriate \l QWebEnginePage objects. The \c Browser object will hand to
|
||||
each new \c BrowserWindow either the global default profile
|
||||
(see \l{QWebEngineProfile::defaultProfile}) or one shared
|
||||
\e{off-the-record} profile instance:
|
||||
|
||||
\dots
|
||||
\skipto m_otrProfile.get
|
||||
\printuntil mainWindow = new BrowserWindow
|
||||
\skipto return mainWindow
|
||||
\printuntil /^\}/
|
||||
|
||||
The \c BrowserWindow and \c TabWidget objects will then ensure that all \l
|
||||
QWebEnginePage objects contained in a window will use this profile.
|
||||
|
||||
\section1 Managing Downloads
|
||||
|
||||
Downloads are associated with a \l QWebEngineProfile. Whenever a download is
|
||||
triggered on a web page the \l QWebEngineProfile::downloadRequested signal is
|
||||
emitted with a \l QWebEngineDownloadItem, which in this example is forwarded
|
||||
to \c DownloadManagerWidget::downloadRequested:
|
||||
|
||||
\quotefromfile webenginewidgets/simplebrowser/browser.cpp
|
||||
\skipto Browser::Browser
|
||||
\printuntil /^\}/
|
||||
|
||||
This method prompts the user for a file name (with a pre-filled suggestion)
|
||||
and starts the download (unless the user cancels the \uicontrol {Save As}
|
||||
dialog):
|
||||
|
||||
\quotefromfile webenginewidgets/simplebrowser/downloadmanagerwidget.cpp
|
||||
\skipto DownloadManagerWidget::downloadRequested
|
||||
\printuntil /^\}/
|
||||
|
||||
The \l QWebEngineDownloadItem object will periodically emit the \l
|
||||
{QWebEngineDownloadItem::}{downloadProgress} signal to notify potential
|
||||
observers of the download progress and the \l
|
||||
{QWebEngineDownloadItem::}{stateChanged} signal when the download is
|
||||
finished or when an error occurs. See \c downloadmanagerwidget.cpp for an
|
||||
example of how these signals can be handled.
|
||||
|
||||
\section1 Files and Attributions
|
||||
|
||||
The example uses icons from the Tango Icon Library:
|
||||
|
||||
\table
|
||||
\row
|
||||
\li \l{simplebrowser-tango}{Tango Icon Library}
|
||||
\li Public Domain
|
||||
\endtable
|
||||
*/
|
|
@ -0,0 +1,106 @@
|
|||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2017 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of the examples of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:BSD$
|
||||
** 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 The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** BSD License Usage
|
||||
** Alternatively, 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 The Qt Company Ltd 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 "downloadmanagerwidget.h"
|
||||
|
||||
#include "browser.h"
|
||||
#include "browserwindow.h"
|
||||
#include "downloadwidget.h"
|
||||
|
||||
#include <QFileDialog>
|
||||
#include <QDir>
|
||||
#include <QWebEngineDownloadItem>
|
||||
|
||||
DownloadManagerWidget::DownloadManagerWidget(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
, m_numDownloads(0)
|
||||
{
|
||||
setupUi(this);
|
||||
}
|
||||
|
||||
void DownloadManagerWidget::downloadRequested(QWebEngineDownloadItem *download)
|
||||
{
|
||||
Q_ASSERT(download && download->state() == QWebEngineDownloadItem::DownloadRequested);
|
||||
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
|
||||
QString path = QFileDialog::getSaveFileName(this, tr("Save as"), QDir(download->downloadDirectory()).filePath(download->downloadFileName()));
|
||||
#else
|
||||
QString path = QFileDialog::getSaveFileName(this, tr("Save as"), download->path());
|
||||
#endif
|
||||
if (path.isEmpty())
|
||||
return;
|
||||
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
|
||||
download->setDownloadDirectory(QFileInfo(path).path());
|
||||
download->setDownloadFileName(QFileInfo(path).fileName());
|
||||
#else
|
||||
download->setPath(path);
|
||||
#endif
|
||||
download->accept();
|
||||
add(new DownloadWidget(download));
|
||||
|
||||
show();
|
||||
}
|
||||
|
||||
void DownloadManagerWidget::add(DownloadWidget *downloadWidget)
|
||||
{
|
||||
connect(downloadWidget, &DownloadWidget::removeClicked, this, &DownloadManagerWidget::remove);
|
||||
m_itemsLayout->insertWidget(0, downloadWidget, 0, Qt::AlignTop);
|
||||
if (m_numDownloads++ == 0)
|
||||
m_zeroItemsLabel->hide();
|
||||
}
|
||||
|
||||
void DownloadManagerWidget::remove(DownloadWidget *downloadWidget)
|
||||
{
|
||||
m_itemsLayout->removeWidget(downloadWidget);
|
||||
downloadWidget->deleteLater();
|
||||
if (--m_numDownloads == 0)
|
||||
m_zeroItemsLabel->show();
|
||||
}
|
|
@ -0,0 +1,83 @@
|
|||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2017 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of the examples of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:BSD$
|
||||
** 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 The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** BSD License Usage
|
||||
** Alternatively, 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 The Qt Company Ltd 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$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef DOWNLOADMANAGERWIDGET_H
|
||||
#define DOWNLOADMANAGERWIDGET_H
|
||||
|
||||
#include "ui_downloadmanagerwidget.h"
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QWebEngineDownloadItem;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
class DownloadWidget;
|
||||
|
||||
// Displays a list of downloads.
|
||||
class DownloadManagerWidget final : public QWidget, public Ui::DownloadManagerWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit DownloadManagerWidget(QWidget *parent = nullptr);
|
||||
|
||||
// Prompts user with a "Save As" dialog. If the user doesn't cancel it, then
|
||||
// the QWebEngineDownloadItem will be accepted and the DownloadManagerWidget
|
||||
// will be shown on the screen.
|
||||
void downloadRequested(QWebEngineDownloadItem *webItem);
|
||||
|
||||
private:
|
||||
void add(DownloadWidget *downloadWidget);
|
||||
void remove(DownloadWidget *downloadWidget);
|
||||
|
||||
int m_numDownloads;
|
||||
};
|
||||
|
||||
#endif // DOWNLOADMANAGERWIDGET_H
|
|
@ -0,0 +1,104 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>DownloadManagerWidget</class>
|
||||
<widget class="QWidget" name="DownloadManagerWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>212</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Downloads</string>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">#DownloadManagerWidget {
|
||||
background: palette(button)
|
||||
}</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="m_topLevelLayout">
|
||||
<property name="sizeConstraint">
|
||||
<enum>QLayout::SetNoConstraint</enum>
|
||||
</property>
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QScrollArea" name="m_scrollArea">
|
||||
<property name="styleSheet">
|
||||
<string notr="true">#m_scrollArea {
|
||||
margin: 2px;
|
||||
border: none;
|
||||
}</string>
|
||||
</property>
|
||||
<property name="verticalScrollBarPolicy">
|
||||
<enum>Qt::ScrollBarAlwaysOn</enum>
|
||||
</property>
|
||||
<property name="horizontalScrollBarPolicy">
|
||||
<enum>Qt::ScrollBarAlwaysOff</enum>
|
||||
</property>
|
||||
<property name="widgetResizable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
|
||||
</property>
|
||||
<widget class="QWidget" name="m_items">
|
||||
<property name="styleSheet">
|
||||
<string notr="true">#m_items {background: palette(mid)}</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="m_itemsLayout">
|
||||
<property name="spacing">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<property name="leftMargin">
|
||||
<number>3</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>3</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>3</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>3</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="m_zeroItemsLabel">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">color: palette(shadow)</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>No downloads</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
|
@ -0,0 +1,163 @@
|
|||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2017 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of the examples of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:BSD$
|
||||
** 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 The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** BSD License Usage
|
||||
** Alternatively, 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 The Qt Company Ltd 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 "downloadwidget.h"
|
||||
|
||||
#include <QFileInfo>
|
||||
#include <QUrl>
|
||||
#include <QWebEngineDownloadItem>
|
||||
|
||||
DownloadWidget::DownloadWidget(QWebEngineDownloadItem *download, QWidget *parent)
|
||||
: QFrame(parent)
|
||||
, m_download(download)
|
||||
, m_timeAdded()
|
||||
{
|
||||
m_timeAdded.start();
|
||||
setupUi(this);
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
|
||||
m_dstName->setText(m_download->downloadFileName());
|
||||
#else
|
||||
m_dstName->setText(QFileInfo(m_download->path()).fileName());
|
||||
#endif
|
||||
m_srcUrl->setText(m_download->url().toDisplayString());
|
||||
|
||||
connect(m_cancelButton, &QPushButton::clicked,
|
||||
[this](bool) {
|
||||
if (m_download->state() == QWebEngineDownloadItem::DownloadInProgress)
|
||||
m_download->cancel();
|
||||
else
|
||||
emit removeClicked(this);
|
||||
});
|
||||
|
||||
connect(m_download, &QWebEngineDownloadItem::downloadProgress,
|
||||
this, &DownloadWidget::updateWidget);
|
||||
|
||||
connect(m_download, &QWebEngineDownloadItem::stateChanged,
|
||||
this, &DownloadWidget::updateWidget);
|
||||
|
||||
updateWidget();
|
||||
}
|
||||
|
||||
inline QString DownloadWidget::withUnit(qreal bytes)
|
||||
{
|
||||
if (bytes < (1 << 10))
|
||||
return tr("%L1 B").arg(bytes);
|
||||
else if (bytes < (1 << 20))
|
||||
return tr("%L1 KiB").arg(bytes / (1 << 10), 0, 'f', 2);
|
||||
else if (bytes < (1 << 30))
|
||||
return tr("%L1 MiB").arg(bytes / (1 << 20), 0, 'f', 2);
|
||||
else
|
||||
return tr("%L1 GiB").arg(bytes / (1 << 30), 0, 'f', 2);
|
||||
}
|
||||
|
||||
void DownloadWidget::updateWidget()
|
||||
{
|
||||
qreal totalBytes = m_download->totalBytes();
|
||||
qreal receivedBytes = m_download->receivedBytes();
|
||||
qreal bytesPerSecond = receivedBytes / m_timeAdded.elapsed() * 1000;
|
||||
|
||||
auto state = m_download->state();
|
||||
switch (state) {
|
||||
case QWebEngineDownloadItem::DownloadRequested:
|
||||
Q_UNREACHABLE();
|
||||
break;
|
||||
case QWebEngineDownloadItem::DownloadInProgress:
|
||||
if (totalBytes >= 0) {
|
||||
m_progressBar->setValue(qRound(100 * receivedBytes / totalBytes));
|
||||
m_progressBar->setDisabled(false);
|
||||
m_progressBar->setFormat(
|
||||
tr("%p% - %1 of %2 downloaded - %3/s")
|
||||
.arg(withUnit(receivedBytes))
|
||||
.arg(withUnit(totalBytes))
|
||||
.arg(withUnit(bytesPerSecond)));
|
||||
} else {
|
||||
m_progressBar->setValue(0);
|
||||
m_progressBar->setDisabled(false);
|
||||
m_progressBar->setFormat(
|
||||
tr("unknown size - %1 downloaded - %2/s")
|
||||
.arg(withUnit(receivedBytes))
|
||||
.arg(withUnit(bytesPerSecond)));
|
||||
}
|
||||
break;
|
||||
case QWebEngineDownloadItem::DownloadCompleted:
|
||||
m_progressBar->setValue(100);
|
||||
m_progressBar->setDisabled(true);
|
||||
m_progressBar->setFormat(
|
||||
tr("completed - %1 downloaded - %2/s")
|
||||
.arg(withUnit(receivedBytes))
|
||||
.arg(withUnit(bytesPerSecond)));
|
||||
break;
|
||||
case QWebEngineDownloadItem::DownloadCancelled:
|
||||
m_progressBar->setValue(0);
|
||||
m_progressBar->setDisabled(true);
|
||||
m_progressBar->setFormat(
|
||||
tr("cancelled - %1 downloaded - %2/s")
|
||||
.arg(withUnit(receivedBytes))
|
||||
.arg(withUnit(bytesPerSecond)));
|
||||
break;
|
||||
case QWebEngineDownloadItem::DownloadInterrupted:
|
||||
m_progressBar->setValue(0);
|
||||
m_progressBar->setDisabled(true);
|
||||
m_progressBar->setFormat(
|
||||
tr("interrupted: %1")
|
||||
.arg(m_download->interruptReasonString()));
|
||||
break;
|
||||
}
|
||||
|
||||
if (state == QWebEngineDownloadItem::DownloadInProgress) {
|
||||
static QIcon cancelIcon(QStringLiteral(":process-stop.png"));
|
||||
m_cancelButton->setIcon(cancelIcon);
|
||||
m_cancelButton->setToolTip(tr("Stop downloading"));
|
||||
} else {
|
||||
static QIcon removeIcon(QStringLiteral(":edit-clear.png"));
|
||||
m_cancelButton->setIcon(removeIcon);
|
||||
m_cancelButton->setToolTip(tr("Remove from list"));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,86 @@
|
|||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2017 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of the examples of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:BSD$
|
||||
** 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 The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** BSD License Usage
|
||||
** Alternatively, 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 The Qt Company Ltd 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$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef DOWNLOADWIDGET_H
|
||||
#define DOWNLOADWIDGET_H
|
||||
|
||||
#include "ui_downloadwidget.h"
|
||||
|
||||
#include <QFrame>
|
||||
#include <QElapsedTimer>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QWebEngineDownloadItem;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
// Displays one ongoing or finished download (QWebEngineDownloadItem).
|
||||
class DownloadWidget final : public QFrame, public Ui::DownloadWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
// Precondition: The QWebEngineDownloadItem has been accepted.
|
||||
explicit DownloadWidget(QWebEngineDownloadItem *download, QWidget *parent = nullptr);
|
||||
|
||||
signals:
|
||||
// This signal is emitted when the user indicates that they want to remove
|
||||
// this download from the downloads list.
|
||||
void removeClicked(DownloadWidget *self);
|
||||
|
||||
private slots:
|
||||
void updateWidget();
|
||||
|
||||
private:
|
||||
QString withUnit(qreal bytes);
|
||||
|
||||
QWebEngineDownloadItem *m_download;
|
||||
QElapsedTimer m_timeAdded;
|
||||
};
|
||||
|
||||
#endif // DOWNLOADWIDGET_H
|
|
@ -0,0 +1,80 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>DownloadWidget</class>
|
||||
<widget class="QFrame" name="DownloadWidget">
|
||||
<property name="styleSheet">
|
||||
<string notr="true">#DownloadWidget {
|
||||
background: palette(button);
|
||||
border: 1px solid palette(dark);
|
||||
margin: 0px;
|
||||
}</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="m_topLevelLayout">
|
||||
<property name="sizeConstraint">
|
||||
<enum>QLayout::SetMinAndMaxSize</enum>
|
||||
</property>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="m_dstName">
|
||||
<property name="styleSheet">
|
||||
<string notr="true">font-weight: bold
|
||||
</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>TextLabel</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QPushButton" name="m_cancelButton">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed"/>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">QPushButton {
|
||||
margin: 1px;
|
||||
border: none;
|
||||
}
|
||||
QPushButton:pressed {
|
||||
margin: none;
|
||||
border: 1px solid palette(shadow);
|
||||
background: palette(midlight);
|
||||
}</string>
|
||||
</property>
|
||||
<property name="flat">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0" colspan="2">
|
||||
<widget class="QLabel" name="m_srcUrl">
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>350</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true"/>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>TextLabel</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0" colspan="2">
|
||||
<widget class="QProgressBar" name="m_progressBar">
|
||||
<property name="styleSheet">
|
||||
<string notr="true">font-size: 12px</string>
|
||||
</property>
|
||||
<property name="value">
|
||||
<number>24</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources>
|
||||
<include location="data/simplebrowser.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</ui>
|
|
@ -0,0 +1,90 @@
|
|||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of the examples of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:BSD$
|
||||
** 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 The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** BSD License Usage
|
||||
** Alternatively, 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 The Qt Company Ltd 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 "browser.h"
|
||||
#include "browserwindow.h"
|
||||
#include "tabwidget.h"
|
||||
#include <QApplication>
|
||||
#include <QWebEngineProfile>
|
||||
#include <QWebEngineSettings>
|
||||
|
||||
QUrl commandLineUrlArgument()
|
||||
{
|
||||
const QStringList args = QCoreApplication::arguments();
|
||||
for (const QString &arg : args.mid(1)) {
|
||||
if (!arg.startsWith(QLatin1Char('-')))
|
||||
return QUrl::fromUserInput(arg);
|
||||
}
|
||||
return QUrl(QStringLiteral("https://www.qt.io"));
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
QCoreApplication::setOrganizationName("QtExamples");
|
||||
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
||||
QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
|
||||
|
||||
QApplication app(argc, argv);
|
||||
app.setWindowIcon(QIcon(QStringLiteral(":AppLogoColor.png")));
|
||||
|
||||
QWebEngineSettings::defaultSettings()->setAttribute(QWebEngineSettings::PluginsEnabled, true);
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 13, 0)
|
||||
QWebEngineSettings::defaultSettings()->setAttribute(QWebEngineSettings::DnsPrefetchEnabled, true);
|
||||
QWebEngineProfile::defaultProfile()->setUseForGlobalCertificateVerification();
|
||||
#endif
|
||||
|
||||
QUrl url = commandLineUrlArgument();
|
||||
|
||||
Browser browser;
|
||||
BrowserWindow *window = browser.createWindow();
|
||||
window->tabWidget()->setUrl(url);
|
||||
|
||||
return app.exec();
|
||||
}
|
|
@ -0,0 +1,121 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>PasswordDialog</class>
|
||||
<widget class="QDialog" name="PasswordDialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>399</width>
|
||||
<height>148</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Authentication Required</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout" columnstretch="0,0" columnminimumwidth="0,0">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="m_iconLabel">
|
||||
<property name="text">
|
||||
<string>Icon</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLabel" name="m_infoLabel">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Info</string>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="userLabel">
|
||||
<property name="text">
|
||||
<string>Username:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLineEdit" name="m_userNameLineEdit"/>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="passwordLabel">
|
||||
<property name="text">
|
||||
<string>Password:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QLineEdit" name="m_passwordLineEdit">
|
||||
<property name="echoMode">
|
||||
<enum>QLineEdit::Password</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0" colspan="2">
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
<zorder>userLabel</zorder>
|
||||
<zorder>m_userNameLineEdit</zorder>
|
||||
<zorder>passwordLabel</zorder>
|
||||
<zorder>m_passwordLineEdit</zorder>
|
||||
<zorder>buttonBox</zorder>
|
||||
<zorder>m_iconLabel</zorder>
|
||||
<zorder>m_infoLabel</zorder>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>PasswordDialog</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>PasswordDialog</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
|
@ -0,0 +1,36 @@
|
|||
TEMPLATE = app
|
||||
TARGET = simplebrowser
|
||||
QT += webenginewidgets
|
||||
|
||||
HEADERS += \
|
||||
browser.h \
|
||||
browserwindow.h \
|
||||
downloadmanagerwidget.h \
|
||||
downloadwidget.h \
|
||||
tabwidget.h \
|
||||
webpage.h \
|
||||
webpopupwindow.h \
|
||||
webview.h
|
||||
|
||||
SOURCES += \
|
||||
browser.cpp \
|
||||
browserwindow.cpp \
|
||||
downloadmanagerwidget.cpp \
|
||||
downloadwidget.cpp \
|
||||
main.cpp \
|
||||
tabwidget.cpp \
|
||||
webpage.cpp \
|
||||
webpopupwindow.cpp \
|
||||
webview.cpp
|
||||
|
||||
FORMS += \
|
||||
certificateerrordialog.ui \
|
||||
passworddialog.ui \
|
||||
downloadmanagerwidget.ui \
|
||||
downloadwidget.ui
|
||||
|
||||
RESOURCES += data/simplebrowser.qrc
|
||||
|
||||
# install
|
||||
target.path = $$[QT_INSTALL_EXAMPLES]/webenginewidgets/simplebrowser
|
||||
INSTALLS += target
|
|
@ -0,0 +1,265 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE QtCreatorProject>
|
||||
<!-- Written by QtCreator 7.0.1, 2022-05-07T13:43:14. -->
|
||||
<qtcreator>
|
||||
<data>
|
||||
<variable>EnvironmentId</variable>
|
||||
<value type="QByteArray">{078859f3-d15c-4c47-862e-d91fc085a361}</value>
|
||||
</data>
|
||||
<data>
|
||||
<variable>ProjectExplorer.Project.ActiveTarget</variable>
|
||||
<value type="qlonglong">0</value>
|
||||
</data>
|
||||
<data>
|
||||
<variable>ProjectExplorer.Project.EditorSettings</variable>
|
||||
<valuemap type="QVariantMap">
|
||||
<value type="bool" key="EditorConfiguration.AutoIndent">true</value>
|
||||
<value type="bool" key="EditorConfiguration.AutoSpacesForTabs">false</value>
|
||||
<value type="bool" key="EditorConfiguration.CamelCaseNavigation">true</value>
|
||||
<valuemap type="QVariantMap" key="EditorConfiguration.CodeStyle.0">
|
||||
<value type="QString" key="language">Cpp</value>
|
||||
<valuemap type="QVariantMap" key="value">
|
||||
<value type="QByteArray" key="CurrentPreferences">CppGlobal</value>
|
||||
</valuemap>
|
||||
</valuemap>
|
||||
<valuemap type="QVariantMap" key="EditorConfiguration.CodeStyle.1">
|
||||
<value type="QString" key="language">QmlJS</value>
|
||||
<valuemap type="QVariantMap" key="value">
|
||||
<value type="QByteArray" key="CurrentPreferences">QmlJSGlobal</value>
|
||||
</valuemap>
|
||||
</valuemap>
|
||||
<value type="qlonglong" key="EditorConfiguration.CodeStyle.Count">2</value>
|
||||
<value type="QByteArray" key="EditorConfiguration.Codec">UTF-8</value>
|
||||
<value type="bool" key="EditorConfiguration.ConstrainTooltips">false</value>
|
||||
<value type="int" key="EditorConfiguration.IndentSize">4</value>
|
||||
<value type="bool" key="EditorConfiguration.KeyboardTooltips">false</value>
|
||||
<value type="int" key="EditorConfiguration.MarginColumn">80</value>
|
||||
<value type="bool" key="EditorConfiguration.MouseHiding">true</value>
|
||||
<value type="bool" key="EditorConfiguration.MouseNavigation">true</value>
|
||||
<value type="int" key="EditorConfiguration.PaddingMode">1</value>
|
||||
<value type="bool" key="EditorConfiguration.PreferSingleLineComments">false</value>
|
||||
<value type="bool" key="EditorConfiguration.ScrollWheelZooming">true</value>
|
||||
<value type="bool" key="EditorConfiguration.ShowMargin">false</value>
|
||||
<value type="int" key="EditorConfiguration.SmartBackspaceBehavior">0</value>
|
||||
<value type="bool" key="EditorConfiguration.SmartSelectionChanging">true</value>
|
||||
<value type="bool" key="EditorConfiguration.SpacesForTabs">true</value>
|
||||
<value type="int" key="EditorConfiguration.TabKeyBehavior">0</value>
|
||||
<value type="int" key="EditorConfiguration.TabSize">8</value>
|
||||
<value type="bool" key="EditorConfiguration.UseGlobal">true</value>
|
||||
<value type="bool" key="EditorConfiguration.UseIndenter">false</value>
|
||||
<value type="int" key="EditorConfiguration.Utf8BomBehavior">1</value>
|
||||
<value type="bool" key="EditorConfiguration.addFinalNewLine">true</value>
|
||||
<value type="bool" key="EditorConfiguration.cleanIndentation">true</value>
|
||||
<value type="bool" key="EditorConfiguration.cleanWhitespace">true</value>
|
||||
<value type="QString" key="EditorConfiguration.ignoreFileTypes">*.md, *.MD, Makefile</value>
|
||||
<value type="bool" key="EditorConfiguration.inEntireDocument">false</value>
|
||||
<value type="bool" key="EditorConfiguration.skipTrailingWhitespace">true</value>
|
||||
</valuemap>
|
||||
</data>
|
||||
<data>
|
||||
<variable>ProjectExplorer.Project.PluginSettings</variable>
|
||||
<valuemap type="QVariantMap">
|
||||
<valuemap type="QVariantMap" key="AutoTest.ActiveFrameworks">
|
||||
<value type="bool" key="AutoTest.Framework.Boost">true</value>
|
||||
<value type="bool" key="AutoTest.Framework.CTest">false</value>
|
||||
<value type="bool" key="AutoTest.Framework.Catch">true</value>
|
||||
<value type="bool" key="AutoTest.Framework.GTest">true</value>
|
||||
<value type="bool" key="AutoTest.Framework.QtQuickTest">true</value>
|
||||
<value type="bool" key="AutoTest.Framework.QtTest">true</value>
|
||||
</valuemap>
|
||||
<valuemap type="QVariantMap" key="AutoTest.CheckStates"/>
|
||||
<value type="int" key="AutoTest.RunAfterBuild">0</value>
|
||||
<value type="bool" key="AutoTest.UseGlobal">true</value>
|
||||
<valuelist type="QVariantList" key="ClangCodeModel.CustomCommandLineKey"/>
|
||||
<value type="bool" key="ClangCodeModel.UseGlobalConfig">true</value>
|
||||
<value type="QString" key="ClangCodeModel.WarningConfigId">Builtin.BuildSystem</value>
|
||||
<valuemap type="QVariantMap" key="ClangTools">
|
||||
<value type="bool" key="ClangTools.AnalyzeOpenFiles">true</value>
|
||||
<value type="bool" key="ClangTools.BuildBeforeAnalysis">true</value>
|
||||
<value type="QString" key="ClangTools.DiagnosticConfig">Builtin.DefaultTidyAndClazy</value>
|
||||
<value type="int" key="ClangTools.ParallelJobs">6</value>
|
||||
<valuelist type="QVariantList" key="ClangTools.SelectedDirs"/>
|
||||
<valuelist type="QVariantList" key="ClangTools.SelectedFiles"/>
|
||||
<valuelist type="QVariantList" key="ClangTools.SuppressedDiagnostics"/>
|
||||
<value type="bool" key="ClangTools.UseGlobalSettings">true</value>
|
||||
</valuemap>
|
||||
</valuemap>
|
||||
</data>
|
||||
<data>
|
||||
<variable>ProjectExplorer.Project.Target.0</variable>
|
||||
<valuemap type="QVariantMap">
|
||||
<value type="QString" key="DeviceType">Desktop</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">桌面</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">桌面</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">{48745b8a-7a2c-4140-8a9d-588a7c4ae2fe}</value>
|
||||
<value type="qlonglong" key="ProjectExplorer.Target.ActiveBuildConfiguration">0</value>
|
||||
<value type="qlonglong" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
|
||||
<value type="qlonglong" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0">
|
||||
<value type="int" key="EnableQmlDebugging">0</value>
|
||||
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/mnt/Dell/Gtk_Dev/testing-repository/Qt5/build-simplebrowser-unknown-Debug</value>
|
||||
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory.shadowDir">/mnt/Dell/Gtk_Dev/testing-repository/Qt5/build-simplebrowser-unknown-Debug</value>
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
|
||||
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">QtProjectManager.QMakeBuildStep</value>
|
||||
<value type="bool" key="QtProjectManager.QMakeBuildStep.QMakeForced">false</value>
|
||||
<valuelist type="QVariantList" key="QtProjectManager.QMakeBuildStep.SelectedAbis"/>
|
||||
</valuemap>
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.1">
|
||||
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value>
|
||||
</valuemap>
|
||||
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">2</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Build</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Build</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Build</value>
|
||||
</valuemap>
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.1">
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
|
||||
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value>
|
||||
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeArguments">clean</value>
|
||||
</valuemap>
|
||||
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Clean</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Clean</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value>
|
||||
</valuemap>
|
||||
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">2</value>
|
||||
<value type="bool" key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment">false</value>
|
||||
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.CustomParsers"/>
|
||||
<value type="bool" key="ProjectExplorer.BuildConfiguration.ParseStandardOutput">false</value>
|
||||
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"/>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Debug</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4BuildConfiguration</value>
|
||||
<value type="int" key="Qt4ProjectManager.Qt4BuildConfiguration.BuildConfiguration">2</value>
|
||||
</valuemap>
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.1">
|
||||
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/mnt/Dell/Gtk_Dev/testing-repository/Qt5/build-simplebrowser-unknown-Release</value>
|
||||
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory.shadowDir">/mnt/Dell/Gtk_Dev/testing-repository/Qt5/build-simplebrowser-unknown-Release</value>
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
|
||||
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">QtProjectManager.QMakeBuildStep</value>
|
||||
<value type="bool" key="QtProjectManager.QMakeBuildStep.QMakeForced">false</value>
|
||||
<valuelist type="QVariantList" key="QtProjectManager.QMakeBuildStep.SelectedAbis"/>
|
||||
</valuemap>
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.1">
|
||||
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value>
|
||||
</valuemap>
|
||||
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">2</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Build</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Build</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Build</value>
|
||||
</valuemap>
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.1">
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
|
||||
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value>
|
||||
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeArguments">clean</value>
|
||||
</valuemap>
|
||||
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Clean</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Clean</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value>
|
||||
</valuemap>
|
||||
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">2</value>
|
||||
<value type="bool" key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment">false</value>
|
||||
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.CustomParsers"/>
|
||||
<value type="bool" key="ProjectExplorer.BuildConfiguration.ParseStandardOutput">false</value>
|
||||
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"/>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Release</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4BuildConfiguration</value>
|
||||
<value type="int" key="Qt4ProjectManager.Qt4BuildConfiguration.BuildConfiguration">0</value>
|
||||
<value type="int" key="QtQuickCompiler">0</value>
|
||||
</valuemap>
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.2">
|
||||
<value type="int" key="EnableQmlDebugging">0</value>
|
||||
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/mnt/Dell/Gtk_Dev/testing-repository/Qt5/build-simplebrowser-unknown-Profile</value>
|
||||
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory.shadowDir">/mnt/Dell/Gtk_Dev/testing-repository/Qt5/build-simplebrowser-unknown-Profile</value>
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
|
||||
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">QtProjectManager.QMakeBuildStep</value>
|
||||
<value type="bool" key="QtProjectManager.QMakeBuildStep.QMakeForced">false</value>
|
||||
<valuelist type="QVariantList" key="QtProjectManager.QMakeBuildStep.SelectedAbis"/>
|
||||
</valuemap>
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.1">
|
||||
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value>
|
||||
</valuemap>
|
||||
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">2</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Build</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Build</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Build</value>
|
||||
</valuemap>
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.1">
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
|
||||
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value>
|
||||
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeArguments">clean</value>
|
||||
</valuemap>
|
||||
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Clean</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Clean</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value>
|
||||
</valuemap>
|
||||
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">2</value>
|
||||
<value type="bool" key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment">false</value>
|
||||
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.CustomParsers"/>
|
||||
<value type="bool" key="ProjectExplorer.BuildConfiguration.ParseStandardOutput">false</value>
|
||||
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"/>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Profile</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4BuildConfiguration</value>
|
||||
<value type="int" key="Qt4ProjectManager.Qt4BuildConfiguration.BuildConfiguration">0</value>
|
||||
<value type="int" key="QtQuickCompiler">0</value>
|
||||
<value type="int" key="SeparateDebugInfo">0</value>
|
||||
</valuemap>
|
||||
<value type="qlonglong" key="ProjectExplorer.Target.BuildConfigurationCount">3</value>
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.Target.DeployConfiguration.0">
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
|
||||
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">0</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Deploy</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Deploy</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Deploy</value>
|
||||
</valuemap>
|
||||
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">1</value>
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.DeployConfiguration.CustomData"/>
|
||||
<value type="bool" key="ProjectExplorer.DeployConfiguration.CustomDataEnabled">false</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.DefaultDeployConfiguration</value>
|
||||
</valuemap>
|
||||
<value type="qlonglong" key="ProjectExplorer.Target.DeployConfigurationCount">1</value>
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.Target.RunConfiguration.0">
|
||||
<value type="bool" key="Analyzer.Perf.Settings.UseGlobalSettings">true</value>
|
||||
<value type="bool" key="Analyzer.QmlProfiler.Settings.UseGlobalSettings">true</value>
|
||||
<value type="bool" key="Analyzer.Valgrind.Settings.UseGlobalSettings">true</value>
|
||||
<valuelist type="QVariantList" key="CustomOutputParsers"/>
|
||||
<value type="int" key="PE.EnvironmentAspect.Base">2</value>
|
||||
<valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4RunConfiguration:/mnt/Dell/Gtk_Dev/testing-repository/Qt5/simplebrowser/simplebrowser.pro</value>
|
||||
<value type="QString" key="ProjectExplorer.RunConfiguration.BuildKey">/mnt/Dell/Gtk_Dev/testing-repository/Qt5/simplebrowser/simplebrowser.pro</value>
|
||||
<value type="bool" key="RunConfiguration.UseCppDebugger">false</value>
|
||||
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>
|
||||
<value type="bool" key="RunConfiguration.UseLibrarySearchPath">true</value>
|
||||
<value type="bool" key="RunConfiguration.UseQmlDebugger">false</value>
|
||||
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
|
||||
<value type="QString" key="RunConfiguration.WorkingDirectory.default">/mnt/Dell/Gtk_Dev/testing-repository/Qt5/build-simplebrowser-unknown-Debug</value>
|
||||
</valuemap>
|
||||
<value type="qlonglong" key="ProjectExplorer.Target.RunConfigurationCount">1</value>
|
||||
</valuemap>
|
||||
</data>
|
||||
<data>
|
||||
<variable>ProjectExplorer.Project.TargetCount</variable>
|
||||
<value type="qlonglong">1</value>
|
||||
</data>
|
||||
<data>
|
||||
<variable>ProjectExplorer.Project.Updater.FileVersion</variable>
|
||||
<value type="int">22</value>
|
||||
</data>
|
||||
<data>
|
||||
<variable>Version</variable>
|
||||
<value type="int">22</value>
|
||||
</data>
|
||||
</qtcreator>
|
|
@ -0,0 +1,305 @@
|
|||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of the examples of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:BSD$
|
||||
** 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 The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** BSD License Usage
|
||||
** Alternatively, 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 The Qt Company Ltd 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 "tabwidget.h"
|
||||
#include "webpage.h"
|
||||
#include "webview.h"
|
||||
#include <QLabel>
|
||||
#include <QMenu>
|
||||
#include <QTabBar>
|
||||
#include <QWebEngineProfile>
|
||||
|
||||
TabWidget::TabWidget(QWebEngineProfile *profile, QWidget *parent)
|
||||
: QTabWidget(parent)
|
||||
, m_profile(profile)
|
||||
{
|
||||
QTabBar *tabBar = this->tabBar();
|
||||
tabBar->setTabsClosable(true);
|
||||
tabBar->setSelectionBehaviorOnRemove(QTabBar::SelectPreviousTab);
|
||||
tabBar->setMovable(true);
|
||||
tabBar->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
connect(tabBar, &QTabBar::customContextMenuRequested, this, &TabWidget::handleContextMenuRequested);
|
||||
connect(tabBar, &QTabBar::tabCloseRequested, this, &TabWidget::closeTab);
|
||||
connect(tabBar, &QTabBar::tabBarDoubleClicked, [this](int index) {
|
||||
if (index == -1)
|
||||
createTab();
|
||||
});
|
||||
|
||||
setDocumentMode(true);
|
||||
setElideMode(Qt::ElideRight);
|
||||
|
||||
connect(this, &QTabWidget::currentChanged, this, &TabWidget::handleCurrentChanged);
|
||||
|
||||
if (profile->isOffTheRecord()) {
|
||||
QLabel *icon = new QLabel(this);
|
||||
QPixmap pixmap(QStringLiteral(":ninja.png"));
|
||||
icon->setPixmap(pixmap.scaledToHeight(tabBar->height()));
|
||||
setStyleSheet(QStringLiteral("QTabWidget::tab-bar { left: %1px; }").
|
||||
arg(icon->pixmap()->width()));
|
||||
}
|
||||
}
|
||||
|
||||
void TabWidget::handleCurrentChanged(int index)
|
||||
{
|
||||
if (index != -1) {
|
||||
WebView *view = webView(index);
|
||||
if (!view->url().isEmpty())
|
||||
view->setFocus();
|
||||
emit titleChanged(view->title());
|
||||
emit loadProgress(view->loadProgress());
|
||||
emit urlChanged(view->url());
|
||||
emit favIconChanged(view->favIcon());
|
||||
emit webActionEnabledChanged(QWebEnginePage::Back, view->isWebActionEnabled(QWebEnginePage::Back));
|
||||
emit webActionEnabledChanged(QWebEnginePage::Forward, view->isWebActionEnabled(QWebEnginePage::Forward));
|
||||
emit webActionEnabledChanged(QWebEnginePage::Stop, view->isWebActionEnabled(QWebEnginePage::Stop));
|
||||
emit webActionEnabledChanged(QWebEnginePage::Reload,view->isWebActionEnabled(QWebEnginePage::Reload));
|
||||
} else {
|
||||
emit titleChanged(QString());
|
||||
emit loadProgress(0);
|
||||
emit urlChanged(QUrl());
|
||||
emit favIconChanged(QIcon());
|
||||
emit webActionEnabledChanged(QWebEnginePage::Back, false);
|
||||
emit webActionEnabledChanged(QWebEnginePage::Forward, false);
|
||||
emit webActionEnabledChanged(QWebEnginePage::Stop, false);
|
||||
emit webActionEnabledChanged(QWebEnginePage::Reload, true);
|
||||
}
|
||||
}
|
||||
|
||||
void TabWidget::handleContextMenuRequested(const QPoint &pos)
|
||||
{
|
||||
QMenu menu;
|
||||
menu.addAction(tr("New &Tab"), this, &TabWidget::createTab, QKeySequence::AddTab);
|
||||
int index = tabBar()->tabAt(pos);
|
||||
if (index != -1) {
|
||||
QAction *action = menu.addAction(tr("Clone Tab"));
|
||||
connect(action, &QAction::triggered, this, [this,index]() {
|
||||
cloneTab(index);
|
||||
});
|
||||
menu.addSeparator();
|
||||
action = menu.addAction(tr("&Close Tab"));
|
||||
action->setShortcut(QKeySequence::Close);
|
||||
connect(action, &QAction::triggered, this, [this,index]() {
|
||||
closeTab(index);
|
||||
});
|
||||
action = menu.addAction(tr("Close &Other Tabs"));
|
||||
connect(action, &QAction::triggered, this, [this,index]() {
|
||||
closeOtherTabs(index);
|
||||
});
|
||||
menu.addSeparator();
|
||||
action = menu.addAction(tr("Reload Tab"));
|
||||
action->setShortcut(QKeySequence::Refresh);
|
||||
connect(action, &QAction::triggered, this, [this,index]() {
|
||||
reloadTab(index);
|
||||
});
|
||||
} else {
|
||||
menu.addSeparator();
|
||||
}
|
||||
menu.addAction(tr("Reload All Tabs"), this, &TabWidget::reloadAllTabs);
|
||||
menu.exec(QCursor::pos());
|
||||
}
|
||||
|
||||
WebView *TabWidget::currentWebView() const
|
||||
{
|
||||
return webView(currentIndex());
|
||||
}
|
||||
|
||||
WebView *TabWidget::webView(int index) const
|
||||
{
|
||||
return qobject_cast<WebView*>(widget(index));
|
||||
}
|
||||
|
||||
void TabWidget::setupView(WebView *webView)
|
||||
{
|
||||
QWebEnginePage *webPage = webView->page();
|
||||
|
||||
connect(webView, &QWebEngineView::titleChanged, [this, webView](const QString &title) {
|
||||
int index = indexOf(webView);
|
||||
if (index != -1) {
|
||||
setTabText(index, title);
|
||||
setTabToolTip(index, title);
|
||||
}
|
||||
if (currentIndex() == index)
|
||||
emit titleChanged(title);
|
||||
});
|
||||
connect(webView, &QWebEngineView::urlChanged, [this, webView](const QUrl &url) {
|
||||
int index = indexOf(webView);
|
||||
if (index != -1)
|
||||
tabBar()->setTabData(index, url);
|
||||
if (currentIndex() == index)
|
||||
emit urlChanged(url);
|
||||
});
|
||||
connect(webView, &QWebEngineView::loadProgress, [this, webView](int progress) {
|
||||
if (currentIndex() == indexOf(webView))
|
||||
emit loadProgress(progress);
|
||||
});
|
||||
connect(webPage, &QWebEnginePage::linkHovered, [this, webView](const QString &url) {
|
||||
if (currentIndex() == indexOf(webView))
|
||||
emit linkHovered(url);
|
||||
});
|
||||
connect(webView, &WebView::favIconChanged, [this, webView](const QIcon &icon) {
|
||||
int index = indexOf(webView);
|
||||
if (index != -1)
|
||||
setTabIcon(index, icon);
|
||||
if (currentIndex() == index)
|
||||
emit favIconChanged(icon);
|
||||
});
|
||||
connect(webView, &WebView::webActionEnabledChanged, [this, webView](QWebEnginePage::WebAction action, bool enabled) {
|
||||
if (currentIndex() == indexOf(webView))
|
||||
emit webActionEnabledChanged(action,enabled);
|
||||
});
|
||||
connect(webPage, &QWebEnginePage::windowCloseRequested, [this, webView]() {
|
||||
int index = indexOf(webView);
|
||||
if (webView->page()->inspectedPage())
|
||||
window()->close();
|
||||
else if (index >= 0)
|
||||
closeTab(index);
|
||||
});
|
||||
connect(webView, &WebView::devToolsRequested, this, &TabWidget::devToolsRequested);
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
|
||||
connect(webPage, &QWebEnginePage::findTextFinished, [this, webView](const QWebEngineFindTextResult &result) {
|
||||
if (currentIndex() == indexOf(webView))
|
||||
emit findTextFinished(result);
|
||||
});
|
||||
#endif
|
||||
}
|
||||
|
||||
WebView *TabWidget::createTab()
|
||||
{
|
||||
WebView *webView = createBackgroundTab();
|
||||
setCurrentWidget(webView);
|
||||
return webView;
|
||||
}
|
||||
|
||||
WebView *TabWidget::createBackgroundTab()
|
||||
{
|
||||
WebView *webView = new WebView;
|
||||
WebPage *webPage = new WebPage(m_profile, webView);
|
||||
webView->setPage(webPage);
|
||||
setupView(webView);
|
||||
int index = addTab(webView, tr("(Untitled)"));
|
||||
setTabIcon(index, webView->favIcon());
|
||||
// Workaround for QTBUG-61770
|
||||
webView->resize(currentWidget()->size());
|
||||
webView->show();
|
||||
return webView;
|
||||
}
|
||||
|
||||
void TabWidget::reloadAllTabs()
|
||||
{
|
||||
for (int i = 0; i < count(); ++i)
|
||||
webView(i)->reload();
|
||||
}
|
||||
|
||||
void TabWidget::closeOtherTabs(int index)
|
||||
{
|
||||
for (int i = count() - 1; i > index; --i)
|
||||
closeTab(i);
|
||||
for (int i = index - 1; i >= 0; --i)
|
||||
closeTab(i);
|
||||
}
|
||||
|
||||
void TabWidget::closeTab(int index)
|
||||
{
|
||||
if (WebView *view = webView(index)) {
|
||||
bool hasFocus = view->hasFocus();
|
||||
removeTab(index);
|
||||
if (hasFocus && count() > 0)
|
||||
currentWebView()->setFocus();
|
||||
if (count() == 0)
|
||||
createTab();
|
||||
view->deleteLater();
|
||||
}
|
||||
}
|
||||
|
||||
void TabWidget::cloneTab(int index)
|
||||
{
|
||||
if (WebView *view = webView(index)) {
|
||||
WebView *tab = createTab();
|
||||
tab->setUrl(view->url());
|
||||
}
|
||||
}
|
||||
|
||||
void TabWidget::setUrl(const QUrl &url)
|
||||
{
|
||||
if (WebView *view = currentWebView()) {
|
||||
view->setUrl(url);
|
||||
view->setFocus();
|
||||
}
|
||||
}
|
||||
|
||||
void TabWidget::triggerWebPageAction(QWebEnginePage::WebAction action)
|
||||
{
|
||||
if (WebView *webView = currentWebView()) {
|
||||
webView->triggerPageAction(action);
|
||||
webView->setFocus();
|
||||
}
|
||||
}
|
||||
|
||||
void TabWidget::nextTab()
|
||||
{
|
||||
int next = currentIndex() + 1;
|
||||
if (next == count())
|
||||
next = 0;
|
||||
setCurrentIndex(next);
|
||||
}
|
||||
|
||||
void TabWidget::previousTab()
|
||||
{
|
||||
int next = currentIndex() - 1;
|
||||
if (next < 0)
|
||||
next = count() - 1;
|
||||
setCurrentIndex(next);
|
||||
}
|
||||
|
||||
void TabWidget::reloadTab(int index)
|
||||
{
|
||||
if (WebView *view = webView(index))
|
||||
view->reload();
|
||||
}
|
|
@ -0,0 +1,111 @@
|
|||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of the examples of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:BSD$
|
||||
** 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 The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** BSD License Usage
|
||||
** Alternatively, 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 The Qt Company Ltd 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$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef TABWIDGET_H
|
||||
#define TABWIDGET_H
|
||||
|
||||
#include <QTabWidget>
|
||||
#include <QWebEnginePage>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QUrl;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
class WebView;
|
||||
|
||||
class TabWidget : public QTabWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
TabWidget(QWebEngineProfile *profile, QWidget *parent = nullptr);
|
||||
|
||||
WebView *currentWebView() const;
|
||||
|
||||
signals:
|
||||
// current tab/page signals
|
||||
void linkHovered(const QString &link);
|
||||
void loadProgress(int progress);
|
||||
void titleChanged(const QString &title);
|
||||
void urlChanged(const QUrl &url);
|
||||
void favIconChanged(const QIcon &icon);
|
||||
void webActionEnabledChanged(QWebEnginePage::WebAction action, bool enabled);
|
||||
void devToolsRequested(QWebEnginePage *source);
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
|
||||
void findTextFinished(const QWebEngineFindTextResult &result);
|
||||
#endif
|
||||
|
||||
public slots:
|
||||
// current tab/page slots
|
||||
void setUrl(const QUrl &url);
|
||||
void triggerWebPageAction(QWebEnginePage::WebAction action);
|
||||
|
||||
WebView *createTab();
|
||||
WebView *createBackgroundTab();
|
||||
void closeTab(int index);
|
||||
void nextTab();
|
||||
void previousTab();
|
||||
|
||||
private slots:
|
||||
void handleCurrentChanged(int index);
|
||||
void handleContextMenuRequested(const QPoint &pos);
|
||||
void cloneTab(int index);
|
||||
void closeOtherTabs(int index);
|
||||
void reloadAllTabs();
|
||||
void reloadTab(int index);
|
||||
|
||||
private:
|
||||
WebView *webView(int index) const;
|
||||
void setupView(WebView *webView);
|
||||
|
||||
QWebEngineProfile *m_profile;
|
||||
};
|
||||
|
||||
#endif // TABWIDGET_H
|
|
@ -0,0 +1,230 @@
|
|||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of the examples of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:BSD$
|
||||
** 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 The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** BSD License Usage
|
||||
** Alternatively, 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 The Qt Company Ltd 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 "browserwindow.h"
|
||||
#include "tabwidget.h"
|
||||
#include "ui_certificateerrordialog.h"
|
||||
#include "ui_passworddialog.h"
|
||||
#include "webpage.h"
|
||||
#include "webview.h"
|
||||
#include <QAuthenticator>
|
||||
#include <QMessageBox>
|
||||
#include <QStyle>
|
||||
#include <QTimer>
|
||||
#include <QWebEngineCertificateError>
|
||||
|
||||
WebPage::WebPage(QWebEngineProfile *profile, QObject *parent)
|
||||
: QWebEnginePage(profile, parent)
|
||||
{
|
||||
connect(this, &QWebEnginePage::authenticationRequired, this, &WebPage::handleAuthenticationRequired);
|
||||
connect(this, &QWebEnginePage::featurePermissionRequested, this, &WebPage::handleFeaturePermissionRequested);
|
||||
connect(this, &QWebEnginePage::proxyAuthenticationRequired, this, &WebPage::handleProxyAuthenticationRequired);
|
||||
connect(this, &QWebEnginePage::registerProtocolHandlerRequested, this, &WebPage::handleRegisterProtocolHandlerRequested);
|
||||
#if !defined(QT_NO_SSL) || QT_VERSION >= QT_VERSION_CHECK(5, 12, 0)
|
||||
connect(this, &QWebEnginePage::selectClientCertificate, this, &WebPage::handleSelectClientCertificate);
|
||||
#endif
|
||||
}
|
||||
|
||||
bool WebPage::certificateError(const QWebEngineCertificateError &error)
|
||||
{
|
||||
QWidget *mainWindow = view()->window();
|
||||
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
|
||||
QWebEngineCertificateError deferredError = error;
|
||||
deferredError.defer();
|
||||
|
||||
QTimer::singleShot(0, mainWindow, [mainWindow, error = std::move(deferredError)] () mutable {
|
||||
if (!error.deferred()) {
|
||||
QMessageBox::critical(mainWindow, tr("Certificate Error"), error.errorDescription());
|
||||
} else {
|
||||
#else
|
||||
if (error.isOverridable()) {
|
||||
#endif
|
||||
QDialog dialog(mainWindow);
|
||||
dialog.setModal(true);
|
||||
dialog.setWindowFlags(dialog.windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
||||
|
||||
Ui::CertificateErrorDialog certificateDialog;
|
||||
certificateDialog.setupUi(&dialog);
|
||||
certificateDialog.m_iconLabel->setText(QString());
|
||||
QIcon icon(mainWindow->style()->standardIcon(QStyle::SP_MessageBoxWarning, 0, mainWindow));
|
||||
certificateDialog.m_iconLabel->setPixmap(icon.pixmap(32, 32));
|
||||
certificateDialog.m_errorLabel->setText(error.errorDescription());
|
||||
dialog.setWindowTitle(tr("Certificate Error"));
|
||||
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
|
||||
if (dialog.exec() == QDialog::Accepted)
|
||||
error.ignoreCertificateError();
|
||||
else
|
||||
error.rejectCertificate();
|
||||
}
|
||||
});
|
||||
return true;
|
||||
#else
|
||||
return dialog.exec() == QDialog::Accepted;
|
||||
}
|
||||
|
||||
QMessageBox::critical(mainWindow, tr("Certificate Error"), error.errorDescription());
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
void WebPage::handleAuthenticationRequired(const QUrl &requestUrl, QAuthenticator *auth)
|
||||
{
|
||||
QWidget *mainWindow = view()->window();
|
||||
QDialog dialog(mainWindow);
|
||||
dialog.setModal(true);
|
||||
dialog.setWindowFlags(dialog.windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
||||
|
||||
Ui::PasswordDialog passwordDialog;
|
||||
passwordDialog.setupUi(&dialog);
|
||||
|
||||
passwordDialog.m_iconLabel->setText(QString());
|
||||
QIcon icon(mainWindow->style()->standardIcon(QStyle::SP_MessageBoxQuestion, 0, mainWindow));
|
||||
passwordDialog.m_iconLabel->setPixmap(icon.pixmap(32, 32));
|
||||
|
||||
QString introMessage(tr("Enter username and password for \"%1\" at %2")
|
||||
.arg(auth->realm()).arg(requestUrl.toString().toHtmlEscaped()));
|
||||
passwordDialog.m_infoLabel->setText(introMessage);
|
||||
passwordDialog.m_infoLabel->setWordWrap(true);
|
||||
|
||||
if (dialog.exec() == QDialog::Accepted) {
|
||||
auth->setUser(passwordDialog.m_userNameLineEdit->text());
|
||||
auth->setPassword(passwordDialog.m_passwordLineEdit->text());
|
||||
} else {
|
||||
// Set authenticator null if dialog is cancelled
|
||||
*auth = QAuthenticator();
|
||||
}
|
||||
}
|
||||
|
||||
inline QString questionForFeature(QWebEnginePage::Feature feature)
|
||||
{
|
||||
switch (feature) {
|
||||
case QWebEnginePage::Geolocation:
|
||||
return WebPage::tr("Allow %1 to access your location information?");
|
||||
case QWebEnginePage::MediaAudioCapture:
|
||||
return WebPage::tr("Allow %1 to access your microphone?");
|
||||
case QWebEnginePage::MediaVideoCapture:
|
||||
return WebPage::tr("Allow %1 to access your webcam?");
|
||||
case QWebEnginePage::MediaAudioVideoCapture:
|
||||
return WebPage::tr("Allow %1 to access your microphone and webcam?");
|
||||
case QWebEnginePage::MouseLock:
|
||||
return WebPage::tr("Allow %1 to lock your mouse cursor?");
|
||||
case QWebEnginePage::DesktopVideoCapture:
|
||||
return WebPage::tr("Allow %1 to capture video of your desktop?");
|
||||
case QWebEnginePage::DesktopAudioVideoCapture:
|
||||
return WebPage::tr("Allow %1 to capture audio and video of your desktop?");
|
||||
case QWebEnginePage::Notifications:
|
||||
return WebPage::tr("Allow %1 to show notification on your desktop?");
|
||||
}
|
||||
return QString();
|
||||
}
|
||||
|
||||
void WebPage::handleFeaturePermissionRequested(const QUrl &securityOrigin, Feature feature)
|
||||
{
|
||||
QString title = tr("Permission Request");
|
||||
QString question = questionForFeature(feature).arg(securityOrigin.host());
|
||||
if (!question.isEmpty() && QMessageBox::question(view()->window(), title, question) == QMessageBox::Yes)
|
||||
setFeaturePermission(securityOrigin, feature, PermissionGrantedByUser);
|
||||
else
|
||||
setFeaturePermission(securityOrigin, feature, PermissionDeniedByUser);
|
||||
}
|
||||
|
||||
void WebPage::handleProxyAuthenticationRequired(const QUrl &, QAuthenticator *auth, const QString &proxyHost)
|
||||
{
|
||||
QWidget *mainWindow = view()->window();
|
||||
QDialog dialog(mainWindow);
|
||||
dialog.setModal(true);
|
||||
dialog.setWindowFlags(dialog.windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
||||
|
||||
Ui::PasswordDialog passwordDialog;
|
||||
passwordDialog.setupUi(&dialog);
|
||||
|
||||
passwordDialog.m_iconLabel->setText(QString());
|
||||
QIcon icon(mainWindow->style()->standardIcon(QStyle::SP_MessageBoxQuestion, 0, mainWindow));
|
||||
passwordDialog.m_iconLabel->setPixmap(icon.pixmap(32, 32));
|
||||
|
||||
QString introMessage = tr("Connect to proxy \"%1\" using:");
|
||||
introMessage = introMessage.arg(proxyHost.toHtmlEscaped());
|
||||
passwordDialog.m_infoLabel->setText(introMessage);
|
||||
passwordDialog.m_infoLabel->setWordWrap(true);
|
||||
|
||||
if (dialog.exec() == QDialog::Accepted) {
|
||||
auth->setUser(passwordDialog.m_userNameLineEdit->text());
|
||||
auth->setPassword(passwordDialog.m_passwordLineEdit->text());
|
||||
} else {
|
||||
// Set authenticator null if dialog is cancelled
|
||||
*auth = QAuthenticator();
|
||||
}
|
||||
}
|
||||
|
||||
//! [registerProtocolHandlerRequested]
|
||||
void WebPage::handleRegisterProtocolHandlerRequested(QWebEngineRegisterProtocolHandlerRequest request)
|
||||
{
|
||||
auto answer = QMessageBox::question(
|
||||
view()->window(),
|
||||
tr("Permission Request"),
|
||||
tr("Allow %1 to open all %2 links?")
|
||||
.arg(request.origin().host())
|
||||
.arg(request.scheme()));
|
||||
if (answer == QMessageBox::Yes)
|
||||
request.accept();
|
||||
else
|
||||
request.reject();
|
||||
}
|
||||
//! [registerProtocolHandlerRequested]
|
||||
|
||||
#if !defined(QT_NO_SSL) || QT_VERSION >= QT_VERSION_CHECK(5, 12, 0)
|
||||
void WebPage::handleSelectClientCertificate(QWebEngineClientCertificateSelection selection)
|
||||
{
|
||||
// Just select one.
|
||||
selection.select(selection.certificates().at(0));
|
||||
}
|
||||
#endif
|
|
@ -0,0 +1,77 @@
|
|||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of the examples of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:BSD$
|
||||
** 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 The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** BSD License Usage
|
||||
** Alternatively, 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 The Qt Company Ltd 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$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef WEBPAGE_H
|
||||
#define WEBPAGE_H
|
||||
|
||||
#include <QWebEnginePage>
|
||||
#include <QWebEngineRegisterProtocolHandlerRequest>
|
||||
|
||||
class WebPage : public QWebEnginePage
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
WebPage(QWebEngineProfile *profile, QObject *parent = nullptr);
|
||||
|
||||
protected:
|
||||
bool certificateError(const QWebEngineCertificateError &error) override;
|
||||
|
||||
private slots:
|
||||
void handleAuthenticationRequired(const QUrl &requestUrl, QAuthenticator *auth);
|
||||
void handleFeaturePermissionRequested(const QUrl &securityOrigin, Feature feature);
|
||||
void handleProxyAuthenticationRequired(const QUrl &requestUrl, QAuthenticator *auth, const QString &proxyHost);
|
||||
void handleRegisterProtocolHandlerRequested(QWebEngineRegisterProtocolHandlerRequest request);
|
||||
#if !defined(QT_NO_SSL) || QT_VERSION >= QT_VERSION_CHECK(5, 12, 0)
|
||||
void handleSelectClientCertificate(QWebEngineClientCertificateSelection clientCertSelection);
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif // WEBPAGE_H
|
|
@ -0,0 +1,100 @@
|
|||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of the examples of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:BSD$
|
||||
** 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 The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** BSD License Usage
|
||||
** Alternatively, 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 The Qt Company Ltd 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 "webpage.h"
|
||||
#include "webpopupwindow.h"
|
||||
#include "webview.h"
|
||||
#include <QAction>
|
||||
#include <QIcon>
|
||||
#include <QLineEdit>
|
||||
#include <QVBoxLayout>
|
||||
#include <QWindow>
|
||||
|
||||
WebPopupWindow::WebPopupWindow(QWebEngineProfile *profile)
|
||||
: m_urlLineEdit(new QLineEdit(this))
|
||||
, m_favAction(new QAction(this))
|
||||
, m_view(new WebView(this))
|
||||
{
|
||||
setAttribute(Qt::WA_DeleteOnClose);
|
||||
setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
|
||||
|
||||
QVBoxLayout *layout = new QVBoxLayout;
|
||||
layout->setContentsMargins(0, 0, 0, 0);
|
||||
setLayout(layout);
|
||||
layout->addWidget(m_urlLineEdit);
|
||||
layout->addWidget(m_view);
|
||||
|
||||
m_view->setPage(new WebPage(profile, m_view));
|
||||
m_view->setFocus();
|
||||
|
||||
m_urlLineEdit->setReadOnly(true);
|
||||
m_urlLineEdit->addAction(m_favAction, QLineEdit::LeadingPosition);
|
||||
|
||||
connect(m_view, &WebView::titleChanged, this, &QWidget::setWindowTitle);
|
||||
connect(m_view, &WebView::urlChanged, [this](const QUrl &url) {
|
||||
m_urlLineEdit->setText(url.toDisplayString());
|
||||
});
|
||||
connect(m_view, &WebView::favIconChanged, m_favAction, &QAction::setIcon);
|
||||
connect(m_view->page(), &WebPage::geometryChangeRequested, this, &WebPopupWindow::handleGeometryChangeRequested);
|
||||
connect(m_view->page(), &WebPage::windowCloseRequested, this, &QWidget::close);
|
||||
}
|
||||
|
||||
WebView *WebPopupWindow::view() const
|
||||
{
|
||||
return m_view;
|
||||
}
|
||||
|
||||
void WebPopupWindow::handleGeometryChangeRequested(const QRect &newGeometry)
|
||||
{
|
||||
if (QWindow *window = windowHandle())
|
||||
setGeometry(newGeometry.marginsRemoved(window->frameMargins()));
|
||||
show();
|
||||
m_view->setFocus();
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of the examples of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:BSD$
|
||||
** 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 The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** BSD License Usage
|
||||
** Alternatively, 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 The Qt Company Ltd 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$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef WEBPOPUPWINDOW_H
|
||||
#define WEBPOPUPWINDOW_H
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QLineEdit;
|
||||
class QWebEngineProfile;
|
||||
class QWebEngineView;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
class WebView;
|
||||
|
||||
class WebPopupWindow : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
WebPopupWindow(QWebEngineProfile *profile);
|
||||
WebView *view() const;
|
||||
|
||||
private slots:
|
||||
void handleGeometryChangeRequested(const QRect &newGeometry);
|
||||
|
||||
private:
|
||||
QLineEdit *m_urlLineEdit;
|
||||
QAction *m_favAction;
|
||||
WebView *m_view;
|
||||
};
|
||||
#endif // WEBPOPUPWINDOW_H
|
|
@ -0,0 +1,198 @@
|
|||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of the examples of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:BSD$
|
||||
** 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 The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** BSD License Usage
|
||||
** Alternatively, 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 The Qt Company Ltd 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 "browser.h"
|
||||
#include "browserwindow.h"
|
||||
#include "tabwidget.h"
|
||||
#include "webpage.h"
|
||||
#include "webpopupwindow.h"
|
||||
#include "webview.h"
|
||||
#include <QContextMenuEvent>
|
||||
#include <QDebug>
|
||||
#include <QMenu>
|
||||
#include <QMessageBox>
|
||||
#include <QTimer>
|
||||
|
||||
WebView::WebView(QWidget *parent)
|
||||
: QWebEngineView(parent)
|
||||
, m_loadProgress(100)
|
||||
{
|
||||
connect(this, &QWebEngineView::loadStarted, [this]() {
|
||||
m_loadProgress = 0;
|
||||
emit favIconChanged(favIcon());
|
||||
});
|
||||
connect(this, &QWebEngineView::loadProgress, [this](int progress) {
|
||||
m_loadProgress = progress;
|
||||
});
|
||||
connect(this, &QWebEngineView::loadFinished, [this](bool success) {
|
||||
m_loadProgress = success ? 100 : -1;
|
||||
emit favIconChanged(favIcon());
|
||||
});
|
||||
connect(this, &QWebEngineView::iconChanged, [this](const QIcon &) {
|
||||
emit favIconChanged(favIcon());
|
||||
});
|
||||
|
||||
connect(this, &QWebEngineView::renderProcessTerminated,
|
||||
[this](QWebEnginePage::RenderProcessTerminationStatus termStatus, int statusCode) {
|
||||
QString status;
|
||||
switch (termStatus) {
|
||||
case QWebEnginePage::NormalTerminationStatus:
|
||||
status = tr("Render process normal exit");
|
||||
break;
|
||||
case QWebEnginePage::AbnormalTerminationStatus:
|
||||
status = tr("Render process abnormal exit");
|
||||
break;
|
||||
case QWebEnginePage::CrashedTerminationStatus:
|
||||
status = tr("Render process crashed");
|
||||
break;
|
||||
case QWebEnginePage::KilledTerminationStatus:
|
||||
status = tr("Render process killed");
|
||||
break;
|
||||
}
|
||||
QMessageBox::StandardButton btn = QMessageBox::question(window(), status,
|
||||
tr("Render process exited with code: %1\n"
|
||||
"Do you want to reload the page ?").arg(statusCode));
|
||||
if (btn == QMessageBox::Yes)
|
||||
QTimer::singleShot(0, [this] { reload(); });
|
||||
});
|
||||
}
|
||||
|
||||
void WebView::setPage(WebPage *page)
|
||||
{
|
||||
createWebActionTrigger(page,QWebEnginePage::Forward);
|
||||
createWebActionTrigger(page,QWebEnginePage::Back);
|
||||
createWebActionTrigger(page,QWebEnginePage::Reload);
|
||||
createWebActionTrigger(page,QWebEnginePage::Stop);
|
||||
QWebEngineView::setPage(page);
|
||||
}
|
||||
|
||||
int WebView::loadProgress() const
|
||||
{
|
||||
return m_loadProgress;
|
||||
}
|
||||
|
||||
void WebView::createWebActionTrigger(QWebEnginePage *page, QWebEnginePage::WebAction webAction)
|
||||
{
|
||||
QAction *action = page->action(webAction);
|
||||
connect(action, &QAction::changed, [this, action, webAction]{
|
||||
emit webActionEnabledChanged(webAction, action->isEnabled());
|
||||
});
|
||||
}
|
||||
|
||||
bool WebView::isWebActionEnabled(QWebEnginePage::WebAction webAction) const
|
||||
{
|
||||
return page()->action(webAction)->isEnabled();
|
||||
}
|
||||
|
||||
QIcon WebView::favIcon() const
|
||||
{
|
||||
QIcon favIcon = icon();
|
||||
if (!favIcon.isNull())
|
||||
return favIcon;
|
||||
|
||||
if (m_loadProgress < 0) {
|
||||
static QIcon errorIcon(QStringLiteral(":dialog-error.png"));
|
||||
return errorIcon;
|
||||
} else if (m_loadProgress < 100) {
|
||||
static QIcon loadingIcon(QStringLiteral(":view-refresh.png"));
|
||||
return loadingIcon;
|
||||
} else {
|
||||
static QIcon defaultIcon(QStringLiteral(":text-html.png"));
|
||||
return defaultIcon;
|
||||
}
|
||||
}
|
||||
|
||||
QWebEngineView *WebView::createWindow(QWebEnginePage::WebWindowType type)
|
||||
{
|
||||
BrowserWindow *mainWindow = qobject_cast<BrowserWindow*>(window());
|
||||
if (!mainWindow)
|
||||
return nullptr;
|
||||
|
||||
switch (type) {
|
||||
case QWebEnginePage::WebBrowserTab: {
|
||||
return mainWindow->tabWidget()->createTab();
|
||||
}
|
||||
case QWebEnginePage::WebBrowserBackgroundTab: {
|
||||
return mainWindow->tabWidget()->createBackgroundTab();
|
||||
}
|
||||
case QWebEnginePage::WebBrowserWindow: {
|
||||
return mainWindow->browser()->createWindow()->currentTab();
|
||||
}
|
||||
case QWebEnginePage::WebDialog: {
|
||||
WebPopupWindow *popup = new WebPopupWindow(page()->profile());
|
||||
connect(popup->view(), &WebView::devToolsRequested, this, &WebView::devToolsRequested);
|
||||
return popup->view();
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void WebView::contextMenuEvent(QContextMenuEvent *event)
|
||||
{
|
||||
QMenu *menu = page()->createStandardContextMenu();
|
||||
const QList<QAction *> actions = menu->actions();
|
||||
auto inspectElement = std::find(actions.cbegin(), actions.cend(), page()->action(QWebEnginePage::InspectElement));
|
||||
if (inspectElement == actions.cend()) {
|
||||
auto viewSource = std::find(actions.cbegin(), actions.cend(), page()->action(QWebEnginePage::ViewSource));
|
||||
if (viewSource == actions.cend())
|
||||
menu->addSeparator();
|
||||
|
||||
QAction *action = new QAction(menu);
|
||||
action->setText("Open inspector in new window");
|
||||
connect(action, &QAction::triggered, [this]() { emit devToolsRequested(page()); });
|
||||
|
||||
QAction *before(inspectElement == actions.cend() ? nullptr : *inspectElement);
|
||||
menu->insertAction(before, action);
|
||||
} else {
|
||||
(*inspectElement)->setText(tr("Inspect element"));
|
||||
}
|
||||
menu->popup(event->globalPos());
|
||||
}
|
||||
|
|
@ -0,0 +1,87 @@
|
|||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of the examples of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:BSD$
|
||||
** 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 The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** BSD License Usage
|
||||
** Alternatively, 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 The Qt Company Ltd 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$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef WEBVIEW_H
|
||||
#define WEBVIEW_H
|
||||
|
||||
#include <QIcon>
|
||||
#include <QWebEngineView>
|
||||
|
||||
class WebPage;
|
||||
|
||||
class WebView : public QWebEngineView
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
WebView(QWidget *parent = nullptr);
|
||||
void setPage(WebPage *page);
|
||||
|
||||
int loadProgress() const;
|
||||
bool isWebActionEnabled(QWebEnginePage::WebAction webAction) const;
|
||||
QIcon favIcon() const;
|
||||
|
||||
protected:
|
||||
void contextMenuEvent(QContextMenuEvent *event) override;
|
||||
QWebEngineView *createWindow(QWebEnginePage::WebWindowType type) override;
|
||||
|
||||
signals:
|
||||
void webActionEnabledChanged(QWebEnginePage::WebAction webAction, bool enabled);
|
||||
void favIconChanged(const QIcon &icon);
|
||||
void devToolsRequested(QWebEnginePage *source);
|
||||
|
||||
private:
|
||||
void createWebActionTrigger(QWebEnginePage *page, QWebEnginePage::WebAction);
|
||||
|
||||
private:
|
||||
int m_loadProgress;
|
||||
};
|
||||
|
||||
#endif
|