From 8292f934246cb283e1b0c32f4388c674f275c7aa Mon Sep 17 00:00:00 2001 From: Soren Stoutner Date: Fri, 12 Aug 2022 14:43:17 -0700 Subject: [PATCH] Implement loading of new tabs from the context menu. --- src/uis/TabWidget.ui | 2 +- src/widgets/PrivacyWebEngineView.cpp | 21 +++++++++++++++++++++ src/widgets/PrivacyWebEngineView.h | 4 ++++ src/widgets/TabWidget.cpp | 6 ++++-- src/widgets/TabWidget.h | 2 +- src/windows/BrowserWindow.h | 4 +++- 6 files changed, 34 insertions(+), 5 deletions(-) diff --git a/src/uis/TabWidget.ui b/src/uis/TabWidget.ui index 3da43c0..2aad7ef 100644 --- a/src/uis/TabWidget.ui +++ b/src/uis/TabWidget.ui @@ -52,8 +52,8 @@ - 24 24 + 24 diff --git a/src/widgets/PrivacyWebEngineView.cpp b/src/widgets/PrivacyWebEngineView.cpp index 28fb66d..10bff6d 100644 --- a/src/widgets/PrivacyWebEngineView.cpp +++ b/src/widgets/PrivacyWebEngineView.cpp @@ -20,6 +20,7 @@ // Application headers. #include "PrivacyWebEngineView.h" #include "databases/CookiesDatabase.h" +#include "windows/BrowserWindow.h" // Construct the class. PrivacyWebEngineView::PrivacyWebEngineView() : QWebEngineView(nullptr) {} @@ -39,6 +40,26 @@ void PrivacyWebEngineView::addCookieToList(const QNetworkCookie &cookie) const emit updateCookiesAction(cookieListPointer->size()); } +QWebEngineView* PrivacyWebEngineView::createWindow(QWebEnginePage::WebWindowType webWindowType) { + qDebug().noquote().nospace() << "Web window type: " << webWindowType; + + // Get a handle for the browser window. + BrowserWindow *browserWindowPointer = qobject_cast(window()); + + // Create the requsted window type. + switch (webWindowType) { + case QWebEnginePage::WebBrowserTab: { + // Create the new tab and return the privacy WebEngine view pointer. It will then be populated with the link from the context menu. + return browserWindowPointer->tabWidgetPointer->addTab(); + } + + default: { + // Return an null pointer. + return nullptr; + } + } +} + void PrivacyWebEngineView::removeCookieFromList(const QNetworkCookie &cookie) const { //qDebug() << "Remove cookie: " << cookie.toRawForm(); diff --git a/src/widgets/PrivacyWebEngineView.h b/src/widgets/PrivacyWebEngineView.h index 3869fc3..8a04957 100644 --- a/src/widgets/PrivacyWebEngineView.h +++ b/src/widgets/PrivacyWebEngineView.h @@ -46,5 +46,9 @@ public Q_SLOTS: // The public slots. void addCookieToList(const QNetworkCookie &cookie) const; void removeCookieFromList(const QNetworkCookie &cookie) const; + +protected: + // The protected functions. + QWebEngineView* createWindow(QWebEnginePage::WebWindowType webWindowType) override; }; #endif diff --git a/src/widgets/TabWidget.cpp b/src/widgets/TabWidget.cpp index 59e4243..ba12f04 100644 --- a/src/widgets/TabWidget.cpp +++ b/src/widgets/TabWidget.cpp @@ -141,7 +141,7 @@ void TabWidget::addFirstTab() tabWidgetPointer->currentWidget()->setFocus(); } -void TabWidget::addTab() +PrivacyWebEngineView* TabWidget::addTab() { // Create a privacy WebEngine view. PrivacyWebEngineView *privacyWebEngineViewPointer = new PrivacyWebEngineView(); @@ -168,7 +168,6 @@ void TabWidget::addTab() // Update the URL line edit when the URL changes. connect(privacyWebEngineViewPointer, SIGNAL(urlChanged(const QUrl)), this, SLOT(updateUrl(const QUrl))); - // Update the progress bar. connect(privacyWebEngineViewPointer, SIGNAL(loadStarted()), this, SLOT(loadStarted())); connect(privacyWebEngineViewPointer, SIGNAL(loadProgress(const int)), this, SLOT(loadProgress(const int))); @@ -290,6 +289,9 @@ void TabWidget::addTab() // Move to the new tab. tabWidgetPointer->setCurrentIndex(newTabIndex); + + // Return the privacy WebEngine view pointer. + return privacyWebEngineViewPointer; } void TabWidget::applyApplicationSettings() diff --git a/src/widgets/TabWidget.h b/src/widgets/TabWidget.h index 525c81a..2b63a63 100644 --- a/src/widgets/TabWidget.h +++ b/src/widgets/TabWidget.h @@ -84,7 +84,7 @@ signals: public Q_SLOTS: // The public slots. - void addTab(); + PrivacyWebEngineView* addTab(); void addCookieToStore(QNetworkCookie cookie, QWebEngineCookieStore *webEngineCookieStorePointer = nullptr) const; void applyApplicationSettings(); void applyDomainSettingsAndReload(); diff --git a/src/windows/BrowserWindow.h b/src/windows/BrowserWindow.h index 39b8e8f..f880cc8 100644 --- a/src/windows/BrowserWindow.h +++ b/src/windows/BrowserWindow.h @@ -45,6 +45,9 @@ public: // The public functions. QSize sizeHint() const override; + // The public variables. + TabWidget *tabWidgetPointer; + private Q_SLOTS: // The private slots. void addOrEditDomainSettings() const; @@ -107,7 +110,6 @@ private: QAction *searchEngineBingActionPointer; QAction *searchEngineYahooActionPointer; QAction *searchEngineCustomActionPointer; - TabWidget *tabWidgetPointer; QLabel *userAgentLabelPointer; QAction *userAgentMenuActionPointer; QAction *userAgentPrivacyBrowserActionPointer; -- 2.43.0