diff options
Diffstat (limited to 'src/webengine/webview.cpp')
-rw-r--r-- | src/webengine/webview.cpp | 47 |
1 files changed, 24 insertions, 23 deletions
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 <QDialog> #include <QStatusBar> #include <QVBoxLayout> +#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<Window *>(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; -} |