Merge pull request #2103 from Wallacoloo/git-2087b

Fix for #2087: Issues with saving projects in X11 when one subwindow is maximized
This commit is contained in:
Colin Wallace
2015-06-29 18:37:56 -07:00
16 changed files with 208 additions and 59 deletions

View File

@@ -30,6 +30,8 @@
#include <QtCore/QList>
#include <QMainWindow>
#include "SubWindow.h"
class QAction;
class QDomElement;
class QGridLayout;
@@ -57,6 +59,9 @@ public:
int addWidgetToToolBar( QWidget * _w, int _row = -1, int _col = -1 );
void addSpacingToToolBar( int _size );
// wrap the widget with a window decoration and add it to the workspace
EXPORT SubWindow* addWindowedWidget(QWidget *w, Qt::WindowFlags windowFlags=0);
///
/// \brief Asks whether changes made to the project are to be saved.

58
include/SubWindow.h Normal file
View File

@@ -0,0 +1,58 @@
/*
* SubWindow.h - Implementation of QMdiSubWindow that correctly tracks
* the geometry that windows should be restored to.
* Workaround for https://bugreports.qt.io/browse/QTBUG-256
*
* Copyright (c) 2015 Colin Wallace <wallace.colin.a@gmail.com>
*
* This file is part of LMMS - http://lmms.io
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program (see COPYING); if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
*/
#ifndef SUBWINDOW_H
#define SUBWINDOW_H
#include <QMdiSubWindow>
#include <QRect>
#include "export.h"
class QMoveEvent;
class QResizeEvent;
class QWidget;
class EXPORT SubWindow : public QMdiSubWindow
{
Q_OBJECT
public:
SubWindow(QWidget *parent=NULL, Qt::WindowFlags windowFlags=0);
// same as QWidet::normalGeometry, but works properly under X11 (see https://bugreports.qt.io/browse/QTBUG-256)
QRect getTrueNormalGeometry() const;
protected:
// hook the QWidget move/resize events to update the tracked geometry
virtual void moveEvent(QMoveEvent * event);
virtual void resizeEvent(QResizeEvent * event);
private:
QRect m_trackedNormalGeom;
};
#endif

View File

