File: widgets-codeeditor.html

package info (click to toggle)
qt4-x11 4%3A4.8.2%2Bdfsg-11
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 701,696 kB
  • sloc: cpp: 2,686,179; ansic: 375,485; python: 25,859; sh: 19,349; xml: 17,091; perl: 14,765; yacc: 5,383; asm: 5,038; makefile: 1,259; lex: 555; ruby: 526; objc: 347; cs: 112; pascal: 112; php: 54; sed: 34
file content (248 lines) | stat: -rw-r--r-- 25,563 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en_US" lang="en_US">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- codeeditor.qdoc -->
  <title>Qt 4.8: Code Editor Example</title>
  <link rel="stylesheet" type="text/css" href="style/offline.css" />
</head>
<body>
<div class="header" id="qtdocheader">
  <div class="content"> 
    <a href="index.html" class="qtref"><span>Qt Reference Documentation</span></a>
  </div>
  <div class="breadcrumb toolblock">
    <ul>
      <li class="first"><a href="index.html">Home</a></li>
      <!--  Breadcrumbs go here -->
<li><a href="all-examples.html">Examples</a></li>
<li>Code Editor Example</li>
    </ul>
  </div>
</div>
<div class="content mainContent">
<div class="toc">
<h3><a name="toc">Contents</a></h3>
<ul>
<li class="level1"><a href="#the-linenumberarea-class">The LineNumberArea Class</a></li>
<li class="level1"><a href="#codeeditor-class-definition">CodeEditor Class Definition</a></li>
<li class="level1"><a href="#codeeditor-class-implementation">CodeEditor Class Implementation</a></li>
<li class="level1"><a href="#suggestions-for-extending-the-code-editor">Suggestions for Extending the Code Editor</a></li>
</ul>
</div>
<h1 class="title">Code Editor Example</h1>
<span class="subtitle"></span>
<!-- $$$widgets/codeeditor-description -->
<div class="descr"> <a name="details"></a>
<p>Files:</p>
<ul>
<li><a href="widgets-codeeditor-codeeditor-cpp.html">widgets/codeeditor/codeeditor.cpp</a></li>
<li><a href="widgets-codeeditor-codeeditor-h.html">widgets/codeeditor/codeeditor.h</a></li>
<li><a href="widgets-codeeditor-main-cpp.html">widgets/codeeditor/main.cpp</a></li>
<li><a href="widgets-codeeditor-codeeditor-pro.html">widgets/codeeditor/codeeditor.pro</a></li>
</ul>
<p>The Code Editor example shows how to create a simple editor that has line numbers and that highlights the current line.<p class="centerAlign"><img src="images/codeeditor-example.png" alt="" /></p><p>As can be seen from the image, the editor displays the line numbers in an area to the left of the area for editing. The editor will highlight the line containing the cursor.</p>
<p>We implement the editor in <tt>CodeEditor</tt>, which is a widget that inherits <a href="qplaintextedit.html">QPlainTextEdit</a>. We keep a separate widget in <tt>CodeEditor</tt> (<tt>LineNumberArea</tt>) onto which we draw the line numbers.</p>
<p><a href="qplaintextedit.html">QPlainTextEdit</a> inherits from <a href="qabstractscrollarea.html">QAbstractScrollArea</a>, and editing takes place within its <a href="qabstractscrollarea.html#viewport">viewport()</a>'s margins. We make room for our line number area by setting the left margin of the viewport to the size we need to draw the line numbers.</p>
<p>When it comes to editing code, we prefer <a href="qplaintextedit.html">QPlainTextEdit</a> over <a href="qtextedit.html">QTextEdit</a> because it is optimized for handling plain text. See the <a href="qplaintextedit.html">QPlainTextEdit</a> class description for details.</p>
<p><a href="qplaintextedit.html">QPlainTextEdit</a> lets us add selections in addition to the selection the user can make with the mouse or keyboard. We use this functionality to highlight the current line. More on this later.</p>
<p>We will now move on to the definitions and implementations of <tt>CodeEditor</tt> and <tt>LineNumberArea</tt>. Let's start with the <tt>LineNumberArea</tt> class.</p>
<a name="the-linenumberarea-class"></a>
<h2>The LineNumberArea Class</h2>
<p>We paint the line numbers on this widget, and place it over the <tt>CodeEditor</tt>'s <a href="qabstractscrollarea.html#viewport">viewport()</a>'s left margin area.</p>
<p>We need to use protected functions in <a href="qplaintextedit.html">QPlainTextEdit</a> while painting the area. So to keep things simple, we paint the area in the <tt>CodeEditor</tt> class. The area also asks the editor to calculate its size hint.</p>
<p>Note that we could simply paint the line numbers directly on the code editor, and drop the LineNumberArea class. However, the <a href="qwidget.html">QWidget</a> class helps us to <a href="qwidget.html#scroll">scroll()</a> its contents. Also, having a separate widget is the right choice if we wish to extend the editor with breakpoints or other code editor features. The widget would then help in the handling of mouse events.</p>
<pre class="cpp"> <span class="keyword">class</span> LineNumberArea : <span class="keyword">public</span> <span class="type"><a href="qwidget.html">QWidget</a></span>
 {
 <span class="keyword">public</span>:
     LineNumberArea(CodeEditor <span class="operator">*</span>editor) : <span class="type"><a href="qwidget.html">QWidget</a></span>(editor) {
         codeEditor <span class="operator">=</span> editor;
     }

     <span class="type"><a href="qsize.html">QSize</a></span> sizeHint() <span class="keyword">const</span> {
         <span class="keyword">return</span> <span class="type"><a href="qsize.html">QSize</a></span>(codeEditor<span class="operator">-</span><span class="operator">&gt;</span>lineNumberAreaWidth()<span class="operator">,</span> <span class="number">0</span>);
     }

 <span class="keyword">protected</span>:
     <span class="type">void</span> paintEvent(<span class="type"><a href="qpaintevent.html">QPaintEvent</a></span> <span class="operator">*</span>event) {
         codeEditor<span class="operator">-</span><span class="operator">&gt;</span>lineNumberAreaPaintEvent(event);
     }

 <span class="keyword">private</span>:
     CodeEditor <span class="operator">*</span>codeEditor;
 };</pre>
