Warning, /plasma/latte-dock/shell/package/contents/views/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     SPDX-FileCopyrightText: 2021 Michail Vourlakos <mvourlakos@gmail.com>
0005 
0006     SPDX-License-Identifier: LGPL-2.0-or-later
0007 */
0008 
0009 import QtQuick 2.4
0010 import QtQuick.Layouts 1.1
0011 
0012 import org.kde.plasma.components 2.0 as PlasmaComponents
0013 import org.kde.plasma.extras 2.0 as PlasmaExtras
0014 import org.kde.plasma.core 2.0 as PlasmaCore
0015 import org.kde.draganddrop 2.0
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 
0023     width: list.cellWidth
0024     height: list.cellHeight
0025 
0026     DragArea {
0027         anchors.fill: parent
0028         supportedActions: Qt.MoveAction | Qt.LinkAction
0029         //onDragStarted: tooltipDialog.visible = false
0030         delegateImage: decoration
0031         enabled: !delegate.pendingUninstall
0032         mimeData {
0033             source: parent
0034         }
0035         Component.onCompleted: mimeData.setData("text/x-plasmoidservicename", pluginName)
0036 
0037         onDragStarted: {
0038             kwindowsystem.showingDesktop = true;
0039             main.draggingWidget = true;
0040         }
0041         onDrop: {
0042             main.draggingWidget = false;
0043         }
0044 
0045         MouseArea {
0046             id: mouseArea
0047             anchors.fill: parent
0048             hoverEnabled: true
0049             onDoubleClicked: {
0050                 if (!delegate.pendingUninstall) {
0051                     widgetExplorer.addApplet(pluginName);
0052                     latteView.extendedInterface.appletCreated(pluginName);
0053                 }
0054             }
0055             onEntered: delegate.GridView.view.currentIndex = index
0056             onExited: delegate.GridView.view.currentIndex = - 1
0057         }
0058 
0059         ColumnLayout {
0060             id: mainLayout
0061             spacing: units.smallSpacing
0062             anchors {
0063                 left: parent.left
0064                 right: parent.right
0065                 //bottom: parent.bottom
0066                 margins: units.smallSpacing * 2
0067                 rightMargin: units.smallSpacing * 2 // don't cram the text to the border too much
0068                 top: parent.top
0069             }
0070 
0071             Item {
0072                 id: iconContainer
0073                 width: units.iconSizes.enormous
0074                 height: width
0075                 Layout.alignment: Qt.AlignHCenter
0076                 opacity: delegate.pendingUninstall ? 0.6 : 1
0077                 Behavior on opacity {
0078                     OpacityAnimator {
0079                         duration: units.longDuration
0080                         easing.type: Easing.InOutQuad
0081                     }
0082                 }
0083 
0084                 Item {
0085                     id: iconWidget
0086                     anchors.fill: parent
0087                     PlasmaCore.IconItem {
0088                         anchors.fill: parent
0089                         source: model.decoration
0090                         visible: model.screenshot === ""
0091                     }
0092                     Image {
0093                         width: units.iconSizes.enormous
0094                         height: width
0095                         anchors.fill: parent
0096                         fillMode: Image.PreserveAspectFit
0097                         source: model.screenshot
0098                     }
0099                 }
0100 
0101                 Item {
0102                     id: badgeMask
0103                     anchors.fill: parent
0104 
0105                     Rectangle {
0106                         x: Math.round(-units.smallSpacing * 1.5 / 2)
0107                         y: x
0108                         width: runningBadge.width + Math.round(units.smallSpacing * 1.5)
0109                         height: width
0110                         radius: height
0111                         visible: running && delegate.GridView.isCurrentItem
0112                     }
0113                 }
0114 
0115                 Rectangle {
0116                     id: runningBadge
0117                     width: height
0118                     height: Math.round(theme.mSize(countLabel.font).height * 1.3)
0119                     radius: height
0120                     color: theme.highlightColor
0121                     visible: running && delegate.GridView.isCurrentItem
0122                     onVisibleChanged: maskShaderSource.scheduleUpdate()
0123 
0124                     PlasmaComponents.Label {
0125                         id: countLabel
0126                         anchors.fill: parent
0127                         horizontalAlignment: Text.AlignHCenter
0128                         verticalAlignment: Text.AlignVCenter
0129                         text: running
0130                     }
0131                 }
0132 
0133                 ShaderEffect {
0134                     anchors.fill: parent
0135                     property var source: ShaderEffectSource {
0136                         sourceItem: iconWidget
0137                         hideSource: true
0138                         live: false
0139                     }
0140                     property var mask: ShaderEffectSource {
0141                         id: maskShaderSource
0142                         sourceItem: badgeMask
0143                         hideSource: true
0144                         live: false
0145                     }
0146 
0147                     supportsAtlasTextures: true
0148 
0149                     fragmentShader: "
0150                         varying highp vec2 qt_TexCoord0;
0151                         uniform highp float qt_Opacity;
0152                         uniform lowp sampler2D source;
0153                         uniform lowp sampler2D mask;
0154                         void main() {
0155                             gl_FragColor = texture2D(source, qt_TexCoord0.st) * (1.0 - (texture2D(mask, qt_TexCoord0.st).a)) * qt_Opacity;
0156                         }
0157                     "
0158                 }
0159 
0160                 PlasmaComponents.ToolButton {
0161                     id: uninstallButton
0162                     anchors {
0163                         top: parent.top
0164                         right: parent.right
0165                     }
0166                     iconSource: delegate.pendingUninstall ? "edit-undo" : "edit-delete"
0167                     // we don't really "undo" anything but we'll pretend to the user that we do
0168                     tooltip: delegate.pendingUninstall ? i18nd("plasma_shell_org.kde.plasma.desktop", "Undo uninstall")
0169                                                        : i18nd("plasma_shell_org.kde.plasma.desktop", "Uninstall widget")
0170                     flat: false
0171                     visible: model.local && delegate.GridView.isCurrentItem
0172 
0173                     onHoveredChanged: {
0174                         if (hovered) {
0175                             // hovering the uninstall button triggers onExited of the main mousearea
0176                             delegate.GridView.view.currentIndex = index
0177                         }
0178                     }
0179 
0180                     onClicked: {
0181                         var pending = pendingUninstallTimer.applets
0182                         if (delegate.pendingUninstall) {
0183                             var index = pending.indexOf(pluginName)
0184                             if (index > -1) {
0185                                 pending.splice(index, 1)
0186                             }
0187                         } else {
0188                             pending.push(pluginName)
0189                         }
0190                         pendingUninstallTimer.applets = pending
0191 
0192                         if (pending.length) {
0193                             pendingUninstallTimer.restart()
0194                         } else {
0195                             pendingUninstallTimer.stop()
0196                         }
0197                     }
0198                 }
0199             }
0200             PlasmaExtras.Heading {
0201                 id: heading
0202                 Layout.fillWidth: true
0203                 level: 4
0204                 text: model.name
0205                 elide: Text.ElideRight
0206                 wrapMode: Text.WordWrap
0207                 maximumLineCount: 2
0208                 lineHeight: 0.95
0209                 horizontalAlignment: Text.AlignHCenter
0210             }
0211             PlasmaComponents.Label {
0212                 Layout.fillWidth: true
0213                 // otherwise causes binding loop due to the way the Plasma sets the height
0214                 height: implicitHeight
0215                 text: model.description
0216                 font: theme.smallestFont
0217                 wrapMode: Text.WordWrap
0218                 elide: Text.ElideRight
0219                 maximumLineCount: heading.lineCount === 1 ? 3 : 2
0220                 horizontalAlignment: Text.AlignHCenter
0221             }
0222         }
0223     }
0224 }