⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qtextdocument.cpp

📁 qt-x11-opensource-src-4.1.4.tar.gz源码
💻 CPP
📖 第 1 页 / 共 4 页
字号:
*/bool QTextDocument::isUndoAvailable() const{    Q_D(const QTextDocument);    return d->isUndoAvailable();}/*!    Returns true is redo is available; otherwise returns false.*/bool QTextDocument::isRedoAvailable() const{    Q_D(const QTextDocument);    return d->isRedoAvailable();}/*!    Sets the document to use the given \a layout. The previous layout    is deleted.*/void QTextDocument::setDocumentLayout(QAbstractTextDocumentLayout *layout){    Q_D(QTextDocument);    d->setLayout(layout);}/*!    Returns the document layout for this document.*/QAbstractTextDocumentLayout *QTextDocument::documentLayout() const{    Q_D(const QTextDocument);    if (!d->lout) {        QTextDocument *that = const_cast<QTextDocument *>(this);        that->d_func()->setLayout(new QTextDocumentLayout(that));    }    return d->lout;}/*!    Returns meta information about the document of the type specified by    \a info.    \sa setMetaInformation()*/QString QTextDocument::metaInformation(MetaInformation info) const{    if (info != DocumentTitle)        return QString();    Q_D(const QTextDocument);    return d->config()->title;}/*!    Sets the document's meta information of the type specified by \a info    to the given \a string.    \sa metaInformation()*/void QTextDocument::setMetaInformation(MetaInformation info, const QString &string){    if (info != DocumentTitle)        return;    Q_D(QTextDocument);    d->config()->title = string;}/*!    Returns the plain text contained in the document. If you want    formatting information use a QTextCursor instead.    \sa toHtml()*/QString QTextDocument::toPlainText() const{    Q_D(const QTextDocument);    QString txt = d->plainText();    txt.replace(QTextBeginningOfFrame, '\n');    txt.replace(QTextEndOfFrame, '\n');    txt.replace(QChar::ParagraphSeparator, '\n');    txt.replace(QChar::LineSeparator, '\n');    txt.replace(QChar::Nbsp, ' ');    return txt;}/*!    Replaces the entire contents of the document with the given plain    \a text.    \sa setHtml()*/void QTextDocument::setPlainText(const QString &text){    Q_D(QTextDocument);    setUndoRedoEnabled(false);    d->clear();    QTextCursor(this).insertText(text);    setUndoRedoEnabled(true);}/*!    Replaces the entire contents of the document with the given    HTML-formatted text in the \a html string.    The HTML formatting is respected as much as possible; for example,    "<b>bold</b> text" will produce text where the first word has a font    weight that gives it a bold appearance: "\bold{bold} text".    \sa setPlainText(), {Supported HTML Subset}*/void QTextDocument::setHtml(const QString &html){    Q_D(QTextDocument);    setUndoRedoEnabled(false);    d->clear();    QTextHtmlImporter(this, html).import();    setUndoRedoEnabled(true);}/*!    \enum QTextDocument::FindFlag    This enum describes the options available to QTextDocument's find function. The options    can be OR-red together from the following list:    \value FindBackward    \value FindCaseSensitively By default find works case insensitive. Specifying this option    changes the behaviour to a case sensitive find operation.    \value FindWholeWords Makes find match only complete words.*//*!    \enum QTextDocument::MetaInformation    This enum describes the different types of meta information that can be    added to a document.    \value DocumentTitle    The title of the document.    \sa metaInformation(), setMetaInformation()*/static bool findInBlock(const QTextBlock &block, const QString &text, const QString &expression, int offset,                        QTextDocument::FindFlags options, QTextCursor &cursor){    const Qt::CaseSensitivity cs = (options & QTextDocument::FindCaseSensitively) ? Qt::CaseSensitive : Qt::CaseInsensitive;    const int idx = (options & QTextDocument::FindBackward) ?                    text.lastIndexOf(expression, offset, cs) : text.indexOf(expression, offset, cs);    if (idx == -1)        return false;    if (options & QTextDocument::FindWholeWords) {        const int start = idx;        const int end = start + expression.length();        if ((start != 0 && text.at(start - 1).isLetterOrNumber())                || (end != text.length() && text.at(end).isLetterOrNumber()))            return false;    }    cursor = QTextCursor(block.docHandle(), block.position() + idx);    cursor.setPosition(cursor.position() + expression.length(), QTextCursor::KeepAnchor);    return true;}/*!    \fn QTextCursor QTextDocument::find(const QString &expr, int position, FindFlags options) const    \overload    Finds the next occurrence of the string, \a expr, in the document.    The search starts at the given \a position, and proceeds forwards    through the document unless specified otherwise in the search options.    The \a options control the type of search performed.    Returns a cursor with the match selected if \a expr was found; otherwise    returns a null cursor.    If the \a position is 0 (the default) the search begins from the beginning    of the document; otherwise it begins at the specified position.*/QTextCursor QTextDocument::find(const QString &expr, int from, FindFlags options) const{    Q_D(const QTextDocument);    if (expr.isEmpty())        return QTextCursor();    int pos = from;    QTextCursor cursor;    QTextBlock block = d->blocksFind(pos);    if (!(options & FindBackward)) {        while (block.isValid()) {            int blockOffset = qMax(0, pos - block.position());            const QString blockText = block.text();            const int blockLength = block.length();            while (blockOffset < blockLength) {                if (findInBlock(block, blockText, expr, blockOffset, options, cursor))                    return cursor;                blockOffset += expr.length();            }            block = block.next();        }    } else {        while (block.isValid()) {            int blockOffset = pos - block.position() - expr.size() - 1;            if (blockOffset > block.length())                blockOffset = block.length() - 1;            const QString blockText = block.text();            while (blockOffset >= 0) {                if (findInBlock(block, blockText, expr, blockOffset, options, cursor))                    return cursor;                blockOffset -= expr.length();            }            block = block.previous();        }    }    return QTextCursor();}/*!    \fn QTextCursor QTextDocument::find(const QString &expr, const QTextCursor &cursor, FindFlags options) const    Finds the next occurrence of the string, \a expr, in the document.    The search starts at the position of the given \a cursor, and proceeds    forwards through the document unless specified otherwise in the search    options. The \a options control the type of search performed.    Returns a cursor with the match selected if \a expr was found; otherwise    returns a null cursor.    If the given \a cursor has a selection, the search begins after the    selection; otherwise it begins at the cursor's position.    By default the search is case-sensitive, and can match text anywhere in the    document.*/QTextCursor QTextDocument::find(const QString &expr, const QTextCursor &from, FindFlags options) const{    const int pos = (from.isNull() ? 0 : from.selectionEnd());    return find(expr, pos, options);}/*!    \fn QTextObject *QTextDocument::createObject(const QTextFormat &format)    Creates and returns a new document object (a QTextObject), based    on the given \a format.    QTextObjects will always get created through this method, so you    must reimplement it if you use custom text objects inside your document.*/QTextObject *QTextDocument::createObject(const QTextFormat &f){    QTextObject *obj = 0;    if (f.isListFormat())        obj = new QTextList(this);    else if (f.isTableFormat())        obj = new QTextTable(this);    else if (f.isFrameFormat())        obj = new QTextFrame(this);    return obj;}/*!    \internal    Returns the frame that contains the text cursor position \a pos.*/QTextFrame *QTextDocument::frameAt(int pos) const{    Q_D(const QTextDocument);    return d->frameAt(pos);}/*!    Returns the document's root frame.*/QTextFrame *QTextDocument::rootFrame() const{    Q_D(const QTextDocument);    return d->rootFrame();}/*!    Returns the text object associated with the given \a objectIndex.*/QTextObject *QTextDocument::object(int objectIndex) const{    Q_D(const QTextDocument);    return d->objectForIndex(objectIndex);}/*!    Returns the text object associated with the format \a f.*/QTextObject *QTextDocument::objectForFormat(const QTextFormat &f) const{    Q_D(const QTextDocument);    return d->objectForFormat(f);}/*!    Returns the text block that contains the \a{pos}-th character.*/QTextBlock QTextDocument::findBlock(int pos) const{    Q_D(const QTextDocument);    return QTextBlock(docHandle(), d->blockMap().findNode(pos));}/*!    Returns the document's first text block.*/QTextBlock QTextDocument::begin() const{    Q_D(const QTextDocument);    return QTextBlock(docHandle(), d->blockMap().begin().n);}/*!    Returns the document's last text block.*/QTextBlock QTextDocument::end() const{    return QTextBlock(docHandle(), 0);}/*!    \property QTextDocument::pageSize    \brief the page size that should be used for layouting the document    \sa modificationChanged()*/void QTextDocument::setPageSize(const QSizeF &size){    Q_D(QTextDocument);    d->pageSize = size;    documentLayout()->documentChanged(0, 0, d->length());}QSizeF QTextDocument::pageSize() const{    Q_D(const QTextDocument);    return d->pageSize;}/*!  returns the number of pages in this document.*/int QTextDocument::pageCount() const{    return documentLayout()->pageCount();}/*!    Sets the default \a font to use in the document layout.*/void QTextDocument::setDefaultFont(const QFont &font){    Q_D(QTextDocument);    d->setDefaultFont(font);    documentLayout()->documentChanged(0, 0, d->length());}/*!    Returns the default font to be used in the document layout.*/QFont QTextDocument::defaultFont() const{    Q_D(const QTextDocument);    return d->defaultFont();}/*!    \fn QTextDocument::modificationChanged(bool changed)    This signal is emitted whenever the content of the document    changes in a way that affects the modification state. If \a    changed is true, the document has been modified; otherwise it is    false.    For example, calling setModified(false) on a document and then    inserting text causes the signal to get emitted. If you undo that    operation, causing the document to return to its original    unmodified state, the signal will get emitted again.*//*!    \property QTextDocument::modified    \brief whether the document has been modified by the user    \sa modificationChanged()*/bool QTextDocument::isModified() const{    return docHandle()->isModified();}void QTextDocument::setModified(bool m){    docHandle()->setModified(m);}#ifndef QT_NO_PRINTERstatic void printPage(int index, QPainter *painter, const QTextDocument *doc, const QRectF &body, const QPointF &pageNumberPos){    painter->save();    painter->translate(body.left(), body.top() - (index - 1) * body.height());    QRectF view(0, (index - 1) * body.height(), body.width(), body.height());    QAbstractTextDocumentLayout *layout = doc->documentLayout();    QAbstractTextDocumentLayout::PaintContext ctx;    painter->setClipRect(view);    ctx.clip = view;        // don't use the system palette text as default text color, on HP/UX    // for example that's white, and white text on white paper doesn't    // look that nice    ctx.palette.setColor(QPalette::Text, Qt::black);    layout->draw(painter, ctx);    if (!pageNumberPos.isNull()) {        painter->setClipping(false);        painter->setFont(QFont(doc->defaultFont()));        const QString pageString = QString::number(index);        painter->drawText(qRound(pageNumberPos.x() - painter->fontMetrics().width(pageString)),                          qRound(pageNumberPos.y() + view.top()),                          pageString);    }    painter->restore();}/*!    Prints the document to the given \a printer. The QPrinter must be    set up before being used with this function.    This is only a convenience method to print the whole document to the printer.*/void QTextDocument::print(QPrinter *printer) const{    Q_D(const QTextDocument);    QPainter p(printer);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -