Ejemplo n.º 1
0
 def drawrect(self, row, col):
     painter = QPainter(self._image)
     painter.fillRect(
         (col + self.border) * self.box_size,
         (row + self.border) * self.box_size,
         self.box_size, self.box_size,
         Qt.black)
Ejemplo n.º 2
0
    def update_icon(self):
        self.icon.fill(QColor(0, 0, 0, 0))

        painter = QPainter(self.icon)

        (width, height) = self.icon.size().toTuple()
        width -= 1
        height -= 1

        painter.fillRect(QRect(0, 0, width, height), QColor(0, 0, 0, 0))

        try:
            scale = min(1.0 / max(self.packets), min_scale)
        except ValueError:
            scale = min_scale

        for index, ping in enumerate(list(reversed(self.packets))):
            x = ping / float(timeout)

            color = QColor(
                int(-324 * x**2 + 390 * x + 138),  # R
                int(-480 * x**2 + 254 * x + 226),  # G
                int(-212 * x**2 + 160 * x + 52),  # B
                255,
            )

            scaled_height = ceil(scale * ping * height)

            painter.fillRect(
                QRect(width - index, height - scaled_height, 1, scaled_height),
                color)

        self.tray_icon.setIcon(QIcon(QPixmap(self.icon)))
        self.tray_icon.show()
Ejemplo n.º 3
0
    def lineNumberAreaPaintEvent(self, event):

        mypainter = QPainter(self._line_number_widget)

        mypainter.fillRect(event.rect(), Qt.lightGray)

        block = self.firstVisibleBlock()
        blockNumber = block.blockNumber()
        top = self.blockBoundingGeometry(block).translated(
            self.contentOffset()).top()
        bottom = top + self.blockBoundingRect(block).height()

        # Just to make sure I use the right font
        height = self.fontMetrics().height()
        while block.isValid() and (top <= event.rect().bottom()):
            if block.isVisible() and (bottom >= event.rect().top()):
                number = str(blockNumber + 1)
                mypainter.setPen(Qt.black)
                mypainter.drawText(0, top, self._line_number_widget.width(),
                                   height, Qt.AlignRight, number)

            block = block.next()
            top = bottom
            bottom = top + self.blockBoundingRect(block).height()
            blockNumber += 1
Ejemplo n.º 4
0
    def paintEvent(self, *args):
        painter = QPainter(self)
        painter.setRenderHint(QPainter.HighQualityAntialiasing)

        r = self.rect()
        painter.fillRect(r, Qt.white)

        for element in self.elements:
            painter.translate(element.bounding_box.topLeft())
            element.paint(painter)
            painter.translate(-element.bounding_box.topLeft())

        for wire in self.wires:
            self._draw_wire(painter, wire)

        painter.setPen(QPen(Qt.red, 1, Qt.DashLine))
        painter.setBrush(Qt.transparent)
        for element in self.selected_elements:
            bb = element.bounding_box
            bb = bb.marginsAdded(QMargins(2, 2, 1, 1))
            painter.drawRect(bb)

        if self.wiring_assistant:
            painter.setPen(QPen(Qt.red, 1, Qt.PenStyle.DotLine))
            for line in self.guidelines:
                painter.drawLine(line)

            painter.setPen(QPen(Qt.red, 1, Qt.PenStyle.SolidLine))
            for p in self.guidepoints:
                painter.drawEllipse(p.x() - 4, p.y() - 4, 8, 8)

            if self.closest_point is not None:
                p = self.closest_point
                painter.drawEllipse(p.x() - 4, p.y() - 4, 8, 8)
Ejemplo n.º 5
0
    def paintEvent(self, event):
        """Event"""
        rec = event.rect()
        painter = QPainter()
        painter.begin(self)
        if not self.start_points:
            painter.fillRect(rec, QColor(0, 0, 0, 100))
            self.update_start_points(rec)
        # make mypy happy
        assert isinstance(self.start_points, list)

        if not self.last_point:
            pt = random.choice(self.start_points)
        else:
            rp = random.choice(self.start_points)
            pt = QPoint(
                (self.last_point.x() + rp.x()) / 2,
                (self.last_point.y() + rp.y()) / 2,
            )

        self.last_point = pt
        painter.setPen(QPen(self.color, 0.8))
        painter.drawPoint(pt)
        painter.end()
        # start next update
        self.update()
