mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-07 15:07:28 -06:00
Added icon for custom Menu items
This commit is contained in:
parent
f577789859
commit
c4fa50a8fc
2 changed files with 8 additions and 4 deletions
|
@ -5,12 +5,14 @@ class SidebarCustomMenuItemsModel(ListModel):
|
||||||
NameRole = Qt.UserRole + 1
|
NameRole = Qt.UserRole + 1
|
||||||
ActionsRole = Qt.UserRole + 2
|
ActionsRole = Qt.UserRole + 2
|
||||||
MenuItemRole = Qt.UserRole + 3
|
MenuItemRole = Qt.UserRole + 3
|
||||||
|
MenuItemIconNameRole = Qt.UserRole + 5
|
||||||
|
|
||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
self.addRoleName(self.NameRole, "name")
|
self.addRoleName(self.NameRole, "name")
|
||||||
self.addRoleName(self.ActionsRole, "actions")
|
self.addRoleName(self.ActionsRole, "actions")
|
||||||
self.addRoleName(self.MenuItemRole, "menu_item")
|
self.addRoleName(self.MenuItemRole, "menu_item")
|
||||||
|
self.addRoleName(self.MenuItemIconNameRole, "iconName")
|
||||||
self._updateExtensionList()
|
self._updateExtensionList()
|
||||||
|
|
||||||
def _updateExtensionList(self)-> None:
|
def _updateExtensionList(self)-> None:
|
||||||
|
@ -19,14 +21,15 @@ class SidebarCustomMenuItemsModel(ListModel):
|
||||||
|
|
||||||
self.appendItem({
|
self.appendItem({
|
||||||
"name": menu_item["name"],
|
"name": menu_item["name"],
|
||||||
|
"iconName": menu_item["iconName"],
|
||||||
"actions": menu_item["actions"],
|
"actions": menu_item["actions"],
|
||||||
"menu_item": menu_item["menu_item"]
|
"menu_item": menu_item["menu_item"]
|
||||||
})
|
})
|
||||||
|
|
||||||
@pyqtSlot(str, "QVariantList")
|
@pyqtSlot(str, "QVariantList", "QVariantMap")
|
||||||
def callMenuItemMethod(self, menu_item_name: str, menu_item_actions: list)-> None:
|
def callMenuItemMethod(self, menu_item_name: str, menu_item_actions: list, kwargs)-> None:
|
||||||
for item in self._items:
|
for item in self._items:
|
||||||
if menu_item_name == item["name"]:
|
if menu_item_name == item["name"]:
|
||||||
for method in menu_item_actions:
|
for method in menu_item_actions:
|
||||||
getattr(item["menu_item"], method)()
|
getattr(item["menu_item"], method)(kwargs)
|
||||||
break
|
break
|
|
@ -568,9 +568,10 @@ Item
|
||||||
MenuItem
|
MenuItem
|
||||||
{
|
{
|
||||||
text: model.name
|
text: model.name
|
||||||
|
iconName: model.iconName
|
||||||
onTriggered:
|
onTriggered:
|
||||||
{
|
{
|
||||||
customMenuItems.model.callMenuItemMethod(name, model.actions)
|
customMenuItems.model.callMenuItemMethod(name, model.actions, {"key": contextMenu.key})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
onObjectAdded: contextMenu.insertItem(index, object)
|
onObjectAdded: contextMenu.insertItem(index, object)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue