Exemple #1
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]
Exemple #2
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)
Exemple #3
0
    def _make_path(self):
        if len(self.coords) < 3:
            return super()._make_path()
            # raise ValueError("At least 3 coordinates are required.")  # programming error - don't use this class for a simple segment!

        path = QPainterPath(self.coords[0])

        for i in range(len(self.coords) - 1):
            pt0 = self._get_line_start(i)
            if i == 0:
                path.lineTo(pt0)
            else:
                path.quadTo(self.coords[i], pt0)
            pt1 = self._get_line_end(i)
            path.lineTo(pt1)

        path.lineTo(self.coords[-1])

        return path
Exemple #4
0
 def update_line(self):
     overlapping_arcs = [
         arc for arc in self.rel_item.arc_items
         if arc.obj_item == self.obj_item
     ]
     count = len(overlapping_arcs)
     path = QPainterPath(self.rel_item.pos())
     if count == 1:
         path.lineTo(self.obj_item.pos())
     else:
         rank = overlapping_arcs.index(self)
         line = QLineF(self.rel_item.pos(), self.obj_item.pos())
         line.setP1(line.center())
         line = line.normalVector()
         line.setLength(self._width * count)
         line.setP1(2 * line.p1() - line.p2())
         t = rank / (count - 1)
         ctrl_point = line.pointAt(t)
         path.quadTo(ctrl_point, self.obj_item.pos())
     self.setPath(path)
    def test_bezier_resolution_after_transform(self, p, opd):
        # Two beziers which are the same size after transformation should be
        # interpolated to the same level of detail
        path = QPainterPath()
        path.moveTo(0, 0)
        path.quadTo(100, 10, 10, 20)
        p.drawPath(path)

        p.scale(10, 10)
        path = QPainterPath()
        path.moveTo(0, 0)
        path.quadTo(10, 1, 1, 2)
        p.drawPath(path)

        lines = opd.getOutlines()
        assert len(lines) == 2
        colour_0, width_0, line_0 = lines[0]
        colour_1, width_1, line_1 = lines[1]

        assert len(line_0) > 2
        assert len(line_0) == len(line_1)
    def test_bezier_resolution(self, p, opd):
        # Two beziers drawn at different sizes should be interpolated to
        # different levels of detail
        path = QPainterPath()
        path.moveTo(0, 0)
        path.quadTo(100, 10, 10, 20)
        p.drawPath(path)

        path = QPainterPath()
        path.moveTo(0, 0)
        path.quadTo(10, 1, 1, 2)
        p.drawPath(path)

        lines = opd.getOutlines()
        assert len(lines) == 2
        colour_0, width_0, line_0 = lines[0]
        colour_1, width_1, line_1 = lines[1]

        assert len(line_0) > 2
        assert len(line_1) > 2
        assert len(line_0) > len(line_1)