本文整理汇总了Python中calibre.gui2.tweak_book.editor.text.PlainTextEdit.paintEvent方法的典型用法代码示例。如果您正苦于以下问题:Python PlainTextEdit.paintEvent方法的具体用法?Python PlainTextEdit.paintEvent怎么用?Python PlainTextEdit.paintEvent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类calibre.gui2.tweak_book.editor.text.PlainTextEdit
的用法示例。
在下文中一共展示了PlainTextEdit.paintEvent方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: paintEvent
# 需要导入模块: from calibre.gui2.tweak_book.editor.text import PlainTextEdit [as 别名]
# 或者: from calibre.gui2.tweak_book.editor.text.PlainTextEdit import paintEvent [as 别名]
def paintEvent(self, event):
w = self.viewport().rect().width()
painter = QPainter(self.viewport())
painter.setClipRect(event.rect())
floor = event.rect().bottom()
ceiling = event.rect().top()
fv = self.firstVisibleBlock().blockNumber()
origin = self.contentOffset()
doc = self.document()
lines = []
for num, text in self.headers:
top, bot = num, num + 3
if bot < fv:
continue
y_top = self.blockBoundingGeometry(doc.findBlockByNumber(top)).translated(origin).y()
y_bot = self.blockBoundingGeometry(doc.findBlockByNumber(bot)).translated(origin).y()
if max(y_top, y_bot) < ceiling:
continue
if min(y_top, y_bot) > floor:
break
painter.setFont(self.heading_font)
br = painter.drawText(3, y_top, w, y_bot - y_top - 5, Qt.TextSingleLine, text)
painter.setPen(QPen(self.palette().text(), 2))
painter.drawLine(0, br.bottom()+3, w, br.bottom()+3)
for top, bot, kind in self.changes:
if bot < fv:
continue
y_top = self.blockBoundingGeometry(doc.findBlockByNumber(top)).translated(origin).y()
y_bot = self.blockBoundingGeometry(doc.findBlockByNumber(bot)).translated(origin).y()
if max(y_top, y_bot) < ceiling:
continue
if min(y_top, y_bot) > floor:
break
if y_top != y_bot:
painter.fillRect(0, y_top, w, y_bot - y_top, self.diff_backgrounds[kind])
lines.append((y_top, y_bot, kind))
if top in self.images:
img, maxw = self.images[top][:2]
if bot > top + 1 and not img.isNull():
y_top = self.blockBoundingGeometry(doc.findBlockByNumber(top+1)).translated(origin).y() + 3
y_bot -= 3
scaled, imgw, imgh = fit_image(img.width(), img.height(), w - 3, y_bot - y_top)
painter.setRenderHint(QPainter.SmoothPixmapTransform, True)
painter.drawPixmap(QRect(3, y_top, imgw, imgh), img)
painter.end()
PlainTextEdit.paintEvent(self, event)
painter = QPainter(self.viewport())
painter.setClipRect(event.rect())
for top, bottom, kind in sorted(lines, key=lambda (t, b, k):{'replace':0}.get(k, 1)):
painter.setPen(QPen(self.diff_foregrounds[kind], 1))
painter.drawLine(0, top, w, top)
painter.drawLine(0, bottom - 1, w, bottom - 1)