Warning, /plasma/plasma-desktop/applets/kimpanel/package/contents/ui/main.qml is written in an unsupported language. File is not indexed.
0001 /* 0002 SPDX-FileCopyrightText: 2014 Weng Xuetian <wengxt@gmail.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 import QtQuick 2.15 0008 import QtQuick.Layouts 1.1 0009 import org.kde.plasma.plasmoid 2.0 0010 import org.kde.plasma.core as PlasmaCore 0011 import org.kde.kquickcontrolsaddons 2.0 0012 import org.kde.plasma.private.kimpanel 0.1 as Kimpanel 0013 import org.kde.kirigami 2.20 as Kirigami 0014 import org.kde.plasma.plasmoid 2.0 0015 0016 PlasmoidItem { 0017 id: kimpanel 0018 0019 property int visibleButtons: 0 0020 readonly property bool vertical: Plasmoid.formFactor === PlasmaCore.Types.Vertical 0021 0022 LayoutMirroring.enabled: !vertical && Qt.application.layoutDirection === Qt.RightToLeft 0023 LayoutMirroring.childrenInherit: true 0024 0025 Layout.minimumWidth: vertical ? Kirigami.Units.iconSizes.small : mainLayout.implicitWidth 0026 Layout.minimumHeight: vertical ? mainLayout.implicitHeight : Kirigami.Units.iconSizes.small 0027 Layout.preferredWidth: vertical ? kimpanel.width : mainLayout.implicitWidth 0028 Layout.preferredHeight: !vertical ? kimpanel.height : mainLayout.implicitHeight 0029 0030 preferredRepresentation:fullRepresentation 0031 0032 Component.onCompleted: { 0033 timer.restart(); 0034 } 0035 0036 InputPanel { } 0037 0038 GridLayout { 0039 id: mainLayout 0040 0041 rowSpacing: 0 0042 columnSpacing: 0 0043 anchors.fill: parent 0044 0045 GridView { 0046 id: items 0047 0048 Layout.alignment: Qt.AlignCenter 0049 0050 interactive: false 0051 flow: kimpanel.vertical ? GridView.FlowLeftToRight : GridView.FlowTopToBottom 0052 0053 // The icon size to display when not using the auto-scaling setting 0054 readonly property int smallIconSize: Kirigami.Units.iconSizes.smallMedium 0055 readonly property bool autoSize: Plasmoid.configuration.scaleIconsToFit 0056 0057 readonly property int gridThickness: kimpanel.vertical ? kimpanel.width : kimpanel.height 0058 // Should change to 2 rows/columns on a 56px panel (in standard DPI) 0059 readonly property int rowsOrColumns: autoSize ? 1 : Math.max(1, Math.min(count, Math.floor(gridThickness / smallSizeCellLength))) 0060 0061 // Add margins only if the panel is larger than a small icon (to avoid large gaps between tiny icons) 0062 readonly property int smallSizeCellLength: gridThickness < smallIconSize ? gridThickness : smallIconSize + Kirigami.Units.smallSpacing 0063 cellHeight: { 0064 if (kimpanel.vertical) { 0065 return autoSize ? kimpanel.width : smallSizeCellLength 0066 } else { 0067 return autoSize ? kimpanel.height : Math.floor(kimpanel.height / rowsOrColumns) 0068 } 0069 } 0070 cellWidth: { 0071 if (kimpanel.vertical) { 0072 return autoSize ? kimpanel.width : Math.floor(kimpanel.width / rowsOrColumns) 0073 } else { 0074 return autoSize ? kimpanel.height : smallSizeCellLength 0075 } 0076 } 0077 0078 //depending on the form factor, we are calculating only one dimension, second is always the same as root/parent 0079 implicitHeight: kimpanel.vertical ? cellHeight * Math.ceil(count / rowsOrColumns) : kimpanel.height 0080 implicitWidth: !kimpanel.vertical ? cellWidth * Math.ceil(count / rowsOrColumns) : kimpanel.width 0081 0082 readonly property int iconSize: { 0083 var size; 0084 if (autoSize) { 0085 size = Math.min(implicitWidth / rowsOrColumns, implicitHeight / rowsOrColumns) 0086 } else { 0087 size = Math.min(gridThickness, smallIconSize) 0088 } 0089 return Kirigami.Units.iconSizes.roundedIconSize(Math.min(size, Kirigami.Units.iconSizes.enormous)) 0090 } 0091 0092 model: ListModel { 0093 id: list 0094 dynamicRoles: true 0095 } 0096 0097 delegate: Item { 0098 width: items.cellWidth 0099 height: items.cellHeight 0100 0101 activeFocusOnTab: true 0102 0103 Keys.onPressed: { 0104 switch (event.key) { 0105 case Qt.Key_Space: 0106 case Qt.Key_Enter: 0107 case Qt.Key_Return: 0108 case Qt.Key_Select: 0109 statusIcon.triggered(Qt.LeftButton); 0110 break; 0111 case Qt.Key_Menu: 0112 statusIcon.triggered(Qt.RightButton); 0113 break; 0114 } 0115 } 0116 Accessible.name: statusIcon.label 0117 Accessible.description: statusIcon.tip 0118 Accessible.role: Accessible.Button 0119 0120 StatusIcon { 0121 id: statusIcon 0122 anchors.centerIn: parent 0123 Layout.alignment: Qt.AlignCenter 0124 0125 width: items.iconSize 0126 height: items.iconSize 0127 label: model.label 0128 tip: model.tip 0129 icon: model.icon 0130 hint: model.hint 0131 0132 onTriggered : { 0133 if (button === Qt.LeftButton) { 0134 if (model.key == 'kimpanel-placeholder') { 0135 return; 0136 } 0137 helper.triggerProperty(model.key); 0138 actionMenu.visualParent = statusIcon; 0139 } else { 0140 contextMenu.open(statusIcon, {key: model.key, label: model.label}); 0141 } 0142 } 0143 } 0144 } 0145 } 0146 } 0147 0148 function hideAction(key) { 0149 // We must use assignment to change the configuration property, 0150 // otherwise it won't get notified. 0151 var hiddenList = Plasmoid.configuration.hiddenList; 0152 if (hiddenList.indexOf(key) === -1) { 0153 hiddenList.push(key); 0154 Plasmoid.configuration.hiddenList = hiddenList; 0155 } 0156 timer.restart(); 0157 } 0158 0159 function showAction(key) { 0160 // We must use assignment to change the configuration property, 0161 // otherwise it won't get notified. 0162 var hiddenList = Plasmoid.configuration.hiddenList; 0163 var index = hiddenList.indexOf(key); 0164 if (index !== -1) { 0165 hiddenList.splice(index, 1); 0166 Plasmoid.configuration.hiddenList = hiddenList; 0167 } 0168 timer.restart(); 0169 } 0170 0171 function showMenu(menu, menuData) { 0172 var actionList = []; 0173 for (var i = 0; i < menuData.length; i++ ) { 0174 actionList.push({"actionId": menuData[i].key, "icon": menuData[i].icon, "text": menuData[i].label, hint: menuData[i].hint}); 0175 } 0176 if (actionList.length > 0) { 0177 menu.actionList = actionList; 0178 menu.open(); 0179 } 0180 } 0181 0182 ActionMenu { 0183 id: actionMenu 0184 onActionClicked: { 0185 helper.triggerProperty(actionId); 0186 } 0187 } 0188 0189 ContextMenu { 0190 id: contextMenu 0191 } 0192 0193 Timer { 0194 id: timer 0195 interval: 50 0196 onTriggered: { 0197 var data = helper.properties; 0198 var nodata = data.length == 0; 0199 var count = list.count; 0200 var c = 0, i; 0201 var hiddenActions = []; 0202 for (i = 0; i < data.length; i ++) { 0203 if (Plasmoid.configuration.hiddenList.indexOf(data[i].key) !== -1) { 0204 hiddenActions.push({'key': data[i].key, 0205 'icon': data[i].icon, 0206 'label': data[i].label}); 0207 } else { 0208 c = c + 1; 0209 } 0210 } 0211 if (c < count) { 0212 list.remove(c, count - c); 0213 } 0214 kimpanel.visibleButtons = c; 0215 0216 c = 0; 0217 for (i = 0; i < data.length; i ++) { 0218 if (Plasmoid.configuration.hiddenList.indexOf(data[i].key) !== -1) { 0219 continue; 0220 } 0221 var itemData = {'key': data[i].key, 0222 'icon': data[i].icon, 0223 'label': data[i].label, 0224 'tip': data[i].tip, 0225 'hint': data[i].hint }; 0226 if (c < count) { 0227 list.set(c, itemData); 0228 } else { 0229 list.append(itemData); 0230 } 0231 c = c + 1; 0232 } 0233 contextMenu.actionList = hiddenActions; 0234 0235 // Add a place holder if there is nothing. 0236 if (list.count == 0 && !nodata) { 0237 var itemData = {'key': 'kimpanel-placeholder', 0238 'icon': 'draw-freehand', 0239 'label': i18n("Input Method Panel"), 0240 'tip': '', 0241 'hint': ''}; 0242 list.append(itemData); 0243 } 0244 } 0245 } 0246 0247 Kimpanel.Kimpanel { 0248 id: helper 0249 } 0250 0251 Connections { 0252 target: helper 0253 function onPropertiesChanged() { 0254 timer.restart(); 0255 } 0256 function onMenuTriggered(menu) { 0257 showMenu(actionMenu, menu); 0258 } 0259 } 0260 } 0261