| 1 |
/* |
| 2 |
SPDX-FileCopyrightText: 2021 Arjen Hiemstra <[email protected]> |
| 3 |
|
| 4 |
SPDX-License-Identifier: LGPL-2.0-or-later |
| 5 |
*/ |
| 6 |
|
| 7 |
import QtQuick |
| 8 |
import QtQuick.Controls |
| 9 |
import QtQuick.Layouts |
| 10 |
|
| 11 |
import org.kde.kirigami as Kirigami |
| 12 |
import org.kde.kitemmodels as KItemModels |
| 13 |
|
| 14 |
import org.kde.ksysguard.sensors as Sensors |
| 15 |
import org.kde.ksysguard.faces as Faces |
| 16 |
|
| 17 |
ColumnLayout { |
| 18 |
id: root |
| 19 |
|
| 20 |
property alias cfg_columnCount: columnCountSpin.value |
| 21 |
property string cfg_faceId |
| 22 |
|
| 23 |
property var faceController: controller |
| 24 |
|
| 25 |
// The pluginId role from the FacesModel. FacesModel is a private class that |
| 26 |
// is only created by FaceController, so we can't access its roles from QML. |
| 27 |
// So declare this here since we need to use it in multiple places. |
| 28 |
readonly property int pluginIdRole: Qt.UserRole + 1 |
| 29 |
|
| 30 |
Kirigami.FormLayout { |
| 31 |
id: form |
| 32 |
|
| 33 |
SpinBox { |
| 34 |
id: columnCountSpin |
| 35 |
Kirigami.FormData.label: i18nc("@label:spinbox", "Number of columns:") |
| 36 |
editable: true |
| 37 |
from: 0 |
| 38 |
to: 99999 |
| 39 |
|
| 40 |
textFromValue: function(value, locale) { |
| 41 |
if (value <= 0) { |
| 42 |
return i18nc("@label automatic number of columns", "Automatic") |
| 43 |
} |
| 44 |
return value.toString() |
| 45 |
} |
| 46 |
|
| 47 |
valueFromText: function(value, locale) { |
| 48 |
return parseInt(value) |
| 49 |
} |
| 50 |
} |
| 51 |
|
| 52 |
ComboBox { |
| 53 |
id: faceCombo |
| 54 |
Kirigami.FormData.label: i18nc("@label:listbox items are sensor face names", "Display style:") |
| 55 |
|
| 56 |
model: KItemModels.KSortFilterProxyModel { |
| 57 |
sourceModel: controller.availableFacesModel |
| 58 |
|
| 59 |
filterRowCallback: function(row, parent) { |
| 60 |
const pluginId = sourceModel.data(sourceModel.index(row, 0, parent), root.pluginIdRole) |
| 61 |
const excludedPlugins = [ |
| 62 |
"org.kde.ksysguard.facegrid", |
| 63 |
"org.kde.ksysguard.colorgrid", |
| 64 |
"org.kde.ksysguard.applicationstable", |
| 65 |
"org.kde.ksysguard.processtable" |
| 66 |
] |
| 67 |
|
| 68 |
return !excludedPlugins.includes(pluginId) |
| 69 |
} |
| 70 |
|
| 71 |
sortRoleName: "display" |
| 72 |
} |
| 73 |
|
| 74 |
textRole: "display" |
| 75 |
currentIndex: { |
| 76 |
// TODO just make an indexOf invocable on the model? |
| 77 |
for (var i = 0; i < count; ++i) { |
| 78 |
const pluginId = model.data(model.index(i, 0), root.pluginIdRole) |
| 79 |
if (pluginId === root.cfg_faceId) { |
| 80 |
return i; |
| 81 |
} |
| 82 |
} |
| 83 |
return -1; |
| 84 |
} |
| 85 |
onActivated: { |
| 86 |
root.cfg_faceId = model.data(model.index(index, 0), root.pluginIdRole) |
| 87 |
} |
| 88 |
} |
| 89 |
} |
| 90 |
|
| 91 |
Faces.FaceLoader { |
| 92 |
id: loader |
| 93 |
parentController: root.faceController |
| 94 |
groupName: "FaceGrid" |
| 95 |
faceId: root.cfg_faceId |
| 96 |
readOnly: false |
| 97 |
} |
| 98 |
|
| 99 |
Item { |
| 100 |
Layout.fillWidth: true |
| 101 |
implicitHeight: children.length > 0 ? children[0].implicitHeight : 0 |
| 102 |
|
| 103 |
children: loader.controller ? loader.controller.faceConfigUi : null |
| 104 |
|
| 105 |
onWidthChanged: { |
| 106 |
if (children.length > 0) { |
| 107 |
children[0].width = width |
| 108 |
} |
| 109 |
} |
| 110 |
|
| 111 |
Connections { |
| 112 |
target: loader.controller ? loader.controller.faceConfigUi : null |
| 113 |
|
| 114 |
function onConfigurationChanged() { |
| 115 |
loader.controller.faceConfigUi.saveConfig() |
| 116 |
root.faceController.faceConfigUi.configurationChanged() |
| 117 |
} |
| 118 |
} |
| 119 |
} |
| 120 |
} |