From c242528a63e3361a02f1d5892b0b036c55839551 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 21 Nov 2021 18:33:39 +0530 Subject: [PATCH] Replace QTextLayouts::*additionalFormats methods --- src/calibre/ebooks/covers.py | 2 +- src/calibre/gui2/tweak_book/diff/highlight.py | 2 +- src/calibre/gui2/tweak_book/diff/view.py | 10 +++++----- src/calibre/gui2/tweak_book/editor/syntax/base.py | 4 ++-- src/calibre/gui2/tweak_book/editor/text.py | 6 +++--- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/calibre/ebooks/covers.py b/src/calibre/ebooks/covers.py index b673a54ac1..af9ff00054 100644 --- a/src/calibre/ebooks/covers.py +++ b/src/calibre/ebooks/covers.py @@ -138,7 +138,7 @@ def __init__(self, text='', width=0, font=None, img=None, max_height=100, align= for text in text.split('
') 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) diff --git a/src/calibre/gui2/tweak_book/diff/highlight.py b/src/calibre/gui2/tweak_book/diff/highlight.py index 51878363da..ff758a38d5 100644 --- a/src/calibre/gui2/tweak_book/diff/highlight.py +++ b/src/calibre/gui2/tweak_book/diff/highlight.py @@ -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: diff --git a/src/calibre/gui2/tweak_book/diff/view.py b/src/calibre/gui2/tweak_book/diff/view.py index 0580f30a9e..61b46921c0 100644 --- a/src/calibre/gui2/tweak_book/diff/view.py +++ b/src/calibre/gui2/tweak_book/diff/view.py @@ -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) # }}} # }}} diff --git a/src/calibre/gui2/tweak_book/editor/syntax/base.py b/src/calibre/gui2/tweak_book/editor/syntax/base.py index 40cb80f45a..150b40af9a 100644 --- a/src/calibre/gui2/tweak_book/editor/syntax/base.py +++ b/src/calibre/gui2/tweak_book/editor/syntax/base.py @@ -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) diff --git a/src/calibre/gui2/tweak_book/editor/text.py b/src/calibre/gui2/tweak_book/editor/text.py index b95ba71c82..1f613516a4 100644 --- a/src/calibre/gui2/tweak_book/editor/text.py +++ b/src/calibre/gui2/tweak_book/editor/text.py @@ -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