standard macOS app behavior

This commit is contained in:
Ryan Cao 2022-05-24 13:35:01 +08:00
parent dca4ea5cea
commit 0426149580
No known key found for this signature in database
GPG Key ID: 528A2C1B6656B97F
2 changed files with 31 additions and 0 deletions

View File

@ -871,6 +871,10 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv)
m_mcedit.reset(new MCEditTool(m_settings));
}
connect(this, &Application::clickedOnDock, [this]() {
this->showMainWindow();
});
connect(this, &Application::aboutToQuit, [this](){
if(m_instances)
{
@ -954,6 +958,22 @@ bool Application::createSetupWizard()
return false;
}
bool Application::event(QEvent* event) {
#ifdef Q_OS_MACOS
if (event->type() == QEvent::ApplicationStateChange) {
auto ev = static_cast<QApplicationStateChangeEvent*>(event);
if (m_prevAppState == Qt::ApplicationActive
&& ev->applicationState() == Qt::ApplicationActive) {
qDebug() << "Clicked on dock!";
emit clickedOnDock();
}
m_prevAppState = ev->applicationState();
}
#endif
return QApplication::event(event);
}
void Application::setupWizardFinished(int status)
{
qDebug() << "Wizard result =" << status;
@ -1284,6 +1304,10 @@ void Application::subRunningInstance()
bool Application::shouldExitNow() const
{
#ifdef Q_OS_MACOS
return false;
#endif
return m_runningInstances == 0 && m_openWindows == 0;
}

View File

@ -94,6 +94,8 @@ public:
Application(int &argc, char **argv);
virtual ~Application();
bool event(QEvent* event) override;
std::shared_ptr<SettingsObject> settings() const {
return m_settings;
}
@ -180,6 +182,7 @@ signals:
void updateAllowedChanged(bool status);
void globalSettingsAboutToOpen();
void globalSettingsClosed();
void clickedOnDock();
public slots:
bool launch(
@ -238,6 +241,10 @@ private:
QString m_rootPath;
Status m_status = Application::StartingUp;
#ifdef Q_OS_MACOS
Qt::ApplicationState m_prevAppState = Qt::ApplicationInactive;
#endif
#if defined Q_OS_WIN32
// used on Windows to attach the standard IO streams
bool consoleAttached = false;