/*SPDX-FileCopyrightText: 2011 Marco Martin <mart@kde.org>SPDX-FileCopyrightText: 2015 Kai Uwe Broulik <kde@privat.broulik.de>SPDX-License-Identifier: LGPL-2.0-or-later*/import QtQuickimport QtQuick.Layoutsimport org.kde.plasma.components as PlasmaComponentsimport org.kde.plasma.core as PlasmaCoreimport org.kde.kwindowsystemimport org.kde.kirigami as Kirigamiimport org.kde.graphicaleffects as KGraphicalEffectsItem {id: delegatereadonly property string pluginName: model.pluginNamereadonly property bool pendingUninstall: pendingUninstallTimer.applets.indexOf(pluginName) > -1readonly property bool pressed: tapHandler.pressedreadonly property bool softwareRendering: GraphicsInfo.api === GraphicsInfo.Softwarewidth: list.cellWidthheight: list.cellHeightAccessible.name: i18nc("@action:button accessible only, %1 is widget name", "Add %1", model.name) + (model.isSupported ? "" : unsupportedTooltip.mainText)Accessible.description: (model.isSupported ? "" : model.unsupportedMessage) + model.description + (overlayedBadge.visible ? overlayedBadge.Accessible.name : "")Accessible.role: Accessible.ButtonHoverHandler {id: hoverHandleronHoveredChanged: if (hovered) delegate.GridView.view.currentIndex = index}TapHandler {id: tapHandlerenabled: !delegate.pendingUninstall && model.isSupportedonTapped: widgetExplorer.addApplet(delegate.pluginName)}PlasmaCore.ToolTipArea {id: unsupportedTooltipanchors.fill: parentvisible: !model.isSupportedmainText: i18nc("@info:tooltip", "Unsupported Widget")subText: model.unsupportedMessage}// Avoid repositioning delegate item after dragFinishedItem {anchors.fill: parentenabled: model.isSupportedDrag.dragType: Drag.AutomaticDrag.supportedActions: Qt.MoveAction | Qt.LinkActionDrag.mimeData: {"text/x-plasmoidservicename" : delegate.pluginName,}Drag.onDragStarted: {KWindowSystem.showingDesktop = true;main.draggingWidget = true;delegate.forceActiveFocus()}Drag.onDragFinished: {main.draggingWidget = false;}DragHandler {id: dragHandleracceptedDevices: PointerDevice.Mouse | PointerDevice.TouchPadenabled: !delegate.pendingUninstall && model.isSupportedonActiveChanged: if (active) {iconContainer.grabToImage(function(result) {if (!dragHandler.active) {return;}parent.Drag.imageSource = result.url;parent.Drag.active = dragHandler.active;}, Qt.size(Kirigami.Units.iconSizes.huge, Kirigami.Units.iconSizes.huge));} else {parent.Drag.active = false;parent.Drag.imageSource = "";}}DragHandler {id: touchDragHandleracceptedDevices: PointerDevice.Stylus | PointerDevice.TouchScreenenabled: dragHandler.enabledyAxis.enabled: falseonActiveChanged: if (active) {iconContainer.grabToImage(function(result) {if (!touchDragHandler.active) {return;}parent.Drag.imageSource = result.url;parent.Drag.active = touchDragHandler.active;}, Qt.size(Kirigami.Units.iconSizes.huge, Kirigami.Units.iconSizes.huge));} else {parent.Drag.active = false;parent.Drag.imageSource = "";}}}ColumnLayout {id: mainLayoutreadonly property color textColor: tapHandler.pressed ? Kirigami.Theme.highlightedTextColor : Kirigami.Theme.textColorspacing: Kirigami.Units.smallSpacinganchors {left: parent.leftright: parent.right//bottom: parent.bottommargins: Kirigami.Units.smallSpacing * 2rightMargin: Kirigami.Units.smallSpacing * 2 // don't cram the text to the border too muchtop: parent.top}Item {id: iconContainerwidth: Kirigami.Units.iconSizes.enormousheight: widthLayout.alignment: Qt.AlignHCenteropacity: delegate.pendingUninstall ? 0.6 : 1Behavior on opacity {OpacityAnimator {duration: Kirigami.Units.longDurationeasing.type: Easing.InOutQuad}}Item {id: iconWidgetanchors.fill: parentKirigami.Icon {anchors.fill: parentsource: model.decorationvisible: model.screenshot === ""selected: tapHandler.pressedenabled: model.isSupported}Image {width: Kirigami.Units.iconSizes.enormousheight: widthanchors.fill: parentfillMode: Image.PreserveAspectFitsource: model.screenshot}}Item {id: badgeMaskanchors.fill: parentRectangle {readonly property int offset: Math.round(Kirigami.Units.smallSpacing * 1.5)x: Math.round(-offset / 2)y: xwidth: overlayedBadge.width + offsetheight: overlayedBadge.height + offsetradius: heightvisible: overlayedBadge.visible}}KGraphicalEffects.BadgeEffect {anchors.fill: parentsource: ShaderEffectSource {sourceItem: iconWidgethideSource: !softwareRenderinglive: false}mask: ShaderEffectSource {id: maskShaderSourcesourceItem: badgeMaskhideSource: truelive: false}}Kirigami.Badge {id: overlayedBadgevisible: ((running && delegate.GridView.isCurrentItem) || model.recent) ?? falsetype: (running && delegate.GridView.isCurrentItem) ? Kirigami.Badge.Type.Information : Kirigami.Badge.Type.Positivetext: (running && delegate.GridView.isCurrentItem) ? running : i18ndc("plasma_shell_org.kde.plasma.desktop", "Text displayed on top of newly-installed widgets", "New!")Accessible.name: running? i18ncp("@info:other accessible for badge showing applet count", "%1 widget active", "%1 widgets active", running): i18nc(" @info:other accessible for badge indicating new widget", "Recently installed")onTextChanged: maskShaderSource.scheduleUpdate()onTypeChanged: maskShaderSource.scheduleUpdate()onVisibleChanged: maskShaderSource.scheduleUpdate()}PlasmaComponents.ToolButton {id: uninstallButtonanchors {top: parent.topright: parent.right}text: delegate.pendingUninstall ? i18ndc("plasma_shell_org.kde.plasma.desktop", "@action:button tooltip and accessible cancel uninstall widget", "Cancel Uninstallation"): i18ndc("plasma_shell_org.kde.plasma.desktop","@action:button tooltip and accessible uninstall widget", "Mark for Uninstallation")icon.name: delegate.pendingUninstall ? "edit-undo" : "edit-delete"display: PlasmaComponents.AbstractButton.IconOnlyAccessible.description: delegate.pendingUninstall? i18nc("@action:button accessible only, %1 is widget name", "Cancel pending uninstallation for widget %1", model.name): i18nc("@action:button accessible only, %1 is widget name", "Mark widget %1 for uninstallation. Requires confirmation", model.name)// we don't really "undo" anything but we'll pretend to the user that we doPlasmaComponents.ToolTip.delay: Kirigami.Units.toolTipDelayPlasmaComponents.ToolTip.visible: hoveredPlasmaComponents.ToolTip.text: textflat: falsevisible: (model.local && delegate.GridView.isCurrentItem && !dragHandler.active && !touchDragHandler.active) ?? falseonHoveredChanged: {if (hovered) {// hovering the uninstall button triggers onExited of the main mouseareadelegate.GridView.view.currentIndex = index}}onClicked: {let pending = pendingUninstallTimer.appletsif (delegate.pendingUninstall) {let index = pending.indexOf(pluginName)if (index > -1) {pending.splice(index, 1)}} else {pending.push(pluginName)}pendingUninstallTimer.applets = pendingif (pending.length) {pendingUninstallTimer.restart()} else {pendingUninstallTimer.stop()}}}PlasmaComponents.ToolButton {id: removeInstancesButtonanchors {top: parent.topright: uninstallButton.visible ? uninstallButton.left : parent.rightrightMargin: uninstallButton.visible ? Kirigami.Units.smallSpacing : 0}text: i18ndc("plasma_shell_org.kde.plasma.desktop", "@action:button", "Remove all instances")display: PlasmaComponents.AbstractButton.IconOnlyicon.name: "edit-clear-all"Accessible.description: i18ncp("@action:button accessible description, %1 number of instances %2 is widget name","Remove running instance of widget %2","Remove all %1 running instances of widget %2", running ,model.name)// we don't really "undo" anything but we'll pretend to the user that we doPlasmaComponents.ToolTip.delay: Kirigami.Units.toolTipDelayPlasmaComponents.ToolTip.visible: hoveredPlasmaComponents.ToolTip.text: textflat: falsevisible: (running && delegate.GridView.isCurrentItem && !dragHandler.active) ?? falseonHoveredChanged: {if (hovered) {// hovering the uninstall button triggers onExited of the main mouseareadelegate.GridView.view.currentIndex = index}}onClicked: widgetExplorer.removeAllInstances(pluginName)}}Kirigami.Heading {id: headingLayout.fillWidth: truelevel: 4text: model.nametextFormat: Text.PlainTextelide: Text.ElideRightwrapMode: Text.WordWrapmaximumLineCount: 3lineHeight: 0.95horizontalAlignment: Text.AlignHCentercolor: mainLayout.textColor}PlasmaComponents.Label {Layout.fillWidth: true// otherwise causes binding loop due to the way the Plasma sets the heighttext: model.descriptiontextFormat: Text.PlainTextfont: Kirigami.Theme.smallFontwrapMode: Text.WordWrapelide: Text.ElideRightmaximumLineCount: 5 - heading.lineCounthorizontalAlignment: Text.AlignHCentercolor: mainLayout.textColor}}}