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

Maximize button for resizable instruments #7514

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions include/SubWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ class LMMS_EXPORT SubWindow : public QMdiSubWindow
void paintEvent( QPaintEvent * pe ) override;
void changeEvent( QEvent * event ) override;

QPushButton* addTitleButton(const std::string & iconName, const QString & toolTip);

signals:
void focusLost();

Expand Down
67 changes: 42 additions & 25 deletions src/gui/SubWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,28 +58,13 @@ SubWindow::SubWindow(QWidget *parent, Qt::WindowFlags windowFlags) :
m_borderColor = Qt::black;

// close, maximize and restore (after maximizing) buttons
m_closeBtn = new QPushButton( embed::getIconPixmap( "close" ), QString(), this );
m_closeBtn->resize( m_buttonSize );
m_closeBtn->setFocusPolicy( Qt::NoFocus );
m_closeBtn->setCursor( Qt::ArrowCursor );
m_closeBtn->setAttribute( Qt::WA_NoMousePropagation );
m_closeBtn->setToolTip( tr( "Close" ) );
m_closeBtn = addTitleButton("close", tr("Close"));
connect( m_closeBtn, SIGNAL(clicked(bool)), this, SLOT(close()));

m_maximizeBtn = new QPushButton( embed::getIconPixmap( "maximize" ), QString(), this );
m_maximizeBtn->resize( m_buttonSize );
m_maximizeBtn->setFocusPolicy( Qt::NoFocus );
m_maximizeBtn->setCursor( Qt::ArrowCursor );
m_maximizeBtn->setAttribute( Qt::WA_NoMousePropagation );
m_maximizeBtn->setToolTip( tr( "Maximize" ) );
m_maximizeBtn = addTitleButton("maximize", tr("Maximize"));
connect( m_maximizeBtn, SIGNAL(clicked(bool)), this, SLOT(showMaximized()));

m_restoreBtn = new QPushButton( embed::getIconPixmap( "restore" ), QString(), this );
m_restoreBtn->resize( m_buttonSize );
m_restoreBtn->setFocusPolicy( Qt::NoFocus );
m_restoreBtn->setCursor( Qt::ArrowCursor );
m_restoreBtn->setAttribute( Qt::WA_NoMousePropagation );
m_restoreBtn->setToolTip( tr( "Restore" ) );
m_restoreBtn = addTitleButton("restore", tr("Restore"));
connect( m_restoreBtn, SIGNAL(clicked(bool)), this, SLOT(showNormal()));

// QLabel for the window title and the shadow effect
Expand All @@ -94,9 +79,8 @@ SubWindow::SubWindow(QWidget *parent, Qt::WindowFlags windowFlags) :
m_windowTitle->setGraphicsEffect( m_shadow );

// disable the minimize button
setWindowFlags( Qt::SubWindow | Qt::WindowMaximizeButtonHint |
Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint |
Qt::CustomizeWindowHint );
setWindowFlags(this->windowFlags() & ~Qt::WindowMinimizeButtonHint);

connect( mdiArea(), SIGNAL(subWindowActivated(QMdiSubWindow*)), this, SLOT(focusChanged(QMdiSubWindow*)));
}

Expand All @@ -111,12 +95,17 @@ SubWindow::SubWindow(QWidget *parent, Qt::WindowFlags windowFlags) :
*/
void SubWindow::paintEvent( QPaintEvent * )
{
// Don't paint any of the other stuff if the sub window is maximized
// so that only its child content is painted.
if (isMaximized())
{
return;
}

QPainter p( this );
QRect rect( 0, 0, width(), m_titleBarHeight );

bool isActive = mdiArea()
? mdiArea()->activeSubWindow() == this
: false;
const bool isActive = windowState() & Qt::WindowActive;

p.fillRect( rect, isActive ? activeColor() : p.pen().brush() );

Expand Down Expand Up @@ -295,9 +284,25 @@ void SubWindow::moveEvent( QMoveEvent * event )
*/
void SubWindow::adjustTitleBar()
{
// Don't show the title or any button if the sub window is maximized. Otherwise they
// might show up behind the actual maximized content of the child widget.
if (isMaximized())
{
m_closeBtn->hide();
m_maximizeBtn->hide();
m_restoreBtn->hide();
m_windowTitle->hide();

return;
}

// Title adjustments
m_windowTitle->show();

// button adjustments
m_maximizeBtn->hide();
m_restoreBtn->hide();
m_closeBtn->show();

const int rightSpace = 3;
const int buttonGap = 1;
Expand Down Expand Up @@ -403,5 +408,17 @@ void SubWindow::resizeEvent( QResizeEvent * event )
}
}

QPushButton* SubWindow::addTitleButton(const std::string & iconName, const QString & toolTip)
{
auto button = new QPushButton(embed::getIconPixmap(iconName), QString(), this);
button->resize(m_buttonSize);
button->setFocusPolicy(Qt::NoFocus);
button->setCursor(Qt::ArrowCursor);
button->setAttribute(Qt::WA_NoMousePropagation);
button->setToolTip(toolTip);

return button;
}


} // namespace lmms::gui
} // namespace lmms::gui
34 changes: 20 additions & 14 deletions src/gui/instrument/InstrumentTrackWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,24 +285,30 @@ InstrumentTrackWindow::InstrumentTrackWindow( InstrumentTrackView * _itv ) :

QMdiSubWindow* subWin = getGUI()->mainWindow()->addWindowedWidget( this );
Qt::WindowFlags flags = subWin->windowFlags();
if (!m_instrumentView->isResizable()) {
flags |= Qt::MSWindowsFixedSizeDialogHint;
// any better way than this?
} else {
subWin->setMaximumSize(m_instrumentView->maximumHeight() + 12, m_instrumentView->maximumWidth() + 208);
subWin->setMinimumSize( m_instrumentView->minimumWidth() + 12, m_instrumentView->minimumHeight() + 208);

if (m_instrumentView->isResizable())
{
// TODO As of writing SlicerT is the only resizable instrument. Is this code specific to SlicerT?
const auto extraSpace = QSize(12, 208);
subWin->setMaximumSize(m_instrumentView->maximumSize() + extraSpace);
subWin->setMinimumSize(m_instrumentView->minimumSize() + extraSpace);

flags |= Qt::WindowMaximizeButtonHint;
}
flags &= ~Qt::WindowMaximizeButtonHint;
subWin->setWindowFlags( flags );
else
{
flags |= Qt::MSWindowsFixedSizeDialogHint;
flags &= ~Qt::WindowMaximizeButtonHint;

// Hide the Size and Maximize options from the system menu since the dialog size is fixed.
QMenu * systemMenu = subWin->systemMenu();
systemMenu->actions().at(2)->setVisible(false); // Size
systemMenu->actions().at(4)->setVisible(false); // Maximize
}

// Hide the Size and Maximize options from the system menu
// since the dialog size is fixed.
QMenu * systemMenu = subWin->systemMenu();
systemMenu->actions().at( 2 )->setVisible( false ); // Size
systemMenu->actions().at( 4 )->setVisible( false ); // Maximize
subWin->setWindowFlags(flags);

subWin->setWindowIcon( embed::getIconPixmap( "instrument_track" ) );
subWin->setWindowIcon(embed::getIconPixmap("instrument_track"));
subWin->hide();
}

Expand Down
Loading