Esempio n. 1
0
def initBrushes():
    """
    returns a list of brush families.
    Eraser is the last item of the list.
    @return:
    @rtype: list of brushFamily instances
    """
    brushes = []
    ######################
    # standard round brush
    ######################
    baseSize = 400  # 25
    qpp = QPainterPath()
    qpp.addEllipse(QRect(0, 0, baseSize, baseSize))
    roundBrushFamily = brushFamily('Round', baseSize, qpp, presetFilename=None)
    brushes.append(roundBrushFamily)
    ##########
    # eraser
    ##########
    qpp = QPainterPath()
    qpp.addEllipse(QRect(0, 0, baseSize, baseSize))
    eraserFamily = brushFamily('Eraser', baseSize, qpp)
    # eraser must be added last
    brushes.append(eraserFamily)
    return brushes
Esempio n. 2
0
    def draw_border(self, painter):
        painter.save()
        painter.translate(0, self.t_height)

        if in_range(self.red_offset, self.l, self.r):
            # non-red zone
            path = QPainterPath()
            path.moveTo(self.red_offset, 0)
            path.lineTo(self.l, 0)
            path.lineTo(self.l, self.bar_height)
            path.lineTo(self.red_offset, self.bar_height)

            painter.drawPath(path)

            # red zone
            path = QPainterPath()
            path.moveTo(self.red_offset, 0)
            path.lineTo(self.r, 0)
            path.lineTo(self.r, self.bar_height)
            path.lineTo(self.red_offset, self.bar_height)

            painter.setPen(self.red_pen)
            painter.drawPath(path)

        else:
            painter.drawRect(QRect(
                self.l,
                self.l,
                self.r - self.l,
                self.bar_height,
            ))

        painter.restore()
Esempio n. 3
0
    def paintEvent(self, event):
        super(BubbleLabel, self).paintEvent(event)
        painter = QPainter(self)
        painter.setRenderHint(QPainter.Antialiasing)  # 抗锯齿

        rectPath = QPainterPath()  # 圆角矩形
        triPath = QPainterPath()  # 底部三角形

        height = self.height() - 8  # 往上偏移8
        rectPath.addRoundedRect(QRectF(0, 0, self.width(), height), 5, 5)
        x = self.width() / 5 * 4
        triPath.moveTo(x, height)  # 移动到底部横线4/5处
        # 画三角形
        triPath.lineTo(x + 6, height + 8)
        triPath.lineTo(x + 12, height)

        rectPath.addPath(triPath)  # 添加三角形到之前的矩形上

        # 边框画笔
        painter.setPen(QPen(self.BorderColor, 1, Qt.SolidLine,
                            Qt.RoundCap, Qt.RoundJoin))
        # 背景画刷
        painter.setBrush(self.BackgroundColor)
        # 绘制形状
        painter.drawPath(rectPath)
        # 三角形底边绘制一条线保证颜色与背景一样
        painter.setPen(QPen(self.BackgroundColor, 1,
                            Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin))
        painter.drawLine(x, height, x + 12, height)
Esempio n. 4
0
    def paintEvent(self, event):
        """
        custom paint event to draw horizontal line and handles at current y level
        """
        super().paintEvent(event)
        painter = QPainter(self)
        #painter.beginNativePainting()
        #painter.setRenderHint(QPainter.Antialiasing)
        x1,y1,x2,y2 = self.rect().getCoords()
        #painter.setPen(QPen(Qt.gray, 1))
        #painter.drawRect(self.rect())
        painter.setPen(QPen(COLOR, 1))
        painter.drawLine(QPoint(x1, y1+(y2-y1)/2), QPoint(x2, y1+(y2-y1)/2))
        path = QPainterPath()
        path.moveTo(x1, y1)
        path.lineTo(x1, y1 + y2)
        path.lineTo(10, y1 + y2/2)
        path.lineTo(x1, y1)
        painter.fillPath(path, QBrush(COLOR))
        path = QPainterPath()
        path.moveTo(x2+1, y1)
        path.lineTo(x2+1, y1 + y2)
        path.lineTo(x2 - 9, y1 + y2/2)
        path.lineTo(x2+1, y1)
        painter.fillPath(path, QBrush(COLOR))

        #painter.endNativePainting()
        painter.end()
    def drawOverlay(self, painter: QPainter) -> None:
        if not self.__showOverlay: return

        radius: int = 80
        painter.save()
        painter.setPen(Qt.NoPen)

        smallCircle: QPainterPath = QPainterPath()
        bigCircle: QPainterPath = QPainterPath()
        radius -= 1
        smallCircle.addEllipse(-radius, -radius, radius * 2, radius * 2)
        radius *= 2
        bigCircle.addEllipse(-radius, -radius + 140, radius * 2, radius * 2)

        # 高光的形状为小圆扣掉大圆的部分
        highlight: QPainterPath = smallCircle - bigCircle

        linearGradient: QLinearGradient = QLinearGradient(0, -radius / 2, 0, 0)
        self.__overlayColor.setAlpha(100)
        linearGradient.setColorAt(0.0, self.__overlayColor)
        self.__overlayColor.setAlpha(30)
        linearGradient.setColorAt(1.0, self.__overlayColor)
        painter.setBrush(linearGradient)
        painter.rotate(-20)
        painter.drawPath(highlight)

        painter.restore()
