Libksysguard

ConfigAppearance.qml
1/*
2 SPDX-FileCopyrightText: 2019 Marco Martin <mart@kde.org>
3 SPDX-FileCopyrightText: 2019 David Edmundson <davidedmundson@kde.org>
4 SPDX-FileCopyrightText: 2019 Arjen Hiemstra <ahiemstra@heimr.nl>
5
6 SPDX-License-Identifier: LGPL-2.0-or-later
7*/
8
9import QtQuick
10import QtQuick.Layouts
11import QtQuick.Controls as QQC2
12
13import org.kde.kirigami as Kirigami
14import org.kde.kquickcontrols
15import org.kde.config
16import org.kde.newstuff as NewStuff
17
18import org.kde.quickcharts as Charts
19import org.kde.ksysguard.sensors as Sensors
20import org.kde.ksysguard.faces as Faces
21
22Kirigami.FormLayout {
23 id: root
24
25 signal configurationChanged
26
27 function saveConfig() {
28 controller.title = cfg_title;
29 controller.faceId = cfg_chartFace;
30 controller.showTitle = cfg_showTitle
31 controller.updateRateLimit = cfg_updateRateLimit
32
33 var preset = pendingPreset;
34 pendingPreset = "";
35 if (preset != "") {
36 controller.loadPreset(preset);
37 root.controller.highPrioritySensorColors = automaticColorSource.colors
38 }
39 }
40
41 property Faces.SensorFaceController controller
42 property alias cfg_title: titleField.text
43 property alias cfg_showTitle: showTitleCheckbox.checked
44 property string cfg_chartFace
45 property alias cfg_updateRateLimit: updateRateLimitSpinBox.value
46
47 onCfg_titleChanged: configurationChanged();
48 onCfg_showTitleChanged: configurationChanged()
49 onCfg_chartFaceChanged: configurationChanged();
50 onCfg_updateRateLimitChanged: configurationChanged();
51
52 // config keys of the selected preset to be applied on save
53 property string pendingPreset
54
55 Component.onCompleted: {
56 cfg_title = controller.title;
57 cfg_chartFace = controller.faceId;
58 cfg_showTitle = controller.showTitle
59 cfg_updateRateLimit = controller.updateRateLimit
60 }
61
62 Charts.ColorGradientSource {
63 id: automaticColorSource
64 baseColor: Kirigami.Theme.highlightColor
65 itemCount: root.controller.highPrioritySensorIds.length
66 }
67
68 Kirigami.OverlaySheet {
69 id: presetSheet
70 parent: root
71 ListView {
72 implicitWidth: Kirigami.Units.gridUnit * 15
73 focus: true
74 model: controller.availablePresetsModel
75 delegate: Kirigami.SwipeListItem {
76 contentItem: QQC2.Label {
77 elide: Text.ElideRight
78 text: model.display
79 }
80 actions: Kirigami.Action {
81 icon.name: "delete"
82 visible: model.writable
83 onTriggered: controller.uninstallPreset(model.pluginId);
84 }
85 onClicked: {
86 cfg_title = model.display;
87 pendingPreset = model.pluginId;
88 if (model.config.chartFace) {
89 cfg_chartFace = model.config.chartFace;
90 }
91
92 root.configurationChanged();
93 presetSheet.close();
94 }
95
96 // shortcut overrides can only be on the item with focus
97 Keys.onShortcutOverride: {
98 if (event.key === Qt.Key_Escape) {
99 event.accepted = true;
100 root.close();
101 }
102 }
103 }
104 }
105 }
106 RowLayout {
107 Kirigami.FormData.label: i18nd("KSysGuardSensorFaces", "Presets:")
108
109 QQC2.Button {
110 icon.name: "document-open"
111 text: i18nd("KSysGuardSensorFaces", "Load Preset...")
112 onClicked: presetSheet.open()
113 }
114
115 NewStuff.Button {
116 Accessible.name: i18nd("KSysGuardSensorFaces", "Get new presets...")
117 configFile: "systemmonitor-presets.knsrc"
118 text: ""
119 onEntryEvent: controller.availablePresetsModel.reload();
120 QQC2.ToolTip {
121 text: parent.Accessible.name
122 }
123 }
124
125 QQC2.Button {
126 id: saveButton
127 icon.name: "document-save"
128 text: i18nd("KSysGuardSensorFaces", "Save Settings As Preset")
129 onClicked: controller.savePreset();
130 }
131 }
132
134 Kirigami.FormData.isSection: true
135 }
136
137 RowLayout {
138 Kirigami.FormData.label: i18nd("KSysGuardSensorFaces", "Title:")
139 QQC2.TextField {
140 id: titleField
141 }
142 QQC2.CheckBox {
143 id: showTitleCheckbox
144 text: i18nd("KSysGuardSensorFaces", "Show Title")
145 }
146 }
147
148 RowLayout {
149 Kirigami.FormData.label: i18nd("KSysGuardSensorFaces", "Display Style:")
150 QQC2.ComboBox {
151 id: faceCombo
152 model: controller.availableFacesModel
153 textRole: "display"
154 currentIndex: {
155 // TODO just make an indexOf invocable on the model?
156 for (var i = 0; i < count; ++i) {
157 if (model.pluginId(i) === cfg_chartFace) {
158 return i;
159 }
160 }
161 return -1;
162 }
163 onActivated: {
164 cfg_chartFace = model.pluginId(index);
165 }
166 }
167
168 NewStuff.Button {
169 text: i18nd("KSysGuardSensorFaces", "Get New Display Styles...")
170 configFile: "systemmonitor-faces.knsrc"
171 onEntryEvent: controller.availableFacesModel.reload();
172 }
173 }
174
175 QQC2.SpinBox {
176 id: updateRateLimitSpinBox
177 Layout.preferredWidth: titleField.implicitWidth
178
179 Kirigami.FormData.label: i18nd("KSysGuardSensorFaces", "Minimum Time Between Updates:")
180
181 from: 0
182 to: 600000
183 stepSize: 500
184 editable: true
185
186 textFromValue: function(value, locale) {
187 if (value <= 0) {
188 return i18nd("KSysGuardSensorFaces", "No Limit");
189 } else {
190 var seconds = value / 1000;
191 if (seconds == 1) { // Manual plural handling because i18ndp doesn't handle floats :(
192 return i18nd("KSysGuardSensorFaces", "1 second");
193 } else {
194 return i18nd("KSysGuardSensorFaces", "%1 seconds", seconds);
195 }
196 }
197 }
198 valueFromText: function(value, locale) {
199 // Don't use fromLocaleString here since it will error out on extra
200 // characters like the (potentially translated) seconds that gets
201 // added above. Instead parseInt ignores non-numeric characters.
202 var v = parseInt(value)
203 if (isNaN(v)) {
204 return 0;
205 } else {
206 return v * 1000;
207 }
208 }
209 }
210}
QString i18nd(const char *domain, const char *text, const TYPE &arg...)
AKONADI_CALENDAR_EXPORT KCalendarCore::Event::Ptr event(const Akonadi::Item &item)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:21:23 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.