Libplasma

MenuItem.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.Layouts
9import QtQuick.Templates as T
10import org.kde.ksvg as KSvg
11//NOTE: importing PlasmaCore is necessary in order to make KSvg load the current Plasma Theme
12import org.kde.plasma.core as PlasmaCore
13import org.kde.kirigami as Kirigami
14
15T.MenuItem {
16 id: controlRoot
17
18 implicitWidth: Math.max(background ? background.implicitWidth : 0,
19 contentItem.implicitWidth + leftPadding + rightPadding + (arrow ? arrow.implicitWidth : 0))
20 implicitHeight: Math.max(background ? background.implicitHeight : 0,
21 Math.max(contentItem.implicitHeight,
22 indicator ? indicator.implicitHeight : 0) + topPadding + bottomPadding)
23 baselineOffset: contentItem.y + contentItem.baselineOffset
24
25 leftPadding: highlight.margins.left
26 topPadding: highlight.margins.top
27 rightPadding: highlight.margins.right
28 bottomPadding: highlight.margins.bottom
29 spacing: Kirigami.Units.smallSpacing
30 hoverEnabled: true
31
32 Kirigami.MnemonicData.enabled: controlRoot.enabled && controlRoot.visible
33 Kirigami.MnemonicData.controlType: Kirigami.MnemonicData.MenuItem
34 Kirigami.MnemonicData.label: controlRoot.text
35 Shortcut {
36 //in case of explicit & the button manages it by itself
37 enabled: !(RegExp(/\&[^\&]/).test(controlRoot.text))
38 sequence: controlRoot.Kirigami.MnemonicData.sequence
39 onActivated: {
40 if (controlRoot.checkable) {
41 controlRoot.toggle();
42 } else {
43 controlRoot.clicked();
44 }
45 }
46 }
47
48 contentItem: RowLayout {
49 Item {
50 Layout.preferredWidth: (controlRoot.ListView.view && controlRoot.ListView.view.hasCheckables) || controlRoot.checkable ? controlRoot.indicator.width : Kirigami.Units.smallSpacing
51 }
53 Layout.alignment: Qt.AlignVCenter
54 visible: (controlRoot.ListView.view && controlRoot.ListView.view.hasIcons) || (controlRoot.icon != undefined && (controlRoot.icon.name.length > 0 || controlRoot.icon.source.length > 0))
55 source: controlRoot.icon ? (controlRoot.icon.name || controlRoot.icon.source) : ""
56 Layout.preferredHeight: Math.max(label.height, Kirigami.Units.iconSizes.small)
57 Layout.preferredWidth: Layout.preferredHeight
58 }
59 Label {
60 id: label
61 Layout.alignment: Qt.AlignVCenter
62 Layout.fillWidth: true
63
64 text: controlRoot.Kirigami.MnemonicData.richTextLabel
65 font: controlRoot.font
66 elide: Text.ElideRight
67 visible: controlRoot.text
68 horizontalAlignment: Text.AlignLeft
69 verticalAlignment: Text.AlignVCenter
70 }
71 }
72
73 arrow: Kirigami.Icon {
74 x: controlRoot.mirrored ? controlRoot.padding : controlRoot.width - width - controlRoot.padding
75 y: controlRoot.topPadding + (controlRoot.availableHeight - height) / 2
76 source: controlRoot.mirrored ? "go-next-symbolic-rtl" : "go-next-symbolic"
77 width: Math.max(label.height, Kirigami.Units.iconSizes.small)
78 height: width
79 visible: controlRoot.subMenu
80 }
81
82 indicator: Loader {
83 x: controlRoot.mirrored ? controlRoot.width - width - controlRoot.rightPadding : controlRoot.leftPadding
84 y: controlRoot.topPadding + Math.round((controlRoot.availableHeight - height) / 2)
85
86 visible: controlRoot.checkable
87 sourceComponent: controlRoot.autoExclusive ? radioComponent : checkComponent
88 }
89
90 Component {
91 id: radioComponent
92 RadioIndicator {
93 control: controlRoot
94 }
95 }
96 Component {
97 id: checkComponent
98 CheckIndicator {
99 control: controlRoot
100 }
101 }
102
103 background: Item {
104 implicitWidth: Kirigami.Units.gridUnit * 8
105
106 KSvg.FrameSvgItem {
107 id: highlight
108 imagePath: "widgets/viewitem"
109 prefix: "hover"
110 anchors.fill: parent
111 opacity: {
112 if (controlRoot.highlighted || controlRoot.hovered || controlRoot.down) {
113 return 1
114 } else {
115 return 0
116 }
117 }
118 Behavior on opacity {
119 enabled: Kirigami.Units.shortDuration > 0
120 NumberAnimation {
121 duration: Kirigami.Units.shortDuration
122 }
123 }
124 }
125 }
126}
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:10:41 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.