@@ -310,7 +310,7 @@ manageVSTEffectView::manageVSTEffectView( VstEffect * _eff, VstEffectControls *
m_vi->m_scrollArea = new QScrollArea( widget );
l = new QGridLayout( widget );
m_vi->m_subWindow = gui->mainWindow()->workspace()->addSubWindow(new QMdiSubWindow, Qt::SubWindow |
m_vi->m_subWindow = gui->mainWindow()->addWindowedWidget(NULL, Qt::SubWindow |
Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowSystemMenuHint);
m_vi->m_subWindow->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
m_vi->m_subWindow->setFixedSize( 960, 300);

View File

@@ -874,7 +874,7 @@ manageVestigeInstrumentView::manageVestigeInstrumentView( Instrument * _instrume
widget = new QWidget(this);
l = new QGridLayout( this );
m_vi->m_subWindow = gui->mainWindow()->workspace()->addSubWindow(new QMdiSubWindow, Qt::SubWindow |
m_vi->m_subWindow = gui->mainWindow()->addWindowedWidget(NULL, Qt::SubWindow |
Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowSystemMenuHint);
m_vi->m_subWindow->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::MinimumExpanding );
m_vi->m_subWindow->setFixedWidth( 960 );

View File

@@ -24,6 +24,7 @@ SET(LMMS_SRCS
gui/PluginBrowser.cpp
gui/SetupDialog.cpp
gui/StringPairDrag.cpp
gui/SubWindow.cpp
gui/TimeLineWidget.cpp
gui/ToolPluginView.cpp
gui/TrackContainerView.cpp

View File

@@ -147,8 +147,7 @@ FxMixerView::FxMixerView() :
// add ourself to workspace
QMdiSubWindow * subWin =
gui->mainWindow()->workspace()->addSubWindow( this );
QMdiSubWindow * subWin = gui->mainWindow()->addWindowedWidget( this );
Qt::WindowFlags flags = subWin->windowFlags();
flags &= ~Qt::WindowMaximizeButtonHint;
subWin->setWindowFlags( flags );

View File

@@ -24,48 +24,49 @@
#include "MainWindow.h"
#include <QDomElement>
#include <QUrl>
#include <QApplication>
#include <QCloseEvent>
#include <QDesktopServices>
#include <QDomElement>
#include <QMdiArea>
#include <QMdiSubWindow>
#include <QMenuBar>
#include <QMessageBox>
#include <QShortcut>
#include <QSplitter>
#include <QUrl>
#include <QWhatsThis>
#include "lmmsversion.h"
#include "GuiApplication.h"
#include "AboutDialog.h"
#include "AudioDummy.h"
#include "AutomationEditor.h"
#include "BBEditor.h"
#include "SongEditor.h"
#include "Song.h"
#include "PianoRoll.h"
#include "ConfigManager.h"
#include "ControllerRackView.h"
#include "embed.h"
#include "Engine.h"
#include "FxMixerView.h"
#include "InstrumentTrack.h"
#include "PianoView.h"
#include "AboutDialog.h"
#include "ControllerRackView.h"
#include "FileBrowser.h"
#include "PluginBrowser.h"
#include "SideBar.h"
#include "ConfigManager.h"
#include "FileDialog.h"
#include "FxMixerView.h"
#include "GuiApplication.h"
#include "InstrumentTrack.h"
#include "lmmsversion.h"
#include "Mixer.h"
#include "PianoRoll.h"
#include "PianoView.h"
#include "PluginBrowser.h"
#include "PluginFactory.h"
#include "PluginView.h"
#include "ProjectJournal.h"
#include "ProjectNotes.h"
#include "SetupDialog.h"
#include "AudioDummy.h"
#include "ToolPlugin.h"
#include "ToolButton.h"
#include "ProjectJournal.h"
#include "AutomationEditor.h"
#include "SideBar.h"
#include "Song.h"
#include "SongEditor.h"
#include "SubWindow.h"
#include "templates.h"
#include "FileDialog.h"
#include "ToolButton.h"
#include "ToolPlugin.h"
#include "VersionedSaveDialog.h"
@@ -560,7 +561,7 @@ void MainWindow::finalize()
gui->songEditor()
})
{
QMdiSubWindow* window = workspace()->addSubWindow(widget);
QMdiSubWindow* window = addWindowedWidget(widget);
window->setWindowIcon(widget->windowIcon());
window->setAttribute(Qt::WA_DeleteOnClose, false);
window->resize(widget->sizeHint());
@@ -607,7 +608,15 @@ void MainWindow::addSpacingToToolBar( int _size )
7, _size );
}
SubWindow* MainWindow::addWindowedWidget(QWidget *w, Qt::WindowFlags windowFlags)
{
// wrap the widget in our own *custom* window that patches some errors in QMdiSubWindow
SubWindow *win = new SubWindow(m_workspace->viewport(), windowFlags);
win->setAttribute(Qt::WA_DeleteOnClose);
win->setWidget(w);
m_workspace->addSubWindow(win);
return win;
}
void MainWindow::resetWindowTitle()
@@ -680,26 +689,29 @@ void MainWindow::clearKeyModifiers()
void MainWindow::saveWidgetState( QWidget * _w, QDomElement & _de )
{
qDebug() << "this " << _w->metaObject()->className();
// If our widget is the main content of a window (e.g. piano roll, FxMixer, etc),
// we really care about the position of the *window* - not the position of the widget within its window
if( _w->parentWidget() != NULL &&
_w->parentWidget()->inherits( "QMdiSubWindow" ) )
{
_w = _w->parentWidget();
}
// If the widget is a SubWindow, then we can make use of the getTrueNormalGeometry() method that
// performs the same as normalGeometry, but isn't broken on X11 ( see https://bugreports.qt.io/browse/QTBUG-256 )
SubWindow *asSubWindow = qobject_cast<SubWindow*>(_w);
QRect normalGeom = asSubWindow != nullptr ? asSubWindow->getTrueNormalGeometry() : _w->normalGeometry();
_de.setAttribute( "visible", _w->isVisible() );
_de.setAttribute( "minimized", _w->isMinimized() );
_de.setAttribute( "maximized", _w->isMaximized() );
bool maxed = _w->isMaximized();
bool mined = _w->isMinimized();
if( mined || maxed ) { _w->showNormal(); }
_de.setAttribute( "x", _w->x() );
_de.setAttribute( "y", _w->y() );
_de.setAttribute( "width", _w->width() );
_de.setAttribute( "height", _w->height() );
if( maxed ) { _w->showMaximized(); }
if( mined ) { _w->showMinimized(); }
_de.setAttribute( "x", normalGeom.x() );
_de.setAttribute( "y", normalGeom.y() );
_de.setAttribute( "width", normalGeom.width() );
_de.setAttribute( "height", normalGeom.height() );
}
@@ -713,21 +725,30 @@ void MainWindow::restoreWidgetState( QWidget * _w, const QDomElement & _de )
qMax( 100, _de.attribute( "height" ).toInt() ) );
if( _de.hasAttribute( "visible" ) && !r.isNull() )
{
// If our widget is the main content of a window (e.g. piano roll, FxMixer, etc),
// we really care about the position of the *window* - not the position of the widget within its window
if ( _w->parentWidget() != NULL &&
_w->parentWidget()->inherits( "QMdiSubWindow" ) )
{
_w = _w->parentWidget();
}
// first restore the window, as attempting to resize a maximized window causes graphics glitching
_w->setWindowState( _w->windowState() & ~(Qt::WindowMaximized | Qt::WindowMinimized) );
_w->resize( r.size() );
_w->move( r.topLeft() );
// set the window to its correct minimized/maximized/restored state
Qt::WindowStates flags = _w->windowState();
flags = _de.attribute( "minimized" ).toInt() ?
( flags | Qt::WindowMinimized ) :
( flags & ~Qt::WindowMinimized );
flags = _de.attribute( "maximized" ).toInt() ?
( flags | Qt::WindowMaximized ) :
( flags & ~Qt::WindowMaximized );
_w->setWindowState( flags );
_w->setVisible( _de.attribute( "visible" ).toInt() );
_w->setWindowState( _de.attribute( "minimized" ).toInt() ?
( _w->windowState() | Qt::WindowMinimized ) :
( _w->windowState() & ~Qt::WindowMinimized ) );
_w->setWindowState( _de.attribute( "maximized" ).toInt() ?
( _w->windowState() | Qt::WindowMaximized ) :
( _w->windowState() & ~Qt::WindowMaximized ) );
}
}

