示例#1
1
 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)
示例#2
0
    def hline(self):
        """
        Insert horizontal line
        """
        # Tag HR is not correctly displayed  in QTextview
        cur_char_fmt = self._text_edit_cursor.charFormat()
        cur_block_fmt = self._text_edit_cursor.blockFormat()
        if bool(self._text_edit_cursor.currentTable()):
            self._text_edit_cursor.insertBlock(cur_block_fmt, cur_char_fmt)

        block_fmt = QTextBlockFormat()
        block_fmt.setTopMargin(5)
        block_fmt.setBottomMargin(5)
        block_fmt.setAlignment(Qt.AlignLeft)
        block_fmt.setBackground(QBrush(QColor("#C1C1C1")))

        char_format = QTextCharFormat()
        char_format.setFont(QFont("Arial", 1))

        self._text_edit_cursor.insertBlock(block_fmt, char_format)
        self._text_edit_cursor.insertText(" ")

        self._text_edit_cursor.insertBlock(cur_block_fmt, cur_char_fmt)

        self.change(self._text_edit_cursor)
示例#3
0
    def text_align(self, horiz, vert):

        fmt = QTextBlockFormat()
        fmt.setAlignment(horiz)
        self._text_edit_cursor.mergeBlockFormat(fmt)

        if self.in_table():
            table = self._text_edit_cursor.currentTable()
            cell = table.cellAt(self._text_edit_cursor)
            cell_format = cell.format()
            cell_format.setVerticalAlignment(vert)
            cell.setFormat(cell_format)
示例#4
0
文件: __main__.py 项目: aaronschif/sp
    def __init__(self, controller):
        super().__init__()
        formc = QTextCharFormat()
        formc.setFontItalic(True)
        formc.setFontWeight(3)
        form = QTextBlockFormat()
        form.setLineHeight(200, 1)


        cur = self.textCursor()
        cur.insertText('', self.format_p)
        new_speech_signal = QObject()
        controller.speech.connect(self.new_speech_signal.emit)
        controller.speech.start()
        self.new_speech_signal.connect(cur.insertText)
示例#5
0
 def clear_format(self):
     txt = self._text.toPlainText()
     self._text_edit_cursor.beginEditBlock()  # ----  begin -------
     self._text_edit_cursor.select(QTextCursor.Document)
     self._text_edit_cursor.removeSelectedText()
     fmt = QTextBlockFormat()
     self._text_edit_cursor.setBlockFormat(fmt)
     self._text_edit_cursor.insertText(txt)
     self._text_edit_cursor.endEditBlock()  # ----  end ---------
示例#6
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)
示例#7
0
 def do_remove_format(self):
     with self.editing_cursor() as c:
         c.setBlockFormat(QTextBlockFormat())
         c.setCharFormat(QTextCharFormat())
示例#8
0
 def do_alignment(self, which):
     with self.editing_cursor() as c:
         fmt = QTextBlockFormat()
         fmt.setAlignment(which)
         c.setBlockFormat(fmt)