Warning, /plasma/plasma-desktop/desktoppackage/contents/explorer/AppletDelegate.qml is written in an unsupported language. File is not indexed.

0001 /*
0002     SPDX-FileCopyrightText: 2011 Marco Martin <mart@kde.org>
0003     SPDX-FileCopyrightText: 2015 Kai Uwe Broulik <kde@privat.broulik.de>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 
0008 import QtQuick 2.15
0009 import QtQuick.Layouts 1.1
0010 
0011 import org.kde.plasma.components 3.0 as PlasmaComponents
0012 import org.kde.plasma.core as PlasmaCore
0013 import org.kde.kwindowsystem
0014 import org.kde.kirigami 2.20 as Kirigami
0015 import org.kde.graphicaleffects as KGraphicalEffects
0016 
0017 Item {
0018     id: delegate
0019 
0020     readonly property string pluginName: model.pluginName
0021     readonly property bool pendingUninstall: pendingUninstallTimer.applets.indexOf(pluginName) > -1
0022     readonly property bool pressed: tapHandler.pressed
0023 
0024     width: list.cellWidth
0025     height: list.cellHeight
0026 
0027     HoverHandler {
0028         id: hoverHandler
0029         onHoveredChanged: if (hovered) delegate.GridView.view.currentIndex = index
0030     }
0031 
0032     TapHandler {
0033         id: tapHandler
0034         enabled: !delegate.pendingUninstall && model.isSupported
0035         onTapped: widgetExplorer.addApplet(delegate.pluginName)
0036     }
0037 
0038     PlasmaCore.ToolTipArea {
0039         anchors.fill: parent
0040         visible: !model.isSupported
0041         mainText: i18n("Unsupported Widget")
0042         subText: model.unsupportedMessage
0043     }
0044 
0045     // Avoid repositioning delegate item after dragFinished
0046     Item {
0047         anchors.fill: parent
0048         enabled: model.isSupported
0049 
0050         Drag.dragType: Drag.Automatic
0051         Drag.supportedActions: Qt.MoveAction | Qt.LinkAction
0052         Drag.mimeData: {
0053             "text/x-plasmoidservicename" : delegate.pluginName,
0054         }
0055         Drag.onDragStarted: {
0056             KWindowSystem.showingDesktop = true;
0057             main.draggingWidget = true;
0058         }
0059         Drag.onDragFinished: {
0060             main.draggingWidget = false;
0061         }
0062 
0063         DragHandler {
0064             id: dragHandler
0065             enabled: !delegate.pendingUninstall && model.isSupported
0066 
0067             onActiveChanged: if (active) {
0068                 iconContainer.grabToImage(function(result) {
0069                     if (!dragHandler.active) {
0070                         return;
0071                     }
0072                     parent.Drag.imageSource = result.url;
0073                     parent.Drag.active = dragHandler.active;
0074                 }, Qt.size(Kirigami.Units.iconSizes.huge, Kirigami.Units.iconSizes.huge));
0075             } else {
0076                 parent.Drag.active = false;
0077                 parent.Drag.imageSource = "";
0078             }
0079         }
0080     }
0081 
0082     ColumnLayout {
0083         id: mainLayout
0084 
0085         readonly property color textColor: tapHandler.pressed ? Kirigami.Theme.highlightedTextColor : Kirigami.Theme.textColor
0086 
0087         spacing: Kirigami.Units.smallSpacing
0088         anchors {
0089             left: parent.left
0090             right: parent.right
0091             //bottom: parent.bottom
0092             margins: Kirigami.Units.smallSpacing * 2
0093             rightMargin: Kirigami.Units.smallSpacing * 2 // don't cram the text to the border too much
0094             top: parent.top
0095         }
0096 
0097         Item {
0098             id: iconContainer
0099             width: Kirigami.Units.iconSizes.enormous
0100             height: width
0101             Layout.alignment: Qt.AlignHCenter
0102             opacity: delegate.pendingUninstall ? 0.6 : 1
0103             Behavior on opacity {
0104                 OpacityAnimator {
0105                     duration: Kirigami.Units.longDuration
0106                     easing.type: Easing.InOutQuad
0107                 }
0108             }
0109 
0110             Item {
0111                 id: iconWidget
0112                 anchors.fill: parent
0113                 Kirigami.Icon {
0114                     anchors.fill: parent
0115                     source: model.decoration
0116                     visible: model.screenshot === ""
0117                     selected: tapHandler.pressed
0118                     enabled: model.isSupported
0119                 }
0120                 Image {
0121                     width: Kirigami.Units.iconSizes.enormous
0122                     height: width
0123                     anchors.fill: parent
0124                     fillMode: Image.PreserveAspectFit
0125                     source: model.screenshot
0126                 }
0127             }
0128 
0129             Item {
0130                 id: badgeMask
0131                 anchors.fill: parent
0132 
0133                 Rectangle {
0134                     x: Math.round(-Kirigami.Units.smallSpacing * 1.5 / 2)
0135                     y: x
0136                     width: runningBadge.width + Math.round(Kirigami.Units.smallSpacing * 1.5)
0137                     height: width
0138                     radius: height
0139                     visible: running && delegate.GridView.isCurrentItem
0140                 }
0141             }
0142 
0143             KGraphicalEffects.BadgeEffect {
0144                 anchors.fill: parent
0145                 source: ShaderEffectSource {
0146                     sourceItem: iconWidget
0147                     hideSource: true
0148                     live: false
0149                 }
0150                 mask: ShaderEffectSource {
0151                     id: maskShaderSource
0152                     sourceItem: badgeMask
0153                     hideSource: true
0154                     live: false
0155                 }
0156             }
0157 
0158             Rectangle {
0159                 id: runningBadge
0160                 width: height
0161                 height: Math.round(Kirigami.Units.iconSizes.sizeForLabels * 1.3)
0162                 radius: height
0163                 color: Kirigami.Theme.highlightColor
0164                 visible: running && delegate.GridView.isCurrentItem
0165                 onVisibleChanged: maskShaderSource.scheduleUpdate()
0166 
0167                 PlasmaComponents.Label {
0168                     id: countLabel
0169                     anchors.fill: parent
0170                     horizontalAlignment: Text.AlignHCenter
0171                     verticalAlignment: Text.AlignVCenter
0172                     text: running
0173                     textFormat: Text.PlainText
0174                 }
0175             }
0176 
0177 
0178             PlasmaComponents.ToolButton {
0179                 id: uninstallButton
0180                 anchors {
0181                     top: parent.top
0182                     right: parent.right
0183                 }
0184                 icon.name: delegate.pendingUninstall ? "edit-undo" : "edit-delete"
0185                 // we don't really "undo" anything but we'll pretend to the user that we do
0186                 PlasmaComponents.ToolTip.delay: Kirigami.Units.toolTipDelay
0187                 PlasmaComponents.ToolTip.visible: hovered
0188                 PlasmaComponents.ToolTip.text: delegate.pendingUninstall ? i18nd("plasma_shell_org.kde.plasma.desktop", "Undo uninstall")
0189                                                     : i18nd("plasma_shell_org.kde.plasma.desktop", "Uninstall widget")
0190                 flat: false
0191                 visible: model.local && delegate.GridView.isCurrentItem && !dragHandler.active
0192 
0193                 onHoveredChanged: {
0194                     if (hovered) {
0195                         // hovering the uninstall button triggers onExited of the main mousearea
0196                         delegate.GridView.view.currentIndex = index
0197                     }
0198                 }
0199 
0200                 onClicked: {
0201                     var pending = pendingUninstallTimer.applets
0202                     if (delegate.pendingUninstall) {
0203                         var index = pending.indexOf(pluginName)
0204                         if (index > -1) {
0205                             pending.splice(index, 1)
0206                         }
0207                     } else {
0208                         pending.push(pluginName)
0209                     }
0210                     pendingUninstallTimer.applets = pending
0211 
0212                     if (pending.length) {
0213                         pendingUninstallTimer.restart()
0214                     } else {
0215                         pendingUninstallTimer.stop()
0216                     }
0217                 }
0218             }
0219         }
0220         Kirigami.Heading {
0221             id: heading
0222             Layout.fillWidth: true
0223             level: 4
0224             text: model.name
0225             textFormat: Text.PlainText
0226             elide: Text.ElideRight
0227             wrapMode: Text.WordWrap
0228             maximumLineCount: 2
0229             lineHeight: 0.95
0230             horizontalAlignment: Text.AlignHCenter
0231             color: mainLayout.textColor
0232         }
0233         PlasmaComponents.Label {
0234             Layout.fillWidth: true
0235             // otherwise causes binding loop due to the way the Plasma sets the height
0236             height: implicitHeight
0237             text: model.description
0238             textFormat: Text.PlainText
0239             font: Kirigami.Theme.smallFont
0240             wrapMode: Text.WordWrap
0241             elide: Text.ElideRight
0242             maximumLineCount: heading.lineCount === 1 ? 3 : 2
0243             horizontalAlignment: Text.AlignHCenter
0244             color: mainLayout.textColor
0245         }
0246     }
0247 }