Exemple #1
0
        def paintEvent(self, event):
            contents_y = self.edit.verticalScrollBar().value()
            page_bottom = contents_y + self.edit.viewport().height()
            font_metrics = self.fontMetrics()
            current_block = self.edit.document().findBlock(
                self.edit.textCursor().position())

            painter = QPainter(self)

            line_count = 0
            # Iterate over all text blocks in the document.
            block = self.edit.document().begin()
            while block.isValid():
                line_count += 1

                # The top left position of the block in the document
                position = self.edit.document().documentLayout(
                ).blockBoundingRect(block).topLeft()

                # Check if the position of the block is out side of the visible
                # area.
                if position.y() > page_bottom:
                    break

                # We want the line number for the selected line to be bold.
                bold = False

                if block == current_block:
                    bold = True
                    font = painter.font()
                    font.setBold(True)
                    painter.setFont(font)

                # Draw the line number right justified at the y position of the
                # line. 3 is a magic padding number. drawText(x, y, text).
                painter.drawText(
                    self.width() - font_metrics.width(str(line_count)) - 3,
                    round(position.y()) - contents_y + font_metrics.ascent(),
                    str(line_count))

                # Remove the bold style if it was set previously.
                if bold:
                    font = painter.font()
                    font.setBold(False)
                    painter.setFont(font)

                block = block.next()

            self.highest_line = line_count
            painter.end()

            QWidget.paintEvent(self, event)
        def numberbarPaint(self, number_bar, event):
            """
			Pain the line numbers
			"""

            font_metrics = self.fontMetrics()
            current_line = self.document().findBlock(
                self.textCursor().position()).blockNumber() + 1

            block = self.firstVisibleBlock()
            line_count = block.blockNumber()
            painter = QPainter(number_bar)

            fg_pen = QtGui.QPen(QtGui.QColor("gray"))

            painter.setFont(self.font)
            painter.setPen(fg_pen)
            painter.fillRect(event.rect(), self.palette().base())

            # Iterate over all visible text blocks in the document.
            while block.isValid():
                line_count += 1
                block_top = self.blockBoundingGeometry(block).translated(
                    self.contentOffset()).top()

                # Check if the position of the block is out side of the visible
                # area.
                if not block.isVisible() or block_top >= event.rect().bottom():
                    break

                # We want the line number for the selected line to be bold.
                if line_count == current_line:
                    font = painter.font()
                    font.setBold(True)
                    painter.setFont(font)
                else:
                    font = painter.font()
                    font.setBold(False)
                    painter.setFont(font)

                # Draw the line number right justified at the position of the line.
                paint_rect = QRect(0, block_top, number_bar.width(),
                                   font_metrics.height())
                painter.drawText(paint_rect, Qt.AlignRight,
                                 unicode("x%.4d" % line_count))

                block = block.next()

            painter.end()
Exemple #3
0
    def paintEvent(self, event):
        contents_y = self.edit.verticalScrollBar().value()
        page_bottom = contents_y + self.edit.viewport().height()
        font_metrics = self.fontMetrics()
        current_block = self.edit.document().findBlock(self.edit.textCursor().position())

        painter = QPainter(self)

        line_count = 0
        # Iterate over all text blocks in the document.
        block = self.edit.document().begin()
        while block.isValid():
            line_count += 1

            # The top left position of the block in the document
            position = self.edit.document().documentLayout().blockBoundingRect(block).topLeft()

            # Check if the position of the block is out side of the visible
            # area.
            if position.y() > page_bottom:
                break

            # We want the line number for the selected line to be bold.
            bold = False
            if block == current_block:
                bold = True
                font = painter.font()
                font.setBold(True)
                painter.setFont(font)

            # Draw the line number right justified at the y position of the
            # line. 3 is a magic padding number. drawText(x, y, text).
            painter.drawText(self.width() - font_metrics.width(str(line_count)) - 3, 
                round(position.y()) - contents_y + font_metrics.ascent()+3, 
                str(line_count))

            # Remove the bold style if it was set previously.
            if bold:
                font = painter.font()
                font.setBold(False)
                painter.setFont(font)

            block = block.next()

        self.highest_line = line_count
        painter.end()

        QWidget.paintEvent(self, event)
