Warning, /plasma/plasma-systemmonitor/src/table/ColumnConfigurationDialog.qml is written in an unsupported language. File is not indexed.
0001 /* 0002 * SPDX-FileCopyrightText: 2020 Arjen Hiemstra <ahiemstra@heimr.nl> 0003 * 0004 * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0005 */ 0006 0007 import QtQuick 2.12 0008 import QtQuick.Controls 2.12 0009 import QtQuick.Layouts 1.12 0010 0011 import org.kde.kirigami 2.5 as Kirigami 0012 0013 import org.kde.ksysguard.formatter 1.0 as Formatter 0014 import org.kde.ksysguard.table 1.0 as Table 0015 0016 Dialog { 0017 id: columnDialog 0018 0019 property alias model: columnView.model 0020 property alias sourceModel: sortModel.sourceModel 0021 property var visibleColumns: [] 0022 property var sortedColumns: [] 0023 property var fixedColumns: [] 0024 property var columnDisplay: {"name": "text"} 0025 0026 title: i18ndc("plasma-systemmonitor", "@window:title", "Configure Columns") 0027 0028 standardButtons: Dialog.Ok | Dialog.Cancel 0029 0030 modal: true 0031 parent: Overlay.overlay 0032 focus: true 0033 0034 x: parent ? Math.round(parent.width / 2 - width / 2) : 0 0035 y: ApplicationWindow.window ? ApplicationWindow.window.pageStack.globalToolBar.height - Kirigami.Units.smallSpacing : 0 0036 width: parent ? parent.width * 0.75 : 0 0037 height: parent ? parent.height * 0.75 : 0 0038 0039 leftPadding: 1 0040 rightPadding: 1 0041 bottomPadding: Kirigami.Units.smallSpacing 0042 topPadding: Kirigami.Units.smallSpacing 0043 bottomInset: -Kirigami.Units.smallSpacing 0044 0045 Kirigami.Theme.colorSet: Kirigami.Theme.View 0046 0047 function setColumnDisplay(display) { 0048 columnDisplay = display 0049 prepare() 0050 apply() 0051 } 0052 0053 onAccepted: { 0054 apply() 0055 } 0056 0057 onAboutToShow: { 0058 prepare() 0059 } 0060 0061 function prepare() { 0062 sortModel.sortedColumns = sortedColumns.filter(id => fixedColumns.indexOf(id) == -1) 0063 let tempDisplay = columnDisplay 0064 fixedColumns.forEach(column => delete tempDisplay[column]) 0065 displayModel.columnDisplay = tempDisplay 0066 } 0067 0068 function apply() { 0069 sortedColumns = fixedColumns.concat(sortModel.sortedColumns) 0070 visibleColumns = fixedColumns.concat(displayModel.visibleColumnIds) 0071 columnDisplay = displayModel.columnDisplay 0072 } 0073 0074 Rectangle { 0075 anchors.fill: parent 0076 Kirigami.Theme.colorSet: Kirigami.Theme.View 0077 color: Kirigami.Theme.backgroundColor 0078 } 0079 0080 ColumnLayout { 0081 anchors.fill: parent 0082 spacing: 0 0083 0084 Kirigami.Separator { Layout.fillWidth: true } 0085 0086 ScrollView { 0087 Layout.fillWidth: true 0088 Layout.fillHeight: true 0089 clip: true 0090 0091 ListView { 0092 id: columnView 0093 0094 0095 model: Table.ColumnDisplayModel { 0096 id: displayModel 0097 0098 sourceModel: Table.ColumnSortModel { 0099 id: sortModel 0100 } 0101 } 0102 0103 delegate: Loader { 0104 width: columnView.width 0105 height: Kirigami.Units.gridUnit * 3 0106 property var modelData: model 0107 sourceComponent: delegateComponent 0108 } 0109 0110 Component { 0111 id: delegateComponent 0112 Kirigami.AbstractListItem { 0113 id: listItem 0114 Kirigami.Theme.colorSet: Kirigami.Theme.View 0115 rightPadding: Kirigami.Units.smallSpacing 0116 property int index: modelData ? modelData.row : -1 0117 activeFocusOnTab: false 0118 contentItem: GridLayout { 0119 rows: 2 0120 flow: GridLayout.TopToBottom 0121 Kirigami.ListItemDragHandle { 0122 id: handle 0123 Layout.fillHeight: true 0124 Layout.rowSpan: 2 0125 listItem: listItem 0126 listView: columnView 0127 onMoveRequested: sortModel.move(oldIndex, newIndex) 0128 } 0129 Label { 0130 Layout.preferredWidth: Kirigami.Units.gridUnit * 10 0131 Layout.rowSpan: modelData && modelData.description ? 1 : 2 0132 text: modelData ? modelData.name : "" 0133 } 0134 Label { 0135 id: descriptionLabel 0136 Layout.fillWidth: true 0137 elide: Text.ElideRight 0138 maximumLineCount: 1 0139 textFormat: Text.PlainText 0140 text: modelData ? modelData.description.replace("<br>", " ") : "" 0141 color: Kirigami.Theme.disabledTextColor 0142 } 0143 0144 ComboBox { 0145 id: showCombo 0146 textRole: "text" 0147 Layout.rowSpan: 2 0148 model: { 0149 var result = [ 0150 {text: i18ndc("plasma-systemmonitor", "@item:inlistbox", "Hidden"), value: "hidden"}, 0151 {text: i18ndc("plasma-systemmonitor", "@item:inlistbox", "Text Only"), value: "text"}, 0152 ] 0153 0154 if (modelData && modelData.unit) { 0155 if (modelData.unit != Formatter.Units.UnitInvalid 0156 && modelData.unit != Formatter.Units.UnitNone) { 0157 result.push({text: i18ndc("plasma-systemmonitor", "@item:inlistbox", "Line Chart"), value: "line"}) 0158 } 0159 if (modelData.unit == Formatter.Units.UnitPercent 0160 && modelData.maximum != 100) { 0161 result.push({text: i18ndc("plasma-systemmonitor", "@item:inlistbox", "Text Only (Scaled to 100%)"), value: "textScaled"}) 0162 result.push({text: i18ndc("plasma-systemmonitor", "@item:inlistbox", "Line Chart (Scaled to 100%)"), value: "lineScaled"}) 0163 } 0164 } 0165 return result 0166 } 0167 0168 currentIndex: { 0169 if (!modelData) { 0170 return -1; 0171 } 0172 0173 for (var i = 0; i < model.length; ++i) { 0174 if (model[i].value == modelData.displayStyle) { 0175 return i; 0176 } 0177 } 0178 return -1; 0179 } 0180 0181 onActivated: { 0182 displayModel.setDisplay(listItem.index, model[index].value); 0183 } 0184 } 0185 } 0186 0187 ToolTip.text: modelData ? modelData.description.replace("<br>", " ") : "" 0188 ToolTip.visible: listItem.hovered && descriptionLabel.truncated 0189 ToolTip.delay: Kirigami.Units.toolTipDelay 0190 } 0191 } 0192 } 0193 } 0194 0195 Kirigami.Separator { Layout.fillWidth: true; } 0196 } 0197 }