From d796821f8304306dbe088701724243b39e8eb358 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Mon, 16 Apr 2018 17:07:36 +0200 Subject: Multiple subwindows interface Subwindows are similar to tab groups. - Rewrote Browser and MainWindow, so they should be somewhat cleaner now - Moved AboutDialog to lib/about What's broken: - loading bar - search box - address bar bookmark suggestions - plugins --- src/webengine/webview.cpp | 47 ++++++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 23 deletions(-) (limited to 'src/webengine/webview.cpp') diff --git a/src/webengine/webview.cpp b/src/webengine/webview.cpp index 7734aa0..d145d2b 100644 --- a/src/webengine/webview.cpp +++ b/src/webengine/webview.cpp @@ -7,19 +7,23 @@ */ #include "webview.h" -#include "mainwindow/mainwindow.h" -#include "mainwindow/widgets/tabbar.h" +#include "webpage.h" +#include "webprofile.h" #include "widgets/pagemenu.h" #include "widgets/pagetoolsmenu.h" #include #include #include +#include "mainwindow/window.h" -WebView::WebView(MainWindow *parentMainWindow, QWidget *parent) +WebView::WebView(WebProfile *profile, QWidget *parent) : QWebEngineView(parent) { - Q_CHECK_PTR(parentMainWindow); - m_parent = parentMainWindow; + Q_CHECK_PTR(profile); + m_profile = profile; + setPage(new WebPage(profile, this)); + + m_parentWindow = qobject_cast(parent); // load status and progress connect(this, &QWebEngineView::loadStarted, this, [this]() { @@ -72,26 +76,32 @@ int WebView::loadProgress() const WebView *WebView::createWindow(QWebEnginePage::WebWindowType type) { - WebView *view = new WebView(m_parent); + if(m_parentWindow == nullptr) { + qDebug("parent window not found!"); + return nullptr; + } + + // parent Window has been found + WebView *view = new WebView(m_profile, m_parentWindow); switch(type) { case QWebEnginePage::WebBrowserWindow: // a complete web browser window - m_parent->newWindow()->tabBar->addTab(view); + m_parentWindow->addTab(view); break; case QWebEnginePage::WebBrowserTab: // a web browser tab - m_parent->tabBar->setCurrentIndex(m_parent->tabBar->addTab(view)); + m_parentWindow->swapToTab(m_parentWindow->addTab(view)); break; case QWebEnginePage::WebDialog: // a window without decorations - m_parent->newWindow()->tabBar->addTab(view); + m_parentWindow->addTab(view); break; case QWebEnginePage::WebBrowserBackgroundTab: // a web browser tab, but don't swap to it - m_parent->tabBar->addTab(view); + m_parentWindow->addTab(view); break; } @@ -100,26 +110,17 @@ WebView *WebView::createWindow(QWebEnginePage::WebWindowType type) void WebView::handleLinkHovered(const QString &url) { - if(isVisible()) { - m_parent->statusBar()->showMessage(url, 3000); - } + // TODO: tooltip + qDebug("%s", qUtf8Printable(url)); } void WebView::triggerViewAction(WebView::ViewAction action) { switch(action) { + case GoHome: + load(m_profile->homepage()); case BookmarkPage: emit newBookmark(this->title(), this->url()); break; } } - -WebView *createWebView(const QUrl &url, WebEngineProfile *profile, MainWindow *parent) -{ - auto *view = new WebView(parent); - auto *page = new WebPage(profile); - view->setPage(page); - page->load(url); - - return view; -} -- cgit v1.2.1