Ejemplo n.º 1
0
def glass_path(scene, x, y, w, h, colr):

    qp = QPainterPath()
    qp.addRoundedRect(x, y, w, h, 5, 5)

    gradient = QLinearGradient(0, +0, 0, 1)
    gradient.setCoordinateMode(QGradient.ObjectBoundingMode)
    gradient.setColorAt(0, colr)
    gradient.setColorAt(1, colr.lighter(150))
    brush = QBrush(gradient)

    item = QGraphicsPathItem()
    item.setPath(qp)
    item.setBrush(brush)
    scene.addItem(item)

    # Draw glass reflection

    glass = QPainterPath()
    r = 3
    glass.addRoundedRect(x + r, y + r, w - 2 * r, 2 * r, r, r)

    gradient = QLinearGradient(0, +0, 0, 1)
    gradient.setCoordinateMode(QGradient.ObjectBoundingMode)
    gradient.setColorAt(0, QColor(255, 255, 255, 188))
    gradient.setColorAt(1, QColor(255, 255, 255, 0))
    brush = QBrush(gradient)

    item = QGraphicsPathItem()
    item.setPath(glass)
    item.setBrush(brush)
    item.setPen(QPen(Qt.transparent))
    scene.addItem(item)
Ejemplo n.º 2
0
    def __init__(self, x1, y1, x2, y2, rgb, parent=None):
        #OVERLOADED IMPL?# DimLeaderObject::DimLeaderObject(DimLeaderObject* obj, QGraphicsItem* parent) : BaseObject(parent)
        """
        Default class constructor.

        :param `x1`: TOWRITE
        :type `x1`: qreal
        :param `y1`: TOWRITE
        :type `y1`: qreal
        :param `x2`: TOWRITE
        :type `x2`: qreal
        :param `y2`: TOWRITE
        :type `y2`: qreal
        :param `rgb`: TOWRITE
        :type `rgb`: QRgb
        :param `parent`: TOWRITE
        :type `parent`: `QGraphicsItem`_
        """
        super(DimLeaderObject, self).__init__(parent)

        qDebug("DimLeaderObject Constructor()")

        self.curved = bool()
        self.filled = bool()
        self.lineStylePath = QPainterPath()
        self.arrowStylePath = QPainterPath()
        self.arrowStyleAngle = float()  # qreal
        self.arrowStyleLength = float()  # qreal
        self.lineStyleAngle = float()  # qreal
        self.lineStyleLength = float()  # qreal

        self.init(x1, y1, x2, y2, rgb,
                  Qt.SolidLine)  # TODO: getCurrentLineType
Ejemplo n.º 3
0
    def _draw_serie(self, painter, ndx_serie, color):

        last_item = len(self.data) - 1

        serie = self.data[ndx_serie]

        serie_below = [0] * len(self.data[last_item])
        if ndx_serie < len(self.data) - 1:
            serie_below = self.data[ ndx_serie + 1 ]

        qlp = QPainterPath() # The top line path
        qfp = QPainterPath() # the filled region path


        x = float(0) * self.x_factor
        y = serie[0] * self.y_factor
        qlp.moveTo(self.x_base + x,self.y_base - y)
        qfp.moveTo(self.x_base + x,self.y_base - y)

        for i in range(1,len(serie)):
            x = float(i) * self.x_factor
            y = float(serie[i]) * self.y_factor

            #print i,y

            qlp.lineTo(self.x_base + x, self.y_base-y)
            qfp.lineTo(self.x_base + x, self.y_base-y)



        for i in reversed(range(0,len(serie_below))):
            x = float(i) * self.x_factor
            y = float(serie_below[i]) * self.y_factor

            qfp.lineTo(self.x_base + x, self.y_base-y)

        qfp.closeSubpath()


        fill_color = QColor(color)
        fill_color.setAlpha(64)
        brush = QBrush(fill_color)
        painter.fillPath(qfp,brush)

        pen = QPen()
        pen.setColor(color)
        if ndx_serie == self.ndx_best_serie:
            pen.setWidth(6)
        else:
            pen.setWidth(2)

        painter.setPen(pen)

        painter.drawPath(qlp)
