Fix MainWindow not propagating close events to docked widgets

Nested FloatingWindows already supported it, so make it consistent.

Personal take: In a non-docking world, users can override their
main window close event and prevent a close, to save a document
or such. However, in a docking world, the main window developer
won't know which widgets are docked, so forwarding needs to happen,
as some might have documents to save.
This commit is contained in:
Sergio Martins
2022-03-09 15:24:07 +00:00
parent 01cc915734
commit 7db9938b85
6 changed files with 20 additions and 2 deletions

View File

@@ -6,6 +6,7 @@
- Added Config::setDropIndicatorAllowedFunc() and corresponding example - Added Config::setDropIndicatorAllowedFunc() and corresponding example
(kddockwidgets_example --hide-certain-docking-indicators) (kddockwidgets_example --hide-certain-docking-indicators)
- Fixed case where unfloating wouldn't restore to the main window (#44 and #96) - Fixed case where unfloating wouldn't restore to the main window (#44 and #96)
- Fixed MainWindow not propagating close events to docked widgets
* v1.5.1 (unreleased) * v1.5.1 (unreleased)
- X11: Improved detecting which window is under the cursor, by using native X11 API - X11: Improved detecting which window is under the cursor, by using native X11 API

View File

@@ -156,3 +156,8 @@ QRect MainWindow::centralAreaGeometry() const
{ {
return centralWidget()->geometry(); return centralWidget()->geometry();
} }
void MainWindow::closeEvent(QCloseEvent *ev)
{
onCloseEvent(ev);
}

View File

@@ -57,6 +57,7 @@ public:
void setCenterWidgetMargins(const QMargins &margins); void setCenterWidgetMargins(const QMargins &margins);
protected: protected:
void closeEvent(QCloseEvent *) override;
void resizeEvent(QResizeEvent *) override; void resizeEvent(QResizeEvent *) override;
QRect centralAreaGeometry() const override; QRect centralAreaGeometry() const override;

View File

@@ -39,6 +39,8 @@
# include "DockWidget.h" # include "DockWidget.h"
#endif #endif
#include <QCloseEvent>
using namespace KDDockWidgets; using namespace KDDockWidgets;
static LayoutWidget *createLayoutWidget(MainWindowBase *mainWindow, MainWindowOptions options) static LayoutWidget *createLayoutWidget(MainWindowBase *mainWindow, MainWindowOptions options)
@@ -791,3 +793,8 @@ QWidgetOrQuick *MainWindowBase::persistentCentralWidget() const
return nullptr; return nullptr;
} }
void MainWindowBase::onCloseEvent(QCloseEvent *e)
{
d->m_layoutWidget->onCloseEvent(e);
}

View File

@@ -223,6 +223,7 @@ public:
QRect windowGeometry() const; QRect windowGeometry() const;
protected: protected:
void onCloseEvent(QCloseEvent *);
void setUniqueName(const QString &uniqueName); void setUniqueName(const QString &uniqueName);
void onResized(QResizeEvent *); // Because QtQuick doesn't have resizeEvent() void onResized(QResizeEvent *); // Because QtQuick doesn't have resizeEvent()
virtual QMargins centerWidgetMargins() const = 0; virtual QMargins centerWidgetMargins() const = 0;

View File

@@ -2989,8 +2989,11 @@ void TestDocks::tst_preventClose()
fw->close(); fw->close();
QVERIFY(dock1->isVisible()); QVERIFY(dock1->isVisible());
dock1->deleteLater(); // Put into a main window
QVERIFY(Testing::waitForDeleted(dock1)); auto m = createMainWindow();
m->addDockWidget(dock1, KDDockWidgets::Location_OnRight);
m->close();
QVERIFY(dock1->isVisible());
} }
void TestDocks::tst_propagateMinSize() void TestDocks::tst_propagateMinSize()