Warning, /plasma/plasma-workspace/applets/systemtray/package/contents/ui/ConfigEntries.qml is written in an unsupported language. File is not indexed.
0001 /* 0002 SPDX-FileCopyrightText: 2013 Sebastian Kügler <sebas@kde.org> 0003 SPDX-FileCopyrightText: 2014 Marco Martin <mart@kde.org> 0004 SPDX-FileCopyrightText: 2019 Konrad Materka <materka@gmail.com> 0005 SPDX-FileCopyrightText: 2022 ivan (@ratijas) tkachenko <me@ratijas.tk> 0006 0007 SPDX-License-Identifier: GPL-2.0-or-later 0008 */ 0009 0010 import QtQuick 2.15 0011 import QtQuick.Controls as QQC2 0012 import QtQuick.Layouts 1.3 0013 0014 import org.kde.plasma.plasmoid 2.0 0015 import org.kde.kquickcontrols 2.0 as KQC 0016 import org.kde.kirigami 2.10 as Kirigami 0017 import org.kde.kitemmodels 1.0 0018 import org.kde.kcmutils as KCM 0019 0020 KCM.ScrollViewKCM { 0021 id: iconsPage 0022 0023 signal configurationChanged 0024 0025 property var cfg_shownItems: [] 0026 property var cfg_hiddenItems: [] 0027 property var cfg_extraItems: [] 0028 property alias cfg_showAllItems: showAllCheckBox.checked 0029 0030 function categoryName(category) { 0031 switch (category) { 0032 case "ApplicationStatus": 0033 return i18n("Application Status") 0034 case "Communications": 0035 return i18n("Communications") 0036 case "SystemServices": 0037 return i18n("System Services") 0038 case "Hardware": 0039 return i18n("Hardware Control") 0040 case "UnknownCategory": 0041 default: 0042 return i18n("Miscellaneous") 0043 } 0044 } 0045 0046 header: Kirigami.SearchField { 0047 id: filterField 0048 } 0049 0050 view: ListView { 0051 id: itemsList 0052 0053 property real visibilityColumnWidth: Kirigami.Units.gridUnit 0054 property real keySequenceColumnWidth: Kirigami.Units.gridUnit 0055 readonly property int iconSize: Kirigami.Units.iconSizes.smallMedium 0056 0057 clip: true 0058 0059 model: KSortFilterProxyModel { 0060 sourceModel: Plasmoid.configSystemTrayModel 0061 filterString: filterField.text 0062 filterCaseSensitivity: Qt.CaseInsensitive 0063 } 0064 reuseItems: true 0065 0066 header: RowLayout { 0067 width: itemsList.width 0068 spacing: Kirigami.Units.smallSpacing 0069 0070 Item { 0071 implicitWidth: itemsList.iconSize + 2 * Kirigami.Units.smallSpacing 0072 } 0073 Kirigami.Heading { 0074 text: i18nc("Name of the system tray entry", "Entry") 0075 textFormat: Text.PlainText 0076 level: 2 0077 elide: Text.ElideRight 0078 Layout.fillWidth: true 0079 } 0080 Kirigami.Heading { 0081 text: i18n("Visibility") 0082 textFormat: Text.PlainText 0083 level: 2 0084 Layout.preferredWidth: itemsList.visibilityColumnWidth 0085 Component.onCompleted: itemsList.visibilityColumnWidth = Math.max(implicitWidth, itemsList.visibilityColumnWidth) 0086 } 0087 Kirigami.Heading { 0088 text: i18n("Keyboard Shortcut") 0089 textFormat: Text.PlainText 0090 level: 2 0091 Layout.preferredWidth: itemsList.keySequenceColumnWidth 0092 Component.onCompleted: itemsList.keySequenceColumnWidth = Math.max(implicitWidth, itemsList.keySequenceColumnWidth) 0093 } 0094 QQC2.Button { // Configure button column 0095 icon.name: "configure" 0096 enabled: false 0097 opacity: 0 0098 Layout.rightMargin: 2 * Kirigami.Units.smallSpacing 0099 } 0100 } 0101 0102 section { 0103 property: "category" 0104 delegate: Kirigami.ListSectionHeader { 0105 label: categoryName(section) 0106 width: itemsList.width 0107 } 0108 } 0109 0110 delegate: QQC2.ItemDelegate { 0111 id: listItem 0112 0113 width: itemsList.width 0114 0115 // Don't need highlight, hover, or pressed effects 0116 highlighted: false 0117 hoverEnabled: false 0118 down: false 0119 0120 readonly property bool isPlasmoid: model.itemType === "Plasmoid" 0121 0122 contentItem: FocusScope { 0123 implicitHeight: childrenRect.height 0124 0125 onActiveFocusChanged: if (activeFocus) { 0126 listItem.ListView.view.positionViewAtIndex(index, ListView.Contain); 0127 } 0128 0129 RowLayout { 0130 width: parent.width 0131 spacing: Kirigami.Units.smallSpacing 0132 0133 Kirigami.Icon { 0134 implicitWidth: itemsList.iconSize 0135 implicitHeight: itemsList.iconSize 0136 source: model.decoration 0137 animated: false 0138 } 0139 0140 QQC2.Label { 0141 Layout.fillWidth: true 0142 text: model.display 0143 textFormat: Text.PlainText 0144 elide: Text.ElideRight 0145 0146 QQC2.ToolTip { 0147 visible: listItem.hovered && parent.truncated 0148 text: parent.text 0149 } 0150 } 0151 0152 QQC2.ComboBox { 0153 id: visibilityComboBox 0154 0155 property real contentWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset, 0156 implicitContentWidth + leftPadding + rightPadding) 0157 implicitWidth: Math.max(contentWidth, itemsList.visibilityColumnWidth) 0158 Component.onCompleted: itemsList.visibilityColumnWidth = Math.max(implicitWidth, itemsList.visibilityColumnWidth) 0159 0160 enabled: (!showAllCheckBox.checked || isPlasmoid) && itemId 0161 textRole: "text" 0162 valueRole: "value" 0163 model: comboBoxModel() 0164 0165 currentIndex: { 0166 let value 0167 0168 if (cfg_shownItems.indexOf(itemId) !== -1) { 0169 value = "shown" 0170 } else if (cfg_hiddenItems.indexOf(itemId) !== -1) { 0171 value = "hidden" 0172 } else if (isPlasmoid && cfg_extraItems.indexOf(itemId) === -1) { 0173 value = "disabled" 0174 } else { 0175 value = "auto" 0176 } 0177 0178 for (let i = 0; i < model.length; i++) { 0179 if (model[i].value === value) { 0180 return i 0181 } 0182 } 0183 0184 return 0 0185 } 0186 0187 onActivated: { 0188 const shownIndex = cfg_shownItems.indexOf(itemId) 0189 const hiddenIndex = cfg_hiddenItems.indexOf(itemId) 0190 const extraIndex = cfg_extraItems.indexOf(itemId) 0191 0192 switch (currentValue) { 0193 case "auto": 0194 if (shownIndex > -1) { 0195 cfg_shownItems.splice(shownIndex, 1) 0196 } 0197 if (hiddenIndex > -1) { 0198 cfg_hiddenItems.splice(hiddenIndex, 1) 0199 } 0200 if (extraIndex === -1) { 0201 cfg_extraItems.push(itemId) 0202 } 0203 break 0204 case "shown": 0205 if (shownIndex === -1) { 0206 cfg_shownItems.push(itemId) 0207 } 0208 if (hiddenIndex > -1) { 0209 cfg_hiddenItems.splice(hiddenIndex, 1) 0210 } 0211 if (extraIndex === -1) { 0212 cfg_extraItems.push(itemId) 0213 } 0214 break 0215 case "hidden": 0216 if (shownIndex > -1) { 0217 cfg_shownItems.splice(shownIndex, 1) 0218 } 0219 if (hiddenIndex === -1) { 0220 cfg_hiddenItems.push(itemId) 0221 } 0222 if (extraIndex === -1) { 0223 cfg_extraItems.push(itemId) 0224 } 0225 break 0226 case "disabled": 0227 if (shownIndex > -1) { 0228 cfg_shownItems.splice(shownIndex, 1) 0229 } 0230 if (hiddenIndex > -1) { 0231 cfg_hiddenItems.splice(hiddenIndex, 1) 0232 } 0233 if (extraIndex > -1) { 0234 cfg_extraItems.splice(extraIndex, 1) 0235 } 0236 break 0237 } 0238 iconsPage.configurationChanged() 0239 } 0240 0241 function comboBoxModel() { 0242 const autoElement = {"value": "auto", "text": i18n("Shown when relevant")} 0243 const shownElement = {"value": "shown", "text": i18n("Always shown")} 0244 const hiddenElement = {"value": "hidden", "text": i18n("Always hidden")} 0245 const disabledElement = {"value": "disabled", "text": i18n("Disabled")} 0246 0247 if (showAllCheckBox.checked) { 0248 if (isPlasmoid) { 0249 return [autoElement, disabledElement] 0250 } else { 0251 return [shownElement] 0252 } 0253 } else { 0254 if (isPlasmoid) { 0255 return [autoElement, shownElement, hiddenElement, disabledElement] 0256 } else { 0257 return [autoElement, shownElement, hiddenElement] 0258 } 0259 } 0260 } 0261 } 0262 KQC.KeySequenceItem { 0263 id: keySequenceItem 0264 Layout.minimumWidth: itemsList.keySequenceColumnWidth 0265 Layout.preferredWidth: itemsList.keySequenceColumnWidth 0266 Component.onCompleted: itemsList.keySequenceColumnWidth = Math.max(implicitWidth, itemsList.keySequenceColumnWidth) 0267 0268 visible: isPlasmoid 0269 enabled: visibilityComboBox.currentValue !== "disabled" 0270 keySequence: model.applet ? model.applet.plasmoid.globalShortcut : "" 0271 onCaptureFinished: { 0272 if (model.applet && keySequence !== model.applet.plasmoid.globalShortcut) { 0273 model.applet.plasmoid.globalShortcut = keySequence 0274 0275 itemsList.keySequenceColumnWidth = Math.max(implicitWidth, itemsList.keySequenceColumnWidth) 0276 } 0277 } 0278 } 0279 // Placeholder for when KeySequenceItem is not visible 0280 Item { 0281 Layout.minimumWidth: itemsList.keySequenceColumnWidth 0282 Layout.maximumWidth: itemsList.keySequenceColumnWidth 0283 visible: !keySequenceItem.visible 0284 } 0285 0286 QQC2.Button { 0287 readonly property QtObject configureAction: (model.applet && model.applet.plasmoid.internalAction("configure")) || null 0288 0289 Accessible.name: configureAction ? configureAction.text : "" 0290 icon.name: "configure" 0291 enabled: configureAction && configureAction.visible && configureAction.enabled 0292 // Still reserve layout space, so not setting visible to false 0293 opacity: enabled ? 1 : 0 0294 onClicked: configureAction.trigger() 0295 0296 QQC2.ToolTip { 0297 // Strip out ampersands right before non-whitespace characters, i.e. 0298 // those used to determine the alt key shortcut 0299 text: parent.Accessible.name.replace(/&(?=\S)/g, "") 0300 } 0301 } 0302 } 0303 } 0304 } 0305 } 0306 0307 footer: QQC2.CheckBox { 0308 id: showAllCheckBox 0309 text: i18n("Always show all entries") 0310 Layout.alignment: Qt.AlignVCenter 0311 } 0312 }