|
8 | 8 | class HierarchyItem(QTreeWidgetItem): |
9 | 9 | def __init__(self, gameObject): |
10 | 10 | super(HierarchyItem, self).__init__() |
11 | | - # self.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable | Qt.ItemIsDropEnabled | Qt.ItemIsDragEnabled) |
12 | 11 | self.setText(0, gameObject.name) |
13 | 12 | self.name = gameObject.name |
14 | 13 | self.gameObject = gameObject |
@@ -105,8 +104,12 @@ def remove(self): |
105 | 104 | if len(items) == 0: |
106 | 105 | print("Nothing selected") |
107 | 106 | return |
| 107 | + |
108 | 108 | for item in items: |
109 | | - print("Removing " + item.gameObject.name) |
| 109 | + item.selectAll() |
| 110 | + items = self.tree_widget.selectedItems() |
| 111 | + for item in items: |
| 112 | + print("Removing", item.gameObject.name) |
110 | 113 |
|
111 | 114 | def add_item(self, gameObject, parent=None): |
112 | 115 | item = HierarchyItem(gameObject) |
@@ -158,15 +161,33 @@ def __init__(self, parent): |
158 | 161 | self.header().setVisible(False) |
159 | 162 | self.setDragEnabled(True) |
160 | 163 | # self.viewport().setAcceptDrops(True) |
161 | | - self.setDropIndicatorShown(True) |
| 164 | + # self.setDropIndicatorShown(True) |
162 | 165 | self.setDragDropMode(QAbstractItemView.InternalMove) |
163 | 166 | self.setIndentation(10) |
| 167 | + self.hierarchy = parent |
164 | 168 |
|
165 | 169 | def selectAll(self): |
166 | 170 | item = self.invisibleRootItem() |
167 | 171 | for i in range(self.invisibleRootItem().childCount()): |
168 | 172 | child = item.child(i) |
169 | 173 | child.selectAll() |
| 174 | + |
| 175 | + def contextMenuEvent(self, event): |
| 176 | + menu = QMenu() |
| 177 | + menu.addAction("New Root GameObject", self.hierarchy.new) |
| 178 | + menu.addAction("New Child GameObject", self.hierarchy.new_child) |
| 179 | + menu.addAction("New Sibling GameObject", self.hierarchy.new_sibling) |
| 180 | + |
| 181 | + num = len(self.selectedItems()) |
| 182 | + if num > 0: |
| 183 | + menu.addSeparator() |
| 184 | + if num == 1: |
| 185 | + menu.addAction("Delete GameObject", self.hierarchy.remove) |
| 186 | + else: |
| 187 | + menu.addAction("Delete GameObjects", self.hierarchy.remove) |
| 188 | + |
| 189 | + menu.exec(event.globalPos()) |
| 190 | + super(CustomTreeWidget, self).contextMenuEvent(event) |
170 | 191 |
|
171 | 192 | # def mousePressEvent(self, event): |
172 | 193 | # item = self.indexAt(event.pos()) |
|
0 commit comments