Exemple #1
0
    def shape(self):
        if self._stock_polygon == NodePolygon.Circle:
            path = super().shape()
        else:
            path = QPainterPath()
            path.addPolygon(self._node_polygon)

        label_path = QPainterPath()
        label_path.addRect(self._label_rect)
        return path.united(label_path)
Exemple #2
0
    def calculate_draw_path(self):
        path = QPainterPath()
        path.addRect(int(self.x), int(self.y), int(self.w), int(self.h))

        # second part only considered if different from first
        if self.has2:
            path2 = QPainterPath()
            path2.addRect(int(self.x2), int(self.y2), int(self.w2), int(self.h2))
            path = path.united(path2)

        return path
    def _create_key_path(steno_layout: StenoLayout, key: StenoKey) -> QPainterPath:
        ''' Creates the path for a key '''

        key_width = steno_layout.key_width
        key_height = steno_layout.key_height

        pos_x = key.x * key_width
        pos_y = key.y * key_height
        width = key_width * key.width
        height = key_height * key.height
        is_round_top = key.is_round_top
        is_round_bottom = key.is_round_bottom

        # Figure out adjustments needed to add rounded parts
        ellipse_height = min((width, height / 2))

        pos_y = pos_y + ellipse_height / 2 if is_round_top else pos_y
        if is_round_top and is_round_bottom:
            height = height - ellipse_height
        elif is_round_top or is_round_bottom:
            height = height - ellipse_height / 2

        # Construct the main key shape
        key_path = QPainterPath()
        key_path.addRect(pos_x, pos_y, width, height)

        # Add on the rounded parts
        if is_round_top:
            key_top = QPainterPath()

            key_top.addEllipse(pos_x, pos_y - ellipse_height / 2,
                               width, ellipse_height)
            key_path = key_path.united(key_top)
        if is_round_bottom:
            key_bottom = QPainterPath()

            key_bottom.addEllipse(pos_x, pos_y + height - ellipse_height / 2,
                                  width, ellipse_height)
            key_path = key_path.united(key_bottom)

        return key_path
    def calculate_draw_path(self):
        path = QPainterPath()
        corner = int(self.h / KEY_ROUNDNESS) if (self.w > self.h) else int(
            self.w / KEY_ROUNDNESS)
        path.addRoundedRect(int(self.x), int(self.y), int(self.w), int(self.h),
                            corner, corner)

        # second part only considered if different from first
        if self.has2:
            path2 = QPainterPath()
            path2.addRoundedRect(int(self.x2), int(self.y2), int(self.w2),
                                 int(self.h2), corner, corner)
            path = path.united(path2)

        return path
Exemple #5
0
def arrow_path_concave(line, width):
    """
    Return a :class:`QPainterPath` of a pretty looking arrow.
    """
    path = QPainterPath()
    p1, p2 = line.p1(), line.p2()

    if p1 == p2:
        return path

    baseline = QLineF(line)
    # Require some minimum length.
    baseline.setLength(max(line.length() - width * 3, width * 3))

    start, end = baseline.p1(), baseline.p2()
    mid = (start + end) / 2.0
    normal = QLineF.fromPolar(1.0, baseline.angle() + 90).p2()

    path.moveTo(start)
    path.lineTo(start + (normal * width / 4.0))

    path.quadTo(mid + (normal * width / 4.0), end + (normal * width / 1.5))

    path.lineTo(end - (normal * width / 1.5))
    path.quadTo(mid - (normal * width / 4.0), start - (normal * width / 4.0))
    path.closeSubpath()

    arrow_head_len = width * 4
    arrow_head_angle = 50
    line_angle = line.angle() - 180

    angle_1 = line_angle - arrow_head_angle / 2.0
    angle_2 = line_angle + arrow_head_angle / 2.0

    points = [
        p2, p2 + QLineF.fromPolar(arrow_head_len, angle_1).p2(),
        baseline.p2(), p2 + QLineF.fromPolar(arrow_head_len, angle_2).p2(), p2
    ]

    poly = QPolygonF(points)
    path_head = QPainterPath()
    path_head.addPolygon(poly)
    path = path.united(path_head)
    return path
Exemple #6
0
def arrow_path_plain(line, width):
    """
    Return an :class:`QPainterPath` of a plain looking arrow.
    """
    path = QPainterPath()
    p1, p2 = line.p1(), line.p2()

    if p1 == p2:
        return path

    baseline = QLineF(line)
    # Require some minimum length.
    baseline.setLength(max(line.length() - width * 3, width * 3))
    path.moveTo(baseline.p1())
    path.lineTo(baseline.p2())

    stroker = QPainterPathStroker()
    stroker.setWidth(width)
    path = stroker.createStroke(path)

    arrow_head_len = width * 4
    arrow_head_angle = 50
    line_angle = line.angle() - 180

    angle_1 = line_angle - arrow_head_angle / 2.0
    angle_2 = line_angle + arrow_head_angle / 2.0

    points = [
        p2, p2 + QLineF.fromPolar(arrow_head_len, angle_1).p2(),
        p2 + QLineF.fromPolar(arrow_head_len, angle_2).p2(), p2
    ]

    poly = QPolygonF(points)
    path_head = QPainterPath()
    path_head.addPolygon(poly)
    path = path.united(path_head)
    return path