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 Jun 17, 2018
1 parent 274e1cc commit 61605ce
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,8 +29,10 @@
#include "SubWindow.h"

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

#include "embed.h"

Expand Down Expand Up @@ -286,20 +288,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 61605ce

Please sign in to comment.