Ejemplo n.º 4
0
    def setPortFlags(self, flags):
        self.m_portFlags = flags

        if self.m_portFlags & self.TypePort:
            font = self.scene().font()
            font.setItalic(True)
            self.label.setFont(font)
            self.setPath(QPainterPath())
        elif self.m_portFlags & self.NamePort:
            font = self.scene().font()
            font.setBold(True)
            self.label.setFont(font)
            self.setPath(QPainterPath())
Ejemplo n.º 5
0
    def __init__(self, parent, scene, view):
        super(QNodesEditor, self).__init__(parent)

        self.scene = scene
        self.scene.installEventFilter(self)

        gridSize = 25
        gridMap = QPixmap(gridSize,gridSize)
        gridPainter = QPainter(gridMap)
        gridPainter.fillRect(0,0,gridSize,gridSize, QApplication.palette().window().color().darker(103))
        gridPainter.fillRect(1,1,gridSize-2,gridSize-2, QApplication.palette().window())
        gridPainter.end()
        self.scene.setBackgroundBrush( QBrush(gridMap) )

        originSize = 50
        originItem = QGraphicsPathItem()
        path = QPainterPath()
        path.moveTo(0,-originSize)
        path.lineTo(0,originSize)
        path.moveTo(-originSize,0)
        path.lineTo(originSize,0)
        originItem.setPath(path)
        originItem.setPen(QPen(QApplication.palette().window().color().darker(110),2))
        originItem.setZValue(-2)
        self.scene.addItem(originItem)

        self.view = view
        self.view.setDragMode(QGraphicsView.RubberBandDrag)
        self.view.setRenderHint(QPainter.Antialiasing)

        self.connection = None
Ejemplo n.º 6
0
    def paint(self, painter, option, widget):
        w = self.w
        h = self.h
        key = QPainterPath()
        key.setFillRule(Qt.WindingFill)

        painter.save()
        painter.rotate(self.angle)
        key.moveTo(0.0, 0.0)
        key.lineTo(w, 0.0)
        key.lineTo(w, h)
        key.lineTo(0.0, h)
        painter.fillPath(key, self.color)
        painter.setPen(QPen(Qt.white, 1))
        key.moveTo(0, 0)
        painter.drawLine(0, 0, w, 0)
        painter.drawLine(w, 0, w, h)
        painter.drawLine(w, h, 0, h)
        painter.drawLine(0, h, 0, 0)

        painter.setPen(Qt.white)
        metric = painter.fontMetrics()

        margin = 5
        textBound = metric.boundingRect(self.text)
        painter.drawText(margin, h - margin, self.text)
        painter.restore()
Ejemplo n.º 7
0
    def __init__(self, parent):
        super(QNEBlock, self).__init__(parent)

        self.m_nodeEditor = None
        self.m_name = ""
        self.m_uuid = ""

        self.normalBrush = QApplication.palette().dark()
        normalColor = self.normalBrush.color()
        normalColor.setAlphaF(0.8)
        self.normalBrush.setColor(normalColor)

        self.selectedBrush = QApplication.palette().light()
        selectedColor = self.selectedBrush.color()
        selectedColor.setAlphaF(0.8)
        self.selectedBrush.setColor(selectedColor)

        self.pen = QPen(QApplication.palette().text().color(), 1)

        path = QPainterPath()
        path.addRoundedRect(-50, -15, 100, 30, 5, 5)
        self.setPath(path)
        self.setBrush(self.normalBrush)
        self.setFlag(QGraphicsItem.ItemIsMovable)
        self.setFlag(QGraphicsItem.ItemIsSelectable)

        self.effect = QGraphicsDropShadowEffect(None)
        self.effect.setBlurRadius(8)
        self.effect.setOffset(2, 2)
        self.setGraphicsEffect(self.effect)

        self.horzMargin = 20
        self.vertMargin = 5
        self.width = self.horzMargin
        self.height = self.vertMargin
