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 committed May 5, 2017
1 parent 3b9f57a commit e7d5b5b
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/gui/SubWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@

#include "SubWindow.h"

#include <QMdiArea>
#include <QMoveEvent>
#include <QScrollBar>
#include <QtCore/QMetaMethod>
#include <QtGui/QMoveEvent>
#include <QtGui/QWindow>
#include <QtWidgets/QMdiArea>
#include <QtWidgets/QScrollBar>

#include "embed.h"

Expand Down Expand Up @@ -233,20 +235,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 (! widget()->windowFlags().testFlag(Qt::Window)) {
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 e7d5b5b

Please sign in to comment.