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 2.7
0011 import QtQuick.Layouts 1.2
0012 import QtQuick.Controls 2.15
0013 import QtQuick.Templates 2.15 as T
0014 import org.kde.qqc2desktopstyle.private 1.0 as StylePrivate
0015 import org.kde.kirigami 2.12 as Kirigami
0016 
0017 T.Menu {
0018     id: control
0019 
0020     implicitWidth: Math.max(background ? background.implicitWidth : 0,
0021                             contentItem ? contentItem.implicitWidth + leftPadding + rightPadding : 0)
0022     implicitHeight: Math.max(background ? background.implicitHeight : 0,
0023                              contentItem ? contentItem.implicitHeight : 0) + topPadding + bottomPadding
0024 
0025     margins: 0
0026     horizontalPadding: style.pixelMetric("menuhmargin")
0027     verticalPadding: style.pixelMetric("menuvmargin")
0028     StylePrivate.StyleItem {
0029         id: style
0030         visible: false
0031     }
0032 
0033     delegate: MenuItem { onImplicitWidthChanged: control.contentItem.contentItem.childrenChanged() }
0034 
0035     contentItem: ListView {
0036         implicitHeight: contentHeight
0037         property bool hasCheckables: false
0038         property bool hasIcons: false
0039         model: control.contentModel
0040 
0041         implicitWidth: {
0042             let maxWidth = 0;
0043             for (let i = 0; i < contentItem.children.length; ++i) {
0044                 maxWidth = Math.max(maxWidth, contentItem.children[i].implicitWidth);
0045             }
0046             return maxWidth;
0047         }
0048 
0049         spacing: 0 // Hardcoded to the Breeze theme value
0050 
0051         interactive: ApplicationWindow.window ? contentHeight > ApplicationWindow.window.height : false
0052         clip: true
0053         currentIndex: control.currentIndex || 0
0054         keyNavigationEnabled: true
0055         keyNavigationWraps: true
0056 
0057         ScrollBar.vertical: ScrollBar {}
0058 
0059         // mimic qtwidgets behaviour in regards to menu highlighting
0060         Connections {
0061             target: control.contentItem.currentItem
0062 
0063             function onHoveredChanged() {
0064                 const item = control.contentItem.currentItem;
0065                 if (item instanceof T.MenuItem && item.highlighted
0066                         && !item.subMenu && !item.hovered) {
0067                     control.currentIndex = -1
0068                 }
0069             }
0070         }
0071     }
0072 
0073     Connections {
0074         target: control.contentItem.contentItem
0075 
0076         function onVisibleChildrenChanged() {
0077             const children = control.contentItem.contentItem.visibleChildren;
0078             let hasCheckables = control.contentItem.hasCheckables;
0079             let hasIcons = control.contentItem.hasIcons;
0080             for (let i in children) {
0081                 const child = children[i];
0082                 if (child.checkable) {
0083                     hasCheckables = true;
0084                 }
0085                 if (child.icon && child.icon.hasOwnProperty("name")
0086                         && (child.icon.name !== "" || child.icon.source.toString() !== "")) {
0087                     hasIcons = true;
0088                 }
0089             }
0090             control.contentItem.hasCheckables = hasCheckables;
0091             control.contentItem.hasIcons = hasIcons;
0092         }
0093     }
0094 
0095     enter: Transition {
0096         NumberAnimation {
0097             property: "opacity"
0098             from: 0
0099             to: 1
0100             easing.type: Easing.InOutQuad
0101             duration: Kirigami.Units.shortDuration
0102         }
0103     }
0104 
0105     exit: Transition {
0106         NumberAnimation {
0107             property: "opacity"
0108             from: 1
0109             to: 0
0110             easing.type: Easing.InOutQuad
0111             duration: Kirigami.Units.shortDuration
0112         }
0113     }
0114 
0115     background: Kirigami.ShadowedRectangle {
0116         radius: 3
0117         implicitWidth: Kirigami.Units.gridUnit * 8
0118         color: Kirigami.Theme.backgroundColor
0119 
0120         property color borderColor: Kirigami.Theme.textColor
0121         border.color: Qt.rgba(borderColor.r, borderColor.g, borderColor.b, 0.3)
0122         border.width: 1
0123 
0124         shadow.xOffset: 0
0125         shadow.yOffset: 2
0126         shadow.color: Qt.rgba(0, 0, 0, 0.3)
0127         shadow.size: 8
0128     }
0129 }