Skip to content

Commit

Permalink
Refactor MainWindow::refocus
Browse files Browse the repository at this point in the history
Refactor `MainWindow::refocus` to make it more readable and
straight-forward. Replace the Qt collection with a vector so that we
can do a simple foreach loop. Also remove the local variable `found` by
returning early on success or setting the focus on the main window
otherwise.

Remove code repetition by fetching the GUI once via `getGUI`.
  • Loading branch information
michaelgregorius committed Sep 24, 2024
1 parent 991fa07 commit 4e78fb5
Showing 1 changed file with 14 additions and 17 deletions.
31 changes: 14 additions & 17 deletions src/gui/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -975,26 +975,23 @@ void MainWindow::toggleFullscreen()
*/
void MainWindow::refocus()
{
QList<QWidget*> editors;
editors
<< getGUI()->songEditor()->parentWidget()
<< getGUI()->patternEditor()->parentWidget()
<< getGUI()->pianoRoll()->parentWidget()
<< getGUI()->automationEditor()->parentWidget();

bool found = false;
QList<QWidget*>::Iterator editor;
for( editor = editors.begin(); editor != editors.end(); ++editor )
{
if( ! (*editor)->isHidden() ) {
(*editor)->setFocus();
found = true;
break;
const auto gui = getGUI();

// Attempt to set the focus on the first of these editors that is not hidden...
const std::vector<QWidget*> editorParents = { gui->songEditor()->parentWidget(), gui->patternEditor()->parentWidget(),
gui->pianoRoll()->parentWidget(), gui->automationEditor()->parentWidget() };

for (auto editorParent : editorParents)
{
if(!editorParent->isHidden())
{
editorParent->setFocus();
return;
}
}

if( ! found )
this->setFocus();
// ... otherwise set the focus on the main window.
this->setFocus();
}


Expand Down

0 comments on commit 4e78fb5

Please sign in to comment.