You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
latte-dock/shell/package/contents/views/AppletDelegate.qml

225 lines
8.2 KiB
QML

/*
SPDX-FileCopyrightText: 2011 Marco Martin <mart@kde.org>
SPDX-FileCopyrightText: 2015 Kai Uwe Broulik <kde@privat.broulik.de>
SPDX-FileCopyrightText: 2021 Michail Vourlakos <mvourlakos@gmail.com>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
import QtQuick 2.4
import QtQuick.Layouts 1.1
import org.kde.plasma.components 2.0 as PlasmaComponents
import org.kde.plasma.extras 2.0 as PlasmaExtras
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.draganddrop 2.0
Item {
id: delegate
readonly property string pluginName: model.pluginName
readonly property bool pendingUninstall: pendingUninstallTimer.applets.indexOf(pluginName) > -1
width: list.cellWidth
height: list.cellHeight
DragArea {
anchors.fill: parent
supportedActions: Qt.MoveAction | Qt.LinkAction
//onDragStarted: tooltipDialog.visible = false
delegateImage: decoration
enabled: !delegate.pendingUninstall
mimeData {
source: parent
}
Component.onCompleted: mimeData.setData("text/x-plasmoidservicename", pluginName)
onDragStarted: {
kwindowsystem.showingDesktop = true;
main.draggingWidget = true;
}
onDrop: {
main.draggingWidget = false;
}
MouseArea {
id: mouseArea
anchors.fill: parent
hoverEnabled: true
onDoubleClicked: {
if (!delegate.pendingUninstall) {
fix #96,FEATURE:AllScreens and AllSecondaryScreens --This is a HUGE FEATURE and so important for multi-screens users. It is introduced as one single commit because it reimplements plenty of infrastructure changes and it will be easier to identify newly introduced bugs. --Users can now choose for their docks and panels to belong at various screen groups. The first two screen groups introduced are AllScreens and AllSecondayScreens. In the future it might be possible to provide CustomScreensGroup that the user will be able to define specific screens in which a dock or panel should be always present. --Current solution specifies an Original dock or panel and clones/copies itself automatically to other screens. So docks and panels in other screens are just real docks and panels that reference themselves to original docks and panels. --Clones are destroyed during layout startup and are automaticaly recreated. It is suggested to export your layouts through the official Layouts Editor in order to share them because in that case clones are not included in the new generated layout file. If in any case you do not this and you share your layout with any previous versions then your clones will just appear as separate docks and panels that belong to specific screens. --Automatic syncing was introduced in order to keep up-to-date the configuration of Original docks and panels with their referenced Clones. --Automatic syncing currently works for all docks and panels settings, for all normal applets configurations and for all subcontaiments configuration such as systrays. --Automatic syncing does not work for applets inside subcontainments such as Group Plasmoid. In such case it is suggested to configure your applets inside your Group Plasmoid in the original dock or panel and afterwards to trigger a recreation for the relevant clones --Manual recreation of clones is easily possible by just choosing the dock or panel to be OnPrimary or OnSpecificScreen and rechoosing afterwards the AllScreensGroup or AllSecondaryScreensGroup
3 years ago
widgetExplorer.addApplet(pluginName);
latteView.extendedInterface.appletCreated(pluginName);
}
}
onEntered: delegate.GridView.view.currentIndex = index
onExited: delegate.GridView.view.currentIndex = - 1
}
ColumnLayout {
id: mainLayout
spacing: units.smallSpacing
anchors {
left: parent.left
right: parent.right
//bottom: parent.bottom
margins: units.smallSpacing * 2
rightMargin: units.smallSpacing * 2 // don't cram the text to the border too much
top: parent.top
}
Item {
id: iconContainer
width: units.iconSizes.enormous
height: width
Layout.alignment: Qt.AlignHCenter
opacity: delegate.pendingUninstall ? 0.6 : 1
Behavior on opacity {
OpacityAnimator {
duration: units.longDuration
easing.type: Easing.InOutQuad
}
}
Item {
id: iconWidget
anchors.fill: parent
PlasmaCore.IconItem {
anchors.fill: parent
source: model.decoration
visible: model.screenshot === ""
}
Image {
width: units.iconSizes.enormous
height: width
anchors.fill: parent
fillMode: Image.PreserveAspectFit
source: model.screenshot
}
}
Item {
id: badgeMask
anchors.fill: parent
Rectangle {
x: Math.round(-units.smallSpacing * 1.5 / 2)
y: x
width: runningBadge.width + Math.round(units.smallSpacing * 1.5)
height: width
radius: height
visible: running && delegate.GridView.isCurrentItem
}
}
Rectangle {
id: runningBadge
width: height
height: Math.round(theme.mSize(countLabel.font).height * 1.3)
radius: height
color: theme.highlightColor
visible: running && delegate.GridView.isCurrentItem
onVisibleChanged: maskShaderSource.scheduleUpdate()
PlasmaComponents.Label {
id: countLabel
anchors.fill: parent
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
text: running
}
}
ShaderEffect {
anchors.fill: parent
property var source: ShaderEffectSource {
sourceItem: iconWidget
hideSource: true
live: false
}
property var mask: ShaderEffectSource {
id: maskShaderSource
sourceItem: badgeMask
hideSource: true
live: false
}
supportsAtlasTextures: true
fragmentShader: "
varying highp vec2 qt_TexCoord0;
uniform highp float qt_Opacity;
uniform lowp sampler2D source;
uniform lowp sampler2D mask;
void main() {
gl_FragColor = texture2D(source, qt_TexCoord0.st) * (1.0 - (texture2D(mask, qt_TexCoord0.st).a)) * qt_Opacity;
}
"
}
PlasmaComponents.ToolButton {
id: uninstallButton
anchors {
top: parent.top
right: parent.right
}
iconSource: delegate.pendingUninstall ? "edit-undo" : "edit-delete"
// we don't really "undo" anything but we'll pretend to the user that we do
tooltip: delegate.pendingUninstall ? i18nd("plasma_shell_org.kde.plasma.desktop", "Undo uninstall")
: i18nd("plasma_shell_org.kde.plasma.desktop", "Uninstall widget")
flat: false
visible: model.local && delegate.GridView.isCurrentItem
onHoveredChanged: {
if (hovered) {
// hovering the uninstall button triggers onExited of the main mousearea
delegate.GridView.view.currentIndex = index
}
}
onClicked: {
var pending = pendingUninstallTimer.applets
if (delegate.pendingUninstall) {
var index = pending.indexOf(pluginName)
if (index > -1) {
pending.splice(index, 1)
}
} else {
pending.push(pluginName)
}
pendingUninstallTimer.applets = pending
if (pending.length) {
pendingUninstallTimer.restart()
} else {
pendingUninstallTimer.stop()
}
}
}
}
PlasmaExtras.Heading {
id: heading
Layout.fillWidth: true
level: 4
text: model.name
elide: Text.ElideRight
wrapMode: Text.WordWrap
maximumLineCount: 2
lineHeight: 0.95
horizontalAlignment: Text.AlignHCenter
}
PlasmaComponents.Label {
Layout.fillWidth: true
// otherwise causes binding loop due to the way the Plasma sets the height
height: implicitHeight
text: model.description
font: theme.smallestFont
wrapMode: Text.WordWrap
elide: Text.ElideRight
maximumLineCount: heading.lineCount === 1 ? 3 : 2
horizontalAlignment: Text.AlignHCenter
}
}
}
}