From f482a6a43adbc2244fc6f02af2566242204a21a4 Mon Sep 17 00:00:00 2001 From: kelteseth Date: Sat, 13 May 2017 10:50:15 +0200 Subject: [PATCH] Add basic settings --- .gitmodules | 3 + ScreenPlay.pro | 6 +- ThirdParty/QJsonModel | 1 + main.cpp | 18 ++-- qml.qrc | 4 + qml/Components/Headline.qml | 53 ++++++++++++ qml/Components/Settings.qml | 44 +++++++++- qml/Components/Settings/SettingBool.qml | 46 ++++++++++ qml/Components/SettingsItemBool.qml | 5 ++ qtquickcontrols2.conf | 15 ++++ settings.json | 10 +++ src/settings.cpp | 41 ++++++--- src/settings.h | 109 ++++++++++++++++++++---- 13 files changed, 311 insertions(+), 44 deletions(-) create mode 160000 ThirdParty/QJsonModel create mode 100644 qml/Components/Headline.qml create mode 100644 qml/Components/Settings/SettingBool.qml create mode 100644 qml/Components/SettingsItemBool.qml create mode 100644 qtquickcontrols2.conf create mode 100644 settings.json diff --git a/.gitmodules b/.gitmodules index 9f0e909e..e2da208e 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "ThirdParty/QtAV"] path = ThirdParty/QtAV url = https://github.com/wang-bin/QtAV.git +[submodule "ThirdParty/QJsonModel"] + path = ThirdParty/QJsonModel + url = https://github.com/dridk/QJsonModel.git diff --git a/ScreenPlay.pro b/ScreenPlay.pro index b37d7243..a3653bb5 100644 --- a/ScreenPlay.pro +++ b/ScreenPlay.pro @@ -1,6 +1,7 @@ TEMPLATE = app QT += qml quick av widgets +QT += qml quick av widgets quickcontrols2 CONFIG += c++14 QtAV SOURCES += main.cpp \ @@ -8,7 +9,7 @@ SOURCES += main.cpp \ src/steamworkshop.cpp \ src/installedlistmodel.cpp \ src/backend.cpp \ - src/monitorlistmodel.cpp + src/monitorlistmodel.cpp \ src/settings.cpp RESOURCES += qml.qrc @@ -18,7 +19,7 @@ HEADERS += \ src/steamworkshop.h \ src/installedlistmodel.h \ src/backend.h \ - src/monitorlistmodel.h + src/monitorlistmodel.h \ src/settings.h INCLUDEPATH += \ @@ -35,6 +36,7 @@ CONFIG(debug, debug|release) { install_it.files += assets/templates/config.json \ assets/icons/favicon.ico \ steam_appid.txt \ + settings.json \ INSTALLS += install_it diff --git a/ThirdParty/QJsonModel b/ThirdParty/QJsonModel new file mode 160000 index 00000000..5ccca6e2 --- /dev/null +++ b/ThirdParty/QJsonModel @@ -0,0 +1 @@ +Subproject commit 5ccca6e2e28fe93edfb9df319079d8a55c365ca5 diff --git a/main.cpp b/main.cpp index f6efb569..28656471 100644 --- a/main.cpp +++ b/main.cpp @@ -1,19 +1,20 @@ #include #include #include +#include #include #include #include #include #include +#include #include -#include #include #include #include #include +#include #include -#include #include "backend.h" #include "installedlistmodel.h" @@ -26,34 +27,29 @@ int main(int argc, char* argv[]) QGuiApplication app(argc, argv); QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling); - QCoreApplication::setOrganizationName("Aimber"); QCoreApplication::setOrganizationDomain("aimber.net"); QCoreApplication::setApplicationName("ScreenPlay"); app.setWindowIcon(QIcon(":/assets/icons/favicon.ico")); + QQuickStyle::setStyle("Material"); InstalledListModel installedListModel; MonitorListModel monitorListModel; - Backend backend; + Settings settings; QQmlApplicationEngine mainWindow; mainWindow.rootContext()->setContextProperty("monitorListModel", &monitorListModel); mainWindow.rootContext()->setContextProperty("installedListModel", &installedListModel); - mainWindow.rootContext()->setContextProperty("backend", &backend); + mainWindow.rootContext()->setContextProperty("settings", &settings); mainWindow.load(QUrl(QStringLiteral("qrc:/qml/main.qml"))); - QObject::connect(&mainWindow, SIGNAL(exitScreenPlay()), &app, SLOT(app.exit())); - ScreenPlay sp(GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN)); sp.context()->setContextProperty("installedListModel", &installedListModel); - sp.context()->setContextProperty("backend", &backend); + sp.context()->setContextProperty("settings", &settings); sp.loadQQuickView(QUrl(QStringLiteral("qrc:/qml/Components/ScreenPlay.qml"))); sp.showQQuickView(GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN)); - QObject::connect(&installedListModel, &InstalledListModel::setScreenVisible, - &sp, &ScreenPlay::setVisible); - int status = app.exec(); //Shutdown diff --git a/qml.qrc b/qml.qrc index ccd692d5..07f062b6 100644 --- a/qml.qrc +++ b/qml.qrc @@ -8,6 +8,7 @@ qml/Components/ScreenPlay.qml qml/Components/Settings.qml qml/Components/Page.qml + qml/Components/Settings/SettingBool.qml assets/licenses/Apache2.txt assets/licenses/OFL.txt assets/fonts/LibreBaskerville-Italic.ttf @@ -32,5 +33,8 @@ assets/icons/icon_download.svg qml/Components/ScreenPlayItemImage.qml assets/icons/favicon.ico + qml/Components/Settings/SettingBool.qml + qml/Components/Headline.qml + qtquickcontrols2.conf diff --git a/qml/Components/Headline.qml b/qml/Components/Headline.qml new file mode 100644 index 00000000..52e2deab --- /dev/null +++ b/qml/Components/Headline.qml @@ -0,0 +1,53 @@ +import QtQuick 2.0 +import QtQuick.Controls 1.4 +import QtQuick.Layouts 1.3 +import QtQuick.Controls.Material 2.0 + + +Item { + id: headline + property string name: "" + + width: parent.width + height: 80 + +Item { + height: 70 + anchors { + top: parent.top + right: parent.right + left: parent.left + } + + + Text { + id:txtName + text: headline.name + font.italic: true + renderType: Text.NativeRendering + verticalAlignment: Text.AlignVCenter + horizontalAlignment: Text.AlignLeft + anchors.bottom: line.top + anchors.bottomMargin: 5 + anchors.left: parent.left + anchors.leftMargin: 10 + font.pixelSize: 18 + color: "#818181" + anchors.margins: 10 + font.family: font_LibreBaskerville_Italic.name + + FontLoader { + id: font_LibreBaskerville_Italic + source: "qrc:/assets/fonts/LibreBaskerville-Italic.ttf" + } + } + + Rectangle { + id:line + height: 1 + width: parent.width + color: "#BBBBBB" + anchors.bottom: parent.bottom + } +} +} diff --git a/qml/Components/Settings.qml b/qml/Components/Settings.qml index 6367e862..8e2125d0 100644 --- a/qml/Components/Settings.qml +++ b/qml/Components/Settings.qml @@ -1,5 +1,45 @@ -import QtQuick 2.0 +import QtQuick 2.7 +import QtQuick.Controls 1.4 +import QtQuick.Layouts 1.3 +import QtQuick.Controls.Material 2.1 + +import "Settings/" Page { - pageName: "Settings" + pageName: "" + + + VisualItemModel { + id:settingsModel + Headline { + name: "General" + } + SettingBool { + name: "Autostart" + isChecked: settings.autostart + onCheckboxChanged: settings.setAutostart(checked) + } + Headline { + name: "Misc" + + } + SettingBool { + name: "Autostart" + } + + } + + + + ListView { + anchors.fill: parent + anchors.margins: 20 + model:settingsModel + boundsBehavior: Flickable.DragOverBounds + cacheBuffer: 1000 + maximumFlickVelocity: 10000 + + + + } } diff --git a/qml/Components/Settings/SettingBool.qml b/qml/Components/Settings/SettingBool.qml new file mode 100644 index 00000000..03c216bb --- /dev/null +++ b/qml/Components/Settings/SettingBool.qml @@ -0,0 +1,46 @@ +import QtQuick 2.0 +import QtQuick.Controls 1.4 +import QtQuick.Layouts 1.3 +import QtQuick.Controls.Material 2.1 + + +Item { + id: settingsBool + property string name: "" + property bool isChecked: false + signal checkboxChanged(bool checked) + + + height: 50 + Layout.preferredHeight: 50 + Material.theme: Material.Dark + Material.accent: Material.Purple + + Text { + id:txtName + text: settingsBool.name + renderType: Text.NativeRendering + verticalAlignment: Text.AlignVCenter + horizontalAlignment: Text.AlignLeft + anchors.verticalCenter: parent.verticalCenter + anchors.left: parent.left + anchors.leftMargin: 20 + font.pixelSize: 16 + font.family: font_Roboto_Regular.name + + FontLoader{ + id: font_Roboto_Regular + source: "qrc:/assets/fonts/Roboto-Regular.ttf" + } + } + + CheckBox { + id: radioButton + anchors.verticalCenter: parent.verticalCenter + anchors.left: txtName.right + anchors.leftMargin: 20 + checked: settingsBool.isChecked + onCheckedChanged: checkboxChanged(radioButton.checked) + } + +} diff --git a/qml/Components/SettingsItemBool.qml b/qml/Components/SettingsItemBool.qml new file mode 100644 index 00000000..9c36e13c --- /dev/null +++ b/qml/Components/SettingsItemBool.qml @@ -0,0 +1,5 @@ +import QtQuick 2.0 + +Item { + +} diff --git a/qtquickcontrols2.conf b/qtquickcontrols2.conf new file mode 100644 index 00000000..0c8980f8 --- /dev/null +++ b/qtquickcontrols2.conf @@ -0,0 +1,15 @@ +; This file can be edited to change the style of the application +; See Styling Qt Quick Controls 2 in the documentation for details: +; http://doc.qt.io/qt-5/qtquickcontrols2-styles.html + +[Controls] +Style=Material + +[Universal] +Theme=Light +;Accent=Steel + +[Material] +Theme=Light +;Accent=BlueGrey +;Primary=BlueGray diff --git a/settings.json b/settings.json new file mode 100644 index 00000000..3a25602f --- /dev/null +++ b/settings.json @@ -0,0 +1,10 @@ +{ + "version" : "0.0.1", + "autostart" : true, + "highPriorityStart" : false, + "sendStatistics" : false, + "renderer": { + "renderer-value": 0, + "renderer-enum" : ["OpenGL","Vulkan", "DirectX11", "DirectX12", "Software"] + } +} \ No newline at end of file diff --git a/src/settings.cpp b/src/settings.cpp index d4e703d1..4e723383 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -6,25 +6,38 @@ Settings::Settings(QObject* parent) QFile configTmp; QJsonDocument configJsonDocument; QJsonParseError parseError; + QJsonObject configObj; - if (QDir(QString("config.json")).exists()) { - configTmp.setFileName("config.json"); - configTmp.open(QIODevice::ReadOnly | QIODevice::Text); - QString config = configTmp.readAll(); - configJsonDocument = QJsonDocument::fromJson(config.toUtf8(), &parseError); + configTmp.setFileName(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) + "/settings.json"); - if ((parseError.error == QJsonParseError::NoError)) { - //TODO - } + if (!configTmp.exists()) { + //If we cannot find the settings json file we will create one + //createDefaultConfig(); } + + + + configTmp.open(QIODevice::ReadOnly | QIODevice::Text); + QString config = configTmp.readAll(); + configJsonDocument = QJsonDocument::fromJson(config.toUtf8(), &parseError); + + if (!(parseError.error == QJsonParseError::NoError)) { + return; + } + + configObj = configJsonDocument.object(); + m_version = configObj.value("version").toVariant(); + m_autostart = configObj.value("autostart").toBool(); + m_highPriorityStart = configObj.value("highPriorityStart").toBool(); + m_sendStatistics = configObj.value("sendStatistics").toBool(); + m_renderer = static_cast(configObj.value("renderer-value").toInt()); } -void Settings::setValue(const QString& key, const QVariant& value) +void Settings::createDefaultConfig() { -} + QFile file(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) + "/settings.json"); + file.open(QIODevice::WriteOnly | QIODevice::Text); + QJsonObject tmpObj; + -QVariant Settings::value(const QString& key, const QVariant& defaultValue) const -{ - QVariant a; - return a; } diff --git a/src/settings.h b/src/settings.h index 156f2d85..b4a9810d 100644 --- a/src/settings.h +++ b/src/settings.h @@ -1,47 +1,126 @@ #ifndef SCREENPLAYSETTINGS_H #define SCREENPLAYSETTINGS_H -#include -#include +#include +#include #include #include #include +#include +#include +#include #include #include -#include -#include +#include class Settings : public QObject { Q_OBJECT public: explicit Settings(QObject* parent = nullptr); - Q_INVOKABLE void setValue(const QString& key, const QVariant& value); - Q_INVOKABLE QVariant value(const QString& key, const QVariant& defaultValue = QVariant()) const; - Q_PROPERTY(QQmlPropertyMap* globalSetting READ globalSetting WRITE setglobalSetting NOTIFY globalSettingChanged) + Q_PROPERTY(QVariant version READ version) + Q_PROPERTY(bool autostart READ autostart WRITE setAutostart NOTIFY autostartChanged) + Q_PROPERTY(bool highPriorityStart READ highPriorityStart WRITE setHighPriorityStart NOTIFY highPriorityStartChanged) + Q_PROPERTY(Renderer renderer READ renderer WRITE setRenderer NOTIFY rendererChanged) + Q_PROPERTY(bool sendStatistics READ sendStatistics WRITE setSendStatistics NOTIFY sendStatisticsChanged) - QQmlPropertyMap* globalSetting() const + enum Renderer { + OpenGL, + Softare, + }; + Q_ENUM(Renderer) + + QVariant version() const { - return m_globalSetting; + return m_version; + } + + bool autostart() const + { + return m_autostart; + } + + bool highPriorityStart() const + { + return m_highPriorityStart; + } + + Renderer renderer() const + { + return m_renderer; + } + + bool sendStatistics() const + { + return m_sendStatistics; } signals: - void globalSettingChanged(QQmlPropertyMap* globalSetting); + void autostartChanged(bool autostart); + + void highPriorityStartChanged(bool highPriorityStart); + + void rendererChanged(Renderer renderer); + + void sendStatisticsChanged(bool sendStatistics); public slots: - void setglobalSetting(QQmlPropertyMap* globalSetting) + void setAutostart(bool autostart) { - if (m_globalSetting == globalSetting) + qDebug() << autostart; + if (m_autostart == autostart) return; - m_globalSetting = globalSetting; - emit globalSettingChanged(m_globalSetting); + m_autostart = autostart; + emit autostartChanged(m_autostart); + } + + void setHighPriorityStart(bool highPriorityStart) + { + if (m_highPriorityStart == highPriorityStart) + return; + + m_highPriorityStart = highPriorityStart; + emit highPriorityStartChanged(m_highPriorityStart); + } + + void setRenderer(Renderer renderer) + { + if (m_renderer == renderer) + return; + + m_renderer = renderer; + emit rendererChanged(m_renderer); + } + + void setsendStatistics(bool sendStatistics) + { + if (m_sendStatistics == sendStatistics) + return; + + m_sendStatistics = sendStatistics; + emit sendStatisticsChanged(m_sendStatistics); + } + + void setSendStatistics(bool sendStatistics) + { + if (m_sendStatistics == sendStatistics) + return; + + m_sendStatistics = sendStatistics; + emit sendStatisticsChanged(m_sendStatistics); } private: - QQmlPropertyMap* m_globalSetting; + void createDefaultConfig(); + + QVariant m_version = ""; + bool m_autostart = true; + bool m_highPriorityStart = true; + Renderer m_renderer = Renderer::OpenGL; + bool m_sendStatistics; }; #endif // SCREENPLAYSETTINGS_H