Exemple #1
0
    def _get_brush(self, properties: Properties) -> qg.QBrush:
        filling = properties.filling
        if filling:
            if filling.type == filling.PATTERN:
                if (
                    self.config.hatch_policy
                    == HatchPolicy.SHOW_APPROXIMATE_PATTERN
                ):
                    # Default pattern scaling is not supported by PyQt:
                    key: PatternKey = (filling.name, filling.angle)
                    qt_pattern = self._pattern_cache.get(key)  # type: ignore
                    if qt_pattern is None:
                        qt_pattern = self._get_qt_pattern(filling.pattern)
                        self._pattern_cache[key] = qt_pattern
                elif self.config.hatch_policy == HatchPolicy.SHOW_SOLID:
                    qt_pattern = qc.Qt.SolidPattern  # type: ignore
                elif self.config.hatch_policy == HatchPolicy.SHOW_OUTLINE:
                    return self._no_fill
                else:
                    raise ValueError(self.config.hatch_policy)
            else:
                qt_pattern = qc.Qt.SolidPattern  # type: ignore

            return qg.QBrush(self._get_color(properties.color), qt_pattern)  # type: ignore
        else:
            return self._no_fill
Exemple #2
0
    def __init__(
        self,
        scene: Optional[qw.QGraphicsScene] = None,
        *,
        use_text_cache: bool = True,
        debug_draw_rect: bool = False,
        extra_lineweight_scaling: float = 2.0,
    ):
        """
        Args:
            extra_lineweight_scaling: compared to other backends,
                PyQt draws lines which appear thinner
        """
        super().__init__()
        self._scene = scene or qw.QGraphicsScene()  # avoids many type errors
        self._color_cache: Dict[Color, qg.QColor] = {}
        self._pattern_cache: Dict[PatternKey, int] = {}
        self._no_line = qg.QPen(qc.Qt.NoPen)
        self._no_fill = qg.QBrush(qc.Qt.NoBrush)

        self._text_renderer = TextRenderer(qg.QFont(), use_text_cache)
        self._line_renderer: PyQtLineRenderer
        self._extra_lineweight_scaling = extra_lineweight_scaling
        self._debug_draw_rect = debug_draw_rect
Exemple #3
0
 def draw_point(self, pos: Vec3, properties: Properties) -> None:
     """Draw a real dimensionless point."""
     brush = qg.QBrush(self._get_color(properties.color), qc.Qt.SolidPattern)
     item = _Point(pos.x, pos.y, brush)
     self._set_item_data(item)
     self._scene.addItem(item)
Exemple #4
0
 def set_background(self, color: Color):
     self._scene.setBackgroundBrush(qg.QBrush(self._get_color(color)))