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 * 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 import org.kde.kitemmodels 1.0 as KItemModels 0013 import org.kde.kquickcontrolsaddons 2.0 as Addons 0014 0015 import org.kde.ksysguard.page 1.0 0016 0017 Dialog { 0018 id: dialog 0019 0020 property string acceptText: i18nc("@action:button", "Add") 0021 property string acceptIcon: "list-add" 0022 0023 property string name: i18nc("@info:placeholder", "New Page") 0024 property string iconName: "ksysguardd" 0025 property real margin: 2 0026 property string actionsFace: "dummy" //Can't leave it empty, otherwise it doesn't update when it's initially set to an empty string 0027 property alias pageData: facesModel.pageData 0028 0029 property string loadType: "ondemand" 0030 0031 modal: true 0032 parent: Overlay.overlay 0033 focus: true 0034 0035 x: parent ? Math.round(parent.width / 2 - width / 2) : 0 0036 y: ApplicationWindow.window ? ApplicationWindow.window.pageStack.globalToolBar.height - Kirigami.Units.smallSpacing : 0 0037 0038 leftPadding: 1 // Allow dialog background border to show 0039 rightPadding: 1 // Allow dialog background border to show 0040 bottomPadding: Kirigami.Units.smallSpacing 0041 topPadding: Kirigami.Units.smallSpacing 0042 bottomInset: -Kirigami.Units.smallSpacing 0043 0044 onAccepted: { 0045 actionsFace = actionsCombobox.currentValue 0046 } 0047 0048 onOpened: { 0049 // Reset focus to the name field. 0050 // When opening the dialog multiple times, the focus object remains the 0051 // last focussed item, which is usually one of the buttons. Since the 0052 // first things we generally want to do in this dialog is edit the 0053 // title, we reset the focus to the name field when the dialog is 0054 // opened. 0055 nameField.focus = true 0056 } 0057 0058 onClosed: { 0059 actionsFace = "dummy" //see above 0060 pageData = null 0061 } 0062 0063 contentItem: Rectangle { 0064 Kirigami.Theme.colorSet: Kirigami.Theme.View 0065 color: Kirigami.Theme.backgroundColor 0066 implicitWidth: Kirigami.Units.gridUnit * 20 0067 implicitHeight: form.implicitHeight + Kirigami.Units.largeSpacing 0068 0069 Kirigami.Separator { anchors { left: parent.left; right: parent.right; top: parent.top } } 0070 0071 Kirigami.FormLayout { 0072 id: form 0073 0074 anchors { 0075 top: parent.top 0076 left: parent.left 0077 right: parent.right 0078 leftMargin: Kirigami.Units.largeSpacing 0079 rightMargin: Kirigami.Units.largeSpacing 0080 } 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: dialog.margin = model[index].value 0124 } 0125 ComboBox { 0126 id: actionsCombobox 0127 Kirigami.FormData.label: i18nc("@label:listbox", "Use Actions From:") 0128 visible: count > 1 0129 textRole: "display" 0130 valueRole: "id" 0131 currentIndex:indexOfValue(dialog.actionsFace) 0132 model: KItemModels.KSortFilterProxyModel { 0133 sourceModel: FacesModel {id: facesModel} 0134 filterRowCallback: function(row, parent) { 0135 // No face option 0136 if (row == facesModel.rowCount() - 1) { 0137 return true 0138 } 0139 const face = facesModel.faceAtIndex(row) 0140 return face.primaryActions.length != 0 && face.secondaryActions.length != 0 0141 } 0142 } 0143 } 0144 ComboBox { 0145 Kirigami.FormData.label: i18nc("@label:listbox", "Load this page:") 0146 0147 textRole: "key" 0148 0149 currentIndex: { 0150 for (var i in model) { 0151 if (model[i].value == dialog.loadType) { 0152 return i 0153 } 0154 } 0155 } 0156 0157 model: [ 0158 { value: "ondemand", key: i18nc("@item:inlistbox", "When needed") }, 0159 { value: "onstart", key: i18nc("@item:inlistbox", "During application startup") } 0160 ] 0161 0162 onActivated: dialog.loadType = model[index].value 0163 } 0164 } 0165 0166 Kirigami.Separator { anchors { left: parent.left; right: parent.right; bottom: parent.bottom } } 0167 0168 Addons.IconDialog { 0169 id: iconDialog; 0170 iconSize: Kirigami.Units.iconSizes.smallMedium 0171 onIconNameChanged: dialog.iconName = iconName 0172 } 0173 } 0174 0175 footer: DialogButtonBox { 0176 Button { 0177 DialogButtonBox.buttonRole: DialogButtonBox.AcceptRole 0178 text: dialog.acceptText 0179 icon.name: dialog.acceptIcon 0180 enabled: nameField.acceptableInput 0181 } 0182 Button { 0183 DialogButtonBox.buttonRole: DialogButtonBox.RejectRole 0184 text: i18nc("@action:button", "Cancel") 0185 icon.name: "dialog-cancel" 0186 } 0187 } 0188 }