Warning, /plasma/libksysguard/faces/ConfigAppearance.qml is written in an unsupported language. File is not indexed.
0001 /* 0002 SPDX-FileCopyrightText: 2019 Marco Martin <mart@kde.org> 0003 SPDX-FileCopyrightText: 2019 David Edmundson <davidedmundson@kde.org> 0004 SPDX-FileCopyrightText: 2019 Arjen Hiemstra <ahiemstra@heimr.nl> 0005 0006 SPDX-License-Identifier: LGPL-2.0-or-later 0007 */ 0008 0009 import QtQuick 0010 import QtQuick.Layouts 0011 import QtQuick.Controls as QQC2 0012 0013 import org.kde.kirigami as Kirigami 0014 import org.kde.kquickcontrols 0015 import org.kde.config 0016 import org.kde.newstuff as NewStuff 0017 0018 import org.kde.quickcharts as Charts 0019 import org.kde.ksysguard.sensors as Sensors 0020 import org.kde.ksysguard.faces as Faces 0021 0022 Kirigami.FormLayout { 0023 id: root 0024 0025 signal configurationChanged 0026 0027 function saveConfig() { 0028 controller.title = cfg_title; 0029 controller.faceId = cfg_chartFace; 0030 controller.showTitle = cfg_showTitle 0031 controller.updateRateLimit = cfg_updateRateLimit 0032 0033 var preset = pendingPreset; 0034 pendingPreset = ""; 0035 if (preset != "") { 0036 controller.loadPreset(preset); 0037 root.controller.highPrioritySensorColors = automaticColorSource.colors 0038 } 0039 } 0040 0041 property Faces.SensorFaceController controller 0042 property alias cfg_title: titleField.text 0043 property alias cfg_showTitle: showTitleCheckbox.checked 0044 property string cfg_chartFace 0045 property alias cfg_updateRateLimit: updateRateLimitSpinBox.value 0046 0047 onCfg_titleChanged: configurationChanged(); 0048 onCfg_showTitleChanged: configurationChanged() 0049 onCfg_chartFaceChanged: configurationChanged(); 0050 onCfg_updateRateLimitChanged: configurationChanged(); 0051 0052 // config keys of the selected preset to be applied on save 0053 property string pendingPreset 0054 0055 Component.onCompleted: { 0056 cfg_title = controller.title; 0057 cfg_chartFace = controller.faceId; 0058 cfg_showTitle = controller.showTitle 0059 cfg_updateRateLimit = controller.updateRateLimit 0060 } 0061 0062 Charts.ColorGradientSource { 0063 id: automaticColorSource 0064 baseColor: Kirigami.Theme.highlightColor 0065 itemCount: root.controller.highPrioritySensorIds.length 0066 } 0067 0068 Kirigami.OverlaySheet { 0069 id: presetSheet 0070 parent: root 0071 ListView { 0072 implicitWidth: Kirigami.Units.gridUnit * 15 0073 focus: true 0074 model: controller.availablePresetsModel 0075 delegate: Kirigami.SwipeListItem { 0076 contentItem: QQC2.Label { 0077 elide: Text.ElideRight 0078 text: model.display 0079 } 0080 actions: Kirigami.Action { 0081 icon.name: "delete" 0082 visible: model.writable 0083 onTriggered: controller.uninstallPreset(model.pluginId); 0084 } 0085 onClicked: { 0086 cfg_title = model.display; 0087 pendingPreset = model.pluginId; 0088 if (model.config.chartFace) { 0089 cfg_chartFace = model.config.chartFace; 0090 } 0091 0092 root.configurationChanged(); 0093 presetSheet.close(); 0094 } 0095 0096 // shortcut overrides can only be on the item with focus 0097 Keys.onShortcutOverride: { 0098 if (event.key === Qt.Key_Escape) { 0099 event.accepted = true; 0100 root.close(); 0101 } 0102 } 0103 } 0104 } 0105 } 0106 RowLayout { 0107 Kirigami.FormData.label: i18nd("KSysGuardSensorFaces", "Presets:") 0108 0109 QQC2.Button { 0110 icon.name: "document-open" 0111 text: i18nd("KSysGuardSensorFaces", "Load Preset...") 0112 onClicked: presetSheet.open() 0113 } 0114 0115 NewStuff.Button { 0116 Accessible.name: i18nd("KSysGuardSensorFaces", "Get new presets...") 0117 configFile: "systemmonitor-presets.knsrc" 0118 text: "" 0119 onEntryEvent: controller.availablePresetsModel.reload(); 0120 QQC2.ToolTip { 0121 text: parent.Accessible.name 0122 } 0123 } 0124 0125 QQC2.Button { 0126 id: saveButton 0127 icon.name: "document-save" 0128 text: i18nd("KSysGuardSensorFaces", "Save Settings As Preset") 0129 onClicked: controller.savePreset(); 0130 } 0131 } 0132 0133 Kirigami.Separator { 0134 Kirigami.FormData.isSection: true 0135 } 0136 0137 RowLayout { 0138 Kirigami.FormData.label: i18nd("KSysGuardSensorFaces", "Title:") 0139 QQC2.TextField { 0140 id: titleField 0141 } 0142 QQC2.CheckBox { 0143 id: showTitleCheckbox 0144 text: i18nd("KSysGuardSensorFaces", "Show Title") 0145 } 0146 } 0147 0148 RowLayout { 0149 Kirigami.FormData.label: i18nd("KSysGuardSensorFaces", "Display Style:") 0150 QQC2.ComboBox { 0151 id: faceCombo 0152 model: controller.availableFacesModel 0153 textRole: "display" 0154 currentIndex: { 0155 // TODO just make an indexOf invocable on the model? 0156 for (var i = 0; i < count; ++i) { 0157 if (model.pluginId(i) === cfg_chartFace) { 0158 return i; 0159 } 0160 } 0161 return -1; 0162 } 0163 onActivated: { 0164 cfg_chartFace = model.pluginId(index); 0165 } 0166 } 0167 0168 NewStuff.Button { 0169 text: i18nd("KSysGuardSensorFaces", "Get New Display Styles...") 0170 configFile: "systemmonitor-faces.knsrc" 0171 onEntryEvent: controller.availableFacesModel.reload(); 0172 } 0173 } 0174 0175 QQC2.SpinBox { 0176 id: updateRateLimitSpinBox 0177 Layout.preferredWidth: titleField.implicitWidth 0178 0179 Kirigami.FormData.label: i18nd("KSysGuardSensorFaces", "Minimum Time Between Updates:") 0180 0181 from: 0 0182 to: 600000 0183 stepSize: 500 0184 editable: true 0185 0186 textFromValue: function(value, locale) { 0187 if (value <= 0) { 0188 return i18nd("KSysGuardSensorFaces", "No Limit"); 0189 } else { 0190 var seconds = value / 1000; 0191 if (seconds == 1) { // Manual plural handling because i18ndp doesn't handle floats :( 0192 return i18nd("KSysGuardSensorFaces", "1 second"); 0193 } else { 0194 return i18nd("KSysGuardSensorFaces", "%1 seconds", seconds); 0195 } 0196 } 0197 } 0198 valueFromText: function(value, locale) { 0199 // Don't use fromLocaleString here since it will error out on extra 0200 // characters like the (potentially translated) seconds that gets 0201 // added above. Instead parseInt ignores non-numeric characters. 0202 var v = parseInt(value) 0203 if (isNaN(v)) { 0204 return 0; 0205 } else { 0206 return v * 1000; 0207 } 0208 } 0209 } 0210 }