refactor: Transform launcher into QMainWindow

This commit is contained in:
Lars Toenning
2024-02-14 22:48:10 +01:00
parent b8a376701b
commit 9da0630063
4 changed files with 790 additions and 798 deletions

View File

@@ -40,11 +40,13 @@ int main(int argc, char *argv[])
} }
//! [SwiftApplicationDemo] //! [SwiftApplicationDemo]
// Dialog to decide external or internal core
CSwiftLauncher launcher; CSwiftLauncher launcher;
CGuiApplication::registerAsRunning(); // needed because launcher's exec is called (normally application exec) const int res = CGuiApplication::exec();
if (launcher.exec() == QDialog::Rejected) { return EXIT_SUCCESS; } if (res != EXIT_SUCCESS || !launcher.shouldStartAppDetached())
launcher.close(); {
return res;
}
const bool s = launcher.startDetached(); const bool s = launcher.startDetached();
return s ? EXIT_SUCCESS : EXIT_FAILURE; return s ? EXIT_SUCCESS : EXIT_FAILURE;
} }

View File

@@ -50,7 +50,7 @@ using namespace BlackMisc::Simulation;
using namespace BlackMisc::Simulation::Data; using namespace BlackMisc::Simulation::Data;
using namespace BlackMisc::Simulation::FsCommon; using namespace BlackMisc::Simulation::FsCommon;
CSwiftLauncher::CSwiftLauncher(QWidget *parent) : QDialog(parent, CEnableForFramelessWindow::modeToWindowFlags(CEnableForFramelessWindow::WindowNormal)), CSwiftLauncher::CSwiftLauncher(QWidget *parent) : QMainWindow(parent, CEnableForFramelessWindow::modeToWindowFlags(CEnableForFramelessWindow::WindowNormal)),
CEnableForFramelessWindow(CEnableForFramelessWindow::WindowFrameless, true, "framelessMainWindow", this), CEnableForFramelessWindow(CEnableForFramelessWindow::WindowFrameless, true, "framelessMainWindow", this),
CCentralMultiSimulatorModelSetCachesAware(), CCentralMultiSimulatorModelSetCachesAware(),
CIdentifiable(this), CIdentifiable(this),
@@ -116,6 +116,8 @@ CSwiftLauncher::CSwiftLauncher(QWidget *parent) : QDialog(parent, CEnableForFram
this->requestMacMicrophoneAccess(); this->requestMacMicrophoneAccess();
this->installerMode(); this->installerMode();
}); });
this->show();
} }
void CSwiftLauncher::installerMode() void CSwiftLauncher::installerMode()
@@ -204,18 +206,18 @@ CoreModes::CoreMode CSwiftLauncher::getCoreMode() const
void CSwiftLauncher::mousePressEvent(QMouseEvent *event) void CSwiftLauncher::mousePressEvent(QMouseEvent *event)
{ {
if (!handleMousePressEvent(event)) { QDialog::mousePressEvent(event); } if (!handleMousePressEvent(event)) { QMainWindow::mousePressEvent(event); }
} }
void CSwiftLauncher::mouseMoveEvent(QMouseEvent *event) void CSwiftLauncher::mouseMoveEvent(QMouseEvent *event)
{ {
if (!handleMouseMoveEvent(event)) { QDialog::mouseMoveEvent(event); } if (!handleMouseMoveEvent(event)) { QMainWindow::mouseMoveEvent(event); }
} }
void CSwiftLauncher::mouseReleaseEvent(QMouseEvent *event) void CSwiftLauncher::mouseReleaseEvent(QMouseEvent *event)
{ {
m_framelessDragPosition = QPoint(); m_framelessDragPosition = QPoint();
QDialog::mouseReleaseEvent(event); QMainWindow::mouseReleaseEvent(event);
} }
void CSwiftLauncher::updateInfoAvailable() void CSwiftLauncher::updateInfoAvailable()
@@ -443,7 +445,7 @@ void CSwiftLauncher::startButtonPressed()
} }
else else
{ {
this->accept(); close();
} }
} }
} }
@@ -459,7 +461,7 @@ void CSwiftLauncher::startButtonPressed()
} }
else else
{ {
this->accept(); close();
} }
} }
} }
@@ -612,6 +614,11 @@ void CSwiftLauncher::showSimulatorConfigDirs()
m_textEditDialog->show(); m_textEditDialog->show();
} }
bool CSwiftLauncher::shouldStartAppDetached() const
{
return !m_executable.isEmpty();
}
void CSwiftLauncher::requestMacMicrophoneAccess() void CSwiftLauncher::requestMacMicrophoneAccess()
{ {
// needed to be able to start core/GUI which need MIC access // needed to be able to start core/GUI which need MIC access

View File

@@ -21,7 +21,7 @@
# include "blackmisc/macos/microphoneaccess.h" # include "blackmisc/macos/microphoneaccess.h"
#endif #endif
#include <QDialog> #include <QMainWindow>
#include <QTimer> #include <QTimer>
#include <QScopedPointer> #include <QScopedPointer>
#include <QNetworkReply> #include <QNetworkReply>
@@ -41,10 +41,9 @@ namespace BlackGui::Components
* \note Besides the fact the launcher makes it easy to start our applications it also pre-fetches some * \note Besides the fact the launcher makes it easy to start our applications it also pre-fetches some
* cache files, hence reducing load times in the subsequent applications. Therefor starting via the launcher * cache files, hence reducing load times in the subsequent applications. Therefor starting via the launcher
* is preferable, but not mandatory. * is preferable, but not mandatory.
* \fixme it was better if launcher was a QMainWindow, because we have to deal with main widgets QDialog and QMainWindow because of launcher
*/ */
class CSwiftLauncher : class CSwiftLauncher :
public QDialog, public QMainWindow,
public BlackGui::CEnableForFramelessWindow, public BlackGui::CEnableForFramelessWindow,
public BlackGui::IMainWindowAccess, public BlackGui::IMainWindowAccess,
public BlackMisc::Simulation::Data::CCentralMultiSimulatorModelSetCachesAware, public BlackMisc::Simulation::Data::CCentralMultiSimulatorModelSetCachesAware,
@@ -82,6 +81,9 @@ public:
//! \remark simplifies debugging //! \remark simplifies debugging
bool startDetached(); bool startDetached();
//! Check if an app is set that should be started detached
bool shouldStartAppDetached() const;
protected: protected:
//! Mouse events for frameless window //! Mouse events for frameless window
//! @{ //! @{

File diff suppressed because it is too large Load Diff