Libksysguard

ConfigAppearance.qml
1 /*
2  * Copyright 2019 Marco Martin <[email protected]>
3  * Copyright 2019 David Edmundson <[email protected]>
4  * Copyright 2019 Arjen Hiemstra <[email protected]>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU Library General Public License as
8  * published by the Free Software Foundation; either version 2, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this program; if not, write to the
18  * Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  */
21 
22 import QtQuick 2.9
23 import QtQuick.Layouts 1.2
24 import QtQuick.Controls 2.2 as QQC2
25 
26 import org.kde.kirigami 2.5 as Kirigami
27 import org.kde.kquickcontrols 2.0
28 import org.kde.kconfig 1.0 // for KAuthorized
29 import org.kde.newstuff 1.62 as NewStuff
30 
31 import org.kde.quickcharts 1.0 as Charts
32 import org.kde.ksysguard.sensors 1.0 as Sensors
33 import org.kde.ksysguard.faces 1.0 as Faces
34 
35 Kirigami.FormLayout {
36  id: root
37 
38  signal configurationChanged
39 
40  function saveConfig() {
41  controller.title = cfg_title;
42  controller.faceId = cfg_chartFace;
43  controller.showTitle = cfg_showTitle
44 
45  var preset = pendingPreset;
46  pendingPreset = "";
47  if (preset != "") {
48  controller.loadPreset(preset);
49  root.controller.highPrioritySensorColors = automaticColorSource.colors
50  }
51  }
52 
53  property Faces.SensorFaceController controller
54  property alias cfg_title: titleField.text
55  property alias cfg_showTitle: showTitleCheckbox.checked
56  property string cfg_chartFace
57 
58  onCfg_titleChanged: configurationChanged();
59  onCfg_showTitleChanged: configurationChanged()
60  onCfg_chartFaceChanged: configurationChanged();
61 
62  // config keys of the selected preset to be applied on save
63  property string pendingPreset
64 
65  Component.onCompleted: {
66  cfg_title = controller.title;
67  cfg_chartFace = controller.faceId;
68  cfg_showTitle = controller.showTitle
69  }
70 
71  Charts.ColorGradientSource {
72  id: automaticColorSource
73  baseColor: Kirigami.Theme.highlightColor
74  itemCount: root.controller.highPrioritySensorIds.length
75  }
76 
77  Kirigami.OverlaySheet {
78  id: presetSheet
79  parent: root
80  ListView {
81  implicitWidth: Kirigami.Units.gridUnit * 15
82  model: controller.availablePresetsModel
83  delegate: Kirigami.SwipeListItem {
84  contentItem: QQC2.Label {
85  Layout.fillWidth: true
86  text: model.display
87  }
88  actions: Kirigami.Action {
89  icon.name: "delete"
90  visible: model.writable
91  onTriggered: controller.uninstallPreset(model.pluginId);
92  }
93  onClicked: {
94  cfg_title = model.display;
95  pendingPreset = model.pluginId;
96  if (model.config.chartFace) {
97  cfg_chartFace = model.config.chartFace;
98  }
99 
100  root.configurationChanged();
101  presetSheet.close();
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  onChangedEntriesChanged: 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  enabled: controller.currentPreset.length == 0
130  onClicked: controller.savePreset();
131  }
132  }
133 
135  Kirigami.FormData.isSection: true
136  }
137 
138  RowLayout {
139  Kirigami.FormData.label: i18nd("KSysGuardSensorFaces", "Title:")
140  QQC2.TextField {
141  id: titleField
142  }
143  QQC2.CheckBox {
144  id: showTitleCheckbox
145  text: i18nd("KSysGuardSensorFaces", "Show Title")
146  }
147  }
148 
149  RowLayout {
150  Kirigami.FormData.label: i18nd("KSysGuardSensorFaces", "Display Style:")
151  QQC2.ComboBox {
152  id: faceCombo
153  model: controller.availableFacesModel
154  textRole: "display"
155  currentIndex: {
156  // TODO just make an indexOf invokable on the model?
157  for (var i = 0; i < count; ++i) {
158  if (model.pluginId(i) === cfg_chartFace) {
159  return i;
160  }
161  }
162  return -1;
163  }
164  onActivated: {
165  cfg_chartFace = model.pluginId(index);
166  }
167  }
168 
169  NewStuff.Button {
170  text: i18nd("KSysGuardSensorFaces", "Get New Display Styles...")
171  configFile: "systemmonitor-faces.knsrc"
172  onChangedEntriesChanged: controller.availableFacesModel.reload();
173  }
174  }
175 }
QString i18nd(const char *domain, const char *text, const TYPE &arg...)
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Thu Mar 4 2021 23:09:25 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.