aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/CMakeLists.txt2
-rw-r--r--src/browser.cpp6
-rw-r--r--src/mainwindow/mainwindow.cpp29
-rw-r--r--src/mainwindow/mainwindow.h1
-rw-r--r--src/mainwindow/widgets/dockwidget.cpp25
-rw-r--r--src/mainwindow/widgets/dockwidget.h23
6 files changed, 78 insertions, 8 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 0f3d0d5..44823df 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -20,6 +20,8 @@ add_executable(poi
mainwindow/mainwindow.h
mainwindow/window.cpp
mainwindow/window.h
+ mainwindow/widgets/dockwidget.cpp
+ mainwindow/widgets/dockwidget.h
mainwindow/widgets/navigationbar.cpp
mainwindow/widgets/navigationbar.h
mainwindow/widgets/searchform.cpp
diff --git a/src/browser.cpp b/src/browser.cpp
index ddaf345..65a67d5 100644
--- a/src/browser.cpp
+++ b/src/browser.cpp
@@ -111,6 +111,9 @@ MainWindow *Browser::createWindow()
auto *bookmarksAction = new QAction(tr("Bookmarks"), window);
bookmarksAction->setShortcut(QKeySequence(QString::fromStdString(m_config->value<std::string>("bookmarks.shortcut").value())));
connect(bookmarksAction, &QAction::triggered, window, [this, window]() {
+ for(MainWindow *w : m_windows) {
+ w->removeDockWidget(m_bookmarks.get());
+ }
window->addDockWidget(Qt::RightDockWidgetArea, m_bookmarks.get());
});
window->addAction(MainWindow::ToolsMenu, bookmarksAction);
@@ -118,6 +121,9 @@ MainWindow *Browser::createWindow()
auto *downloadsAction = new QAction(tr("Downloads"), window);
downloadsAction->setShortcut(QKeySequence(QString::fromStdString(m_config->value<std::string>("downloads.shortcut").value())));
connect(downloadsAction, &QAction::triggered, window, [this, window]() {
+ for(MainWindow *w : m_windows) {
+ w->removeDockWidget(m_downloads.get());
+ }
window->addDockWidget(Qt::RightDockWidgetArea, m_downloads.get());
});
window->addAction(MainWindow::ToolsMenu, downloadsAction);
diff --git a/src/mainwindow/mainwindow.cpp b/src/mainwindow/mainwindow.cpp
index eba02c6..5129abc 100644
--- a/src/mainwindow/mainwindow.cpp
+++ b/src/mainwindow/mainwindow.cpp
@@ -14,7 +14,7 @@
#include "window.h"
#include <QApplication>
#include <QCloseEvent>
-#include <QDockWidget>
+#include "widgets/dockwidget.h"
#include <QLineEdit>
#include <QMdiArea>
#include <QMdiSubWindow>
@@ -153,17 +153,30 @@ void MainWindow::addAction(ActionLocation where, QAction *action)
void MainWindow::addDockWidget(Qt::DockWidgetArea area, QWidget *widget)
{
- QDockWidget *dock = new QDockWidget(widget->windowTitle(), this);
- dock->setAttribute(Qt::WA_DeleteOnClose, true);
+ QList<QDockWidget *> docks;
+ for(QDockWidget *dock : findChildren<QDockWidget *>()) {
+ if(dockWidgetArea(dock) == area)
+ docks.append(dock);
+ }
+
+ DockWidget *dock = new DockWidget(widget->windowTitle(), this);
dock->setWidget(widget);
- connect(dock, &QDockWidget::visibilityChanged, [dock](bool visible) {
- if(!visible && dock->widget()) {
+ if(docks.empty())
+ QMainWindow::addDockWidget(area, dock);
+ else
+ tabifyDockWidget(docks.last(), dock);
+}
+
+void MainWindow::removeDockWidget(QWidget *widget)
+{
+ const auto docks = this->findChildren<QDockWidget *>();
+ for(QDockWidget *dock : docks) {
+ if(dock->widget() == widget) {
dock->widget()->setParent(nullptr);
+ dock->close();
}
- });
-
- QMainWindow::addDockWidget(area, dock);
+ }
}
void MainWindow::createTab(const QUrl &url)
diff --git a/src/mainwindow/mainwindow.h b/src/mainwindow/mainwindow.h
index 2532189..8f511a3 100644
--- a/src/mainwindow/mainwindow.h
+++ b/src/mainwindow/mainwindow.h
@@ -40,6 +40,7 @@ public:
void addAction(ActionLocation where, QAction *action);
void addDockWidget(Qt::DockWidgetArea area, QWidget *widget);
+ void removeDockWidget(QWidget *widget);
Window *currentSubWindow() const;
diff --git a/src/mainwindow/widgets/dockwidget.cpp b/src/mainwindow/widgets/dockwidget.cpp
new file mode 100644
index 0000000..f70e26f
--- /dev/null
+++ b/src/mainwindow/widgets/dockwidget.cpp
@@ -0,0 +1,25 @@
+/*
+ * This file is part of smolbote. It's copyrighted by the contributors recorded
+ * in the version control history of the file, available from its original
+ * location: https://neueland.iserlohn-fortress.net/smolbote.hg
+ *
+ * SPDX-License-Identifier: GPL-3.0
+ */
+
+#include "dockwidget.h"
+#include <QCloseEvent>
+
+DockWidget::DockWidget(const QString &title, QWidget *parent, Qt::WindowFlags flags)
+ : QDockWidget(title, parent, flags)
+{
+ setAttribute(Qt::WA_DeleteOnClose, true);
+}
+
+DockWidget::~DockWidget()
+{
+ // dock widget takes ownership of its widget, so closing the dock widget
+ // causes it to delete the widget as well
+ // clear the widget's parent to prevent this
+ if(widget())
+ widget()->setParent(nullptr);
+}
diff --git a/src/mainwindow/widgets/dockwidget.h b/src/mainwindow/widgets/dockwidget.h
new file mode 100644
index 0000000..35a4cc7
--- /dev/null
+++ b/src/mainwindow/widgets/dockwidget.h
@@ -0,0 +1,23 @@
+/*
+ * This file is part of smolbote. It's copyrighted by the contributors recorded
+ * in the version control history of the file, available from its original
+ * location: https://neueland.iserlohn-fortress.net/smolbote.hg
+ *
+ * SPDX-License-Identifier: GPL-3.0
+ */
+
+#ifndef SMOLBOTE_DOCKWIDGET_H
+#define SMOLBOTE_DOCKWIDGET_H
+
+#include <QDockWidget>
+
+
+class DockWidget : public QDockWidget
+{
+public:
+ DockWidget(const QString &title, QWidget *parent = nullptr, Qt::WindowFlags flags = Qt::WindowFlags());
+ ~DockWidget();
+
+};
+
+#endif // SMOLBOTE_DOCKWIDGET_H