Remove frames around diff text views so that the diff lines cross the separator cleanly

This commit is contained in:
Kovid Goyal 2014-01-26 21:44:35 +05:30
parent 3e6a84d903
commit d24c887c2f

View File

@ -15,10 +15,10 @@ from future_builtins import zip
from PyQt4.Qt import ( from PyQt4.Qt import (
QSplitter, QApplication, QPlainTextDocumentLayout, QTextDocument, QTimer, QSplitter, QApplication, QPlainTextDocumentLayout, QTextDocument, QTimer,
QTextCursor, QTextCharFormat, Qt, QRect, QPainter, QPalette, QPen, QTextCursor, QTextCharFormat, Qt, QRect, QPainter, QPalette, QPen, QBrush,
QBrush, QColor, QTextLayout, QCursor, QFont, QSplitterHandle, QStyle, QColor, QTextLayout, QCursor, QFont, QSplitterHandle, QPainterPath,
QPainterPath, QHBoxLayout, QWidget, QScrollBar, QEventLoop, pyqtSignal, QHBoxLayout, QWidget, QScrollBar, QEventLoop, pyqtSignal, QImage, QPixmap,
QImage, QPixmap, QMenu, QIcon) QMenu, QIcon)
from calibre import human_readable, fit_image from calibre import human_readable, fit_image
from calibre.gui2.tweak_book import tprefs from calibre.gui2.tweak_book import tprefs
@ -50,6 +50,7 @@ class TextBrowser(PlainTextEdit): # {{{
def __init__(self, right=False, parent=None): def __init__(self, right=False, parent=None):
PlainTextEdit.__init__(self, parent) PlainTextEdit.__init__(self, parent)
self.setFrameStyle(0)
self.side_margin = 0 self.side_margin = 0
self.setContextMenuPolicy(Qt.CustomContextMenu) self.setContextMenuPolicy(Qt.CustomContextMenu)
self.customContextMenuRequested.connect(self.show_context_menu) self.customContextMenuRequested.connect(self.show_context_menu)
@ -157,8 +158,7 @@ class TextBrowser(PlainTextEdit): # {{{
self.setViewportMargins(self.side_margin, 0, 0, 0) self.setViewportMargins(self.side_margin, 0, 0, 0)
def available_width(self): def available_width(self):
fw = QApplication.style().pixelMetric(QStyle.PM_DefaultFrameWidth) return self.width() - self.side_margin
return self.width() - fw - self.side_margin
def line_number_area_width(self): def line_number_area_width(self):
digits = 1 digits = 1
@ -333,7 +333,6 @@ class DiffSplitHandle(QSplitterHandle): # {{{
w = self.width() w = self.width()
h = self.height() h = self.height()
painter.setRenderHints(QPainter.Antialiasing, True) painter.setRenderHints(QPainter.Antialiasing, True)
fw = QApplication.style().pixelMetric(QStyle.PM_DefaultFrameWidth)
C = 16 # Curve factor. C = 16 # Curve factor.
@ -356,10 +355,10 @@ class DiffSplitHandle(QSplitterHandle): # {{{
for (ltop, lbot, kind), (rtop, rbot, kind) in zip(left.changes, right.changes): for (ltop, lbot, kind), (rtop, rbot, kind) in zip(left.changes, right.changes):
if lbot < lfv and rbot < rfv: if lbot < lfv and rbot < rfv:
continue continue
ly_top = left.blockBoundingGeometry(ldoc.findBlockByNumber(ltop)).translated(lorigin).y() + fw ly_top = left.blockBoundingGeometry(ldoc.findBlockByNumber(ltop)).translated(lorigin).y()
ly_bot = left.blockBoundingGeometry(ldoc.findBlockByNumber(lbot)).translated(lorigin).y() + fw ly_bot = left.blockBoundingGeometry(ldoc.findBlockByNumber(lbot)).translated(lorigin).y()
ry_top = right.blockBoundingGeometry(rdoc.findBlockByNumber(rtop)).translated(rorigin).y() + fw ry_top = right.blockBoundingGeometry(rdoc.findBlockByNumber(rtop)).translated(rorigin).y()
ry_bot = right.blockBoundingGeometry(rdoc.findBlockByNumber(rbot)).translated(rorigin).y() + fw ry_bot = right.blockBoundingGeometry(rdoc.findBlockByNumber(rbot)).translated(rorigin).y()
if max(ly_top, ly_bot, ry_top, ry_bot) < 0: if max(ly_top, ly_bot, ry_top, ry_bot) < 0:
continue continue
if min(ly_top, ly_bot, ry_top, ry_bot) > h: if min(ly_top, ly_bot, ry_top, ry_bot) > h:
@ -399,7 +398,7 @@ class DiffSplitHandle(QSplitterHandle): # {{{
break break
ly = painter.boundingRect(3, ly_top, left.width(), ly_bot - ly_top - 5, Qt.TextSingleLine, text).bottom() + 3 ly = painter.boundingRect(3, ly_top, left.width(), ly_bot - ly_top - 5, Qt.TextSingleLine, text).bottom() + 3
ry = painter.boundingRect(3, ry_top, right.width(), ry_bot - ry_top - 5, Qt.TextSingleLine, text).bottom() + 3 ry = painter.boundingRect(3, ry_top, right.width(), ry_bot - ry_top - 5, Qt.TextSingleLine, text).bottom() + 3
line = create_line(ly + fw, ry + fw) line = create_line(ly, ry)
painter.setPen(QPen(left.palette().text(), 2)) painter.setPen(QPen(left.palette().text(), 2))
painter.setRenderHints(QPainter.Antialiasing, ly != ry) painter.setRenderHints(QPainter.Antialiasing, ly != ry)
painter.drawPath(line) painter.drawPath(line)