Skip to content

Commit

Permalink
Reduce code duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
lukas-w committed May 5, 2017
1 parent e7d5b5b commit cfed76a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
2 changes: 2 additions & 0 deletions include/SubWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 10 additions & 4 deletions src/gui/SubWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}


Expand Down Expand Up @@ -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());
Expand All @@ -242,7 +248,7 @@ void SubWindow::detach()

void SubWindow::attach()
{
if (! widget()->windowFlags().testFlag(Qt::Window)) {
if (! isDetached()) {
return;
}
auto frame = widget()->windowHandle()->frameGeometry();
Expand All @@ -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);
Expand Down

0 comments on commit cfed76a

Please sign in to comment.