diff options
Diffstat (limited to 'src/mainwindow.cpp')
-rw-r--r-- | src/mainwindow.cpp | 56 |
1 files changed, 36 insertions, 20 deletions
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index a2b9ff1..f57cab9 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -7,24 +7,18 @@ */ #include "mainwindow.h" +#include "browser.h" #include "forms/aboutdialog.h" +#include "forms/searchform.h" #include "ui_mainwindow.h" #include "widgets/mainwindowmenubar.h" -#include <QMessageBox> - #include <QDockWidget> - -#include <settings/configuration.h> - +#include <QMessageBox> #include <bookmarks/bookmarkswidget.h> #include <downloads/downloadswidget.h> - -#include "browser.h" -#include <settings/settingsdialog.h> - #include <navigation/urllineedit.h> - -#include "forms/searchform.h" +#include <settings/configuration.h> +#include <settings/settingsdialog.h> MainWindow::MainWindow(std::shared_ptr<Configuration> config, QWidget *parent) : QMainWindow(parent) @@ -93,7 +87,8 @@ MainWindow::MainWindow(std::shared_ptr<Configuration> config, QWidget *parent) url.replace("$term", t); tabBar->currentView()->load(QUrl::fromUserInput(url)); }); - connect(tabBar, SIGNAL(currentTabChanged(WebView *)), this, SLOT(handleTabChanged(WebView *))); + connect(tabBar, &MainWindowTabBar::currentTabChanged, this, &MainWindow::handleTabChanged); + //connect(tabBar, SIGNAL(currentTabChanged(WebView *)), this, SLOT(handleTabChanged(WebView *))); // loading bar ui->statusBar->addPermanentWidget(m_progressBar); @@ -136,12 +131,17 @@ MainWindow::~MainWindow() void MainWindow::addTabbedDock(Qt::DockWidgetArea area, QWidget *widget) { - // get all dock widgets - QList<QDockWidget *> allDockWidgets = findChildren<QDockWidget *>(); - // make a list of widgets in the area we want + // this way we can append the new dock widget to the last one QVector<QDockWidget *> areaDockWidgets; - for(QDockWidget *w : allDockWidgets) { + for(QDockWidget *w : findChildren<QDockWidget *>()) { + // check if widget is already shown + if(w->widget() == widget) { + // in this case, close the dock and return + w->close(); + return; + } + if(dockWidgetArea(w) == area) { areaDockWidgets.append(w); } @@ -149,13 +149,29 @@ void MainWindow::addTabbedDock(Qt::DockWidgetArea area, QWidget *widget) // create a dock widget QDockWidget *dock = new QDockWidget(widget->windowTitle(), this); - - // release the held widget when deleted - connect(dock, &QDockWidget::destroyed, this, [dock]() { - dock->widget()->setParent(nullptr); + dock->setAttribute(Qt::WA_DeleteOnClose, true); + + // when the dock widget becomes invisble, release the docked widget + // setting the widget makes the dock its parent; setting parent back to nullptr + // makes the dock not show the widget any more + connect(dock, &QDockWidget::visibilityChanged, [dock](bool visible) { + if(!visible && dock->widget()) { + dock->widget()->setParent(nullptr); + } }); dock->setWidget(widget); + // the same widget may be shown by docks in other windows + // in that case, they grab ownership and the current dock won't be showing anything + // so the current widget needs to be closed + auto *w = dynamic_cast<BookmarksWidget *>(widget); + w->closeOthers(); + if(w) { + connect(w, &BookmarksWidget::closeOthersSignal, dock, [dock]() { + dock->close(); + }); + } + if(areaDockWidgets.empty()) { // no other widgets addDockWidget(area, dock); |