Warning, /plasma/kdeplasma-addons/applets/quicklaunch/package/contents/ui/IconItem.qml is written in an unsupported language. File is not indexed.
0001 /* 0002 * SPDX-FileCopyrightText: 2015 David Rosca <nowrep@gmail.com> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0005 */ 0006 0007 import QtQuick 2.15 0008 import org.kde.plasma.core as PlasmaCore 0009 import org.kde.kirigami 2.20 as Kirigami 0010 import org.kde.ksvg 1.0 as KSvg 0011 import org.kde.plasma.components 3.0 as PlasmaComponents3 0012 import org.kde.plasma.plasmoid 2.0 0013 import org.kde.draganddrop 2.0 as DragAndDrop 0014 import org.kde.plasma.extras 2.0 as PlasmaExtras 0015 0016 import "layout.js" as LayoutManager 0017 0018 Item { 0019 id: iconItem 0020 0021 readonly property int itemIndex : index 0022 property bool dragging : false 0023 property bool isPopupItem : false 0024 readonly property var launcher : logic.launcherData(url) 0025 readonly property string iconName : launcher.iconName || "fork" 0026 0027 width: isPopupItem ? LayoutManager.popupItemWidth() : grid.cellWidth 0028 height: isPopupItem ? LayoutManager.popupItemHeight() : grid.cellHeight 0029 0030 Keys.onPressed: { 0031 switch (event.key) { 0032 case Qt.Key_Space: 0033 case Qt.Key_Enter: 0034 case Qt.Key_Return: 0035 case Qt.Key_Select: 0036 logic.openUrl(url); 0037 break; 0038 case Qt.Key_Menu: 0039 contextMenu.refreshActions(); 0040 contextMenu.open(0,0); 0041 event.accepted = true; 0042 break; 0043 case Qt.Key_Backspace: 0044 case Qt.Key_Delete: 0045 removeLauncher(); 0046 event.accepted = true; 0047 break; 0048 } 0049 0050 // BEGIN Arrow keys 0051 if (!(event.modifiers & Qt.ControlModifier) || !(event.modifiers & Qt.ShiftModifier)) { 0052 return; 0053 } 0054 0055 switch (event.key) { 0056 case Qt.Key_Up: { 0057 if (iconItem.isPopupItem && iconItem.itemIndex === 0 && Plasmoid.location === PlasmaCore.Types.TopEdge) { 0058 iconItem.ListView.view.moveItemToGrid(iconItem, url); 0059 break; 0060 } else if (!iconItem.isPopupItem && Plasmoid.location === PlasmaCore.Types.BottomEdge) { 0061 iconItem.GridView.view.moveItemToPopup(iconItem, url); 0062 break; 0063 } 0064 0065 decreaseIndex(); 0066 break; 0067 } 0068 0069 case Qt.Key_Down: { 0070 if (iconItem.isPopupItem && iconItem.itemIndex === iconItem.ListView.view.count - 1 && Plasmoid.location === PlasmaCore.Types.BottomEdge) { 0071 iconItem.ListView.view.moveItemToGrid(iconItem, url); 0072 break; 0073 } else if (!iconItem.isPopupItem && Plasmoid.location === PlasmaCore.Types.TopEdge) { 0074 iconItem.GridView.view.moveItemToPopup(iconItem, url); 0075 break; 0076 } 0077 0078 increaseIndex(); 0079 break; 0080 } 0081 0082 case Qt.Key_Left: { 0083 if (iconItem.isPopupItem && Plasmoid.location === PlasmaCore.Types.LeftEdge) { 0084 iconItem.ListView.view.moveItemToGrid(iconItem, url); 0085 break; 0086 } else if (!iconItem.isPopupItem && Plasmoid.location === PlasmaCore.Types.RightEdge) { 0087 iconItem.GridView.view.moveItemToPopup(iconItem, url); 0088 break; 0089 } 0090 0091 decreaseIndex(); 0092 break; 0093 } 0094 case Qt.Key_Right: { 0095 if (iconItem.isPopupItem && Plasmoid.location === PlasmaCore.Types.RightEdge) { 0096 iconItem.ListView.view.moveItemToGrid(iconItem, url); 0097 break; 0098 } else if (!iconItem.isPopupItem && Plasmoid.location === PlasmaCore.Types.LeftEdge) { 0099 iconItem.GridView.view.moveItemToPopup(iconItem, url); 0100 break; 0101 } 0102 0103 increaseIndex(); 0104 break; 0105 } 0106 default: 0107 return; 0108 } 0109 0110 event.accepted = true; 0111 // END Arrow keys 0112 } 0113 0114 function decreaseIndex() { 0115 const newIndex = iconItem.itemIndex - 1; 0116 if (newIndex < 0) { 0117 return; 0118 } 0119 if (iconItem.isPopupItem) { 0120 popupModel.moveUrl(iconItem.itemIndex, newIndex); 0121 iconItem.ListView.view.currentIndex = newIndex; 0122 } else { 0123 launcherModel.moveUrl(iconItem.itemIndex, newIndex); 0124 iconItem.GridView.view.currentIndex = newIndex; 0125 } 0126 } 0127 0128 function increaseIndex() { 0129 const newIndex = iconItem.itemIndex + 1; 0130 if (newIndex === (iconItem.isPopupItem ? iconItem.ListView.view.count : iconItem.GridView.view.count)) { 0131 return; 0132 } 0133 if (iconItem.isPopupItem) { 0134 popupModel.moveUrl(iconItem.itemIndex, newIndex); 0135 iconItem.ListView.view.currentIndex = newIndex; 0136 } else { 0137 launcherModel.moveUrl(iconItem.itemIndex, newIndex); 0138 iconItem.GridView.view.currentIndex = newIndex; 0139 } 0140 } 0141 0142 DragAndDrop.DragArea { 0143 id: dragArea 0144 width: Math.min(iconItem.width, iconItem.height) 0145 height: width 0146 enabled: !plasmoid.immutable 0147 defaultAction: Qt.MoveAction 0148 supportedActions: Qt.IgnoreAction | Qt.MoveAction 0149 delegate: icon 0150 0151 mimeData { 0152 url: url 0153 source: iconItem 0154 } 0155 0156 onDragStarted: { 0157 dragging = true; 0158 } 0159 0160 onDrop: { 0161 dragging = false; 0162 0163 if (action == Qt.MoveAction) { 0164 removeLauncher(); 0165 } 0166 } 0167 0168 MouseArea { 0169 id: mouseArea 0170 anchors.fill: parent 0171 anchors.margins: LayoutManager.itemPadding() 0172 hoverEnabled: true 0173 acceptedButtons: Qt.LeftButton | Qt.RightButton 0174 0175 activeFocusOnTab: true 0176 Accessible.name: iconItem.launcher.applicationName 0177 Accessible.description: i18n("Launch %1", iconItem.launcher.genericName || iconItem.launcher.applicationName) 0178 Accessible.role: Accessible.Button 0179 0180 onActiveFocusChanged: { 0181 if (activeFocus) { 0182 entered(); 0183 } 0184 } 0185 0186 onEntered: { 0187 if (iconItem.ListView.view) { 0188 iconItem.ListView.view.currentIndex = iconItem.itemIndex; 0189 } 0190 } 0191 0192 onPressed: { 0193 if (mouse.button == Qt.RightButton) { 0194 contextMenu.refreshActions(); 0195 contextMenu.open(mouse.x, mouse.y); 0196 } 0197 } 0198 0199 onClicked: { 0200 if (mouse.button == Qt.LeftButton) { 0201 logic.openUrl(url) 0202 } 0203 } 0204 0205 Kirigami.Icon { 0206 id: icon 0207 0208 anchors { 0209 top: parent.top 0210 left: parent.left 0211 } 0212 0213 width: Kirigami.Units.iconSizes.medium 0214 height: width 0215 source: url == "quicklaunch:drop" ? "" : iconName 0216 active: mouseArea.containsMouse 0217 } 0218 0219 PlasmaComponents3.Label { 0220 id: label 0221 0222 anchors { 0223 bottom : parent.bottom 0224 right : parent.right 0225 } 0226 0227 text: iconItem.launcher.applicationName 0228 textFormat: Text.PlainText 0229 maximumLineCount: 1 0230 wrapMode: Text.Wrap 0231 } 0232 0233 KSvg.FrameSvgItem { 0234 anchors.fill: parent 0235 imagePath: "widgets/viewitem" 0236 prefix: "hover" 0237 visible: dragging || url == "quicklaunch:drop" 0238 } 0239 0240 PlasmaCore.ToolTipArea { 0241 anchors.fill: parent 0242 active: !dragging 0243 mainText: iconItem.launcher.applicationName 0244 subText: iconItem.launcher.genericName 0245 icon: iconName 0246 } 0247 0248 PlasmaExtras.Menu { 0249 id: contextMenu 0250 0251 property var jumpListItems : [] 0252 0253 visualParent: mouseArea 0254 0255 PlasmaExtras.MenuItem { 0256 id: jumpListSeparator 0257 separator: true 0258 } 0259 0260 PlasmaExtras.MenuItem { 0261 text: i18nc("@action:inmenu", "Add Launcher…") 0262 icon: "list-add" 0263 onClicked: addLauncher() 0264 } 0265 0266 PlasmaExtras.MenuItem { 0267 text: i18nc("@action:inmenu", "Edit Launcher…") 0268 icon: "document-edit" 0269 onClicked: editLauncher() 0270 } 0271 0272 PlasmaExtras.MenuItem { 0273 text: i18nc("@action:inmenu", "Remove Launcher") 0274 icon: "list-remove" 0275 onClicked: removeLauncher() 0276 } 0277 0278 PlasmaExtras.MenuItem { 0279 separator: true 0280 } 0281 0282 PlasmaExtras.MenuItem { 0283 action: Plasmoid.internalAction("configure") 0284 } 0285 0286 PlasmaExtras.MenuItem { 0287 action: Plasmoid.internalAction("remove") 0288 } 0289 0290 function refreshActions() { 0291 for (var i = 0; i < jumpListItems.length; ++i) { 0292 var item = jumpListItems[i]; 0293 removeMenuItem(item); 0294 item.destroy(); 0295 } 0296 jumpListItems = []; 0297 0298 for (var i = 0; i < launcher.jumpListActions.length; ++i) { 0299 var action = launcher.jumpListActions[i]; 0300 var item = menuItemComponent.createObject(iconItem, { 0301 "text": action.name, 0302 "icon": action.icon 0303 }); 0304 item.clicked.connect(function() { 0305 logic.openExec(this.exec); 0306 }.bind(action)); 0307 0308 addMenuItem(item, jumpListSeparator); 0309 jumpListItems.push(item); 0310 } 0311 } 0312 } 0313 0314 Component { 0315 id: menuItemComponent 0316 PlasmaExtras.MenuItem { } 0317 } 0318 } 0319 } 0320 0321 states: [ 0322 State { 0323 name: "popup" 0324 when: isPopupItem 0325 0326 AnchorChanges { 0327 target: dragArea 0328 anchors.left: dragArea.parent.left 0329 anchors.right: dragArea.parent.right 0330 anchors.top: dragArea.parent.top 0331 anchors.bottom: dragArea.parent.bottom 0332 } 0333 0334 AnchorChanges { 0335 target: icon 0336 anchors.right: undefined 0337 anchors.bottom: undefined 0338 } 0339 0340 AnchorChanges { 0341 target: label 0342 anchors.top: label.parent.top 0343 anchors.left: icon.right 0344 } 0345 0346 PropertyChanges { 0347 target: label 0348 horizontalAlignment: Text.AlignHLeft 0349 visible: true 0350 elide: Text.ElideRight 0351 anchors.leftMargin: Kirigami.Units.smallSpacing 0352 anchors.rightMargin: Kirigami.Units.smallSpacing 0353 } 0354 }, 0355 0356 State { 0357 name: "grid" 0358 when: !isPopupItem 0359 0360 AnchorChanges { 0361 target: dragArea 0362 anchors.verticalCenter: dragArea.parent.verticalCenter 0363 anchors.horizontalCenter: dragArea.parent.horizontalCenter 0364 } 0365 0366 AnchorChanges { 0367 target: icon 0368 anchors.right: icon.parent.right 0369 anchors.bottom: label.visible ? label.top : icon.parent.bottom 0370 } 0371 0372 AnchorChanges { 0373 target: label 0374 anchors.top: undefined 0375 anchors.left: label.parent.left 0376 } 0377 0378 PropertyChanges { 0379 target: label 0380 horizontalAlignment: Text.AlignHCenter 0381 visible: showLauncherNames 0382 elide: Text.ElideNone 0383 } 0384 } 0385 ] 0386 0387 function addLauncher() 0388 { 0389 logic.addLauncher(isPopupItem); 0390 } 0391 0392 function editLauncher() 0393 { 0394 logic.editLauncher(url, itemIndex, isPopupItem); 0395 } 0396 0397 function removeLauncher() 0398 { 0399 var m = isPopupItem ? popupModel : launcherModel; 0400 m.removeUrl(itemIndex); 0401 } 0402 }