Warning, /plasma/plasma-systemmonitor/src/page/PageDialog.qml is written in an unsupported language. File is not indexed.
0001 /* 0002 * SPDX-FileCopyrightText: 2020 Arjen Hiemstra <ahiemstra@heimr.nl> 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 import org.kde.kitemmodels as KItemModels 0014 import org.kde.iconthemes as KIconThemes 0015 0016 import org.kde.ksysguard.page 0017 0018 Kirigami.Dialog { 0019 id: dialog 0020 0021 property string acceptText: i18nc("@action:button", "Add") 0022 property string acceptIcon: "list-add" 0023 0024 property string name: i18nc("@info:placeholder", "New Page") 0025 property string iconName: "ksysguardd" 0026 property real margin: 2 0027 property string actionsFace: "dummy" //Can't leave it empty, otherwise it doesn't update when it's initially set to an empty string 0028 property alias pageData: facesModel.pageData 0029 0030 property string loadType: "ondemand" 0031 0032 // No top padding since the content item is a Kirigami.FormLayout which 0033 // brings its own. But it doesn't provide any other padding, so we need to 0034 // add some or else it touches the edges of the dialog's content area, 0035 // which looks bad. 0036 topPadding: 0 0037 leftPadding: Kirigami.Units.largeSpacing 0038 rightPadding: Kirigami.Units.largeSpacing 0039 bottomPadding: Kirigami.Units.largeSpacing 0040 0041 focus: true 0042 0043 // We already have a cancel button in the footer 0044 showCloseButton: false 0045 0046 standardButtons: Kirigami.Dialog.Cancel 0047 0048 customFooterActions: [ 0049 Kirigami.Action { 0050 text: dialog.acceptText 0051 icon.name: dialog.acceptIcon 0052 enabled: nameField.acceptableInput 0053 onTriggered: { 0054 if (actionsCombobox.currentValue) { 0055 dialog.actionsFace = actionsCombobox.currentValue; 0056 } 0057 dialog.accept(); 0058 } 0059 } 0060 ] 0061 0062 onOpened: { 0063 // Reset focus to the name field. 0064 // When opening the dialog multiple times, the focus object remains the 0065 // last focussed item, which is usually one of the buttons. Since the 0066 // first things we generally want to do in this dialog is edit the 0067 // title, we reset the focus to the name field when the dialog is 0068 // opened. 0069 nameField.forceActiveFocus() 0070 } 0071 0072 onClosed: { 0073 actionsFace = "dummy" //see above 0074 pageData = null 0075 } 0076 0077 Kirigami.FormLayout { 0078 id: form 0079 0080 focus: true 0081 0082 TextField { 0083 id: nameField 0084 0085 Kirigami.FormData.label: i18nc("@label:textbox", "Name:") 0086 text: dialog.name 0087 onTextEdited: dialog.name = text 0088 0089 focus: true 0090 0091 validator: RegularExpressionValidator { regularExpression: /^[\pL\pN][^\pC/]*/ } 0092 } 0093 Kirigami.InlineMessage { 0094 Layout.fillWidth: true 0095 type: Kirigami.MessageType.Error 0096 text: i18nc("@info:status", "Name cannot be empty.") 0097 visible: !nameField.acceptableInput 0098 } 0099 Button { 0100 Kirigami.FormData.label: i18nc("@label:textbox", "Icon:") 0101 icon.name: dialog.iconName 0102 onClicked: iconDialog.open() 0103 } 0104 ComboBox { 0105 Kirigami.FormData.label: i18nc("@label:listbox", "Page Margins:") 0106 0107 textRole: "key" 0108 0109 currentIndex: { 0110 for (var i in model) { 0111 if (model[i].value == dialog.margin) { 0112 return i 0113 } 0114 } 0115 } 0116 0117 model: [ 0118 { value: 0, key: i18nc("@item:inlistbox", "None") }, 0119 { value: 1, key: i18nc("@item:inlistbox", "Small") }, 0120 { value: 2, key: i18nc("@item:inlistbox", "Large") } 0121 ] 0122 0123 onActivated: index => { 0124 dialog.margin = model[index].value; 0125 } 0126 } 0127 ComboBox { 0128 id: actionsCombobox 0129 Kirigami.FormData.label: i18nc("@label:listbox", "Use Actions From:") 0130 visible: count > 1 0131 textRole: "display" 0132 valueRole: "id" 0133 currentIndex:indexOfValue(dialog.actionsFace) 0134 model: KItemModels.KSortFilterProxyModel { 0135 sourceModel: FacesModel {id: facesModel} 0136 filterRowCallback: function(row, parent) { 0137 // No face option 0138 if (row == facesModel.rowCount() - 1) { 0139 return true 0140 } 0141 const face = facesModel.faceAtIndex(row) 0142 return face.primaryActions.length != 0 && face.secondaryActions.length != 0 0143 } 0144 } 0145 } 0146 ComboBox { 0147 Kirigami.FormData.label: i18nc("@label:listbox", "Load this page:") 0148 0149 textRole: "key" 0150 0151 currentIndex: { 0152 for (var i in model) { 0153 if (model[i].value == dialog.loadType) { 0154 return i 0155 } 0156 } 0157 } 0158 0159 model: [ 0160 { value: "ondemand", key: i18nc("@item:inlistbox", "When needed") }, 0161 { value: "onstart", key: i18nc("@item:inlistbox", "During application startup") } 0162 ] 0163 0164 onActivated: index => { 0165 dialog.loadType = model[index].value; 0166 } 0167 } 0168 } 0169 0170 KIconThemes.IconDialog { 0171 id: iconDialog 0172 iconSize: Kirigami.Units.iconSizes.smallMedium 0173 onIconNameChanged: dialog.iconName = iconName 0174 } 0175 }