Kirigami2

ActionsMenu.qml
1 /*
2  * SPDX-FileCopyrightText: 2018 Aleix Pol Gonzalez <[email protected]>
3  *
4  * SPDX-License-Identifier: LGPL-2.0-or-later
5  */
6 
7 import QtQuick 2.15
8 import QtQuick.Controls 2.15 as QQC2
9 import org.kde.kirigami 2.20 as Kirigami
10 
11 QQC2.Menu
12 {
13  id: theMenu
14  z: 999999999
15  property alias actions: actionsInstantiator.model
16  property Component submenuComponent
17  // renamed to work on both Qt 5.9 and 5.10
18  property Component itemDelegate: ActionMenuItem {}
19  property Component separatorDelegate: QQC2.MenuSeparator { property var action }
20  property Component loaderDelegate: Loader { property var action }
21  property QQC2.Action parentAction
22  property QQC2.MenuItem parentItem
23 
24  Item {
25  id: invisibleItems
26  visible: false
27  }
28  Instantiator {
29  id: actionsInstantiator
30 
31  active: theMenu.visible
32  delegate: QtObject {
33  readonly property QQC2.Action action: modelData
34  property QtObject item: null
35  property bool isSubMenu: false
36 
37  function create() {
38  if (!action.hasOwnProperty("children") && !action.children || action.children.length === 0) {
39  if (action.hasOwnProperty("separator") && action.separator) {
40  item = theMenu.separatorDelegate.createObject(null, { action: action });
41  }
42  else if (action.displayComponent) {
43  item = theMenu.loaderDelegate.createObject(null,
44  { action: action, sourceComponent: action.displayComponent });
45  }
46  else {
47  item = theMenu.itemDelegate.createObject(null, { action: action });
48  }
49  theMenu.addItem(item)
50  } else if (theMenu.submenuComponent) {
51  item = theMenu.submenuComponent.createObject(null, { parentAction: action, title: action.text, actions: action.children });
52 
53  theMenu.insertMenu(theMenu.count, item)
54  item.parentItem = theMenu.contentData[theMenu.contentData.length-1]
55  item.parentItem.icon = action.icon
56  isSubMenu = true
57  }
58  }
59  function remove() {
60  if (isSubMenu) {
61  theMenu.removeMenu(item)
62  } else {
63  theMenu.removeItem(item)
64  }
65  item.destroy()
66  }
67  }
68 
69  onObjectAdded: object.create()
70  onObjectRemoved: object.remove()
71  }
72 }
KGuiItem remove()
QAction * create(StandardGameAction id, const QObject *recvr, const char *slot, QObject *parent)
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Tue Feb 7 2023 04:14:23 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.