Exemplo n.º 1
0
    def create_qr_scene(self, scene, qr_pixel_map, qr_text, backgound_pixmap) :
        
        pixmap_item = QGraphicsPixmapItem(qr_pixel_map)
        
        pixmap_item.setY(100)
        pixmap_item.setX(100)

        background_item = QGraphicsPixmapItem(backgound_pixmap)


        url_item = QGraphicsTextItem(qr_text)
        url_item.setFont(QFont('Arial', 50))
        url_item.setTextWidth(820)
        url_item.setY(450)
        url_item.setX(1150)
        url_item.setZValue(1)
       
        pixmap_item.setZValue(1)
        background_item.setZValue(-1)
        
        scene.addItem(pixmap_item)
        scene.addItem(url_item)
        scene.addItem(background_item)
        

        return scene
Exemplo n.º 2
0
    def draw_message(self,
                     text: str,
                     name: str,
                     window_type="standard",
                     mode=0,
                     left=True) -> QGraphicsItemGroup:
        # Create the message box
        talk_window: QPixmap = self.view.talk_windows[window_type][mode]
        message_box = self.scene.addPixmap(talk_window)
        talk_window_x = _TALK_WINDOW_MODE_0_X if not mode else -3
        talk_window_y = _TALK_WINDOW_Y if not mode else _TALK_WINDOW_Y - 5
        message_box.setPos(talk_window_x, talk_window_y)

        # Create the name plate
        name_plate_texture: QPixmap = self.view.talk_windows["name_plate"][
            "plate"]
        name_plate = self.scene.addPixmap(name_plate_texture)
        name_plate_x = _NAME_PLATE_LEFT_X if left else _NAME_PLATE_RIGHT_X
        name_plate.setPos(name_plate_x, _NAME_PLATE_Y)

        # Create the name plate text
        name_plate_text = QGraphicsTextItem()
        name_plate_text.setPlainText(name)
        name_plate_text.setDefaultTextColor(QColor.fromRgba(0xFFFFFFB3))
        name_plate_text.setFont(self.view.name_plate_font)
        name_plate_text.setTextWidth(name_plate_texture.width())
        name_plate_text.setPos(name_plate_x, _NAME_PLATE_Y)

        # Center the name plate text
        block_format = QTextBlockFormat()
        block_format.setAlignment(QtGui.Qt.AlignCenter)
        cursor = name_plate_text.textCursor()
        cursor.select(QTextCursor.Document)
        cursor.mergeBlockFormat(block_format)
        cursor.clearSelection()
        name_plate_text.setTextCursor(cursor)
        self.scene.addItem(name_plate_text)

        # Create the message box text. Draw two lines if required.
        # Truncate lines with width > 312
        split_text = text.split("\n")
        message_box_text = QGraphicsTextItem()
        message_box_text_2 = QGraphicsTextItem()
        if split_text and split_text[0]:
            text_utils.draw_message_text(message_box_text,
                                         self.view.name_plate_font,
                                         split_text[0],
                                         _TALK_WINDOW_MODE_0_X + 20,
                                         _TALK_WINDOW_Y + 5, 312)
        if len(split_text) > 1 and split_text[1]:
            text_utils.draw_message_text(message_box_text_2,
                                         self.view.name_plate_font,
                                         split_text[1],
                                         _TALK_WINDOW_MODE_0_X + 20,
                                         _TALK_WINDOW_Y + 21, 312)

        group = self.scene.createItemGroup([
            message_box, message_box_text, message_box_text_2, name_plate,
            name_plate_text
        ])
        group.setZValue(2.0)
        return group