Esempio n. 6
0
def loadPresets(filename, first=1):
    """
    Loads brush preset from file
    @param filename:
    @type filename: str
    @return:
    @rtype:  list of brushFamily instances
    """
    brushes = []
    patterns = []
    baseSize = 400  # 25
    try:
        rank = first
        entry = os.path.basename(filename)
        if entry[-4:].lower() in ['.png', '.jpg']:
            try:
                qpp = QPainterPath()
                qpp.addEllipse(QRect(0, 0, baseSize, baseSize))
                presetBrushFamily = brushFamily('Preset ' + str(rank),
                                                baseSize,
                                                qpp,
                                                presetFilename=os.getcwd() +
                                                '\\' + BRUSHES_PATH + '\\' +
                                                entry)
                brushes.append(presetBrushFamily)
                rank += 1
            except IOError:
                pass
        elif entry[-4:].lower() in ['.abr']:
            sImages, pImages = aParser.readFile(os.getcwd() + '\\' +
                                                BRUSHES_PATH + '\\' + entry)
            for im in sImages:
                qpp = QPainterPath()
                qpp.addEllipse(QRect(0, 0, baseSize, baseSize))
                alpha = np.full_like(im, 255)
                im = np.dstack((im, im, im, im))  # alpha))
                qim = ndarrayToQImage(im, format=QImage.Format_ARGB32)
                presetBrushFamily = brushFamily('Preset ' + str(rank),
                                                baseSize,
                                                qpp,
                                                image=qim)
                brushes.append(presetBrushFamily)
                rank += 1
            rank = first
            for im in pImages:
                #alpha = np.full_like(im, 255)
                im = np.dstack((im, im, im, im))
                qim = ndarrayToQImage(im, format=QImage.Format_ARGB32)
                p = pattern('pattern ' + str(rank),
                            im=qim,
                            pxmp=QPixmap.fromImage(qim))
                patterns.append(p)
                rank += 1
    except IOError:
        pass
    return brushes, patterns
Esempio n. 7
0
    def path(self):
        """Compute and return QPainterPath that is used to draw the curved line.  
        Internal function use this to reset their path in response to external changes. 
        """
        if self._source_pos is None or self._target_pos is None:
            return QPainterPath()

        result = QPainterPath()
        result.moveTo(self._source_pos)
        result.cubicTo(self._bezier_point_1(), self._bezier_point_2(),
                       self._target_pos)

        return result
