Skip to content

Commit

Permalink
fix the maximize behavior of subwindows on Mac
Browse files Browse the repository at this point in the history
  • Loading branch information
BaraMGB committed May 27, 2016
1 parent 028e83c commit 16e750e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 5 deletions.
1 change: 1 addition & 0 deletions include/SubWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class EXPORT SubWindow : public QMdiSubWindow
QGraphicsDropShadowEffect * m_shadow;

static void elideText( QLabel *label, QString text );
bool isMaximizedOnMac();
};

#endif
44 changes: 39 additions & 5 deletions src/gui/SubWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@
#include <QMdiArea>
#include <QMoveEvent>
#include <QResizeEvent>
#include <QScrollBar>

#include "embed.h"



SubWindow::SubWindow( QWidget *parent, Qt::WindowFlags windowFlags ) :
QMdiSubWindow( parent, windowFlags ),
m_buttonSize( 17, 17 ),
Expand Down Expand Up @@ -121,6 +123,23 @@ void SubWindow::elideText( QLabel *label, QString text )



bool SubWindow::isMaximizedOnMac()
{
// we check if the subwindow size is identically to the MdiArea size
// we have to care about scrollbars in the MdiArea and decrease the test size in case
int hScrollBarHeight = this->mdiArea()->horizontalScrollBar()->size().height();
int vScrollBarWidth = this->mdiArea()->verticalScrollBar()->size().width();

if( !this->mdiArea()->horizontalScrollBar()->isVisible() ) { hScrollBarHeight = 0; }
if( !this->mdiArea()->verticalScrollBar()->isVisible() ) { vScrollBarWidth = 0; }
QSize AreaSize( this->mdiArea()->size().width() - vScrollBarWidth, this->mdiArea()->size().height() - hScrollBarHeight );

return AreaSize == this->size();
}




QRect SubWindow::getTrueNormalGeometry() const
{
return m_trackedNormalGeom;
Expand Down Expand Up @@ -218,24 +237,36 @@ void SubWindow::resizeEvent( QResizeEvent * event )
// then we set the buttons and show them if needed
if( windowFlags() & Qt::WindowMaximizeButtonHint )
{
buttonBarWidth = buttonBarWidth + m_buttonSize.width() + buttonGap;
m_maximizeBtn->move( middleButtonPos );
// on Mac the isMaximize() function returns always false
// so we have to implement our own test
#ifdef LMMS_BUILD_APPLE
if( isMaximizedOnMac() )
{
m_restoreBtn->move( middleButtonPos );
m_restoreBtn->show();
}
else
{
m_maximizeBtn->show();
}
#else
m_maximizeBtn->show();
#endif
buttonBarWidth = buttonBarWidth + m_buttonSize.width() + buttonGap;
}

if( windowFlags() & Qt::WindowMinimizeButtonHint )
{
buttonBarWidth = buttonBarWidth + m_buttonSize.width() + buttonGap;
if( m_maximizeBtn->isHidden() )
if( m_maximizeBtn->isHidden() && !isMaximizedOnMac() )
{
m_minimizeBtn->move( middleButtonPos );
}
else
{
m_minimizeBtn->move( leftButtonPos );
}
m_minimizeBtn->show();
m_restoreBtn->hide();
if( isMinimized() )
{
if( m_maximizeBtn->isHidden() )
Expand All @@ -247,7 +278,10 @@ void SubWindow::resizeEvent( QResizeEvent * event )
m_restoreBtn->move( leftButtonPos );
}
m_restoreBtn->show();
m_minimizeBtn->hide();
}
else
{
m_minimizeBtn->show();
}
}

Expand Down

0 comments on commit 16e750e

Please sign in to comment.