/*SPDX-FileCopyrightText: 2013 Marco Martin <mart@kde.org>SPDX-License-Identifier: GPL-2.0-or-later*/import QtQuickimport QtQuick.Layoutsimport QtQuick.Windowimport org.kde.plasma.core as PlasmaCoreimport org.kde.ksvg as KSvgimport org.kde.plasma.plasmoidimport org.kde.kquickcontrolsaddonsimport org.kde.kirigami as KirigamiPlasmaCore.ToolTipArea {id: rootobjectName: "org.kde.desktop-CompactApplet"anchors.fill: parentmainText: plasmoidItem.toolTipMainTextsubText: plasmoidItem.toolTipSubTextlocation: Plasmoid.locationactive: !plasmoidItem.expandedtextFormat: plasmoidItem.toolTipTextFormatmainItem: plasmoidItem.toolTipItem ? plasmoidItem.toolTipItem : nullreadonly property bool vertical: location === PlasmaCore.Types.RightEdge || location === PlasmaCore.Types.LeftEdgeproperty Item fullRepresentationproperty Item compactRepresentationproperty Item expandedFeedback: expandedItemproperty PlasmoidItem plasmoidItemonCompactRepresentationChanged: {if (compactRepresentation) {compactRepresentation.anchors.fill = null;compactRepresentation.parent = compactRepresentationParent;compactRepresentation.anchors.fill = compactRepresentationParent;compactRepresentation.visible = true;}root.visible = true;}onFullRepresentationChanged: {if (fullRepresentation) {fullRepresentation.anchors.fill = null;fullRepresentation.parent = appletParent;fullRepresentation.anchors.fill = appletParent;// This avoids the content being drawn underneath the// separator between the panel and the applet.if (!separator.visible) {return;}if (Plasmoid.location === PlasmaCore.Types.TopEdge) {fullRepresentation.anchors.topMargin = separator.height} else if (Plasmoid.location === PlasmaCore.Types.BottomEdge) {fullRepresentation.anchors.bottomMargin = separator.height} else if (Plasmoid.location === PlasmaCore.Types.LeftEdge) {fullRepresentation.anchors.leftMargin = separator.width} else if (Plasmoid.location === PlasmaCore.Types.RightEdge) {fullRepresentation.anchors.rightMargin = separator.width}}}FocusScope {id: compactRepresentationParentanchors.fill: parentactiveFocusOnTab: trueonActiveFocusChanged: {// When the scope gets the active focus, try to focus its first descendant,// if there is on which has activeFocusOnTabif (!activeFocus) {return;}let nextItem = nextItemInFocusChain();let candidate = nextItem;while (candidate.parent) {if (candidate === compactRepresentationParent) {nextItem.forceActiveFocus();return;}candidate = candidate.parent;}}objectName: "expandApplet"Accessible.name: root.mainTextAccessible.description: i18ndc("plasma_shell_org.kde.plasma.desktop", "@info:whatsthis Accessible description for panel widget %1", "Open %1", root.subText)Accessible.role: Accessible.ButtonAccessible.onPressAction: Plasmoid.activated()Keys.onPressed: event => {switch (event.key) {case Qt.Key_Space:case Qt.Key_Enter:case Qt.Key_Return:case Qt.Key_Select:Plasmoid.activated();break;}}}KSvg.FrameSvgItem {id: expandedItemz: -100property var containerMargins: {let item = root;while (item.parent) {item = item.parent;if (item.isAppletContainer) {return item.getMargins;}}return undefined;}anchors {fill: parentproperty bool returnAllMargins: true// The above makes sure margin is returned even for side margins, that// would be otherwise turned off.bottomMargin: !vertical && containerMargins ? -containerMargins('bottom', returnAllMargins) : 0topMargin: !vertical && containerMargins ? -containerMargins('top', returnAllMargins) : 0leftMargin: vertical && containerMargins ? -containerMargins('left', returnAllMargins) : 0rightMargin: vertical && containerMargins ? -containerMargins('right', returnAllMargins) : 0}imagePath: "widgets/tabbar"visible: opacity > 0prefix: {let prefix;switch (Plasmoid.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;}opacity: root.plasmoidItem.expanded ? 1 : 0Behavior on opacity {NumberAnimation {duration: Kirigami.Units.shortDurationeasing.type: Easing.InOutQuad}}}Timer {id: expandedSyncinterval: 100onTriggered: root.plasmoidItem.expanded = dialog.visible;}Connections {target: Plasmoid.internalAction("configure")function onTriggered() {if (root.plasmoidItem.hideOnWindowDeactivate) {root.plasmoidItem.expanded = false}}}Connections {target: root.Plasmoidfunction onContextualActionsAboutToShow() { root.hideImmediately() }}PlasmaCore.AppletPopup {id: dialogobjectName: "popupWindow"popupDirection: {switch (Plasmoid.location) {case PlasmaCore.Types.TopEdge:return Qt.BottomEdgecase PlasmaCore.Types.LeftEdge:return Qt.RightEdgecase PlasmaCore.Types.RightEdge:return Qt.LeftEdgedefault:return Qt.TopEdge}}margin: (Plasmoid.containmentDisplayHints & PlasmaCore.Types.ContainmentPrefersFloatingApplets) ? Kirigami.Units.largeSpacing : 0Behavior on margin {NumberAnimation {// Since the panel animation won't be perfectly in sync,// using a duration larger than the panel animation results// in a better-looking animation.duration: Kirigami.Units.veryLongDurationeasing.type: Easing.OutCubic}}floating: Plasmoid.location === PlasmaCore.Types.FloatingremoveBorderStrategy: Plasmoid.location === PlasmaCore.Types.Floating? PlasmaCore.AppletPopup.AtScreenEdges: PlasmaCore.AppletPopup.AtScreenEdges | PlasmaCore.AppletPopup.AtPanelEdgeshideOnWindowDeactivate: root.plasmoidItem.hideOnWindowDeactivatevisible: root.plasmoidItem.expanded && root.fullRepresentationvisualParent: root.compactRepresentationbackgroundHints: (Plasmoid.containmentDisplayHints & PlasmaCore.Types.ContainmentPrefersOpaqueBackground) ? PlasmaCore.AppletPopup.SolidBackground : PlasmaCore.AppletPopup.StandardBackgroundappletInterface: root.plasmoidItemproperty var oldStatus: PlasmaCore.Types.UnknownStatusonVisibleChanged: {if (!visible) {expandedSync.restart();Plasmoid.status = oldStatus;} else {oldStatus = Plasmoid.status;Plasmoid.status = PlasmaCore.Types.RequiresAttentionStatus;// This call currently fails and complains at runtime:// QWindow::setWindowState: QWindow::setWindowState does not accept Qt::WindowActivedialog.requestActivate();}}//It's a MouseEventListener to get all the events, so the eventfilter will be able to catch themmainItem: MouseEventListener {id: appletParentfocus: true// Workaround for QTBUG-146992// https://qt-project.atlassian.net/browse/QTBUG-146992// https://codereview.qt-project.org/c/qt/qtbase/+/738776enabled: dialog.visibleKeys.onEscapePressed: {root.plasmoidItem.expanded = false;}property real extraWidth: 0property real extraHeight: 0Layout.minimumWidth: root.fullRepresentation ? root.fullRepresentation.Layout.minimumWidth + extraWidth : 0Layout.minimumHeight: root.fullRepresentation ? root.fullRepresentation.Layout.minimumHeight + extraHeight : 0Layout.maximumWidth: root.fullRepresentation ? root.fullRepresentation.Layout.maximumWidth + extraWidth : InfinityLayout.maximumHeight: root.fullRepresentation ? root.fullRepresentation.Layout.maximumHeight + extraHeight : InfinityimplicitWidth: {if (root.fullRepresentation !== null) {/****/ if (root.fullRepresentation.Layout.preferredWidth > 0) {return root.fullRepresentation.Layout.preferredWidth + extraWidth;} else if (root.fullRepresentation.implicitWidth > 0) {return root.fullRepresentation.implicitWidth + extraWidth;}}return Kirigami.Units.iconSizes.sizeForLabels * 35;}implicitHeight: {if (root.fullRepresentation !== null) {/****/ if (root.fullRepresentation.Layout.preferredHeight > 0) {return root.fullRepresentation.Layout.preferredHeight + extraHeight;} else if (root.fullRepresentation.implicitHeight > 0) {return root.fullRepresentation.implicitHeight + extraHeight;}}return Kirigami.Units.iconSizes.sizeForLabels * 25;}onActiveFocusChanged: {if (activeFocus && root.fullRepresentation) {root.fullRepresentation.forceActiveFocus()}}// Draws a line between the applet dialog and the panelKSvg.SvgItem {id: separator// Only draw for popups of panel applets, not desktop appletsvisible: [PlasmaCore.Types.TopEdge, PlasmaCore.Types.LeftEdge, PlasmaCore.Types.RightEdge, PlasmaCore.Types.BottomEdge].includes(Plasmoid.location) && !dialog.marginanchors {topMargin: -dialog.topPaddingleftMargin: -dialog.leftPaddingrightMargin: -dialog.rightPaddingbottomMargin: -dialog.bottomPadding}z: 999 /* Draw the line on top of the applet */elementId: (Plasmoid.location === PlasmaCore.Types.TopEdge || Plasmoid.location === PlasmaCore.Types.BottomEdge) ? "horizontal-line" : "vertical-line"imagePath: "widgets/line"states: [State {when: Plasmoid.location === PlasmaCore.Types.TopEdgeAnchorChanges {target: separatoranchors {top: separator.parent.topleft: separator.parent.leftright: separator.parent.right}}PropertyChanges {separator.height: 1appletParent.extraHeight: 1appletParent.extraWidth: 0}},State {when: Plasmoid.location === PlasmaCore.Types.LeftEdgeAnchorChanges {target: separatoranchors {left: separator.parent.lefttop: separator.parent.topbottom: separator.parent.bottom}}PropertyChanges {separator.width: 1appletParent.extraHeight: 0appletParent.extraWidth: 1}},State {when: Plasmoid.location === PlasmaCore.Types.RightEdgeAnchorChanges {target: separatoranchors {top: separator.parent.topright: separator.parent.rightbottom: separator.parent.bottom}}PropertyChanges {separator.width: 1appletParent.extraHeight: 0appletParent.extraWidth: 1}},State {when: Plasmoid.location === PlasmaCore.Types.BottomEdgeAnchorChanges {target: separatoranchors {left: separator.parent.leftright: separator.parent.rightbottom: separator.parent.bottom}}PropertyChanges {separator.height: 1appletParent.extraHeight: 1appletParent.extraWidth: 0}}]}LayoutMirroring.enabled: Application.layoutDirection === Qt.RightToLeftLayoutMirroring.childrenInherit: true}}}