Пример #1
0
 def do_alignment(self, which):
     with self.editing_cursor() as c:
         c = self.textCursor()
         fmt = QTextBlockFormat()
         fmt.setAlignment(which)
         c.mergeBlockFormat(fmt)
     self.update_cursor_position_actions()
Пример #2
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()
Пример #3
0
 def do_list(self, fmt):
     with self.editing_cursor() as c:
         ls = c.currentList()
         if ls is not None:
             lf = ls.format()
             if lf.style() == fmt:
                 c.setBlockFormat(QTextBlockFormat())
             else:
                 lf.setStyle(fmt)
                 ls.setFormat(lf)
         else:
             ls = c.createList(fmt)
Пример #4
0
 def do_remove_format(self):
     with self.editing_cursor() as c:
         c.setBlockFormat(QTextBlockFormat())
         c.setCharFormat(QTextCharFormat())
Пример #5
0
 def do_remove_format(self):
     with self.editing_cursor() as c:
         c.setBlockFormat(QTextBlockFormat())
         c.setCharFormat(QTextCharFormat())
     self.update_cursor_position_actions()