aerothemeplasma/Plasma Widgets/org.kde.plasma.private.systemtray/contents/ui/CurrentItemHighLight.qml
2021-08-24 15:42:11 +02:00

182 lines
5.2 KiB
QML

/*
* Copyright 2011 Marco Martin <mart@kde.org>
*
* 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.12
import org.kde.plasma.plasmoid 2.0
import org.kde.plasma.core 2.0 as PlasmaCore
PlasmaCore.FrameSvgItem {
id: currentItemHighLight
property int location
property bool animationEnabled: true
property var highlightedItem: null
z: -1 // always draw behind icons
opacity: systemTrayState.expanded ? 0.8 : 0
MouseArea
{
id: trayItemHighlight
anchors.fill: parent
hoverEnabled: true
property int highlightOpacity: 0
onEntered: highlightOpacity = 1
onExited: highlightOpacity = 0
}
imagePath: "widgets/tabbar"
prefix: {
var prefix = ""
switch (location) {
case PlasmaCore.Types.LeftEdge:
prefix = "west-active-tab";
break;
case PlasmaCore.Types.TopEdge:
prefix = "north-active-tab";
break;
case PlasmaCore.Types.RightEdge:
prefix = "east-active-tab";
break;
default:
prefix = "south-active-tab";
}
if (!hasElementPrefix(prefix)) {
prefix = "active-tab";
}
return prefix;
}
// update when System Tray is expanded - applet activated or hidden icons shown
Connections {
target: systemTrayState
function onActiveAppletChanged() {
Qt.callLater(updateHighlightedItem);
}
function onExpandedChanged() {
Qt.callLater(updateHighlightedItem);
}
}
// update when applet changes parent (e.g. moves from active to hidden icons)
Connections {
target: systemTrayState.activeApplet
function onParentChanged() {
Qt.callLater(updateHighlightedItem);
}
}
// update when System Tray size changes
Connections {
target: parent
function onWidthChanged() {
Qt.callLater(updateHighlightedItem);
}
function onHeightChanged() {
Qt.callLater(updateHighlightedItem);
}
}
// update when scale of newly added tray item changes (check 'add' animation in GridView in main.qml)
Connections {
target: !!highlightedItem && highlightedItem.parent ? highlightedItem.parent : null
function onScaleChanged() {
Qt.callLater(updateHighlightedItem);
}
}
function updateHighlightedItem() {
if (systemTrayState.expanded) {
if (systemTrayState.activeApplet && systemTrayState.activeApplet.parent && systemTrayState.activeApplet.parent.inVisibleLayout) {
changeHighlightedItem(systemTrayState.activeApplet.parent.container);
} else { // 'Show hiden items' popup
changeHighlightedItem(parent);
}
} else {
highlightedItem = null;
}
}
function changeHighlightedItem(nextItem) {
// do not animate the first appearance
// or when the property value of a highlighted item changes
if (!highlightedItem || (highlightedItem === nextItem)) {
animationEnabled = false;
}
highlightedItem = nextItem;
const p = parent.mapFromItem(highlightedItem, 0, 0)
x = p.x;
y = p.y;
width = highlightedItem.width
height = highlightedItem.height
animationEnabled = true;
}
Behavior on opacity {
NumberAnimation {
duration: PlasmaCore.Units.longDuration
easing.type: systemTrayState.expanded ? Easing.OutCubic : Easing.InCubic
}
}
Behavior on x {
id: xAnim
enabled: animationEnabled
NumberAnimation {
duration: PlasmaCore.Units.longDuration
easing.type: Easing.InOutCubic
}
}
Behavior on y {
id: yAnim
enabled: animationEnabled
NumberAnimation {
duration: PlasmaCore.Units.longDuration
easing.type: Easing.InOutCubic
}
}
Behavior on width {
id: widthAnim
enabled: animationEnabled
NumberAnimation {
duration: PlasmaCore.Units.longDuration
easing.type: Easing.InOutCubic
}
}
Behavior on height {
id: heightAnim
enabled: animationEnabled
NumberAnimation {
duration: PlasmaCore.Units.longDuration
easing.type: Easing.InOutCubic
}
}
}