Esempio n. 1
0
 def do_format_block(self):
     name = self.sender().block_name
     with self.editing_cursor() as c:
         bf = QTextBlockFormat()
         cf = QTextCharFormat()
         bcf = c.blockCharFormat()
         lvl = self.level_for_block_type(name)
         wt = QFont.Weight.Bold if lvl else None
         adjust = (0, 3, 2, 1, 0, -1, -1)[lvl]
         pos = None
         if not c.hasSelection():
             pos = c.position()
             c.movePosition(QTextCursor.MoveOperation.StartOfBlock,
                            QTextCursor.MoveMode.MoveAnchor)
             c.movePosition(QTextCursor.MoveOperation.EndOfBlock,
                            QTextCursor.MoveMode.KeepAnchor)
         # margin values are taken from qtexthtmlparser.cpp
         hmargin = 0
         if name == 'blockquote':
             hmargin = 40
         tmargin = bmargin = 12
         if name == 'h1':
             tmargin, bmargin = 18, 12
         elif name == 'h2':
             tmargin, bmargin = 16, 12
         elif name == 'h3':
             tmargin, bmargin = 14, 12
         elif name == 'h4':
             tmargin, bmargin = 12, 12
         elif name == 'h5':
             tmargin, bmargin = 12, 4
         bf.setLeftMargin(hmargin), bf.setRightMargin(hmargin)
         bf.setTopMargin(tmargin), bf.setBottomMargin(bmargin)
         bf.setHeadingLevel(lvl)
         if adjust:
             bcf.setProperty(QTextFormat.Property.FontSizeAdjustment,
                             adjust)
             cf.setProperty(QTextFormat.Property.FontSizeAdjustment, adjust)
         if wt:
             bcf.setProperty(QTextFormat.Property.FontWeight, wt)
             cf.setProperty(QTextFormat.Property.FontWeight, wt)
         c.setBlockCharFormat(bcf)
         c.mergeCharFormat(cf)
         c.mergeBlockFormat(bf)
         if pos is not None:
             c.setPosition(pos)
     self.update_cursor_position_actions()
Esempio n. 2
0
def syntax_text_char_format(*args):
    ans = QTextCharFormat(*args)
    ans.setProperty(SYNTAX_PROPERTY, True)
    return ans
Esempio n. 3
0
def spell_property(sfmt, locale):
    s = QTextCharFormat(sfmt)
    s.setProperty(SPELL_LOCALE_PROPERTY, locale)
    return s