diff --git a/include/MainWindow.h b/include/MainWindow.h index a8aae83c5..9fd9acecd 100644 --- a/include/MainWindow.h +++ b/include/MainWindow.h @@ -145,6 +145,7 @@ private: void finalize(); void toggleWindow( QWidget *window, bool forceShow = false ); + void refocus(); QMdiArea * m_workspace; diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index 9566ec110..fa051e69f 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -879,6 +879,7 @@ void MainWindow::toggleWindow( QWidget *window, bool forceShow ) else { parent->hide(); + refocus(); } // Workaround for Qt Bug #260116 @@ -891,6 +892,38 @@ void MainWindow::toggleWindow( QWidget *window, bool forceShow ) +/* + * When an editor window with focus is toggled off, attempt to set focus + * to the next visible editor window, or if none are visible, set focus + * to the parent window. + */ +void MainWindow::refocus() +{ + QList editors; + editors + << Engine::songEditor()->parentWidget() + << Engine::getBBEditor()->parentWidget() + << Engine::pianoRoll()->parentWidget() + << Engine::automationEditor()->parentWidget(); + + bool found = false; + QList::Iterator editor; + for( editor = editors.begin(); editor != editors.end(); ++editor ) + { + if( ! (*editor)->isHidden() ) { + (*editor)->setFocus(); + found = true; + break; + } + } + + if( ! found ) + this->setFocus(); +} + + + + void MainWindow::toggleBBEditorWin( bool forceShow ) { toggleWindow( Engine::getBBEditor(), forceShow );