Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix the maximize behavior of subwindows on Mac #2798

Merged
merged 1 commit into from
Jun 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 isMaximized();
};

#endif
57 changes: 30 additions & 27 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::isMaximized()
{
#ifdef LMMS_BUILD_APPLE
// 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();
#else
return QMdiSubWindow::isMaximized();
#endif
}




QRect SubWindow::getTrueNormalGeometry() const
{
return m_trackedNormalGeom;
Expand Down Expand Up @@ -198,11 +217,13 @@ void SubWindow::resizeEvent( QResizeEvent * event )
m_maximizeBtn->hide();
m_restoreBtn->hide();

const bool isMax = isMaximized();
const bool isMin = isMinimized();
const int rightSpace = 3;
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,36 +241,17 @@ void SubWindow::resizeEvent( QResizeEvent * event )
{
buttonBarWidth = buttonBarWidth + m_buttonSize.width() + buttonGap;
m_maximizeBtn->move( middleButtonPos );
m_maximizeBtn->show();
m_restoreBtn->move( middleButtonPos );
m_maximizeBtn->setHidden( isMax );
}

if( windowFlags() & Qt::WindowMinimizeButtonHint )
{
buttonBarWidth = buttonBarWidth + m_buttonSize.width() + buttonGap;
if( m_maximizeBtn->isHidden() )
{
m_minimizeBtn->move( middleButtonPos );
}
else
{
m_minimizeBtn->move( leftButtonPos );
}
m_minimizeBtn->show();
m_restoreBtn->hide();
if( isMinimized() )
{
if( m_maximizeBtn->isHidden() )
{
m_restoreBtn->move( middleButtonPos );
}
else
{
m_restoreBtn->move( leftButtonPos );
}
m_restoreBtn->show();
m_minimizeBtn->hide();
}
m_minimizeBtn->move( m_maximizeBtn->isHidden() && !isMax ? middleButtonPos : leftButtonPos );
m_minimizeBtn->setHidden( isMin );
}
m_restoreBtn->setVisible( isMax || isMin );

// title QLabel adjustments
m_windowTitle->setAlignment( Qt::AlignHCenter );
Expand All @@ -259,8 +261,9 @@ void SubWindow::resizeEvent( QResizeEvent * event )

// if minimized we can't use widget()->width(). We have to hard code the width,
// as the width of all minimized windows is the same.
if( isMinimized() )
if( isMin )
{
m_restoreBtn->move( m_maximizeBtn->isHidden() ? middleButtonPos : leftButtonPos );
m_windowTitle->setFixedWidth( 120 );
}

Expand All @@ -273,7 +276,7 @@ void SubWindow::resizeEvent( QResizeEvent * event )

// if the window was resized and ISN'T minimized/maximized/fullscreen,
// then save the current size
if( !isMaximized() && !isMinimized() && !isFullScreen() )
if( !isMax && !isMin && !isFullScreen() )
{
m_trackedNormalGeom.setSize( event->size() );
}
Expand Down