Ejemplo n.º 6
0
	def paintEvent(self, event):
		width = self.width()
		font_height = self.fontMetrics().height()

		text_edit = self.parent()

		event_rect = event.rect()
		event_rect_top = event_rect.top()
		event_rect_bottom = event_rect.bottom()

		# Create painter
		painter = QPainter(self)

		# Background
		painter.fillRect(event_rect, self.backgroundColour)

		# Line numbers
		block = text_edit.firstVisibleBlock()
		block_number = block.blockNumber()

		top = int(text_edit.blockBoundingGeometry(block).translated(text_edit.contentOffset()).top())
		bottom = top + int(text_edit.blockBoundingRect(block).height())

		painter.setPen(self.numberColour)
		while block.isValid() and top <= event_rect_bottom:
			if block.isVisible() and bottom >= event_rect_top:
				painter.drawText(0, top, width, font_height, self.numberAlignment, str(block_number + 1))

			block = block.next()
			top = bottom
			bottom = top + int(text_edit.blockBoundingRect(block).height())
			block_number += 1
Ejemplo n.º 7
0
    def lineNumberAreaPaintEvent(self, event):
        painter = QPainter(self.lineNumberArea)

        painter.fillRect(
            event.rect(),
            QColor("#1E1E1E"))  #QColor.fromRgb(103, 104, 103, 255))

        block = self.firstVisibleBlock()
        blockNumber = block.blockNumber()
        top = self.blockBoundingGeometry(block).translated(
            self.contentOffset()).top()
        bottom = top + self.blockBoundingRect(block).height()

        height = self.fontMetrics().height()
        while block.isValid() and (top <= event.rect().bottom()):
            if block.isVisible() and (bottom >= event.rect().top()):
                number = str(blockNumber + 1)
                painter.setPen(QColor("#235662"))
                painter.setFont(QFont("Sans serif", 8, QFont.Bold))
                painter.drawText(0, top, self.lineNumberArea.width(), height,
                                 Qt.AlignJustify, number)

            block = block.next()
            top = bottom
            bottom = top + self.blockBoundingRect(block).height()
            blockNumber += 1
Ejemplo n.º 8
0
    def paintEvent(self, event):
        p = QPainter(self)
        p.setRenderHint(QPainter.Antialiasing)

        r = event.rect()

        if self.is_revealed:
            if self.is_start:
                p.drawPixmap(r, QPixmap(IMG_START))

            elif self.is_mine:
                p.drawPixmap(r, QPixmap(IMG_BOMB))

            elif self.adjacent_n > 0:
                pen = QPen(NUM_COLORS[self.adjacent_n])
                p.setPen(pen)
                f = p.font()
                f.setBold(True)
                p.setFont(f)
                p.drawText(r, Qt.AlignHCenter | Qt.AlignVCenter, str(self.adjacent_n))

        else:
            p.fillRect(r, QBrush(Qt.lightGray))
            pen = QPen(Qt.gray)
            pen.setWidth(1)
            p.setPen(pen)
            p.drawRect(r)

            if self.is_flagged:
                p.drawPixmap(r, QPixmap(IMG_FLAG))