<a name="codeeditor-class-definition"></a>
<h2>CodeEditor Class Definition</h2>
<p>Here is the code editor's class definition:</p>
<pre class="cpp"> <span class="keyword">class</span> CodeEditor : <span class="keyword">public</span> <span class="type"><a href="qplaintextedit.html">QPlainTextEdit</a></span>
 {
     Q_OBJECT

 <span class="keyword">public</span>:
     CodeEditor(<span class="type"><a href="qwidget.html">QWidget</a></span> <span class="operator">*</span>parent <span class="operator">=</span> <span class="number">0</span>);

     <span class="type">void</span> lineNumberAreaPaintEvent(<span class="type"><a href="qpaintevent.html">QPaintEvent</a></span> <span class="operator">*</span>event);
     <span class="type">int</span> lineNumberAreaWidth();

 <span class="keyword">protected</span>:
     <span class="type">void</span> resizeEvent(<span class="type"><a href="qresizeevent.html">QResizeEvent</a></span> <span class="operator">*</span>event);

 <span class="keyword">private</span> <span class="keyword">slots</span>:
     <span class="type">void</span> updateLineNumberAreaWidth(<span class="type">int</span> newBlockCount);
     <span class="type">void</span> highlightCurrentLine();
     <span class="type">void</span> updateLineNumberArea(<span class="keyword">const</span> <span class="type"><a href="qrect.html">QRect</a></span> <span class="operator">&amp;</span><span class="operator">,</span> <span class="type">int</span>);

 <span class="keyword">private</span>:
     <span class="type"><a href="qwidget.html">QWidget</a></span> <span class="operator">*</span>lineNumberArea;
 };</pre>
