From 5c530f5e132377d1de270a82ad58ad7958288082 Mon Sep 17 00:00:00 2001 From: Elias Date: Thu, 7 Feb 2019 14:16:38 +0100 Subject: [PATCH] Move Window and widget location setup into settings --- ScreenPlay/main.cpp | 58 ++---------------------------------- ScreenPlay/src/settings.cpp | 59 +++++++++++++++++++++++++++++++++++++ ScreenPlay/src/settings.h | 1 + 3 files changed, 62 insertions(+), 56 deletions(-) diff --git a/ScreenPlay/main.cpp b/ScreenPlay/main.cpp index ff6f9c51..216aa45c 100644 --- a/ScreenPlay/main.cpp +++ b/ScreenPlay/main.cpp @@ -50,6 +50,7 @@ int main(int argc, char* argv[]) // This gives us nice clickable output in QtCreator qSetMessagePattern("%{if-category}%{category}: %{endif}%{message}\n Loc: [%{file}:%{line}]"); + // Qt < 6.0 needs this init QtWebEngine QtWebEngine::initialize(); QFontDatabase::addApplicationFont(":/assets/fonts/LibreBaskerville-Italic.ttf"); @@ -73,67 +74,12 @@ int main(int argc, char* argv[]) ScreenPlay screenPlay(&installedListModel, &settings, &monitorListModel, &app, &sdkConnector); Create create(&settings, &qmlUtil); - QDir SPWorkingDir(QDir::currentPath()); - QDir SPBaseDir(QDir::currentPath()); - -#ifdef QT_DEBUG - qDebug() << "Starting in Debug mode!"; - - if (SPWorkingDir.cdUp()) { -#ifdef Q_OS_OSX - settings.setScreenPlayWindowPath(QUrl::fromUserInput(SPWorkingDir.path() + "/../../../ScreenPlayWindow/ScreenPlayWindow.app/Contents/MacOS/ScreenPlayWindow").toLocalFile()); - settings.setScreenPlayWidgetPath(QUrl::fromUserInput(SPWorkingDir.path() + "/../../../ScreenPlayWidget/ScreenPlayWidget.app/Contents/MacOS/ScreenPlayWidget").toLocalFile()); - qDebug() << "Setting ScreenPlayWindow Path to " << settings.getScreenPlayWindowPath(); - qDebug() << "Setting ScreenPlayWdiget Path to " << settings.getScreenPlayWidgetPath(); -#endif - -#ifdef Q_OS_WIN - settings.setScreenPlayWindowPath(QUrl(SPWorkingDir.path() + "/ScreenPlayWindow/debug/ScreenPlayWindow.exe")); - settings.setScreenPlayWidgetPath(QUrl(SPWorkingDir.path() + "/ScreenPlayWidget/debug/ScreenPlayWidget.exe")); -#endif - } - - // We need to detect the right base path so we can copy later the example projects - SPBaseDir.cdUp(); - SPBaseDir.cdUp(); - SPBaseDir.cd("ScreenPlay"); - SPBaseDir.cd("ScreenPlay"); - settings.setScreenPlayBasePath(QUrl(SPBaseDir.path())); -#endif -#ifdef QT_NO_DEBUG - qDebug() << "Starting in Release mode!"; - settings.setScreenPlayBasePath(QUrl(SPWorkingDir.path())); - - // If we build in the release version we must be cautious! - // The working dir in steam is the ScreenPlay.exe location - // In QtCreator is the dir above ScreenPlay.exe (!) - - SPWorkingDir.cdUp(); - SPWorkingDir.cd("ScreenPlayWindow"); - - if (QDir(SPWorkingDir.path() + "/release").exists()) { - // If started by QtCreator - SPWorkingDir.cd("release"); - settings.setScreenPlayWindowPath(QUrl(SPWorkingDir.path() + "/ScreenPlayWindow.exe")); - SPWorkingDir.cdUp(); - SPWorkingDir.cdUp(); - SPWorkingDir.cd("ScreenPlayWidget"); - SPWorkingDir.cd("release"); - settings.setScreenPlayWidgetPath(QUrl(SPWorkingDir.path() + "/ScreenPlayWidget.exe")); - } else { - // If started by Steam - settings.setScreenPlayWindowPath(QUrl("ScreenPlayWindow.exe")); - settings.setScreenPlayWidgetPath(QUrl("ScreenPlayWidget.exe")); - } -#endif - // All the list need the default path from the settings // to know where to look for the files profileListModel.loadProfiles(); settings.loadActiveProfiles(); QQmlApplicationEngine mainWindowEngine; - mainWindowEngine.rootContext()->setContextProperty("screenPlay", &screenPlay); mainWindowEngine.rootContext()->setContextProperty("screenPlayCreate", &create); mainWindowEngine.rootContext()->setContextProperty("utility", &qmlUtil); @@ -142,8 +88,8 @@ int main(int argc, char* argv[]) mainWindowEngine.rootContext()->setContextProperty("installedListModel", &installedListModel); mainWindowEngine.rootContext()->setContextProperty("profileListModel", &profileListModel); mainWindowEngine.rootContext()->setContextProperty("screenPlaySettings", &settings); - mainWindowEngine.load(QUrl(QStringLiteral("qrc:/main.qml"))); + installedListFilter.sortByRoleType("All"); installedListModel.loadScreens(); diff --git a/ScreenPlay/src/settings.cpp b/ScreenPlay/src/settings.cpp index a3d824eb..497928c0 100644 --- a/ScreenPlay/src/settings.cpp +++ b/ScreenPlay/src/settings.cpp @@ -113,6 +113,8 @@ Settings::Settings(ProfileListModel* plm, MonitorListModel* mlm, InstalledListMo m_checkForOtherFullscreenApplicationTimer = new QTimer(this); connect(m_checkForOtherFullscreenApplicationTimer, &QTimer::timeout, this, &Settings::checkForOtherFullscreenApplication); m_checkForOtherFullscreenApplicationTimer->start(1500); + + setupWidgetAndWindowPaths(); } Settings::~Settings() @@ -319,6 +321,63 @@ void Settings::createDefaultConfig() defaultSettings.close(); } +void Settings::setupWidgetAndWindowPaths() +{ + QDir SPWorkingDir(QDir::currentPath()); + QDir SPBaseDir(QDir::currentPath()); + +#ifdef QT_DEBUG + qDebug() << "Starting in Debug mode!"; + + if (SPWorkingDir.cdUp()) { +#ifdef Q_OS_OSX + setScreenPlayWindowPath(QUrl::fromUserInput(SPWorkingDir.path() + "/../../../ScreenPlayWindow/ScreenPlayWindow.app/Contents/MacOS/ScreenPlayWindow").toLocalFile()); + setScreenPlayWidgetPath(QUrl::fromUserInput(SPWorkingDir.path() + "/../../../ScreenPlayWidget/ScreenPlayWidget.app/Contents/MacOS/ScreenPlayWidget").toLocalFile()); + qDebug() << "Setting ScreenPlayWindow Path to " << settings.getScreenPlayWindowPath(); + qDebug() << "Setting ScreenPlayWdiget Path to " << settings.getScreenPlayWidgetPath(); +#endif + +#ifdef Q_OS_WIN + setScreenPlayWindowPath(QUrl(SPWorkingDir.path() + "/ScreenPlayWindow/debug/ScreenPlayWindow.exe")); + setScreenPlayWidgetPath(QUrl(SPWorkingDir.path() + "/ScreenPlayWidget/debug/ScreenPlayWidget.exe")); +#endif + } + + // We need to detect the right base path so we can copy later the example projects + SPBaseDir.cdUp(); + SPBaseDir.cdUp(); + SPBaseDir.cd("ScreenPlay"); + SPBaseDir.cd("ScreenPlay"); + setScreenPlayBasePath(QUrl(SPBaseDir.path())); +#endif +#ifdef QT_NO_DEBUG + qDebug() << "Starting in Release mode!"; + setScreenPlayBasePath(QUrl(SPWorkingDir.path())); + + // If we build in the release version we must be cautious! + // The working dir in steam is the ScreenPlay.exe location + // In QtCreator is the dir above ScreenPlay.exe (!) + + SPWorkingDir.cdUp(); + SPWorkingDir.cd("ScreenPlayWindow"); + + if (QDir(SPWorkingDir.path() + "/release").exists()) { + // If started by QtCreator + SPWorkingDir.cd("release"); + settings.setScreenPlayWindowPath(QUrl(SPWorkingDir.path() + "/ScreenPlayWindow.exe")); + SPWorkingDir.cdUp(); + SPWorkingDir.cdUp(); + SPWorkingDir.cd("ScreenPlayWidget"); + SPWorkingDir.cd("release"); + setScreenPlayWidgetPath(QUrl(SPWorkingDir.path() + "/ScreenPlayWidget.exe")); + } else { + // If started by Steam + setScreenPlayWindowPath(QUrl("ScreenPlayWindow.exe")); + setScreenPlayWidgetPath(QUrl("ScreenPlayWidget.exe")); + } +#endif +} + bool Settings::getOfflineMode() const { return m_offlineMode; diff --git a/ScreenPlay/src/settings.h b/ScreenPlay/src/settings.h index 71eeb8fd..4753fbe0 100644 --- a/ScreenPlay/src/settings.h +++ b/ScreenPlay/src/settings.h @@ -293,6 +293,7 @@ public slots: private: void createDefaultConfig(); + void setupWidgetAndWindowPaths(); QVersionNumber m_version; QSettings m_qSettings;