Ejemplo n.º 9
0
    def line_number_area_paint(self, event):
        """
        Paints the line numbers next to the code editor
        """
        painter = QPainter(self.line_number_area)
        painter.fillRect(event.rect(), QColor(self.config.get('colors', 'editor_lines_area_bg')))

        block = self.firstVisibleBlock()
        block_number = block.blockNumber()
        top = self.blockBoundingGeometry(block).translated(self.contentOffset()).top()
        bottom = top + self.blockBoundingRect(block).height()

        while block.isValid() and top <= event.rect().bottom():
            if block.isVisible() and bottom >= event.rect().top():
                number = str(block_number + 1)

                if block_number in self.breakpoints:
                    painter.setPen(QColor(self.config.get('colors', 'editor_breakpoint')))
                else:
                    painter.setPen(QColor(self.config.get('colors', 'editor_lines_area_text')))

                painter.drawText(0, top, self.line_number_area.width(),
                                 self.fontMetrics().height(),
                                 Qt.AlignRight, number)
            block = block.next()
            top = bottom
            bottom = top + self.blockBoundingRect(block).height()
            block_number += 1
Ejemplo n.º 10
0
    def __init__(self, *args, **kwargs):
        super().__init__(*args)
        self._zoom_level = 0
        self.grid_spacing = 8
        self.show_grid = False

        self.canvas_size = kwargs.get('size') or QtCore.QSize(256, 256)
        self.layer = Layer(self.canvas_size)
        self.tool = None

        self.scroll_area = QtWidgets.QScrollArea()
        self.scroll_area.setBackgroundRole(QtGui.QPalette.Dark)
        self.scroll_area.setAlignment(QtCore.Qt.AlignCenter)
        self.setCentralWidget(self.scroll_area)

        self.image_label = ImageLabel()
        self.image_label.setFrameRect(QtCore.QRect(0, 0, 0, 0))
        self.image_label.setFixedSize(self.canvas_size)
        self.image_label.setBackgroundRole(QtGui.QPalette.Light)
        self.scroll_area.setWidget(self.image_label)
        self.image_label.setScaledContents(True)

        self.draw_layer()

        self.setup_gestures()
        self.setup_actions()
        self.setup_docks()

        self.overlay = overlay.OverlayWidget(self.image_label)
        self.overlay.resize(self.image_label.size())
        self.overlay.show()

        p = QPainter(self.overlay)
        p.fillRect(self.overlay.rect(), QtCore.Qt.GlobalColor.black)
Ejemplo n.º 11
0
    def lineNumberAreaPaintEvent(self, event):
        painter = QPainter(self.lineNumberArea)

        painter.fillRect(event.rect(), QColor(233, 233, 233, 255))

        block = self.firstVisibleBlock()
        blockNumber = block.blockNumber()
        top = self.blockBoundingGeometry(block).translated(
            self.contentOffset()).top()
        bottom = top + self.blockBoundingRect(block).height()

        # Just to make sure I use the right font
        height = self.fontMetrics().height()
        while block.isValid() and (top <= event.rect().bottom()):
            if block.isVisible() and (bottom >= event.rect().top()):
                number = str(blockNumber + 1)
                fFont = QFont("Courier New", 10)
                painter.setPen(QColor(130, 130, 130, 255))
                painter.setFont(fFont)
                painter.drawText(0, top, self.lineNumberArea.width(), height,
                                 Qt.AlignCenter, number)

            block = block.next()
            top = bottom
            bottom = top + self.blockBoundingRect(block).height()
            blockNumber += 1
Ejemplo n.º 12
0
 def paintEvent(self, event):
     painter = QPainter(self)
     painter.fillRect(self.rect(), QBrush(self._color_srgb))
     painter.setCompositionMode(QPainter.RasterOp_SourceXorDestination)
     pen = QPen(QBrush(Qt.white), 2., Qt.SolidLine, Qt.SquareCap,
                Qt.MiterJoin)
     painter.setPen(pen)
     painter.drawRect(self.rect().adjusted(1, 1, -1, -1))
Ejemplo n.º 13
0
    def createColorIcon(color):
        pixmap = QPixmap(20, 20)
        painter = QPainter(pixmap)
        painter.setPen(Qt.NoPen)
        painter.fillRect(QRect(0, 0, 20, 20), color)
        painter.end()

        return QIcon(pixmap)
