44 #ifndef QT_NO_SYNTAXHIGHLIGHTER 45 #include <private/qobject_p.h> 47 #include <private/qtextdocument_p.h> 86 q_func()->rehighlight();
98 bool formatsChanged =
false;
107 if (preeditAreaLength != 0) {
109 while (it != ranges.
end()) {
110 if (it->start >= preeditAreaStart
111 && it->start + it->
length <= preeditAreaStart + preeditAreaLength) {
114 it = ranges.
erase(it);
115 formatsChanged =
true;
118 }
else if (!ranges.
isEmpty()) {
120 formatsChanged =
true;
148 if (preeditAreaLength != 0) {
149 if (r.
start >= preeditAreaStart)
150 r.
start += preeditAreaLength;
152 r.
length += preeditAreaLength;
156 formatsChanged =
true;
163 if (preeditAreaLength != 0) {
164 if (r.
start >= preeditAreaStart)
165 r.
start += preeditAreaLength;
167 r.
length += preeditAreaLength;
171 formatsChanged =
true;
174 if (formatsChanged) {
201 bool forceHighlightOfNextBlock =
false;
203 while (block.
isValid() && (block.
position() < endPosition || forceHighlightOfNextBlock)) {
204 const int stateBeforeHighlight = block.
userState();
208 forceHighlightOfNextBlock = (block.
userState() != stateBeforeHighlight);
210 block = block.
next();
225 q->highlightBlock(block.
text());
362 this,
SLOT(_q_reformatBlocks(
int,
int,
int)));
366 for (
QTextBlock blk =
d->doc->begin(); blk.isValid(); blk = blk.next())
367 blk.layout()->clearAdditionalFormats();
373 this,
SLOT(_q_reformatBlocks(
int,
int,
int)));
374 d->rehighlightPending =
true;
425 const bool rehighlightPending =
d->rehighlightPending;
430 if (rehighlightPending)
431 d->rehighlightPending = rehighlightPending;
496 if (start < 0 || start >=
d->formatChanges.count())
499 const int end =
qMin(start + count,
d->formatChanges.count());
500 for (
int i = start; i <
end; ++i)
501 d->formatChanges[i] = format;
558 if (pos < 0 || pos >=
d->formatChanges.count())
560 return d->formatChanges.at(pos);
573 if (!
d->currentBlock.isValid())
576 const QTextBlock previous =
d->currentBlock.previous();
590 if (!
d->currentBlock.isValid())
593 return d->currentBlock.userState();
604 if (!
d->currentBlock.isValid())
607 d->currentBlock.setUserState(newState);
647 if (!
d->currentBlock.isValid())
650 d->currentBlock.setUserData(data);
662 if (!
d->currentBlock.isValid())
665 return d->currentBlock.userData();
679 return d->currentBlock;
684 #include "moc_qsyntaxhighlighter.cpp" 686 #endif // QT_NO_SYNTAXHIGHLIGHTER void rehighlight()
Reapplies the highlighting to the whole document.
The QColor class provides colors based on RGB, HSV or CMYK values.
void setAdditionalFormats(const QList< FormatRange > &overrides)
Sets the additional formats supported by the text layout to formatList.
virtual ~QSyntaxHighlighter()
Destructor.
The QTextLayout::FormatRange structure is used to apply extra formatting information for a specified ...
void endEditBlock()
Indicates the end of a block of editing operations on the document that should appear as a single ope...
QString text() const
Returns the block's contents as plain text.
The QTextCharFormat class provides formatting information for characters in a QTextDocument.
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
QSyntaxHighlighter(QObject *parent)
Constructs a QSyntaxHighlighter with the given parent.
#define QT_END_NAMESPACE
This macro expands to.
QVector< T > & fill(const T &t, int size=-1)
Assigns value to all items in the vector.
#define it(className, varName)
QTextDocument * document() const
Returns the QTextDocument on which this syntax highlighter is installed.
int count(const T &t) const
Returns the number of occurrences of value in the vector.
int length() const
Returns the number of characters in this string.
iterator begin()
Returns an STL-style iterator pointing to the first item in the list.
void setFont(const QFont &font)
Sets the text format's font.
void setFormat(int start, int count, const QTextCharFormat &format)
This function is applied to the syntax highlighter's current text block (i.e.
int start
Specifies the beginning of the format range within the text layout's text.
The QObject class is the base class of all Qt objects.
void markContentsDirty(int from, int length)
Marks the contents specified by the given position and length as "dirty", informing the document that...
int previousBlockState() const
Returns the end state of the text block previous to the syntax highlighter's current block...
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
QTextBlock next() const
Returns the text block in the document after this block, or an empty text block if this is the last o...
int position() const
Returns the index of the block's first character within the document.
#define QT_BEGIN_NAMESPACE
This macro expands to.
void clear()
Removes all the elements from the vector and releases the memory used by the vector.
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
QTextDocumentPrivate * docHandle() const
So that not all classes have to be friends of each other.
The QTextCursor class offers an API to access and modify QTextDocuments.
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the list...
The QTextBlock class provides a container for text fragments in a QTextDocument.
static const char * data(const QByteArray &arr)
void setCurrentBlockUserData(QTextBlockUserData *data)
Attaches the given data to the current text block.
void clear()
Removes all items from the list.
int position() const
Returns the absolute position of the cursor within the document.
int length() const
Returns the length of the block in characters.
int currentBlockState() const
Returns the state of the current text block.
QTextBlock currentBlock() const
Returns the current text block.
QPointer< QTextDocument > doc
void rehighlightBlock(const QTextBlock &block)
Reapplies the highlighting to the given QTextBlock block.
int preeditAreaPosition() const
Returns the position of the area in the text layout that will be processed before editing occurs...
const T & at(int i) const
Returns the item at index position i in the vector.
void applyFormatChanges()
void _q_reformatBlocks(int from, int charsRemoved, int charsAdded)
The QTextBlockUserData class is used to associate custom data with blocks of text.
void setCurrentBlockState(int newState)
Sets the state of the current text block to newState.
static bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *member)
Disconnects signal in object sender from method in object receiver.
int userState() const
Returns the integer value previously set with setUserState() or -1.
void reformatBlock(const QTextBlock &block)
QString preeditAreaText() const
Returns the text that is inserted in the layout before editing occurs.
#define Q_ASSERT_X(cond, where, what)
iterator erase(iterator pos)
Removes the item associated with the iterator pos from the list, and returns an iterator to the next ...
The QTextLayout class is used to lay out and render text.
void beginEditBlock()
Indicates the start of a block of editing operations on the document that should appear as a single o...
#define Q_DECLARE_PUBLIC(Class)
void rehighlight(QTextCursor &cursor, QTextCursor::MoveOperation operation)
The QFont class specifies a font used for drawing text.
QTextBlock findBlock(int pos) const
Returns the text block that contains the {pos}-th character.
The QSyntaxHighlighter class allows you to define syntax highlighting rules, and in addition you can ...
void reformatBlocks(int from, int charsRemoved, int charsAdded)
QList< FormatRange > additionalFormats() const
Returns the list of additional formats supported by the text layout.
QObject * parent() const
Returns a pointer to the parent object.
QTextDocument * document() const
Returns a pointer to the underlying document.
int length() const
This function is identical to count().
bool singleShot
This static function calls a slot after a given time interval.
bool movePosition(MoveOperation op, MoveMode=MoveAnchor, int n=1)
Moves the cursor by performing the given operation n times, using the specified mode, and returns true if all operations were completed successfully; otherwise returns false.
The QTextDocument class holds formatted text that can be viewed and edited using a QTextEdit...
bool isValid() const
Returns true if this text block is valid; otherwise returns false.
int length
Specifies the numer of characters the format range spans.
QSyntaxHighlighterPrivate()
QTextCharFormat format
Specifies the format to apply.
void setForeground(const QBrush &brush)
Sets the foreground brush to the specified brush.
QTextCharFormat format(int pos) const
Returns the format at position inside the syntax highlighter's current text block.
void setDocument(QTextDocument *doc)
Installs the syntax highlighter on the given QTextDocument doc.
static const KeyPair *const end
QTextBlockUserData * currentBlockUserData() const
Returns the QTextBlockUserData object previously attached to the current text block.
void _q_delayedRehighlight()
QVector< QTextCharFormat > formatChanges
const QTextDocument * document() const
Returns the text document this text block belongs to, or 0 if the text block does not belong to any d...
The QTextEdit class provides a widget that is used to edit and display both plain and rich text...
QTextLayout * layout() const
Returns the QTextLayout that is used to lay out and display the block's contents. ...