summaryrefslogtreecommitdiffstats
path: root/doc/src/examples/codeeditor.qdoc
diff options
context:
space:
mode:
Diffstat (limited to 'doc/src/examples/codeeditor.qdoc')
-rw-r--r--doc/src/examples/codeeditor.qdoc26
1 files changed, 26 insertions, 0 deletions
diff --git a/doc/src/examples/codeeditor.qdoc b/doc/src/examples/codeeditor.qdoc
index 435f650..1718d52 100644
--- a/doc/src/examples/codeeditor.qdoc
+++ b/doc/src/examples/codeeditor.qdoc
@@ -194,4 +194,30 @@
with QSyntaxHighlighter" article in Qt Quarterly 31 implements
this. You find it here: \l{http://doc.qt.nokia.com/qq/}.
+ The line number area is now painted every time the cursor blinks
+ (because we connect \l{QPlainTextEdit::}{updateRequest()} to
+ \c updateLineNumberArea()). We can avoid this by introducing a new
+ member variable to CodeEditor that keeps track of when the update
+ request comes from a cursor blink (in which case we do not
+ repaint). The code below requires the \c m_countCache variable,
+ which is a QPair<int, int> initialized with \c -1 for both
+ \l{QPair::}{first} and \l{QPair::}{second}.
+
+ \code
+ void CodeEditor::updateLineNumberArea(const QRect &rect, int dy)
+ {
+ if (dy) {
+ lineNumberArea->scroll(0, dy);
+ } else if (m_countCache.first != blockCount()
+ || m_countCache.second != textCursor().block().lineCount()) {
+ lineNumberArea->update(0, rect.y(), lineNumberArea->width(), rect.height());
+ m_countCache.first = blockCount();
+ m_countCache.second = textCursor().block().lineCount();
+ }
+
+ if (rect.contains(viewport()->rect()))
+ updateLineNumberAreaWidth(0);
+ }
+ \endcode
*/
+