Warning, /plasma/plasma-sdk/plasmoidviewer/qmlpackages/shell/contents/applet/CompactApplet.qml is written in an unsupported language. File is not indexed.

0001 /*
0002     SPDX-FileCopyrightText: 2013 Marco Martin <mart@kde.org>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 import QtQuick 2.15
0007 import QtQuick.Layouts 1.15
0008 import QtQuick.Window 2.15
0009 
0010 import org.kde.plasma.core as PlasmaCore
0011 import org.kde.ksvg 1.0 as KSvg
0012 import org.kde.plasma.plasmoid 2.0
0013 import org.kde.kquickcontrolsaddons 2.0
0014 import org.kde.kirigami 2.20 as Kirigami
0015 
0016 PlasmaCore.ToolTipArea {
0017     id: root
0018     objectName: "org.kde.desktop-CompactApplet"
0019     anchors.fill: parent
0020 
0021     mainText: plasmoidItem ? plasmoidItem.toolTipMainText : ""
0022     subText: plasmoidItem ? plasmoidItem.toolTipSubText : ""
0023     location: Plasmoid.location
0024     active: plasmoidItem ? !plasmoidItem.expanded : false
0025     textFormat: plasmoidItem ? plasmoidItem.toolTipTextFormat : 0
0026     mainItem: plasmoidItem && plasmoidItem.toolTipItem ? plasmoidItem.toolTipItem : null
0027 
0028     property Item fullRepresentation
0029     property Item compactRepresentation
0030     property Item expandedFeedback: expandedItem
0031     property PlasmoidItem plasmoidItem
0032 
0033     onCompactRepresentationChanged: {
0034         if (compactRepresentation) {
0035             compactRepresentation.anchors.fill = null;
0036             compactRepresentation.parent = compactRepresentationParent;
0037             compactRepresentation.anchors.fill = compactRepresentationParent;
0038             compactRepresentation.visible = true;
0039         }
0040         root.visible = true;
0041     }
0042 
0043     onFullRepresentationChanged: {
0044         if (fullRepresentation) {
0045             fullRepresentation.anchors.fill = null;
0046             fullRepresentation.parent = appletParent;
0047             fullRepresentation.anchors.fill = appletParent;
0048         }
0049     }
0050 
0051     FocusScope {
0052         id: compactRepresentationParent
0053         anchors.fill: parent
0054         activeFocusOnTab: true
0055         onActiveFocusChanged: {
0056             // When the scope gets the active focus, try to focus its first descendant,
0057             // if there is on which has activeFocusOnTab
0058             if (!activeFocus) {
0059                 return;
0060             }
0061             let nextItem = nextItemInFocusChain();
0062             let candidate = nextItem;
0063             while (candidate.parent) {
0064                 if (candidate === compactRepresentationParent) {
0065                     nextItem.forceActiveFocus();
0066                     return;
0067                 }
0068                 candidate = candidate.parent;
0069             }
0070         }
0071 
0072         objectName: "expandApplet"
0073         Accessible.name: root.mainText
0074         Accessible.description: i18nd("plasma_shell_org.kde.plasma.desktop", "Open %1", root.subText)
0075         Accessible.role: Accessible.Button
0076         Accessible.onPressAction: Plasmoid.activated()
0077 
0078         Keys.onPressed: {
0079             switch (event.key) {
0080                 case Qt.Key_Space:
0081                 case Qt.Key_Enter:
0082                 case Qt.Key_Return:
0083                 case Qt.Key_Select:
0084                     Plasmoid.activated();
0085                     break;
0086             }
0087         }
0088     }
0089 
0090     KSvg.FrameSvgItem {
0091         id: expandedItem
0092         z: -100
0093 
0094         property var containerMargins: {
0095             let item = root;
0096             while (item.parent) {
0097                 item = item.parent;
0098                 if (item.isAppletContainer) {
0099                     return item.getMargins;
0100                 }
0101             }
0102             return undefined;
0103         }
0104 
0105         anchors {
0106             fill: parent
0107             property bool returnAllMargins: true
0108             // The above makes sure margin is returned even for side margins, that
0109             // would be otherwise turned off.
0110             bottomMargin: containerMargins ? -containerMargins('bottom', returnAllMargins) : 0;
0111             topMargin: containerMargins ? -containerMargins('top', returnAllMargins) : 0;
0112             leftMargin: containerMargins ? -containerMargins('left', returnAllMargins) : 0;
0113             rightMargin: containerMargins ? -containerMargins('right', returnAllMargins) : 0;
0114         }
0115         imagePath: "widgets/tabbar"
0116         visible: opacity > 0
0117         prefix: {
0118             let prefix;
0119             switch (Plasmoid.location) {
0120             case PlasmaCore.Types.LeftEdge:
0121                 prefix = "west-active-tab";
0122                 break;
0123             case PlasmaCore.Types.TopEdge:
0124                 prefix = "north-active-tab";
0125                 break;
0126             case PlasmaCore.Types.RightEdge:
0127                 prefix = "east-active-tab";
0128                 break;
0129             default:
0130                 prefix = "south-active-tab";
0131             }
0132             if (!hasElementPrefix(prefix)) {
0133                 prefix = "active-tab";
0134             }
0135             return prefix;
0136         }
0137         opacity: plasmoidItem && plasmoidItem.expanded ? 1 : 0
0138         Behavior on opacity {
0139             NumberAnimation {
0140                 duration: Kirigami.Units.shortDuration
0141                 easing.type: Easing.InOutQuad
0142             }
0143         }
0144     }
0145 
0146     Timer {
0147         id: expandedSync
0148         interval: 100
0149         onTriggered: plasmoidItem.expanded = dialog.visible;
0150     }
0151 
0152     Connections {
0153         target: Plasmoid.internalAction("configure")
0154         function onTriggered() {
0155             if (root.plasmoidItem.hideOnWindowDeactivate) {
0156                 plasmoidItem.expanded = false
0157             }
0158         }
0159     }
0160 
0161     Connections {
0162         target: root.Plasmoid
0163         function onContextualActionsAboutToShow() { root.hideImmediately() }
0164     }
0165 
0166     PlasmaCore.Dialog {
0167         id: dialog
0168         objectName: "popupWindow"
0169         flags: Qt.WindowStaysOnTopHint
0170         location: Plasmoid.location
0171         hideOnWindowDeactivate: root.plasmoidItem && root.plasmoidItem.hideOnWindowDeactivate
0172         visible: root.plasmoidItem && root.plasmoidItem.expanded && fullRepresentation
0173         visualParent: root.compactRepresentation
0174         backgroundHints: (Plasmoid.containmentDisplayHints & PlasmaCore.Types.ContainmentPrefersOpaqueBackground) ? PlasmaCore.Dialog.SolidBackground : PlasmaCore.Dialog.StandardBackground
0175         type: PlasmaCore.Dialog.AppletPopup
0176         appletInterface: fullRepresentation && fullRepresentation.appletInterface || null
0177 
0178         property var oldStatus: PlasmaCore.Types.UnknownStatus
0179 
0180         onVisibleChanged: {
0181             if (!visible) {
0182                 expandedSync.restart();
0183                 Plasmoid.status = oldStatus;
0184             } else {
0185                 oldStatus = Plasmoid.status;
0186                 Plasmoid.status = PlasmaCore.Types.RequiresAttentionStatus;
0187                 // This call currently fails and complains at runtime:
0188                 // QWindow::setWindowState: QWindow::setWindowState does not accept Qt::WindowActive
0189                 dialog.requestActivate();
0190             }
0191         }
0192         //It's a MouseEventListener to get all the events, so the eventfilter will be able to catch them
0193         mainItem: MouseEventListener {
0194             id: appletParent
0195 
0196             focus: true
0197 
0198             Keys.onEscapePressed: {
0199                 root.plasmoidItem.expanded = false;
0200             }
0201 
0202             Layout.minimumWidth: fullRepresentation ? fullRepresentation.Layout.minimumWidth : 0
0203             Layout.minimumHeight: fullRepresentation ? fullRepresentation.Layout.minimumHeight : 0
0204 
0205             Layout.preferredWidth: fullRepresentation ? fullRepresentation.Layout.preferredWidth : -1
0206             Layout.preferredHeight: fullRepresentation ? fullRepresentation.Layout.preferredHeight : -1
0207 
0208             Layout.maximumWidth: fullRepresentation ? fullRepresentation.Layout.maximumWidth : Infinity
0209             Layout.maximumHeight: fullRepresentation ? fullRepresentation.Layout.maximumHeight : Infinity
0210 
0211             width: {
0212                 if (root.fullRepresentation !== null) {
0213                     /****/ if (root.fullRepresentation.Layout.preferredWidth > 0) {
0214                         return root.fullRepresentation.Layout.preferredWidth;
0215                     } else if (root.fullRepresentation.implicitWidth > 0) {
0216                         return root.fullRepresentation.implicitWidth;
0217                     }
0218                 }
0219                 return Kirigami.Units.iconSizes.sizeForLabels * 35;
0220             }
0221             height: {
0222                 if (root.fullRepresentation !== null) {
0223                     /****/ if (fullRepresentation.Layout.preferredHeight > 0) {
0224                         return fullRepresentation.Layout.preferredHeight;
0225                     } else if (fullRepresentation.implicitHeight > 0) {
0226                         return fullRepresentation.implicitHeight;
0227                     }
0228                 }
0229                 return Kirigami.Units.iconSizes.sizeForLabels * 25;
0230             }
0231 
0232             onActiveFocusChanged: {
0233                 if (activeFocus && fullRepresentation) {
0234                     fullRepresentation.forceActiveFocus()
0235                 }
0236             }
0237 
0238             // Draws a line between the applet dialog and the panel
0239             KSvg.SvgItem {
0240                 // Only draw for popups of panel applets, not desktop applets
0241                 visible: [PlasmaCore.Types.TopEdge, PlasmaCore.Types.LeftEdge, PlasmaCore.Types.RightEdge, PlasmaCore.Types.BottomEdge]
0242                     .includes(Plasmoid.location)
0243                 anchors {
0244                     top: Plasmoid.location === PlasmaCore.Types.BottomEdge ? undefined : parent.top
0245                     left: Plasmoid.location === PlasmaCore.Types.RightEdge ? undefined : parent.left
0246                     right: Plasmoid.location === PlasmaCore.Types.LeftEdge ? undefined : parent.right
0247                     bottom: Plasmoid.location === PlasmaCore.Types.TopEdge ? undefined : parent.bottom
0248                     topMargin: Plasmoid.location === PlasmaCore.Types.BottomEdge ? undefined : -dialog.margins.top
0249                     leftMargin: Plasmoid.location === PlasmaCore.Types.RightEdge ? undefined : -dialog.margins.left
0250                     rightMargin: Plasmoid.location === PlasmaCore.Types.LeftEdge ? undefined : -dialog.margins.right
0251                     bottomMargin: Plasmoid.location === PlasmaCore.Types.TopEdge ? undefined : -dialog.margins.bottom
0252                 }
0253                 height: (Plasmoid.location === PlasmaCore.Types.TopEdge || Plasmoid.location === PlasmaCore.Types.BottomEdge) ? 1 : undefined
0254                 width: (Plasmoid.location === PlasmaCore.Types.LeftEdge || Plasmoid.location === PlasmaCore.Types.RightEdge) ? 1 : undefined
0255                 z: 999 /* Draw the line on top of the applet */
0256                 elementId: (Plasmoid.location === PlasmaCore.Types.TopEdge || Plasmoid.location === PlasmaCore.Types.BottomEdge) ? "horizontal-line" : "vertical-line"
0257                 imagePath: "widgets/line"
0258             }
0259 
0260             LayoutMirroring.enabled: Qt.application.layoutDirection === Qt.RightToLeft
0261             LayoutMirroring.childrenInherit: true
0262         }
0263     }
0264 }