67
src/gui/SubWindow.cpp Normal file
View File

@@ -0,0 +1,67 @@
/*
* SubWindow.cpp - Implementation of QMdiSubWindow that correctly tracks
* the geometry that windows should be restored to.
* Workaround for https://bugreports.qt.io/browse/QTBUG-256
*
* Copyright (c) 2015 Colin Wallace <wallace.colin.a@gmail.com>
*
* This file is part of LMMS - http://lmms.io
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program (see COPYING); if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
*/
#include "SubWindow.h"
#include <QMoveEvent>
#include <QResizeEvent>
#include <QWidget>
SubWindow::SubWindow(QWidget *parent, Qt::WindowFlags windowFlags)
: QMdiSubWindow(parent, windowFlags)
{
// initialize the tracked geometry to whatever Qt thinks the normal geometry currently is.
// this should always work, since QMdiSubWindows will not start as maximized
m_trackedNormalGeom = normalGeometry();
}
QRect SubWindow::getTrueNormalGeometry() const
{
return m_trackedNormalGeom;
}
void SubWindow::moveEvent(QMoveEvent * event)
{
QMdiSubWindow::moveEvent(event);
// if the window was moved and ISN'T minimized/maximized/fullscreen,
// then save the current position
if (!isMaximized() && !isMinimized() && !isFullScreen())
{
m_trackedNormalGeom.moveTopLeft(event->pos());
}
}
void SubWindow::resizeEvent(QResizeEvent * event)
{
QMdiSubWindow::resizeEvent(event);
// if the window was resized and ISN'T minimized/maximized/fullscreen,
// then save the current size
if (!isMaximized() && !isMinimized() && !isFullScreen())
{
m_trackedNormalGeom.setSize(event->size());
}
}

View File

