Warning, /plasma/plasma-desktop/applets/kicker/package/contents/ui/CompactRepresentation.qml is written in an unsupported language. File is not indexed.

0001 /*
0002     SPDX-FileCopyrightText: 2013-2014 Eike Hein <hein@kde.org>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 import QtQuick 2.15
0008 import QtQuick.Layouts 1.15
0009 
0010 import org.kde.plasma.core as PlasmaCore
0011 import org.kde.plasma.plasmoid 2.0
0012 import org.kde.kirigami 2.20 as Kirigami
0013 
0014 import org.kde.plasma.private.kicker 0.1 as Kicker
0015 
0016 Item {
0017     id: root
0018 
0019     readonly property bool vertical: (Plasmoid.formFactor === PlasmaCore.Types.Vertical)
0020     readonly property bool useCustomButtonImage: (Plasmoid.configuration.useCustomButtonImage
0021         && Plasmoid.configuration.customButtonImage.length !== 0)
0022 
0023     readonly property Component dashWindowComponent: kicker.isDash ? Qt.createComponent(Qt.resolvedUrl("./DashboardRepresentation.qml"), root) : null
0024     readonly property Kicker.DashboardWindow dashWindow: dashWindowComponent && dashWindowComponent.status === Component.Ready
0025         ? dashWindowComponent.createObject(root, { visualParent: root }) : null
0026 
0027     onWidthChanged: updateSizeHints()
0028     onHeightChanged: updateSizeHints()
0029 
0030     function updateSizeHints() {
0031         if (useCustomButtonImage) {
0032             if (vertical) {
0033                 const scaledHeight = Math.floor(parent.width * (buttonIcon.implicitHeight / buttonIcon.implicitWidth));
0034                 root.Layout.minimumHeight = scaledHeight;
0035                 root.Layout.maximumHeight = scaledHeight;
0036                 root.Layout.minimumWidth = -1;
0037             } else {
0038                 const scaledWidth = Math.floor(parent.height * (buttonIcon.implicitWidth / buttonIcon.implicitHeight));
0039                 root.Layout.minimumWidth = scaledWidth;
0040                 root.Layout.maximumWidth = scaledWidth;
0041                 root.Layout.minimumHeight = -1;
0042             }
0043         } else {
0044             root.Layout.minimumWidth = -1;
0045             root.Layout.minimumHeight = -1;
0046         }
0047     }
0048 
0049     Kirigami.Icon {
0050         id: buttonIcon
0051 
0052         anchors.fill: parent
0053 
0054         readonly property double aspectRatio: root.vertical
0055             ? implicitHeight / implicitWidth
0056             : implicitWidth / implicitHeight
0057 
0058         active: mouseArea.containsMouse && !justOpenedTimer.running
0059         source: root.useCustomButtonImage ? Plasmoid.configuration.customButtonImage : Plasmoid.configuration.icon
0060 
0061         // A custom icon could also be rectangular. However, if a square, custom, icon is given, assume it
0062         // to be an icon and round it to the nearest icon size again to avoid scaling artifacts.
0063         roundToIconSize: !root.useCustomButtonImage || aspectRatio === 1
0064 
0065         onSourceChanged: root.updateSizeHints()
0066     }
0067 
0068     MouseArea {
0069         id: mouseArea
0070 
0071         anchors.fill: parent
0072 
0073         property bool wasExpanded: false;
0074 
0075         activeFocusOnTab: true
0076         hoverEnabled: !root.dashWindow || !root.dashWindow.visible
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         Accessible.name: Plasmoid.title
0089         Accessible.description: toolTipSubText
0090         Accessible.role: Accessible.Button
0091 
0092         onPressed: {
0093             if (!kicker.isDash) {
0094                 wasExpanded = kicker.expanded
0095             }
0096         }
0097 
0098         onClicked: {
0099             if (kicker.isDash) {
0100                 root.dashWindow.toggle();
0101                 justOpenedTimer.start();
0102             } else {
0103                 kicker.expanded = !wasExpanded;
0104             }
0105         }
0106     }
0107 
0108     Connections {
0109         target: Plasmoid
0110         enabled: kicker.isDash && root.dashWindow !== null
0111 
0112         function onActivated() {
0113             root.dashWindow.toggle();
0114             justOpenedTimer.start();
0115         }
0116     }
0117 }