<p>In the editor we resize and draw the line numbers on the <tt>LineNumberArea</tt>. We need to do this when the number of lines in the editor changes, and when the editor's viewport() is scrolled. Of course, it is also done when the editor's size changes. We do this in <tt>updateLineNumberWidth()</tt> and <tt>updateLineNumberArea()</tt>.</p>
<p>Whenever, the cursor's position changes, we highlight the current line in <tt>highlightCurrentLine()</tt>.</p>
<a name="codeeditor-class-implementation"></a>
<h2>CodeEditor Class Implementation</h2>
<p>We will now go through the code editors implementation, starting off with the constructor.</p>
<pre class="cpp"> CodeEditor<span class="operator">::</span>CodeEditor(<span class="type"><a href="qwidget.html">QWidget</a></span> <span class="operator">*</span>parent) : <span class="type"><a href="qplaintextedit.html">QPlainTextEdit</a></span>(parent)
 {
     lineNumberArea <span class="operator">=</span> <span class="keyword">new</span> LineNumberArea(<span class="keyword">this</span>);

     connect(<span class="keyword">this</span><span class="operator">,</span> SIGNAL(blockCountChanged(<span class="type">int</span>))<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> SLOT(updateLineNumberAreaWidth(<span class="type">int</span>)));
     connect(<span class="keyword">this</span><span class="operator">,</span> SIGNAL(updateRequest(<span class="type"><a href="qrect.html">QRect</a></span><span class="operator">,</span><span class="type">int</span>))<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> SLOT(updateLineNumberArea(<span class="type"><a href="qrect.html">QRect</a></span><span class="operator">,</span><span class="type">int</span>)));
     connect(<span class="keyword">this</span><span class="operator">,</span> SIGNAL(cursorPositionChanged())<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> SLOT(highlightCurrentLine()));

     updateLineNumberAreaWidth(<span class="number">0</span>);
     highlightCurrentLine();
 }</pre>
<p>In the constructor we connect our slots to signals in <a href="qplaintextedit.html">QPlainTextEdit</a>. It is necessary to calculate the line number area width and highlight the first line when the editor is created.</p>
<pre class="cpp"> <span class="type">int</span> CodeEditor<span class="operator">::</span>lineNumberAreaWidth()
 {
     <span class="type">int</span> digits <span class="operator">=</span> <span class="number">1</span>;
     <span class="type">int</span> max <span class="operator">=</span> <a href="qtglobal.html#qMax">qMax</a>(<span class="number">1</span><span class="operator">,</span> blockCount());
     <span class="keyword">while</span> (max <span class="operator">&gt;</span><span class="operator">=</span> <span class="number">10</span>) {
         max <span class="operator">/</span><span class="operator">=</span> <span class="number">10</span>;
         <span class="operator">+</span><span class="operator">+</span>digits;
     }

     <span class="type">int</span> space <span class="operator">=</span> <span class="number">3</span> <span class="operator">+</span> fontMetrics()<span class="operator">.</span>width(QLatin1Char(<span class="char">'9'</span>)) <span class="operator">*</span> digits;

     <span class="keyword">return</span> space;
 }</pre>