Esempio n. 8
0
    def paint(self,
              painter=QPainter,
              option=QStyleOptionGraphicsItem,
              widget=QWidget):
        corners = 5
        body = self.boundingRect()
        height = body.height()
        width = body.width()
        percentage = height / 10
        painter.setRenderHint(QPainter.Antialiasing)

        path = QPainterPath()
        path.addRoundedRect(body, corners, corners)
        pen = QPen(QColor(255, 255, 255, 100),
                   3) if self.hover and not self.isPressed else QPen(
                       Qt.black, 0.1)
        pen.setJoinStyle(Qt.RoundJoin)
        pen.setCosmetic(True)
        painter.setPen(pen)
        painter.fillPath(path, self._model["bgColor"])
        painter.drawPath(path)
        if not self.isPressed:
            grad = QLinearGradient(0, height, 0, height - percentage)
            grad.setColorAt(0, QColor(175, 175, 175, 255))
            grad.setColorAt(1, QColor(175, 175, 175, 0))
            path = QPainterPath()
            path.addRoundedRect(body, corners, corners)
            painter.setCompositionMode(QPainter.CompositionMode_Multiply)
            painter.setPen(Qt.NoPen)
            painter.fillPath(path, grad)
            painter.drawPath(path)

            grad = QLinearGradient(0, percentage, 0, 0)
            grad.setColorAt(1, QColor(255, 255, 255, 255))
            grad.setColorAt(0, QColor(255, 255, 255, 0))
            path = QPainterPath()
            path.addRoundedRect(body, corners, corners)
            painter.setCompositionMode(QPainter.CompositionMode_Overlay)
            painter.setPen(Qt.NoPen)
            painter.fillPath(path, grad)
            painter.drawPath(path)
            painter.setCompositionMode(QPainter.CompositionMode_Source)
        else:
            path = QPainterPath()
            path.addRoundedRect(body, corners, corners)
            painter.setCompositionMode(QPainter.CompositionMode_Overlay)
            painter.setPen(Qt.NoPen)
            painter.fillPath(path, QColor(255, 255, 255))
            painter.drawPath(path)
            painter.setCompositionMode(QPainter.CompositionMode_Source)
        super(ButtonNode, self).paint(painter, option, widget)
Esempio n. 9
0
    def draw_plus(self, painter=QPainter):
        brush = QBrush()
        # Highlighted
        painter.setPen(Qt.NoPen)
        if self._highlight:
            brush.setStyle(Qt.SolidPattern)
            brush.setColor(QColor(255, 0, 0))
        else:
            brush.setStyle(Qt.SolidPattern)
            brush.setColor(QColor(224, 224, 224))
        boundry = self.boundingRect()
        painter.setBrush(brush)
        path = QPainterPath()
        widthSec = boundry.width() / 3
        heightSec = boundry.height() / 3
        path.moveTo(widthSec, 0)
        path.lineTo(widthSec * 2, 0)
        path.lineTo(widthSec * 2, heightSec)
        path.lineTo(widthSec * 3, heightSec)
        path.lineTo(widthSec * 3, heightSec * 2)
        path.lineTo(widthSec * 2, heightSec * 2)
        path.lineTo(widthSec * 2, heightSec * 3)
        path.lineTo(widthSec, heightSec * 3)
        path.lineTo(widthSec, heightSec * 2)
        path.lineTo(0, heightSec * 2)
        path.lineTo(0, heightSec)
        path.lineTo(widthSec, heightSec)
        path.lineTo(widthSec, 0)
        painter.drawPath(path)

        # background
        brush.setColor(self._model["bgColor"])
        painter.setBrush(brush)
        offset = 4
        path = QPainterPath()
        widthSec = boundry.width() / 3
        heightSec = boundry.height() / 3
        path.moveTo(widthSec + offset, 0 + offset)
        path.lineTo((widthSec * 2) - offset, 0 + offset)
        path.lineTo((widthSec * 2) - offset, heightSec + offset)
        path.lineTo((widthSec * 3) - offset, heightSec + offset)
        path.lineTo((widthSec * 3) - offset, (heightSec * 2) - offset)
        path.lineTo((widthSec * 2) - offset, (heightSec * 2) - offset)
        path.lineTo((widthSec * 2) - offset, (heightSec * 3) - offset)
        path.lineTo(widthSec + offset, (heightSec * 3) - offset)
        path.lineTo(widthSec + offset, (heightSec * 2) - offset)
        path.lineTo(0 + offset, (heightSec * 2) - offset)
        path.lineTo(0 + offset, heightSec + offset)
        path.lineTo(widthSec + offset, heightSec + offset)
        path.lineTo(widthSec + offset, 0 + offset)
        painter.drawPath(path)