Ejemplo n.º 14
0
def get_icon(name, color=None):
    pixmap = QPixmap(f'icons-fontawesome/{name}.svg')
    if color != None:
        painter = QPainter(pixmap)
        painter.setCompositionMode(QPainter.CompositionMode_SourceIn)
        painter.fillRect(pixmap.rect(), color)
        painter.end()
    return QIcon(pixmap)
Ejemplo n.º 15
0
    def _draw_background(self, painter: QPainter, level: Level):
        painter.save()

        bg_color = bg_color_for_object_set(level.object_set_number, level.header.object_palette_index)

        painter.fillRect(level.get_rect(self.block_length), bg_color)

        painter.restore()
Ejemplo n.º 16
0
    def paintEvent(self, event):
        painter = QPainter()
        painter.begin(self)
        painter.setRenderHint(painter.Antialiasing)
        font = painter.font()
        font.setBold(True)
        painter.setFont(font)

        x = self.rect().x()
        y = self.rect().y()
        w = self.rect().width() - 1
        h = self.rect().height() - 1

        # draw the text
        painter.drawText(x + 33, y + 3, w, 16, Qt.AlignLeft | Qt.AlignTop,
                         self.title())

        painter.setRenderHint(QPainter.Antialiasing, False)

        self.__drawTriangle(painter, x, y)

        # draw the borders - top
        headerHeight = 20

        headerRect = QRect(x + 1, y + 1, w - 1, headerHeight)
        headerRectShadow = QRect(x - 1, y - 1, w + 1, headerHeight + 2)

        # Highlight
        pen = QPen(self.palette().color(QPalette.Light))
        pen.setWidthF(0.4)
        painter.setPen(pen)

        painter.drawRect(headerRect)
        painter.fillRect(headerRect, QColor(255, 255, 255, 18))

        # Shadow
        pen.setColor(self.palette().color(QPalette.Dark))
        painter.setPen(pen)
        painter.drawRect(headerRectShadow)

        if not self.isCollapsed():
            # draw the lover border
            pen = QPen(self.palette().color(QPalette.Dark))
            pen.setWidthF(0.8)
            painter.setPen(pen)

            offSet = headerHeight + 3
            bodyRect = QRect(x, y + offSet, w, h - offSet)
            bodyRectShadow = QRect(x + 1, y + offSet, w + 1, h - offSet + 1)
            painter.drawRect(bodyRect)

            pen.setColor(self.palette().color(QPalette.Light))
            pen.setWidthF(0.4)
            painter.setPen(pen)

            painter.drawRect(bodyRectShadow)

        painter.end()
    def paintEvent(self, event):
        # self.image.setPixelColor(0, 0, QColor(0, 255, 0))

        painter = QPainter(self)
        # painter.translate(self.width() / 2, self.height() / 2)
        # painter.drawEllipse(-5, -5, 20, 20)
        r = QRect(0, 0, self.width(), self.height())
        painter.fillRect(r, QColor())
        painter.drawPixmap(r, self.pixmap)
Ejemplo n.º 18
0
 def paintEvent(self, event):
     super().paintEvent(event)
     p = QPainter(self)
     p.fillRect(QRect(0, 0, self.PageWidth, self.PageHeight), Qt.white)
     p.setFont(QFont("微软雅黑", pointSize=10))
     p.setPen(Qt.black)
     p.drawRect(self.PageHorizontalMargin, self.PageVerticalMargin,
                self.PageContentWidth, self.PageContentHeight)
     p.drawText(QPoint(0, self.PageVerticalMargin), str(self.PageNumber))
Ejemplo n.º 19
0
 def paintEvent(self, event):
     super().paintEvent(event)
     painter = QPainter(self)
     brush = QBrush()
     brush.setColor(self.color)
     brush.setStyle(Qt.SolidPattern)
     rect = QRect(3, 3, -6 + self.width(), -6 + painter.device().height())
     painter.setBrush(brush)
     painter.fillRect(rect, brush)
