Warning, /plasma/libksysguard/faces/facepackages/facegrid/contents/ui/Config.qml is written in an unsupported language. File is not indexed.

0001 /*
0002     SPDX-FileCopyrightText: 2021 Arjen Hiemstra <ahiemstra@heimr.nl>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005  */
0006 
0007 import QtQuick
0008 import QtQuick.Controls
0009 import QtQuick.Layouts
0010 
0011 import org.kde.kirigami as Kirigami
0012 import org.kde.kitemmodels as KItemModels
0013 
0014 import org.kde.ksysguard.sensors as Sensors
0015 import org.kde.ksysguard.faces as Faces
0016 
0017 ColumnLayout {
0018     id: root
0019 
0020     property alias cfg_columnCount: columnCountSpin.value
0021     property string cfg_faceId
0022 
0023     property var faceController: controller
0024 
0025     // The pluginId role from the FacesModel. FacesModel is a private class that
0026     // is only created by FaceController, so we can't access its roles from QML.
0027     // So declare this here since we need to use it in multiple places.
0028     readonly property int pluginIdRole: Qt.UserRole + 1
0029 
0030     Kirigami.FormLayout {
0031         id: form
0032 
0033         SpinBox {
0034             id: columnCountSpin
0035             Kirigami.FormData.label: i18n("Number of Columns:")
0036             editable: true
0037             from: 0
0038             to: 99999
0039 
0040             textFromValue: function(value, locale) {
0041                 if (value <= 0) {
0042                     return i18nc("@label", "Automatic")
0043                 }
0044                 return value.toString()
0045             }
0046 
0047             valueFromText: function(value, locale) {
0048                 return parseInt(value)
0049             }
0050         }
0051 
0052         ComboBox {
0053             id: faceCombo
0054             Kirigami.FormData.label: i18n("Display Style:")
0055 
0056             model: KItemModels.KSortFilterProxyModel {
0057                 sourceModel: controller.availableFacesModel
0058 
0059                 filterRowCallback: function(row, parent) {
0060                     const pluginId = sourceModel.data(sourceModel.index(row, 0, parent), root.pluginIdRole)
0061                     const excludedPlugins = [
0062                         "org.kde.ksysguard.facegrid",
0063                         "org.kde.ksysguard.applicationstable",
0064                         "org.kde.ksysguard.processtable"
0065                     ]
0066 
0067                     return !excludedPlugins.includes(pluginId)
0068                 }
0069 
0070                 sortRole: "display"
0071             }
0072 
0073             textRole: "display"
0074             currentIndex: {
0075                 // TODO just make an indexOf invocable on the model?
0076                 for (var i = 0; i < count; ++i) {
0077                     const pluginId = model.data(model.index(i, 0), root.pluginIdRole)
0078                     if (pluginId === root.cfg_faceId) {
0079                         return i;
0080                     }
0081                 }
0082                 return -1;
0083             }
0084             onActivated: {
0085                 root.cfg_faceId = model.data(model.index(index, 0), root.pluginIdRole)
0086             }
0087         }
0088     }
0089 
0090     Faces.FaceLoader {
0091         id: loader
0092         parentController: root.faceController
0093         groupName: "FaceGrid"
0094         faceId: root.cfg_faceId
0095         readOnly: false
0096     }
0097 
0098     Item {
0099         Layout.fillWidth: true
0100         implicitHeight: children.length > 0 ? children[0].implicitHeight : 0
0101 
0102         children: loader.controller ? loader.controller.faceConfigUi : null
0103 
0104         onWidthChanged: {
0105             if (children.length > 0) {
0106                 children[0].width = width
0107             }
0108         }
0109 
0110         Connections {
0111             target: loader.controller ? loader.controller.faceConfigUi : null
0112 
0113             function onConfigurationChanged() {
0114                 loader.controller.faceConfigUi.saveConfig()
0115                 root.faceController.faceConfigUi.configurationChanged()
0116             }
0117         }
0118     }
0119 }