Beispiel #1
0
 def printEntry(self, match, term, pages, notes):
     if match.field is SearchFieldKind.TERM:
         text = term
     elif match.field is SearchFieldKind.PAGES:
         text = pages
     elif match.field is SearchFieldKind.NOTES:
         text = notes
     doc = QTextDocument()
     doc.setHtml(text)
     print("{: 3d}: [{}]".format(match.eid, doc.toPlainText()))
Beispiel #2
0
    def sizeHint(self, option, index):
        """QStyledItemDelegate.sizeHint implementation
        """
        options = QStyleOptionViewItemV4(option)
        self.initStyleOption(options,index)

        doc = QTextDocument()
        doc.setDocumentMargin(1)
        #  bad long (multiline) strings processing doc.setTextWidth(options.rect.width())
        doc.setHtml(options.text)
        return QSize(doc.idealWidth(), doc.size().height())
Beispiel #3
0
 def find(self, backwards=False):
     options = QTextDocument.FindFlags()
     if self.searchCaseSensitive.isChecked():
         options |= QTextDocument.FindCaseSensitively
     if backwards:
         options |= QTextDocument.FindBackward
     if not self.editor.find(self.searchLine.text(), options):
         self.searchLine.setStyleSheet('QLineEdit {background: yellow}')
     else:
         self.searchLine.setStyleSheet('')
Beispiel #4
0
    def paint(self, painter, option, index):
        """QStyledItemDelegate.paint implementation
        """
        option.state &= ~QStyle.State_HasFocus  # never draw focus rect
        
        options = QStyleOptionViewItemV4(option)
        self.initStyleOption(options,index)

        style = QApplication.style() if options.widget is None else options.widget.style()

        doc = QTextDocument()
        doc.setDocumentMargin(1)
        doc.setHtml(options.text)
        if options.widget is not None:
            doc.setDefaultFont(options.widget.font())
        #  bad long (multiline) strings processing doc.setTextWidth(options.rect.width())

        options.text = ""
        style.drawControl(QStyle.CE_ItemViewItem, options, painter)

        ctx = QAbstractTextDocumentLayout.PaintContext()

        # Highlighting text if item is selected
        if option.state & QStyle.State_Selected:
            ctx.palette.setColor(QPalette.Text, option.palette.color(QPalette.Active, QPalette.HighlightedText))

        textRect = style.subElementRect(QStyle.SE_ItemViewItemText, options)
        painter.save()
        painter.translate(textRect.topLeft())
        """Original example contained line
            painter.setClipRect(textRect.translated(-textRect.topLeft()))
        but text is drawn clipped with it on kubuntu 12.04
        """
        doc.documentLayout().draw(painter, ctx)

        painter.restore()
Beispiel #5
0
def output(config, document):
    p = (
        """<p style="font-family: '{family}'; font-size: {size}pt;">""".format(
            family=config.StdFont, size=config.StdFontSize))
    pad = lambda match: p + (int(match.group("level")) * 4 * "&nbsp;")
    doc = QTextDocument()
    doc.setHtml(INDENT_RX.sub(pad, document))
    printer = getattr(config, "Printer", None)
    if printer is None:
        printer = QPrinter(QPrinter.HighResolution)
        printer.setCreator("{} {}".format(QApplication.applicationName(),
                                          QApplication.applicationVersion()))
        printer.setOutputFormat(QPrinter.PdfFormat)
        printer.setOrientation(QPrinter.Portrait)
        settings = QSettings()
        size = PaperSizeKind(
            int(settings.value(Gopt.Key.PaperSize, Gopt.Default.PaperSize)))
        printer.setPaperSize(
            QPrinter.A4 if size is PaperSizeKind.A4 else QPrinter.Letter)
        printer.setOutputFileName(config.Filename)
    doc.print_(printer)
Beispiel #6
0
    def testUndoRedo(self):
        text = 'foobar'
        doc = QTextDocument(text)

        self.assertFalse(doc.isRedoAvailable())
        self.assertTrue(doc.isUndoAvailable())
        self.assertEqual(doc.toPlainText(), text)

        cursor = QTextCursor(doc)
        doc.undo(cursor)

        self.assertTrue(doc.isRedoAvailable())
        self.assertFalse(doc.isUndoAvailable())
        self.assertEqual(doc.toPlainText(), '')

        doc.redo(cursor)

        self.assertFalse(doc.isRedoAvailable())
        self.assertTrue(doc.isUndoAvailable())
        self.assertEqual(doc.toPlainText(), text)
Beispiel #7
0
    def make_page(self, html):
        page = QTextDocument()
        page.setHtml(html)

        self.pages.append(page)
    def testUndoRedo(self):
        text = 'foobar'
        doc = QTextDocument(text)

        self.assertFalse(doc.isRedoAvailable())
        self.assertTrue(doc.isUndoAvailable())
        self.assertEqual(doc.toPlainText(), text)

        cursor = QTextCursor(doc)
        doc.undo(cursor)

        self.assertTrue(doc.isRedoAvailable())
        self.assertFalse(doc.isUndoAvailable())
        self.assertEqual(doc.toPlainText(), '')

        doc.redo(cursor)

        self.assertFalse(doc.isRedoAvailable())
        self.assertTrue(doc.isUndoAvailable())
        self.assertEqual(doc.toPlainText(), text)