From 276a917ebdfebc22abdd4d4b489a64dfc6fda709 Mon Sep 17 00:00:00 2001 From: Elias Steurer Date: Fri, 1 Dec 2023 17:51:00 +0100 Subject: [PATCH] Fix enums in qml --- ScreenPlay/inc/public/ScreenPlay/settings.h | 2 +- ScreenPlay/qml/Settings/SettingsComboBox.qml | 8 +++-- ScreenPlay/qml/Settings/SettingsView.qml | 37 ++++---------------- ScreenPlay/src/settings.cpp | 6 ++-- 4 files changed, 15 insertions(+), 38 deletions(-) diff --git a/ScreenPlay/inc/public/ScreenPlay/settings.h b/ScreenPlay/inc/public/ScreenPlay/settings.h index b930a2cd..6330630e 100644 --- a/ScreenPlay/inc/public/ScreenPlay/settings.h +++ b/ScreenPlay/inc/public/ScreenPlay/settings.h @@ -170,7 +170,7 @@ public slots: void setFont(QString font); void setTheme(ScreenPlay::Settings::Theme theme); void setSteamVersion(bool steamVersion); - void setDesktopEnvironment(DesktopEnvironment desktopEnvironment); + void setDesktopEnvironment(ScreenPlay::Settings::DesktopEnvironment desktopEnvironment); void setBuildInfos(const QString& buildInfos); private: diff --git a/ScreenPlay/qml/Settings/SettingsComboBox.qml b/ScreenPlay/qml/Settings/SettingsComboBox.qml index a6d15dba..04147078 100644 --- a/ScreenPlay/qml/Settings/SettingsComboBox.qml +++ b/ScreenPlay/qml/Settings/SettingsComboBox.qml @@ -1,6 +1,8 @@ import QtQuick import QtQuick.Controls import QtQuick.Layouts +import ScreenPlay +import ScreenPlayApp Control { id: settingsComboBox @@ -21,7 +23,7 @@ Control { verticalAlignment: Text.AlignVCenter horizontalAlignment: Text.AlignLeft font.pointSize: 12 - //font.family: App.settings.font + font.family: App.settings.font anchors { top: parent.top @@ -40,7 +42,7 @@ Control { horizontalAlignment: Text.AlignLeft wrapMode: Text.WordWrap font.pointSize: 10 - //font.family: App.settings.font + font.family: App.settings.font anchors { top: txtHeadline.bottom @@ -58,7 +60,7 @@ Control { implicitWidth: 200 textRole: "text" valueRole: "value" - //font.family: App.settings.font + font.family: App.settings.font anchors { right: parent.right diff --git a/ScreenPlay/qml/Settings/SettingsView.qml b/ScreenPlay/qml/Settings/SettingsView.qml index e8f722b4..12f0caf4 100644 --- a/ScreenPlay/qml/Settings/SettingsView.qml +++ b/ScreenPlay/qml/Settings/SettingsView.qml @@ -14,14 +14,6 @@ Item { property Item modalSource - function indexOfValue(model, value) { - for (var i = 0; i < model.length; i++) { - let ourValue = model[i].value; - if (value === ourValue) - return i; - } - return -1; - } Flickable { id: flickableWrapper @@ -151,14 +143,8 @@ Item { headline: qsTr("Language") description: qsTr("Set the ScreenPlay UI Language") - Component.onCompleted: { - print("as",settingsLanguage.comboBox.currentIndex,settingsLanguage.comboBox.model,App.settings.language ) - //settingsLanguage.comboBox.currentIndex = root.indexOfValue(settingsLanguage.comboBox.model, App.settings.language); - //print(settingsLanguage.comboBox.currentIndex ) - - } - comboBox { + Component.onCompleted: comboBox.currentIndex = comboBox.indexOfValue(App.settings.language) model: ListModel { id: lmLangauge ListElement { value: Settings.Language.En_US; text: "English" } @@ -175,13 +161,9 @@ Item { ListElement { value: Settings.Language.Tr_TR; text: "Turkish" } ListElement { value: Settings.Language.Nl_NL; text: "Dutch" } } - onActivated: (index) => { - print(index,lmLangauge.get(index),lmLangauge.get(index).value,lmLangauge.get(index).text) - print(Settings.Language.Pl_PL) - print("onActivated",settingsLanguage.comboBox.currentValue,index) - // App.settings.setLanguage(settingsLanguage.comboBox.currentValue); - - //App.settings.retranslateUI(); + onActivated: { + App.settings.setLanguage(settingsLanguage.comboBox.currentValue); + App.settings.retranslateUI(); } } } @@ -194,18 +176,14 @@ Item { headline: qsTr("Theme") description: qsTr("Switch dark/light theme") - Component.onCompleted: { - //settingsTheme.comboBox.currentIndex = root.indexOfValue(settingsTheme.comboBox.model, App.settings.theme); - } - comboBox { + Component.onCompleted: comboBox.currentIndex = comboBox.indexOfValue(App.settings.theme) model: ListModel { ListElement { value: Settings.Theme.System; text: qsTr("System Default") } ListElement { value: Settings.Theme.Dark; text: qsTr("Dark") } ListElement { value: Settings.Theme.Light; text: qsTr("Light") } } onActivated: { - print("onActivated", settingsTheme.comboBox.currentValue,Settings.Theme.Light) App.settings.setTheme(settingsTheme.comboBox.currentValue); } } @@ -244,11 +222,8 @@ Item { headline: qsTr("Default Wallpaper Fill Mode") description: qsTr("Set this property to define how the video is scaled to fit the target area.") - Component.onCompleted: { - cbVideoFillMode.comboBox.currentIndex = root.indexOfValue(cbVideoFillMode.comboBox.model, App.settings.videoFillMode); - } - comboBox { + Component.onCompleted: comboBox.currentIndex = comboBox.indexOfValue(App.settings.videoFillMode) model: ListModel { ListElement { value: Video.FillMode.Stretch; text: qsTr("Stretch") } ListElement { value: Video.FillMode.Fill; text: qsTr("Fill") } diff --git a/ScreenPlay/src/settings.cpp b/ScreenPlay/src/settings.cpp index 7a1a3b14..c45d4b93 100644 --- a/ScreenPlay/src/settings.cpp +++ b/ScreenPlay/src/settings.cpp @@ -556,7 +556,7 @@ void Settings::setCheckWallpaperVisible(bool checkWallpaperVisible) emit checkWallpaperVisibleChanged(m_checkWallpaperVisible); } -void Settings::setVideoFillMode(Video::FillMode videoFillMode) +void Settings::setVideoFillMode(ScreenPlay::Video::FillMode videoFillMode) { if (m_videoFillMode == videoFillMode) return; @@ -567,7 +567,7 @@ void Settings::setVideoFillMode(Video::FillMode videoFillMode) emit videoFillModeChanged(m_videoFillMode); } -void Settings::setLanguage(Language language) +void Settings::setLanguage(ScreenPlay::Settings::Language language) { if (m_language == language) return; @@ -587,7 +587,7 @@ void Settings::setFont(QString font) emit fontChanged(m_font); } -void Settings::setTheme(Theme theme) +void Settings::setTheme(ScreenPlay::Settings::Theme theme) { if (m_theme == theme) return;