Пример #1
0
 def testus(self):
     self.setup(self.getTargetRect().size())
     painter = gui.Painter(self)
     try:
         dct = dict(antialias=True,
                    background=self.background,
                    painter=painter)
         self.setExportMode(True, dct)
         painter.use_antialiasing()
         self.getScene().render(painter, core.RectF(self.getTargetRect()),
                                core.RectF(self.getSourceRect()))
     finally:
         self.setExportMode(False)
     painter.end()
Пример #2
0
    def paintEvent(self, event):
        painter = gui.Painter(self)
        painter.fill_rect(self.rect(), "transparent")
        painter.use_antialiasing()

        if self._current_counter >= self._line_num:
            self._current_counter = 0

        painter.set_pen(style="none")
        painter.translate(self._inner_radius + self._line_length,
                          self._inner_radius + self._line_length)
        rect = core.RectF(0, -self._line_width / 2, self._line_length,
                          self._line_width)
        for i in range(self._line_num):
            with painter.backup_state():
                rotate_angle = 360 * i / self._line_num
                painter.rotate(rotate_angle)
                painter.translate(self._inner_radius, 0)
                distance = self.linecount_distance_from_primary(
                    i, self._current_counter, self._line_num)
                color = self._current_line_color(
                    distance,
                    self._line_num,
                    self._trail_fade_percentage,
                    self._minimum_trail_opacity,
                    self._color,
                )
                painter.setBrush(color)
                painter.drawRoundedRect(
                    rect,
                    self._roundness,
                    self._roundness,
                    QtCore.Qt.SizeMode.RelativeSize,
                )
Пример #3
0
    def _draw_span(self, painter: widgets.StylePainter, rect: core.Rect):
        opt = widgets.StyleOptionSlider()
        self.initStyleOption(opt)
        painter.set_pen(color=self.gradient_left, width=0)
        groove = self.style().subControlRect(SLIDER_STYLE, opt, GROOVE_STYLE,
                                             self)
        if opt.is_horizontal():
            groove.adjust(0, 0, -1, 0)
            self._setup_painter(
                painter,
                opt.get_orientation(),
                groove.center().x(),
                groove.top(),
                groove.center().x(),
                groove.bottom(),
            )
        else:
            groove.adjust(0, 0, 0, -1)
            self._setup_painter(
                painter,
                opt.get_orientation(),
                groove.left(),
                groove.center().y(),
                groove.right(),
                groove.center().y(),
            )

        # draw groove
        intersected = core.RectF(rect.intersected(groove))
        gradient = gui.LinearGradient(intersected.topLeft(),
                                      intersected.topRight())
        gradient[0] = self.gradient_left
        gradient[1] = self.gradient_right
        painter.fillRect(intersected, gradient)
Пример #4
0
    def draw_span(self, painter, rect):
        opt = widgets.StyleOptionSlider()
        super().initStyleOption(opt)

        # area
        groove = self.style().subControlRect(SLIDER_STYLE, opt, GROOVE_STYLE,
                                             self)
        if opt.is_horizontal():
            groove.adjust(0, 0, -1, 0)
        else:
            groove.adjust(0, 0, 0, -1)

        # pen & brush
        painter.setPen(gui.Pen(self.gradient_left, 0))
        if opt.is_horizontal():
            self.setup_painter(painter, opt.orientation,
                               groove.center().x(), groove.top(),
                               groove.center().x(), groove.bottom())
        else:
            self.setup_painter(painter, opt.orientation, groove.left(),
                               groove.center().y(), groove.right(),
                               groove.center().y())

        # draw groove
        intersected = core.RectF(rect.intersected(groove))
        gradient = QtGui.QLinearGradient(intersected.topLeft(),
                                         intersected.topRight())
        gradient.setColorAt(0, self.gradient_left)
        gradient.setColorAt(1, self.gradient_right)
        painter.fillRect(intersected, gradient)
Пример #5
0
 def _calculate_inner_rect(self,
                           outer_radius: float) -> tuple[core.RectF, float]:
     if self.bar_style in ("line", "expand"):
         inner_radius = outer_radius - self.outline_pen_width
     else:
         inner_radius = outer_radius * 0.75
     delta = (outer_radius - inner_radius) / 2
     inner_rect = core.RectF(delta, delta, inner_radius, inner_radius)
     return inner_rect, inner_radius
Пример #6
0
 def add_rect(
     self,
     rect: types.RectType | types.RectFType,
     pen: QtGui.QPen | None = None,
     brush: QtGui.QBrush | None = None,
 ) -> widgets.GraphicsRectItem:
     if isinstance(rect, QtCore.QRect):
         rect = core.RectF(rect)
     elif isinstance(rect, tuple):
         rect = core.RectF(*rect)
     g_item = widgets.GraphicsRectItem()
     g_item.setRect(rect)
     if brush is not None:
         g_item.setBrush(brush)
     if pen is not None:
         g_item.setPen(pen)
     self.addItem(g_item)
     return g_item
Пример #7
0
 def add_ellipse(
     self,
     ellipse: types.RectType | types.RectFType,
     pen: QtGui.QPen | None = None,
     brush: QtGui.QBrush | None = None,
 ) -> widgets.GraphicsEllipseItem:
     if isinstance(ellipse, QtCore.QRect):
         ellipse = core.RectF(ellipse)
     elif isinstance(ellipse, tuple):
         ellipse = core.RectF(*ellipse)
     g_item = widgets.GraphicsEllipseItem()
     g_item.setRect(ellipse)
     if brush is not None:
         g_item.setBrush(brush)
     if pen is not None:
         g_item.setPen(pen)
     self.addItem(g_item)
     return g_item