Esempio n. 10
0
    def __init__(self,
                 item,
                 duration=2000,
                 count=5,
                 percentage_size=0.24,
                 x_shift=0):
        """Initializes animation stuff.

        Args:
            item (QGraphicsItem): The item on top of which the animation should play.
        """
        self._item = item
        self.cubes = [QGraphicsTextItem("\uf1b2", item) for i in range(count)]
        self.opacity_at_value_path = QPainterPath(QPointF(0.0, 0.0))
        self.opacity_at_value_path.lineTo(QPointF(0.01, 1.0))
        self.opacity_at_value_path.lineTo(QPointF(0.5, 1.0))
        self.opacity_at_value_path.lineTo(QPointF(1.0, 0.0))
        self.time_line = QTimeLine()
        self.time_line.setLoopCount(0)  # loop forever
        self.time_line.setFrameRange(0, 10)
        self.time_line.setDuration(duration)
        self.time_line.setCurveShape(QTimeLine.LinearCurve)
        self.time_line.valueChanged.connect(
            self._handle_time_line_value_changed)
        self.time_line.stateChanged.connect(
            self._handle_time_line_state_changed)
        font = QFont('Font Awesome 5 Free Solid')
        item_rect = item.rect()
        cube_size = percentage_size * 0.875 * item_rect.height()
        font.setPixelSize(cube_size)
        rect = item_rect.translated(-0.5 * cube_size + x_shift, -cube_size)
        end = rect.center()
        ctrl = end - QPointF(0, 0.6 * rect.height())
        lower, upper = 0.2, 0.8
        starts = [lower + i * (upper - lower) / count for i in range(count)]
        starts = [
            rect.topLeft() + QPointF(start * rect.width(), 0)
            for start in starts
        ]
        self.paths = [QPainterPath(start) for start in starts]
        for path in self.paths:
            path.quadTo(ctrl, end)
        self.offsets = [i / count for i in range(count)]
        for cube in self.cubes:
            cube.setFont(font)
            cube.setDefaultTextColor("#003333")
            cube.setTransformOriginPoint(cube.boundingRect().center())
            cube.hide()
            cube.setOpacity(0)
Esempio n. 11
0
 def _get_dst_offset(self, c1):
     if not self.dst_connector:
         guide_path = QPainterPath(self.src_center)
         guide_path.quadTo(c1, self.dst_center)
         line = self._get_joint_line(guide_path).unitVector()
         return QPointF(-line.dx(), -line.dy())
     return {"left": QPointF(-1, 0), "bottom": QPointF(0, 1), "right": QPointF(1, 0)}[self.dst_connector.position]
Esempio n. 12
0
 def group_object_pixmap(self, object_class_name):
     if object_class_name in self.group_obj_pixmap_cache:
         return self.group_obj_pixmap_cache[object_class_name]
     object_pixmap = self.object_pixmap(object_class_name)
     size = object_pixmap.size()
     width, height = size.width(), size.height()
     radius = width / 8
     pen_width = width / 32
     margin = width / 16
     pen = QPen(QApplication.palette().shadow().color())
     pen.setWidth(pen_width)
     path = QPainterPath()
     path.addRoundedRect(0, 0, width, height, radius, radius)
     pixmap = QPixmap(size)
     pixmap.fill(Qt.transparent)
     painter = QPainter(pixmap)
     painter.setRenderHint(QPainter.Antialiasing, True)
     painter.fillPath(path, QApplication.palette().window())
     painter.setPen(pen)
     painter.drawRoundedRect(pixmap.rect().adjusted(pen_width, pen_width, -pen_width, -pen_width), radius, radius)
     painter.drawPixmap(
         pixmap.rect().adjusted(margin, margin, -width / 2, -height / 2), object_pixmap, object_pixmap.rect()
     )
     painter.drawPixmap(
         pixmap.rect().adjusted(width / 2, margin, -margin, -height / 2), object_pixmap, object_pixmap.rect()
     )
     painter.drawPixmap(
         pixmap.rect().adjusted(width / 2, height / 2, -margin, -margin), object_pixmap, object_pixmap.rect()
     )
     painter.drawPixmap(
         pixmap.rect().adjusted(margin, height / 2, -width / 2, -margin), object_pixmap, object_pixmap.rect()
     )
     painter.end()
     self.group_obj_pixmap_cache[object_class_name] = pixmap
     return pixmap
