From c05965117c291c14949224a2269cbded803ea425 Mon Sep 17 00:00:00 2001 From: Tobias Doerffel Date: Wed, 6 Oct 2010 10:14:22 +0200 Subject: [PATCH] InstrumentTrackView: use QMdiArea's window activation history There's no need to implement an own (buggy) window activation history for InstrumentTrackWindows. Use QMdiArea::subWindowList(...) instead. Fixes buggy keyboard focus when switching between InstrumentTrackWindows. --- include/InstrumentTrack.h | 7 +----- src/gui/MainWindow.cpp | 9 +++++--- src/tracks/InstrumentTrack.cpp | 39 +++++++++++++++++----------------- 3 files changed, 26 insertions(+), 29 deletions(-) diff --git a/include/InstrumentTrack.h b/include/InstrumentTrack.h index d02b12dde..e690a595c 100644 --- a/include/InstrumentTrack.h +++ b/include/InstrumentTrack.h @@ -41,7 +41,6 @@ class QLineEdit; template class QQueue; -template class QStack; class ArpeggiatorView; class ChordCreatorView; class EffectRackView; @@ -260,10 +259,7 @@ public: return castModel(); } - static InstrumentTrackWindow * topLevelInstrumentTrackWindow() - { - return s_windowStack.isEmpty() ? NULL : s_windowStack.top(); - } + static InstrumentTrackWindow * topLevelInstrumentTrackWindow(); QMenu * midiMenu() { @@ -294,7 +290,6 @@ private: InstrumentTrackWindow * m_window; static QQueue s_windowCache; - static QStack s_windowStack; // widgets in track-settings-widget trackLabelButton * m_tlb; diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index e74eadc25..2f438b478 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -1243,15 +1243,18 @@ void MainWindow::keyPressEvent( QKeyEvent * _ke ) case Qt::Key_Shift: m_keyMods.m_shift = true; break; case Qt::Key_Alt: m_keyMods.m_alt = true; break; default: - if( InstrumentTrackView::topLevelInstrumentTrackWindow() ) + { + InstrumentTrackWindow * w = + InstrumentTrackView::topLevelInstrumentTrackWindow(); + if( w ) { - InstrumentTrackView::topLevelInstrumentTrackWindow()-> - pianoView()->keyPressEvent( _ke ); + w->pianoView()->keyPressEvent( _ke ); } if( !_ke->isAccepted() ) { QMainWindow::keyPressEvent( _ke ); } + } } } diff --git a/src/tracks/InstrumentTrack.cpp b/src/tracks/InstrumentTrack.cpp index 88beb5300..7f3571446 100644 --- a/src/tracks/InstrumentTrack.cpp +++ b/src/tracks/InstrumentTrack.cpp @@ -26,7 +26,6 @@ #include #include #include -#include #include #include #include @@ -876,7 +875,6 @@ Instrument * InstrumentTrack::loadInstrument( const QString & _plugin_name ) QQueue InstrumentTrackView::s_windowCache; -QStack InstrumentTrackView::s_windowStack; @@ -987,6 +985,24 @@ InstrumentTrackView::~InstrumentTrackView() +InstrumentTrackWindow * InstrumentTrackView::topLevelInstrumentTrackWindow() +{ + InstrumentTrackWindow * w = NULL; + foreach( QMdiSubWindow * sw, + engine::mainWindow()->workspace()->subWindowList( + QMdiArea::ActivationHistoryOrder ) ) + { + if( sw->isVisible() && sw->widget()->inherits( "InstrumentTrackWindow" ) ) + { + w = qobject_cast( sw->widget() ); + } + } + + return w; +} + + + // TODO: Add windows to free list on freeInstrumentTrackWindow. // But, don't NULL m_window or disconnect signals. This will allow windows // that are being show/hidden frequently to stay connected. @@ -994,12 +1010,6 @@ void InstrumentTrackView::freeInstrumentTrackWindow() { if( m_window != NULL ) { - if( qFind( s_windowStack.begin(), s_windowStack.end(), m_window ) != - s_windowStack.end() ) - { - s_windowStack.erase( - qFind( s_windowStack.begin(), s_windowStack.end(), m_window ) ); - } m_lastPos = m_window->parentWidget()->pos(); if( configManager::inst()->value( "ui", @@ -1102,23 +1112,12 @@ void InstrumentTrackView::dropEvent( QDropEvent * _de ) void InstrumentTrackView::toggleInstrumentWindow( bool _on ) { - InstrumentTrackWindow * w = getInstrumentTrackWindow(); - w->toggleVisibility( _on ); + getInstrumentTrackWindow()->toggleVisibility( _on ); if( !_on ) { freeInstrumentTrackWindow(); } - else - { - if( qFind( s_windowStack.begin(), s_windowStack.end(), w ) != - s_windowStack.end() ) - { - s_windowStack.erase( - qFind( s_windowStack.begin(), s_windowStack.end(), w ) ); - } - s_windowStack.push( w ); - } }