def paintEvent(self, paintEvent): painter = QPainter(self) if self.note is not None: EMImageGenerator.drawNoteIcon(painter, self.note, 0, 0, 48, self.index) else: painter.setPen(Qt.black) painter.setBrush(Qt.white) painter.drawRect(0, 0, 48, 48)
def drawPreviewTileSingle(self, painter): if self.selectedModelImages[0] is not None: point = (int(self.xOffset + (self.tileSize * self.mouseIndex[0])), int(self.yOffset + (self.tileSize * self.mouseIndex[1]))) painter.drawImage( point[0], point[1], self.selectedModelImages[0].scaled(self.tileSize, self.tileSize)) EMImageGenerator.drawGrid(painter, 1, 1, point[0], point[1], self.tileSize, Qt.red)
def drawPreviewTileGroup(self, painter): if self.selectedModelImages[1] is not None: model = self.selectedGroup groupIndex = self.indexAlignedGroup() point = (int(self.xOffset + (self.tileSize * groupIndex[0])), int(self.yOffset + (self.tileSize * groupIndex[1]))) painter.drawImage( point[0], point[1], self.selectedModelImages[1].scaled( self.tileSize * model.getNumCols(), self.tileSize * model.getNumRows())) EMImageGenerator.drawGrid(painter, model.getNumCols(), model.getNumRows(), point[0], point[1], self.tileSize, Qt.red)
def exportEncounterMap(self): # , mods=None): modifiers = [] print(modifiers) filePath = QFileDialog.getSaveFileName(self, "Open Encounter", "", "Image (*.png)") if filePath is not None: fp = filePath[0] if fp.endswith(".png"): fp = fp[:-4] # self.mapEditor.setFilePath(filePath) model = self.mapEditor.getModel() if model is not None: mapImage = EMImageGenerator.genImageFromModel( model, ("drawGrid")) if mapImage is not None: if "groupPrint" in modifiers: numY = math.ceil(model.getNumRows()/3) numX = math.ceil(model.getNumCols()/2) width = 6 * 72 height = 9 * 72 for y in range(numY): for x in range(numX): croppedImage = mapImage.copy( x*width, y*height, width, height) ModelManager.saveImageToFile( croppedImage, fp+"{}{}".format(y, x)) else: ModelManager.saveImageToFile(mapImage, fp) # pass else: print("model is not MapModel")
def paintEvent(self, paintEvent): painter = QPainter(self) if self.model is not None: self.modelImage = EMImageGenerator.genImageFromModel(self.model) # tempImg = EMImageGenerator.genImageFromModel( # self.model) # TODO: Convert to Pixmap painter.drawImage( 10, 10, self.modelImage.scaled(self.tileSize, self.tileSize)) EMImageGenerator.drawGrid(painter, 1, 1, 10, 10, self.tileSize) # self.drawTile(painter, 0, 0, self.model) if not self.preview and self.selectedShape > -1: points = self.model.generateShapeOffset( self.selectedShape, 0, 0, self.tileSize, self.xOffset, self.yOffset) self.drawPointObjects(painter, points)
def paintEvent(self, paintEvent): painter = QPainter(self) if (self.model is not None): nr = self.model.getNumRows() nc = self.model.getNumCols() img = EMImageGenerator.genImageFromModel(self.model) painter.drawImage(0, 0, img.scaled(self.width, self.height)) if self.preview: EMImageGenerator.drawGrid( painter, nc, nr, self.xOffset, self.yOffset, self.tileSize, Qt.black, EMImageGenerator.GridPatternPreviewSimple, 1) else: EMImageGenerator.drawGrid(painter, nc, nr, self.xOffset, self.yOffset, self.tileSize) # draw preview Image if not self.preview: if self.mouseIndex != (-1, -1) and not self.mousePressed: if (self.selectedObject[0] != -1 and self.pTileImage is not None): tp = (int(self.xOffset + (self.mouseIndex[0] * self.tileSize)), int(self.yOffset + (self.mouseIndex[1] * self.tileSize))) painter.drawImage( tp[0], tp[1], self.pTileImage.scaled(self.tileSize, self.tileSize)) EMImageGenerator.drawGrid(painter, 1, 1, tp[0], tp[1], self.tileSize, Qt.red)
def updateSelectedObject(self, uid, objNum=-1): self.selectedObject[self.openTab] = uid tab = self.openTab if objNum == -1 else objNum if tab == 1 and uid > -1: group = ModelManager.fetchByUid(ModelManager.GroupName, self.selectedObject[1]) if group is None: self.selectedGroup = None else: self.selectedGroup = GroupModel.createModelTransform( group, self.sOptions) if self.selectedGroup is not None: self.selectedModelImages[1] = EMImageGenerator.genImageFromModel( self.selectedGroup) if self.selectedObject[0] is not None: self.selectedModelImages[0] = EMImageGenerator.genImageFromModel( ModelManager.fetchByUid(ModelManager.TileName, self.selectedObject[0]), {"transformOptions": self.sOptions})
def transformP(self, type): if type == "cw": self.sOptions[0] = (self.sOptions[0] + 1) % 4 elif type == "ccw": self.sOptions[0] = (self.sOptions[0] + 3) % 4 elif type == "h": self.sOptions[1] = not self.sOptions[1] elif type == "v": self.sOptions[2] = not self.sOptions[2] if self.selectedObject[0] != -1: self.pTileImage = EMImageGenerator.genImageFromModel( ModelManager.fetchByUid(ModelManager.TileName, self.selectedObject[0]), {"transformOptions": self.sOptions}) self.updatePreview.emit()
def paintEvent(self, paintEvent): painter = QPainter(self) if (self.model is not None): nr = self.model.getNumRows() nc = self.model.getNumCols() img = EMImageGenerator.genImageFromModel(self.model) painter.drawImage(0, 0, img.scaled(self.width, self.height)) EMImageGenerator.drawGrid(painter, nc, nr, self.xOffset, self.yOffset, self.tileSize) if self.mouseIndex != (-1, -1) and not self.mousePressed: if self.openTab == 0 and self.selectedObject[0] != -1: self.drawPreviewTileSingle(painter) elif self.openTab == 1 and self.selectedObject[1] != -1: self.drawPreviewTileGroup(painter) # Draw the notes notes = self.model.getMapNotes() for index in range(len(notes)): # print(index) note = notes[index] if self.pressedItem is None or self.pressedItem[1] is not note: np = note.getPos() # print(np) np = (int(np[0] * self.tileSize), int(np[1] * self.tileSize)) options = [] print(self.mouseOverItem) if (self.mouseOverItem is not None and self.mouseOverItem[0] == 3 and self.mouseOverItem[1] == index): options.append("mouseover") EMImageGenerator.drawNoteIcon(painter, note, np[0] - 24, np[1] - 24, 48, index + 1, options) # note.drawNoteIcon(painter, ) index += 1 if self.pressedItem is not None: if self.pressedItem[0] == 3: note = self.pressedItem[1] np = note.getPos() # print(np) np = (int(np[0] * self.tileSize), int(np[1] * self.tileSize)) EMImageGenerator.drawNoteIcon(painter, note, np[0] - 24, np[1] - 24, 48, notes.index(note) + 1, ["selected"])
def paintEvent(self, paintEvent): painter = QPainter(self) img = EMImageGenerator.getTextureImage(self.model.getUid()) painter.drawImage(0, 0, img, 0, 0, self.width, self.height) painter.end()
def updateImage(self): self.generatedImage = EMImageGenerator.genImageFromModel(self.model)
def __init__(self, model, width=216, height=216): super(TextureEditPreview, self).__init__(model, 1, 1, 216, width, height) self.generatedImage = EMImageGenerator.genImageFromModel(model)
def setPTile(self, tileId): self.selectedObject[0] = tileId self.pTileImage = EMImageGenerator.genImageFromModel( ModelManager.fetchByUid(ModelManager.TileName, tileId), {"transformOptions": self.sOptions})