Warning, /plasma/plasma-simplemenu/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.0
0008 import QtQuick.Layouts 1.1
0009 
0010 import org.kde.plasma.plasmoid 2.0
0011 import org.kde.plasma.core 2.0 as PlasmaCore
0012 
0013 Item {
0014     id: root
0015 
0016     readonly property var screenGeometry: plasmoid.screenGeometry
0017     readonly property bool inPanel: (plasmoid.location == PlasmaCore.Types.TopEdge
0018         || plasmoid.location == PlasmaCore.Types.RightEdge
0019         || plasmoid.location == PlasmaCore.Types.BottomEdge
0020         || plasmoid.location == PlasmaCore.Types.LeftEdge)
0021     readonly property bool vertical: (plasmoid.formFactor == PlasmaCore.Types.Vertical)
0022     readonly property bool useCustomButtonImage: (plasmoid.configuration.useCustomButtonImage
0023         && plasmoid.configuration.customButtonImage.length != 0)
0024     property QtObject dashWindow: null
0025 
0026     Plasmoid.status: dashWindow && dashWindow.visible ? PlasmaCore.Types.RequiresAttentionStatus : PlasmaCore.Types.PassiveStatus
0027 
0028     onWidthChanged: updateSizeHints()
0029     onHeightChanged: updateSizeHints()
0030 
0031     function updateSizeHints() {
0032         if (useCustomButtonImage) {
0033             if (vertical) {
0034                 var scaledHeight = Math.floor(parent.width * (buttonIcon.implicitHeight / buttonIcon.implicitWidth));
0035                 root.Layout.minimumHeight = scaledHeight;
0036                 root.Layout.maximumHeight = scaledHeight;
0037                 root.Layout.minimumWidth = units.iconSizes.small;
0038                 root.Layout.maximumWidth = inPanel ? units.iconSizeHints.panel : -1;
0039             } else {
0040                 var scaledWidth = Math.floor(parent.height * (buttonIcon.implicitWidth / buttonIcon.implicitHeight));
0041                 root.Layout.minimumWidth = scaledWidth;
0042                 root.Layout.maximumWidth = scaledWidth;
0043                 root.Layout.minimumHeight = units.iconSizes.small;
0044                 root.Layout.maximumHeight = inPanel ? units.iconSizeHints.panel : -1;
0045             }
0046         } else {
0047             root.Layout.minimumWidth = units.iconSizes.small;
0048             root.Layout.maximumWidth = inPanel ? units.iconSizeHints.panel : -1;
0049             root.Layout.minimumHeight = units.iconSizes.small
0050             root.Layout.maximumHeight = inPanel ? units.iconSizeHints.panel : -1;
0051         }
0052     }
0053 
0054     Connections {
0055         target: units.iconSizeHints
0056 
0057         onPanelChanged: updateSizeHints()
0058     }
0059 
0060     PlasmaCore.IconItem {
0061         id: buttonIcon
0062 
0063         anchors.fill: parent
0064 
0065         readonly property double aspectRatio: (vertical ? implicitHeight / implicitWidth
0066             : implicitWidth / implicitHeight)
0067 
0068         source: useCustomButtonImage ? plasmoid.configuration.customButtonImage : plasmoid.configuration.icon
0069 
0070         active: mouseArea.containsMouse
0071 
0072         smooth: true
0073 
0074         // A custom icon could also be rectangular. However, if a square, custom, icon is given, assume it
0075         // to be an icon and round it to the nearest icon size again to avoid scaling artefacts.
0076         roundToIconSize: !useCustomButtonImage || aspectRatio === 1
0077 
0078         onSourceChanged: updateSizeHints()
0079     }
0080 
0081     MouseArea
0082     {
0083         id: mouseArea
0084 
0085         anchors.fill: parent
0086 
0087         hoverEnabled: true
0088 
0089         onClicked: {
0090             dashWindow.visible = !dashWindow.visible;
0091         }
0092     }
0093 
0094     Component.onCompleted: {
0095         dashWindow = Qt.createQmlObject("MenuRepresentation {}", root);
0096         plasmoid.activated.connect(function() {
0097             dashWindow.visible = !dashWindow.visible;
0098         });
0099     }
0100 }