Warning, /plasma/plasma-simplemenu/package/contents/ui/ItemGridDelegate.qml is written in an unsupported language. File is not indexed.

0001 /*
0002     SPDX-FileCopyrightText: 2015 Eike Hein <hein@kde.org>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 import QtQuick 2.0
0008 
0009 import org.kde.plasma.plasmoid 2.0
0010 import org.kde.plasma.core 2.0 as PlasmaCore
0011 import org.kde.plasma.components 2.0 as PlasmaComponents
0012 import org.kde.kquickcontrolsaddons 2.0
0013 
0014 import "../code/tools.js" as Tools
0015 
0016 Item {
0017     id: item
0018 
0019     implicitWidth: GridView.view.cellWidth
0020     implicitHeight: GridView.view.cellHeight
0021 
0022     property bool showLabel: true
0023 
0024     readonly property int itemIndex: model.index
0025     readonly property url url: model.url != undefined ? model.url : ""
0026     property bool pressed: false
0027     readonly property bool hasActionList: ((model.favoriteId != null)
0028         || (("hasActionList" in model) && (model.hasActionList == true)))
0029 
0030     Accessible.role: Accessible.MenuItem
0031     Accessible.name: model.display
0032 
0033     function openActionMenu(x, y) {
0034         var actionList = hasActionList ? model.actionList : [];
0035         Tools.fillActionMenu(i18n, actionMenu, actionList, GridView.view.model.favoritesModel, model.favoriteId);
0036         actionMenu.visualParent = item;
0037         actionMenu.open(x, y);
0038     }
0039 
0040     function actionTriggered(actionId, actionArgument) {
0041         Tools.triggerAction(plasmoid, GridView.view.model, model.index, actionId, actionArgument);
0042     }
0043 
0044     PlasmaCore.IconItem {
0045         id: icon
0046 
0047         y: showLabel ? (2 * highlightItemSvg.margins.top) : 0
0048 
0049         anchors.horizontalCenter: parent.horizontalCenter
0050         anchors.verticalCenter: showLabel ? undefined : parent.verticalCenter
0051 
0052         width: iconSize
0053         height: width
0054 
0055         animated: false
0056         usesPlasmaTheme: item.GridView.view.usesPlasmaTheme
0057 
0058         source: model.decoration
0059     }
0060 
0061     PlasmaComponents.Label {
0062         id: label
0063 
0064         visible: showLabel
0065 
0066         anchors {
0067             top: icon.bottom
0068             topMargin: units.smallSpacing
0069             left: parent.left
0070             leftMargin: highlightItemSvg.margins.left
0071             right: parent.right
0072             rightMargin: highlightItemSvg.margins.right
0073         }
0074 
0075         horizontalAlignment: Text.AlignHCenter
0076 
0077         elide: Text.ElideRight
0078         wrapMode: Text.NoWrap
0079 
0080         text: model.display
0081     }
0082 
0083     Keys.onPressed: {
0084         if (event.key == Qt.Key_Menu && hasActionList) {
0085             event.accepted = true;
0086             openActionMenu(item);
0087         } else if ((event.key == Qt.Key_Enter || event.key == Qt.Key_Return)) {
0088             event.accepted = true;
0089             GridView.view.model.trigger(index, "", null);
0090 
0091             if ("toggle" in root) {
0092                 root.toggle();
0093             } else {
0094                 root.visible = false;
0095             }
0096         }
0097     }
0098 }