Warning, /plasma/kdeplasma-addons/applets/grouping/package/contents/ui/main.qml is written in an unsupported language. File is not indexed.
0001 /* 0002 * SPDX-FileCopyrightText: 2011 Marco Martin <mart@kde.org> 0003 * SPDX-FileCopyrightText: 2016 David Edmundson <davidedmundson@kde.org> 0004 * 0005 * SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 import QtQuick 2.15 0009 import QtQuick.Layouts 1.15 0010 0011 import org.kde.plasma.core as PlasmaCore 0012 import org.kde.kirigami 2.20 as Kirigami 0013 import org.kde.plasma.components 3.0 as PlasmaComponents 0014 import org.kde.plasma.plasmoid 2.0 0015 import org.kde.draganddrop 2.0 as DnD 0016 0017 import "items" 0018 0019 ContainmentItem { 0020 id: root 0021 0022 //be at least the same size as the system tray popup 0023 Layout.minimumWidth: Kirigami.Units.gridUnit * 24 0024 Layout.minimumHeight: Kirigami.Units.gridUnit * 21 0025 Layout.preferredWidth: Layout.minimumWidth 0026 Layout.preferredHeight: Layout.minimumHeight * 1.5 0027 0028 property Component plasmoidItemComponent 0029 0030 Containment.onAppletAdded: { 0031 addApplet(applet); 0032 //when we add an applet, select it straight away 0033 //we know it will always be at the end of the stack 0034 tabbar.currentIndex = mainStack.count -1; 0035 } 0036 Containment.onAppletRemoved: { 0037 for (var i = 0; i < mainStack.count; i++) { 0038 if (mainStack.children[i].itemId === applet.id) { 0039 mainStack.children[i].destroy(); 0040 break; 0041 } 0042 } 0043 } 0044 0045 function addApplet(applet) { 0046 const appletItem = root.itemFor(applet); 0047 0048 if (!plasmoidItemComponent) { 0049 plasmoidItemComponent = Qt.createComponent("items/PlasmoidItem.qml"); 0050 } 0051 0052 if (plasmoidItemComponent.status === Component.Error) { 0053 console.warn("Could not create PlasmoidItem", plasmoidItemComponent.errorString()); 0054 } 0055 0056 var plasmoidContainer = plasmoidItemComponent.createObject(mainStack, { "applet": appletItem }); 0057 0058 appletItem.anchors.fill = undefined; 0059 appletItem.parent = plasmoidContainer; 0060 appletItem.anchors.fill = plasmoidContainer; 0061 appletItem.visible = true; 0062 } 0063 0064 Component.onCompleted: { 0065 var applets = Containment.applets; 0066 for (var i = 0 ; i < applets.length; i++) { 0067 addApplet(applets[i]); 0068 } 0069 } 0070 0071 Item { 0072 anchors.fill: parent 0073 PlasmaComponents.TabBar { 0074 id: tabbar 0075 anchors.top: parent.top 0076 anchors.left: parent.left 0077 anchors.right: parent.right 0078 0079 LayoutMirroring.enabled: Qt.application.layoutDirection === Qt.RightToLeft 0080 LayoutMirroring.childrenInherit: true 0081 0082 Repeater { 0083 model: mainStack.children 0084 0085 //attached properties: 0086 // model == a QQmlDMObjectData wrapper round the PlasmoidItem 0087 // modelData == the PlasmoidItem instance 0088 PlasmaComponents.TabButton { 0089 text: model.text 0090 MouseArea { 0091 acceptedButtons: Qt.RightButton 0092 anchors.fill: parent 0093 onClicked: { 0094 modelData.clicked(mouse); 0095 } 0096 } 0097 } 0098 } 0099 //hack: PlasmaComponents.TabBar is being weird with heights. Probably a bug 0100 height: contentChildren[0] ? contentChildren[0].height : undefined 0101 } 0102 0103 StackLayout { 0104 id: mainStack 0105 currentIndex: tabbar.currentIndex 0106 anchors.top: tabbar.bottom 0107 anchors.left: parent.left 0108 anchors.right: parent.right 0109 anchors.bottom: parent.bottom 0110 } 0111 } 0112 0113 DnD.DropArea { 0114 anchors.fill: parent 0115 0116 preventStealing: true 0117 0118 /** Extracts the name of the applet in the drag data if present 0119 * otherwise returns null*/ 0120 function appletName(event) { 0121 if (event.mimeData.formats.indexOf("text/x-plasmoidservicename") < 0) { 0122 return null; 0123 } 0124 var plasmoidId = event.mimeData.getDataAsByteArray("text/x-plasmoidservicename"); 0125 return plasmoidId; 0126 } 0127 0128 onDragEnter: { 0129 if (!appletName(event)) { 0130 event.ignore(); 0131 } 0132 } 0133 0134 onDrop: { 0135 var plasmoidId = appletName(event); 0136 if (!plasmoidId) { 0137 event.ignore(); 0138 return; 0139 } 0140 plasmoid.newTask(plasmoidId); 0141 } 0142 } 0143 0144 PlasmaComponents.Label { 0145 anchors.fill: mainStack 0146 text: i18n("Drag applets here") 0147 textFormat: Text.PlainText 0148 visible: mainStack.count === 0 0149 elide: Text.ElideRight 0150 horizontalAlignment: Text.AlignHCenter 0151 verticalAlignment: Text.AlignVCenter 0152 } 0153 }