diff options
author | Colin Noga <Tempus@Spectrum-Song.local> | 2011-11-09 19:00:49 -0600 |
---|---|---|
committer | Colin Noga <Tempus@Spectrum-Song.local> | 2011-11-09 19:00:49 -0600 |
commit | 58397adbf19eb20d1359fa591a147ec7117821e6 (patch) | |
tree | b10f63a3b60c42b3d23a29070b674a59b8308adf /src | |
parent | 033904483314a538b2ab44d8b718750745a99e8f (diff) | |
download | koopatlas-58397adbf19eb20d1359fa591a147ec7117821e6.tar.gz koopatlas-58397adbf19eb20d1359fa591a147ec7117821e6.zip |
KPObjectSelector and everything it needs is all setup. Emits objects as required, and can return an object with currentSelectedObject().
Diffstat (limited to '')
-rw-r--r-- | src/tileset.py | 35 | ||||
-rw-r--r-- | src/ui.py | 123 |
2 files changed, 140 insertions, 18 deletions
diff --git a/src/tileset.py b/src/tileset.py index b0cb88c..c060f07 100644 --- a/src/tileset.py +++ b/src/tileset.py @@ -187,6 +187,25 @@ class KPGroupModel(QtCore.QAbstractListModel): return self.container.objectCount() + def groupItem(self): + """Returns the group item""" + + return self.container + + + def flags(self, index): + # item = QtCore.QAbstractItemModel.flags(self, index) + + item, depth = self.container.getItem(index.row()) + + if isinstance(item, KPGroupItem): + return Qt.ItemFlags(32) + else: + return Qt.ItemFlags(33) + + return Qt.ItemFlags(33) + + def data(self, index, role=Qt.DisplayRole): # Should return the contents of a row when asked for the index # @@ -261,6 +280,19 @@ class KPGroupItem(object): self.alignment = Qt.AlignCenter + def getGroupList(self, returnList=[], depth=0): + """Gets a list of group names and indices for the sorter menu""" + + returnList.append(((' ' * depth) + self.name, self.startIndex, self.endIndex)) + + depth += 1 + + for group in self.groups: + group.getGroupList(returnList, depth) + + return returnList + + def objectCount(self): ''' Retrieves the total number of items in this group and all it's children ''' @@ -352,6 +384,9 @@ class KPTileset(object): getObjectIcon(KPTileObject, (width, height)) # Returns a render map for the Object at the given size + getModel() + # Returns the tileset's groupModel, which handles groups + overrideTile(Tile Index, QPixmap) # Takes a 24x24 QPixmap and a tile index @@ -1,3 +1,5 @@ +# -*- coding: UTF-8 -*- + from common import * from editorui import * @@ -70,48 +72,133 @@ class KPObjectSelector(QtGui.QListView): """Initialises the widget. Remember to call setModel() on it with a KPGroupModel whenever the layer changes.""" - QtGui.QListView.__init__(self) + font = QtGui.QFont() + font.setPixelSize(22) + font.setBold(True) + + icon = QtGui.QIcon('icons/downArrow.png') + + self.sorterButton = QtGui.QToolButton() + + string = QtCore.QString(QtCore.QChar(0x25BE)) + string.append(' All Groups') + + self.sorterButton.setText(string) + self.sorterButton.setFont(font) + self.sorterButton.setPopupMode(2) + self.sorterButton.setSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding) + + self.sorterMenu = QtGui.QMenu() + self.sorterMenu.setFixedWidth(self.sorterButton.width()) + action = self.sorterMenu.addAction("test 1") + self.sorterButton.setMenu(self.sorterMenu) + + + layout = QtGui.QBoxLayout(2) + layout.setAlignment(Qt.AlignTop) + layout.setContentsMargins(0,0,0,0) + layout.setMargin(0) + layout.setSpacing(0) + + + + thing = QtGui.QListView.__init__(self) self.setFlow(QtGui.QListView.LeftToRight) self.setLayoutMode(QtGui.QListView.SinglePass) self.setMovement(QtGui.QListView.Static) self.setResizeMode(QtGui.QListView.Adjust) self.setWrapping(True) + + self.toolbar = QtGui.QToolBar() + self.toolbar.setFixedHeight(28) + self.toolbar.addWidget(self.sorterButton) + layout.addWidget(self.toolbar) + + + self.setLayout(layout) + + + # Borrowed the signals and junk from Reggie, figure we'll need em' self.clicked.connect(self.handleObjReplace) + self.sorterMenu.triggered.connect(self.toggleTopLevel) + + + def resizeEvent(self, event): + QtGui.QListView.resizeEvent(self, event) + self.sorterMenu.setFixedWidth(self.width()-self.verticalScrollBar().width()) - def toggleTopLevel(self, id): + + def currentSelectedObject(self): + """Returns the currently selected object reference, for painting purposes.""" + + index = self.currentIndex().row() + object = self.model().groupItem().getItem(index) + + return object + + + def setModel(self, model): + """Sets the model and the menu sorting list""" + + QtGui.QListView.setModel(self, model) + + menuList = model.groupItem().getGroupList() + + string = QtCore.QString(QtCore.QChar(0x25BE)) + string.append(' All Groups') + + self.sorterButton.setText(string) + self.sorterMenu.clear() + + for item in menuList: + actionMan = self.sorterMenu.addAction(item[0]) + + actionMan.setData((item[1], item[2])) + + + def toggleTopLevel(self, action): """Changes the top level group in the list view.""" - # Not quite sure how to implement this yet. Basically, the model is hierarchal, - # and it'll return items from whatever the top level KPGroupItem is. But removing - # and adding stuff isn't possible, since I need to retain my recursive object. - # - # So here's the structure. Above this QListView, there will be a QComboBox. - # - # The QComboBox will list all groups in my hierarchy. - # Selecting a group will cause the QListView to only show items for those rows, - # even though all rows are retained. - # - # It's kind of like a custom QSortFilterProxyModel. Maybe I should subclass that. + name = str(action.text()).strip() + startRow = action.data().toPyObject()[0] + endRow = action.data().toPyObject()[1] + + for row in xrange(self.model().rowCount()): + + if (row < startRow) or (row > endRow): + self.setRowHidden(row, True) + else: + self.setRowHidden(row, False) + string = QtCore.QString(QtCore.QChar(0x25BE)) + string.append(' ' + name) + + self.sorterButton.setText(string) - self.setCurrentIndex(self.model().index(sel, 0, QtCore.QModelIndex())) @QtCore.pyqtSlot(QtCore.QModelIndex, QtCore.QModelIndex) def currentChanged(self, current, previous): - """Throws a signal when the selected object changed""" - self.objChanged.emit(current.row()) + """Throws a signal emitting the current object when changed""" + i = current.row() + object = self.model().groupItem().getItem(i) + + self.objChanged.emit(object) + def handleObjReplace(self, index): """Throws a signal when the selected object is used as a replacement""" if QtGui.QApplication.keyboardModifiers() == QtCore.Qt.AltModifier: - self.objReplaced.emit(index.row()) + i = current.row() + object = self.model().groupItem().getItem(i) + + self.objReplaced.emit(object) objChanged = QtCore.pyqtSignal(int) - objReplaced = QtCore.pyqtSignal(int) + objReplaced = QtCore.pyqtSignal(KPTileObject) |