Esempio n. 13
0
    def paint(self, painter, *args):
        super().paint(painter, *args)

        kind = self.desc.kind
        painter.setPen(QPen(Qt.black, 2))
        path = QPainterPath()
        r = self.rect()

        if kind == 'and':
            path.moveTo(r.topLeft())
            path.lineTo(r.center().x(), r.top())
            path.quadTo(r.topRight(), QPoint(r.right(), r.height() / 2))
            path.quadTo(r.bottomRight(), QPoint(r.width() / 2, r.bottom()))
            path.lineTo(r.bottomLeft())
            path.closeSubpath()
        elif kind == 'or':
            path.moveTo(r.topLeft())
            path.lineTo(r.width() / 4, r.top())
            path.quadTo(QPoint(r.width() / 4 * 3, r.top()),
                        QPoint(r.right(),
                               r.height() / 2))
            path.quadTo(QPoint(r.width() / 4 * 3, r.bottom()),
                        QPoint(r.width() / 4, r.bottom()))
            path.lineTo(r.bottomLeft())
            path.quadTo(r.center(), r.topLeft())

        painter.drawPath(path)
Esempio n. 14
0
    def paintEvent(self, event: QPaintEvent):
        super().paintEvent(event)

        if self._viewport_anchoring_scheduled:
            self._anchor_viewport()
            self._viewport_anchoring_scheduled = False

        painter = QPainter(self.viewport())
        painter.setRenderHint(QPainter.Antialiasing)
        painter.setBrush(QColor(123, 184, 234))
        painter.setPen(QPen(Qt.white, 0.5))

        scale_text = f'{self._cur_scale * 100:.0f}%'
        scale_text_bounding_rect = self._scale_font_metrics.boundingRect(
            scale_text)
        viewport_rect = self.viewport().rect()
        # Align the scale text to (Qt.AlignHCenter | Qt.AlignBottom)
        pad = 2
        self._scale_text_rect = QRect(viewport_rect.width() / 2 - scale_text_bounding_rect.width() / 2,
                                      viewport_rect.height() - scale_text_bounding_rect.height() - 6,
                                      scale_text_bounding_rect.width(), scale_text_bounding_rect.height())\
            .adjusted(-pad, -pad, pad, pad)  # add pads to update when scrolling without artifacts

        # Use QPainterPath to draw text with outline
        path = QPainterPath()
        path.addText(self._scale_text_rect.bottomLeft(), self._scale_font,
                     scale_text)
        painter.drawPath(path)
Esempio n. 15
0
    def paintEvent(self, *args):
        painter = QPainter(self)
        painter.setRenderHint(QPainter.Antialiasing)

        painter.setBrush(Qt.black)
        painter.setPen(QPen(Qt.transparent))
        for block in self.blocks:
            painter.drawRect(block)

        if self.debug:
            lines = list()
            points = list()
            for p1 in self.graph:
                for p2 in self.graph[p1]:
                    lines.append(QLine(*p1, *p2))
                    points.append(QPoint(*p1))
                    points.append(QPoint(*p2))

            painter.setPen(QPen(Qt.black))
            painter.drawLines(lines)
            painter.setPen(QPen(Qt.red, 3))
            painter.drawPoints(points)

        if self.path:
            painter.setPen(QPen(Qt.green))
            painter.setBrush(Qt.transparent)
            p = QPainterPath()
            p.moveTo(*self.path[0])
            for point in self.path:
                p.lineTo(*point)
            painter.drawPath(p)
Esempio n. 16
0
    def draw_NI_minimalistic(painter, c, w, h, bounding_rect):
        """
        :param painter: painter from paint event
        :param c: color
        :param w: width
        :param h: height
        :param bounding_rect: NodeInstance's bounding rect
        """

        path = QPainterPath()
        path.moveTo(-w / 2, 0)

        path.cubicTo(-w / 2, -h / 2, -w / 2, -h / 2, 0, -h / 2)
        path.cubicTo(+w / 2, -h / 2, +w / 2, -h / 2, +w / 2, 0)
        path.cubicTo(+w / 2, +h / 2, +w / 2, +h / 2, 0, +h / 2)
        path.cubicTo(-w / 2, +h / 2, -w / 2, +h / 2, -w / 2, 0)
        path.closeSubpath()

        body_gradient = QLinearGradient(bounding_rect.bottomLeft(),
                                        bounding_rect.topRight())
        body_gradient.setColorAt(0, QColor(c.red(), c.green(), c.blue(), 150))
        body_gradient.setColorAt(1, QColor(c.red(), c.green(), c.blue(), 80))

        painter.setBrush(body_gradient)
        painter.setPen(QPen(QColor(30, 43, 48)))

        painter.drawPath(path)
