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

0001 /*
0002  * SPDX-FileCopyrightText: 2020 Carson Black <uhhadd@gmail.com>
0003  *
0004  * SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 import QtQuick 2.15
0008 import QtQuick.Controls 2.15
0009 
0010 import org.kde.ksvg 1.0 as KSvg
0011 import org.kde.plasma.components 3.0 as PC3
0012 import org.kde.kirigami 2.12 as Kirigami
0013 
0014 AbstractButton {
0015     id: controlRoot
0016 
0017     property bool menuIsOpen: false
0018 
0019     signal activated()
0020 
0021     // QMenu opens on press, so we'll replicate that here
0022     hoverEnabled: true
0023 
0024     // This will trigger even if hoverEnabled has just became true and the
0025     // mouse cursor is already hovering.
0026     //
0027     // In practice, this never works, at least on X11: when menuIsOpen the
0028     // hover event would not be delivered. Instead we rely on
0029     // plasmoid.requestActivateIndex signal to filter
0030     // QEvent::MouseMove events and tell us when to change the index.
0031     onHoveredChanged: if (hovered && menuIsOpen) { activated(); }
0032 
0033     // You don't actually have to "close" the menu via click/pressed handlers.
0034     // Instead, the menu will be closed automatically, as by any
0035     // other "outside of the menu" click event.
0036     onPressed: activated()
0037 
0038     enum State {
0039         Rest,
0040         Hover,
0041         Down
0042     }
0043 
0044     property int menuState: {
0045         // can't trust hovered state while QMenu is grabbing mouse pointer.
0046         if (down) {
0047             return MenuDelegate.State.Down;
0048         } else if (hovered && !menuIsOpen) {
0049             return MenuDelegate.State.Hover;
0050         }
0051         return MenuDelegate.State.Rest;
0052     }
0053 
0054     Kirigami.MnemonicData.controlType: Kirigami.MnemonicData.SecondaryControl
0055     Kirigami.MnemonicData.label: text
0056 
0057     topPadding: rest.margins.top
0058     leftPadding: rest.margins.left
0059     rightPadding: rest.margins.right
0060     bottomPadding: rest.margins.bottom
0061 
0062     Accessible.description: i18nc("@info:usagetip", "Open a menu")
0063 
0064     background: KSvg.FrameSvgItem {
0065         id: rest
0066         imagePath: "widgets/menubaritem"
0067         prefix: switch (controlRoot.menuState) {
0068             case MenuDelegate.State.Down: return "pressed";
0069             case MenuDelegate.State.Hover: return "hover";
0070             case MenuDelegate.State.Rest: return "normal";
0071         }
0072     }
0073 
0074     contentItem: PC3.Label {
0075         text: controlRoot.Kirigami.MnemonicData.richTextLabel
0076         textFormat: Text.StyledText
0077         verticalAlignment: Text.AlignVCenter
0078         elide: Text.ElideRight
0079         color: controlRoot.menuState === MenuDelegate.State.Rest ? Kirigami.Theme.textColor : Kirigami.Theme.highlightedTextColor
0080     }
0081 }