Ejemplo n.º 8
0
    def _draw_indicator(self, event, qp):

        cx, cy, w, r = self._get_geometry(event)

        pen = qp.pen()
        pen.setWidth(3)
        pen.setColor(Qt.black)
        qp.setPen(pen)
        qp.setBrush(Qt.black)

        ro = r - 10
        cx, cy = r + 5, r + 5

        qp.translate(cx, cy)
        qp.rotate(self.indicator)

        path = QPainterPath()
        path.moveTo(-2, 0)
        path.lineTo(0, -ro)
        path.lineTo(2, 0)
        qp.drawPath(path)

        cr = 10
        cr2 = cr / 2.0

        qp.drawEllipse(-cr2, -cr2, cr, cr)
Ejemplo n.º 9
0
 def set_shape(self, width, height):
     ''' Define the bouding rectangle of the JOIN symbol '''
     circ = min(width, height)
     path = QPainterPath()
     path.addEllipse(0, 0, circ, circ)
     self.setPath(path)
     super(Join, self).set_shape(width, height)
Ejemplo n.º 10
0
    def _draw_serie(self, painter, ndx_serie, color):

        serie = self.data[ndx_serie]

        if not serie:
            return

        qp = QPainterPath()
        # qp.addRect(2,2,total_width-4,total_height-4)

        x = float(0) * self.x_factor
        y = serie[0] * self.y_factor
        qp.moveTo(self.x_centers[0],self.y_base - y)
        # print y_base

        for i in range(1,len(serie)):
            x = float(i) * self.x_factor
            y = float(serie[i]) * self.y_factor

            qp.lineTo(self.x_centers[i], self.y_base-y)

        pen = QPen()
        pen.setColor(color)

        if ndx_serie == self.ndx_best_serie:
            pen.setWidth(6)
        else:
            pen.setWidth(2)

        painter.setPen(pen)
        painter.drawPath(qp)
Ejemplo n.º 11
0
    def _draw_serie(self, painter, ndx_serie, color):

        serie = self.data[ndx_serie]

        #mainlog.debug(serie)

        fill_color = QColor(color)
        fill_color.setAlpha(64)
        brush = QBrush(fill_color)
        pen = QPen()
        pen.setCapStyle(Qt.SquareCap)
        pen.setColor(color)

        qp = QPainterPath()
        painter.setPen(pen)

        for i in range(len(serie)):
            x, y_top, y_below = self._item_coordinates(i)

            h = max(1, float(y_top - y_below - 1))
            qp.addRect( x,
                        float(self.y_base-y_top),
                        float(self.bar_width),
                        h)

        painter.fillPath(qp,brush)
        painter.drawPath(qp)

        #mainlog.debug("Drawing peak values, juste before {}".format(self._peak_values))
        if self._peak_values:
            #mainlog.debug("Drawing peak values")
            self._draw_peak_values(painter, self._peak_values )
Ejemplo n.º 12
0
    def addPort(self, name, hasInput=False, hasOutput=False, flags=0):
        port = QNEPort(self)
        port.setName(name)
        port.setCanConnect(hasInput, hasOutput)
        port.setNEBlock(self)
        port.setPortFlags(flags)

        innerSize = port.innerSize()
        width = innerSize.width()
        height = innerSize.height()
        if width > self.width - self.horzMargin:
            self.width = width + self.horzMargin
        self.height += height

        path = QPainterPath()
        path.addRoundedRect(-self.width / 2, -self.height / 2, self.width,
                            self.height, 5, 5)
        self.setPath(path)

        y = -self.height / 2 + self.vertMargin + port.radius()
        for port_ in self.childItems():
            if port_.type() != QNEPort.Type:
                continue

            port_.setPos(-self.width / 2 - port.radius(), y)
            port_.setWidth(self.width)
            y += port_.innerSize().height()

        return port