Esempio n. 17
0
    def __init__(self):
        super(Edge, self).__init__()
        self.setZValue(-1)  # Draw edges behind nodes
        self.setFlag(self.ItemIsSelectable)

        self._source: Union[Output, None] = None
        """An edge is drawn from its source to its target. Node's output is edge's source.  
        This variable represents current source as a variable of type Output.
        """
        self._target: Union[Input, None] = None
        """An edge is drawn from its source to its target. Node's input is edge's target.  
        This variable represents current target as a variable of type Input.
        """

        self._source_pos: Union[QPointF, None] = None
        """An edge is drawn from its source to its target. Node's output is edge's source.  
        This variable represents current source coordinates in scene pixels.
        """
        self._target_pos: Union[QPointF, None] = None
        """An edge is drawn from its source to its target. Node's input is edge's target.  
        This variable represents current target coordinates in scene pixels.
        """

        self._path = QPainterPath()
        self._pen = QPen()

        self.styleChange()
        self.paletteChange()
Esempio n. 18
0
    def paint_border_background(self, painter):
        """paint_border_background(self, painter:PySide2.QtGui.QPainter)"""
        painter.save()
        pen = QPen()
        pen.setColor(self.border_color())
        pen.setWidth(self.border_width())
        painter.setPen(pen)
        brush = QBrush(self.background_color())
        painter.setBrush(brush)
        painter.setOpacity(self.opacity())
        # painter.setRenderHint(QPainter.Antialiasing)
        rc = self.rect()
        paint_path = QPainterPath()
        # adjust shadow
        if self._shadow is not None:
            rc.adjust(self.shadow_blur(), self.shadow_blur(),
                      -self.shadow_blur(), -self.shadow_blur())

        # self._calc_background_path(rc, paint_path)
        if self._calc_background_path(rc, paint_path):
            painter.setRenderHint(QPainter.Antialiasing)

        if self.border_width() > 0:
            painter.drawPath(paint_path)
        else:
            painter.fillPath(paint_path, brush)

        painter.restore()
Esempio n. 19
0
 def updatePath(self):
     axeSize = self.size
     yZero = self.yZero
     try:
         X = []
         for item in self.fixedPoints:
             X.extend([item.B.x() + item.x(), item.C.x() + item.x()])
         X = np.array(X)
         Y = np.array(
             [-(item.A.y() + item.y())
              for item in self.fixedPoints]) + yZero
         T = displacementSpline(X,
                                Y,
                                self.xCoords,
                                clippingInterval=[-self.scene().axeSize, 0],
                                period=self.period)
         self.spline = [
             QPointF(x, y + yZero) for x, y in zip(self.xCoords, -T)
         ]  # scene coord.
         # build path
         polygon = QPolygonF(self.spline)
         qpp = QPainterPath()
         qpp.addPolygon(polygon)
         # stroke path
         stroker = QPainterPathStroker()
         stroker.setWidth(self.strokeWidth)
         mboundingPath = stroker.createStroke(qpp)
         self.setPath(mboundingPath)
     except ValueError:
         pass
Esempio n. 20
0
 def __init__(self,
              x,
              y,
              color=Qt.white,
              fillColor=None,
              persistent=False,
              rect=None,
              parentItem=None):
     super().__init__(parent=parentItem)
     self.color = color
     self.setAcceptHoverEvents(True)
     self.persistent = persistent
     self.rect = rect
     if self.rect is not None:
         self.xmin, self.xmax, self.ymin, self.ymax = rect.left(
         ), rect.right(), rect.top(), rect.bottom()
         x = min(max(x, self.xmin), self.xmax)
         y = min(max(y, self.ymin), self.ymax)
     self.setPos(QPointF(x, y))
     self.clicked = False
     self.setPen(QPen(color, 2))
     # filling brush
     if fillColor is not None:
         self.setBrush(QBrush(fillColor))
     qpp = QPainterPath()
     # coordinates are relative to activePoint
     qpp.addEllipse(-4, -4, 8, 8)
     self.setPath(qpp)
Esempio n. 21
0
 def updatePath(self):
     qpp = QPainterPath()
     # coordinates are relative to activeTangent object
     qpp.moveTo(0, 0)
     qpp.lineTo((self.controlPoint - self.contactPoint))
     qpp.addEllipse(self.controlPoint - self.contactPoint, 5.0, 5.0)
     self.setPath(qpp)