Exemplo n.º 3
0
class AbstractNode(AbstractGeneralGraphicsItemClass):
    __metaclass__ = AbstractGeneralGraphicsItem_Meta

    def __init__(self, graphWidget, state):
        super(AbstractNode, self).__init__()

        self.graph = weakref.ref(graphWidget)
        self.isAcceptable = state.isAcceptable
        self.isCurrent = state.isCurrent

        self.newPos = QPointF()
        self.setFlag(QGraphicsItem.ItemIsMovable)
        self.setFlag(QGraphicsItem.ItemIsSelectable)
        self.setFlag(QGraphicsItem.ItemSendsGeometryChanges)
        self.setCacheMode(self.DeviceCoordinateCache)
        self.setZValue(-1)
        self.setAcceptHoverEvents(True)

        self._edges = []
        self.currentFill = self.fillQColor
        self.border = QGraphicsEllipseItem(-self.radius, -self.radius,
                                           self.radius * 2, self.radius * 2)
        self.finalNodeBorder = QGraphicsEllipseItem(-self.radius + 5,
                                                    -self.radius + 5,
                                                    self.radius * 2 - 10,
                                                    self.radius * 2 - 10)
        self.finalNodeBorder.mapToParent(self.border.pos())
        if self.isAcceptable == False:
            pen = self.finalNodeBorder.pen()
            pen.setColor(QColor(25, 255, 5))
            self.finalNodeBorder.update()

        if self.isCurrent == True:
            self.resolveFillColor()

        self.labelBox = QGraphicsTextItem(self)
        self.labelBox.setPos(-self.radius / 2, -self.radius / 2)
        self.labelBox.setDefaultTextColor(QColor(0, 0, 0))

    @property
    @abstractmethod
    def borderQColor(self):
        pass

    @property
    @abstractmethod
    def fillQColor(self):
        pass

    @property
    @abstractmethod
    def currentStateFillQColor(self):
        pass

    @property
    @abstractmethod
    def radius(self):
        pass

    @abstractmethod
    def setLabel(self, value):
        pass

    def toggleCurrentState(self):
        self.isCurrent = not self.isCurrent
        self.resolveFillColor()

    def resolveFillColor(self):
        brush = QBrush()
        if self.isCurrent == True:
            brush.setColor(self.currentStateFillQColor)
            brush.setStyle(Qt.SolidPattern)
            self.currentFill = self.currentStateFillQColor
        else:
            brush.setColor(self.fillQColor)
            brush.setStyle(Qt.SolidPattern)
            self.currentFill = self.fillQColor
        self.border.setBrush(brush)
        self.update()

    def toggleFinalNodeBorder(self):
        self.isAcceptable = not self.isAcceptable
        self.resolveFinalNodeBorder()

    def resolveFinalNodeBorder(self):
        pen = QPen()
        if self.isAcceptable == True:
            pen.setColor(self.borderQColor)
            pen.setWidth(2)
        else:
            pen.setColor(self.currentFill)
            pen.setWidth(1)
        self.finalNodeBorder.setPen(pen)
        self.update()

    def addEdge(self, edge):
        self._edges.append(weakref.ref(edge))
        edge.adjust()

    def getEdges(self):
        return self._edges

    def getEdgesForInput(self, input):
        edges = []
        for edge in self._edges:
            if edge.onInput == input:
                edges.append(edge)
        return edges

    def getEdgesFromSelf(self, input):
        edges = []
        for edge in self._edges:
            if edge.onInput == input and edge.fromNode is self:
                edges.append(edge)
        return edges

    def getEdgeToNode(self, toNode):
        toReturn = None
        for edge in self._edges:
            if edge.toNode() is toNode:
                toReturn = edge
        return toReturn

    def boundingRect(self):
        adjust = 2.0
        return QRectF(-self.radius - adjust, -self.radius - adjust,
                      (self.radius + adjust) * 2, (self.radius + adjust) * 2)

    def shape(self):
        path = QtGui.QPainterPath()
        path.addEllipse(-self.radius, -self.radius, self.radius * 2,
                        self.radius * 2)
        return path

    def paint(self, painter, option, widget):
        pen = QPen()
        pen.setWidth(2)
        pen.setColor(self.borderQColor)
        brush = QBrush()
        self.border.setPen(pen)
        self.border.setBrush(brush)
        self.resolveFillColor()
        self.resolveFinalNodeBorder()
        self.border.paint(painter, option, widget)
        self.finalNodeBorder.paint(painter, option, widget)
        self.labelBox.setTextWidth(35)
        self.labelBox.setDefaultTextColor(QColor(0, 0, 0))

    def itemChange(self, change, value):
        if change == QGraphicsItem.ItemPositionChange:
            for edge in self._edges:
                edge().adjust()

        return QGraphicsItem.itemChange(self, change, value)

    def mousePressEvent(self, event):
        self.update()
        QGraphicsItem.mousePressEvent(self, event)

    def mouseReleaseEvent(self, event):
        QGraphicsItem.mouseReleaseEvent(self, event)
        self.update()