def drawPatchQt(self, pos, turn, invert, patch_type, image, size, foreColor, backColor, penwidth): # pylint: disable=unused-argument """ :param size: patch size """ path = self.PATH_SET[patch_type] if not path: # blank patch invert = not invert path = [(0., 0.), (1., 0.), (1., 1.), (0., 1.), (0., 0.)] polygon = QPolygonF([QPointF(x * size, y * size) for x, y in path]) rot = turn % 4 rect = [ QPointF(0., 0.), QPointF(size, 0.), QPointF(size, size), QPointF(0., size) ] rotation = [0, 90, 180, 270] nopen = QtGui.QPen(foreColor, Qt.NoPen) foreBrush = QtGui.QBrush(foreColor, Qt.SolidPattern) if penwidth > 0: pen_color = QtGui.QColor(255, 255, 255) pen = QtGui.QPen(pen_color, Qt.SolidPattern) pen.setWidth(penwidth) painter = QPainter() painter.begin(image) painter.setPen(nopen) painter.translate(pos[0] * size + penwidth / 2, pos[1] * size + penwidth / 2) painter.translate(rect[rot]) painter.rotate(rotation[rot]) if invert: # subtract the actual polygon from a rectangle to invert it poly_rect = QPolygonF(rect) polygon = poly_rect.subtracted(polygon) painter.setBrush(foreBrush) if penwidth > 0: # draw the borders painter.setPen(pen) painter.drawPolygon(polygon, Qt.WindingFill) # draw the fill painter.setPen(nopen) painter.drawPolygon(polygon, Qt.WindingFill) painter.end() return image