@@ -38,7 +38,7 @@
ToolPluginView::ToolPluginView( ToolPlugin * _toolPlugin ) :
PluginView( _toolPlugin, NULL )
{
gui->mainWindow()->workspace()->addSubWindow( this );
gui->mainWindow()->addWindowedWidget( this );
parentWidget()->setAttribute( Qt::WA_DeleteOnClose, false );
setWindowTitle( _toolPlugin->displayName() );

View File

@@ -75,8 +75,7 @@ ControllerRackView::ControllerRackView( ) :
layout->addWidget( m_addButton );
this->setLayout( layout );
QMdiSubWindow * subWin =
gui->mainWindow()->workspace()->addSubWindow( this );
QMdiSubWindow * subWin = gui->mainWindow()->addWindowedWidget( this );
// No maximize button
Qt::WindowFlags flags = subWin->windowFlags();

View File

@@ -65,8 +65,7 @@ ControllerView::ControllerView( Controller * _model, QWidget * _parent ) :
m_controllerDlg = getController()->createDialog( gui->mainWindow()->workspace() );
m_subWindow = gui->mainWindow()->workspace()->addSubWindow(
m_controllerDlg );
m_subWindow = gui->mainWindow()->addWindowedWidget( m_controllerDlg );
Qt::WindowFlags flags = m_subWindow->windowFlags();
flags &= ~Qt::WindowMaximizeButtonHint;

View File

@@ -110,7 +110,7 @@ EffectView::EffectView( Effect * _model, QWidget * _parent ) :
m_controlView = effect()->controls()->createView();
if( m_controlView )
{
m_subWindow = gui->mainWindow()->workspace()->addSubWindow(
m_subWindow = gui->mainWindow()->addWindowedWidget(
m_controlView,
Qt::SubWindow | Qt::CustomizeWindowHint |
Qt::WindowTitleHint | Qt::WindowSystemMenuHint );

View File

@@ -71,7 +71,7 @@ ProjectNotes::ProjectNotes() :
setWindowTitle( tr( "Project notes" ) );
setWindowIcon( embed::getIconPixmap( "project_notes" ) );
gui->mainWindow()->workspace()->addSubWindow( this );
gui->mainWindow()->addWindowedWidget( this );
parentWidget()->setAttribute( Qt::WA_DeleteOnClose, false );
parentWidget()->move( 700, 10 );
parentWidget()->resize( 400, 300 );

View File

@@ -293,7 +293,7 @@ void TempoSyncKnob::showCustom()
if( m_custom == NULL )
{
m_custom = new MeterDialog( gui->mainWindow()->workspace() );
gui->mainWindow()->workspace()->addSubWindow( m_custom );
gui->mainWindow()->addWindowedWidget( m_custom );
m_custom->setWindowTitle( "Meter" );
m_custom->setModel( &model()->m_custom );
}

View File

@@ -1423,19 +1423,19 @@ InstrumentTrackWindow::InstrumentTrackWindow( InstrumentTrackView * _itv ) :
setFixedWidth( INSTRUMENT_WIDTH );
resize( sizeHint() );
QMdiSubWindow * subWin = gui->mainWindow()->workspace()->addSubWindow( this );
QMdiSubWindow * subWin = gui->mainWindow()->addWindowedWidget( this );
Qt::WindowFlags flags = subWin->windowFlags();
flags |= Qt::MSWindowsFixedSizeDialogHint;
flags &= ~Qt::WindowMaximizeButtonHint;
subWin->setWindowFlags( flags );
// 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->setWindowIcon( embed::getIconPixmap( "instrument_track" ) );
subWin->setWindowIcon( embed::getIconPixmap( "instrument_track" ) );
subWin->setFixedSize( subWin->size() );
subWin->hide();
}

View File

@@ -589,7 +589,7 @@ SampleTrackView::SampleTrackView( SampleTrack * _t, TrackContainerView* tcv ) :
m_effectRack = new EffectRackView( _t->audioPort()->effects() );
m_effectRack->setFixedSize( 240, 242 );
m_effWindow = gui->mainWindow()->workspace()->addSubWindow( m_effectRack );
m_effWindow = gui->mainWindow()->addWindowedWidget( m_effectRack );
m_effWindow->setAttribute( Qt::WA_DeleteOnClose, false );
m_effWindow->layout()->setSizeConstraint( QLayout::SetFixedSize );
m_effWindow->setWindowTitle( _t->name() );