Esempio n. 22
0
 def paint(self, painter, *args, **kwargs):
     margin = QMarginsF(3, 0, 3, 0)
     box = self.boundingRect().marginsAdded(margin)
     path = QPainterPath()
     path.addRoundedRect(box, 5, 5)
     painter.fillPath(path, QColor(*self.background_color))
     super().paint(painter, *args, **kwargs)
Esempio n. 23
0
 def shape(self):
     path = QPainterPath()
     path.setFillRule(Qt.WindingFill)
     path.addRect(self.rect())
     for handle in self.handles:
         path.addRect(handle.boundingRect())
     return path
Esempio n. 24
0
    def _make_connecting_path(self, guide_path):
        """Returns a 'thick' path connecting source and destination, by following the given 'guide' path.

        Args:
            guide_path (QPainterPath)

        Returns:
            QPainterPath
        """
        points, angles = self._points_and_angles_from_path(guide_path)
        outgoing_points = []
        incoming_points = []
        for point, angle in zip(points, angles):
            off = self._radius_from_point_and_angle(point, angle)
            outgoing_points.append(point + off)
            incoming_points.insert(0, point - off)
        p0 = guide_path.pointAtPercent(0)
        a0 = guide_path.angleAtPercent(0)
        off0 = self._radius_from_point_and_angle(p0, a0)
        curve_path = QPainterPath(p0 + off0)
        self._follow_points(curve_path, outgoing_points)
        curve_path.lineTo(incoming_points[0])
        self._follow_points(curve_path, incoming_points)
        curve_path.lineTo(p0 - off0)
        curve_path.closeSubpath()
        curve_path.setFillRule(Qt.WindingFill)
        return curve_path.simplified()
Esempio n. 25
0
    def connection_path(p1: QPointF, p2: QPointF):
        """Returns the nice looking QPainterPath of a connection for two given points."""

        path = QPainterPath()

        path.moveTo(p1)

        distance_x = abs(p1.x()) - abs(p2.x())
        distance_y = abs(p1.y()) - abs(p2.y())

        if ((p1.x() < p2.x() - 30)
                or math.sqrt((distance_x**2) +
                             (distance_y**2)) < 100) and (p1.x() < p2.x()):
            path.cubicTo(p1.x() + ((p2.x() - p1.x()) / 2), p1.y(),
                         p1.x() + ((p2.x() - p1.x()) / 2), p2.y(), p2.x(),
                         p2.y())
        elif p2.x() < p1.x() - 100 and abs(distance_x) / 2 > abs(distance_y):
            path.cubicTo(p1.x() + 100 + (p1.x() - p2.x()) / 10, p1.y(),
                         p1.x() + 100 + (p1.x() - p2.x()) / 10,
                         p1.y() - (distance_y / 2),
                         p1.x() - (distance_x / 2),
                         p1.y() - (distance_y / 2))
            path.cubicTo(p2.x() - 100 - (p1.x() - p2.x()) / 10,
                         p2.y() + (distance_y / 2),
                         p2.x() - 100 - (p1.x() - p2.x()) / 10, p2.y(), p2.x(),
                         p2.y())
        else:
            path.cubicTo(p1.x() + 100 + (p1.x() - p2.x()) / 3, p1.y(),
                         p2.x() - 100 - (p1.x() - p2.x()) / 3, p2.y(), p2.x(),
                         p2.y())
        return path
Esempio n. 26
0
    def _create_block_item(self):
        """
        Create the block background and border.
        """

        self._block_item = QPainterPath()
        self._block_item.addRect(0, 0, self.width, self.height)
