mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-06-23 15:30:45 -04:00
Improve appearance by painting border lines for change blocks last and indicating context boundaries in the line number column as well
This commit is contained in:
parent
57c0b9c737
commit
2eccbae35f
@ -133,12 +133,16 @@ class TextBrowser(PlainTextEdit): # {{{
|
|||||||
while block.isValid() and top <= ev.rect().bottom():
|
while block.isValid() and top <= ev.rect().bottom():
|
||||||
r = ev.rect()
|
r = ev.rect()
|
||||||
if block.isVisible() and bottom >= r.top():
|
if block.isVisible() and bottom >= r.top():
|
||||||
if self.right:
|
text = unicode(self.line_number_map.get(num, ''))
|
||||||
painter.drawText(r.left() + 3, top, r.right(), self.fontMetrics().height(),
|
if text == '-':
|
||||||
Qt.AlignLeft, unicode(self.line_number_map.get(num, '')))
|
painter.drawLine(r.left() + 2, (top + bottom)//2, r.right() - 2, (top + bottom)//2)
|
||||||
else:
|
else:
|
||||||
painter.drawText(r.left(), top, r.right() - 5, self.fontMetrics().height(),
|
if self.right:
|
||||||
Qt.AlignRight, unicode(self.line_number_map.get(num, '')))
|
painter.drawText(r.left() + 3, top, r.right(), self.fontMetrics().height(),
|
||||||
|
Qt.AlignLeft, text)
|
||||||
|
else:
|
||||||
|
painter.drawText(r.left(), top, r.right() - 5, self.fontMetrics().height(),
|
||||||
|
Qt.AlignRight, text)
|
||||||
block = block.next()
|
block = block.next()
|
||||||
top = bottom
|
top = bottom
|
||||||
bottom = top + int(self.blockBoundingRect(block).height())
|
bottom = top + int(self.blockBoundingRect(block).height())
|
||||||
@ -153,28 +157,28 @@ class TextBrowser(PlainTextEdit): # {{{
|
|||||||
fv = self.firstVisibleBlock().blockNumber()
|
fv = self.firstVisibleBlock().blockNumber()
|
||||||
origin = self.contentOffset()
|
origin = self.contentOffset()
|
||||||
doc = self.document()
|
doc = self.document()
|
||||||
prev_top = None
|
lines = []
|
||||||
|
|
||||||
for top, bot, kind in self.changes:
|
for top, bot, kind in self.changes:
|
||||||
if bot < fv:
|
if bot < fv:
|
||||||
continue
|
continue
|
||||||
y_top = self.blockBoundingGeometry(doc.findBlockByNumber(top)).translated(origin).y() - 1
|
y_top = self.blockBoundingGeometry(doc.findBlockByNumber(top)).translated(origin).y()
|
||||||
y_bot = self.blockBoundingGeometry(doc.findBlockByNumber(bot)).translated(origin).y() + 1
|
y_bot = self.blockBoundingGeometry(doc.findBlockByNumber(bot)).translated(origin).y()
|
||||||
if max(y_top, y_bot) < ceiling:
|
if max(y_top, y_bot) < ceiling:
|
||||||
continue
|
continue
|
||||||
if min(y_top, y_bot) > floor:
|
if min(y_top, y_bot) > floor:
|
||||||
break
|
break
|
||||||
consecutive = prev_top == y_top # A replace after an insert or a delete
|
if y_top != y_bot:
|
||||||
if consecutive:
|
painter.fillRect(0, y_top, w, y_bot - y_top, self.diff_backgrounds[kind])
|
||||||
y_top += 2
|
lines.append((y_top, y_bot, kind))
|
||||||
prev_top = y_top
|
|
||||||
painter.fillRect(0, y_top, w, y_bot - y_top, self.diff_backgrounds[kind])
|
|
||||||
if not consecutive:
|
|
||||||
painter.setPen(QPen(self.diff_foregrounds[kind], 1))
|
|
||||||
painter.drawLine(0, y_top, w, y_top)
|
|
||||||
painter.drawLine(0, y_bot - 1, w, y_bot - 1)
|
|
||||||
painter.end()
|
painter.end()
|
||||||
PlainTextEdit.paintEvent(self, event)
|
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)
|
||||||
|
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
@ -252,6 +256,8 @@ class TextDiffView(QSplitter):
|
|||||||
self.changes.append(Change(
|
self.changes.append(Change(
|
||||||
ltop=cl.block().blockNumber()-1, lbot=cl.block().blockNumber(),
|
ltop=cl.block().blockNumber()-1, lbot=cl.block().blockNumber(),
|
||||||
rtop=cr.block().blockNumber()-1, rbot=cr.block().blockNumber(), kind='boundary'))
|
rtop=cr.block().blockNumber()-1, rbot=cr.block().blockNumber(), kind='boundary'))
|
||||||
|
self.left.line_number_map[self.changes[-1].ltop] = '-'
|
||||||
|
self.right.line_number_map[self.changes[-1].rtop] = '-'
|
||||||
cl.endEditBlock(), cr.endEditBlock()
|
cl.endEditBlock(), cr.endEditBlock()
|
||||||
del self.left_lines
|
del self.left_lines
|
||||||
del self.right_lines
|
del self.right_lines
|
||||||
|
Loading…
x
Reference in New Issue
Block a user