aboutsummaryrefslogtreecommitdiff
path: root/src/webengine/webview.cpp
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2018-04-16 17:07:36 +0200
committerAqua-sama <aqua@iserlohn-fortress.net>2018-04-16 17:07:36 +0200
commitd796821f8304306dbe088701724243b39e8eb358 (patch)
tree836c85aa421db5c495e2b36f6a02cea924b6d919 /src/webengine/webview.cpp
parentBranch of Qt5.11 features (diff)
downloadsmolbote-d796821f8304306dbe088701724243b39e8eb358.tar.xz
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
Diffstat (limited to 'src/webengine/webview.cpp')
-rw-r--r--src/webengine/webview.cpp47
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;
-}