def changingObjects(self): changingObjects = QList() for movingObject in self.mMovingObjects: changingObjects.append(movingObject.item.mapObject()) return changingObjects
def __init__(self, parent): super().__init__(parent) self.mSettings = QSettings() self.mSaveBeforeExecute = False self.mCommands = QList() # Load saveBeforeExecute option s = self.mSettings.value("saveBeforeExecute", True) self.mSaveBeforeExecute = bool(s) # Load command list variant = self.mSettings.value("commandList") commands = variant if commands is None: commands = [] for commandVariant in commands: self.mCommands.append(Command.fromQVariant(commandVariant)) # Add default commands the first time the app has booted up. # This is useful on it's own and helps demonstrate how to use the commands. addPrefStr = "addedDefaultCommands" addedCommands = self.mSettings.value(addPrefStr, False) if (not addedCommands): # Disable default commands by default so user gets an informative # warning when clicking the command button for the first time command = Command(False) if sys.platform == 'linux': command.command = "gedit %mapfile" elif sys.platform == 'darwin': command.command = "open -t %mapfile" if (not command.command.isEmpty()): command.name = self.tr("Open in text editor") self.mCommands.push_back(command) self.commit() self.mSettings.setValue(addPrefStr, True)
def setupRuleList(self): combinedRegions = coherentRegions(self.mLayerInputRegions.region() + self.mLayerOutputRegions.region()) combinedRegions = QList( sorted(combinedRegions, key=lambda x: x.y(), reverse=True)) rulesInput = coherentRegions(self.mLayerInputRegions.region()) rulesOutput = coherentRegions(self.mLayerOutputRegions.region()) for i in range(combinedRegions.size()): self.mRulesInput.append(QRegion()) self.mRulesOutput.append(QRegion()) for reg in rulesInput: for i in range(combinedRegions.size()): if (reg.intersects(combinedRegions[i])): self.mRulesInput[i] += reg break for reg in rulesOutput: for i in range(combinedRegions.size()): if (reg.intersects(combinedRegions[i])): self.mRulesOutput[i] += reg break for i in range(self.mRulesInput.size()): checkCoherent = self.mRulesInput.at(i).united( self.mRulesOutput.at(i)) coherentRegions(checkCoherent).length() == 1 return True
def setSelectedObjectItems(self, items): # Inform the map document about the newly selected objects selectedObjects = QList() #selectedObjects.reserve(items.size()) for item in items: selectedObjects.append(item.mapObject()) self.mMapDocument.setSelectedObjects(selectedObjects)
def interfaces(self): results = QList() for plugin in self.mPlugins: result = plugin.instance if result: results.append(result) return results
def objectGroups(self): layers = QList() for layer in self.mLayers: og = layer.asObjectGroup() if og: layers.append(og) return layers
def setSelectedObjectItems(self, items): # Inform the map document about the newly selected objects selectedObjects = QList() #selectedObjects.reserve(items.size()) for item in items: selectedObjects.append(item.mapObject()) self.mMapDocument.setSelectedObjects(selectedObjects)
def init(self, parent): layout = QHBoxLayout(parent) layout.setContentsMargins(0, 0, 0, 0) self.m_treeWidget = QtPropertyEditorView(parent) self.m_treeWidget.setEditorPrivate(self) self.m_treeWidget.setIconSize(QSize(18, 18)) layout.addWidget(self.m_treeWidget) parent.setFocusProxy(self.m_treeWidget) self.m_treeWidget.setColumnCount(2) labels = QList() labels.append(QCoreApplication.translate("QtTreePropertyBrowser", "Property")) labels.append(QCoreApplication.translate("QtTreePropertyBrowser", "Value")) self.m_treeWidget.setHeaderLabels(labels) self.m_treeWidget.setAlternatingRowColors(True) self.m_treeWidget.setEditTriggers(QAbstractItemView.EditKeyPressed) self.m_delegate = QtPropertyEditorDelegate(parent) self.m_delegate.setEditorPrivate(self) self.m_treeWidget.setItemDelegate(self.m_delegate) self.m_treeWidget.header().setSectionsMovable(False) self.m_treeWidget.header().setSectionResizeMode(QHeaderView.Stretch) self.m_expandIcon = drawIndicatorIcon(self.q_ptr.palette(), self.q_ptr.style()) self.m_treeWidget.collapsed.connect(self.slotCollapsed) self.m_treeWidget.expanded.connect(self.slotExpanded) self.m_treeWidget.currentItemChanged.connect(self.slotCurrentTreeItemChanged)
def interfaces(self): results = QList() for plugin in self.mPlugins: result = plugin.instance if result: results.append(result) return results
class FormatHelper(): def __init__(self, capabilities, initialFilter): self.mFilter = initialFilter self.mFormats = QList() self.mFormatByNameFilter = QMap() def t(self, format): if (format.hasCapabilities(capabilities)): nameFilter = format.nameFilter() self.mFilter += ";;" self.mFilter += nameFilter self.mFormats.append(format) self.mFormatByNameFilter.insert(nameFilter, format) PluginManager.each(self, t) def filter(self): return self.mFilter def formats(self): return self.mFormats def formatByNameFilter(self, nameFilter): return self.mFormatByNameFilter.value(nameFilter)
def __init__(self, parent=None): super(MyController, self).__init__(parent) self.theClassNames = QList() self.theClassCombo = QComboBox(self) self.theControlledObject = None button = QToolButton(self) self.theController = ObjectController(self) buttonBox = QDialogButtonBox(self) button.clicked.connect(self.createAndControl) buttonBox.rejected.connect(self.reject) button.setText(self.tr("Create And Control")) buttonBox.setStandardButtons(QDialogButtonBox.Close) layout = QVBoxLayout(self) internalLayout = QHBoxLayout() internalLayout.addWidget(self.theClassCombo) internalLayout.addWidget(button) layout.addLayout(internalLayout) layout.addWidget(self.theController) layout.addWidget(buttonBox) self.theClassNames.append("QWidget") self.theClassNames.append("QPushButton") self.theClassNames.append("QDialogButtonBox") self.theClassNames.append("QTreeWidget") self.theClassNames.append("QCalendarWidget") self.theClassNames.append("QAction") self.theClassNames.append("QTimeLine") self.theClassNames.append("QTextDocument") self.theClassCombo.addItems(self.theClassNames)
def tileLayers(self): layers = QList() for layer in self.mLayers: tl = layer.asTileLayer() if tl: layers.append(tl) return layers
def setCurrentTiles(self, tiles): if (self.mCurrentTiles == tiles): return del self.mCurrentTiles self.mCurrentTiles = tiles # Set the selected tiles on the map document if (tiles): selectedTiles = QList() for y in range(tiles.height()): for x in range(tiles.width()): cell = tiles.cellAt(x, y) if (not cell.isEmpty()): selectedTiles.append(cell.tile) self.mMapDocument.setSelectedTiles(selectedTiles) # Create a tile stamp with these tiles map = self.mMapDocument.map() stamp = Map(map.orientation(), tiles.width(), tiles.height(), map.tileWidth(), map.tileHeight()) stamp.addLayer(tiles.clone()) stamp.addTilesets(tiles.usedTilesets()) self.mEmittingStampCaptured = True self.stampCaptured.emit(TileStamp(stamp)) self.mEmittingStampCaptured = False
def setupRuleList(self): combinedRegions = coherentRegions( self.mLayerInputRegions.region() + self.mLayerOutputRegions.region()) combinedRegions = QList(sorted(combinedRegions, key=lambda x:x.y(), reverse=True)) rulesInput = coherentRegions( self.mLayerInputRegions.region()) rulesOutput = coherentRegions( self.mLayerOutputRegions.region()) for i in range(combinedRegions.size()): self.mRulesInput.append(QRegion()) self.mRulesOutput.append(QRegion()) for reg in rulesInput: for i in range(combinedRegions.size()): if (reg.intersects(combinedRegions[i])): self.mRulesInput[i] += reg break for reg in rulesOutput: for i in range(combinedRegions.size()): if (reg.intersects(combinedRegions[i])): self.mRulesOutput[i] += reg break for i in range(self.mRulesInput.size()): checkCoherent = self.mRulesInput.at(i).united(self.mRulesOutput.at(i)) coherentRegions(checkCoherent).length() == 1 return True
def lowerToBottom(self): selectedItems = self.mMapScene.selectedObjectItems() objectGroup = RaiseLowerHelper.sameObjectGroup(selectedItems) if (not objectGroup): return if (objectGroup.drawOrder() != ObjectGroup.DrawOrder.IndexOrder): return ranges = RangeSet() for item in selectedItems: ranges.insert(int(item.zValue())) commands = QList() to = 0 for it in ranges: first = it[0] _from = first count = it[1] - first + 1 if (_from == to): to += count continue commands.append( ChangeMapObjectsOrder(self.mMapDocument, objectGroup, _from, to, count)) to += count self.push( commands, QCoreApplication.translate("Undo Commands", "Lower Object To Bottom"))
def objects(_type=None): results = QList() for object in PluginManager.instance().mObjects: if _type != None and type(object) != _type: continue results.append(object) return results
def tileLayers(self): layers = QList() for layer in self.mLayers: tl = layer.asTileLayer() if tl: layers.append(tl) return layers
def objects(_type=None): results = QList() for object in PluginManager.instance().mObjects: if _type!=None and type(object)!=_type: continue results.append(object) return results
def changingObjects(self): changingObjects = QList() for movingObject in self.mMovingObjects: changingObjects.append(movingObject.item.mapObject()) return changingObjects
def selectionChanged(self, selected, deselected): super().selectionChanged(selected, deselected) if (not self.mMapDocument or self.mSynching): return selectedRows = self.selectionModel().selectedRows() currentLayerIndex = -1 selectedObjects = QList() for index in selectedRows: og = self.model().toLayer(index) if og: i = self.mMapDocument.map().layers().indexOf(og) if (currentLayerIndex == -1): currentLayerIndex = i elif (currentLayerIndex != i): currentLayerIndex = -2 o = self.model().toMapObject(index) if o: selectedObjects.append(o) # Switch the current object layer if only one object layer (and/or its objects) # are included in the current selection. if (currentLayerIndex >= 0 and currentLayerIndex != self.mMapDocument.currentLayerIndex()): self.mMapDocument.setCurrentLayerIndex(currentLayerIndex) if (selectedObjects != self.mMapDocument.selectedObjects()): self.mSynching = True if (selectedObjects.count() == 1): o = selectedObjects.first() center = o.bounds().center() DocumentManager.instance().centerViewOn(center) self.mMapDocument.setSelectedObjects(selectedObjects) self.mSynching = False
def objectGroups(self): layers = QList() for layer in self.mLayers: og = layer.asObjectGroup() if og: layers.append(og) return layers
def raise_(self): if (not self.initContext()): return # Iterate backwards over the ranges in order to keep the indexes valid size = len(self.mSelectionRanges) if size <= 0: # no range return firstRange = self.mSelectionRanges.begin() it = self.mSelectionRanges.end() if (it == firstRange): # no range return # For each range of objects, only the first will move commands = QList() lastIndex = len(self.mRelatedObjects) - 1 for i in range(size - 1, -1, -1): it = self.mSelectionRanges.item(i) value = it[1] # The last range may be already at the top of the related items if value == lastIndex: continue movingItem = self.mRelatedObjects.at(value) targetItem = self.mRelatedObjects.at(value + 1) _from = int(movingItem.zValue()) to = int(targetItem.zValue() + 1) commands.append( ChangeMapObjectsOrder(self.mMapDocument, self.mObjectGroup, _from, to, 1)) self.push(commands, QCoreApplication.translate("Undo Commands", "Raise Object"))
def commit(self): # Save saveBeforeExecute option self.mSettings.setValue("saveBeforeExecute", self.mSaveBeforeExecute) # Save command list commands = QList() for command in self.mCommands: commands.append(command.toQVariant()) self.mSettings.setValue("commandList", commands)
def __init__(self, mapScene): self.mSelectionRanges = RangeSet() self.mMapDocument = mapScene.mapDocument() self.mMapScene = mapScene # Context self.mObjectGroup = None self.mRelatedObjects = QList()
def commit(self): # Save saveBeforeExecute option self.mSettings.setValue("saveBeforeExecute", self.mSaveBeforeExecute) # Save command list commands = QList() for command in self.mCommands: commands.append(command.toQVariant()) self.mSettings.setValue("commandList", commands)
def __init__(self): self.q_ptr = None self.m_indexToItem = QMap() self.m_itemToIndex = QMap() self.m_widgetToItem = QMap() self.m_mainLayout = 0 self.m_children = QList() self.m_recreateQueue = QList()
def __init__(self, parent=None): super(PropertyWidget, self).__init__(parent) self.setupUi(self) self.groupManager = QtGroupPropertyManager(self) self.boolManager = QtBoolPropertyManager(self) self.intManager = QtIntPropertyManager(self) self.doubleManager = QtDoublePropertyManager(self) self.stringManager = QtStringPropertyManager(self) self.colorManager = QtColorPropertyManager(self) self.enumManager = QtEnumPropertyManager(self) self.pointManager = QtPointFPropertyManager(self) self.boolManager.valueChangedSignal.connect(self.valueChanged) self.intManager.valueChangedSignal.connect(self.valueChanged) self.doubleManager.valueChangedSignal.connect(self.valueChanged) self.stringManager.valueChangedSignal.connect(self.valueChanged) self.colorManager.valueChangedSignal.connect(self.valueChanged) self.enumManager.valueChangedSignal.connect(self.valueChanged) self.pointManager.valueChangedSignal.connect(self.valueChanged) checkBoxFactory = QtCheckBoxFactory(self) spinBoxFactory = QtSpinBoxFactory(self) doubleSpinBoxFactory = QtDoubleSpinBoxFactory(self) lineEditFactory = QtLineEditFactory(self) comboBoxFactory = QtEnumEditorFactory(self) charEditfactory = QtCharEditorFactory(self) self.prop_browser.setFactoryForManager(\ self.boolManager, checkBoxFactory) self.prop_browser.setFactoryForManager(\ self.intManager, spinBoxFactory) self.prop_browser.setFactoryForManager(\ self.doubleManager, doubleSpinBoxFactory) self.prop_browser.setFactoryForManager(\ self.stringManager, lineEditFactory) self.prop_browser.setFactoryForManager(\ self.colorManager.subIntPropertyManager(), spinBoxFactory) self.prop_browser.setFactoryForManager(\ self.enumManager, comboBoxFactory) self.prop_browser.setFactoryForManager(\ self.pointManager.subDoublePropertyManager(), doubleSpinBoxFactory) self.selectedNodeID_ = -1 # for CS Nodes #self.CS_ = {} self.EnumToCSID_ = {} self.CSIDtoEnum_ = {} self.CSNames_ = QList() # for Material Nodes self.EnumToMatID_ = {} self.MatIDtoEnum_ = {} self.MatNames_ = QList()
def __init__(self, map, fileName=QString()): super().__init__() ## # The filename of a plugin is unique. So it can be used to determine # the right plugin to be used for saving or reloading the map. # The nameFilter of a plugin can not be used, since it's translatable. # The filename of a plugin must not change while maps are open using this # plugin. ## self.mReaderFormat = None self.mWriterFormat = None self.mExportFormat = None self.mSelectedArea = QRegion() self.mSelectedObjects = QList() self.mSelectedTiles = QList() self.mCurrentLayerIndex = 0 self.mLastSaved = QDateTime() self.mLastExportFileName = '' self.mFileName = fileName self.mMap = map self.mLayerModel = LayerModel(self) self.mCurrentObject = map ## Current properties object. ## self.mRenderer = None self.mMapObjectModel = MapObjectModel(self) self.mTerrainModel = TerrainModel(self, self) self.mUndoStack = QUndoStack(self) self.createRenderer() if (map.layerCount() == 0): _x = -1 else: _x = 0 self.mCurrentLayerIndex = _x self.mLayerModel.setMapDocument(self) # Forward signals emitted from the layer model self.mLayerModel.layerAdded.connect(self.onLayerAdded) self.mLayerModel.layerAboutToBeRemoved.connect( self.onLayerAboutToBeRemoved) self.mLayerModel.layerRemoved.connect(self.onLayerRemoved) self.mLayerModel.layerChanged.connect(self.layerChanged) # Forward signals emitted from the map object model self.mMapObjectModel.setMapDocument(self) self.mMapObjectModel.objectsAdded.connect(self.objectsAdded) self.mMapObjectModel.objectsChanged.connect(self.objectsChanged) self.mMapObjectModel.objectsRemoved.connect(self.onObjectsRemoved) self.mMapObjectModel.rowsInserted.connect( self.onMapObjectModelRowsInserted) self.mMapObjectModel.rowsRemoved.connect( self.onMapObjectModelRowsInsertedOrRemoved) self.mMapObjectModel.rowsMoved.connect(self.onObjectsMoved) self.mTerrainModel.terrainRemoved.connect(self.onTerrainRemoved) self.mUndoStack.cleanChanged.connect(self.modifiedChanged) # Register tileset references tilesetManager = TilesetManager.instance() tilesetManager.addReferences(self.mMap.tilesets())
def removeTiles(self): view = self.currentTilesetView() if (not view): return if (not view.selectionModel().hasSelection()): return indexes = view.selectionModel().selectedIndexes() model = view.tilesetModel() tileIds = RangeSet() tiles = QList() for index in indexes: tile = model.tileAt(index) if tile: tileIds.insert(tile.id()) tiles.append(tile) def matchesAnyTile(cell): tile = cell.tile if tile: return tiles.contains(tile) return False inUse = self.hasTileReferences(self.mMapDocument, matchesAnyTile) # If the tileset is in use, warn the user and confirm removal if (inUse): warning = QMessageBox( QMessageBox.Warning, self.tr("Remove Tiles"), self.tr("One or more of the tiles to be removed are " "still in use by the map!"), QMessageBox.Yes | QMessageBox.No, self) warning.setDefaultButton(QMessageBox.Yes) warning.setInformativeText( self.tr("Remove all references to these tiles?")) if (warning.exec() != QMessageBox.Yes): return undoStack = self.mMapDocument.undoStack() undoStack.beginMacro(self.tr("Remove Tiles")) removeTileReferences(self.mMapDocument, matchesAnyTile) # Iterate backwards over the ranges in order to keep the indexes valid firstRange = tileIds.begin() it = tileIds.end() if (it == firstRange): # no range return tileset = view.tilesetModel().tileset() while (it != firstRange): it -= 1 item = tileIds.item(it) length = item[1] - item[0] + 1 undoStack.push( RemoveTiles(self.mMapDocument, tileset, item[0], length)) undoStack.endMacro() # Clear the current tiles, will be referencing the removed tiles self.setCurrentTiles(None) self.setCurrentTile(None)
def __init__(self, parent): super().__init__(parent) self.mObjectGroups = QList() self.mObjects = QMap() self.mGroups = QMap() self.mMapDocument = None self.mMap = None self.mObject = None self.mObjectGroupIcon = ":/images/16x16/layer-object.png"
def removeObject(self, og, o): objects = QList() objects.append(o) row = og.objects().indexOf(o) self.beginRemoveRows(self.index(og), row, row) og.removeObjectAt(row) self.mObjects.remove(o) self.endRemoveRows() self.objectsRemoved.emit(objects) return row
def removeObject(self, og, o): objects = QList() objects.append(o) row = og.objects().indexOf(o) self.beginRemoveRows(self.index(og), row, row) og.removeObjectAt(row) self.mObjects.remove(o) self.endRemoveRows() self.objectsRemoved.emit(objects) return row
def layers(self, *args): l = len(args) if l == 0: return QList(self.mLayers) elif l == 1: tp = args[0] layers = QList() for layer in self.mLayers: if (layer.layerType() == tp): layers.append(layer) return layers
def layers(self, *args): l = len(args) if l==0: return QList(self.mLayers) elif l==1: tp = args[0] layers = QList() for layer in self.mLayers: if (layer.layerType() == tp): layers.append(layer) return layers
def __init__(self, map, fileName = QString()): super().__init__() ## # The filename of a plugin is unique. So it can be used to determine # the right plugin to be used for saving or reloading the map. # The nameFilter of a plugin can not be used, since it's translatable. # The filename of a plugin must not change while maps are open using this # plugin. ## self.mReaderFormat = None self.mWriterFormat = None self.mExportFormat = None self.mSelectedArea = QRegion() self.mSelectedObjects = QList() self.mSelectedTiles = QList() self.mCurrentLayerIndex = 0 self.mLastSaved = QDateTime() self.mLastExportFileName = '' self.mFileName = fileName self.mMap = map self.mLayerModel = LayerModel(self) self.mCurrentObject = map ## Current properties object. ## self.mRenderer = None self.mMapObjectModel = MapObjectModel(self) self.mTerrainModel = TerrainModel(self, self) self.mUndoStack = QUndoStack(self) self.createRenderer() if (map.layerCount() == 0): _x = -1 else: _x = 0 self.mCurrentLayerIndex = _x self.mLayerModel.setMapDocument(self) # Forward signals emitted from the layer model self.mLayerModel.layerAdded.connect(self.onLayerAdded) self.mLayerModel.layerAboutToBeRemoved.connect(self.onLayerAboutToBeRemoved) self.mLayerModel.layerRemoved.connect(self.onLayerRemoved) self.mLayerModel.layerChanged.connect(self.layerChanged) # Forward signals emitted from the map object model self.mMapObjectModel.setMapDocument(self) self.mMapObjectModel.objectsAdded.connect(self.objectsAdded) self.mMapObjectModel.objectsChanged.connect(self.objectsChanged) self.mMapObjectModel.objectsRemoved.connect(self.onObjectsRemoved) self.mMapObjectModel.rowsInserted.connect(self.onMapObjectModelRowsInserted) self.mMapObjectModel.rowsRemoved.connect(self.onMapObjectModelRowsInsertedOrRemoved) self.mMapObjectModel.rowsMoved.connect(self.onObjectsMoved) self.mTerrainModel.terrainRemoved.connect(self.onTerrainRemoved) self.mUndoStack.cleanChanged.connect(self.modifiedChanged) # Register tileset references tilesetManager = TilesetManager.instance() tilesetManager.addReferences(self.mMap.tilesets())
def __init__(self): self.q_ptr = 0 self.m_object = 0 self.m_classToProperty = QMap() self.m_propertyToClass = QMap() self.m_propertyToIndex = QMap() self.m_classToIndexToProperty = QMapMap() self.m_propertyToExpanded = QMap() self.m_topLevelProperties = QList() self.m_browser = 0 self.m_manager = 0 self.m_readOnlyManager = 0
def intToEnum(self, metaEnum, intValue): valueMap = QMap() # dont show multiple enum values which have the same values values = QList() for i in range(metaEnum.keyCount()): value = metaEnum.value(i) if (not valueMap.contains(value)): valueMap[value] = True values.append(value) if (intValue >= values.count()): return -1 return values.at(intValue)
def __init__(self, capabilities, initialFilter): self.mFilter = initialFilter self.mFormats = QList() self.mFormatByNameFilter = QMap() def t(self, format): if (format.hasCapabilities(capabilities)): nameFilter = format.nameFilter() self.mFilter += ";;" self.mFilter += nameFilter self.mFormats.append(format) self.mFormatByNameFilter.insert(nameFilter, format) PluginManager.each(self, t)
def applyMapObjectValueTo(self, id, val, mapObject): command = None x = id if x == PropertyId.NameProperty or x == PropertyId.TypeProperty: command = ChangeMapObject( self.mMapDocument, mapObject, self.mIdToProperty[PropertyId.NameProperty].value(), self.mIdToProperty[PropertyId.TypeProperty].value()) elif x == PropertyId.VisibleProperty: command = SetMapObjectVisible(self.mMapDocument, mapObject, val) elif x == PropertyId.XProperty: oldPos = mapObject.position() newPos = QPointF(val, oldPos.y()) command = MoveMapObject(self.mMapDocument, mapObject, newPos, oldPos) elif x == PropertyId.YProperty: oldPos = mapObject.position() newPos = QPointF(oldPos.x(), val) command = MoveMapObject(self.mMapDocument, mapObject, newPos, oldPos) elif x == PropertyId.WidthProperty: oldSize = mapObject.size() newSize = QSizeF(val, oldSize.height()) command = ResizeMapObject(self.mMapDocument, mapObject, newSize, oldSize) elif x == PropertyId.HeightProperty: oldSize = mapObject.size() newSize = QSizeF(oldSize.width(), val) command = ResizeMapObject(self.mMapDocument, mapObject, newSize, oldSize) elif x == PropertyId.RotationProperty: newRotation = val oldRotation = mapObject.rotation() command = RotateMapObject(self.mMapDocument, mapObject, newRotation, oldRotation) elif x == PropertyId.FlippingProperty: flippingFlags = val flippedHorizontally = flippingFlags & 1 flippedVertically = flippingFlags & 2 # You can only change one checkbox at a time if (mapObject.cell().flippedHorizontally != flippedHorizontally): command = FlipMapObjects(self.mMapDocument, QList([mapObject]), FlipDirection.FlipHorizontally) elif (mapObject.cell().flippedVertically != flippedVertically): command = FlipMapObjects(self.mMapDocument, QList([mapObject]), FlipDirection.FlipVertically) else: pass return command
def duplicateObjects(self, objects): if (objects.isEmpty()): return self.mUndoStack.beginMacro(self.tr("Duplicate %n Object(s)", "", objects.size())) clones = QList() for mapObject in objects: clone = mapObject.clone() clones.append(clone) self.mUndoStack.push(AddMapObject(self, mapObject.objectGroup(), clone)) self.mUndoStack.endMacro() self.setSelectedObjects(clones)
def copyObjectRegion(self, srcLayer, srcX, srcY, width, height, dstLayer, dstX, dstY): undo = self.mMapDocument.undoStack() rect = QRectF(srcX, srcY, width, height) pixelRect = self.mMapDocument.renderer().tileToPixelCoords_(rect) objects = objectsInRegion(srcLayer, pixelRect.toAlignedRect()) pixelOffset = self.mMapDocument.renderer().tileToPixelCoords(dstX, dstY) pixelOffset -= pixelRect.topLeft() clones = QList() for obj in objects: clone = obj.clone() clones.append(clone) clone.setX(clone.x() + pixelOffset.x()) clone.setY(clone.y() + pixelOffset.y()) undo.push(AddMapObject(self.mMapDocument, dstLayer, clone))
def duplicateObjects(self, objects): if (objects.isEmpty()): return self.mUndoStack.beginMacro( self.tr("Duplicate %n Object(s)", "", objects.size())) clones = QList() for mapObject in objects: clone = mapObject.clone() clones.append(clone) self.mUndoStack.push( AddMapObject(self, mapObject.objectGroup(), clone)) self.mUndoStack.endMacro() self.setSelectedObjects(clones)
def changeSelectedNode(self): if not self.directSelection_: return nodeIDs = QList() for item in self.selectedItems(): node = item.data(1, Qt.UserRole) nodeID = node.getID() nodeIDs.append(nodeID) if nodeIDs != self.selectedNodeIDs_: #print('NOH Tree, Selected Nodes:', nodeIDs, self.selectedNodeIDs_) self.selectedNodeIDs_ = nodeIDs self.itemsSelected.emit(nodeIDs)
def __init__(self, parent): super().__init__(parent) self.mSettings = QSettings() self.mSaveBeforeExecute = False self.mCommands = QList() # Load saveBeforeExecute option s = self.mSettings.value("saveBeforeExecute", True) self.mSaveBeforeExecute = bool(s) # Load command list variant = self.mSettings.value("commandList") commands = variant if commands is None: commands = [] for commandVariant in commands: self.mCommands.append(Command.fromQVariant(commandVariant)) # Add default commands the first time the app has booted up. # This is useful on it's own and helps demonstrate how to use the commands. addPrefStr = "addedDefaultCommands" addedCommands = self.mSettings.value(addPrefStr, False) if (not addedCommands): # Disable default commands by default so user gets an informative # warning when clicking the command button for the first time command = Command(False) if sys.platform == 'linux': command.command = "gedit %mapfile" elif sys.platform == 'darwin': command.command = "open -t %mapfile" if (not command.command.isEmpty()): command.name = self.tr("Open in text editor") self.mCommands.push_back(command) self.commit() self.mSettings.setValue(addPrefStr, True)
def setObjectVisible(self, o, visible): if o.isVisible() == visible: return o.setVisible(visible) index = self.index(o) self.dataChanged.emit(index, index) self.objectsChanged.emit(QList([o]))
def setObjectName(self, o, name): if o.name() == name: return o.setName(name) index = self.index(o) self.dataChanged.emit(index, index) self.objectsChanged.emit(QList([o]))
def setObjectType(self, o, type): if o.type() == type: return o.setType(type) index = self.index(o, 1) self.dataChanged.emit(index, index) self.objectsChanged.emit(QList([o]))
def __init__(self, control, parent=None): super().__init__(parent) self.mControl = control self.mFileNames = QList() self.mFileVersions = QMap()
def __init__(self, parent=None): super(MyController, self).__init__(parent) self.theClassNames = QList() self.theClassCombo = QComboBox(self) self.theControlledObject = None button = QToolButton(self) self.theController = ObjectController(self) buttonBox = QDialogButtonBox(self) button.clicked.connect(self.createAndControl) buttonBox.rejected.connect(self.reject) button.setText(self.tr("Create And Control")) buttonBox.setStandardButtons(QDialogButtonBox.Close) layout = QVBoxLayout(self) internalLayout = QHBoxLayout() internalLayout.addWidget(self.theClassCombo) internalLayout.addWidget(button) layout.addLayout(internalLayout) layout.addWidget(self.theController) layout.addWidget(buttonBox) self.theClassNames.append("QWidget") self.theClassNames.append("QPushButton") self.theClassNames.append("QDialogButtonBox") self.theClassNames.append("QTreeWidget") self.theClassNames.append("QCalendarWidget") self.theClassNames.append("QAction") self.theClassNames.append("QTimeLine") self.theClassNames.append("QTextDocument") self.theClassCombo.addItems(self.theClassNames)
def cleanUpRuleMapLayers(self): self.cleanTileLayers() it = QList.const_iterator() for it in self.mLayerList: del it self.mLayerList.clear() # do not delete mLayerRuleRegions, it is owned by the rulesmap self.mLayerInputRegions = None self.mLayerOutputRegions = None self.mInputRules.clear()
def __init__(self, parent): super().__init__(parent) self.mObjectGroups = QList() self.mObjects = QMap() self.mGroups = QMap() self.mMapDocument = None self.mMap = None self.mObject = None self.mObjectGroupIcon = ":/images/16x16/layer-object.png"
def __init__(self, name, tileWidth, tileHeight, tileSpacing = 0, margin = 0): super().__init__(Object.TilesetType) self.mName = name self.mTileWidth = tileWidth self.mTileHeight = tileHeight self.mTileSpacing = tileSpacing self.mMargin = margin self.mImageWidth = 0 self.mImageHeight = 0 self.mColumnCount = 0 self.mTerrainDistancesDirty = False self.mTileOffset = QPoint() self.mFileName = QString() self.mTiles = QList() self.mTransparentColor = QColor() self.mImageSource = QString() self.mTerrainTypes = QList() self.mWeakPointer = None
def intToFlag(self, metaEnum, intValue): valueMap = QMap() # dont show multiple enum values which have the same values values = QList() for i in range(metaEnum.keyCount()): value = metaEnum.value(i) if (not valueMap.contains(value) and self.isPowerOf2(value)): valueMap[value] = True values.append(value) flagValue = 0 temp = intValue i = 0 while (temp): if (i >= values.count()): return -1 if (temp & 1): flagValue |= values.at(i) i += 1 temp = temp >> 1 return flagValue
def __init__(self): self.q_ptr = 0 self.m_object = 0 self.m_classToProperty = QMap() self.m_propertyToClass = QMap() self.m_propertyToIndex = QMap() self.m_classToIndexToProperty = QMapMap() self.m_propertyToExpanded = QMap() self.m_topLevelProperties = QList() self.m_browser = 0 self.m_manager = 0 self.m_readOnlyManager = 0
def __init__(self, capabilities, initialFilter): self.mFilter = initialFilter self.mFormats = QList() self.mFormatByNameFilter = QMap() def t(self, format): if (format.hasCapabilities(capabilities)): nameFilter = format.nameFilter() self.mFilter += ";;" self.mFilter += nameFilter self.mFormats.append(format) self.mFormatByNameFilter.insert(nameFilter, format) PluginManager.each(self, t)
def pasteObjectGroup(self, objectGroup, mapDocument, view, mode = PasteMode.Standard): currentLayer = mapDocument.currentLayer() if (not currentLayer): return currentObjectGroup = currentLayer.asObjectGroup() if (not currentObjectGroup): return # Determine where to insert the objects renderer = mapDocument.renderer() center = objectGroup.objectsBoundingRect().center() # Take the mouse position if the mouse is on the view, otherwise # take the center of the view. viewPos = QPoint() if (view.underMouse()): viewPos = view.mapFromGlobal(QCursor.pos()) else: viewPos = QPoint(view.width() / 2, view.height() / 2) scenePos = view.mapToScene(viewPos) insertPos = renderer.screenToPixelCoords_(scenePos) - center SnapHelper(renderer).snap(insertPos) undoStack = mapDocument.undoStack() pastedObjects = QList() pastedObjects.reserve(objectGroup.objectCount()) undoStack.beginMacro(self.tr("Paste Objects")) for mapObject in objectGroup.objects(): if (mode == PasteMode.NoTileObjects and not mapObject.cell().isEmpty()): continue objectClone = mapObject.clone() objectClone.setPosition(objectClone.position() + insertPos) pastedObjects.append(objectClone) undoStack.push(AddMapObject(mapDocument, currentObjectGroup, objectClone)) undoStack.endMacro() mapDocument.setSelectedObjects(pastedObjects)
def currentObjects(self): objects = QList() if (self.mCurrentObject): if (self.mCurrentObject.typeId() == Object.MapObjectType and not self.mSelectedObjects.isEmpty()): for mapObj in self.mSelectedObjects: objects.append(mapObj) elif (self.mCurrentObject.typeId() == Object.TileType and not self.mSelectedTiles.isEmpty()): for tile in self.mSelectedTiles: objects.append(tile) else: objects.append(self.mCurrentObject) return objects
def __init__(self, parent = None): super().__init__(parent) self.mDocuments = QList() self.mTabWidget = MovableTabWidget() self.mUndoGroup = QUndoGroup(self) self.mSelectedTool = None self.mViewWithTool = None self.mFileSystemWatcher = FileSystemWatcher(self) self.mTabWidget.setDocumentMode(True) self.mTabWidget.setTabsClosable(True) self.mTabWidget.currentChanged.connect(self.currentIndexChanged) self.mTabWidget.tabCloseRequested.connect(self.documentCloseRequested) self.mTabWidget.tabMoved.connect(self.documentTabMoved) self.mFileSystemWatcher.fileChanged.connect(self.fileChanged)
def __init__(self, *args): self.mObjects = QList() self.mColor = QColor() l = len(args) if l==0: super().__init__(Layer.ObjectGroupType, QString(), 0, 0, 0, 0) elif l==5: ## # Constructor with some parameters. ## name, x, y, width, height = args super().__init__(Layer.ObjectGroupType, name, x, y, width, height) else: pass self.mDrawOrder = ObjectGroup.DrawOrder.IndexOrder