Пример #1
0
    def __init__(self, parent):
        """Exclamation icon graphics item.
        Used to notify that a ProjectItem is missing some configuration.

        Args:
            parent (ProjectItemIcon): the parent item
        """
        super().__init__(parent)
        self._parent = parent
        self._notifications = list()
        self.renderer = QSvgRenderer()
        self.colorizer = QGraphicsColorizeEffect()
        self.colorizer.setColor(QColor("red"))
        # Load SVG
        loading_ok = self.renderer.load(
            ":/icons/project_item_icons/exclamation-circle.svg")
        if not loading_ok:
            return
        size = self.renderer.defaultSize()
        self.setSharedRenderer(self.renderer)
        dim_max = max(size.width(), size.height())
        rect_w = parent.rect().width()  # Parent rect width
        self.setScale(0.2 * rect_w / dim_max)
        self.setGraphicsEffect(self.colorizer)
        self.setAcceptHoverEvents(True)
        self.setFlag(QGraphicsItem.ItemIsSelectable, enabled=False)
        self.hide()
Пример #2
0
    def refreshImage(self, i, j):
        currentItem = self.itemAt(self.xFromCol(j), self.yFromRow(i),
                                  QTransform())
        if currentItem != 0 and currentItem.data(0) == 777:
            currentItem = None

        filename = self.getPieceFilename(self.board[i][j])
        if filename == "":
            return

        y = self.nPieceWidth * i
        x = self.nPieceWidth * j
        item = QGraphicsPixmapItem(QPixmap(filename))

        colorize = QGraphicsColorizeEffect()
        if self.board[i][j].color() == pieceColor.White:
            if self.threatPiece[i][j]:
                colorize.setColor(self.cLightPieceColorThreat)
            else:
                colorize.setColor(self.cLightPieceColor)
        else:
            if self.threatPiece[i][j]:
                colorize.setColor(self.cDarkPieceColorThreat)
            else:
                colorize.setColor(self.cDarkPieceColor)

        item.setGraphicsEffect(colorize)
        item.setCacheMode(QGraphicsItem.NoCache)  # needed for proper rendering
        item.setData(0, 777)

        self.addItem(item)
        item.setPos(x, y)
Пример #3
0
    def __init__(self, parent, id, country):
        super(Country, self).__init__()

        self.id = id

        self.country = country

        self.name = country["name"]

        self.parent = parent

        self.setSharedRenderer(self.parent.renderer)
        self.setCacheMode(QGraphicsItem.DeviceCoordinateCache)

        self.setElementId(self.id)

        self.setPos(self.country["position"]["x"],
                    self.country["position"]["y"])

        # set colour of country
        self.colour = QColor()
        self.colour.setRgb(self.country["colour"]["r"],
                           self.country["colour"]["g"],
                           self.country["colour"]["b"])

        qDebug("Country initialised: " + self.country["name"])

        # country will appear green when selected
        self.selectedEffect = QGraphicsColorizeEffect()
        self.selectedEffect.setColor("green")
        self.setGraphicsEffect(self.selectedEffect)

        # country is not selected by default
        self.deselectCountry()
    def __init__(self, toolbox, x, y, w, h, project_item, icon_file,
                 icon_color, background_color):
        """Base class for project item icons drawn in Design View.

        Args:
            toolbox (ToolBoxUI): QMainWindow instance
            x (float): Icon x coordinate
            y (float): Icon y coordinate
            w (float): Icon width
            h (float): Icon height
            project_item (ProjectItem): Item
            icon_file (str): Path to icon resource
            icon_color (QColor): Icon's color
            background_color (QColor): Background color
        """
        super().__init__()
        self._toolbox = toolbox
        self._project_item = project_item
        self._moved_on_scene = False
        self.renderer = QSvgRenderer()
        self.svg_item = QGraphicsSvgItem()
        self.colorizer = QGraphicsColorizeEffect()
        self.setRect(QRectF(x, y, w, h))  # Set ellipse coordinates and size
        self.text_font_size = 10  # point size
        # Make item name graphics item.
        name = project_item.name if project_item else ""
        self.name_item = QGraphicsSimpleTextItem(name)
        shadow_effect = QGraphicsDropShadowEffect()
        shadow_effect.setOffset(1)
        shadow_effect.setEnabled(False)
        self.setGraphicsEffect(shadow_effect)
        self.set_name_attributes()  # Set font, size, position, etc.
        # Make connector buttons
        self.connectors = dict(
            bottom=ConnectorButton(self, toolbox, position="bottom"),
            left=ConnectorButton(self, toolbox, position="left"),
            right=ConnectorButton(self, toolbox, position="right"),
        )
        # Make exclamation and rank icons
        self.exclamation_icon = ExclamationIcon(self)
        self.rank_icon = RankIcon(self)
        # Group the drawn items together by setting the background rectangle as the parent of other QGraphicsItems
        # NOTE: setting the parent item moves the items as one!
        self.name_item.setParentItem(self)
        for conn in self.connectors.values():
            conn.setParentItem(self)
        self.svg_item.setParentItem(self)
        self.exclamation_icon.setParentItem(self)
        self.rank_icon.setParentItem(self)
        brush = QBrush(background_color)
        self._setup(brush, icon_file, icon_color)
        # Add items to scene
        scene = self._toolbox.ui.graphicsView.scene()
        scene.addItem(self)
