Kirigami2

ContextDrawerActionItem.qml
1 /*
2  * SPDX-FileCopyrightText: 2019 Marco Martin <[email protected]>
3  *
4  * SPDX-License-Identifier: LGPL-2.0-or-later
5  */
6 
7 import QtQuick 2.6
8 import QtQuick.Controls 2.0 as QQC2
9 import QtQuick.Layouts 1.2
10 import org.kde.kirigami 2.5 as Kirigami
11 
12 Kirigami.BasicListItem {
13  id: listItem
14 
15  readonly property bool isSeparator: modelData.hasOwnProperty("separator") && modelData.separator
16 
17  readonly property bool isExpandible: modelData && modelData.hasOwnProperty("expandible") && modelData.expandible
18 
19  checked: modelData.checked
20  icon: modelData.icon
21  separatorVisible: false
22  reserveSpaceForIcon: !isSeparator
23  reserveSpaceForLabel: !isSeparator
24 
25  label: model ? (model.text ? model.text : model.tooltip) : (modelData.text ? modelData.text : modelData.tooltip)
26  hoverEnabled: (!isExpandible || root.collapsed) && !Kirigami.Settings.tabletMode
27  sectionDelegate: isExpandible
28  font.pointSize: isExpandible ? Kirigami.Theme.defaultFont.pointSize * 1.30 : Kirigami.Theme.defaultFont.pointSize
29 
30  enabled: !isExpandible && !isSeparator && (model ? model.enabled : modelData.enabled)
31  visible: model ? model.visible : modelData.visible
32  opacity: enabled || isExpandible ? 1.0 : 0.6
33 
34  Kirigami.Separator {
35  id: separatorAction
36 
37  visible: listItem.isSeparator
38  Layout.fillWidth: true
39  }
40 
41  ActionsMenu {
42  id: actionsMenu
43  y: Kirigami.Settings.isMobile ? -height : listItem.height
44  z: 99999999
45  actions: modelData.children
46  submenuComponent: Component {
47  ActionsMenu {}
48  }
49  }
50 
51  Loader {
52  Layout.fillWidth: true
53  Layout.fillHeight: true
54  sourceComponent: modelData.displayComponent
55  onStatusChanged: {
56  for (const i in parent.children) {
57  const child = parent.children[i];
58  if (child === this) {
59  child.visible = status === Loader.Ready;
60  break;
61  } else {
62  child.visible = status !== Loader.Ready;
63  }
64  }
65  }
66  Component.onCompleted: statusChanged()
67  }
68 
69  Kirigami.Icon {
70  isMask: true
71  Layout.alignment: Qt.AlignVCenter
72  Layout.preferredHeight: Kirigami.Units.iconSizes.small/2
73  selected: listItem.checked || listItem.pressed
74  Layout.preferredWidth: Layout.preferredHeight
75  source: "go-up-symbolic"
76  visible: !isExpandible && !listItem.isSeparator && modelData.children!== undefined && modelData.children.length > 0
77  }
78 
79  onPressed: {
80  if (modelData.children.length > 0) {
81  actionsMenu.open();
82  }
83  }
84  onClicked: {
85  if (modelData.children.length === 0) {
86  root.drawerOpen = false;
87  }
88 
89  if (modelData && modelData.trigger !== undefined) {
90  modelData.trigger();
91  // assume the model is a list of QAction or Action
92  } else if (menu.model.length > index) {
93  menu.model[index].trigger();
94  } else {
95  console.warning("Don't know how to trigger the action")
96  }
97  }
98 }
This class contains global kirigami settings about the current device setup It is exposed to QML as t...
Definition: settings.h:16
A visual separator.
Definition: Separator.qml:17
Q_SCRIPTABLE CaptureState status()
QString label(StandardShortcut id)
const QObjectList & children() const const
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.