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 28, 2016
1 parent 028e83c commit 8b7a850
Show file tree
Hide file tree
Showing 2 changed files with 36 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
40 changes: 35 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,19 @@ void SubWindow::elideText( QLabel *label, QString text )



bool SubWindow::isMaximizedOnMac()
{
// check if subwindow size is identical to the MdiArea size, accounting for scrollbars
int hScrollBarHeight = mdiArea()->horizontalScrollBar()->isVisible() ? mdiArea()->horizontalScrollBar()->size().height() : 0;
int vScrollBarWidth = mdiArea()->verticalScrollBar()->isVisible() ? mdiArea()->verticalScrollBar()->size().width() : 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 @@ -202,7 +217,7 @@ void SubWindow::resizeEvent( QResizeEvent * event )
const int buttonGap = 1;
const int menuButtonSpace = 24;

QPoint rightButtonPos( width() - rightSpace - m_buttonSize.width() , 3 );
QPoint rightButtonPos( width() - rightSpace - m_buttonSize.width(), 3 );
QPoint middleButtonPos( width() - rightSpace - ( 2 * m_buttonSize.width() ) - buttonGap, 3 );
QPoint leftButtonPos( width() - rightSpace - ( 3 * m_buttonSize.width() ) - ( 2 * buttonGap ), 3 );

Expand All @@ -220,22 +235,34 @@ void SubWindow::resizeEvent( QResizeEvent * event )
{
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
}

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 +274,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 8b7a850

Please sign in to comment.