Warning, /plasma/plasma-systemmonitor/src/page/PageSortDialog.qml is written in an unsupported language. File is not indexed.
0001 /*
0002 * SPDX-FileCopyrightText: 2020 David Redondo <kde@david-redondo.de>
0003 * SPDX-FileCopyrightText: 2023 Nate Graham <nate@kde.org>
0004 *
0005 * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0006 */
0007
0008 import QtQuick
0009 import QtQuick.Controls
0010 import QtQuick.Layouts
0011
0012 import org.kde.kirigami as Kirigami
0013
0014
0015 import org.kde.ksysguard.page as Page
0016
0017 Kirigami.Dialog {
0018 id: dialog
0019
0020 property alias model : sortModel.sourceModel
0021 property string startPage
0022 property string newStartPage
0023 property bool startPageWasChanged: false
0024
0025 preferredWidth: parent ? parent.width * 0.5 : -1
0026 preferredHeight: parent ? parent.height * 0.5 : -1
0027
0028 focus: true
0029
0030 // We already have a cancel button in the footer
0031 showCloseButton: false
0032
0033 standardButtons: Dialog.Ok | Dialog.Cancel
0034
0035 onAboutToShow: {
0036 sortModel.sourceModel = model
0037 }
0038
0039 onAccepted: {
0040 if (dialog.startPageWasChanged) {
0041 startPage = newStartPage;
0042 }
0043 sortModel.applyChangesToSourceModel()
0044 }
0045
0046 ListView {
0047 id: pageList
0048
0049 reuseItems: true
0050 clip: true
0051
0052 model: Page.PageSortModel {
0053 id: sortModel
0054 }
0055 delegate: ItemDelegate {
0056 id: listItem
0057 readonly property string title: model ? model.title : ""
0058 //Using directly model.hidden below doesn't work for some reason
0059 readonly property bool hidden: model ? model.hidden : false
0060 readonly property var filesWritable: model ? model.filesWriteable : false
0061 readonly property bool shouldRemoveFiles: model ? model.shouldRemoveFiles : false
0062
0063 width: pageList.width - pageList.leftMargin - pageList.rightMargin
0064
0065 activeFocusOnTab: false
0066
0067 // We don't want visual interactivity for the background
0068 highlighted: false
0069 hoverEnabled: false
0070 down: false
0071
0072 contentItem: RowLayout {
0073 spacing: Kirigami.Units.smallSpacing
0074
0075 Kirigami.ListItemDragHandle {
0076 id: handle
0077 Layout.fillHeight: true
0078 Layout.rowSpan: 2
0079 listItem: listItem
0080 listView: pageList
0081 onMoveRequested: (oldIndex, newIndex) => {
0082 sortModel.move(oldIndex, newIndex)
0083 }
0084 }
0085 CheckBox {
0086 checked: !listItem.hidden
0087 onToggled: pageList.model.setData(pageList.model.index(index, 0), !listItem.hidden, Page.PagesModel.HiddenRole)
0088 ToolTip.text: listItem.hidden ? i18nc("@info:tooltip", "Show Page")
0089 : i18nc("@info:tooltip", "Hide Page")
0090 ToolTip.delay: Kirigami.Units.toolTipDelay
0091 ToolTip.visible: hovered
0092 }
0093 Kirigami.Icon {
0094 Layout.preferredWidth: Kirigami.Units.iconSizes.smallMedium
0095 Layout.preferredHeight: Layout.preferredWidth
0096 source: model ? model.icon : ""
0097 opacity: listItem.hidden ? 0.3 : 1
0098 }
0099 ColumnLayout {
0100 Layout.fillWidth: true
0101 Layout.alignment: Qt.AlignVCenter
0102 spacing: 0
0103 Label {
0104 Layout.fillWidth: true
0105 text: listItem.title
0106 opacity: listItem.hidden ? 0.3 : 1
0107 }
0108 Label {
0109 id: subtitle
0110 Layout.fillWidth: true
0111 font: Kirigami.Theme.smallFont
0112 opacity: 0.7
0113 visible: text.length > 0
0114 }
0115 }
0116 Button {
0117 id: removeButton
0118 onClicked: pageList.model.setData(pageList.model.index(index, 0), !listItem.shouldRemoveFiles, Page.PageSortModel.ShouldRemoveFilesRole)
0119 ToolTip.delay: Kirigami.Units.toolTipDelay
0120 ToolTip.visible: hovered
0121 }
0122
0123 states: [
0124 State {
0125 name: "noChanges"
0126 extend: "localChanges"
0127 when: listItem.filesWritable == Page.PagesModel.NotWriteable
0128 PropertyChanges {
0129 target: removeButton;
0130 enabled: false;
0131 }
0132 },
0133 State {
0134 name: "removeLocalChanges"
0135 when: listItem.filesWritable == Page.PagesModel.LocalChanges && listItem.shouldRemoveFiles
0136 PropertyChanges {
0137 target: removeButton
0138 icon.name: "edit-redo"
0139 ToolTip.text: i18nc("@info:tooltip", "Do not reset the page")
0140 }
0141 PropertyChanges {
0142 target: subtitle
0143 text: i18nc("@item:intable", "The page will be reset to its default state")
0144 }
0145 },
0146 State {
0147 name: "localChanges"
0148 when: listItem.filesWritable == Page.PagesModel.LocalChanges
0149 PropertyChanges {
0150 target: removeButton
0151 icon.name: "edit-reset"
0152 ToolTip.text: i18nc("@info:tooltip", "Reset the page to its default state")
0153 }
0154 },
0155 State {
0156 name: "remove"
0157 when: listItem.filesWritable == Page.PagesModel.AllWriteable && listItem.shouldRemoveFiles
0158 PropertyChanges {
0159 target: removeButton
0160 icon.name: "edit-undo"
0161 ToolTip.text: i18nc("@info:tooltip", "Do not remove this page")
0162 }
0163 PropertyChanges {
0164 target: subtitle
0165 text: i18nc("@item:intable", "The page will be removed")
0166 }
0167 PropertyChanges {
0168 target: listItem
0169 backgroundColor: Kirigami.Theme.negativeBackgroundColor
0170 }
0171 },
0172 State {
0173 name: "removeable"
0174 when: listItem.filesWritable == Page.PagesModel.AllWriteable
0175 PropertyChanges {
0176 target: removeButton
0177 icon.name: "edit-delete"
0178 ToolTip.text: i18nc("@info:tooltip", "Remove this page")
0179 }
0180 }
0181 ]
0182 }
0183 }
0184 }
0185
0186 footerLeadingComponent: RowLayout {
0187 spacing: Kirigami.Units.smallSpacing
0188
0189 Label {
0190 leftPadding: Kirigami.Units.largeSpacing
0191 text: i18nc("@label:listbox", "Start with:")
0192 }
0193 ComboBox {
0194 id: startPageBox
0195 textRole: "title"
0196 valueRole: "fileName"
0197 model: createModel()
0198
0199 function createModel() {
0200 var result = [{fileName: "", title: i18n("Last Visited Page"), icon: "clock"}];
0201 for (var i = 0; i < sortModel.rowCount(); ++i) {
0202 const index = sortModel.index(i, 0)
0203 if (sortModel.data(index, Page.PagesModel.HiddenRole)) {
0204 continue
0205 }
0206 if (sortModel.data(index, Page.PageSortModel.ShouldRemoveFilesRole)
0207 && sortModel.data(index, Page.PagesModel.FilesWriteableRole) == Page.PagesModel.AllWriteable) {
0208 continue
0209 }
0210 result.push({fileName: sortModel.data(index, Page.PagesModel.FileNameRole),
0211 title: sortModel.data(index, Page.PagesModel.TitleRole),
0212 icon: sortModel.data(index, Page.PagesModel.IconRole)})
0213 }
0214 return result
0215 }
0216
0217 Connections {
0218 target: sortModel
0219 function onDataChanged() { refreshModel() }
0220 function onRowsMoved() { refreshModel() }
0221 function refreshModel() {
0222 const value = startPageBox.currentValue
0223 startPageBox.model = startPageBox.createModel()
0224 startPageBox.currentIndex = startPageBox.indexOfValue(value)
0225 }
0226 }
0227
0228 delegate: ItemDelegate {
0229 width: parent.width
0230 highlighted: startPageBox.highlightedIndex == index
0231 contentItem: RowLayout {
0232 Kirigami.Icon {
0233 color: highlighted ? Kirigami.Theme.highlightedTextColor : Kirigami.Theme.textColor
0234 source: modelData.icon
0235 Layout.preferredHeight: Kirigami.Units.iconSizes.small
0236 Layout.preferredWidth: Kirigami.Units.iconSizes.small
0237 }
0238 Label {
0239 text: modelData.title
0240 color: highlighted ? Kirigami.Theme.highlightedTextColor : Kirigami.Theme.textColor
0241 Layout.fillWidth: true
0242 }
0243 }
0244 }
0245
0246 onActivated: {
0247 dialog.startPageWasChanged = true;
0248 dialog.newStartPage = currentValue;
0249 }
0250
0251 Component.onCompleted: {
0252 currentIndex = indexOfValue(startPage);
0253 }
0254 }
0255 }
0256 }