Exemple #4
0
    def paintEvent(self, event):
        pmap = self.blank if self.pixmap is None or self.pixmap.isNull(
        ) else self.pixmap
        target = self.rect()
        scaled, width, height = fit_image(pmap.width(), pmap.height(),
                                          target.width(), target.height())
        target.setRect(target.x(), target.y(), width, height)
        p = QPainter(self)
        p.setRenderHints(QPainter.Antialiasing
                         | QPainter.SmoothPixmapTransform)
        p.drawPixmap(target, pmap)

        if self.pixmap is not None and not self.pixmap.isNull():
            sztgt = target.adjusted(0, 0, 0, -4)
            f = p.font()
            f.setBold(True)
            p.setFont(f)
            sz = u'\u00a0%d x %d\u00a0' % (self.pixmap.width(),
                                           self.pixmap.height())
            flags = Qt.AlignBottom | Qt.AlignRight | Qt.TextSingleLine
            szrect = p.boundingRect(sztgt, flags, sz)
            p.fillRect(szrect.adjusted(0, 0, 0, 4), QColor(0, 0, 0, 200))
            p.setPen(QPen(QColor(255, 255, 255)))
            p.drawText(sztgt, flags, sz)
        p.end()
Exemple #5
0
 def paintEvent(self, event):
     canvas_size = self.rect()
     width = self.current_pixmap_size.width()
     extrax = canvas_size.width() - width
     if extrax < 0: extrax = 0
     x = int(extrax / 2.)
     height = self.current_pixmap_size.height()
     extray = canvas_size.height() - height
     if extray < 0: extray = 0
     y = int(extray / 2.)
     target = QRect(x, y, width, height)
     p = QPainter(self)
     p.setRenderHints(QPainter.Antialiasing
                      | QPainter.SmoothPixmapTransform)
     p.drawPixmap(
         target,
         self.pixmap.scaled(target.size(), Qt.KeepAspectRatio,
                            Qt.SmoothTransformation))
     if gprefs['bd_overlay_cover_size']:
         sztgt = target.adjusted(0, 0, 0, -4)
         f = p.font()
         f.setBold(True)
         p.setFont(f)
         sz = u'\u00a0%d x %d\u00a0' % (self.pixmap.width(),
                                        self.pixmap.height())
         flags = Qt.AlignBottom | Qt.AlignRight | Qt.TextSingleLine
         szrect = p.boundingRect(sztgt, flags, sz)
         p.fillRect(szrect.adjusted(0, 0, 0, 4), QColor(0, 0, 0, 200))
         p.setPen(QPen(QColor(255, 255, 255)))
         p.drawText(sztgt, flags, sz)
     p.end()
Exemple #6
0
 def paintEvent(self, event):
     QWidget.paintEvent(self, event)
     pmap = self._pixmap
     if pmap.isNull():
         return
     w, h = pmap.width(), pmap.height()
     ow, oh = w, h
     cw, ch = self.rect().width(), self.rect().height()
     scaled, nw, nh = fit_image(w, h, cw, ch)
     if scaled:
         pmap = pmap.scaled(nw, nh, Qt.IgnoreAspectRatio, Qt.SmoothTransformation)
     w, h = pmap.width(), pmap.height()
     x = int(abs(cw - w) / 2.0)
     y = int(abs(ch - h) / 2.0)
     target = QRect(x, y, w, h)
     p = QPainter(self)
     p.setRenderHints(QPainter.Antialiasing | QPainter.SmoothPixmapTransform)
     p.drawPixmap(target, pmap)
     if self.draw_border:
         pen = QPen()
         pen.setWidth(self.BORDER_WIDTH)
         p.setPen(pen)
         p.drawRect(target)
     if self.show_size:
         sztgt = target.adjusted(0, 0, 0, -4)
         f = p.font()
         f.setBold(True)
         p.setFont(f)
         sz = u"\u00a0%d x %d\u00a0" % (ow, oh)
         flags = Qt.AlignBottom | Qt.AlignRight | Qt.TextSingleLine
         szrect = p.boundingRect(sztgt, flags, sz)
         p.fillRect(szrect.adjusted(0, 0, 0, 4), QColor(0, 0, 0, 200))
         p.setPen(QPen(QColor(255, 255, 255)))
         p.drawText(sztgt, flags, sz)
     p.end()
