Skip to content

Commit

Permalink
Subwindow detach: Fix minor pos & size issues
Browse files Browse the repository at this point in the history
  • Loading branch information
lukas-w authored and PhysSong committed Jan 12, 2022
1 parent 4b3bf9f commit 4cba419
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/gui/SubWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@
#include "SubWindow.h"

#include <QMdiArea>
#include <QMetaMethod>
#include <QMoveEvent>
#include <QPainter>
#include <QScrollBar>
#include <QWindow>

#include "embed.h"

Expand Down Expand Up @@ -261,20 +263,28 @@ void SubWindow::detach()
auto pos = mapToGlobal(widget()->pos());
widget()->setWindowFlags(Qt::Window);
widget()->show();
widget()->move(pos);
hide();

widget()->windowHandle()->setPosition(pos);
}

void SubWindow::attach()
{
if (! isDetached()) {
return;
}
auto pos = widget()->pos();
auto frame = widget()->windowHandle()->frameGeometry();

widget()->setWindowFlags(Qt::Widget);
widget()->show();
show();
move(mdiArea()->mapFromGlobal(pos));

// 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]() {
move(mdiArea()->mapFromGlobal(frame.topLeft()));
resize(frame.size());
}, Qt::QueuedConnection);
}


Expand Down

0 comments on commit 4cba419

Please sign in to comment.