<p>The <tt>lineNumberAreaWidth()</tt> function calculates the width of the <tt>LineNumberArea</tt> widget. We take the number of digits in the last line of the editor and multiply that with the maximum width of a digit.</p>
<pre class="cpp"> <span class="type">void</span> CodeEditor<span class="operator">::</span>updateLineNumberAreaWidth(<span class="type">int</span> <span class="comment">/* newBlockCount */</span>)
 {
     setViewportMargins(lineNumberAreaWidth()<span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">0</span>);
 }</pre>
<p>When we update the width of the line number area, we simply call <a href="qabstractscrollarea.html#setViewportMargins">QAbstractScrollArea::setViewportMargins</a>().</p>
<pre class="cpp"> <span class="type">void</span> CodeEditor<span class="operator">::</span>updateLineNumberArea(<span class="keyword">const</span> <span class="type"><a href="qrect.html">QRect</a></span> <span class="operator">&amp;</span>rect<span class="operator">,</span> <span class="type">int</span> dy)
 {
     <span class="keyword">if</span> (dy)
         lineNumberArea<span class="operator">-</span><span class="operator">&gt;</span>scroll(<span class="number">0</span><span class="operator">,</span> dy);
     <span class="keyword">else</span>
         lineNumberArea<span class="operator">-</span><span class="operator">&gt;</span>update(<span class="number">0</span><span class="operator">,</span> rect<span class="operator">.</span>y()<span class="operator">,</span> lineNumberArea<span class="operator">-</span><span class="operator">&gt;</span>width()<span class="operator">,</span> rect<span class="operator">.</span>height());

     <span class="keyword">if</span> (rect<span class="operator">.</span>contains(viewport()<span class="operator">-</span><span class="operator">&gt;</span>rect()))
         updateLineNumberAreaWidth(<span class="number">0</span>);
 }</pre>
<p>This slot is invoked when the editors viewport has been scrolled. The <a href="qrect.html">QRect</a> given as argument is the part of the editing area that is do be updated (redrawn). <tt>dy</tt> holds the number of pixels the view has been scrolled vertically.</p>
<pre class="cpp"> <span class="type">void</span> CodeEditor<span class="operator">::</span>resizeEvent(<span class="type"><a href="qresizeevent.html">QResizeEvent</a></span> <span class="operator">*</span>e)
 {
     <span class="type"><a href="qplaintextedit.html">QPlainTextEdit</a></span><span class="operator">::</span>resizeEvent(e);

     <span class="type"><a href="qrect.html">QRect</a></span> cr <span class="operator">=</span> contentsRect();
     lineNumberArea<span class="operator">-</span><span class="operator">&gt;</span>setGeometry(<span class="type"><a href="qrect.html">QRect</a></span>(cr<span class="operator">.</span>left()<span class="operator">,</span> cr<span class="operator">.</span>top()<span class="operator">,</span> lineNumberAreaWidth()<span class="operator">,</span> cr<span class="operator">.</span>height()));
 }</pre>
<p>When the size of the editor changes, we also need to resize the line number area.</p>
<pre class="cpp"> <span class="type">void</span> CodeEditor<span class="operator">::</span>highlightCurrentLine()
 {
     <span class="type"><a href="qlist.html">QList</a></span><span class="operator">&lt;</span><span class="type"><a href="qtextedit.html">QTextEdit</a></span><span class="operator">::</span>ExtraSelection<span class="operator">&gt;</span> extraSelections;

     <span class="keyword">if</span> (<span class="operator">!</span>isReadOnly()) {
         <span class="type"><a href="qtextedit.html">QTextEdit</a></span><span class="operator">::</span>ExtraSelection selection;

         <span class="type"><a href="qcolor.html">QColor</a></span> lineColor <span class="operator">=</span> <span class="type"><a href="qcolor.html">QColor</a></span>(<span class="type"><a href="qt.html">Qt</a></span><span class="operator">::</span>yellow)<span class="operator">.</span>lighter(<span class="number">160</span>);

         selection<span class="operator">.</span>format<span class="operator">.</span>setBackground(lineColor);
         selection<span class="operator">.</span>format<span class="operator">.</span>setProperty(<span class="type"><a href="qtextformat.html">QTextFormat</a></span><span class="operator">::</span>FullWidthSelection<span class="operator">,</span> <span class="keyword">true</span>);
         selection<span class="operator">.</span>cursor <span class="operator">=</span> textCursor();
         selection<span class="operator">.</span>cursor<span class="operator">.</span>clearSelection();
         extraSelections<span class="operator">.</span>append(selection);
     }

     setExtraSelections(extraSelections);
 }</pre>
<p>When the cursor position changes, we highlight the current line, i.e&#x2e;, the line containing the cursor.</p>
<p><a href="qplaintextedit.html">QPlainTextEdit</a> gives the possibility to have more than one selection at the same time. we can set the character format (<a href="qtextcharformat.html">QTextCharFormat</a>) of these selections. We clear the cursors selection before setting the new new QPlainTextEdit::ExtraSelection, else several lines would get highlighted when the user selects multiple lines with the mouse.</p>
<p>One sets the selection with a text cursor. When using the FullWidthSelection property, the current cursor text block (line) will be selected. If you want to select just a portion of the text block, the cursor should be moved with <a href="qtextcursor.html#movePosition">QTextCursor::movePosition</a>() from a position set with <a href="qtextcursor.html#setPosition">setPosition()</a>.</p>
<pre class="cpp"> <span class="type">void</span> CodeEditor<span class="operator">::</span>lineNumberAreaPaintEvent(<span class="type"><a href="qpaintevent.html">QPaintEvent</a></span> <span class="operator">*</span>event)
 {
     <span class="type"><a href="qpainter.html">QPainter</a></span> painter(lineNumberArea);
     painter<span class="operator">.</span>fillRect(event<span class="operator">-</span><span class="operator">&gt;</span>rect()<span class="operator">,</span> <span class="type"><a href="qt.html">Qt</a></span><span class="operator">::</span>lightGray);</pre>
<p>The <tt>lineNumberAreaPaintEvent()</tt> is called from <tt>LineNumberArea</tt> whenever it receives a paint event. We start off by painting the widget's background.</p>
<pre class="cpp">     <span class="type"><a href="qtextblock.html">QTextBlock</a></span> block <span class="operator">=</span> firstVisibleBlock();
     <span class="type">int</span> blockNumber <span class="operator">=</span> block<span class="operator">.</span>blockNumber();
     <span class="type">int</span> top <span class="operator">=</span> (<span class="type">int</span>) blockBoundingGeometry(block)<span class="operator">.</span>translated(contentOffset())<span class="operator">.</span>top();
     <span class="type">int</span> bottom <span class="operator">=</span> top <span class="operator">+</span> (<span class="type">int</span>) blockBoundingRect(block)<span class="operator">.</span>height();</pre>
<p>We will now loop through all visible lines and paint the line numbers in the extra area for each line. Notice that in a plain text edit each line will consist of one <a href="qtextblock.html">QTextBlock</a>; though, if line wrapping is enabled, a line may span several rows in the text edit's viewport.</p>
<p>We get the top and bottom y-coordinate of the first text block, and adjust these values by the height of the current text block in each iteration in the loop.</p>
<pre class="cpp">     <span class="keyword">while</span> (block<span class="operator">.</span>isValid() <span class="operator">&amp;</span><span class="operator">&amp;</span> top <span class="operator">&lt;</span><span class="operator">=</span> event<span class="operator">-</span><span class="operator">&gt;</span>rect()<span class="operator">.</span>bottom()) {
         <span class="keyword">if</span> (block<span class="operator">.</span>isVisible() <span class="operator">&amp;</span><span class="operator">&amp;</span> bottom <span class="operator">&gt;</span><span class="operator">=</span> event<span class="operator">-</span><span class="operator">&gt;</span>rect()<span class="operator">.</span>top()) {
             <span class="type"><a href="qstring.html">QString</a></span> number <span class="operator">=</span> <span class="type"><a href="qstring.html">QString</a></span><span class="operator">::</span>number(blockNumber <span class="operator">+</span> <span class="number">1</span>);
             painter<span class="operator">.</span>setPen(<span class="type"><a href="qt.html">Qt</a></span><span class="operator">::</span>black);
             painter<span class="operator">.</span>drawText(<span class="number">0</span><span class="operator">,</span> top<span class="operator">,</span> lineNumberArea<span class="operator">-</span><span class="operator">&gt;</span>width()<span class="operator">,</span> fontMetrics()<span class="operator">.</span>height()<span class="operator">,</span>
                              <span class="type"><a href="qt.html">Qt</a></span><span class="operator">::</span>AlignRight<span class="operator">,</span> number);
         }

         block <span class="operator">=</span> block<span class="operator">.</span>next();
         top <span class="operator">=</span> bottom;
         bottom <span class="operator">=</span> top <span class="operator">+</span> (<span class="type">int</span>) blockBoundingRect(block)<span class="operator">.</span>height();
         <span class="operator">+</span><span class="operator">+</span>blockNumber;
     }
 }</pre>
<p>Notice that we check if the block is visible in addition to check if it is in the areas viewport - a block can, for example, be hidden by a window placed over the text edit.</p>
<a name="suggestions-for-extending-the-code-editor"></a>
<h2>Suggestions for Extending the Code Editor</h2>
<p>No self-respecting code editor is without a syntax highligther; the <a href="richtext-syntaxhighlighter.html">Syntax Highlighter Example</a> shows how to create one.</p>
<p>In addition to line numbers, you can add more to the extra area, for instance, break points.</p>
<p><a href="qsyntaxhighlighter.html">QSyntaxHighlighter</a> gives the possibility to add user data to each text block with <a href="qsyntaxhighlighter.html#setCurrentBlockUserData">setCurrentBlockUserData()</a>. This can be used to implement parenthesis matching. In the <tt>highlightCurrentLine()</tt>, the data of the currentBlock() can be fetched with <a href="qtextblock.html#userData">QTextBlock::userData</a>(). Matching parentheses can be highlighted with an extra selection. The &quot;Matching Parentheses with <a href="qsyntaxhighlighter.html">QSyntaxHighlighter</a>&quot; article in Qt Quarterly 31 implements this. You find it here: <a href="http://doc.qt.nokia.com/qq/">http://doc.qt.nokia.com/qq/</a>.</p>
<p>The line number area is now painted every time the cursor blinks (because we connect <a href="qplaintextedit.html#updateRequest">updateRequest()</a> to <tt>updateLineNumberArea()</tt>). 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 <tt>m_countCache</tt> variable, which is a <a href="qpair.html">QPair</a>&lt;int, int&gt; initialized with <tt>-1</tt> for both <a href="qpair.html#first-var">first</a> and <a href="qpair.html#second-var">second</a>.</p>
<pre class="cpp"> <span class="type">void</span> CodeEditor<span class="operator">::</span>updateLineNumberArea(<span class="keyword">const</span> <span class="type"><a href="qrect.html">QRect</a></span> <span class="operator">&amp;</span>rect<span class="operator">,</span> <span class="type">int</span> dy)
 {
     <span class="keyword">if</span> (dy) {
         lineNumberArea<span class="operator">-</span><span class="operator">&gt;</span>scroll(<span class="number">0</span><span class="operator">,</span> dy);
     } <span class="keyword">else</span> <span class="keyword">if</span> (m_countCache<span class="operator">.</span>first <span class="operator">!</span><span class="operator">=</span> blockCount()
                <span class="operator">|</span><span class="operator">|</span> m_countCache<span class="operator">.</span>second <span class="operator">!</span><span class="operator">=</span> textCursor()<span class="operator">.</span>block()<span class="operator">.</span>lineCount()) {
         lineNumberArea<span class="operator">-</span><span class="operator">&gt;</span>update(<span class="number">0</span><span class="operator">,</span> rect<span class="operator">.</span>y()<span class="operator">,</span> lineNumberArea<span class="operator">-</span><span class="operator">&gt;</span>width()<span class="operator">,</span> rect<span class="operator">.</span>height());
         m_countCache<span class="operator">.</span>first <span class="operator">=</span> blockCount();
         m_countCache<span class="operator">.</span>second <span class="operator">=</span> textCursor()<span class="operator">.</span>block()<span class="operator">.</span>lineCount();
     }

     <span class="keyword">if</span> (rect<span class="operator">.</span>contains(viewport()<span class="operator">-</span><span class="operator">&gt;</span>rect()))
         updateLineNumberAreaWidth(<span class="number">0</span>);
 }</pre>
</div>
<!-- @@@widgets/codeeditor -->
  <div class="ft">
    <span></span>
  </div>
</div> 
<div class="footer">
    <p>
      <acronym title="Copyright">&copy;</acronym> 2012 Nokia Corporation and/or its
      subsidiaries. Documentation contributions included herein are the copyrights of
      their respective owners.</p>
    <br />
    <p>
      The documentation provided herein is licensed under the terms of the
      <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation
      License version 1.3</a> as published by the Free Software Foundation.</p>
    <p>
      Documentation sources may be obtained from <a href="http://www.qt-project.org">
      www.qt-project.org</a>.</p>
    <br />
    <p>
      Nokia, Qt and their respective logos are trademarks of Nokia Corporation 
      in Finland and/or other countries worldwide. All other trademarks are property
      of their respective owners. <a title="Privacy Policy"
      href="http://en.gitorious.org/privacy_policy/">Privacy Policy</a></p>
</div>
</body>
</html>