1
0
mirror of https://gitlab.com/kelteseth/ScreenPlay.git synced 2024-11-25 04:02:50 +01:00

Add basic settings

This commit is contained in:
kelteseth 2017-05-13 10:50:15 +02:00
parent d96b1e270f
commit f482a6a43a
13 changed files with 311 additions and 44 deletions

3
.gitmodules vendored
View File

@ -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

View File

@ -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

1
ThirdParty/QJsonModel vendored Submodule

@ -0,0 +1 @@
Subproject commit 5ccca6e2e28fe93edfb9df319079d8a55c365ca5

View File

@ -1,19 +1,20 @@
#include <QDebug>
#include <QDir>
#include <QGuiApplication>
#include <QIcon>
#include <QLibrary>
#include <QModelIndex>
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include <QQmlEngine>
#include <QQuickStyle>
#include <QQuickView>
#include <QQmlContext>
#include <QScreen>
#include <QUrl>
#include <QVariant>
#include <QWindow>
#include <QtQuick/QQuickItem>
#include <qt_windows.h>
#include <QIcon>
#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

View File

@ -8,6 +8,7 @@
<file>qml/Components/ScreenPlay.qml</file>
<file>qml/Components/Settings.qml</file>
<file>qml/Components/Page.qml</file>
<file>qml/Components/Settings/SettingBool.qml</file>
<file>assets/licenses/Apache2.txt</file>
<file>assets/licenses/OFL.txt</file>
<file>assets/fonts/LibreBaskerville-Italic.ttf</file>
@ -32,5 +33,8 @@
<file>assets/icons/icon_download.svg</file>
<file>qml/Components/ScreenPlayItemImage.qml</file>
<file>assets/icons/favicon.ico</file>
<file>qml/Components/Settings/SettingBool.qml</file>
<file>qml/Components/Headline.qml</file>
<file>qtquickcontrols2.conf</file>
</qresource>
</RCC>

View File

@ -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
}
}
}

View File

@ -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
}
}

View File

@ -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)
}
}

View File

@ -0,0 +1,5 @@
import QtQuick 2.0
Item {
}

15
qtquickcontrols2.conf Normal file
View File

@ -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

10
settings.json Normal file
View File

@ -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"]
}
}

View File

@ -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<Renderer>(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;
}

View File

@ -1,47 +1,126 @@
#ifndef SCREENPLAYSETTINGS_H
#define SCREENPLAYSETTINGS_H
#include <QObject >
#include <QQmlPropertyMap>
#include <QDir>
#include <QFile>
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
#include <QObject >
#include <QQmlPropertyMap>
#include <QStandardPaths>
#include <QString>
#include <QVariant>
#include <QDir>
#include <QFile>
#include <QDebug>
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