NSettingsIndicator: add default setting indicator (#1080)

N*Widgets: show NSettingsIndicator if settings are not default
This commit is contained in:
Ly-sec
2025-12-20 14:55:09 +01:00
parent c8b76c7b90
commit 9cb6613308
20 changed files with 793 additions and 411 deletions
+49
View File
@@ -18,6 +18,9 @@ RowLayout {
property string placeholder: ""
property string searchPlaceholder: I18n.tr("placeholders.search")
property Component delegate: null
property bool isSettings: false
property var defaultValue: ""
property string settingsPath: ""
readonly property real preferredHeight: Style.baseWidgetSize * 1.1
@@ -26,6 +29,49 @@ RowLayout {
spacing: Style.marginL
Layout.fillWidth: true
readonly property bool isValueChanged: isSettings && (currentKey !== defaultValue)
readonly property string indicatorTooltip: {
if (!isSettings) return "";
var displayValue = "";
if (defaultValue === "") {
// Try to find the display name for empty key in the model
if (model && model.count > 0) {
for (var i = 0; i < model.count; i++) {
var item = model.get(i);
if (item && item.key === "") {
displayValue = item.name || I18n.tr("settings.indicator.system-default");
break;
}
}
// If not found in model, show "System Default" instead of "(empty)"
if (displayValue === "") {
displayValue = I18n.tr("settings.indicator.system-default");
}
} else {
displayValue = I18n.tr("settings.indicator.system-default");
}
} else {
// Try to find the display name for the default key in the model
if (model && model.count > 0) {
for (var i = 0; i < model.count; i++) {
var item = model.get(i);
if (item && item.key === defaultValue) {
displayValue = item.name || String(defaultValue);
break;
}
}
if (displayValue === "") {
displayValue = String(defaultValue);
}
} else {
displayValue = String(defaultValue);
}
}
return I18n.tr("settings.indicator.default-value", {
"value": displayValue
});
}
// Filtered model for search results
property ListModel filteredModel: ListModel {}
property string searchText: ""
@@ -113,6 +159,8 @@ RowLayout {
NLabel {
label: root.label
description: root.description
showIndicator: root.isSettings && root.isValueChanged
indicatorTooltip: root.indicatorTooltip
}
Item {
@@ -339,4 +387,5 @@ RowLayout {
}
}
}
}