Kirigami2

GlobalDrawerActionItem.qml
1 /*
2  * SPDX-FileCopyrightText: 2015 Marco Martin <[email protected]>
3  *
4  * SPDX-License-Identifier: LGPL-2.0-or-later
5  */
6 
7 import QtQuick 2.6
8 import QtQuick.Window 2.6
9 import QtQuick.Controls 2.0 as QQC2
10 import QtQuick.Controls.impl 2.3 as QQC2Impl
11 import QtQuick.Layouts 1.2
12 import org.kde.kirigami 2.5 as Kirigami
13 
14 Kirigami.AbstractListItem {
15  id: listItem
16 
17  readonly property bool wideMode: width > height * 2
18  readonly property bool isSeparator: modelData.hasOwnProperty("separator") && modelData.separator
19 
20  readonly property bool isExpandible: modelData && modelData.hasOwnProperty("expandible") && modelData.expandible
21 
22  checked: modelData.checked || (actionsMenu && actionsMenu.visible)
23  width: parent.width
24 
25  contentItem: RowLayout {
26  spacing: Kirigami.Units.largeSpacing
27 
28  Kirigami.Icon {
29  id: iconItem
30  color: modelData.icon.color
31  source: modelData.icon.name || modelData.icon.source
32 
33  readonly property int size: Kirigami.Units.iconSizes.smallMedium
34  Layout.minimumHeight: size
35  Layout.maximumHeight: size
36  Layout.minimumWidth: size
37  Layout.maximumWidth: size
38  selected: (listItem.highlighted || listItem.checked || listItem.pressed)
39  visible: source !== undefined
40  }
41 
42  QQC2Impl.MnemonicLabel {
43  id: labelItem
44  text: width > height * 2 ? listItem.Kirigami.MnemonicData.mnemonicLabel : ""
45  Layout.fillWidth: true
46  mnemonicVisible: listItem.Kirigami.MnemonicData.active
47  color: (listItem.highlighted || listItem.checked || listItem.pressed) ? listItem.activeTextColor : listItem.textColor
48  elide: Text.ElideRight
49  font: listItem.font
50  opacity: {
51  if (root.collapsed) {
52  return 0;
53  } else if (!listItem.enabled) {
54  return 0.6;
55  } else {
56  return 1.0;
57  }
58  }
59  Behavior on opacity {
60  NumberAnimation {
61  duration: Kirigami.Units.longDuration/2
62  easing.type: Easing.InOutQuad
63  }
64  }
65  }
66 
67  Kirigami.Separator {
68  id: separatorAction
69 
70  visible: listItem.isSeparator
71  Layout.fillWidth: true
72  }
73 
74  Kirigami.Icon {
75  Shortcut {
76  sequence: listItem.Kirigami.MnemonicData.sequence
77  onActivated: listItem.clicked()
78  }
79  isMask: true
80  Layout.alignment: Qt.AlignVCenter
81  Layout.leftMargin: !root.collapsed ? 0 : -width
82  Layout.preferredHeight: !root.collapsed ? Kirigami.Units.iconSizes.small : Kirigami.Units.iconSizes.small/2
83  opacity: 0.7
84  selected: listItem.checked || listItem.pressed
85  Layout.preferredWidth: Layout.preferredHeight
86  source: (LayoutMirroring.enabled ? "go-next-symbolic-rtl" : "go-next-symbolic")
87  visible: (!isExpandible || root.collapsed) && !listItem.isSeparator && modelData.hasOwnProperty("children") && modelData.children!==undefined && modelData.children.length > 0
88  }
89  }
90  Kirigami.MnemonicData.enabled: listItem.enabled && listItem.visible
91  Kirigami.MnemonicData.controlType: Kirigami.MnemonicData.MenuItem
92  Kirigami.MnemonicData.label: modelData.text
93  property ActionsMenu actionsMenu: ActionsMenu {
94  x: Qt.application.layoutDirection === Qt.RightToLeft ? -width : listItem.width
95  actions: modelData.hasOwnProperty("children") ? modelData.children : null
96  submenuComponent: Component {
97  ActionsMenu {}
98  }
99  onVisibleChanged: {
100  if (visible) {
101  stackView.openSubMenu = listItem.actionsMenu;
102  } else if (stackView.openSubMenu === listItem.actionsMenu) {
103  stackView.openSubMenu = null;
104  }
105  }
106  }
107 
108  // TODO: animate the hide by collapse
109  visible: (model ? model.visible || model.visible===undefined : modelData.visible) && opacity > 0
110  opacity: !root.collapsed || iconItem.source.length > 0
111  Behavior on opacity {
112  NumberAnimation {
113  duration: Kirigami.Units.longDuration/2
114  easing.type: Easing.InOutQuad
115  }
116  }
117  enabled: !isSeparator && ( (model && model.enabled !== undefined) ? model.enabled : modelData.enabled)
118 
119  hoverEnabled: (!isExpandible || root.collapsed) && !Kirigami.Settings.tabletMode
120  sectionDelegate: isExpandible
121  font.pointSize: isExpandible ? Kirigami.Theme.defaultFont.pointSize * 1.30 : Kirigami.Theme.defaultFont.pointSize
122  height: implicitHeight * opacity
123 
124  data: [
125  QQC2.ToolTip {
126  visible: !listItem.isSeparator && (modelData.hasOwnProperty("tooltip") && modelData.tooltip.length || root.collapsed) && (!actionsMenu || !actionsMenu.visible) && listItem.hovered && text.length > 0
127  text: modelData.hasOwnProperty("tooltip") && modelData.tooltip.length ? modelData.tooltip : modelData.text
128  delay: Kirigami.Units.toolTipDelay
129  timeout: 5000
130  y: listItem.height/2 - height/2
131  x: Qt.application.layoutDirection === Qt.RightToLeft ? -width : listItem.width
132  }
133  ]
134 
135  onHoveredChanged: {
136  if (!hovered) {
137  return;
138  }
139  if (stackView.openSubMenu) {
140  stackView.openSubMenu.visible = false;
141 
142  if (!listItem.actionsMenu.hasOwnProperty("count") || listItem.actionsMenu.count>0) {
143  if (listItem.actionsMenu.hasOwnProperty("popup")) {
144  listItem.actionsMenu.popup(listItem, listItem.width, 0)
145  } else {
146  listItem.actionsMenu.visible = true;
147  }
148  }
149  }
150  }
151 
152  onClicked: trigger()
153  Keys.onEnterPressed: event => trigger()
154  Keys.onReturnPressed: event => trigger()
155 
156  function trigger() {
157  modelData.trigger();
158  if (modelData.hasOwnProperty("children") && modelData.children!==undefined && modelData.children.length > 0) {
159  if (root.collapsed) {
160  // fallbacks needed for Qt 5.9
161  if ((!listItem.actionsMenu.hasOwnProperty("count") || listItem.actionsMenu.count>0) && !listItem.actionsMenu.visible) {
162  stackView.openSubMenu = listItem.actionsMenu;
163  if (listItem.actionsMenu.hasOwnProperty("popup")) {
164  listItem.actionsMenu.popup(listItem, listItem.width, 0)
165  } else {
166  listItem.actionsMenu.visible = true;
167  }
168  }
169  } else {
170  stackView.push(menuComponent, {model: modelData.children, level: level + 1, current: modelData });
171  }
172  } else if (root.resetMenuOnTriggered) {
173  root.resetMenu();
174  }
175  checked = Qt.binding(function() { return modelData.checked || (actionsMenu && actionsMenu.visible) });
176  }
177 
178  Keys.onDownPressed: event => nextItemInFocusChain().focus = true
179  Keys.onUpPressed: event => nextItemInFocusChain(false).focus = true
180 }
This class contains global kirigami settings about the current device setup It is exposed to QML as t...
Definition: settings.h:16
QStringView level(QStringView ifopt)
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Sun Jan 29 2023 04:11:03 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.