From 3372309f7314f2d0b35870ae4d3b576cce95c410 Mon Sep 17 00:00:00 2001 From: Tobias Doerffel Date: Sun, 7 Sep 2008 12:09:02 +0000 Subject: [PATCH] properly save and restore position, size, visibility and state of MDI-subwindows git-svn-id: https://lmms.svn.sf.net/svnroot/lmms/trunk/lmms@1569 0778d3d1-df1d-0410-868b-ea421aaaa00d --- ChangeLog | 26 +++++ include/controller_rack_view.h | 29 ++---- include/fx_mixer_view.h | 6 +- include/main_window.h | 8 ++ include/piano_roll.h | 5 +- include/project_notes.h | 3 +- include/track_container.h | 7 -- include/track_container_view.h | 8 +- src/core/song.cpp | 7 ++ src/core/track_container.cpp | 6 -- src/gui/main_window.cpp | 20 +++- src/gui/track_container_view.cpp | 25 ++++- src/gui/widgets/controller_rack_view.cpp | 122 +++-------------------- src/tracks/instrument_track.cpp | 11 +- 14 files changed, 123 insertions(+), 160 deletions(-) diff --git a/ChangeLog b/ChangeLog index dba383e67..325ebe0db 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,31 @@ 2008-09-07 Tobias Doerffel + * include/controller_rack_view.h: + * include/fx_mixer_view.h: + * include/main_window.h: + * include/piano_roll.h: + * include/project_notes.h: + * include/track_container.h: + * include/track_container_view.h: + * src/core/song.cpp: + * src/core/track_container.cpp: + * src/gui/fx_mixer_view.cpp: + * src/gui/main_window.cpp: + * src/gui/track_container_view.cpp: + * src/gui/widgets/controller_rack_view.cpp: + * src/tracks/instrument_track.cpp: + properly save and restore position, size, visibility and state of + MDI-subwindows + + * src/core/serializing_object.cpp: + fixed hook-mechanism + + * include/song_editor.h: + * src/gui/song_editor.cpp: + * src/gui/fx_mixer_view.cpp: + * src/gui/widgets/visualization_widget.cpp: + moved peridic update-timer from songEditor to mainWindow + * data/projects/cool_songs/Chris-HorizonRemix.mmp: added song diff --git a/include/controller_rack_view.h b/include/controller_rack_view.h index 4ee9c86c4..b2f080cd6 100644 --- a/include/controller_rack_view.h +++ b/include/controller_rack_view.h @@ -27,25 +27,31 @@ #include +#include "serializing_object.h" #include "types.h" -#include "mv_base.h" class QPushButton; class QScrollArea; -class QVBoxLayout; +//class QVBoxLayout; class controllerView; -class controllerRackView : public QWidget, public modelView +class controllerRackView : public QWidget, public serializingObject { Q_OBJECT public: controllerRackView(); virtual ~controllerRackView(); - void clear( void ); + virtual void saveSettings( QDomDocument & _doc, QDomElement & _parent ); + virtual void loadSettings( const QDomElement & _this ); + + inline virtual QString nodeName( void ) const + { + return( "controllerrackview" ); + } public slots: @@ -56,24 +62,11 @@ private slots: virtual void update( void ); void addController( void ); + private: - /*virtual void modelChanged( void ); - - inline effectChain * fxChain( void ) - { - return( castModel() ); - } - - inline const effectChain * fxChain( void ) const - { - return( castModel() ); - } -*/ - QVector m_controllerViews; QVBoxLayout * m_mainLayout; - //groupBox * m_effectsGroupBox; QScrollArea * m_scrollArea; QPushButton * m_addButton; diff --git a/include/fx_mixer_view.h b/include/fx_mixer_view.h index 55484862f..75f6dda63 100644 --- a/include/fx_mixer_view.h +++ b/include/fx_mixer_view.h @@ -40,13 +40,17 @@ class pixmapButton; -class fxMixerView : public QWidget, public modelView +class fxMixerView : public QWidget, public modelView, + public serializingObjectHook { Q_OBJECT public: fxMixerView(); virtual ~fxMixerView(); + virtual void saveSettings( QDomDocument & _doc, QDomElement & _this ); + virtual void loadSettings( const QDomElement & _this ); + fxLine * currentFxLine( void ) { return( m_currentFxLine ); diff --git a/include/main_window.h b/include/main_window.h index 001575f51..daed10e2a 100644 --- a/include/main_window.h +++ b/include/main_window.h @@ -26,6 +26,7 @@ #ifndef _MAIN_WINDOW_H #define _MAIN_WINDOW_H +#include #include #include #include @@ -120,6 +121,7 @@ protected: virtual void focusOutEvent( QFocusEvent * _fe ); virtual void keyPressEvent( QKeyEvent * _ke ); virtual void keyReleaseEvent( QKeyEvent * _ke ); + virtual void timerEvent( QTimerEvent * _ev ); private: @@ -157,6 +159,8 @@ private: QMenu * m_toolsMenu; QList m_tools; + QBasicTimer m_updateTimer; + friend class engine; @@ -168,6 +172,10 @@ private slots: void showTool( QAction * _idx ); void updateRecentlyOpenedProjectsMenu( void ); + +signals: + void periodicUpdate( void ); + } ; #endif diff --git a/include/piano_roll.h b/include/piano_roll.h index ba83d07ea..a976ffaa9 100644 --- a/include/piano_roll.h +++ b/include/piano_roll.h @@ -30,7 +30,7 @@ #include #include "combobox_model.h" -#include "journalling_object.h" +#include "serializing_object.h" #include "note.h" #include "types.h" @@ -46,7 +46,7 @@ class timeLine; class toolButton; -class pianoRoll : public QWidget, public journallingObject +class pianoRoll : public QWidget, public serializingObject { Q_OBJECT public: @@ -72,6 +72,7 @@ public: virtual void saveSettings( QDomDocument & _doc, QDomElement & _parent ); virtual void loadSettings( const QDomElement & _this ); + inline virtual QString nodeName( void ) const { return( "pianoroll" ); diff --git a/include/project_notes.h b/include/project_notes.h index 1ade30c5f..97848b63e 100644 --- a/include/project_notes.h +++ b/include/project_notes.h @@ -37,7 +37,7 @@ class QTextCharFormat; class QTextEdit; -class EXPORT projectNotes : public QMainWindow, public journallingObject +class EXPORT projectNotes : public QMainWindow, public serializingObject { Q_OBJECT public: @@ -49,6 +49,7 @@ public: virtual void saveSettings( QDomDocument & _doc, QDomElement & _parent ); virtual void loadSettings( const QDomElement & _this ); + inline virtual QString nodeName( void ) const { return( "projectnotes" ); diff --git a/include/track_container.h b/include/track_container.h index 07e2d714c..0914fb423 100644 --- a/include/track_container.h +++ b/include/track_container.h @@ -66,13 +66,6 @@ public: void clearAllTracks( void ); - /* - trackList & tracks( void ) - { - return( m_tracks ); - } - */ - const trackList & tracks( void ) const { return( m_tracks ); diff --git a/include/track_container_view.h b/include/track_container_view.h index 2d05935e2..83ed9bcb2 100644 --- a/include/track_container_view.h +++ b/include/track_container_view.h @@ -26,8 +26,8 @@ #ifndef _TRACK_CONTAINER_VIEW_H #define _TRACK_CONTAINER_VIEW_H -#include #include +#include #include @@ -40,13 +40,17 @@ class trackContainer; class trackContainerView : public QWidget, public modelView, - public journallingObject + public journallingObject, + public serializingObjectHook { Q_OBJECT public: trackContainerView( trackContainer * _tc ); virtual ~trackContainerView(); + virtual void saveSettings( QDomDocument & _doc, QDomElement & _this ); + virtual void loadSettings( const QDomElement & _this ); + QWidget * contentWidget( void ) { return( m_scrollArea ); diff --git a/src/core/song.cpp b/src/core/song.cpp index 1aa03a113..232d83bf5 100644 --- a/src/core/song.cpp +++ b/src/core/song.cpp @@ -915,6 +915,12 @@ void song::loadProject( const QString & _file_name ) else if( engine::hasGUI() ) { if( node.nodeName() == + engine::getControllerRackView()->nodeName() ) + { + engine::getControllerRackView()-> + restoreState( node.toElement() ); + } + else if( node.nodeName() == engine::getPianoRoll()->nodeName() ) { engine::getPianoRoll()->restoreState( @@ -999,6 +1005,7 @@ bool song::saveProject( void ) engine::getFxMixer()->saveState( mmp, mmp.content() ); if( engine::hasGUI() ) { + engine::getControllerRackView()->saveState( mmp, mmp.content() ); engine::getPianoRoll()->saveState( mmp, mmp.content() ); engine::getAutomationEditor()->saveState( mmp, mmp.content() ); ( (journallingObject *)( engine::getProjectNotes() ) )-> diff --git a/src/core/track_container.cpp b/src/core/track_container.cpp index 15ffa89c4..465fec5b2 100644 --- a/src/core/track_container.cpp +++ b/src/core/track_container.cpp @@ -57,8 +57,6 @@ void trackContainer::saveSettings( QDomDocument & _doc, QDomElement & _this ) { _this.setTagName( classNodeName() ); _this.setAttribute( "type", nodeName() ); -// ### TODO - //mainWindow::saveWidgetState( this, _this ); // save settings of each track m_tracksMutex.lockForRead(); @@ -118,10 +116,6 @@ void trackContainer::loadSettings( const QDomElement & _this ) node = node.nextSibling(); } -// ### TODO -// mainWindow::restoreWidgetState( this, _this ); - - if( pd != NULL ) { pd->setValue( start_val + _this.childNodes().count() ); diff --git a/src/gui/main_window.cpp b/src/gui/main_window.cpp index d5fcb5592..7a891cf64 100644 --- a/src/gui/main_window.cpp +++ b/src/gui/main_window.cpp @@ -155,7 +155,7 @@ mainWindow::mainWindow( void ) : setCentralWidget( main_widget ); - + m_updateTimer.start( 1000 / 20, this ); // 20 fps } @@ -578,6 +578,8 @@ void mainWindow::saveWidgetState( QWidget * _w, QDomElement & _de ) _de.setAttribute( "x", _w->x() ); _de.setAttribute( "y", _w->y() ); _de.setAttribute( "visible", _w->isVisible() ); + _de.setAttribute( "minimized", _w->isMinimized() ); + _de.setAttribute( "maximized", _w->isMaximized() ); _de.setAttribute( "width", _w->width() ); _de.setAttribute( "height", _w->height() ); @@ -592,7 +594,7 @@ void mainWindow::restoreWidgetState( QWidget * _w, const QDomElement & _de ) tMax( 0, _de.attribute( "y" ).toInt() ), tMax( 100, _de.attribute( "width" ).toInt() ), tMax( 100, _de.attribute( "height" ).toInt() ) ); - if( !r.isNull()) + if( !r.isNull() ) { if ( _w->parentWidget() != NULL && _w->parentWidget()->inherits( "QMdiSubWindow" ) ) @@ -603,6 +605,12 @@ void mainWindow::restoreWidgetState( QWidget * _w, const QDomElement & _de ) _w->resize( r.size() ); _w->move( r.topLeft() ); _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 ) ); } } @@ -909,6 +917,14 @@ void mainWindow::keyReleaseEvent( QKeyEvent * _ke ) +void mainWindow::timerEvent( QTimerEvent * ) +{ + emit periodicUpdate(); +} + + + + void mainWindow::fillTemplatesMenu( void ) { m_templatesMenu->clear(); diff --git a/src/gui/track_container_view.cpp b/src/gui/track_container_view.cpp index c72d917d6..53a6dc27e 100644 --- a/src/gui/track_container_view.cpp +++ b/src/gui/track_container_view.cpp @@ -24,6 +24,7 @@ #include +#include #include #include #include @@ -33,9 +34,8 @@ #include "track_container_view.h" #include "track_container.h" #include "bb_track.h" -#include "config_mgr.h" +#include "main_window.h" #include "debug.h" -#include "engine.h" #include "file_browser.h" #include "import_filter.h" #include "instrument.h" @@ -51,6 +51,8 @@ trackContainerView::trackContainerView( trackContainer * _tc ) : QWidget(), modelView( NULL, this ), + journallingObject(), + serializingObjectHook(), m_currentPosition( 0, 0 ), m_tc( _tc ), m_trackViews(), @@ -59,6 +61,8 @@ trackContainerView::trackContainerView( trackContainer * _tc ) : m_rubberBand( new rubberBand( m_scrollArea ) ), m_origin() { + m_tc->setHook( this ); + QVBoxLayout * layout = new QVBoxLayout( this ); layout->setMargin( 0 ); layout->setSpacing( 0 ); @@ -99,6 +103,23 @@ trackContainerView::~trackContainerView() +void trackContainerView::saveSettings( QDomDocument & _doc, + QDomElement & _this ) +{ + mainWindow::saveWidgetState( this, _this ); +} + + + + +void trackContainerView::loadSettings( const QDomElement & _this ) +{ + mainWindow::restoreWidgetState( this, _this ); +} + + + + trackView * trackContainerView::addTrackView( trackView * _tv ) { QMap map; diff --git a/src/gui/widgets/controller_rack_view.cpp b/src/gui/widgets/controller_rack_view.cpp index 425b84368..558dcec8a 100644 --- a/src/gui/widgets/controller_rack_view.cpp +++ b/src/gui/widgets/controller_rack_view.cpp @@ -43,8 +43,7 @@ controllerRackView::controllerRackView( ) : - QWidget(), - modelView( NULL, this ) + QWidget() { setFixedSize( 250, 250 ); setWindowIcon( embed::getIconPixmap( "controller" ) ); @@ -70,8 +69,6 @@ controllerRackView::controllerRackView( ) : m_lastY = 0; - setModel( engine::getSong() ); - QMdiSubWindow * subWin = engine::getMainWindow()->workspace()->addSubWindow( this ); Qt::WindowFlags flags = subWin->windowFlags(); @@ -90,64 +87,29 @@ controllerRackView::controllerRackView( ) : controllerRackView::~controllerRackView() { - clear(); + // delete scroll-area with all children + delete m_scrollArea; } - -void controllerRackView::clear( void ) +void controllerRackView::saveSettings( QDomDocument & _doc, + QDomElement & _this ) { -/* for( QVector::iterator it = m_controllerViews.begin(); - it != m_controllerViews.end(); ++it ) - { - delete *it; - } - m_controllerViews.clear();*/ + mainWindow::saveWidgetState( this, _this ); } -/* -void controllerRackView::moveUp( controllerView * _view ) + +void controllerRackView::loadSettings( const QDomElement & _this ) { - fxChain()->moveUp( _view->getEffect() ); - if( _view != m_effectViews.first() ) - { - int i = 0; - for( QVector::iterator it = - m_effectViews.begin(); - it != m_effectViews.end(); it++, i++ ) - { - if( *it == _view ) - { - break; - } - } - - effectView * temp = m_effectViews[ i - 1 ]; - - m_effectViews[i - 1] = _view; - m_effectViews[i] = temp; - - update(); - } -}*/ + mainWindow::restoreWidgetState( this, _this ); +} -/* -void controllerRackView::moveDown( effectView * _view ) -{ - if( _view != m_effectViews.last() ) - { - // moving next effect up is the same - moveUp( *( qFind( m_effectViews.begin(), m_effectViews.end(), - _view ) + 1 ) ); - } -}*/ - void controllerRackView::deleteController( controllerView * _view ) { @@ -162,6 +124,7 @@ void controllerRackView::deleteController( controllerView * _view ) + void controllerRackView::update( void ) { QWidget * w = m_scrollArea->widget(); @@ -173,7 +136,7 @@ void controllerRackView::update( void ) int i = 0; for( i = 0; i < m_controllerViews.size(); ++i ) { - delete m_controllerViews[i]; + delete m_controllerViews[i]; } m_controllerViews.clear(); @@ -193,57 +156,6 @@ void controllerRackView::update( void ) w->setFixedSize( 210, i*32 ); - /* - for( QVector::iterator it = fxChain()->m_effects.begin(); - it != fxChain()->m_effects.end(); ++it ) - { - int i = 0; - for( QVector::iterator vit = - m_effectViews.begin(); - vit != m_effectViews.end(); ++vit, ++i ) - { - if( ( *vit )->getEffect() == *it ) - { - view_map[i] = TRUE; - break; - } - } - if( i >= m_effectViews.size() ) - { - effectView * view = new effectView( *it, w ); - connect( view, SIGNAL( moveUp( effectView * ) ), - this, SLOT( moveUp( effectView * ) ) ); - connect( view, SIGNAL( moveDown( effectView * ) ), - this, SLOT( moveDown( effectView * ) ) ); - connect( view, SIGNAL( deletePlugin( effectView * ) ), - this, SLOT( deletePlugin( effectView * ) ) ); - view->show(); - m_effectViews.append( view ); - view_map[i] = TRUE; - - } - } - - int i = m_lastY = 0; - for( QVector::iterator it = m_effectViews.begin(); - it != m_effectViews.end(); ) - { - if( i < view_map.size() && i < m_effectViews.size() && - view_map[i] == FALSE ) - { - delete m_effectViews[i]; - m_effectViews.erase( it ); - } - else - { - ( *it )->move( 0, m_lastY ); - m_lastY += ( *it )->height(); - ++it; - ++i; - } - } - w->setFixedSize( 210, m_lastY ); -*/ setUpdatesEnabled( true ); QWidget::update(); } @@ -267,16 +179,6 @@ void controllerRackView::addController( void ) } -/* - -void effectRackView::modelChanged( void ) -{ - clear(); - m_effectsGroupBox->setModel( &fxChain()->m_enabledModel ); - update(); -} -*/ - #include "moc_controller_rack_view.cxx" diff --git a/src/tracks/instrument_track.cpp b/src/tracks/instrument_track.cpp index dfe20da38..97e4ba15b 100644 --- a/src/tracks/instrument_track.cpp +++ b/src/tracks/instrument_track.cpp @@ -681,10 +681,6 @@ void instrumentTrack::saveTrackSpecificSettings( QDomDocument & _doc, m_arpeggiator.saveState( _doc, _this ); m_midiPort.saveState( _doc, _this ); m_audioPort.getEffects()->saveState( _doc, _this ); - if( getHook() ) - { - getHook()->saveSettings( _doc, _this ); - } } @@ -792,11 +788,6 @@ void instrumentTrack::loadTrackSpecificSettings( const QDomElement & _this ) node = node.nextSibling(); } engine::getMixer()->unlock(); - - if( getHook() ) - { - getHook()->loadSettings( _this ); - } } @@ -959,6 +950,7 @@ void instrumentTrackView::freeInstrumentTrackWindow( void ) { if( s_windows.count() < INSTRUMENT_WINDOW_CACHE_SIZE ) { + model()->setHook( NULL ); m_window->parentWidget()->hide(); m_window->setModel( engine::getDummyTrackContainer()-> @@ -1001,6 +993,7 @@ instrumentTrackWindow * instrumentTrackView::getInstrumentTrackWindow( void ) m_window->setInstrumentTrackView( this ); m_window->setModel( model() ); m_window->updateInstrumentView(); + model()->setHook( m_window ); } else {