From 34dc3f5bada77391bd4e8806c82012be3df8c04d Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Sat, 9 Dec 2017 12:59:08 +0100 Subject: Fixed new window action --- src/mainwindow.cpp | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) (limited to 'src/mainwindow.cpp') diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index bf70710..3a2d71d 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -38,6 +38,8 @@ #include #include +#include "browser.h" + MainWindow::MainWindow(std::shared_ptr config, QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow), @@ -150,16 +152,7 @@ void MainWindow::addTabbedDock(Qt::DockWidgetArea area, QWidget *widget) // get all dock widgets QList allDockWidgets = findChildren(); - // check if the widget we're adding is there already - for(QDockWidget *w : allDockWidgets) { - if(w->widget() == widget) { - // widget is already shown --> return - w->show(); - return; - } - } - - // we haven't shown this widget, so let's make a list of widgets in the area we want + // make a list of widgets in the area we want QVector areaDockWidgets; for(QDockWidget *w : allDockWidgets) { if(dockWidgetArea(w) == area) { @@ -168,8 +161,12 @@ void MainWindow::addTabbedDock(Qt::DockWidgetArea area, QWidget *widget) } // create a dock widget - // this dock widget will be destroyed with the MainWindow QDockWidget *dock = new QDockWidget(widget->windowTitle(), this); + + // release the held widget when deleted + connect(dock, &QDockWidget::destroyed, this, [dock]() { + dock->widget()->setParent(nullptr); + }); dock->setWidget(widget); if(areaDockWidgets.empty()) { @@ -190,6 +187,14 @@ void MainWindow::newTab(const QUrl &url) tabBar->addTab(url); } +void MainWindow::newWindow(const QUrl &url) +{ + Browser *instance = static_cast(qApp->instance()); + MainWindow *window = instance->createWindow(); + window->setProfile(tabBar->profile()); + window->newTab(url); +} + void MainWindow::focusAddress() { m_addressBar->setFocus(); @@ -251,13 +256,6 @@ void MainWindow::toggleFullscreen() } } -void MainWindow::newWindow(const QUrl &url) -{ - QHash options; - options.insert("urls", url); - //browser->createWindow(options); -} - void MainWindow::handleTabChanged(WebView *view) { Q_ASSERT(view != nullptr); -- cgit v1.2.1