diff --git a/applets/systemtray/package/contents/ui/items/AbstractItem.qml b/applets/systemtray/package/contents/ui/items/AbstractItem.qml index 2c26aa3eb..2d31fc0b9 100644 --- a/applets/systemtray/package/contents/ui/items/AbstractItem.qml +++ b/applets/systemtray/package/contents/ui/items/AbstractItem.qml @@ -1,142 +1,144 @@ /* * Copyright 2016 Marco Martin * Copyright 2020 Konrad Materka * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Library General Public License for more details * * You should have received a copy of the GNU Library General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import QtQuick 2.2 import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.plasma.components 2.0 as PlasmaComponents PlasmaCore.ToolTipArea { id: abstractItem height: inVisibleLayout ? visibleLayout.cellHeight : hiddenLayout.iconItemHeight width: inVisibleLayout ? visibleLayout.cellWidth : hiddenLayout.width + property var model: itemModel + property string itemId property alias text: label.text property Item iconItem - property int /*PlasmaCore.Types.ItemStatus*/ status - property int /*PlasmaCore.Types.ItemStatus*/ effectiveStatus + property int /*PlasmaCore.Types.ItemStatus*/ status: model.status || PlasmaCore.Types.UnknownStatus + property int /*PlasmaCore.Types.ItemStatus*/ effectiveStatus: model.effectiveStatus || PlasmaCore.Types.UnknownStatus readonly property bool inHiddenLayout: effectiveStatus === PlasmaCore.Types.PassiveStatus readonly property bool inVisibleLayout: effectiveStatus === PlasmaCore.Types.ActiveStatus signal clicked(var mouse) signal pressed(var mouse) signal wheel(var wheel) signal contextMenu(var mouse) /* subclasses need to assign to this tooltip properties mainText: subText: icon: */ location: { if (inHiddenLayout) { if (LayoutMirroring.enabled && plasmoid.location !== PlasmaCore.Types.RightEdge) { return PlasmaCore.Types.LeftEdge; } else if (plasmoid.location !== PlasmaCore.Types.LeftEdge) { return PlasmaCore.Types.RightEdge; } } return plasmoid.location; } //BEGIN CONNECTIONS onContainsMouseChanged: { if (inHiddenLayout && containsMouse) { root.hiddenLayout.currentIndex = index } } //END CONNECTIONS PulseAnimation { targetItem: iconItem running: (abstractItem.status === PlasmaCore.Types.NeedsAttentionStatus || abstractItem.status === PlasmaCore.Types.RequiresAttentionStatus ) && units.longDuration > 0 } function activated() { activatedAnimation.start() } SequentialAnimation { id: activatedAnimation loops: 1 ScaleAnimator { target: iconItem from: 1 to: 0.5 duration: units.shortDuration easing.type: Easing.InQuad } ScaleAnimator { target: iconItem from: 0.5 to: 1 duration: units.shortDuration easing.type: Easing.OutQuad } } MouseArea { anchors.fill: abstractItem hoverEnabled: true drag.filterChildren: true acceptedButtons: Qt.LeftButton | Qt.MiddleButton | Qt.RightButton onClicked: abstractItem.clicked(mouse) onPressed: { abstractItem.hideToolTip() abstractItem.pressed(mouse) } onPressAndHold: { abstractItem.contextMenu(mouse) } onWheel: { abstractItem.wheel(wheel); //Don't accept the event in order to make the scrolling by mouse wheel working //for the parent scrollview this icon is in. wheel.accepted = false; } } PlasmaComponents.Label { id: label anchors { left: parent.left leftMargin: iconItem ? iconItem.width + units.smallSpacing : 0 verticalCenter: parent.verticalCenter } opacity: visible ? 1 : 0 visible: abstractItem.inHiddenLayout && !root.activeApplet Behavior on opacity { NumberAnimation { duration: units.longDuration easing.type: Easing.InOutQuad } } } } diff --git a/applets/systemtray/package/contents/ui/items/ItemLoader.qml b/applets/systemtray/package/contents/ui/items/ItemLoader.qml index ec8e9ec14..24a977eda 100644 --- a/applets/systemtray/package/contents/ui/items/ItemLoader.qml +++ b/applets/systemtray/package/contents/ui/items/ItemLoader.qml @@ -1,38 +1,34 @@ /* * Copyright 2020 Konrad Materka * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Library General Public License for more details * * You should have received a copy of the GNU Library General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import QtQuick 2.0 Loader { id: itemLoader - Component.onCompleted: { + property var itemModel: model + + source: { if (model.itemType === "Plasmoid" && model.hasApplet) { - itemLoader.setSource("PlasmoidItem.qml", { - "applet": model.applet, - "effectiveStatus": model.effectiveStatus - }) + return "PlasmoidItem.qml" } else if (model.itemType === "StatusNotifier") { - itemLoader.setSource("StatusNotifierItem.qml", { - "model": model, - "effectiveStatus": model.effectiveStatus - }) + return "StatusNotifierItem.qml" } } } diff --git a/applets/systemtray/package/contents/ui/items/PlasmoidItem.qml b/applets/systemtray/package/contents/ui/items/PlasmoidItem.qml index 2c7c5442d..16c99b1c0 100644 --- a/applets/systemtray/package/contents/ui/items/PlasmoidItem.qml +++ b/applets/systemtray/package/contents/ui/items/PlasmoidItem.qml @@ -1,117 +1,116 @@ /* * Copyright 2015 Marco Martin * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Library General Public License for more details * * You should have received a copy of the GNU Library General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import QtQuick 2.1 import org.kde.plasma.core 2.0 as PlasmaCore AbstractItem { id: plasmoidContainer - property Item applet + property Item applet: model.applet || null iconItem: applet text: applet ? applet.title : "" itemId: applet ? applet.pluginName : "" mainText: applet ? applet.toolTipMainText : "" subText: applet ? applet.toolTipSubText : "" icon: applet ? applet.icon : "" mainItem: applet && applet.toolTipItem ? applet.toolTipItem : null textFormat: applet ? applet.toolTipTextFormat : "" - status: applet ? applet.status : PlasmaCore.Types.UnknownStatus active: root.activeApplet !== applet onClicked: { if (applet && mouse.button === Qt.LeftButton) { applet.expanded = true; } } onPressed: { if (mouse.button === Qt.RightButton) { plasmoidContainer.contextMenu(mouse); } } onContextMenu: { if (applet) { plasmoid.nativeInterface.showPlasmoidMenu(applet, 0, plasmoidContainer.inHiddenLayout ? applet.height : 0); } } onHeightChanged: { if (applet) { applet.width = Math.min(plasmoidContainer.width, plasmoidContainer.height) applet.height = applet.width } } onWidthChanged: { if (applet) { applet.width = Math.min(plasmoidContainer.width, plasmoidContainer.height) applet.height = applet.width } } //This is to make preloading effective, minimizes the scene changes function preloadFullRepresentationItem(fullRepresentationItem) { if (fullRepresentationItem && fullRepresentationItem.parent === null) { fullRepresentationItem.width = expandedRepresentation.width fullRepresentationItem.width = expandedRepresentation.height fullRepresentationItem.parent = preloadedStorage; } } onAppletChanged: { if (applet) { applet.parent = plasmoidContainer applet.anchors.left = plasmoidContainer.left applet.anchors.verticalCenter = plasmoidContainer.verticalCenter applet.width = Math.min(plasmoidContainer.width, plasmoidContainer.height) applet.height = applet.width applet.visible = true preloadFullRepresentationItem(applet.fullRepresentationItem) } } Connections { target: applet onActivated: plasmoidContainer.activated() onExpandedChanged: { if (expanded) { var oldApplet = root.activeApplet; root.activeApplet = applet; if (oldApplet && oldApplet !== applet) { oldApplet.expanded = false; } dialog.visible = true; plasmoidContainer.activated() } else if (root.activeApplet === applet) { if (!inHiddenLayout) { dialog.visible = false; } //if not expanded we don't have an active applet anymore root.activeApplet = null; } } onFullRepresentationItemChanged: { preloadFullRepresentationItem(fullRepresentationItem) } } } diff --git a/applets/systemtray/package/contents/ui/items/StatusNotifierItem.qml b/applets/systemtray/package/contents/ui/items/StatusNotifierItem.qml index 497d44b16..f33bfa680 100644 --- a/applets/systemtray/package/contents/ui/items/StatusNotifierItem.qml +++ b/applets/systemtray/package/contents/ui/items/StatusNotifierItem.qml @@ -1,131 +1,127 @@ /* * Copyright 2016 Marco Martin * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Library General Public License for more details * * You should have received a copy of the GNU Library General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import QtQuick 2.1 import org.kde.plasma.core 2.0 as PlasmaCore AbstractItem { id: taskIcon - property var model - itemId: model.Id text: model.Title mainText: model.ToolTipTitle !== "" ? model.ToolTipTitle : model.Title subText: model.ToolTipSubTitle icon: model.ToolTipIcon !== "" ? model.ToolTipIcon : model.Icon ? model.Icon : model.IconName textFormat: Text.AutoText - status: model.status - iconItem: iconItem PlasmaCore.IconItem { id: iconItem source: { if (model.status === PlasmaCore.Types.NeedsAttentionStatus) { if (model.AttentionIcon) { return model.AttentionIcon } if (model.AttentionIconName) { return model.AttentionIconName } } return model.Icon ? model.Icon : model.IconName } width: Math.min(parent.width, parent.height) height: width active: taskIcon.containsMouse anchors { left: parent.left verticalCenter: parent.verticalCenter } } onContextMenu: { openContextMenu(plasmoid.nativeInterface.popupPosition(taskIcon, mouse.x, mouse.y)) } onClicked: { var pos = plasmoid.nativeInterface.popupPosition(taskIcon, mouse.x, mouse.y); switch (mouse.button) { case Qt.LeftButton: var service = plasmoid.nativeInterface.serviceForSource(model.DataEngineSource); var operation = service.operationDescription("Activate"); operation.x = pos.x; operation.y = pos.y; var job = service.startOperationCall(operation); job.finished.connect(function () { if (!job.result) { // On error try to invoke the context menu. // Workaround primarily for apps using libappindicator. openContextMenu(pos); } }); taskIcon.activated() break; case Qt.RightButton: openContextMenu(pos); break; case Qt.MiddleButton: var service = plasmoid.nativeInterface.serviceForSource(model.DataEngineSource); var operation = service.operationDescription("SecondaryActivate"); operation.x = pos.x; operation.y = pos.y; service.startOperationCall(operation); taskIcon.activated() break; } } function openContextMenu(pos) { var service = plasmoid.nativeInterface.serviceForSource(model.DataEngineSource); var operation = service.operationDescription("ContextMenu"); operation.x = pos.x; operation.y = pos.y; var job = service.startOperationCall(operation); job.finished.connect(function () { plasmoid.nativeInterface.showStatusNotifierContextMenu(job, taskIcon); }); } onWheel: { //don't send activateVertScroll with a delta of 0, some clients seem to break (kmix) if (wheel.angleDelta.y !== 0) { var service = plasmoid.nativeInterface.serviceForSource(model.DataEngineSource); var operation = service.operationDescription("Scroll"); operation.delta =wheel.angleDelta.y; operation.direction = "Vertical"; service.startOperationCall(operation); } if (wheel.angleDelta.x !== 0) { var service = plasmoid.nativeInterface.serviceForSource(model.DataEngineSource); var operation = service.operationDescription("Scroll"); operation.delta =wheel.angleDelta.x; operation.direction = "Horizontal"; service.startOperationCall(operation); } } }