diff --git a/include/Editor.h b/include/Editor.h index 681bce46c..a5b667166 100644 --- a/include/Editor.h +++ b/include/Editor.h @@ -56,7 +56,7 @@ protected: DropToolBar * addDropToolBar(Qt::ToolBarArea whereToAdd, QString const & windowTitle); DropToolBar * addDropToolBar(QWidget * parent, Qt::ToolBarArea whereToAdd, QString const & windowTitle); - void closeEvent( QCloseEvent * _ce ) override; + void closeEvent(QCloseEvent * event) override; protected slots: virtual void play() {} virtual void record() {} diff --git a/include/MainWindow.h b/include/MainWindow.h index 4442a7ac2..6c140a1e6 100644 --- a/include/MainWindow.h +++ b/include/MainWindow.h @@ -72,6 +72,8 @@ public: LMMS_EXPORT SubWindow* addWindowedWidget(QWidget *w, Qt::WindowFlags windowFlags = QFlag(0)); + void refocus(); + /// /// \brief Asks whether changes made to the project are to be saved. /// @@ -195,7 +197,6 @@ private: void finalize(); void toggleWindow( QWidget *window, bool forceShow = false ); - void refocus(); void exportProject(bool multiExport = false); void handleSaveResult(QString const & filename, bool songSavedSuccessfully); diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index fa0c50956..c45ea14ac 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -975,26 +975,21 @@ void MainWindow::toggleFullscreen() */ void MainWindow::refocus() { - QList editors; - editors - << getGUI()->songEditor()->parentWidget() - << getGUI()->patternEditor()->parentWidget() - << getGUI()->pianoRoll()->parentWidget() - << getGUI()->automationEditor()->parentWidget(); + const auto gui = getGUI(); - bool found = false; - QList::Iterator editor; - for( editor = editors.begin(); editor != editors.end(); ++editor ) + // Attempt to set the focus on the first of these editors that is not hidden... + for (auto editorParent : { gui->songEditor()->parentWidget(), gui->patternEditor()->parentWidget(), + gui->pianoRoll()->parentWidget(), gui->automationEditor()->parentWidget() }) { - if( ! (*editor)->isHidden() ) { - (*editor)->setFocus(); - found = true; - break; + if (!editorParent->isHidden()) + { + editorParent->setFocus(); + return; } } - if( ! found ) - this->setFocus(); + // ... otherwise set the focus on the main window. + this->setFocus(); } diff --git a/src/gui/editors/Editor.cpp b/src/gui/editors/Editor.cpp index a61c2cd60..ab12e3fb9 100644 --- a/src/gui/editors/Editor.cpp +++ b/src/gui/editors/Editor.cpp @@ -24,6 +24,8 @@ #include "Editor.h" +#include "GuiApplication.h" +#include "MainWindow.h" #include "Song.h" #include "embed.h" @@ -138,7 +140,7 @@ QAction *Editor::playAction() const return m_playAction; } -void Editor::closeEvent( QCloseEvent * _ce ) +void Editor::closeEvent(QCloseEvent * event) { if( parentWidget() ) { @@ -148,7 +150,8 @@ void Editor::closeEvent( QCloseEvent * _ce ) { hide(); } - _ce->accept(); + getGUI()->mainWindow()->refocus(); + event->ignore(); } DropToolBar::DropToolBar(QWidget* parent) : QToolBar(parent)