Ejemplo n.º 13
0
 def reshape(self):
     ''' Update the connection shape - redefined: if the last element
     of a branch is e.g. a nextstate, don't join the connection point '''
     if self.parentItem().terminal_symbol:
         self.setPath(QPainterPath())
     else:
         super(JoinConnection, self).reshape()
Ejemplo n.º 14
0
    def _draw_horizontal_ruler(self, painter, text, y_value, color):

        y = y_value * self.y_factor

        pen = QPen()
        pen.setCapStyle(Qt.SquareCap)
        pen.setColor(color)

        qp = QPainterPath()

        r = QRect(1,1,1000,1000)
        bb = painter.boundingRect(r,Qt.AlignLeft,text)
        bb = QRect(self.x_base,self.y_base - y - bb.height(), bb.width() + 2, bb.height())

        # print("{} {} {} {}".format(bb.x(),bb.y(),bb.width(),bb.height()))

        fill_color = QColor(0,0,0)
        fill_color.setAlpha(128)
        brush = QBrush(fill_color)

        painter.fillRect(bb,brush)

        qp.moveTo(self.x_base,self.y_base - y)
        qp.lineTo(self.total_width + self.x_base, self.y_base - y)

        painter.setPen(pen)
        painter.drawPath(qp)

        text_pen = QPen()
        text_pen.setCapStyle(Qt.RoundCap)
        text_pen.setColor(color) # alpha=255=fully opaque
        text_pen.setWidth(1)

        painter.setPen(text_pen)
        painter.drawText(self.x_base,self.y_base - y - 5,text)
Ejemplo n.º 15
0
    def __init__(self, strng, x, y, rgb, parent=None):
        #OVERLOADED IMPL?# TextSingleObject::TextSingleObject(TextSingleObject* obj, QGraphicsItem* parent) : BaseObject(parent)
        """
        Default class constructor.

        :param `strng`: TOWRITE
        :type `strng`: QString
        :param `x`: TOWRITE
        :type `x`: qreal
        :param `y`: TOWRITE
        :type `y`: qreal
        :param `rgb`: TOWRITE
        :type `rgb`: QRgb
        :param `parent`: TOWRITE
        :type `parent`: `QGraphicsItem`_
        """
        super(TextSingleObject, self).__init__(parent)

        qDebug("TextSingleObject Constructor()")

        self.objText = str()
        self.objTextFont = str()
        self.objTextJustify = str()
        self.objTextSize = float()  # qreal
        self.objTextBold = bool()
        self.objTextItalic = bool()
        self.objTextUnderline = bool()
        self.objTextStrikeOut = bool()
        self.objTextOverline = bool()
        self.objTextBackward = bool()
        self.objTextUpsideDown = bool()
        self.objTextPath = QPainterPath()

        self.init(str, x, y, rgb, Qt.SolidLine)  # TODO: getCurrentLineType
Ejemplo n.º 16
0
    def _draw_selected_items_in_series(self, painter):
        fm = painter.fontMetrics()

        pen = QPen()
        pen.setWidth(1)
        pen.setColor(Qt.GlobalColor.white)
        painter.setPen(pen)

        # We assume all series have the very same number of values
        # and all values on the same index are drawn on the same X
        # coordinate

        ndx_serie = self.best_serie_intra_ndx

        aesthetic_shift = 5

        if ndx_serie is not None:

            to_draw = []
            for i in range(len(self.data)):
                x, y = self._item_coordinates_lines(i, ndx_serie)
                #mainlog.debug("{} {}".format(ndx_serie,i))
                v = self.data[i][ndx_serie]

                text = str(int(v))

                to_draw.append( (self.y_base - y, text) )

            last_y = 100000
            for y, text in sorted( to_draw, key=lambda z : z[0], reverse=True):
                r = QRect(x + aesthetic_shift,0,1000,1000)
                bb = painter.boundingRect(r,Qt.AlignLeft,text)
                if bb.right() > self.width():
                    x = x - bb.width() - 2*aesthetic_shift# left align

                if y + bb.height() > last_y:
                    y = last_y - bb.height()

                fill_color = QColor(16, 16, 48)
                fill_color.setAlpha(196)
                brush = QBrush(fill_color)
                margin = 2
                r = QRect(x + aesthetic_shift - margin,
                          y - aesthetic_shift - bb.height() - margin,
                          bb.width() + 2*margin,
                          bb.height() + 2*margin)
                painter.fillRect(r, brush)

                painter.drawText(x + aesthetic_shift,
                                 y - aesthetic_shift,
                                 text)

                last_y = y

            x, y = self._item_coordinates_lines(0, ndx_serie)
            qp = QPainterPath()
            qp.moveTo(x, self.y_base)
            qp.lineTo(x, self.y_base - self.total_height)
            painter.drawPath(qp)
