Libplasma

Menu.qml
1/*
2 SPDX-FileCopyrightText: 2016 Marco Martin <mart@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7import QtQuick
8import QtQuick.Window
9import QtQuick.Controls
10import QtQuick.Templates as T
11import org.kde.ksvg as KSvg
12//NOTE: importing PlasmaCore is necessary in order to make KSvg load the current Plasma Theme
13import org.kde.plasma.core as PlasmaCore
14import org.kde.kirigami as Kirigami
15
16T.Menu {
17 id: control
18
19 implicitWidth: Math.max(background ? background.implicitWidth : 0,
20 contentItem ? contentItem.implicitWidth + leftPadding + rightPadding : 0)
21 implicitHeight: Math.max(background ? background.implicitHeight : 0,
22 contentItem ? contentItem.implicitHeight : 0) + topPadding + bottomPadding
23
24 delegate: MenuItem { width: parent.width; onImplicitWidthChanged: control.contentItem.contentItem.childrenChanged() }
25
26 margins: 0
27
28 topPadding: (background as KSvg.FrameSvgItem)?.margins.top ?? undefined
29 leftPadding: (background as KSvg.FrameSvgItem)?.margins.left ?? undefined
30 rightPadding: (background as KSvg.FrameSvgItem)?.margins.right ?? undefined
31 bottomPadding: (background as KSvg.FrameSvgItem)?.margins.bottom ?? undefined
32
33 contentItem: ListView {
34 implicitHeight: contentHeight
35 property bool hasCheckables: false
36 property bool hasIcons: false
37 model: control.contentModel
38
39 implicitWidth: {
40 var maxWidth = 0;
41 for (var i = 0; i < contentItem.children.length; ++i) {
42 maxWidth = Math.max(maxWidth, contentItem.children[i].implicitWidth);
43 }
44 return maxWidth;
45 }
46
47 interactive: Window.window ? contentHeight + control.topPadding + control.bottomPadding > Window.window.height : false
48 clip: true
49 currentIndex: control.currentIndex || 0
50 keyNavigationEnabled: true
51 keyNavigationWraps: true
52
53 T.ScrollBar.vertical: ScrollBar {}
54 }
55
56 Connections {
57 target: control.contentItem.contentItem
58
59 function onChildrenChanged() {
60 for (var i in control.contentItem.contentItem.children) {
61 var child = control.contentItem.contentItem.children[i];
62 if (child.checkable) {
63 control.contentItem.hasCheckables = true;
64 }
65 if (child.icon && child.icon.hasOwnProperty("name") && (child.icon.name.length > 0 || child.icon.source.length > 0)) {
66 control.contentItem.hasIcons = true;
67 }
68 }
69 }
70 }
71
72 enter: Transition {
73 NumberAnimation {
74 property: "opacity"
75 from: 0
76 to: 1
77 easing.type: Easing.InOutQuad
78 duration: Kirigami.Units.shortDuration
79 }
80 }
81
82 exit: Transition {
83 NumberAnimation {
84 property: "opacity"
85 from: 1
86 to: 0
87 easing.type: Easing.InOutQuad
88 duration: Kirigami.Units.shortDuration
89 }
90 }
91
92 background: KSvg.FrameSvgItem {
93 imagePath: "widgets/background"
94 implicitWidth: Kirigami.Units.gridUnit * 8
95 implicitHeight: Kirigami.Units.gridUnit * 2
96 }
97}
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:01:35 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.