mirror of
https://gitlab.com/kelteseth/ScreenPlay.git
synced 2024-11-23 19:22:35 +01:00
Fix #44
Remove hardcoded langauge keys Remove currentIndex and ListModel comboBoxListModel
This commit is contained in:
parent
311cf42f42
commit
5507f0a175
@ -1,5 +1,5 @@
|
||||
import QtQuick 2.12
|
||||
import QtQuick.Controls 2.3
|
||||
import QtQuick 2.14
|
||||
import QtQuick.Controls 2.14
|
||||
import QtQuick.Dialogs 1.2
|
||||
import QtQuick.Layouts 1.3
|
||||
import QtGraphicalEffects 1.0
|
||||
@ -162,58 +162,52 @@ Item {
|
||||
}
|
||||
|
||||
SettingsHorizontalSeperator {}
|
||||
|
||||
SettingsComboBox {
|
||||
id: settingsLanguage
|
||||
headline: qsTr("Language")
|
||||
description: qsTr("Set the ScreenPlay UI Language")
|
||||
onCurrentIndexChanged: {
|
||||
var key = settingsLanguage.comboBoxListModel.get(
|
||||
settingsLanguage.currentIndex).text.toString()
|
||||
comboBox.currentIndex: indexOfValue(ScreenPlay.settings.language)
|
||||
|
||||
var languageKey
|
||||
|
||||
switch (key) {
|
||||
case "German":
|
||||
languageKey = "de"
|
||||
break
|
||||
case "English":
|
||||
languageKey = "en"
|
||||
break
|
||||
case "Russian":
|
||||
languageKey = "ru"
|
||||
break
|
||||
case "French":
|
||||
languageKey = "fr"
|
||||
break
|
||||
case "Spanish":
|
||||
languageKey = "es"
|
||||
break
|
||||
default:
|
||||
languageKey = "en"
|
||||
break
|
||||
function indexOfValue(value) {
|
||||
for (var i = 0; i < liLanguage.count; i++) {
|
||||
let ourValue = liLanguage.get(i).value
|
||||
if (value === ourValue)
|
||||
return i
|
||||
}
|
||||
|
||||
ScreenPlay.settings.setqSetting("language",
|
||||
languageKey)
|
||||
|
||||
return -1
|
||||
}
|
||||
comboBox.onActivated: {
|
||||
ScreenPlay.settings.setqSetting(
|
||||
"language",
|
||||
liLanguage.get(comboBox.currentIndex).value)
|
||||
ScreenPlay.settings.setupLanguage()
|
||||
ScreenPlay.mainWindowEngine.retranslate()
|
||||
}
|
||||
comboBoxListModel: ListModel {
|
||||
comboBox.textRole: "text"
|
||||
comboBox.valueRole: "value"
|
||||
comboBox.model: ListModel {
|
||||
id: liLanguage
|
||||
ListElement {
|
||||
text: "English"
|
||||
value: "en"
|
||||
}
|
||||
ListElement {
|
||||
text: "German"
|
||||
value: "de"
|
||||
}
|
||||
ListElement {
|
||||
text: "Russian"
|
||||
value: "ru"
|
||||
}
|
||||
ListElement {
|
||||
text: "French"
|
||||
value: "fr"
|
||||
}
|
||||
ListElement {
|
||||
text: "Spanish"
|
||||
value: "es"
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -286,10 +280,7 @@ Item {
|
||||
id: settingsFillModeComboBox
|
||||
headline: qsTr("Default Fill Mode")
|
||||
description: qsTr("Set this property to define how the video is scaled to fit the target area.")
|
||||
onCurrentIndexChanged: {
|
||||
|
||||
}
|
||||
comboBoxListModel: ListModel {
|
||||
comboBox.model: ListModel {
|
||||
ListElement {
|
||||
text: "Stretch"
|
||||
}
|
||||
|
@ -6,10 +6,9 @@ Item {
|
||||
id: settingsComboBox
|
||||
property string headline: "Headline"
|
||||
property string description: "Lorem ipsum dolor sit amet, consectetuer adipiscing elit."
|
||||
property int currentIndex:0
|
||||
property bool isChecked: false
|
||||
property bool enabled: true
|
||||
property ListModel comboBoxListModel
|
||||
property alias comboBox: comboBox
|
||||
|
||||
onEnabledChanged: {
|
||||
|
||||
@ -69,8 +68,5 @@ Item {
|
||||
rightMargin: 20
|
||||
verticalCenter: parent.verticalCenter
|
||||
}
|
||||
|
||||
model: comboBoxListModel
|
||||
onActivated:settingsComboBox.currentIndex = currentIndex
|
||||
}
|
||||
}
|
||||
|
@ -302,6 +302,7 @@ void Settings::setupLanguage()
|
||||
if (tsFile.exists(":/translations/ScreenPlay_" + localeSplits.at(0) + ".qm")) {
|
||||
m_translator.load(":/translations/ScreenPlay_" + localeSplits.at(0) + ".qm");
|
||||
m_qSettings.setValue("language", QVariant(localeSplits.at(0)));
|
||||
setLanguage(QVariant(localeSplits.at(0)).toString());
|
||||
m_qSettings.sync();
|
||||
app->installTranslator(&m_translator);
|
||||
}
|
||||
@ -309,6 +310,7 @@ void Settings::setupLanguage()
|
||||
QFile tsFile;
|
||||
if (tsFile.exists(":/translations/ScreenPlay_" + m_qSettings.value("language").toString() + ".qm")) {
|
||||
m_translator.load(":/translations/ScreenPlay_" + m_qSettings.value("language").toString() + ".qm");
|
||||
setLanguage(m_qSettings.value("language").toString());
|
||||
app->installTranslator(&m_translator);
|
||||
}
|
||||
}
|
||||
|
@ -54,6 +54,7 @@ class Settings : public QObject {
|
||||
Q_PROPERTY(bool offlineMode READ offlineMode WRITE setOfflineMode NOTIFY offlineModeChanged)
|
||||
Q_PROPERTY(QString decoder READ decoder WRITE setDecoder NOTIFY decoderChanged)
|
||||
Q_PROPERTY(QString gitBuildHash READ gitBuildHash WRITE setGitBuildHash NOTIFY gitBuildHashChanged)
|
||||
Q_PROPERTY(QString language READ language WRITE setLanguage NOTIFY languageChanged)
|
||||
|
||||
public:
|
||||
explicit Settings(
|
||||
@ -110,6 +111,11 @@ public:
|
||||
return m_anonymousTelemetry;
|
||||
}
|
||||
|
||||
QString language() const
|
||||
{
|
||||
return m_language;
|
||||
}
|
||||
|
||||
signals:
|
||||
void autostartChanged(bool autostart);
|
||||
void highPriorityStartChanged(bool highPriorityStart);
|
||||
@ -124,6 +130,8 @@ signals:
|
||||
|
||||
void anonymousTelemetryChanged(bool anonymousTelemetry);
|
||||
|
||||
void languageChanged(QString language);
|
||||
|
||||
public slots:
|
||||
bool writeSingleSettingConfig(QString name, QVariant value);
|
||||
void writeJsonFileFromResource(const QString& filename);
|
||||
@ -171,7 +179,6 @@ public slots:
|
||||
|
||||
void setLocalStoragePath(QUrl localStoragePath)
|
||||
{
|
||||
|
||||
//Remove: "file:///"
|
||||
QJsonValue cleanedPath = QJsonValue(localStoragePath.toString());
|
||||
|
||||
@ -236,6 +243,15 @@ public slots:
|
||||
emit anonymousTelemetryChanged(m_anonymousTelemetry);
|
||||
}
|
||||
|
||||
void setLanguage(QString language)
|
||||
{
|
||||
if (m_language == language)
|
||||
return;
|
||||
|
||||
m_language = language;
|
||||
emit languageChanged(m_language);
|
||||
}
|
||||
|
||||
private:
|
||||
void restoreDefault(const QString& appConfigLocation, const QString& settingsFileType);
|
||||
|
||||
@ -255,5 +271,6 @@ private:
|
||||
QString m_gitBuildHash;
|
||||
bool m_silentStart { false };
|
||||
bool m_anonymousTelemetry { true };
|
||||
QString m_language;
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user