Пример #8
0
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))
Пример #9
0
 def serialize_fields(self):
     return dict(
         scene=self.scene(),
         background_brush=self.get_background_brush(),
         foreground_brush=self.get_foreground_brush(),
         transformation_anchor=self.get_transformation_anchor(),
         resize_anchor=self.get_resize_anchor(),
         viewport_update_mode=self.get_viewport_update_mode(),
         drag_mode=self.get_drag_mode(),
         rubberband_selection_mode=self.get_rubberband_selection_mode(),
         scene_rect=core.RectF(self.sceneRect()),
         cache_mode=self.get_cache_mode(),
         is_interactive=self.isInteractive(),
     )
Пример #10
0
 def serialize_fields(self):
     return dict(
         items=self.items(),
         background_brush=self.get_background_brush(),
         foreground_brush=self.get_foreground_brush(),
         item_index_method=self.get_item_index_method(),
         minimum_render_size=self.minimumRenderSize(),
         palette=self.get_palette(),
         bsp_tree_depth=self.bspTreeDepth(),
         focus_on_touch=self.focusOnTouch(),
         sticky_focus=self.stickyFocus(),
         scene_rect=core.RectF(self.sceneRect()),
         font=self.get_font(),
     )
Пример #11
0
 def fill_rect(
     self,
     rect: types.RectType | types.RectFType,
     color: types.ColorType,
     pattern: constants.PatternStr = "solid",
 ):
     if pattern not in constants.PATTERN:
         raise InvalidParamError(pattern, constants.PATTERN)
     if isinstance(rect, tuple):
         rect = core.RectF(*rect)
     color = colors.get_color(color)
     if pattern != "solid":
         color = gui.Brush(color, constants.PATTERN[pattern])
     self.fillRect(rect, color)
Пример #12
0
 def paintEvent(self, event: gui.PaintEvent):
     outer_radius = min(self.width(), self.height())
     rect = core.RectF(1, 1, outer_radius - 2, outer_radius - 2)
     with gui.Painter(self) as painter:
         painter.use_antialiasing()
         if self.bar_style != "line":
             self._rebuild_data_brush_if_needed()
         painter.fillRect(0, 0, outer_radius, outer_radius,
                          self.palette().window())
         self._draw_base(painter, rect)
         self._draw_value(painter, rect, self.current_value)
         inner_rect, inner_radius = self._calculate_inner_rect(outer_radius)
         self._draw_inner_background(painter, inner_rect)
         self._draw_text(painter, inner_rect, inner_radius,
                         self.current_value)
Пример #13
0
    def paint(
        self,
        painter: QtGui.QPainter,
        rect: QtCore.QRect,
        mode: QtGui.QIcon.Mode,
        state: QtGui.QIcon.State,
    ):
        """Paint the icon int ``rect`` using ``painter``."""
        color = self._color
        if mode == QtGui.QIcon.Mode.Disabled:
            color = self._color.transparent(0.3)

        xml = self._xml.replace('fill="currentColor"',
                                color.get_name("svg_argb"))
        xml_byte = xml.encode()
        renderer = svg.SvgRenderer(xml_byte)
        renderer.render(painter, core.RectF(rect))
Пример #14
0
 def editorEvent(self, event, model, option, index):
     text = index.data()
     font = index.data(constants.FONT_ROLE)
     # alignment = index.data(constants.ALIGNMENT_ROLE)
     if font is None:
         font = gui.GuiApplication.get_font()
     fm = gui.FontMetricsF(font)
     rect = fm.get_bounding_rect(
         core.RectF(option.rect),
         constants.ALIGN_LEFT | constants.ALIGN_V_CENTER,  # type: ignore
         text,
     )
     if (event.type() == QtCore.QEvent.Type.MouseButtonPress
             and event.button() == QtCore.Qt.MouseButton.LeftButton
             and event.localPos() in rect):
         text = index.data()
         gui.DesktopServices.open_url(text)
         return True
     return False
Пример #15
0
 def get_frame_bounding_rect(self, frame: QtGui.QTextBlock) -> core.RectF:
     return core.RectF(self.frameBoundingRect(frame))
Пример #16
0
def test_pdfwriter():
    writer = gui.PdfWriter("test")
    writer.setup(core.RectF())
Пример #17
0
 def get_children_rect(self) -> core.RectF:
     return core.RectF(self.childrenRect())
Пример #18
0
 def get_bounding_rect(self) -> core.RectF:
     return core.RectF(self.boundingRect())
Пример #19
0
 def get_bounding_rect(self, *args) -> core.RectF:
     return core.RectF(self.boundingRect(*args))
Пример #20
0
 def get_block_bounding_rect(self, block: QtGui.QTextBlock) -> core.RectF:
     return core.RectF(self.blockBoundingRect(block))
Пример #21
0
 def get_input_item_rectangle(self) -> core.RectF:
     return core.RectF(self.inputItemRectangle())
Пример #22
0
 def get_anchor_rectangle(self) -> core.RectF:
     return core.RectF(self.anchorRectangle())
Пример #23
0
    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)
Пример #24
0
 def get_rect(self):
     return core.RectF(self.rect())
Пример #25
0
 def get_tight_bounding_rect(self, text: str) -> core.RectF:
     return core.RectF(self.tightBoundingRect(text))
Пример #26
0
def test_rectf():
    rect = core.RectF()
    repr(rect)
Пример #27
0
 def get_cursor_rectangle(self) -> core.RectF:
     return core.RectF(self.cursorRectangle())
Пример #28
0
 def get_viewboxf(self) -> core.RectF:
     return core.RectF(self.viewBoxF())
Пример #29
0
 def get_keyboard_rectangle(self) -> core.RectF:
     return core.RectF(self.keyboardRectangle())
Пример #30
0
 def get_plot_area(self) -> core.RectF:
     return core.RectF(self.plotArea())