Ejemplo n.º 17
0
    def objectSavePath(self):
        """
        TOWRITE

        :rtype: `QPainterPath`_
        """
        path = QPainterPath()
        path.lineTo(self.objectDeltaX(), self.objectDeltaY())
        return path
Ejemplo n.º 18
0
    def objectSavePath(self):
        """
        TOWRITE

        :rtype: `QPainterPath`_
        """
        path = QPainterPath()
        path.addRect(-0.00000001, -0.00000001, 0.00000002, 0.00000002)
        return path
Ejemplo n.º 19
0
 def __init__(self, pos, edge, symbol):
     ''' Create the point - as a small, lightblue box '''
     super(Connectionpoint, self).__init__(pos, edge=edge)
     path = QPainterPath()
     path.addRect(0, 0, 10, 10)
     self.setPath(path)
     self.setPos(pos.x() - 5, pos.y() - 5)
     # Symbol actually owning the connection point
     self.symbol = symbol
Ejemplo n.º 20
0
 def set_shape(self, width, height):
     ''' Compute the polygon to fit in width, height '''
     path = QPainterPath()
     path.lineTo(width, 0)
     path.lineTo(width, height)
     path.lineTo(0, height)
     path.lineTo(0, 0)
     self.setPath(path)
     super(Task, self).set_shape(width, height)
Ejemplo n.º 21
0
 def set_shape(self, width, height):
     ''' Compute the polygon to fit in width, height '''
     path = QPainterPath()
     path.addRect(0, 0, width, height)
     path.moveTo(7, 0)
     path.lineTo(7, height)
     path.moveTo(width - 7, 0)
     path.lineTo(width - 7, height)
     self.setPath(path)
     super(ProcedureCall, self).set_shape(width, height)
Ejemplo n.º 22
0
 def shape(self):
     """
     Returns the shape of this item as a QPainterPath in local coordinates.
     """
     path = QPainterPath()
     path.addRect(self.rect())
     if self.isSelected():
         for shape in self.handles.values():
             path.addEllipse(shape)
     return path
Ejemplo n.º 23
0
 def set_shape(self, width, height):
     ''' Define polygon points to draw the symbol '''
     path = QPainterPath()
     path.moveTo(width / 2, 0)
     path.lineTo(width, height / 2)
     path.lineTo(width / 2, height)
     path.lineTo(0, height / 2)
     path.lineTo(width / 2, 0)
     self.setPath(path)
     super(Decision, self).set_shape(width, height)
Ejemplo n.º 24
0
 def set_shape(self, width, height):
     ''' Compute the polygon to fit in width, height '''
     path = QPainterPath()
     path.addRoundedRect(0, 0, width, height, height / 2, height / 2)
     path.moveTo(min(width / 2, height / 2), 0)
     path.lineTo(min(width / 2, height / 2), height)
     path.moveTo(max(width / 2, width - height / 2), 0)
     path.lineTo(max(width / 2, width - height / 2), height)
     self.setPath(path)
     super(Start, self).set_shape(width, height)
