Skip to content

Commit

Permalink
Have MainWindow and others make use of the new SubWindow class
Browse files Browse the repository at this point in the history
  • Loading branch information
Wallacoloo committed Jun 15, 2015
1 parent 7cc917c commit 908591b
Show file tree
Hide file tree
Showing 13 changed files with 80 additions and 57 deletions.
5 changes: 5 additions & 0 deletions include/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
#include <QtCore/QList>
#include <QMainWindow>

#include "SubWindow.h"

class QAction;
class QDomElement;
class QGridLayout;
Expand Down Expand Up @@ -57,6 +59,9 @@ class MainWindow : public QMainWindow
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
SubWindow* addWindowedWidget(QWidget *w, Qt::WindowFlags windowFlags=0);


///
/// \brief Asks whether changes made to the project are to be saved.
Expand Down
2 changes: 1 addition & 1 deletion plugins/VstEffect/VstEffectControls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion plugins/vestige/vestige.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
3 changes: 1 addition & 2 deletions src/gui/FxMixerView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
95 changes: 58 additions & 37 deletions src/gui/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 "FileBrowser.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 "AboutDialog.h"
#include "ControllerRackView.h"
#include "FileBrowser.h"
#include "PluginBrowser.h"
#include "SideBar.h"
#include "ConfigManager.h"
#include "Mixer.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"


Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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() );
}


Expand All @@ -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 ) );
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/gui/ToolPluginView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() );
Expand Down
3 changes: 1 addition & 2 deletions src/gui/widgets/ControllerRackView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
3 changes: 1 addition & 2 deletions src/gui/widgets/ControllerView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/gui/widgets/EffectView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
2 changes: 1 addition & 1 deletion src/gui/widgets/ProjectNotes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
2 changes: 1 addition & 1 deletion src/gui/widgets/TempoSyncKnob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
Expand Down
14 changes: 7 additions & 7 deletions src/tracks/InstrumentTrack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion src/tracks/SampleTrack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() );
Expand Down

0 comments on commit 908591b

Please sign in to comment.