예제 #1
0
class RText(QObject):
    def __init__(self, text, x, y, size, color):
        self._pos = QPointF(x - 1.8, y + 1.8)
        super().__init__()
        self.text = QGraphicsTextItem(text)
        transform = QTransform.fromScale(0.3, -0.3)
        self.text.setTransformOriginPoint(self._pos)
        self.text.setTransform(transform)
        self.text.setPos(self._pos)
        # self.text.setRotation(-180)
        font = QFont("Times", 2)
        self.text.setFont(font)

        self._visible = 1

    @pyqtProperty(int)
    def visible(self):
        return self._visible

    @visible.setter
    def visible(self, value):
        if value > 0:
            self.text.show()
        else:
            self.text.hide()
        self._visible = value
 def loadMap(self, mapLocation):
     with open(mapLocation) as file:
         mapObjList = json.load(file)
     for item in mapObjList["objects"]:
         if (item["type"] == "rect"):
             shape = QGraphicsRectItem(item["centerX"] - item["length"] / 2, -item["centerY"] - item["width"] / 2,
                                       item["length"], item["width"])
             shape.setTransformOriginPoint(QPoint(item["centerX"], -item["centerY"]))
             shape.setPen(QPen(self.black))
             shape.setBrush(QBrush(self.black, Qt.SolidPattern))
             shape.setRotation(item["rotation"])
             self.scene.addItem(shape)
         elif (item["type"] == "text"):
             label = QGraphicsTextItem(item["text"])
             label.setX(item["centerX"] - item["length"] / 2)
             label.setY(-item["centerY"] - item["width"] / 2)
             font = QFont("Bavaria")
             font.setPointSize(24)
             font.setWeight(QFont.Bold)
             label.setFont(font)
             label.setTransformOriginPoint(QPoint(item["length"] / 2, item["width"]/2))
             label.setRotation(item["rotation"])
             self.RoomNames.append(label)
             self.scene.addItem(label)
         elif (item["type"] == "obstacle"):
             shape = QGraphicsRectItem(item["centerX"] - item["length"] / 2, -item["centerY"] - item["width"] / 2,
                                       item["length"], item["width"])
             shape.setTransformOriginPoint(QPoint(item["centerX"], -item["centerY"]))
             shape.setPen(QPen(self.gray))
             shape.setBrush(QBrush(self.gray, Qt.SolidPattern))
             shape.setRotation(item["rotation"])
             self.ObstacleList.append(shape)
         elif (item["type"] == "plant"):
             shape = QGraphicsEllipseItem(item["centerX"] - item["length"] / 2, -item["centerY"] - item["width"] / 2,
                                          item["length"], item["width"])
             shape.setTransformOriginPoint(QPoint(item["centerX"], -item["centerY"]))
             shape.setPen(QPen(self.green))
             shape.setBrush(QBrush(self.green, Qt.SolidPattern))
             shape.setRotation(item["rotation"])
             self.ObstacleList.append(shape)
     self.OperatorMap.scale(self.scaleFactor, self.scaleFactor)