Warning, /plasma/kdeplasma-addons/applets/grouping/package/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  *  SPDX-FileCopyrightText: 2016 David Edmundson <davidedmundson@kde.org>
0004  *
0005  *  SPDX-License-Identifier: GPL-2.0-or-later
0006  */
0007 import QtQuick 2.0
0008 import QtQuick.Layouts 1.1
0009 import QtQuick.Window 2.0
0010 
0011 import org.kde.plasma.core as PlasmaCore
0012 import org.kde.kirigami 2.20 as Kirigami
0013 import org.kde.kquickcontrolsaddons 2.0
0014 import org.kde.plasma.plasmoid
0015 
0016 PlasmaCore.ToolTipArea {
0017     id: root
0018     objectName: "org.kde.desktop-CompactApplet"
0019     anchors.fill: parent
0020 
0021     icon: plasmoid.icon
0022     mainText: plasmoid.toolTipMainText
0023     subText: plasmoid.toolTipSubText
0024     location: plasmoid.location
0025     active: !plasmoidItem.expanded
0026     textFormat: plasmoid.toolTipTextFormat
0027     mainItem: plasmoid.toolTipItem ? plasmoid.toolTipItem : null
0028     property PlasmoidItem plasmoidItem
0029 
0030     property Item fullRepresentation
0031     property Item compactRepresentation
0032 
0033     onCompactRepresentationChanged: {
0034         if (compactRepresentation) {
0035             compactRepresentation.parent = root;
0036             compactRepresentation.anchors.fill = root;
0037             compactRepresentation.visible = true;
0038         }
0039         root.visible = true;
0040     }
0041 
0042     onFullRepresentationChanged: {
0043 
0044         if (!fullRepresentation) {
0045             return;
0046         }
0047         //if the fullRepresentation size was restored to a stored size, or if is dragged from the desktop, restore popup size
0048         if (fullRepresentation.width > 0) {
0049             popupWindow.mainItem.width = Qt.binding(function() {
0050                 return fullRepresentation.width
0051             })
0052         } else if (fullRepresentation.Layout && fullRepresentation.Layout.preferredWidth > 0) {
0053             popupWindow.mainItem.width = Qt.binding(function() {
0054                 return fullRepresentation.Layout.preferredWidth
0055             })
0056         } else if (fullRepresentation.implicitWidth > 0) {
0057             popupWindow.mainItem.width = Qt.binding(function() {
0058                 return fullRepresentation.implicitWidth
0059             })
0060         } else {
0061             popupWindow.mainItem.width = Qt.binding(function() {
0062                 return Kirigami.Theme.gridUnit * 35
0063             })
0064         }
0065 
0066         if (fullRepresentation.height > 0) {
0067             popupWindow.mainItem.height = Qt.binding(function() {
0068                 return fullRepresentation.height
0069             })
0070         } else if (fullRepresentation.Layout && fullRepresentation.Layout.preferredHeight > 0) {
0071             popupWindow.mainItem.height = Qt.binding(function() {
0072                 return fullRepresentation.Layout.preferredHeight
0073             })
0074         } else if (fullRepresentation.implicitHeight > 0) {
0075             popupWindow.mainItem.height = Qt.binding(function() {
0076                 return fullRepresentation.implicitHeight
0077             })
0078         } else {
0079             popupWindow.mainItem.height = Qt.binding(function() {
0080                 return Kirigami.Theme.gridUnit * 25
0081             })
0082         }
0083 
0084         fullRepresentation.parent = appletParent;
0085         fullRepresentation.anchors.fill = fullRepresentation.parent;
0086     }
0087 
0088     Timer {
0089         id: expandedSync
0090         interval: 100
0091         onTriggered: plasmoidItem.expanded = popupWindow.visible;
0092     }
0093 
0094     Connections {
0095         target: plasmoid.internalAction("configure")
0096         function onTriggered() {
0097             plasmoidItem.expanded = false
0098         }
0099     }
0100 
0101     Connections {
0102         target: plasmoid
0103         function onContextualActionsAboutToShow() {
0104             root.hideToolTip()
0105         }
0106     }
0107 
0108     PlasmaCore.Dialog {
0109         id: popupWindow
0110         objectName: "popupWindow"
0111         flags: Qt.WindowStaysOnTopHint
0112         visible: plasmoidItem.expanded && fullRepresentation
0113         visualParent: compactRepresentation ? compactRepresentation : null
0114         location: plasmoid.location
0115         hideOnWindowDeactivate: root.plasmoidItem.hideOnWindowDeactivate
0116 
0117         property var oldStatus: PlasmaCore.Types.UnknownStatus
0118 
0119         //It's a MouseEventListener to get all the events, so the eventfilter will be able to catch them
0120         mainItem: MouseEventListener {
0121             id: appletParent
0122 
0123             focus: true
0124 
0125             Keys.onEscapePressed: {
0126                 plasmoidItem.expanded = false;
0127             }
0128 
0129             LayoutMirroring.enabled: Qt.application.layoutDirection === Qt.RightToLeft
0130             LayoutMirroring.childrenInherit: true
0131 
0132             Layout.minimumWidth: (fullRepresentation && fullRepresentation.Layout) ? fullRepresentation.Layout.minimumWidth : 0
0133             Layout.minimumHeight: (fullRepresentation && fullRepresentation.Layout) ? fullRepresentation.Layout.minimumHeight: 0
0134             Layout.maximumWidth: (fullRepresentation && fullRepresentation.Layout) ? fullRepresentation.Layout.maximumWidth : Infinity
0135             Layout.maximumHeight: (fullRepresentation && fullRepresentation.Layout) ? fullRepresentation.Layout.maximumHeight: Infinity
0136 
0137             onActiveFocusChanged: {
0138                 if (activeFocus && fullRepresentation) {
0139                     fullRepresentation.forceActiveFocus()
0140                 }
0141             }
0142         }
0143 
0144         onVisibleChanged: {
0145             if (!visible) {
0146                 expandedSync.restart();
0147                 plasmoid.status = oldStatus;
0148             } else {
0149                 oldStatus = plasmoid.status;
0150                 plasmoid.status = PlasmaCore.Types.RequiresAttentionStatus;
0151                 // This call currently fails and complains at runtime:
0152                 // QWindow::setWindowState: QWindow::setWindowState does not accept Qt::WindowActive
0153                 popupWindow.requestActivate();
0154             }
0155         }
0156     }
0157 }