Exemple #7
0
 def paintEvent(self, event):
     canvas_size = self.rect()
     width = self.current_pixmap_size.width()
     extrax = canvas_size.width() - width
     if extrax < 0:
         extrax = 0
     x = int(extrax/2.)
     height = self.current_pixmap_size.height()
     extray = canvas_size.height() - height
     if extray < 0:
         extray = 0
     y = int(extray/2.)
     target = QRect(x, y, width, height)
     p = QPainter(self)
     p.setRenderHints(QPainter.Antialiasing | QPainter.SmoothPixmapTransform)
     p.drawPixmap(target, self.pixmap.scaled(target.size(),
         Qt.KeepAspectRatio, Qt.SmoothTransformation))
     if gprefs['bd_overlay_cover_size']:
         sztgt = target.adjusted(0, 0, 0, -4)
         f = p.font()
         f.setBold(True)
         p.setFont(f)
         sz = u'\u00a0%d x %d\u00a0'%(self.pixmap.width(), self.pixmap.height())
         flags = Qt.AlignBottom|Qt.AlignRight|Qt.TextSingleLine
         szrect = p.boundingRect(sztgt, flags, sz)
         p.fillRect(szrect.adjusted(0, 0, 0, 4), QColor(0, 0, 0, 200))
         p.setPen(QPen(QColor(255,255,255)))
         p.drawText(sztgt, flags, sz)
     p.end()
		def numberbarPaint(self, number_bar, event):
		
			"""
			Pain the line numbers
			"""
		
			font_metrics = self.fontMetrics()
			current_line = self.document().findBlock(self.textCursor().position()).blockNumber() + 1
	 
			block = self.firstVisibleBlock()
			line_count = block.blockNumber()
			painter = QPainter(number_bar)
			
			fg_pen = QtGui.QPen(QtGui.QColor("gray"))
			
			painter.setFont(self.font)
			painter.setPen(fg_pen)
			painter.fillRect(event.rect(), self.palette().base())
	 
			# Iterate over all visible text blocks in the document.
			while block.isValid():
				line_count += 1
				block_top = self.blockBoundingGeometry(block).translated(self.contentOffset()).top()
		 
				# Check if the position of the block is out side of the visible
				# area.
				if not block.isVisible() or block_top >= event.rect().bottom():
					break
		 
				# We want the line number for the selected line to be bold.
				if line_count == current_line:
					font = painter.font()
					font.setBold(True)
					painter.setFont(font)
				else:
					font = painter.font()
					font.setBold(False)
					painter.setFont(font)
		 
				# Draw the line number right justified at the position of the line.
				paint_rect = QRect(0, block_top, number_bar.width(), font_metrics.height())
				painter.drawText(paint_rect, Qt.AlignRight, unicode("x%.4d" % line_count))
		 
				block = block.next()
	 
			painter.end()
Exemple #9
0
 def paintEvent(self, ev):
     br = ev.region().boundingRect()
     QWidget.paintEvent(self, ev)
     p = QPainter(self)
     p.setClipRect(br)
     f = p.font()
     f.setBold(True)
     f.setPointSize(20)
     p.setFont(f)
     p.setPen(Qt.SolidLine)
     r = QRect(0, self.dummy.geometry().top() + 10, self.geometry().width(), 150)
     p.drawText(r, Qt.AlignHCenter | Qt.AlignTop | Qt.TextSingleLine, self.text)
     p.end()
Exemple #10
0
 def paintEvent(self, ev):
     br = ev.region().boundingRect()
     QWidget.paintEvent(self, ev)
     p = QPainter(self)
     p.setClipRect(br)
     f = p.font()
     f.setBold(True)
     f.setPointSize(20)
     p.setFont(f)
     p.setPen(Qt.SolidLine)
     r = QRect(0, self.dummy.geometry().top() + 10, self.geometry().width(), 150)
     p.drawText(r, Qt.AlignHCenter | Qt.AlignTop | Qt.TextSingleLine, self.text)
     p.end()
