Warning, /frameworks/qqc2-desktop-style/org.kde.desktop/Menu.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.Controls
0013 import QtQuick.Templates as T
0014 import org.kde.kirigami as Kirigami
0015 import org.kde.qqc2desktopstyle.private as StylePrivate
0016
0017 T.Menu {
0018 id: control
0019
0020 z: Kirigami.OverlayZStacking.z
0021
0022 implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset,
0023 contentWidth + leftPadding + rightPadding)
0024 implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset,
0025 contentHeight + topPadding + bottomPadding)
0026
0027 margins: 0
0028
0029 rightPadding: (scrollbar.visible && !mirrored) ? scrollbar.width : undefined
0030 leftPadding: (scrollbar.visible && mirrored) ? scrollbar.width : undefined
0031 horizontalPadding: style.pixelMetric("menuhmargin")
0032 verticalPadding: style.pixelMetric("menuvmargin")
0033
0034 StylePrivate.StyleItem {
0035 id: style
0036 visible: false
0037 }
0038
0039 delegate: MenuItem {}
0040
0041 contentItem: ListView {
0042 id: listview
0043 property bool hasCheckables: false
0044 property bool hasIcons: false
0045
0046 implicitWidth: contentItem.children
0047 .reduce((maxWidth, child) => Math.max(maxWidth, child.implicitWidth), 0)
0048 // Some non-zero value, so the whole menu does not get stuck zero
0049 // sized. Otherwise in RTL environment ListView just refuses to
0050 // report any usable contentHeight -- just zero.
0051 implicitHeight: Math.max(1, contentHeight)
0052 model: control.contentModel
0053
0054 spacing: 0 // Hardcoded to the Breeze theme value
0055
0056 interactive: Window.window
0057 ? contentHeight + control.topPadding + control.bottomPadding > Window.window.height
0058 : false
0059 clip: true
0060 currentIndex: control.currentIndex
0061
0062 keyNavigationEnabled: true
0063 keyNavigationWraps: true
0064
0065 ScrollBar.vertical: ScrollBar {
0066 id: scrollbar
0067 parent: listview.parent
0068 anchors.top: listview.top
0069 anchors.left: listview.right
0070 anchors.bottom: listview.bottom
0071 }
0072
0073 // mimic qtwidgets behaviour regarding menu highlighting
0074 Connections {
0075 target: control.contentItem.currentItem
0076
0077 function onHoveredChanged() {
0078 const item = control.contentItem.currentItem;
0079 if (item instanceof T.MenuItem && item.highlighted
0080 && !item.subMenu && !item.hovered) {
0081 control.currentIndex = -1
0082 }
0083 }
0084 }
0085 }
0086
0087 Connections {
0088 target: control.contentItem.contentItem
0089
0090 function onVisibleChildrenChanged() {
0091 const children = control.contentItem.contentItem.visibleChildren;
0092 let hasCheckables = control.contentItem.hasCheckables;
0093 let hasIcons = control.contentItem.hasIcons;
0094 for (const child of children) {
0095 if (child.checkable) {
0096 hasCheckables = true;
0097 }
0098 if (child.icon && child.icon.hasOwnProperty("name")
0099 && (child.icon.name !== "" || child.icon.source.toString() !== "")) {
0100 hasIcons = true;
0101 }
0102 }
0103 control.contentItem.hasCheckables = hasCheckables;
0104 control.contentItem.hasIcons = hasIcons;
0105 }
0106 }
0107
0108 enter: Transition {
0109 NumberAnimation {
0110 property: "opacity"
0111 from: 0
0112 to: 1
0113 easing.type: Easing.InOutQuad
0114 duration: Kirigami.Units.shortDuration
0115 }
0116 }
0117
0118 exit: Transition {
0119 NumberAnimation {
0120 property: "opacity"
0121 from: 1
0122 to: 0
0123 easing.type: Easing.InOutQuad
0124 duration: Kirigami.Units.shortDuration
0125 }
0126 }
0127
0128 background: Kirigami.ShadowedRectangle {
0129 radius: 3
0130 implicitWidth: Kirigami.Units.gridUnit * 8
0131 color: Kirigami.Theme.backgroundColor
0132
0133 border.color: Kirigami.ColorUtils.linearInterpolation(Kirigami.Theme.backgroundColor, Kirigami.Theme.textColor, Kirigami.Theme.frameContrast)
0134 border.width: 1
0135
0136 shadow.xOffset: 0
0137 shadow.yOffset: 2
0138 shadow.color: Qt.rgba(0, 0, 0, 0.3)
0139 shadow.size: 8
0140 }
0141 }