mirror of
git://github.com/kovidgoyal/calibre.git
synced 2026-05-09 07:33:12 +02:00
Replace QTextLayouts::*additionalFormats methods
This commit is contained in:
parent
ecc3608a3f
commit
c242528a63
5 changed files with 12 additions and 12 deletions
|
|
@ -138,7 +138,7 @@ def __init__(self, text='', width=0, font=None, img=None, max_height=100, align=
|
|||
for text in text.split('<br>') if text else ():
|
||||
text, formats = parse_text_formatting(sanitize(text))
|
||||
l = QTextLayout(unescape_formatting(text), font, img)
|
||||
l.setAdditionalFormats(formats)
|
||||
l.setFormats(formats)
|
||||
to = QTextOption(align)
|
||||
to.setWrapMode(QTextOption.WrapMode.WrapAtWordBoundaryOrAnywhere)
|
||||
l.setTextOption(to)
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ def copy_lines(self, lo, hi, cursor):
|
|||
dest_block = cursor.block()
|
||||
c = QTextCursor(dest_block)
|
||||
try:
|
||||
afs = block.layout().additionalFormats()
|
||||
afs = block.layout().formats()
|
||||
except AttributeError:
|
||||
afs = ()
|
||||
for af in afs:
|
||||
|
|
|
|||
|
|
@ -160,9 +160,9 @@ def __init__(self, right=False, parent=None, show_open_in_editor=False):
|
|||
setattr(self, '%s_format' % x, f)
|
||||
|
||||
def calculate_metrics(self):
|
||||
w = self.fontMetrics()
|
||||
self.number_width = max(map(lambda x:w.width(str(x)), range(10)))
|
||||
self.space_width = w.width(' ')
|
||||
fm = self.fontMetrics()
|
||||
self.number_width = max(map(lambda x:fm.horizontalAdvance(str(x)), range(10)))
|
||||
self.space_width = fm.horizontalAdvance(' ')
|
||||
|
||||
def show_context_menu(self, pos):
|
||||
m = QMenu(self)
|
||||
|
|
@ -879,7 +879,7 @@ def do_tag(block, words, lo, hi, pos, fmts):
|
|||
for word in words[lo:hi]:
|
||||
if word == '\n':
|
||||
if fmts:
|
||||
block.layout().setAdditionalFormats(fmts)
|
||||
block.layout().setFormats(fmts)
|
||||
pos, block, fmts = 0, block.next(), []
|
||||
continue
|
||||
|
||||
|
|
@ -897,7 +897,7 @@ def do_tag(block, words, lo, hi, pos, fmts):
|
|||
rsb, rpos, rfmts = do_tag(rsb, rl, rlo, rhi, rpos, rfmts)
|
||||
for block, fmts in ((lsb, lfmts), (rsb, rfmts)):
|
||||
if fmts:
|
||||
block.layout().setAdditionalFormats(fmts)
|
||||
block.layout().setFormats(fmts)
|
||||
# }}}
|
||||
|
||||
# }}}
|
||||
|
|
|
|||
|
|
@ -95,7 +95,7 @@ def set_document(self, doc, doc_name=None):
|
|||
c.beginEditBlock()
|
||||
blk = old_doc.begin()
|
||||
while blk.isValid():
|
||||
blk.layout().clearAdditionalFormats()
|
||||
blk.layout().clearFormats()
|
||||
blk = blk.next()
|
||||
c.endEditBlock()
|
||||
self.doc = self.doc_name = None
|
||||
|
|
@ -237,4 +237,4 @@ def apply_format_changes(self, block, formats):
|
|||
r.start += preedit_length
|
||||
elif r.start + r.length >= preedit_start:
|
||||
r.length += preedit_length
|
||||
layout.setAdditionalFormats(formats)
|
||||
layout.setFormats(formats)
|
||||
|
|
|
|||
|
|
@ -566,7 +566,7 @@ def find_next_spell_error(self, from_cursor=True):
|
|||
c.movePosition(QTextCursor.MoveOperation.Start)
|
||||
block = c.block()
|
||||
while block.isValid():
|
||||
for r in block.layout().additionalFormats():
|
||||
for r in block.layout().formats():
|
||||
if r.format.property(SPELL_PROPERTY):
|
||||
if not from_cursor or block.position() + r.start + r.length > c.position():
|
||||
c.setPosition(block.position() + r.start)
|
||||
|
|
@ -730,7 +730,7 @@ def recheck_word(self, word, locale):
|
|||
c.movePosition(QTextCursor.MoveOperation.Start)
|
||||
block = c.block()
|
||||
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:
|
||||
self.highlighter.reformat_block(block)
|
||||
break
|
||||
|
|
@ -741,7 +741,7 @@ def syntax_range_for_cursor(self, cursor):
|
|||
if cursor.isNull():
|
||||
return
|
||||
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):
|
||||
return r
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue