from common import * class KPLayer(object): def __repr__(self): return "" % self.name def __init__(self): self.name = '' self.tileset = '' self.objects = [] class KPNodeAction(object): def __init__(self): pass class KPNode(object): def __init__(self): self.position = (0,0) self.actions = [] class KPPathSegment(object): def __init__(self): self.start = None self.end = None self.animation = None # default class KPPath(object): def __init__(self): self.startNode = None self.endNode = None self.segments = [] class KPDoodad(object): def __init__(self): self.position = (0,0) self.angle = 0 self.scale = (0,0) class KPMap(object): def __init__(self): self.nextLayerNumber = 1 self.layers = [self.createNewLayer() for x in range(4)] self.layerModel = KPMap.LayerModel(self.layers) self.nodes = [] self.paths = [] self.doodads = [] # LAYERS class LayerModel(QtCore.QAbstractListModel): def __init__(self, layerList): QtCore.QAbstractListModel.__init__(self) self.list = layerList def headerData(self, section, orientation, role = Qt.DisplayRole): return 'Layer' def rowCount(self, parent): return len(self.list) def data(self, index, role = Qt.DisplayRole): try: if (role == Qt.DisplayRole or role == Qt.EditRole) and index.isValid(): return self.list[index.row()].name except IndexError: pass return QtCore.QVariant() def flags(self, index): if not index.isValid(): return Qt.ItemIsEnabled return Qt.ItemIsEditable \ | QtCore.QAbstractListModel.flags(self, index) def setData(self, index, value, role = Qt.EditRole): if index.isValid() and role == Qt.EditRole: value = str(value.toString()) if len(value) > 0: self.list[index.row()].name = value self.dataChanged.emit(index, index) return True return False def createNewLayer(self): layer = KPLayer() layer.name = "Layer %d" % self.nextLayerNumber self.nextLayerNumber += 1 return layer def appendLayer(self, layer): return self.insertLayer(len(self.layers), layer) def insertLayer(self, index, layer): self.layerModel.beginInsertRows(QtCore.QModelIndex(), index, index) self.layers.insert(index, layer) self.layerModel.endInsertRows() return index def moveLayer(self, fromIndex, toIndex): if fromIndex == toIndex: return if fromIndex < 0 or toIndex < 0: raise ValueError if fromIndex >= len(self.layers) or toIndex > len(self.layers): raise ValueError self.layerModel.beginMoveRows( QtCore.QModelIndex(), fromIndex, fromIndex, QtCore.QModelIndex(), toIndex) toMove = self.layers[fromIndex] newIndex = ((toIndex > fromIndex) and (toIndex - 1)) or toIndex del self.layers[fromIndex] self.layers.insert(newIndex, toMove) self.layerModel.endMoveRows() return newIndex def removeLayer(self, layer): if layer not in self.layers: raise ValueError index = self.layers.index(layer) self.layerModel.beginRemoveRows(QtCore.QModelIndex(), index, index) del self.layers[index] self.layerModel.endRemoveRows()