aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2018-05-28 10:21:30 +0200
committerAqua-sama <aqua@iserlohn-fortress.net>2018-05-28 10:21:30 +0200
commit49f1351231a71969160b2574603d198af3cf67b3 (patch)
tree3f74847f218efc8cf166f3f49e663177daefff41
parentSwap to new tab after creating it (diff)
downloadsmolbote-49f1351231a71969160b2574603d198af3cf67b3.tar.xz
Remove Window::addTab(WebView *view)
-rw-r--r--src/mainwindow/widgets/tabwidget.cpp2
-rw-r--r--src/mainwindow/window.cpp18
-rw-r--r--src/mainwindow/window.h8
-rw-r--r--src/webengine/webview.cpp8
4 files changed, 22 insertions, 14 deletions
diff --git a/src/mainwindow/widgets/tabwidget.cpp b/src/mainwindow/widgets/tabwidget.cpp
index 97c2717..9608efc 100644
--- a/src/mainwindow/widgets/tabwidget.cpp
+++ b/src/mainwindow/widgets/tabwidget.cpp
@@ -65,7 +65,7 @@ TabWidget::~TabWidget()
int TabWidget::addTab(WebView *view)
{
- Q_CHECK_PTR(view);
+ Q_ASSERT_X(view != nullptr, "TabWidget::addTab", "Tried to add null view");
int idx = QTabWidget::addTab(view, view->title());
connect(view, &WebView::titleChanged, [this, view](const QString &title) {
diff --git a/src/mainwindow/window.cpp b/src/mainwindow/window.cpp
index a5ab90b..47f8489 100644
--- a/src/mainwindow/window.cpp
+++ b/src/mainwindow/window.cpp
@@ -10,7 +10,6 @@
#include "webengine/webprofile.h"
#include "webengine/webview.h"
#include "widgets/tabwidget.h"
-#include <QUrl>
#include <QToolButton>
#include <QStyle>
#include <QAction>
@@ -30,9 +29,16 @@ Window::Window(const QHash<QString, QString> &config, QWidget *parent, Qt::Windo
resize(800, 600);
setWidget(tabWidget);
+ profile = WebProfile::defaultProfile();
+
#ifdef QT_DEBUG
{
auto *menu = systemMenu();
+
+ menu->addSeparator();
+ menu->addAction(tr("Debug menu"))->setEnabled(false);
+ menu->addAction(tr("Profile: %1").arg(profile->isOffTheRecord() ? tr("off-the-record") : profile->storageName()))->setEnabled(false);
+
menu->addSeparator();
auto *saveSession_action = menu->addAction(tr("Save session"));
menu->addAction(tr("Load session"))->setEnabled(false);
@@ -106,16 +112,16 @@ WebView *Window::currentView()
return qobject_cast<WebView *>(tabWidget->currentWidget());
}
-int Window::addTab(WebView *view)
+WebView *Window::view(int index) const
{
- Q_CHECK_PTR(view);
- return tabWidget->addTab(view);
+ return qobject_cast<WebView *>(tabWidget->widget(index));
}
int Window::addTab(const QUrl &url)
{
- auto *view = new WebView(WebProfile::defaultProfile(), this);
- view->load(url);
+ auto *view = new WebView(profile, this);
+ if(!url.isEmpty())
+ view->load(url);
return tabWidget->addTab(view);
}
diff --git a/src/mainwindow/window.h b/src/mainwindow/window.h
index 22955b8..a569214 100644
--- a/src/mainwindow/window.h
+++ b/src/mainwindow/window.h
@@ -11,9 +11,11 @@
#include <QMdiSubWindow>
#include <memory>
+#include <QUrl>
class TabWidget;
class WebView;
+class WebProfile;
class Window : public QMdiSubWindow
{
Q_OBJECT
@@ -23,6 +25,8 @@ public:
~Window() override;
WebView *currentView();
+ WebView *view(int index) const;
+
QJsonObject session() const;
void restoreSession(const QJsonObject &sessionData);
@@ -31,12 +35,12 @@ signals:
void showStatusMessage(const QString &message, int timeout = 0);
public slots:
- int addTab(WebView *view);
- int addTab(const QUrl &url);
+ int addTab(const QUrl &url = QUrl());
void swapToTab(int index);
private:
+ WebProfile *profile;
TabWidget *tabWidget;
QMetaObject::Connection titleConnection;
diff --git a/src/webengine/webview.cpp b/src/webengine/webview.cpp
index 1dca046..686a689 100644
--- a/src/webengine/webview.cpp
+++ b/src/webengine/webview.cpp
@@ -69,26 +69,24 @@ WebView *WebView::createWindow(QWebEnginePage::WebWindowType type)
}
// parent Window has been found
- WebView *view = new WebView(m_profile, m_parentWindow);
+ auto index = m_parentWindow->addTab();
+ WebView *view = m_parentWindow->view(index);
switch(type) {
case QWebEnginePage::WebBrowserWindow:
// a complete web browser window
- m_parentWindow->addTab(view);
break;
case QWebEnginePage::WebBrowserTab:
// a web browser tab
- m_parentWindow->swapToTab(m_parentWindow->addTab(view));
+ m_parentWindow->swapToTab(index);
break;
case QWebEnginePage::WebDialog:
// a window without decorations
- m_parentWindow->addTab(view);
break;
case QWebEnginePage::WebBrowserBackgroundTab:
// a web browser tab, but don't swap to it
- m_parentWindow->addTab(view);
break;
}