def create_blue_green_rect():
    pixmap = QPixmap(4, 2)
    painter = QPainter(pixmap)
    try:
        painter.fillRect(0, 0, 2, 2, QColor('blue'))
        painter.fillRect(2, 0, 2, 2, QColor('green'))
    finally:
        painter.end()
    return pixmap
Ejemplo n.º 21
0
def _chromosone_to_pixmap(chromosone, total_triangles, size):
    width, height = size
    pixmap = QPixmap(width, height)
    painter = QPainter(pixmap)
    painter.fillRect(0, 0, width, height, Qt.gray)
    painter.setRenderHint(QPainter.Antialiasing)
    painter.setPen(Qt.transparent)
    _draw_chromosone(painter, chromosone, total_triangles, size=size)
    return pixmap
Ejemplo n.º 22
0
def pix_add_blurry(pix, transparency: float):
    temp_pix = QPixmap(pix.size())
    temp_pix.fill(Qt.transparent)
    painter = QPainter(temp_pix)
    painter.setCompositionMode(QPainter.CompositionMode_Source)
    painter.drawPixmap(0, 0, pix)
    painter.setCompositionMode(QPainter.CompositionMode_DestinationIn)
    painter.fillRect(temp_pix.rect(), QColor(0, 0, 0, int(255 * transparency)))
    painter.end()
    return temp_pix
Ejemplo n.º 23
0
 def paintEvent(self, event:QPaintEvent):
     """
     draws background
     :param event:
     :return: None
     """
     color = QColor(240,240,240)
     white = QColor(255,255,255)
     custom_painter = QPainter(self)
     custom_painter.fillRect(self.rect(), white)
Ejemplo n.º 24
0
    def paintEvent(self, event:QPaintEvent):
        """
        draws background
        :param event:
        :return: None
        """
        custom_painter = QPainter(self)
        custom_painter.fillRect(self.rect(), self.back_color)

        custom_painter.setPen(self.border_color)
        custom_painter.drawRect(0,0, self.rect().width()-1, self.rect().height()-1)
Ejemplo n.º 25
0
 def paintEvent(self, event):
     painter = QPainter(self)
     brush = self.palette().window().color()
     painter.fillRect(self.rect(), brush)
     painter.drawPixmap(2, 2, self._pixmap)
     painter.save()
     pen = QPen(QBrush(Qt.black), 2., Qt.SolidLine, Qt.SquareCap,
                Qt.MiterJoin)
     painter.setPen(pen)
     painter.drawRect(QRect(1, self._pos * self._scale + 1, 21, 5))
     painter.restore()
Ejemplo n.º 26
0
    def assert_equal(self):
        __tracebackhide__ = True
        self.end()
        self.different_pixels = 0
        actual_image: QImage = self.actual.device().toImage()
        expected_image: QImage = self.expected.device().toImage()
        diff_pixmap = QPixmap(actual_image.width(), actual_image.height())
        diff = QPainter(diff_pixmap)
        try:
            white = QColor('white')
            diff.fillRect(0, 0, actual_image.width(), actual_image.height(),
                          white)
            for x in range(actual_image.width()):
                for y in range(actual_image.height()):
                    actual_colour = actual_image.pixelColor(x, y)
                    expected_colour = expected_image.pixelColor(x, y)
                    diff.setPen(
                        self.diff_colour(actual_colour, expected_colour, x, y))
                    diff.drawPoint(x, y)
        finally:
            diff.end()
        diff_image: QImage = diff.device().toImage()

        display_diff(actual_image, diff_image, expected_image,
                     self.different_pixels)

        if self.different_pixels == 0:
            return
        actual_image.save(str(self.work_dir / (self.name + '_actual.png')))
        expected_image.save(str(self.work_dir / (self.name + '_expected.png')))
        diff_path = self.work_dir / (self.name + '_diff.png')
        is_saved = diff_image.save(str(diff_path))
        diff_width = self.diff_max_x - self.diff_min_x + 1
        diff_height = self.diff_max_y - self.diff_min_y + 1
        diff_section = QImage(diff_width, diff_height, QImage.Format_RGB32)
        diff_section_painter = QPainter(diff_section)
        try:
            diff_section_painter.drawPixmap(0, 0, diff_width, diff_height,
                                            QPixmap.fromImage(diff_image),
                                            self.diff_min_x, self.diff_min_y,
                                            diff_width, diff_height)
        finally:
            diff_section_painter.end()
        # To see an image dumped in the Travis CI log, copy the text from the
        # log, and paste it in test_pixmap_differ.test_decode_image.
        print(f'Encoded image of differing section '
              f'({self.diff_min_x}, {self.diff_min_y}) - '
              f'({self.diff_max_x}, {self.diff_max_y}):')
        print(encode_image(diff_section))
        message = f'Found {self.different_pixels} different pixels, '
        message += f'see' if is_saved else 'could not write'
        message += f' {diff_path.relative_to(Path(__file__).parent.parent)}.'
        assert self.different_pixels == 0, message
