Skip to content

Commit 37210ea

Browse files
committed
Rightclick menu
1 parent 0aa3fcc commit 37210ea

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

drag.ui

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,18 @@
4040
<property name="selectionMode">
4141
<enum>QAbstractItemView::ExtendedSelection</enum>
4242
</property>
43+
<property name="textElideMode">
44+
<enum>Qt::ElideRight</enum>
45+
</property>
46+
<property name="indentation">
47+
<number>10</number>
48+
</property>
49+
<property name="wordWrap">
50+
<bool>false</bool>
51+
</property>
52+
<attribute name="headerVisible">
53+
<bool>false</bool>
54+
</attribute>
4355
<column>
4456
<property name="text">
4557
<string>1</string>

editor/views.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
class HierarchyItem(QTreeWidgetItem):
99
def __init__(self, gameObject):
1010
super(HierarchyItem, self).__init__()
11-
# self.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable | Qt.ItemIsDropEnabled | Qt.ItemIsDragEnabled)
1211
self.setText(0, gameObject.name)
1312
self.name = gameObject.name
1413
self.gameObject = gameObject
@@ -105,8 +104,12 @@ def remove(self):
105104
if len(items) == 0:
106105
print("Nothing selected")
107106
return
107+
108108
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)
110113

111114
def add_item(self, gameObject, parent=None):
112115
item = HierarchyItem(gameObject)
@@ -158,15 +161,33 @@ def __init__(self, parent):
158161
self.header().setVisible(False)
159162
self.setDragEnabled(True)
160163
# self.viewport().setAcceptDrops(True)
161-
self.setDropIndicatorShown(True)
164+
# self.setDropIndicatorShown(True)
162165
self.setDragDropMode(QAbstractItemView.InternalMove)
163166
self.setIndentation(10)
167+
self.hierarchy = parent
164168

165169
def selectAll(self):
166170
item = self.invisibleRootItem()
167171
for i in range(self.invisibleRootItem().childCount()):
168172
child = item.child(i)
169173
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)
170191

171192
# def mousePressEvent(self, event):
172193
# item = self.indexAt(event.pos())

0 commit comments

Comments
 (0)