Esempio n. 1
0
    def __update(self) -> None:
        color = port_colors[self.__target_type or self.current_type()]

        if self.__highlighted:
            self.setOpacity(1.0)

            self.__tooltip.setVisible(self.__highlighted)
            ttpos = self.scenePos()
            ttpos += QtCore.QPointF(
                0, -self.__tooltip.boundingRect().height() / 2)
            if self.__desc.direction == node_db.PortDescription.OUTPUT:
                ttpos += QtCore.QPointF(20, 0)
            else:
                ttpos -= QtCore.QPointF(
                    20 + self.__tooltip.boundingRect().width(), 0)
            self.__tooltip.setPos(ttpos)

        else:
            self.setOpacity(0.7)
            self.__tooltip.setVisible(False)

        if self.__highlighted or self.__target_type is not None:
            pen = QtGui.QPen()
            pen.setColor(Qt.red)
            pen.setWidth(2)
            self.setPen(pen)
            self.setBrush(color)
            rect = QtCore.QRectF(-15, -12, 30, 24)

        else:
            pen = QtGui.QPen()
            pen.setColor(QtGui.QColor(80, 80, 200))
            pen.setWidth(1)
            self.setPen(pen)
            self.setBrush(color)
            rect = QtCore.QRectF(-10, -8, 20, 16)

        path = QtGui.QPainterPath()
        if self.__desc.direction == node_db.PortDescription.INPUT:
            path.moveTo(0, rect.top())
            path.arcTo(rect, 90, 180)

        else:
            path.moveTo(0, rect.top())
            path.arcTo(rect, 90, -180)

        self.setPath(path)
Esempio n. 2
0
    def paint(self, painter, option, widget):
        r = self.radius
        if not self.captured and self.glow and settings.on_shadows:
            gr = settings.glow_radius
            img = QImage(gr * 2, gr * 2, 6)
            img.fill(0)
            ipainter = QPainter(img)
            grad = QRadialGradient(gr, gr, gr)
            alpha = int(self.radius / settings.max_planet_radius * 4 if self.bang else 1) * 50
            grad.setColorAt(0, QColor(255, 166, 0, min(alpha, 255)))
            grad.setColorAt(1, QColor(0, 0, 0, 0))
            brush = QBrush(grad)
            ipainter.setBrush(brush)
            ipainter.setPen(QColor(0, 0, 0, 0))
            ipainter.drawEllipse(0, 0, gr * 2, gr * 2)
            ipainter.setCompositionMode(7)
            for fangle, sl, fp, sp in self.shadow_collection:
                path = QPainterPath(QPointF(*fp))
                path.arcTo(0, 0, gr * 2, gr * 2, fangle, sl)
                path.lineTo(*sp)
                path.lineTo(*fp)
                ipainter.fillPath(path, QBrush(QColor(0, 0, 0, 0)))
            ipainter.end()
            painter.drawImage(r - gr, r - gr, img)
            self.shadow_collection = []

        super(Planet, self).paint(painter, option, widget)

        if not self.glow:
            for rate, vect in self.glow_collection:
                r_vect = Vect(r, r)
                vect.len = r
                vect += r_vect
                x, y = vect.coord
                alpha = int(255 * rate)
                grad = QRadialGradient(x, y, r * 2)
                grad.setColorAt(0, QColor(255, 166, 0, alpha))
                grad.setColorAt(0.7, QColor(0, 0, 0, 0))
                brush = QBrush(grad)
                painter.setBrush(brush)
                painter.setPen(QColor(0, 0, 0, 0))
                painter.drawEllipse(0, 0, r * 2, r * 2)
            self.glow_collection = []
        self.draw_atmosphere(painter)
Esempio n. 3
0
File: gui2.py Progetto: LCAS/ToNE
    def __init__(self, diagramType, contextMenu, parent=None, scene=None):
        super(DiagramItem, self).__init__(parent, scene)

        self.arrows = []

        self.diagramType = diagramType
        self.contextMenu = contextMenu

        path = QtGui.QPainterPath()
        if self.diagramType == self.StartEnd:
            path.moveTo(200, 50)
            path.arcTo(150, 0, 50, 50, 0, 90)
            path.arcTo(50, 0, 50, 50, 90, 90)
            path.arcTo(50, 50, 50, 50, 180, 90)
            path.arcTo(150, 50, 50, 50, 270, 90)
            path.lineTo(200, 25)
            self.myPolygon = path.toFillPolygon()
        elif self.diagramType == self.Conditional:
            self.myPolygon = QtGui.QPolygonF([
                    QtCore.QPointF(-25, 0), QtCore.QPointF(0, 25),
                    QtCore.QPointF(25, 0), QtCore.QPointF(0, -25),
                    QtCore.QPointF(-25, 0)])
        elif self.diagramType == self.Step:
            self.myPolygon = QtGui.QPolygonF([
                    QtCore.QPointF(-25, -25), QtCore.QPointF(25, -25),
                    QtCore.QPointF(25, 25), QtCore.QPointF(-25, 25),
                    QtCore.QPointF(-25, -25)])
        else:
            self.myPolygon = QtGui.QPolygonF([
                    QtCore.QPointF(-30, -20), QtCore.QPointF(-15, 20),
                    QtCore.QPointF(30, 20), QtCore.QPointF(15, -20),
                    QtCore.QPointF(-30, -20)])


        self.setPolygon(self.myPolygon)
        self.setFlag(QtGui.QGraphicsItem.ItemIsMovable, True)
        self.setFlag(QtGui.QGraphicsItem.ItemIsSelectable, True)