def paintEvent(self, event): painter = gui.Painter(self) painter.use_antialiasing() painter.set_pen("none") painter.set_transparent_background(False) painter.set_transparent_background(True) painter.set_brush(gui.Brush()) with painter.paint_on(widgets.Widget()): pass painter.set_brush(gui.Color("red")) painter.fill_rect((0, 1, 3, 5), "transparent") painter.fill_rect(core.Rect(), "transparent") with pytest.raises(InvalidParamError): painter.fill_rect(core.Rect(), "transparent", "test") with pytest.raises(ValueError): painter.fill_rect(core.Rect(), "testus") painter.set_color("black") painter.set_composition_mode("source_atop") painter.get_composition_mode() == "source_atop" with pytest.raises(InvalidParamError): painter.set_composition_mode("test") painter.set_clip_path(gui.PainterPath(), "replace") with pytest.raises(InvalidParamError): painter.set_clip_path(gui.PainterPath(), "test") with pytest.raises(InvalidParamError): painter.set_pen(style="test") with painter.backup_state(): pass assert painter.get_text_rect("test") is not None
def clip_path( self, operation: constants.ClipOperationStr = "replace" ) -> Iterator[gui.PainterPath]: path = gui.PainterPath() yield path self.set_clip_path(path, operation)
def test_painterpath(): path = gui.PainterPath() rect = core.RectF(0, 0, 1, 1) path.addRect(rect) assert len(path) == 5 assert bool(path) assert core.PointF(0.5, 0.5) in path path[1] = (0.5, 0.5) path.add_rect(QtCore.QRect(0, 0, 1, 1))
def _draw_value(self, painter: gui.Painter, rect: core.RectF, value: float): if value == self._min_value: return diff = self.current_value - self._min_value value_range = self._max_value - self._min_value delta = max(value_range / diff, 0) if self.bar_style == "expand": painter.setBrush(self.palette().highlight()) color = self.palette().shadow().color() painter.set_pen(color=color, width=self.data_pen_width) radius = (rect.height() / 2) / delta painter.drawEllipse(rect.center(), radius, radius) elif self.bar_style == "line": color = self.palette().highlight().color() painter.set_pen(color=color, width=self.data_pen_width) painter.setBrush(QtCore.Qt.BrushStyle.NoBrush) pen_width = self.outline_pen_width / 2 adjusted = rect.adjusted(pen_width, pen_width, -pen_width, -pen_width) if value == self._max_value: painter.drawEllipse(adjusted) else: arc_length = 360 / delta painter.drawArc(adjusted, int(self.null_pos * 16), int(-arc_length * 16)) elif self.bar_style in ["donut", "pie"]: data_path = gui.PainterPath() data_path.set_fill_rule("winding") if value == self._max_value: data_path.addEllipse(rect) else: arc_length = 360 / delta center_point = rect.center() data_path.moveTo(center_point) data_path.arcTo(rect, self.null_pos, -arc_length) data_path.lineTo(center_point) painter.setBrush(self.palette().highlight()) shadow_color = self.palette().shadow().color() painter.set_pen(color=shadow_color, width=self.data_pen_width) painter.drawPath(data_path)
def create_stroke(self, path: QtGui.QPainterPath) -> gui.PainterPath: return gui.PainterPath(self.createStroke(path))
def get_shape(self) -> gui.PainterPath: return gui.PainterPath(self.shape())
def paintEvent(self, event): # Draw time scale = self.get_scale() with gui.Painter(self) as qp: qp.set_color(self.text_color) qp.setFont(self.text_font) qp.use_antialiasing() w = 0 while (w := w + 100) <= self.width(): time_string = helpers.format_seconds(w * scale) rect = core.Rect(w - 50, 0, 100, 100) qp.drawText(rect, constants.ALIGN_H_CENTER, time_string) # Draw down line qp.set_pen(color=PEN_COLOR, width=5) qp.drawLine(0, 40, self.width(), 40) # Draw dash lines point = 0 qp.set_pen(color=self.text_color) qp.drawLine(0, 40, self.width(), 40) while point <= self.width(): y2 = 30 if point % 30 != 0 else 20 qp.drawLine(3 * point, 40, 3 * point, y2) point += 10 if self._position is not None and self._is_in: qp.drawLine(self._position.x(), 0, self._position.x(), 40) poly = gui.Polygon() if self._position is not None: val = self.pointer_time_pos / self.get_scale() line = core.Line(val, 40, val, self.height()) poly.add_points((val - 10, 20), (val + 10, 20), (val, 40)) else: line = core.Line(0, 0, 0, self.height()) poly.add_points((-10, 20), (10, 20), (0, 40)) # Draw samples t = 0.0 for sample in self.video_samples: scaled_dur = sample.duration / scale scaled_t = t / scale t += sample.duration # Clear clip path with qp.clip_path() as path: rect = core.RectF(scaled_t, 50, scaled_dur, 200) path.addRoundedRect(rect, 10, 10) # Draw sample path = gui.PainterPath() qp.set_pen(color=sample.color) rect = core.RectF(scaled_t, 50, scaled_dur, 50) path.addRoundedRect(rect, 10, 10) sample.start_pos = scaled_t sample.end_pos = scaled_t + scaled_dur qp.fillPath(path, sample.color) qp.drawPath(path) # Draw preview pictures if sample.picture is None: continue pic_width = sample.picture.size().width() if pic_width < scaled_dur: width = float(pic_width) pic = sample.picture else: width = scaled_dur pic = sample.picture.copy(0, 0, int(scaled_dur), 45) with qp.clip_path() as path: rect = core.RectF(scaled_t, 52.5, width, 45) path.addRoundedRect(rect, 10, 10) qp.drawPixmap(int(scaled_t), int(52.5), int(width), 45, pic) # Clear clip path with qp.clip_path() as path: path.add_rect(self.rect()) # Draw pointer qp.set_color(PEN_COLOR) qp.set_brush(PEN_COLOR) qp.drawPolygon(poly) qp.drawLine(line)