From 3323b83af3bc0cd4feff0e0463718e77d4eabef7 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Wed, 20 Dec 2017 12:53:40 +0100 Subject: Can now open links in new tab --- src/webengine/webview.cpp | 40 ++++++++++++++++++++++++++++++++++++++-- src/webengine/webview.h | 8 ++++++-- 2 files changed, 44 insertions(+), 4 deletions(-) (limited to 'src/webengine') diff --git a/src/webengine/webview.cpp b/src/webengine/webview.cpp index 5463610..ff2780c 100644 --- a/src/webengine/webview.cpp +++ b/src/webengine/webview.cpp @@ -28,9 +28,15 @@ #include #include -WebView::WebView(QWidget *parent) : +#include "mainwindow.h" +#include + +WebView::WebView(MainWindow *parentMainWindow, QWidget *parent) : QWebEngineView(parent) { + Q_CHECK_PTR(parentMainWindow); + m_parent = parentMainWindow; + m_pageMenu = new QMenu(); m_pageMenu->setMinimumWidth(240); @@ -125,7 +131,37 @@ void WebView::setPage(QWebEnginePage *page) QWebEngineView::setPage(page); } +WebView *WebView::createWindow(QWebEnginePage::WebWindowType type) +{ + WebView *view = new WebView(m_parent); + switch (type) { + case QWebEnginePage::WebBrowserWindow: + // a complete web browser window + m_parent->newWindow()->tabBar->addTab(view); + break; + + case QWebEnginePage::WebBrowserTab: + // a web browser tab + m_parent->tabBar->setCurrentIndex(m_parent->tabBar->addTab(view)); + break; + + case QWebEnginePage::WebDialog: + // a window without decorations + m_parent->newWindow()->tabBar->addTab(view); + break; + + case QWebEnginePage::WebBrowserBackgroundTab: + // a web browser tab, but don't swap to it + m_parent->tabBar->addTab(view); + break; + } + + return view; +} + void WebView::handleLinkHovered(const QString &url) { - emit linkHovered(url); + if(isVisible()) { + m_parent->statusBar()->showMessage(url); + } } diff --git a/src/webengine/webview.h b/src/webengine/webview.h index 10654fa..d30a1fd 100644 --- a/src/webengine/webview.h +++ b/src/webengine/webview.h @@ -12,11 +12,12 @@ #include #include +class MainWindow; class WebView : public QWebEngineView { Q_OBJECT public: - explicit WebView(QWidget *parent = nullptr); + explicit WebView(MainWindow *parentMainWindow, QWidget *parent = nullptr); ~WebView(); QMenu *pageMenu(); @@ -24,13 +25,16 @@ public: void setPage(QWebEnginePage *page); signals: - void linkHovered(const QString &url); void newBookmark(const QString &title, const QUrl &url); +protected: + WebView *createWindow(QWebEnginePage::WebWindowType type); + private slots: void handleLinkHovered(const QString &url); private: + MainWindow *m_parent = nullptr; QMenu *m_pageMenu = nullptr; }; -- cgit v1.2.1