📄 qtextdocument.cpp
字号:
*/void QTextDocument::redo(){ Q_D(QTextDocument); d->undoRedo(false);}/*! \internal Appends a custom undo \a item to the undo stack.*/void QTextDocument::appendUndoItem(QAbstractUndoItem *item){ Q_D(QTextDocument); d->appendUndoItem(item);}/*! \property QTextDocument::undoRedoEnabled \brief whether undo/redo are enabled for this document This defaults to true. If disabled, the undo stack is cleared and no items will be added to it.*/void QTextDocument::setUndoRedoEnabled(bool enable){ Q_D(QTextDocument); d->enableUndoRedo(enable);}bool QTextDocument::isUndoRedoEnabled() const{ Q_D(const QTextDocument); return d->isUndoRedoEnabled();}/*! \property QTextDocument::maximumBlockCount \since 4.2 \brief Specifies the limit for blocks in the document. Specifies the maximum number of blocks the document may have. If there are more blocks in the document that specified with this property blocks are removed from the beginning of the document. A negative or zero value specifies that the document may contain an unlimited amount of blocks. The default value is 0. Note that setting this property will apply the limit immediately to the document contents. Setting this property also disables the undo redo history. This property is undefined in documents with tables or frames.*/int QTextDocument::maximumBlockCount() const{ Q_D(const QTextDocument); return d->maximumBlockCount;}void QTextDocument::setMaximumBlockCount(int maximum){ Q_D(QTextDocument); d->maximumBlockCount = maximum; d->ensureMaximumBlockCount(); setUndoRedoEnabled(false);}/*! \since 4.3 The default text option is used on all QTextLayout objects in the document. This allows setting global properties for the document such as the default word wrap mode.*/QTextOption QTextDocument::defaultTextOption() const{ Q_D(const QTextDocument); return d->defaultTextOption;}/*! \since 4.3 Sets the default text option.*/void QTextDocument::setDefaultTextOption(const QTextOption &option){ Q_D(QTextDocument); d->defaultTextOption = option; if (d->lout) d->lout->documentChanged(0, 0, d->length());}/*! \fn void QTextDocument::markContentsDirty(int position, int length) Marks the contents specified by the given \a position and \a length as "dirty", informing the document that it needs to be laid out again.*/void QTextDocument::markContentsDirty(int from, int length){ Q_D(QTextDocument); if (!d->inContentsChange) d->beginEditBlock(); d->documentChange(from, length); if (!d->inContentsChange) d->endEditBlock();}/*! \property QTextDocument::useDesignMetrics \since 4.1*/void QTextDocument::setUseDesignMetrics(bool b){ Q_D(QTextDocument); d->defaultTextOption.setUseDesignMetrics(b); if (d->lout) d->lout->documentChanged(0, 0, d->length());}bool QTextDocument::useDesignMetrics() const{ Q_D(const QTextDocument); return d->defaultTextOption.useDesignMetrics();}/*! \since 4.2 Draws the content of the document with painter \a p, clipped to \a rect. If \a rect is a null rectangle (default) then the document is painted unclipped.*/void QTextDocument::drawContents(QPainter *p, const QRectF &rect){ p->save(); QAbstractTextDocumentLayout::PaintContext ctx; if (rect.isValid()) { p->setClipRect(rect); ctx.clip = rect; } documentLayout()->draw(p, ctx); p->restore();}/*! \property QTextDocument::textWidth \since 4.2 The text width specifies the preferred width for text in the document. If the text (or content in general) is wider than the specified with it is broken into multiple lines and grows vertically. If the text cannot be broken into multiple lines to fit into the specified text width it will be larger and the size() and the idealWidth() property will reflect that. If the text width is set to -1 then the text will not be broken into multiple lines unless it is enforced through an explicit line break or a new paragraph. The default value is -1. Setting the text width will also set the page height to -1, causing the document to grow or shrink vertically in a continuous way. If you want the document layout to break the text into multiple pages then you have to set the pageSize property instead. \sa size(), idealWidth(), pageSize()*/void QTextDocument::setTextWidth(qreal width){ Q_D(QTextDocument); QSizeF sz = d->pageSize; sz.setWidth(width); sz.setHeight(-1); setPageSize(sz);}qreal QTextDocument::textWidth() const{ Q_D(const QTextDocument); return d->pageSize.width();}/*! \since 4.2 Returns the ideal width of the text document. The ideal width is the actually used width of the document without optional alignments taken into account. It is always <= size().width(). \sa adjustSize(), textWidth*/qreal QTextDocument::idealWidth() const{ if (QTextDocumentLayout *lout = qobject_cast<QTextDocumentLayout *>(documentLayout())) return lout->idealWidth(); return textWidth();}/*! \since 4.2 Adjusts the document to a reasonable size. \sa idealWidth(), textWidth, size*/void QTextDocument::adjustSize(){ // Pull this private function in from qglobal.cpp Q_CORE_EXPORT unsigned int qt_int_sqrt(unsigned int n); QFont f = defaultFont(); QFontMetrics fm(f); int mw = fm.width(QLatin1Char('x')) * 80; int w = mw; setTextWidth(w); QSizeF size = documentLayout()->documentSize(); if (size.width() != 0) { w = qt_int_sqrt((uint)(5 * size.height() * size.width() / 3)); setTextWidth(qMin(w, mw)); size = documentLayout()->documentSize(); if (w*3 < 5*size.height()) { w = qt_int_sqrt((uint)(2 * size.height() * size.width())); setTextWidth(qMin(w, mw)); } } setTextWidth(idealWidth());}/*! \property QTextDocument::size \since 4.2 Returns the actual size of the document. This is equivalent to documentLayout()->documentSize(); The size of the document can be changed either by setting a text width or setting an entire page size. Note that the width is always >= pageSize().width(). \sa setTextWidth(), setPageSize(), idealWidth()*/QSizeF QTextDocument::size() const{ return documentLayout()->documentSize();}/*! \property QTextDocument::blockCount \since 4.2 Returns the number of text blocks in the document. The value of this property is undefined in documents with tables or frames.*/int QTextDocument::blockCount() const{ Q_D(const QTextDocument); return d->blockMap().numNodes();}/*! \property QTextDocument::defaultStyleSheet \since 4.2 The default style sheet is applied to all newly HTML formatted text that is inserted into the document, for example using setHtml() or QTextCursor::insertHtml(). The style sheet needs to be compliant to CSS 2.1 syntax. \bold{Note:} Changing the default style sheet does not have any effect to the existing content of the document. \sa {Supported HTML Subset}*/void QTextDocument::setDefaultStyleSheet(const QString &sheet){ Q_D(QTextDocument); d->defaultStyleSheet = sheet; QCss::Parser parser(sheet); d->parsedDefaultStyleSheet = QCss::StyleSheet(); parser.parse(&d->parsedDefaultStyleSheet);}QString QTextDocument::defaultStyleSheet() const{ Q_D(const QTextDocument); return d->defaultStyleSheet;}/*! \fn void QTextDocument::contentsChanged() This signal is emitted whenever the document's content changes; for example, when text is inserted or deleted, or when formatting is applied. \sa contentsChange()*//*! \fn void QTextDocument::contentsChange(int position, int charsRemoved, int charsAdded) This signal is emitted whenever the document's content changes; for example, when text is inserted or deleted, or when formatting is applied. Information is provided about the \a position of the character in the document where the change occurred, the number of characters removed (\a charsRemoved), and the number of characters added (\a charsAdded). The signal is emitted before the document's layout manager is notified about the change. This hook allows you to implement syntax highlighting for the document. \sa QAbstractTextDocumentLayout::documentChanged(), contentsChanged()*//*! \fn QTextDocument::undoAvailable(bool available); This signal is emitted whenever undo operations become available (\a available is true) or unavailable (\a available is false). See the \l {Overview of Qt's Undo Framework}{Qt Undo Framework} documentation for details. \sa undo(), isUndoRedoEnabled()*//*! \fn QTextDocument::redoAvailable(bool available); This signal is emitted whenever redo operations become available (\a available is true) or unavailable (\a available is false).*//*! \fn QTextDocument::cursorPositionChanged(const QTextCursor &cursor); This signal is emitted whenever the position of a cursor changed due to an editing operation. The cursor that changed is passed in \a cursor. If you need a signal when the cursor is moved with the arrow keys you can use the \l{QTextEdit::}{cursorPositionChanged()} signal in QTextEdit.*//*! \fn QTextDocument::blockCountChanged(int newBlockCount); \since 4.3 This signal is emitted when the total number of text blocks in the document changes. The value passed in \a newBlockCount is the new total.*//*! Returns true if undo is available; otherwise returns false.*/bool QTextDocument::isUndoAvailable() const{ Q_D(const QTextDocument); return d->isUndoAvailable();}/*! Returns true if 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. Note that when setting a new layout for a QTextEdit you have to create a new QTextDocument first, set the new layout on it and then set the new document on QTextEdit.*/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->title;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -