diff options
Diffstat (limited to 'examples/opengl/legacy/framebufferobject2/main.cpp')
0 files changed, 0 insertions, 0 deletions
![]() |
index : qt/qtbase.git | |
| Qt Base (Core, Gui, Widgets, Network, ...) |
| summaryrefslogtreecommitdiffstats |
/****************************************************************************
**
** Copyright (C) 2019 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtGui module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 3 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL3 included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 3 requirements
** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 2.0 or (at your option) the GNU General
** Public license version 3 or any later version approved by the KDE Free
** Qt Foundation. The licenses are as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-2.0.html and
** https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "qtextdocument.h"
#include <qtextformat.h>
#include "qtextcursor_p.h"
#include "qtextdocumentlayout_p.h"
#include "qtextdocumentfragment.h"
#include "qtextdocumentfragment_p.h"
#include "qtexttable.h"
#include "qtextlist.h"
#include <qdebug.h>
#include <qregexp.h>
#if QT_CONFIG(regularexpression)
#include <qregularexpression.h>
#endif
#include <qvarlengtharray.h>
#if QT_CONFIG(textcodec)
#include <qtextcodec.h>
#endif
#include <qthread.h>
#include <qcoreapplication.h>
#include <qmetaobject.h>
#include "qtexthtmlparser_p.h"
#include "qpainter.h"
#include <qfile.h>
#include <qfileinfo.h>
#include <qdir.h>
#include "qfont_p.h"
#include "private/qdataurl_p.h"
#include "qtextdocument_p.h"
#include <private/qabstracttextdocumentlayout_p.h>
#include "qpagedpaintdevice.h"
#include "private/qpagedpaintdevice_p.h"
#if QT_CONFIG(textmarkdownreader)
#include <private/qtextmarkdownimporter_p.h>
#endif
#if QT_CONFIG(textmarkdownwriter)
#include <private/qtextmarkdownwriter_p.h>
#endif
#include <limits.h>
QT_BEGIN_NAMESPACE
Q_CORE_EXPORT Q_DECL_CONST_FUNCTION unsigned int qt_int_sqrt(unsigned int n);
/*!
Returns \c true if the string \a text is likely to be rich text;
otherwise returns \c false.
This function uses a fast and therefore simple heuristic. It
mainly checks whether there is something that looks like a tag
before the first line break. Although the result may be correct
for common cases, there is no guarantee.
This function is defined in the \c <QTextDocument> header file.
*/
bool Qt::mightBeRichText(const QString& text)
{
if (text.isEmpty())
return false;
int start = 0;
while (start < text.length() && text.at(start).isSpace())
++start;
// skip a leading <?xml ... ?> as for example with xhtml
if (text.midRef(start, 5).compare(QLatin1String("<?xml")) == 0) {
while (start < text.length()) {
if (text.at(start) == QLatin1Char('?')
&& start + 2 < text.length()
&& text.at(start + 1) == QLatin1Char('>')) {
start += 2;
break;
}
++start;
}
while (start < text.length() && text.at(start).isSpace())
++start;
}
if (text.midRef(start, 5).compare(QLatin1String("<!doc"), Qt::CaseInsensitive) == 0)
return true;
int open = start;
while (open < text.length() && text.at(open) != QLatin1Char('<')
&& text.at(open) != QLatin1Char('\n')) {
if (text.at(open) == QLatin1Char('&') && text.midRef(open + 1, 3) == QLatin1String("lt;"))
return true; // support desperate attempt of user to see <...>
++open;
}
if (open < text.length() && text.at(open) == QLatin1Char('<')) {
const int close = text.indexOf(QLatin1Char('>'), open);
if (close > -1) {
QString tag;
for (int i = open+1; i < close; ++i) {
if (text[i].isDigit() || text[i].isLetter())
tag += text[i];
else if (!tag.isEmpty() && text[i].isSpace())
break;
else if (!tag.isEmpty() && text[i] == QLatin1Char('/') && i + 1 == close)
break;
else if (!text[i].isSpace() && (!tag.isEmpty() || text[i] != QLatin1Char('!')))
return false; // that's not a tag
}
#ifndef QT_NO_TEXTHTMLPARSER
return QTextHtmlParser::lookupElement(std::move(tag).toLower()) != -1;
#else
return false;
#endif // QT_NO_TEXTHTMLPARSER
}
}
return false;
}
/*!
Converts the plain text string \a plain to an HTML-formatted
paragraph while preserving most of its look.
\a mode defines how whitespace is handled.
This function is defined in the \c <QTextDocument> header file.
\sa QString::toHtmlEscaped(), mightBeRichText()
*/
QString Qt::convertFromPlainText(const QString &plain, Qt::WhiteSpaceMode mode)
{
int col = 0;
QString rich;
rich += QLatin1String("<p>");
for (int i = 0; i < plain.length(); ++i) {
if (plain[i] == QLatin1Char('\n')){
int c = 1;
while (i+1 < plain.length() && plain[i+1] == QLatin1Char('\n')) {
i++;
c++;
}
if (c == 1)
rich += QLatin1String("<br>\n");
else {
rich += QLatin1String("</p>\n");
while (--c > 1)
rich += QLatin1String("<br>\n");
rich += QLatin1String("<p>");
}
col = 0;
} else {
if (mode == Qt::WhiteSpacePre && plain[i] == QLatin1Char('\t')){
rich += QChar(0x00a0U);
++col;
while (col % 8) {
rich += QChar(0x00a0U);
++col;
}
}
else if (mode == Qt::WhiteSpacePre && plain[i].isSpace())
rich += QChar(0x00a0U);
else if (plain[i] == QLatin1Char('<'))
rich += QLatin1String("<");
else if (plain[i] == QLatin1Char('>'))
rich += QLatin1String(">");
else if (plain[i] == QLatin1Char('&'))
rich += QLatin1String("&");
else
rich += plain[i];
++col;
}
}
if (col != 0)
rich += QLatin1String("</p>");
return rich;
}
/*!
\fn QTextCodec *Qt::codecForHtml(const QByteArray &ba)
\internal
This function is defined in the \c <QTextDocument> header file.
*/
#if QT_CONFIG(textcodec)
QTextCodec *Qt::codecForHtml(const QByteArray &ba)
{
return QTextCodec::codecForHtml(ba);
}
#endif
/*!
\class QTextDocument
\reentrant
\inmodule QtGui
\brief The QTextDocument class holds formatted text.
\ingroup richtext-processing
QTextDocument is a container for structured rich text documents, providing
support for styled text and various types of document elements, such as
lists, tables, frames, and images.
They can be created for use in a QTextEdit, or used independently.
Each document element is described by an associated format object. Each
format object is treated as a unique object by QTextDocuments, and can be
passed to objectForFormat() to obtain the document element that it is
applied to.
A QTextDocument can be edited programmatically using a QTextCursor, and
its contents can be examined by traversing the document structure. The
entire document structure is stored as a hierarchy of document elements
beneath the root frame, found with the rootFrame() function. Alternatively,
if you just want to iterate over the textual contents of the document you
can use begin(), end(), and findBlock() to retrieve text blocks that you
can examine and iterate over.
The layout of a document is determined by the documentLayout();
you can create your own QAbstractTextDocumentLayout subclass and
set it using setDocumentLayout() if you want to use your own
layout logic. The document's title and other meta-information can be
obtained by calling the metaInformation() function. For documents that
are exposed to users through the QTextEdit class, the document title
is also available via the QTextEdit::documentTitle() function.
The toPlainText() and toHtml() convenience functions allow you to retrieve the
contents of the document as plain text and HTML.
The document's text can be searched using the find() functions.
Undo/redo of operations performed on the document can be controlled using
the setUndoRedoEnabled() function. The undo/redo system can be controlled
by an editor widget through the undo() and redo() slots; the document also
provides contentsChanged(), undoAvailable(), and redoAvailable() signals
that inform connected editor widgets about the state of the undo/redo
system. The following are the undo/redo operations of a QTextDocument:
\list
\li Insertion or removal of characters. A sequence of insertions or removals
within the same text block are regarded as a single undo/redo operation.
\li Insertion or removal of text blocks. Sequences of insertion or removals
in a single operation (e.g., by selecting and then deleting text) are
regarded as a single undo/redo operation.
\li Text character format changes.
\li Text block format changes.
\li Text block group format changes.
\endlist
\sa QTextCursor, QTextEdit, {Rich Text Processing}, {Text Object Example}
*/
/*!
\property QTextDocument::defaultFont
\brief the default font used to display the document's text
*/
/*!
\property QTextDocument::defaultTextOption
\brief the default text option will be set on all \l{QTextLayout}s in the document.
When \l{QTextBlock}s are created, the defaultTextOption is set on their
QTextLayout. This allows setting global properties for the document such as the
default word wrap mode.
*/
/*!
Constructs an empty QTextDocument with the given \a parent.
*/
QTextDocument::QTextDocument(QObject *parent)
: QObject(*new QTextDocumentPrivate, parent)
{
Q_D(QTextDocument);
d->init();
}
/*!
Constructs a QTextDocument containing the plain (unformatted) \a text
specified, and with the given \a parent.
*/
QTextDocument::QTextDocument(const QString &text, QObject *parent)
: QObject(*new QTextDocumentPrivate, parent)
{
Q_D(QTextDocument);
d->init();
QTextCursor(this).insertText(text);
}
/*!
\internal
*/
QTextDocument::QTextDocument(QTextDocumentPrivate &dd, QObject *parent)
: QObject(dd, parent)
{
Q_D(QTextDocument);
d->init();
}
/*!
Destroys the document.
*/
QTextDocument::~QTextDocument()
{
}
/*!
Creates a new QTextDocument that is a copy of this text document. \a
parent is the parent of the returned text document.
*/
QTextDocument *QTextDocument::clone(QObject *parent) const
{
Q_D(const QTextDocument);
QTextDocument *doc = new QTextDocument(parent);
if (isEmpty()) {
const QTextCursor thisCursor(const_cast<QTextDocument *>(this));
const auto blockFormat = thisCursor.blockFormat();
if (blockFormat.isValid() && !blockFormat.isEmpty())
QTextCursor(doc).setBlockFormat(blockFormat);
const auto blockCharFormat = thisCursor.blockCharFormat();
if (blockCharFormat.isValid() && !blockCharFormat.isEmpty())
QTextCursor(doc).setBlockCharFormat(blockCharFormat);
} else {
QTextCursor(doc).insertFragment(QTextDocumentFragment(this));
}
doc->rootFrame()->setFrameFormat(rootFrame()->frameFormat());
QTextDocumentPrivate *priv = doc->d_func();
priv->title = d->title;
priv->url = d->url;
priv->pageSize = d->pageSize;
priv->indentWidth = d->indentWidth;
priv->defaultTextOption = d->defaultTextOption;
priv->setDefaultFont(d->defaultFont());
priv->resources = d->resources;
priv->cachedResources.clear();
#ifndef QT_NO_CSSPARSER
priv->defaultStyleSheet = d->defaultStyleSheet;
priv->parsedDefaultStyleSheet = d->parsedDefaultStyleSheet;
#endif
return doc;
}
/*!
Returns \c true if the document is empty; otherwise returns \c false.
*/
bool QTextDocument::isEmpty() const
{
Q_D(const QTextDocument);
/* because if we're empty we still have one single paragraph as
* one single fragment */
return d->length() <= 1;
}
/*!
Clears the document.
*/
void QTextDocument::clear()
{
Q_D(QTextDocument);
d->clear();
d->resources.clear();
}
/*!
\since 4.2
Undoes the last editing operation on the document if undo is
available. The provided \a cursor is positioned at the end of the
location where the edition operation was undone.
See the \l {Overview of Qt's Undo Framework}{Qt Undo Framework}
documentation for details.
\sa undoAvailable(), isUndoRedoEnabled()
*/
void QTextDocument::undo(QTextCursor *cursor)
{
Q_D(QTextDocument);
const int pos = d->undoRedo(true);
if (cursor && pos >= 0) {
*cursor = QTextCursor(this);
cursor->setPosition(pos);
}
}
/*!
\since 4.2
Redoes the last editing operation on the document if \l{QTextDocument::isRedoAvailable()}{redo is available}.
The provided \a cursor is positioned at the end of the location where
the edition operation was redone.
*/
void QTextDocument::redo(QTextCursor *cursor)
{
Q_D(QTextDocument);
const int pos = d->undoRedo(false);
if (cursor && pos >= 0) {
*cursor = QTextCursor(this);
cursor->setPosition(pos);
}
}
/*! \enum QTextDocument::Stacks
\value UndoStack The undo stack.
\value RedoStack The redo stack.
\value UndoAndRedoStacks Both the undo and redo stacks.
*/
/*!
\since 4.7
Clears the stacks specified by \a stacksToClear.
This method clears any commands on the undo stack, the redo stack,
or both (the default). If commands are cleared, the appropriate
signals are emitted, QTextDocument::undoAvailable() or
QTextDocument::redoAvailable().
\sa QTextDocument::undoAvailable(), QTextDocument::redoAvailable()
*/
void QTextDocument::clearUndoRedoStacks(Stacks stacksToClear)
{
Q_D(QTextDocument);
d->clearUndoRedoStacks(stacksToClear, true);
}
/*!
\overload
*/
void QTextDocument::undo()
{
Q_D(QTextDocument);
d->undoRedo(true);
}
/*!
\overload
Redoes the last editing operation on the document if \l{QTextDocument::isRedoAvailable()}{redo is available}.
*/
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 to \a option.
*/
void QTextDocument::setDefaultTextOption(const QTextOption &option)
{
Q_D(QTextDocument);
d->defaultTextOption = option;
if (d->lout)
d->lout->documentChanged(0, 0, d->length());
}
/*!
\property QTextDocument::baseUrl
\since 5.3
\brief the base URL used to resolve relative resource URLs within the document.
Resource URLs are resolved to be within the same directory as the target of the base
URL meaning any portion of the path after the last '/' will be ignored.
\table
\header \li Base URL \li Relative URL \li Resolved URL
\row \li file:///path/to/content \li images/logo.png \li file:///path/to/images/logo.png
\row \li file:///path/to/content/ \li images/logo.png \li file:///path/to/content/images/logo.png
\row \li file:///path/to/content/index.html \li images/logo.png \li file:///path/to/content/images/logo.png
\row \li file:///path/to/content/images/ \li ../images/logo.png \li file:///path/to/content/images/logo.png
\endtable
*/
QUrl QTextDocument::baseUrl() const
{
Q_D(const QTextDocument);
return d->baseUrl;
}
void QTextDocument::setBaseUrl(const QUrl &url)
{
Q_D(QTextDocument);
if (d->baseUrl != url) {
d->baseUrl = url;
if (d->lout)
d->lout->documentChanged(0, 0, d->length());
emit baseUrlChanged(url);
}
}
/*!
\since 4.8
The default cursor movement style is used by all QTextCursor objects
created from the document. The default is Qt::LogicalMoveStyle.
*/
Qt::CursorMoveStyle QTextDocument::defaultCursorMoveStyle() const
{
Q_D(const QTextDocument);
return d->defaultCursorMoveStyle;
}
/*!
\since 4.8
Sets the default cursor movement style to the given \a style.
*/
void QTextDocument::setDefaultCursorMoveStyle(Qt::CursorMoveStyle style)
{
Q_D(QTextDocument);
d->defaultCursorMoveStyle = style;
}
/*!
\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);
d->documentChange(from, length);
if (!d->inContentsChange) {
if (d->lout) {
d->lout->documentChanged(d->docChangeFrom, d->docChangeOldLength, d->docChangeLength);
d->docChangeFrom = -1;
}
}
}
/*!
\property QTextDocument::useDesignMetrics
\since 4.1
\brief whether the document uses design metrics of fonts to improve the accuracy of text layout
If this property is set to true, the layout will use design metrics.
Otherwise, the metrics of the paint device as set on
QAbstractTextDocumentLayout::setPaintDevice() will be used.
Using design metrics makes a layout have a width that is no longer dependent on hinting
and pixel-rounding. This means that WYSIWYG text layout becomes possible because the width
scales much more linearly based on paintdevice metrics than it would otherwise.
By default, this property is \c false.
*/
void QTextDocument::setUseDesignMetrics(bool b)
{
Q_D(QTextDocument);
if (b == d->defaultTextOption.useDesignMetrics())
return;
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();
}
/*!
\property QTextDocument::documentMargin
\since 4.5
The margin around the document. The default is 4.
*/
qreal QTextDocument::documentMargin() const
{
Q_D(const QTextDocument);
return d->documentMargin;
}
void QTextDocument::setDocumentMargin(qreal margin)
{
Q_D(QTextDocument);
if (d->documentMargin != margin) {
d->documentMargin = margin;
QTextFrame* root = rootFrame();
QTextFrameFormat format = root->frameFormat();
format.setMargin(margin);
root->setFrameFormat(format);
if (d->lout)
d->lout->documentChanged(0, 0, d->length());
}
}
/*!
\property QTextDocument::indentWidth
\since 4.4
Returns the width used for text list and text block indenting.
The indent properties of QTextListFormat and QTextBlockFormat specify
multiples of this value. The default indent width is 40.
*/
qreal QTextDocument::indentWidth() const
{
Q_D(const QTextDocument);
return d->indentWidth;
}
/*!
\since 4.4
Sets the \a width used for text list and text block indenting.
The indent properties of QTextListFormat and QTextBlockFormat specify
multiples of this value. The default indent width is 40 .
\sa indentWidth()
*/
void QTextDocument::setIndentWidth(qreal width)
{
Q_D(QTextDocument);
if (d->indentWidth != width) {
d->indentWidth = width;
if (d->lout)
d->lout->documentChanged(0, 0, d->length());
}
}
/*!
\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
QFont f = defaultFont();
QFontMetrics fm(f);
int mw = fm.horizontalAdvance(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().
By default, for a newly-created, empty document, this property contains
a configuration-dependent size.
\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.
By default, if defined, this property contains a value of 1.
\sa lineCount(), characterCount()
*/
int QTextDocument::blockCount() const
{
Q_D(const QTextDocument);
return d->blockMap().numNodes();
}
/*!
\since 4.5
Returns the number of lines of this document (if the layout supports
this). Otherwise, this is identical to the number of blocks.
\sa blockCount(), characterCount()
*/
int QTextDocument::lineCount() const
{
Q_D(const QTextDocument);
return d->blockMap().length(2);
}
/*!
\since 4.5
Returns the number of characters of this document.
\note As a QTextDocument always contains at least one
QChar::ParagraphSeparator, this method will return at least 1.
\sa blockCount(), characterAt()
*/
int QTextDocument::characterCount() const
{
Q_D(const QTextDocument);
return d->length();
}
/*!
\since 4.5
Returns the character at position \a pos, or a null character if the
position is out of range.
\sa characterCount()
*/
QChar QTextDocument::characterAt(int pos) const
{
Q_D(const QTextDocument);
if (pos < 0 || pos >= d->length())
return QChar();
QTextDocumentPrivate::FragmentIterator fragIt = d->find(pos);
const QTextFragmentData * const frag = fragIt.value();
const int offsetInFragment = qMax(0, pos - fragIt.position());
return d->text.at(frag->stringPosition + offsetInFragment);
}
/*!
\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.
\b{Note:} Changing the default style sheet does not have any effect to the existing content
of the document.
\sa {Supported HTML Subset}
*/
#ifndef QT_NO_CSSPARSER
void QTextDocument::setDefaultStyleSheet(const QString &sheet)
{
Q_D(QTextDocument);
d->defaultStyleSheet = sheet;
QCss::Parser parser(sheet);
d->parsedDefaultStyleSheet = QCss::StyleSheet();
d->parsedDefaultStyleSheet.origin = QCss::StyleSheetOrigin_UserAgent;
parser.parse(&d->parsedDefaultStyleSheet);
}
QString QTextDocument::defaultStyleSheet() const
{
Q_D(const QTextDocument);
return d->defaultStyleSheet;
}
#endif // QT_NO_CSSPARSER
/*!
\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 void 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 void QTextDocument::redoAvailable(bool available);
This signal is emitted whenever redo operations become available
(\a available is true) or unavailable (\a available is false).
*/
/*!
\fn void 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 the document is used with the QTextEdit class and you need a signal when the
cursor is moved with the arrow keys you can use the \l{QTextEdit::}{cursorPositionChanged()}
signal in QTextEdit.
*/
/*!
\fn void 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.
*/
/*!
\fn void QTextDocument::documentLayoutChanged();