diff --git a/ScreenPlay/ScreenPlay.pro b/ScreenPlay/ScreenPlay.pro index 7e9ec4bc..86e2bf46 100644 --- a/ScreenPlay/ScreenPlay.pro +++ b/ScreenPlay/ScreenPlay.pro @@ -19,6 +19,7 @@ DISTFILES += \ RESOURCES += Resources.qrc SOURCES += main.cpp \ + app.cpp \ src/createimportvideo.cpp \ src/installedlistmodel.cpp \ src/monitorlistmodel.cpp \ @@ -39,6 +40,7 @@ TRANSLATIONS = translations/ScreenPlay_en.ts \ translations/ScreenPlay_de.ts HEADERS += \ + app.h \ src/globalvariables.h \ src/createimportvideo.h \ src/installedlistmodel.h \ diff --git a/ScreenPlay/app.cpp b/ScreenPlay/app.cpp new file mode 100644 index 00000000..3a604f92 --- /dev/null +++ b/ScreenPlay/app.cpp @@ -0,0 +1,65 @@ +#include "app.h" + +App::App(int& argc, char** argv) + : QObject(nullptr) + , app { std::make_unique(argc, argv) } + , mainWindowEngine{std::make_unique()} +{ + QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling); + QGuiApplication::setOrganizationName("ScreenPlay"); + QGuiApplication::setOrganizationDomain("screen-play.app"); + QGuiApplication::setApplicationName("ScreenPlay"); + QGuiApplication::setApplicationVersion("0.3.0"); + QGuiApplication::setQuitOnLastWindowClosed(false); + QGuiApplication::setWindowIcon(QIcon(":/assets/icons/favicon.ico")); + + // Qt < 6.0 needs this init QtWebEngine + QtWebEngine::initialize(); + + auto globalVariables = make_shared(); + auto installedListModel = make_shared(globalVariables); + auto installedListFilter = make_shared(installedListModel); + auto monitorListModel = make_shared(); + auto profileListModel = make_shared(globalVariables); + auto sdkConnector = make_shared(); + auto settings = make_shared(globalVariables); + QObject::connect(settings.get(), &Settings::resetInstalledListmodel, installedListModel.get(), &InstalledListModel::reset); + + Create create(globalVariables); + Util util { + mainWindowEngine->networkAccessManager() + }; + ScreenPlayManager screenPlay { + globalVariables, + monitorListModel, + sdkConnector + }; + + // This needs to change in the future because setContextProperty gets depricated in Qt 6 + mainWindowEngine->rootContext()->setContextProperty(QStringLiteral("globalVariables"), globalVariables.get()); + mainWindowEngine->rootContext()->setContextProperty(QStringLiteral("screenPlay"), &screenPlay); + mainWindowEngine->rootContext()->setContextProperty(QStringLiteral("screenPlayCreate"), &create); + mainWindowEngine->rootContext()->setContextProperty(QStringLiteral("utility"), &util); + mainWindowEngine->rootContext()->setContextProperty(QStringLiteral("installedListFilter"), installedListFilter.get()); + mainWindowEngine->rootContext()->setContextProperty(QStringLiteral("monitorListModel"), monitorListModel.get()); + mainWindowEngine->rootContext()->setContextProperty(QStringLiteral("installedListModel"), installedListModel.get()); + mainWindowEngine->rootContext()->setContextProperty(QStringLiteral("profileListModel"), profileListModel.get()); + mainWindowEngine->rootContext()->setContextProperty(QStringLiteral("screenPlaySettings"), settings.get()); + mainWindowEngine->load(QUrl(QStringLiteral("qrc:/main.qml"))); + + // Instead of setting "renderType: Text.NativeRendering" every time + // we can set it here once :) + QQuickWindow::setTextRenderType(QQuickWindow::TextRenderType::NativeTextRendering); + + // Set visible if the -silent parameter was not set + QStringList argumentList = app->arguments(); + if (!argumentList.contains("-silent")) { + settings->setMainWindowVisible(true); + } + installedListModel->init(); +} + +int App::run() +{ + return app->exec(); +} diff --git a/ScreenPlay/app.h b/ScreenPlay/app.h new file mode 100644 index 00000000..1346ae5f --- /dev/null +++ b/ScreenPlay/app.h @@ -0,0 +1,70 @@ +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "src/create.h" +#include "src/globalvariables.h" +#include "src/installedlistfilter.h" +#include "src/installedlistmodel.h" +#include "src/monitorlistmodel.h" +#include "src/profilelistmodel.h" +#include "src/screenplaymanager.h" +#include "src/sdkconnector.h" +#include "src/settings.h" +#include "src/util.h" + +using std::make_shared, + std::shared_ptr, + ScreenPlay::Util, + ScreenPlay::InstalledListModel, + ScreenPlay::ScreenPlayManager, + ScreenPlay::InstalledListFilter, + ScreenPlay::MonitorListModel, + ScreenPlay::ProfileListModel, + ScreenPlay::SDKConnector, + ScreenPlay::Settings, + ScreenPlay::Create; + +class App : public QObject { + Q_OBJECT + + Q_PROPERTY(shared_ptr globalVariables READ globalVariables WRITE setGlobalVariables NOTIFY globalVariablesChanged) +public: + explicit App(int &argc, char **argv); + + shared_ptr globalVariables() const + { + return m_globalVariables; + } + +signals: + + void globalVariablesChanged(shared_ptr globalVariables); + +public slots: +int run(); +void setGlobalVariables(shared_ptr globalVariables) +{ + if (m_globalVariables == globalVariables) + return; + + m_globalVariables = globalVariables; + emit globalVariablesChanged(m_globalVariables); +} + +private: + std::unique_ptr app; + std::unique_ptr mainWindowEngine; + shared_ptr m_globalVariables; +}; diff --git a/ScreenPlay/main.cpp b/ScreenPlay/main.cpp index 76fde9c6..c27290bc 100644 --- a/ScreenPlay/main.cpp +++ b/ScreenPlay/main.cpp @@ -1,97 +1,7 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include "src/create.h" -#include "src/globalvariables.h" -#include "src/installedlistfilter.h" -#include "src/installedlistmodel.h" -#include "src/monitorlistmodel.h" -#include "src/profilelistmodel.h" -#include "src/screenplaymanager.h" -#include "src/sdkconnector.h" -#include "src/settings.h" -#include "src/util.h" - -using std::make_shared, - ScreenPlay::Util, - ScreenPlay::InstalledListModel, - ScreenPlay::ScreenPlayManager, - ScreenPlay::InstalledListFilter, - ScreenPlay::MonitorListModel, - ScreenPlay::ProfileListModel, - ScreenPlay::SDKConnector, - ScreenPlay::Settings, - ScreenPlay::Create; +#include "app.h" int main(int argc, char* argv[]) { - - QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling); - QGuiApplication::setOrganizationName("ScreenPlay"); - QGuiApplication::setOrganizationDomain("screen-play.app"); - QGuiApplication::setApplicationName("ScreenPlay"); - QGuiApplication::setApplicationVersion("0.3.0"); - - QGuiApplication app(argc, argv); - - QGuiApplication::setQuitOnLastWindowClosed(false); - QGuiApplication::setWindowIcon(QIcon(":/assets/icons/favicon.ico")); - - // Qt < 6.0 needs this init QtWebEngine - QtWebEngine::initialize(); - QQmlApplicationEngine mainWindowEngine; - - auto globalVariables = make_shared(); - auto installedListModel = make_shared(globalVariables); - auto installedListFilter = make_shared(installedListModel); - auto monitorListModel = make_shared(); - auto profileListModel = make_shared(globalVariables); - auto sdkConnector = make_shared(); - auto settings = make_shared(globalVariables); - QObject::connect(settings.get(), &Settings::resetInstalledListmodel, installedListModel.get(), &InstalledListModel::reset); - - Create create(globalVariables); - Util util { - mainWindowEngine.networkAccessManager() - }; - ScreenPlayManager screenPlay { - globalVariables, - monitorListModel, - sdkConnector - }; - - // This needs to change in the future because setContextProperty gets depricated in Qt 6 - mainWindowEngine.rootContext()->setContextProperty(QStringLiteral("globalVariables"), globalVariables.get()); - mainWindowEngine.rootContext()->setContextProperty(QStringLiteral("screenPlay"), &screenPlay); - mainWindowEngine.rootContext()->setContextProperty(QStringLiteral("screenPlayCreate"), &create); - mainWindowEngine.rootContext()->setContextProperty(QStringLiteral("utility"), &util); - mainWindowEngine.rootContext()->setContextProperty(QStringLiteral("installedListFilter"), installedListFilter.get()); - mainWindowEngine.rootContext()->setContextProperty(QStringLiteral("monitorListModel"), monitorListModel.get()); - mainWindowEngine.rootContext()->setContextProperty(QStringLiteral("installedListModel"), installedListModel.get()); - mainWindowEngine.rootContext()->setContextProperty(QStringLiteral("profileListModel"), profileListModel.get()); - mainWindowEngine.rootContext()->setContextProperty(QStringLiteral("screenPlaySettings"), settings.get()); - mainWindowEngine.load(QUrl(QStringLiteral("qrc:/main.qml"))); - - // Instead of setting "renderType: Text.NativeRendering" every time - // we can set it here once :) - QQuickWindow::setTextRenderType(QQuickWindow::TextRenderType::NativeTextRendering); - - // Set visible if the -silent parameter was not set - QStringList argumentList = app.arguments(); - if (!argumentList.contains("-silent")) { - settings->setMainWindowVisible(true); - } - installedListModel->init(); - - return app.exec(); + App app(argc,argv); + return app.run(); }