Warning, /frameworks/qqc2-desktop-style/org.kde.desktop/MenuItem.qml is written in an unsupported language. File is not indexed.
0001 /* 0002 SPDX-FileCopyrightText: 2017 Marco Martin <mart@kde.org> 0003 SPDX-FileCopyrightText: 2017 The Qt Company Ltd. 0004 SPDX-FileCopyrightText: 2023 ivan tkachenko <me@ratijas.tk> 0005 0006 SPDX-License-Identifier: LGPL-3.0-only OR GPL-2.0-or-later 0007 */ 0008 0009 0010 import QtQuick 0011 import QtQuick.Layouts 0012 import QtQuick.Templates as T 0013 import org.kde.kirigami as Kirigami 0014 import org.kde.desktop.private as Private 0015 0016 T.MenuItem { 0017 id: controlRoot 0018 0019 implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset, 0020 implicitContentWidth + leftPadding + rightPadding + (arrow ? arrow.implicitWidth : 0)) 0021 0022 implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset, 0023 implicitContentHeight + topPadding + bottomPadding, 0024 implicitIndicatorHeight + topPadding + bottomPadding) 0025 0026 baselineOffset: contentItem.y + contentItem.baselineOffset 0027 0028 // Let optional chaining operator fallback to undefined which would call a 0029 // RESET method so that width would follow implicit width automatically. 0030 width: parent?.width 0031 // Note: Binding height here to make sure menu items that are not visible are 0032 // properly collapsed, otherwise they will still occupy space inside the menu. 0033 height: visible ? undefined : 0 0034 0035 Layout.fillWidth: true 0036 padding: Kirigami.Units.smallSpacing 0037 verticalPadding: Kirigami.Settings.hasTransientTouchInput ? 8 : 4 // Hardcoded to the Breeze theme value 0038 hoverEnabled: !Kirigami.Settings.isMobile 0039 0040 Kirigami.MnemonicData.enabled: enabled && visible 0041 Kirigami.MnemonicData.controlType: Kirigami.MnemonicData.MenuItem 0042 Kirigami.MnemonicData.label: text 0043 Shortcut { 0044 //in case of explicit & the button manages it by itself 0045 enabled: !(RegExp(/\&[^\&]/).test(controlRoot.text)) 0046 sequence: controlRoot.Kirigami.MnemonicData.sequence 0047 onActivated: { 0048 if (controlRoot.checkable) { 0049 controlRoot.toggle(); 0050 } else { 0051 controlRoot.clicked(); 0052 } 0053 } 0054 } 0055 0056 contentItem: RowLayout { 0057 Item { 0058 Layout.preferredWidth: (controlRoot.ListView.view && controlRoot.ListView.view.hasCheckables) || controlRoot.checkable ? controlRoot.indicator.width : Kirigami.Units.smallSpacing 0059 } 0060 Kirigami.Icon { 0061 Layout.alignment: Qt.AlignVCenter 0062 visible: (controlRoot.ListView.view && controlRoot.ListView.view.hasIcons) 0063 || (controlRoot.icon.name !== "" || controlRoot.icon.source.toString() !== "") 0064 source: controlRoot.icon.name !== "" ? controlRoot.icon.name : controlRoot.icon.source 0065 color: controlRoot.icon.color 0066 Layout.preferredHeight: Kirigami.Settings.hasTransientTouchInput ? Kirigami.Units.iconSizes.smallMedium : Kirigami.Units.iconSizes.small 0067 Layout.preferredWidth: Layout.preferredHeight 0068 } 0069 Label { 0070 id: label 0071 Layout.alignment: Qt.AlignVCenter 0072 Layout.fillWidth: true 0073 0074 text: controlRoot.Kirigami.MnemonicData.richTextLabel 0075 font: controlRoot.font 0076 color: Kirigami.Theme.textColor 0077 elide: Text.ElideRight 0078 visible: controlRoot.text 0079 horizontalAlignment: Text.AlignLeft 0080 verticalAlignment: Text.AlignVCenter 0081 } 0082 Label { 0083 id: shortcut 0084 Layout.alignment: Qt.AlignVCenter 0085 visible: controlRoot.action && controlRoot.action.shortcut !== undefined 0086 0087 Shortcut { 0088 id: itemShortcut 0089 sequence: (shortcut.visible && controlRoot.action !== null) ? controlRoot.action.shortcut : "" 0090 } 0091 0092 text: visible ? itemShortcut.nativeText : "" 0093 font: controlRoot.font 0094 color: label.color 0095 horizontalAlignment: Text.AlignRight 0096 verticalAlignment: Text.AlignVCenter 0097 } 0098 Item { 0099 Layout.preferredWidth: Kirigami.Units.smallSpacing 0100 } 0101 } 0102 0103 arrow: Kirigami.Icon { 0104 x: controlRoot.mirrored ? controlRoot.padding : controlRoot.width - width - controlRoot.padding 0105 y: controlRoot.topPadding + (controlRoot.availableHeight - height) / 2 0106 source: controlRoot.mirrored ? "go-next-symbolic-rtl" : "go-next-symbolic" 0107 width: Kirigami.Units.iconSizes.small 0108 height: width 0109 visible: controlRoot.subMenu 0110 } 0111 0112 indicator: Private.CheckIndicator { 0113 x: controlRoot.mirrored ? controlRoot.width - width - controlRoot.rightPadding : controlRoot.leftPadding 0114 y: controlRoot.topPadding + (controlRoot.availableHeight - height) / 2 0115 0116 drawIcon: false // We're drawing it ourselves in this control 0117 0118 visible: controlRoot.checkable 0119 on: controlRoot.checked 0120 control: controlRoot 0121 } 0122 0123 background: Rectangle { 0124 implicitWidth: Kirigami.Units.gridUnit * 8 0125 opacity: (controlRoot.highlighted || controlRoot.hovered) ? 1 : 0 0126 color: Qt.alpha(Kirigami.Theme.focusColor, 0.3) 0127 border.color: Kirigami.Theme.focusColor 0128 border.width: 1 0129 radius: 3 0130 } 0131 }