yuxshao / ptcollab

A collaborative piano-roll music sequencer!
https://yuxshao.github.io/ptcollab/
MIT License
96 stars 12 forks source link

EditorWindow: Make Quit option trigger window close events #115

Closed OPNA2608 closed 1 year ago

OPNA2608 commented 1 year ago

Currently, selecting the "Quit" menu option will trigger an instant shutdown of the application via QCoreApplication::quit(), which acts akin to instantly returning from main. Doing it this way doesn't trigger any QWindow::closeEvents by design though, so our "unsaved changes" check on the EditorWindow is bypassed.

Making the button work that way is confusing for users: There is no warning about unsaved changes, backups do not get cleaned up, and on the next startup it is treated like an unexpected termination - all because a menu option was used instead of the OS' window controls.

Instead of QCoreApplication::quit(), call QApplication::closeAllWindows(). This has the same effect of shutting down the application, but it's achieved by sending close events to all windows instead, which is exactly what we need. In fact, the documentation of this method[1] even points out that it's ideal for hooking up to an Exit menu option.

[1]: At least for Qt 5.15 LTS, https://doc.qt.io/qt-5/qapplication.html#closeAllWindows