kcms/mobileshell: Use js list model instead of ListModel

Use a proper JS list model instead of creating a ListModel and then appending items to it.
This commit is contained in:
Devin Lin 2025-04-06 20:54:53 -04:00
parent 8b4abd134a
commit ebdb8bd848
2 changed files with 47 additions and 79 deletions

View file

@ -39,27 +39,19 @@ FormCard.FormCardPage {
text: i18n("Vibration Duration") text: i18n("Vibration Duration")
description: i18n("How long shell vibrations should be.") description: i18n("How long shell vibrations should be.")
property string longString: i18nc("Long duration", "Long") model: [
property string mediumString: i18nc("Medium duration", "Medium") {"name": i18nc("Long duration", "Long"), "value": 100},
property string shortString: i18nc("Short duration", "Short") {"name": i18nc("Medium duration", "Medium"), "value": 50},
{"name": i18nc("Short duration", "Short"), "value": 10}
currentIndex: indexOfValue(ShellSettings.Settings.vibrationDuration) ]
model: ListModel {
// we can't use i18n with ListElement
Component.onCompleted: {
append({"name": vibrationDurationDelegate.longString, "value": 100});
append({"name": vibrationDurationDelegate.mediumString, "value": 50});
append({"name": vibrationDurationDelegate.shortString, "value": 10});
// indexOfValue doesn't bind to model changes unfortunately, set currentIndex manually here
vibrationDurationDelegate.currentIndex = vibrationDurationDelegate.indexOfValue(ShellSettings.Settings.vibrationDuration)
}
}
textRole: "name" textRole: "name"
valueRole: "value" valueRole: "value"
Component.onCompleted: dialog.parent = root Component.onCompleted: {
currentIndex = indexOfValue(ShellSettings.Settings.vibrationDuration);
dialog.parent = root;
}
onCurrentValueChanged: ShellSettings.Settings.vibrationDuration = currentValue; onCurrentValueChanged: ShellSettings.Settings.vibrationDuration = currentValue;
} }
} }

View file

