Plasma

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

KDE's Doxygen guidelines are available online.