Changeset 846 for trunk/src/gui/text/qsyntaxhighlighter.cpp
- Timestamp:
- May 5, 2011, 5:36:53 AM (14 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:mergeinfo changed
/branches/vendor/nokia/qt/4.7.2 (added) merged: 845 /branches/vendor/nokia/qt/current merged: 844 /branches/vendor/nokia/qt/4.6.3 removed
- Property svn:mergeinfo changed
-
trunk/src/gui/text/qsyntaxhighlighter.cpp
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) … … 60 60 Q_DECLARE_PUBLIC(QSyntaxHighlighter) 61 61 public: 62 inline QSyntaxHighlighterPrivate() : rehighlightPending(false) {} 62 inline QSyntaxHighlighterPrivate() 63 : rehighlightPending(false), inReformatBlocks(false) 64 {} 63 65 64 66 QPointer<QTextDocument> doc; 65 67 66 68 void _q_reformatBlocks(int from, int charsRemoved, int charsAdded); 67 void reformatBlock(QTextBlock block); 68 69 void reformatBlocks(int from, int charsRemoved, int charsAdded); 70 void reformatBlock(const QTextBlock &block); 71 69 72 inline void rehighlight(QTextCursor &cursor, QTextCursor::MoveOperation operation) { 70 QObject::disconnect(doc, SIGNAL(contentsChange(int,int,int)), 71 q_func(), SLOT(_q_reformatBlocks(int,int,int))); 73 inReformatBlocks = true; 72 74 cursor.beginEditBlock(); 73 75 int from = cursor.position(); 74 76 cursor.movePosition(operation); 75 _q_reformatBlocks(from, 0, cursor.position() - from);77 reformatBlocks(from, 0, cursor.position() - from); 76 78 cursor.endEditBlock(); 77 QObject::connect(doc, SIGNAL(contentsChange(int,int,int)), 78 q_func(), SLOT(_q_reformatBlocks(int,int,int))); 79 inReformatBlocks = false; 79 80 } 80 81 … … 84 85 rehighlightPending = false; 85 86 q_func()->rehighlight(); 86 return;87 87 } 88 88 … … 91 91 QTextBlock currentBlock; 92 92 bool rehighlightPending; 93 93 94 }; 94 95 95 96 void QSyntaxHighlighterPrivate::applyFormatChanges() 96 97 { 98 99 97 100 QTextLayout *layout = currentBlock.layout(); 98 101 … … 102 105 const int preeditAreaLength = layout->preeditAreaText().length(); 103 106 104 QList<QTextLayout::FormatRange>::Iterator it = ranges.begin(); 105 while (it != ranges.end()) { 106 if (it->start >= preeditAreaStart 107 && it->start + it->length <= preeditAreaStart + preeditAreaLength) 108 ++it; 109 else 110 it = ranges.erase(it); 107 if (preeditAreaLength != 0) { 108 QList<QTextLayout::FormatRange>::Iterator it = ranges.begin(); 109 while (it != ranges.end()) { 110 if (it->start >= preeditAreaStart 111 && it->start + it->length <= preeditAreaStart + preeditAreaLength) { 112 ++it; 113 } else { 114 it = ranges.erase(it); 115 formatsChanged = true; 116 } 117 } 118 } else if (!ranges.isEmpty()) { 119 ranges.clear(); 120 formatsChanged = true; 111 121 } 112 122 … … 114 124 115 125 QTextLayout::FormatRange r; 116 r.start = r.length =-1;126 r.start = -1; 117 127 118 128 int i = 0; … … 136 146 r.length = i - r.start; 137 147 138 if (r.start >= preeditAreaStart) { 139 r.start += preeditAreaLength; 140 } else if (r.start + r.length >= preeditAreaStart) { 141 r.length += preeditAreaLength; 148 if (preeditAreaLength != 0) { 149 if (r.start >= preeditAreaStart) 150 r.start += preeditAreaLength; 151 else if (r.start + r.length >= preeditAreaStart) 152 r.length += preeditAreaLength; 142 153 } 143 154 144 155 ranges << r; 145 r.start = r.length = -1; 156 formatsChanged = true; 157 r.start = -1; 146 158 } 147 159 … … 149 161 r.length = formatChanges.count() - r.start; 150 162 151 if (r.start >= preeditAreaStart) { 152 r.start += preeditAreaLength; 153 } else if (r.start + r.length >= preeditAreaStart) { 154 r.length += preeditAreaLength; 163 if (preeditAreaLength != 0) { 164 if (r.start >= preeditAreaStart) 165 r.start += preeditAreaLength; 166 else if (r.start + r.length >= preeditAreaStart) 167 r.length += preeditAreaLength; 155 168 } 156 169 157 170 ranges << r; 158 } 159 160 layout->setAdditionalFormats(ranges); 171 formatsChanged = true; 172 } 173 174 if (formatsChanged) { 175 layout->setAdditionalFormats(ranges); 176 doc->markContentsDirty(currentBlock.position(), currentBlock.length()); 177 } 161 178 } 162 179 163 180 void QSyntaxHighlighterPrivate::_q_reformatBlocks(int from, int charsRemoved, int charsAdded) 164 181 { 165 Q_UNUSED(charsRemoved); 182 if (!inReformatBlocks) 183 reformatBlocks(from, charsRemoved, charsAdded); 184 } 185 186 void QSyntaxHighlighterPrivate::reformatBlocks(int from, int charsRemoved, int charsAdded) 187 { 166 188 rehighlightPending = false; 167 189 … … 192 214 } 193 215 194 void QSyntaxHighlighterPrivate::reformatBlock( QTextBlockblock)216 void QSyntaxHighlighterPrivate::reformatBlock(block) 195 217 { 196 218 Q_Q(QSyntaxHighlighter); … … 199 221 200 222 currentBlock = block; 201 QTextBlock previous = block.previous();202 223 203 224 formatChanges.fill(QTextCharFormat(), block.length() - 1); 204 225 q->highlightBlock(block.text()); 205 226 applyFormatChanges(); 206 207 doc->markContentsDirty(block.position(), block.length());208 227 209 228 currentBlock = QTextBlock(); … … 350 369 connect(d->doc, SIGNAL(contentsChange(int,int,int)), 351 370 this, SLOT(_q_reformatBlocks(int,int,int))); 371 352 372 QTimer::singleShot(0, this, SLOT(_q_delayedRehighlight())); 353 d->rehighlightPending = true;354 373 } 355 374 } … … 392 411 { 393 412 Q_D(QSyntaxHighlighter); 394 if (!d->doc )413 if (!d->doc) 395 414 return; 415 416 396 417 397 418 QTextCursor cursor(block); 398 419 d->rehighlight(cursor, QTextCursor::EndOfBlock); 420 421 422 399 423 } 400 424 … … 461 485 { 462 486 Q_D(QSyntaxHighlighter); 463 464 487 if (start < 0 || start >= d->formatChanges.count()) 465 488 return; … … 629 652 630 653 Returns the current text block. 631 654 */ 632 655 QTextBlock QSyntaxHighlighter::currentBlock() const 633 656 {
Note:
See TracChangeset
for help on using the changeset viewer.