Exemple #11
0
def create_icon(text, palette=None, sz=32, divider=2):
    if palette is None:
        palette = QApplication.palette()
    img = QImage(sz, sz, QImage.Format_ARGB32)
    img.fill(Qt.transparent)
    p = QPainter(img)
    p.setRenderHints(p.TextAntialiasing | p.Antialiasing)
    qDrawShadeRect(p, img.rect(), palette, fill=QColor('#ffffff'), lineWidth=1, midLineWidth=1)
    f = p.font()
    f.setFamily('Liberation Sans'), f.setPixelSize(sz // divider), f.setBold(True)
    p.setFont(f), p.setPen(Qt.black)
    p.drawText(img.rect().adjusted(2, 2, -2, -2), Qt.AlignCenter, text)
    p.end()
    return QIcon(QPixmap.fromImage(img))
Exemple #12
0
def create_icon(text, palette=None, sz=32, divider=2):
    if palette is None:
        palette = QApplication.palette()
    img = QImage(sz, sz, QImage.Format_ARGB32)
    img.fill(Qt.transparent)
    p = QPainter(img)
    p.setRenderHints(p.TextAntialiasing | p.Antialiasing)
    qDrawShadeRect(p,
                   img.rect(),
                   palette,
                   fill=QColor('#ffffff'),
                   lineWidth=1,
                   midLineWidth=1)
    f = p.font()
    f.setFamily('Liberation Sans'), f.setPixelSize(sz //
                                                   divider), f.setBold(True)
    p.setFont(f), p.setPen(Qt.black)
    p.drawText(img.rect().adjusted(2, 2, -2, -2), Qt.AlignCenter, text)
    p.end()
    return QIcon(QPixmap.fromImage(img))
Exemple #13
0
    def paintEvent(self, event):
        pmap = self.blank if self.pixmap is None or self.pixmap.isNull() else self.pixmap
        target = self.rect()
        scaled, width, height = fit_image(pmap.width(), pmap.height(), target.width(), target.height())
        target.setRect(target.x(), target.y(), width, height)
        p = QPainter(self)
        p.setRenderHints(QPainter.Antialiasing | QPainter.SmoothPixmapTransform)
        p.drawPixmap(target, pmap)

        if self.pixmap is not None and not self.pixmap.isNull():
            sztgt = target.adjusted(0, 0, 0, -4)
            f = p.font()
            f.setBold(True)
            p.setFont(f)
            sz = u'\u00a0%d x %d\u00a0'%(self.pixmap.width(), self.pixmap.height())
            flags = Qt.AlignBottom|Qt.AlignRight|Qt.TextSingleLine
            szrect = p.boundingRect(sztgt, flags, sz)
            p.fillRect(szrect.adjusted(0, 0, 0, 4), QColor(0, 0, 0, 200))
            p.setPen(QPen(QColor(255,255,255)))
            p.drawText(sztgt, flags, sz)
        p.end()
Exemple #14
0
 def paintEvent(self, event):
     QWidget.paintEvent(self, event)
     pmap = self._pixmap
     if pmap.isNull():
         return
     w, h = pmap.width(), pmap.height()
     ow, oh = w, h
     cw, ch = self.rect().width(), self.rect().height()
     scaled, nw, nh = fit_image(w, h, cw, ch)
     if scaled:
         pmap = pmap.scaled(nw, nh, Qt.IgnoreAspectRatio,
                            Qt.SmoothTransformation)
     w, h = pmap.width(), pmap.height()
     x = int(abs(cw - w) / 2.)
     y = int(abs(ch - h) / 2.)
     target = QRect(x, y, w, h)
     p = QPainter(self)
     p.setRenderHints(QPainter.Antialiasing
                      | QPainter.SmoothPixmapTransform)
     p.drawPixmap(target, pmap)
     if self.draw_border:
         pen = QPen()
         pen.setWidth(self.BORDER_WIDTH)
         p.setPen(pen)
         p.drawRect(target)
     if self.show_size:
         sztgt = target.adjusted(0, 0, 0, -4)
         f = p.font()
         f.setBold(True)
         p.setFont(f)
         sz = u'\u00a0%d x %d\u00a0' % (ow, oh)
         flags = Qt.AlignBottom | Qt.AlignRight | Qt.TextSingleLine
         szrect = p.boundingRect(sztgt, flags, sz)
         p.fillRect(szrect.adjusted(0, 0, 0, 4), QColor(0, 0, 0, 200))
         p.setPen(QPen(QColor(255, 255, 255)))
         p.drawText(sztgt, flags, sz)
     p.end()
Exemple #15
0
            #     p.translate(xmax/10, xmax/10)
            #     p.scale(1, 1.5)
            # p.restore()

            # # p.scale(2, 2)
            # # p.rotate(45)
            # p.drawPixmap(0, 0, 2048, 2048, QPixmap(I('library.png')))
            # p.drawRect(0, 0, 2048, 2048)

            # p.save()
            # p.drawLine(0, 0, 5000, 0)
            # p.rotate(45)
            # p.drawLine(0, 0, 5000, 0)
            # p.restore()

            f = p.font()
            f.setPointSize(20)
            # f.setLetterSpacing(f.PercentageSpacing, 200)
            # f.setUnderline(True)
            # f.setOverline(True)
            # f.setStrikeOut(True)
            f.setFamily("DejaVu Sans")
            p.setFont(f)
            # p.setPen(QColor(0, 0, 255))
            # p.scale(2, 2)
            # p.rotate(45)
            p.drawText(QPoint(0, 300), "Some—text not By’s ū --- Д AV ff ff")
        finally:
            p.end()
        if dev.engine.errors_occurred:
            raise SystemExit(1)
Exemple #16
0
        def numberbarPaint(self, number_bar, event):
            font_metrics = self.fontMetrics()
            # edit_font = self.font()
            current_line = self.document().findBlock(
                self.textCursor().position()).blockNumber() + 1

            block = self.firstVisibleBlock()
            # block = self.document().findBlock(2)
            # block = self.document().firstBlock()
            line_count = block.blockNumber()
            painter = QPainter(number_bar)

            # baseBrush=self.palette().light()
            # baseBrush.setColor(Qt.darkGray)
            painter.fillRect(event.rect(), self.palette().light())

            # Iterate over all visible text blocks in the document.
            while block.isValid():
                line_count += 1
                block_bounding_rect = self.blockBoundingGeometry(
                    block).translated(self.contentOffset())

                block_top = block_bounding_rect.top()
                # block_top_middle=block_top + font_metrics.height()/2

                # f.write('line_count: %s , %s' % (line_count,block_top))
                # Check if the position of the block is out side of the visible
                # area.
                if not block.isVisible() or block_top >= event.rect().bottom():
                    break
                    # pass

                # We want the line number for the selected line to be bold.
                if line_count == current_line:
                    font = painter.font()
                    font.setBold(True)
                    # font.setPointSize(font.pointSize() * 2)
                    # painter.setFont(font)
                else:
                    font = painter.font()
                    font.setBold(False)
                    # font.setPointSize(font.pointSize() * 2)

                # print 'painter font size',font.pointSize(),
                # '--->',font.pointSize()*2
                edit_font_size = self.font().pointSize()
                if edit_font_size > 0:
                    font.setPointSize(edit_font_size)

                painter.setFont(font)

                # font.setPointSize(20)

                # Draw the line number right justified at the position of the
                # line.
                paint_rect = QRect(
                    0, block_top, number_bar.width(),
                    font_metrics.height())  # edit_font.pixelSize())
                painter.drawText(paint_rect, Qt.AlignRight,
                                 unicode(line_count))

                block = block.next()

            painter.end()
Exemple #17
0
        def numberbarPaint(self, number_bar, event):
            font_metrics = self.fontMetrics()
            # edit_font = self.font()
            current_line = self.document().findBlock(
                self.textCursor().position()).blockNumber() + 1

            block = self.firstVisibleBlock()
            # block = self.document().findBlock(2)
            # block = self.document().firstBlock()
            line_count = block.blockNumber()
            painter = QPainter(number_bar)

            # baseBrush=self.palette().light()
            # baseBrush.setColor(Qt.darkGray)
            painter.fillRect(event.rect(), self.palette().light())

            # Iterate over all visible text blocks in the document.
            while block.isValid():
                line_count += 1
                block_bounding_rect = self.blockBoundingGeometry(
                    block).translated(self.contentOffset())

                block_top = block_bounding_rect.top()
                # block_top_middle=block_top + font_metrics.height()/2

                # f.write('line_count: %s , %s' % (line_count,block_top))
                # Check if the position of the block is out side of the visible
                # area.
                if not block.isVisible() or block_top >= event.rect().bottom():
                    break
                    # pass

                # We want the line number for the selected line to be bold.
                if line_count == current_line:
                    font = painter.font()
                    font.setBold(True)
                    # font.setPointSize(font.pointSize() * 2)
                    # painter.setFont(font)
                else:
                    font = painter.font()
                    font.setBold(False)
                    # font.setPointSize(font.pointSize() * 2)

                # print 'painter font size',font.pointSize(),
                # '--->',font.pointSize()*2
                edit_font_size = self.font().pointSize()
                if edit_font_size > 0:
                    font.setPointSize(edit_font_size)

                painter.setFont(font)

                # font.setPointSize(20)

                # Draw the line number right justified at the position of the
                # line.
                paint_rect = QRect(
                    0, block_top, number_bar.width(),  font_metrics.height())  # edit_font.pixelSize())
                painter.drawText(
                    paint_rect, Qt.AlignRight, unicode(line_count))

                block = block.next()

            painter.end()