Warning, /plasma/plasma-workspace/applets/appmenu/package/contents/ui/main.qml is written in an unsupported language. File is not indexed.

0001 /*
0002     SPDX-FileCopyrightText: 2013 Heena Mahour <heena393@gmail.com>
0003     SPDX-FileCopyrightText: 2013 Sebastian Kügler <sebas@kde.org>
0004     SPDX-FileCopyrightText: 2016 Kai Uwe Broulik <kde@privat.broulik.de>
0005 
0006     SPDX-License-Identifier: GPL-2.0-or-later
0007 */
0008 import QtQuick 2.15
0009 import QtQuick.Layouts 1.15
0010 import QtQuick.Controls 2.15
0011 // Deliberately imported after QtQuick to avoid missing restoreMode property in Binding. Fix in Qt 6.
0012 import QtQml 2.15
0013 
0014 import org.kde.plasma.plasmoid 2.0
0015 import org.kde.kquickcontrolsaddons 2.0 // For KCMShell
0016 import org.kde.plasma.core as PlasmaCore
0017 import org.kde.plasma.private.keyboardindicator as KeyboardIndicator
0018 import org.kde.plasma.components 3.0 as PlasmaComponents3
0019 import org.kde.plasma.private.appmenu 1.0 as AppMenuPrivate
0020 import org.kde.kirigami 2.5 as Kirigami
0021 
0022 PlasmoidItem {
0023     id: root
0024 
0025     readonly property bool vertical: Plasmoid.formFactor === PlasmaCore.Types.Vertical
0026     readonly property bool view: Plasmoid.configuration.compactView
0027 
0028     onViewChanged: {
0029         Plasmoid.view = view;
0030     }
0031 
0032     Plasmoid.constraintHints: Plasmoid.CanFillArea
0033     preferredRepresentation: Plasmoid.configuration.compactView ? compactRepresentation : fullRepresentation
0034 
0035     // Only exists because the default CompactRepresentation doesn't expose a
0036     // way to mark its icon as disabled.
0037     // TODO remove once it gains that feature.
0038     compactRepresentation: PlasmaComponents3.ToolButton {
0039         readonly property int fakeIndex: 0
0040         Layout.fillWidth: false
0041         Layout.fillHeight: false
0042         Layout.minimumWidth: implicitWidth
0043         Layout.maximumWidth: implicitWidth
0044         enabled: appMenuModel.menuAvailable
0045         checkable: appMenuModel.menuAvailable && Plasmoid.currentIndex === fakeIndex
0046         checked: checkable
0047         icon.name: "application-menu"
0048 
0049         display: PlasmaComponents3.AbstractButton.IconOnly
0050         text: Plasmoid.title
0051         Accessible.description: toolTipSubText
0052 
0053         onClicked: Plasmoid.trigger(this, 0);
0054     }
0055 
0056     fullRepresentation: GridLayout {
0057         id: buttonGrid
0058 
0059         Plasmoid.status: {
0060             if (appMenuModel.menuAvailable && Plasmoid.currentIndex > -1 && buttonRepeater.count > 0) {
0061                 return PlasmaCore.Types.NeedsAttentionStatus;
0062             } else {
0063                 //when we're not enabled set to active to show the configure button
0064                 return buttonRepeater.count > 0 ? PlasmaCore.Types.ActiveStatus : PlasmaCore.Types.HiddenStatus;
0065             }
0066         }
0067 
0068         LayoutMirroring.enabled: Qt.application.layoutDirection === Qt.RightToLeft
0069         Layout.minimumWidth: implicitWidth
0070         Layout.minimumHeight: implicitHeight
0071 
0072         flow: root.vertical ? GridLayout.TopToBottom : GridLayout.LeftToRight
0073         rowSpacing: 0
0074         columnSpacing: 0
0075 
0076         Binding {
0077             target: plasmoid
0078             property: "buttonGrid"
0079             value: buttonGrid
0080             restoreMode: Binding.RestoreNone
0081         }
0082 
0083         Connections {
0084             target: Plasmoid
0085             function onRequestActivateIndex(index: int) {
0086                 const button = buttonRepeater.itemAt(index);
0087                 if (button) {
0088                     button.activated();
0089                 }
0090             }
0091         }
0092 
0093         Connections {
0094             target: Plasmoid
0095             function onActivated() {
0096                 const button = buttonRepeater.itemAt(0);
0097                 if (button) {
0098                     button.activated();
0099                 }
0100             }
0101         }
0102 
0103         PlasmaComponents3.ToolButton {
0104             id: noMenuPlaceholder
0105             visible: buttonRepeater.count === 0
0106             text: Plasmoid.title
0107             Layout.fillWidth: root.vertical
0108             Layout.fillHeight: !root.vertical
0109         }
0110 
0111         Repeater {
0112             id: buttonRepeater
0113             model: appMenuModel.visible ? appMenuModel : null
0114 
0115             MenuDelegate {
0116                 readonly property int buttonIndex: index
0117 
0118                 Layout.fillWidth: root.vertical
0119                 Layout.fillHeight: !root.vertical
0120                 text: activeMenu
0121                 // TODO: Alt and other modifiers might be unavailable on Wayland
0122                 Kirigami.MnemonicData.active: altState.pressed
0123 
0124                 down: pressed || Plasmoid.currentIndex === index
0125                 visible: text !== "" && model.activeActions.visible
0126 
0127                 menuIsOpen: Plasmoid.currentIndex !== -1
0128                 onActivated: Plasmoid.trigger(this, index)
0129 
0130                 // So we can show mnemonic underlines only while Alt is pressed
0131                 KeyboardIndicator.KeyState {
0132                     id: altState
0133                     key: Qt.Key_Alt
0134                 }
0135             }
0136         }
0137         Item {
0138             Layout.preferredWidth: 0
0139             Layout.preferredHeight: 0
0140             Layout.fillWidth: true
0141             Layout.fillHeight: true
0142         }
0143     }
0144 
0145     AppMenuPrivate.AppMenuModel {
0146         id: appMenuModel
0147         containmentStatus: Plasmoid.containment.status
0148         screenGeometry: root.screenGeometry
0149         onRequestActivateIndex: Plasmoid.requestActivateIndex(index)
0150         Component.onCompleted: {
0151             Plasmoid.model = appMenuModel;
0152         }
0153     }
0154 }