Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix empty editor windows #7515

Merged
merged 7 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/Editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class Editor : public QMainWindow
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() {}
Expand Down
3 changes: 2 additions & 1 deletion include/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ class MainWindow : public QMainWindow
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.
///
Expand Down Expand Up @@ -195,7 +197,6 @@ private slots:
void finalize();

void toggleWindow( QWidget *window, bool forceShow = false );
void refocus();

void exportProject(bool multiExport = false);
void handleSaveResult(QString const & filename, bool songSavedSuccessfully);
Expand Down
29 changes: 12 additions & 17 deletions src/gui/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -975,26 +975,21 @@ 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...
for (auto editorParent : { gui->songEditor()->parentWidget(), gui->patternEditor()->parentWidget(),
gui->pianoRoll()->parentWidget(), gui->automationEditor()->parentWidget() })
{
if (!editorParent->isHidden())
{
editorParent->setFocus();
return;
}
}

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


Expand Down
7 changes: 5 additions & 2 deletions src/gui/editors/Editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

#include "Editor.h"

#include "GuiApplication.h"
#include "MainWindow.h"
#include "Song.h"

#include "embed.h"
Expand Down Expand Up @@ -138,7 +140,7 @@ QAction *Editor::playAction() const
return m_playAction;
}

void Editor::closeEvent( QCloseEvent * _ce )
void Editor::closeEvent(QCloseEvent * event)
{
if( parentWidget() )
{
Expand All @@ -148,7 +150,8 @@ void Editor::closeEvent( QCloseEvent * _ce )
{
hide();
}
_ce->accept();
getGUI()->mainWindow()->refocus();
event->ignore();
}

DropToolBar::DropToolBar(QWidget* parent) : QToolBar(parent)
Expand Down
Loading