From cfed76a50fae9d2f06c4ee79bc2fe4cc66ae9400 Mon Sep 17 00:00:00 2001 From: Lukas W Date: Fri, 5 May 2017 17:09:26 +0200 Subject: [PATCH] Reduce code duplication --- include/SubWindow.h | 2 ++ src/gui/SubWindow.cpp | 14 ++++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/include/SubWindow.h b/include/SubWindow.h index 66b8e803e33..a69d8319dd7 100644 --- a/include/SubWindow.h +++ b/include/SubWindow.h @@ -70,6 +70,8 @@ public slots: virtual void paintEvent( QPaintEvent * pe ); virtual void changeEvent( QEvent * event ); virtual void showEvent( QShowEvent* event ); + + bool isDetached() const; private: const QSize m_buttonSize; diff --git a/src/gui/SubWindow.cpp b/src/gui/SubWindow.cpp index 1ae149edfde..8846a4d73c8 100644 --- a/src/gui/SubWindow.cpp +++ b/src/gui/SubWindow.cpp @@ -138,9 +138,15 @@ void SubWindow::changeEvent( QEvent *event ) } -void SubWindow::showEvent(QShowEvent *) +void SubWindow::showEvent(QShowEvent *e) { attach(); + QMdiSubWindow::showEvent(e); +} + +bool SubWindow::isDetached() const +{ + return widget()->windowFlags().testFlag(Qt::Window); } @@ -229,7 +235,7 @@ void SubWindow::setBorderColor( const QColor &c ) void SubWindow::detach() { - if (widget()->windowFlags().testFlag(Qt::Window)) { + if (isDetached()) { return; } auto pos = mapToGlobal(widget()->pos()); @@ -242,7 +248,7 @@ void SubWindow::detach() void SubWindow::attach() { - if (! widget()->windowFlags().testFlag(Qt::Window)) { + if (! isDetached()) { return; } auto frame = widget()->windowHandle()->frameGeometry(); @@ -253,7 +259,7 @@ void SubWindow::attach() // Delay moving & resizing using event queue. Ensures that this widget is // visible first, so that resizing works. - QObject o;connect(&o, &QObject::destroyed, this, [this, frame]() { + QObject o; connect(&o, &QObject::destroyed, this, [this, frame]() { move(mdiArea()->mapFromGlobal(frame.topLeft())); resize(frame.size()); }, Qt::QueuedConnection);