diff options
Diffstat (limited to 'examples/webenginewidgets/demobrowser/webview.cpp')
-rw-r--r-- | examples/webenginewidgets/demobrowser/webview.cpp | 90 |
1 files changed, 38 insertions, 52 deletions
diff --git a/examples/webenginewidgets/demobrowser/webview.cpp b/examples/webenginewidgets/demobrowser/webview.cpp index 94e872dbf..a785ae48b 100644 --- a/examples/webenginewidgets/demobrowser/webview.cpp +++ b/examples/webenginewidgets/demobrowser/webview.cpp @@ -1,12 +1,22 @@ /**************************************************************************** ** ** Copyright (C) 2016 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ +** Contact: https://www.qt.io/licensing/ ** -** This file is part of the examples of the Qt Toolkit. +** This file is part of the demonstration applications of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: +** 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 @@ -55,9 +65,7 @@ #include <QtWidgets/QMessageBox> #include <QtGui/QMouseEvent> -#if defined(QWEBENGINEPAGE_HITTESTCONTENT) -#include <QWebEngineHitTestResult> -#endif +#include <QWebEngineContextMenuData> #ifndef QT_NO_UITOOLS #include <QtUiTools/QUiLoader> @@ -165,6 +173,8 @@ QWebEnginePage *WebPage::createWindow(QWebEnginePage::WebWindowType type) { if (type == QWebEnginePage::WebBrowserTab) { return mainWindow()->tabWidget()->newTab()->page(); + } else if (type == QWebEnginePage::WebBrowserBackgroundTab) { + return mainWindow()->tabWidget()->newTab(false)->page(); } else if (type == QWebEnginePage::WebBrowserWindow) { BrowserApplication::instance()->newMainWindow(); BrowserMainWindow *mainWindow = BrowserApplication::instance()->mainWindow(); @@ -261,11 +271,8 @@ void WebPage::authenticationRequired(const QUrl &requestUrl, QAuthenticator *aut passwordDialog.introLabel->setWordWrap(true); if (dialog.exec() == QDialog::Accepted) { - QByteArray key = BrowserApplication::authenticationKey(requestUrl, auth->realm()); auth->setUser(passwordDialog.userNameLineEdit->text()); auth->setPassword(passwordDialog.passwordLineEdit->text()); - auth->setOption("key", key); - BrowserApplication::instance()->setLastAuthenticator(auth); } else { // Set authenticator null if dialog is cancelled *auth = QAuthenticator(); @@ -292,12 +299,8 @@ void WebPage::proxyAuthenticationRequired(const QUrl &requestUrl, QAuthenticator proxyDialog.introLabel->setWordWrap(true); if (dialog.exec() == QDialog::Accepted) { - QString user = proxyDialog.userNameLineEdit->text(); - QByteArray key = BrowserApplication::proxyAuthenticationKey(user, proxyHost, auth->realm()); - auth->setUser(user); + auth->setUser(proxyDialog.userNameLineEdit->text()); auth->setPassword(proxyDialog.passwordLineEdit->text()); - auth->setOption("key", key); - BrowserApplication::instance()->setLastProxyAuthenticator(auth); } else { // Set authenticator null if dialog is cancelled *auth = QAuthenticator(); @@ -308,7 +311,6 @@ WebView::WebView(QWidget* parent) : QWebEngineView(parent) , m_progress(0) , m_page(0) - , m_iconReply(0) { connect(this, SIGNAL(loadProgress(int)), this, SLOT(setProgress(int))); @@ -347,8 +349,9 @@ void WebView::setPage(WebPage *_page) connect(page(), SIGNAL(statusBarMessage(QString)), SLOT(setStatusBarText(QString))); #endif - connect(page(), SIGNAL(iconUrlChanged(QUrl)), - this, SLOT(onIconUrlChanged(QUrl))); + disconnect(page(), &QWebEnginePage::iconChanged, this, &WebView::iconChanged); + connect(page(), SIGNAL(iconChanged(QIcon)), + this, SLOT(onIconChanged(QIcon))); connect(page(), &WebPage::featurePermissionRequested, this, &WebView::onFeaturePermissionRequested); #if defined(QWEBENGINEPAGE_UNSUPPORTEDCONTENT) page()->setForwardUnsupportedContent(true); @@ -357,16 +360,20 @@ void WebView::setPage(WebPage *_page) void WebView::contextMenuEvent(QContextMenuEvent *event) { - QMenu *menu = page()->createStandardContextMenu(); - const QList<QAction*> actions = menu->actions(); - QList<QAction*>::const_iterator it = qFind(actions.cbegin(), actions.cend(), page()->action(QWebEnginePage::OpenLinkInThisWindow)); - if (it != actions.cend()) { - (*it)->setText(tr("Open Link in This Window")); - ++it; - QAction *before(it == actions.cend() ? nullptr : *it); - menu->insertAction(before, page()->action(QWebEnginePage::OpenLinkInNewWindow)); - menu->insertAction(before, page()->action(QWebEnginePage::OpenLinkInNewTab)); + QMenu *menu; + if (page()->contextMenuData().linkUrl().isValid()) { + menu = new QMenu(this); + menu->addAction(page()->action(QWebEnginePage::OpenLinkInThisWindow)); + menu->addAction(page()->action(QWebEnginePage::OpenLinkInNewWindow)); + menu->addAction(page()->action(QWebEnginePage::OpenLinkInNewBackgroundTab)); + menu->addSeparator(); + menu->addAction(page()->action(QWebEnginePage::DownloadLinkToDisk)); + menu->addAction(page()->action(QWebEnginePage::CopyLinkToClipboard)); + } else { + menu = page()->createStandardContextMenu(); } + if (page()->contextMenuData().selectedText().isEmpty()) + menu->addAction(page()->action(QWebEnginePage::SavePage)); connect(menu, &QMenu::aboutToHide, menu, &QObject::deleteLater); menu->popup(event->globalPos()); } @@ -435,33 +442,12 @@ QUrl WebView::url() const return m_initialUrl; } -QIcon WebView::icon() const -{ - if (!m_icon.isNull()) - return m_icon; - return BrowserApplication::instance()->defaultIcon(); -} - -void WebView::onIconUrlChanged(const QUrl &url) +void WebView::onIconChanged(const QIcon &icon) { - QNetworkRequest iconRequest(url); - m_iconReply = BrowserApplication::networkAccessManager()->get(iconRequest); - m_iconReply->setParent(this); - connect(m_iconReply, SIGNAL(finished()), this, SLOT(iconLoaded())); -} - -void WebView::iconLoaded() -{ - m_icon = QIcon(); - if (m_iconReply) { - QByteArray data = m_iconReply->readAll(); - QPixmap pixmap; - pixmap.loadFromData(data); - m_icon.addPixmap(pixmap); - m_iconReply->deleteLater(); - m_iconReply = 0; - } - emit iconChanged(); + if (icon.isNull()) + emit iconChanged(BrowserApplication::instance()->defaultIcon()); + else + emit iconChanged(icon); } void WebView::mousePressEvent(QMouseEvent *event) |