mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Replace QTextLayouts::*additionalFormats methods
This commit is contained in:
parent
83cd7bfa12
commit
8846f7fd44
@ -138,7 +138,7 @@ class Block:
|
|||||||
for text in text.split('<br>') if text else ():
|
for text in text.split('<br>') if text else ():
|
||||||
text, formats = parse_text_formatting(sanitize(text))
|
text, formats = parse_text_formatting(sanitize(text))
|
||||||
l = QTextLayout(unescape_formatting(text), font, img)
|
l = QTextLayout(unescape_formatting(text), font, img)
|
||||||
l.setAdditionalFormats(formats)
|
l.setFormats(formats)
|
||||||
to = QTextOption(align)
|
to = QTextOption(align)
|
||||||
to.setWrapMode(QTextOption.WrapMode.WrapAtWordBoundaryOrAnywhere)
|
to.setWrapMode(QTextOption.WrapMode.WrapAtWordBoundaryOrAnywhere)
|
||||||
l.setTextOption(to)
|
l.setTextOption(to)
|
||||||
|
@ -40,7 +40,7 @@ class QtHighlighter(QTextDocument):
|
|||||||
dest_block = cursor.block()
|
dest_block = cursor.block()
|
||||||
c = QTextCursor(dest_block)
|
c = QTextCursor(dest_block)
|
||||||
try:
|
try:
|
||||||
afs = block.layout().additionalFormats()
|
afs = block.layout().formats()
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
afs = ()
|
afs = ()
|
||||||
for af in afs:
|
for af in afs:
|
||||||
|
@ -160,9 +160,9 @@ class TextBrowser(PlainTextEdit): # {{{
|
|||||||
setattr(self, '%s_format' % x, f)
|
setattr(self, '%s_format' % x, f)
|
||||||
|
|
||||||
def calculate_metrics(self):
|
def calculate_metrics(self):
|
||||||
w = self.fontMetrics()
|
fm = self.fontMetrics()
|
||||||
self.number_width = max(map(lambda x:w.width(str(x)), range(10)))
|
self.number_width = max(map(lambda x:fm.horizontalAdvance(str(x)), range(10)))
|
||||||
self.space_width = w.width(' ')
|
self.space_width = fm.horizontalAdvance(' ')
|
||||||
|
|
||||||
def show_context_menu(self, pos):
|
def show_context_menu(self, pos):
|
||||||
m = QMenu(self)
|
m = QMenu(self)
|
||||||
@ -879,7 +879,7 @@ class DiffSplit(QSplitter): # {{{
|
|||||||
for word in words[lo:hi]:
|
for word in words[lo:hi]:
|
||||||
if word == '\n':
|
if word == '\n':
|
||||||
if fmts:
|
if fmts:
|
||||||
block.layout().setAdditionalFormats(fmts)
|
block.layout().setFormats(fmts)
|
||||||
pos, block, fmts = 0, block.next(), []
|
pos, block, fmts = 0, block.next(), []
|
||||||
continue
|
continue
|
||||||
|
|
||||||
@ -897,7 +897,7 @@ class DiffSplit(QSplitter): # {{{
|
|||||||
rsb, rpos, rfmts = do_tag(rsb, rl, rlo, rhi, rpos, rfmts)
|
rsb, rpos, rfmts = do_tag(rsb, rl, rlo, rhi, rpos, rfmts)
|
||||||
for block, fmts in ((lsb, lfmts), (rsb, rfmts)):
|
for block, fmts in ((lsb, lfmts), (rsb, rfmts)):
|
||||||
if fmts:
|
if fmts:
|
||||||
block.layout().setAdditionalFormats(fmts)
|
block.layout().setFormats(fmts)
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
# }}}
|
# }}}
|
||||||
|
@ -95,7 +95,7 @@ class SyntaxHighlighter:
|
|||||||
c.beginEditBlock()
|
c.beginEditBlock()
|
||||||
blk = old_doc.begin()
|
blk = old_doc.begin()
|
||||||
while blk.isValid():
|
while blk.isValid():
|
||||||
blk.layout().clearAdditionalFormats()
|
blk.layout().clearFormats()
|
||||||
blk = blk.next()
|
blk = blk.next()
|
||||||
c.endEditBlock()
|
c.endEditBlock()
|
||||||
self.doc = self.doc_name = None
|
self.doc = self.doc_name = None
|
||||||
@ -237,4 +237,4 @@ class SyntaxHighlighter:
|
|||||||
r.start += preedit_length
|
r.start += preedit_length
|
||||||
elif r.start + r.length >= preedit_start:
|
elif r.start + r.length >= preedit_start:
|
||||||
r.length += preedit_length
|
r.length += preedit_length
|
||||||
layout.setAdditionalFormats(formats)
|
layout.setFormats(formats)
|
||||||
|
@ -566,7 +566,7 @@ class TextEdit(PlainTextEdit):
|
|||||||
c.movePosition(QTextCursor.MoveOperation.Start)
|
c.movePosition(QTextCursor.MoveOperation.Start)
|
||||||
block = c.block()
|
block = c.block()
|
||||||
while block.isValid():
|
while block.isValid():
|
||||||
for r in block.layout().additionalFormats():
|
for r in block.layout().formats():
|
||||||
if r.format.property(SPELL_PROPERTY):
|
if r.format.property(SPELL_PROPERTY):
|
||||||
if not from_cursor or block.position() + r.start + r.length > c.position():
|
if not from_cursor or block.position() + r.start + r.length > c.position():
|
||||||
c.setPosition(block.position() + r.start)
|
c.setPosition(block.position() + r.start)
|
||||||
@ -730,7 +730,7 @@ class TextEdit(PlainTextEdit):
|
|||||||
c.movePosition(QTextCursor.MoveOperation.Start)
|
c.movePosition(QTextCursor.MoveOperation.Start)
|
||||||
block = c.block()
|
block = c.block()
|
||||||
while block.isValid():
|
while block.isValid():
|
||||||
for r in block.layout().additionalFormats():
|
for r in block.layout().formats():
|
||||||
if r.format.property(SPELL_PROPERTY) and self.text_for_range(block, r) == word:
|
if r.format.property(SPELL_PROPERTY) and self.text_for_range(block, r) == word:
|
||||||
self.highlighter.reformat_block(block)
|
self.highlighter.reformat_block(block)
|
||||||
break
|
break
|
||||||
@ -741,7 +741,7 @@ class TextEdit(PlainTextEdit):
|
|||||||
if cursor.isNull():
|
if cursor.isNull():
|
||||||
return
|
return
|
||||||
pos = cursor.positionInBlock()
|
pos = cursor.positionInBlock()
|
||||||
for r in cursor.block().layout().additionalFormats():
|
for r in cursor.block().layout().formats():
|
||||||
if r.start <= pos <= r.start + r.length and r.format.property(SYNTAX_PROPERTY):
|
if r.start <= pos <= r.start + r.length and r.format.property(SYNTAX_PROPERTY):
|
||||||
return r
|
return r
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user