Warning, /plasma/plasma-systemmonitor/src/page/ColumnControl.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.14 0008 import QtQuick.Controls 2.14 0009 import QtQuick.Layouts 1.14 0010 0011 import org.kde.kirigami 2.12 as Kirigami 0012 0013 import org.kde.ksysguard.page 1.0 0014 0015 Container { 0016 id: control 0017 0018 property PageDataObject columnData 0019 0020 function replaceSensors(replacement) { 0021 for (let i = 0; i < repeater.count; ++i) { 0022 repeater.itemAt(i).replaceSensors(replacement) 0023 } 0024 } 0025 0026 Kirigami.AbstractCard { 0027 parent: control.background 0028 anchors.fill: parent 0029 visible: control.columnData.showBackground 0030 showClickFeedback: true 0031 onClicked: control.select(control) 0032 } 0033 0034 contentItem: Row { 0035 id: row 0036 0037 anchors.fill: parent 0038 anchors.topMargin: control.topPadding 0039 anchors.bottomMargin: control.bottomPadding 0040 anchors.leftMargin: control.leftPadding 0041 anchors.rightMargin: control.rightPadding 0042 0043 spacing: Kirigami.Units.largeSpacing 0044 0045 move: Transition { 0046 NumberAnimation { properties: "x,y"; duration: Kirigami.Units.shortDuration } 0047 } 0048 0049 function relayout() { 0050 let itemCount = repeater.count; 0051 let separatorsWidth = 0; 0052 let separatorsCount = 0; 0053 let minimumContentHeight = 0; 0054 let minimumHeight = 0; 0055 0056 for (let i = 0; i < itemCount; ++i) { 0057 let item = repeater.itemAt(i) 0058 if (item) { 0059 if (item.sectionData.isSeparator) { 0060 separatorsWidth += item.width 0061 separatorsCount += 1 0062 } else { 0063 minimumContentHeight = Math.max(minimumContentHeight, item.minimumContentHeight) 0064 minimumHeight = Math.max(minimumHeight, item.minimumHeight) 0065 } 0066 } 0067 } 0068 0069 let sectionWidth = (row.width - separatorsWidth - (itemCount - 1) * spacing) / (itemCount - separatorsCount) 0070 0071 for (let i = 0; i < itemCount; ++i) { 0072 let item = repeater.itemAt(i) 0073 if (item && !item.sectionData.isSeparator) { 0074 item.width = sectionWidth 0075 } 0076 } 0077 0078 control.minimumContentHeight = minimumContentHeight 0079 control.minimumHeight = minimumHeight + control.topPadding + control.bottomPadding 0080 } 0081 0082 onWidthChanged: Qt.callLater(relayout) 0083 onHeightChanged: Qt.callLater(relayout) 0084 0085 Repeater { 0086 id: repeater 0087 model: PageDataModel { data: control.columnData } 0088 0089 onItemAdded: Qt.callLater(row.relayout) 0090 onItemRemoved: Qt.callLater(row.relayout) 0091 0092 SectionControl { 0093 height: parent.height 0094 onWidthChanged: Qt.callLater(row.relayout) 0095 0096 onMinimumContentHeightChanged: Qt.callLater(row.relayout) 0097 onMinimumHeightChanged: Qt.callLater(row.relayout) 0098 0099 activeItem: control.activeItem 0100 single: control.columnData.children.length == 1 0101 sectionData: model.data 0102 index: model.index 0103 0104 onSelect: control.select(item) 0105 onAddSection: control.addSection(index + 1) 0106 onAddSeparator: control.addSeparator(index + 1) 0107 onRemove: control.columnData.removeChild(index) 0108 onMove: control.columnData.moveChild(from, to) 0109 0110 onMissingSensorsChanged: control.missingSensorsChanged(id, title, sensors) 0111 } 0112 } 0113 } 0114 0115 toolbar.addActions: [ 0116 Action { 0117 text: i18nc("@action", "Add Section") 0118 onTriggered: addSection(control.columnData.children.length) 0119 }, 0120 Action { 0121 text: i18nc("@action", "Add Separator") 0122 onTriggered: addSeparator(control.columnData.children.length) 0123 } 0124 ] 0125 toolbar.moveAxis: Qt.XAxis 0126 0127 toolbar.extraActions: [ 0128 Action { 0129 icon.name: "view-visible" 0130 text: i18nc("@action", "Show Background") 0131 checkable: true 0132 checked: control.columnData.showBackground 0133 onTriggered: control.columnData.showBackground = !control.columnData.showBackground 0134 }, 0135 Action { 0136 icon.name: "trim-margins" 0137 text: i18nc("@action", "Remove Background Margins") 0138 enabled: control.columnData.showBackground 0139 checkable: true 0140 checked: control.columnData.noMargins 0141 onTriggered: control.columnData.noMargins = !control.columnData.noMargins 0142 } 0143 ] 0144 0145 function addSection(index) { 0146 control.columnData.insertChild(index, {name: "section-" + index, isSeparator: false}) 0147 } 0148 0149 function addSeparator(index) { 0150 control.columnData.insertChild(index, {name: "section-" + index, isSeparator: true}) 0151 } 0152 0153 Component.onCompleted: { 0154 if (columnData.children.length == 0) { 0155 addSection(0) 0156 } 0157 } 0158 }