Esempio n. 27
0
 def drawPlotGrid(cls, axeSize, gradient=None):
     """
     Rerturns a QGraphicsPathItem initialized with
     a square grid.
     @param axeSize:
     @type axeSize:
     @param gradient:
     @type gradient
     @return:
     @rtype: QGraphicsPathItem
     """
     lineWidth = 1
     item = QGraphicsPathItem()
     if gradient is None:
         item.setPen(QPen(Qt.darkGray, lineWidth, Qt.DashLine))
     else:
         item.setPen(QPen(gradient, lineWidth, Qt.DashLine))
     qppath = QPainterPath()
     qppath.moveTo(QPoint(0, 0))
     qppath.lineTo(QPoint(axeSize, 0))
     qppath.lineTo(QPoint(axeSize, -axeSize))
     qppath.lineTo(QPoint(0, -axeSize))
     qppath.closeSubpath()
     qppath.lineTo(QPoint(axeSize, -axeSize))
     # draw grid
     for i in range(1, 5):
         a = (axeSize * i) / 4
         qppath.moveTo(a, -axeSize)
         qppath.lineTo(a, 0)
         qppath.moveTo(0, -a)
         qppath.lineTo(axeSize, -a)
     item.setPath(qppath)
     return item
Esempio n. 28
0
    def draw_dark_minimalistic(self, painter):
        path = QPainterPath()
        path.moveTo(-self.width / 2, 0)

        path.cubicTo(-self.width / 2, -self.height / 2,
                     -self.width / 2, -self.height / 2,
                     0, -self.height / 2)
        path.cubicTo(+self.width / 2, -self.height / 2,
                     +self.width / 2, -self.height / 2,
                     +self.width / 2, 0)
        path.cubicTo(+self.width / 2, +self.height / 2,
                     +self.width / 2, +self.height / 2,
                     0, +self.height / 2)
        path.cubicTo(-self.width / 2, +self.height / 2,
                     -self.width / 2, +self.height / 2,
                     -self.width / 2, 0)
        path.closeSubpath()

        c = self.parent_node.color
        body_gradient = QLinearGradient(self.boundingRect().bottomLeft(),
                                        self.boundingRect().topRight())
        body_gradient.setColorAt(0, QColor(c.red(), c.green(), c.blue(), 150))
        body_gradient.setColorAt(1, QColor(c.red(), c.green(), c.blue(), 80))

        painter.setBrush(body_gradient)
        painter.setPen(QPen(QColor(30, 43, 48)))

        painter.drawPath(path)
Esempio n. 29
0
    def draw_NI_minimalistic(painter,
                             c,
                             w,
                             h,
                             background_color=QColor('#36383B')):
        """
        :param painter: painter from paint event
        :param c_s: corner size/corner radius
        :param c: color
        :param w: width
        :param h: height
        :param background_color: (default) background color
        """

        c_s = 10

        path = QPainterPath()
        path.moveTo(-w / 2, 0)

        path.lineTo(-w / 2 + c_s / 2, -h / 2 + c_s / 2)
        path.lineTo(0, -h / 2)
        path.lineTo(+w / 2 - c_s / 2, -h / 2 + c_s / 2)
        path.lineTo(+w / 2, 0)
        path.lineTo(+w / 2 - c_s / 2, +h / 2 - c_s / 2)
        path.lineTo(0, +h / 2)
        path.lineTo(-w / 2 + c_s / 2, +h / 2 - c_s / 2)
        path.closeSubpath()

        painter.setBrush(background_color)
        pen = QPen(c)
        pen.setWidth(2)
        painter.setPen(pen)

        painter.drawPath(path)
Esempio n. 30
0
    def drawValue(self, p, baseRect, value, arcLength):
        # nothing to draw
        if value == self.min:
            return

        # for Line style
        if self.barStyle == self.StyleLine:
            p.setPen(
                QPen(self.palette().highlight().color(), self.dataPenWidth))
            p.setBrush(Qt.NoBrush)
            p.drawArc(
                baseRect.adjusted(self.outlinePenWidth / 2,
                                  self.outlinePenWidth / 2,
                                  -self.outlinePenWidth / 2,
                                  -self.outlinePenWidth / 2),
                self.nullPosition * 16, -arcLength * 16)
            return

        # for Pie and Donut styles
        dataPath = QPainterPath()
        dataPath.setFillRule(Qt.WindingFill)

        # pie segment outer
        dataPath.moveTo(baseRect.center())
        dataPath.arcTo(baseRect, self.nullPosition, -arcLength)
        dataPath.lineTo(baseRect.center())

        p.setBrush(self.palette().highlight())
        p.setBrush(QColor(255, 255, 255, 255 * 0.3))

        # pen = QtGui.QPen(self.palette().shadow().color(), self.dataPenWidth)
        pen = QPen(self.palette().shadow().color(), -1)
        p.setPen(pen)
        p.drawPath(dataPath)