Ejemplo n.º 27
0
    def createColorToolButtonIcon(icon, color):
        pixmap = QPixmap(50, 80)
        pixmap.fill(Qt.transparent)
        painter = QPainter(pixmap)
        image = icon.pixmap(QSize(50, 80))
        target = QRect(0, 0, 50, 60)
        source = QRect(0, 0, 42, 42)
        painter.fillRect(QRect(0, 60, 50, 80), color)
        painter.drawPixmap(target, image, source)
        painter.end()

        return QIcon(pixmap)
Ejemplo n.º 28
0
    def _draw_background(self, painter: QPainter, level: Level):
        painter.save()

        if level.object_set_number == CLOUDY_OBJECT_SET:
            bg_color = QColor(
                *NESPalette[load_palette_group(level.object_set_number, level.header.object_palette_index)[3][2]]
            )
        else:
            bg_color = bg_color_for_object_set(level.object_set_number, level.header.object_palette_index)

        painter.fillRect(level.get_rect(self.block_length), bg_color)

        painter.restore()
Ejemplo n.º 29
0
    def draw(cls, x, y, self: PreparedText, painter: QPainter):
        font = QFont(self.fontName)
        if self.fontSize:
            font.setPointSizeF(self.fontSize)
        if self.fontBold:
            font.setBold(True)
        if self.fontItalic:
            font.setItalic(True)
        brushStyle = self.brushStyle or Qt.BrushStyle.SolidPattern
        w = self.width
        h = self.height
        tx = self.left + x
        ty = self.top + y
        if self.border:
            w -= self.border.width
            h -= self.border.width * 2
            tx += self.border.width
            ty += self.border.width
        rect = QRectF(tx, ty, w, h)

        if self.backColor:
            painter.setBrush(brush_style_map[brushStyle])
            painter.fillRect(rect, QColor('#' + hex(self.backColor)[2:]))
        if self.allowTags:
            doc = QTextDocument()
            doc.setDefaultFont(font)
            doc.setHtml(self.text)
            doc.setDocumentMargin(0)
            painter.save()
            painter.translate(tx + 2, ty + 1)
            doc.drawContents(painter, QRectF(0, 0, self.width, self.height))
            painter.restore()
        else:
            painter.save()
            painter.setFont(font)
            flags = cls.textFlags(self)
            rect.setX(rect.x() + 2)
            rect.setY(rect.y() + 1)
            painter.drawText(rect, flags, self.text)
            painter.restore()
        if self.border and self.border.color is not None:
            old_pen = painter.pen()
            pen = QPen(
                QColor(self.border.color), self.border.width,
                pen_style_map.get(self.border.style, Qt.PenStyle.SolidLine))
            painter.setPen(pen)
            painter.drawLines(
                cls.getLines(self, self.left + x, self.top + y,
                             self.left + self.width + x,
                             self.top + y + self.height))
            painter.setPen(old_pen)