Ejemplo n.º 25
0
    def setRectFromRect(self, r):
        """
        TOWRITE

        :param `r`: TOWRITE
        :type `r`: QPointF
        """
        p = QPainterPath()
        p.addRect(r)
        self.setPath(p)
Ejemplo n.º 26
0
 def set_shape(self, width, height):
     ''' Compute the polygon to fit in width, height '''
     self.setPen(QPen(Qt.blue))
     self.textbox_alignment = Qt.AlignLeft | Qt.AlignTop
     path = QPainterPath()
     path.moveTo(0, 0)
     path.lineTo(0, height)
     #path.moveTo(0, height / 2)
     #path.lineTo(width, height / 2)
     self.setPath(path)
     super(Input, self).set_shape(width, height)
Ejemplo n.º 27
0
 def fillEllipse(
     self,
     painter,
     x,
     y,
     size,
     brush,
 ):
     path = QPainterPath()
     path.addEllipse(x, y, size, size)
     painter.fillPath(path, brush)
Ejemplo n.º 28
0
    def reshape(self):
        ''' Update the shape of the edge (redefined function) '''
        path = QPainterPath()
        # If there is a starting point, draw a line to the first curve point
        if self.start_point:
            path.moveTo(self.source_connection.center)
            path.lineTo(self.bezier[0])
        else:
            path.moveTo(self.source_connection.center)
        # Loop over the curve points:
        for group in self.bezier[1:]:
            path.cubicTo(*[point.center for point in group])

        # If there is an ending point, draw a line to it
        if self.end_point:
            path.lineTo(self.end_connection.center)

        end_point = path.currentPosition()
        arrowhead = self.angle_arrow(path)
        path.lineTo(arrowhead[0])
        path.moveTo(end_point)
        path.lineTo(arrowhead[1])
        path.moveTo(end_point)
        try:
            # Add the transition label, if any (none for the START edge)
            font = QFont('arial', pointSize=8)
            metrics = QFontMetrics(font)
            label = self.edge.get('label', '') or ''
            lines = label.split('\n')
            width = metrics.width(max(lines))  # longest line
            height = metrics.height() * len(lines)
            # lp is the position of the center of the text
            pos = self.mapFromScene(*self.edge['lp'])
            if not self.text_label:
                self.text_label = QGraphicsTextItem(self.edge.get('label', ''),
                                                    parent=self)
                self.text_label.setX(pos.x() - width / 2)
                self.text_label.setY(pos.y() - height / 2)
                self.text_label.setFont(font)
                # Make horizontal center alignment, as dot does
                self.text_label.setTextWidth(
                    self.text_label.boundingRect().width())
                fmt = QTextBlockFormat()
                fmt.setAlignment(Qt.AlignHCenter)
                cursor = self.text_label.textCursor()
                cursor.select(QTextCursor.Document)
                cursor.mergeBlockFormat(fmt)
                cursor.clearSelection()
                self.text_label.setTextCursor(cursor)
                self.text_label.show()
        except KeyError:
            # no label
            pass
        self.setPath(path)
Ejemplo n.º 29
0
 def __init__(self, pos, edge):
     ''' Set the original control point - with color, shape '''
     path = QPainterPath()
     path.addEllipse(pos.x() - 5, pos.y() - 5, 10, 10)
     super(Controlpoint, self).__init__(path, parent=edge)
     self.setPen(QColor(50, 100, 120, 200))
     self.setBrush(QColor(200, 200, 210, 120))
     self.setFlags(QGraphicsItem.ItemIsSelectable
                   | QGraphicsItem.ItemIsMovable)
     self.edge = edge
     self.hide()
Ejemplo n.º 30
0
 def updatePath(self):
     """
     TOWRITE
     """
     path = QPainterPath()
     r = self.rect()  # QRectF
     path.arcMoveTo(r, 0)
     path.arcTo(r, 0, 360)
     # NOTE: Reverse the path so that the inside area isn't considered part of the ellipse
     path.arcTo(r, 0, -360)
     self.setObjectPath(path)