Пример #5
0
    def __init__(self, toolbox, x, y, project_item, icon_file, icon_color,
                 background_color):
        """Base class for project item icons drawn in Design View.

        Args:
            toolbox (ToolBoxUI): QMainWindow instance
            x (float): Icon x coordinate
            y (float): Icon y coordinate
            project_item (ProjectItem): Item
            icon_file (str): Path to icon resource
            icon_color (QColor): Icon's color
            background_color (QColor): Background color
        """
        super().__init__()
        self._toolbox = toolbox
        self._project_item = project_item
        self._moved_on_scene = False
        self._previous_pos = QPointF()
        self._current_pos = QPointF()
        self.icon_group = {self}
        self.renderer = QSvgRenderer()
        self.svg_item = QGraphicsSvgItem(self)
        self.colorizer = QGraphicsColorizeEffect()
        self.setRect(
            QRectF(x - self.ITEM_EXTENT / 2, y - self.ITEM_EXTENT / 2,
                   self.ITEM_EXTENT, self.ITEM_EXTENT))
        self.text_font_size = 10  # point size
        # Make item name graphics item.
        name = project_item.name if project_item else ""
        self.name_item = QGraphicsSimpleTextItem(name, self)
        self.set_name_attributes()  # Set font, size, position, etc.
        # Make connector buttons
        self.connectors = dict(
            bottom=ConnectorButton(self, toolbox, position="bottom"),
            left=ConnectorButton(self, toolbox, position="left"),
            right=ConnectorButton(self, toolbox, position="right"),
        )
        # Make exclamation and rank icons
        self.exclamation_icon = ExclamationIcon(self)
        self.rank_icon = RankIcon(self)
        brush = QBrush(background_color)
        self._setup(brush, icon_file, icon_color)
        self.activate()
Пример #6
0
 def __init__(self, toolbox, icon_file, icon_color, background_color):
     """
     Args:
         toolbox (ToolboxUI): QMainWindow instance
         icon_file (str): Path to icon resource
         icon_color (QColor): Icon's color
         background_color (QColor): Background color
     """
     super().__init__()
     self._toolbox = toolbox
     self.icon_file = icon_file
     self._moved_on_scene = False
     self.previous_pos = QPointF()
     self.current_pos = QPointF()
     self.icon_group = {self}
     self.renderer = QSvgRenderer()
     self.svg_item = QGraphicsSvgItem(self)
     self.colorizer = QGraphicsColorizeEffect()
     self.setRect(
         QRectF(-self.ITEM_EXTENT / 2, -self.ITEM_EXTENT / 2,
                self.ITEM_EXTENT, self.ITEM_EXTENT))
     self.text_font_size = 10  # point size
     # Make item name graphics item.
     self._name = ""
     self.name_item = QGraphicsSimpleTextItem(self._name, self)
     self.set_name_attributes()  # Set font, size, position, etc.
     # Make connector buttons
     self.connectors = dict(
         bottom=ConnectorButton(self, toolbox, position="bottom"),
         left=ConnectorButton(self, toolbox, position="left"),
         right=ConnectorButton(self, toolbox, position="right"),
     )
     # Make exclamation and rank icons
     self.exclamation_icon = ExclamationIcon(self)
     self.execution_icon = ExecutionIcon(self)
     self.rank_icon = RankIcon(self)
     brush = QBrush(background_color)
     self._setup(brush, icon_file, icon_color)
     shadow_effect = QGraphicsDropShadowEffect()
     shadow_effect.setOffset(1)
     shadow_effect.setEnabled(False)
     self.setGraphicsEffect(shadow_effect)
Пример #7
0
    def searched(self):
        """
        Provides the color changing animation for recently searched nodes
        """

        self.draw(Cell.SEARCHED)

        if self.node.isStart:
            self.setStart()
        elif self.node.isEnd:
            self.setEnd()
        else:

            self.effect = QGraphicsColorizeEffect(self)
            self.setGraphicsEffect(self.effect)

            self.paAnimation = QPropertyAnimation(self.effect, b"color")
            self.paAnimation.setStartValue(QColor(131, 18, 165))
            self.paAnimation.setEndValue(Cell.SEARCHED)
            self.paAnimation.setDuration(1000)
            self.paAnimation.start()