Ejemplo n.º 30
0
    def lineNumberAreaPaintEvent(self, e):
        self.verticalScrollBar().setSliderPosition(self.verticalScrollBar().sliderPosition())

        painter = QPainter(self.lineNumberArea)

        # draw the background
        background = self.lineNumberArea.palette().color(self.lineNumberArea.backgroundRole())
        painter.fillRect(e.rect(), background)

        currentBlockNumber = self.textCursor().blockNumber()
        blockNumber = self.getFirstVisibleBlockId()
        block = self.document().findBlockByNumber(blockNumber)

        prev_block = self.document().findBlockByNumber(blockNumber - 1) if blockNumber > 0 else block
        translate_y = - self.verticalScrollBar().sliderPosition() if blockNumber > 0 else 0

        # Adjust text position according to the previous "non entirely visible" block if applicable
        # Also takes in consideration the document's margin offset.
        if blockNumber == 0:
            # Simply adjust to document's margin
            additional_margin = self.document().documentMargin() - 1 - self.verticalScrollBar().sliderPosition()
        else:
            # Getting the height of the visible part of the previous "non entirely visible" block
            # additional_margin = self.document().documentLayout().blockBoundingRect(prev_block).translated(
            #     0, translate_y).intersect(self.viewport().geometry().height())
            additional_margin = self.document().documentLayout().blockBoundingRect(prev_block).translated(
                0, translate_y).intersected(self.viewport().geometry()).height()

        # Shift the starting point
        top = self.viewport().geometry().top() + additional_margin
        bottom = top + self.document().documentLayout().blockBoundingRect(block).height()

        col_1 = QColor(90, 255, 30)     # Current line (custom green)
        col_0 = QColor(120, 120, 120)   # Other lines  (custom darkgrey)

        # Draw the numbers (displaying the current line number in green)
        while block.isValid() and top <= e.rect().bottom():
            if block.isVisible() and bottom >= e.rect().top():
                number = str(int(blockNumber + 1))
                painter.setPen(col_1 if currentBlockNumber == blockNumber else col_0)
                painter.drawText(0,
                                 top,
                                 self.lineNumberArea.width() - self.lineNumberArea.rightMargin,
                                 self.fontMetrics().height(),
                                 Qt.AlignRight,
                                 number)

            block = block.next()
            top = bottom
            bottom = top + self.document().documentLayout().blockBoundingRect(block).height()
            blockNumber += 1
Ejemplo n.º 31
0
    def paintEvent(self, event):
        painter = QPainter(self)
        painter.fillRect(self.rect(), Qt.black)

        if self.pixmap.isNull():
            painter.setPen(Qt.white)
            painter.drawText(self.rect(), Qt.AlignCenter,
                    "Rendering initial image, please wait...")
            return

        if self.curScale == self.pixmapScale:
            painter.drawPixmap(self.pixmapOffset, self.pixmap)
        else:
            scaleFactor = self.pixmapScale / self.curScale
            newWidth = int(self.pixmap.width() * scaleFactor)
            newHeight = int(self.pixmap.height() * scaleFactor)
            newX = self.pixmapOffset.x() + (self.pixmap.width() - newWidth) / 2
            newY = self.pixmapOffset.y() + (self.pixmap.height() - newHeight) / 2

            painter.save()
            painter.translate(newX, newY)
            painter.scale(scaleFactor, scaleFactor)
            exposed, _ = painter.matrix().inverted()
            exposed = exposed.mapRect(self.rect()).adjusted(-1, -1, 1, 1)
            painter.drawPixmap(exposed, self.pixmap, exposed)
            painter.restore()

        text = "Use mouse wheel or the '+' and '-' keys to zoom. Press and " \
                "hold left mouse button to scroll."
        metrics = painter.fontMetrics()
        textWidth = metrics.width(text)

        painter.setPen(Qt.NoPen)
        painter.setBrush(QColor(0, 0, 0, 127))
        painter.drawRect((self.width() - textWidth) / 2 - 5, 0, textWidth + 10,
                metrics.lineSpacing() + 5)
        painter.setPen(Qt.white)
        painter.drawText((self.width() - textWidth) / 2,
                metrics.leading() + metrics.ascent(), text)