@ -85,35 +85,24 @@ KCM.SimpleKCM {
FormCard.FormComboBoxDelegate { FormCard.FormComboBoxDelegate {
id: statusBarScaleFactorDelegate id: statusBarScaleFactorDelegate
property string tinyString: i18nc("Status bar height", "Tiny")
property string smallString: i18nc("Status bar height", "Small")
property string normalString: i18nc("Status bar height", "Normal")
property string largeString: i18nc("Status bar height","Large")
property string xlargeString: i18nc("Status bar height", "Very Large")
text: i18n("Status Bar Size") text: i18n("Status Bar Size")
description: i18n("Size of the top panel (needs restart).") description: i18n("Size of the top panel (needs restart).")
currentIndex: indexOfValue(ShellSettings.Settings.statusBarScaleFactor) model: [
model: ListModel { {"name": i18nc("Status bar height", "Tiny"), "value": 1.0},
// We can't use i18n with ListElement, so use a property instead {"name": i18nc("Status bar height", "Small"), "value": 1.15},
Component.onCompleted: { {"name": i18nc("Status bar height", "Normal"), "value": 1.25},
append({"name": statusBarScaleFactorDelegate.tinyString, "value": 1.0}); {"name": i18nc("Status bar height", "Large"), "value": 1.5},
append({"name": statusBarScaleFactorDelegate.smallString, "value": 1.15}); {"name": i18nc("Status bar height", "Very Large"), "value": 2.0}
append({"name": statusBarScaleFactorDelegate.normalString, "value": 1.25}); ]
append({"name": statusBarScaleFactorDelegate.largeString, "value": 1.5});
append({"name": statusBarScaleFactorDelegate.xlargeString, "value": 2.0});
// indexOfValue doesn't bind to model changes unfortunately, set currentIndex manually here
statusBarScaleFactorDelegate.currentIndex = statusBarScaleFactorDelegate.indexOfValue(ShellSettings.Settings.statusBarScaleFactor)
}
}
textRole: "name" textRole: "name"
valueRole: "value" valueRole: "value"
Component.onCompleted: dialog.parent = root Component.onCompleted: {
currentIndex = indexOfValue(ShellSettings.Settings.statusBarScaleFactor);
dialog.parent = root;
}
onCurrentValueChanged: ShellSettings.Settings.statusBarScaleFactor = currentValue onCurrentValueChanged: ShellSettings.Settings.statusBarScaleFactor = currentValue
} }
@ -175,22 +164,18 @@ KCM.SimpleKCM {
text: i18n("Top Left Drawer Mode") text: i18n("Top Left Drawer Mode")
description: i18n("Mode when opening from the top left.") description: i18n("Mode when opening from the top left.")
currentIndex: indexOfValue(ShellSettings.Settings.actionDrawerTopLeftMode) model: [
model: ListModel { {"name": quickSettings.pinnedString, "value": ShellSettings.Settings.Pinned},
// we can't use i18n with ListElement {"name": quickSettings.expandedString, "value": ShellSettings.Settings.Expanded}
Component.onCompleted: { ]
append({"name": quickSettings.pinnedString, "value": ShellSettings.Settings.Pinned});
append({"name": quickSettings.expandedString, "value": ShellSettings.Settings.Expanded});
// indexOfValue doesn't bind to model changes unfortunately, set currentIndex manually here
topLeftActionDrawerModeDelegate.currentIndex = topLeftActionDrawerModeDelegate.indexOfValue(ShellSettings.Settings.actionDrawerTopLeftMode)
}
}
textRole: "name" textRole: "name"
valueRole: "value" valueRole: "value"
Component.onCompleted: dialog.parent = root Component.onCompleted: {
currentIndex = indexOfValue(ShellSettings.Settings.actionDrawerTopLeftMode);
dialog.parent = root;
}
onCurrentValueChanged: ShellSettings.Settings.actionDrawerTopLeftMode = currentValue onCurrentValueChanged: ShellSettings.Settings.actionDrawerTopLeftMode = currentValue
} }
@ -201,21 +186,16 @@ KCM.SimpleKCM {
text: i18n("Top Right Drawer Mode") text: i18n("Top Right Drawer Mode")
description: i18n("Mode when opening from the top right.") description: i18n("Mode when opening from the top right.")
model: ListModel { model: [
// we can't use i18n with ListElement {"name": quickSettings.pinnedString, "value": ShellSettings.Settings.Pinned},
Component.onCompleted: { {"name": quickSettings.expandedString, "value": ShellSettings.Settings.Expanded}
append({"name": quickSettings.pinnedString, "value": ShellSettings.Settings.Pinned}); ]
append({"name": quickSettings.expandedString, "value": ShellSettings.Settings.Expanded});
// indexOfValue doesn't bind to model changes unfortunately, set currentIndex manually here
topRightActionDrawerModeDelegate.currentIndex = topRightActionDrawerModeDelegate.indexOfValue(ShellSettings.Settings.actionDrawerTopRightMode)
}
}
textRole: "name" textRole: "name"
valueRole: "value" valueRole: "value"
Component.onCompleted: { Component.onCompleted: {
currentIndex = indexOfValue(ShellSettings.Settings.actionDrawerTopRightMode);
dialog.parent = root dialog.parent = root
} }
onCurrentValueChanged: ShellSettings.Settings.actionDrawerTopRightMode = currentValue onCurrentValueChanged: ShellSettings.Settings.actionDrawerTopRightMode = currentValue
@ -236,20 +216,18 @@ KCM.SimpleKCM {
id: lockscreenLeftButtonDelegate id: lockscreenLeftButtonDelegate
text: i18nc("@label:listbox", "Left button") text: i18nc("@label:listbox", "Left button")
model: ListModel { model: [
Component.onCompleted: { {"name": quickActionButtons.noneString, "value": ShellSettings.Settings.None},
append({"name": quickActionButtons.noneString, "value": ShellSettings.Settings.None}); {"name": quickActionButtons.flashlightString, "value": ShellSettings.Settings.Flashlight}
append({"name": quickActionButtons.flashlightString, "value": ShellSettings.Settings.Flashlight}); // {"name": quickActionButtons.cameraString, "value": ShellSettings.Settings.Camera}
// append({"name": quickActionButtons.cameraString, "value": ShellSettings.Settings.Camera}); ]
lockscreenLeftButtonDelegate.currentIndex = lockscreenLeftButtonDelegate.indexOfValue(ShellSettings.Settings.lockscreenLeftButtonAction)
}
}
textRole: "name" textRole: "name"
valueRole: "value" valueRole: "value"
Component.onCompleted: { Component.onCompleted: {
dialog.parent = root currentIndex = indexOfValue(ShellSettings.Settings.lockscreenLeftButtonAction);
dialog.parent = root;
} }
onCurrentValueChanged: ShellSettings.Settings.lockscreenLeftButtonAction = currentValue onCurrentValueChanged: ShellSettings.Settings.lockscreenLeftButtonAction = currentValue
} }
@ -260,20 +238,18 @@ KCM.SimpleKCM {
id: lockscreenRightButtonDelegate id: lockscreenRightButtonDelegate
text: i18nc("@label:listbox", "Right button") text: i18nc("@label:listbox", "Right button")
model: ListModel { model: [
Component.onCompleted: { {"name": quickActionButtons.noneString, "value": ShellSettings.Settings.None},
append({"name": quickActionButtons.noneString, "value": ShellSettings.Settings.None}); {"name": quickActionButtons.flashlightString, "value": ShellSettings.Settings.Flashlight}
append({"name": quickActionButtons.flashlightString, "value": ShellSettings.Settings.Flashlight}); // {"name": quickActionButtons.cameraString, "value": ShellSettings.Settings.Camera}
// append({"name": quickActionButtons.cameraString, "value": ShellSettings.Settings.Camera}); ]
lockscreenRightButtonDelegate.currentIndex = lockscreenRightButtonDelegate.indexOfValue(ShellSettings.Settings.lockscreenRightButtonAction)
}
}
textRole: "name" textRole: "name"
valueRole: "value" valueRole: "value"
Component.onCompleted: { Component.onCompleted: {
dialog.parent = root currentIndex = indexOfValue(ShellSettings.Settings.lockscreenRightButtonAction);
dialog.parent = root;
} }
onCurrentValueChanged: ShellSettings.Settings.lockscreenRightButtonAction = currentValue onCurrentValueChanged: ShellSettings.Settings.lockscreenRightButtonAction = currentValue
} }