Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/widgets/widgets/qplaintextedit.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /**************************************************************************** | - | ||||||||||||||||||||||||
2 | ** | - | ||||||||||||||||||||||||
3 | ** Copyright (C) 2015 The Qt Company Ltd. | - | ||||||||||||||||||||||||
4 | ** Contact: http://www.qt.io/licensing/ | - | ||||||||||||||||||||||||
5 | ** | - | ||||||||||||||||||||||||
6 | ** This file is part of the QtWidgets module of the Qt Toolkit. | - | ||||||||||||||||||||||||
7 | ** | - | ||||||||||||||||||||||||
8 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||||||||||||||||||||
9 | ** Commercial License Usage | - | ||||||||||||||||||||||||
10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||||||||||||||
11 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||||||||||||||
12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||||||||||||||
13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||||||||||||||
14 | ** and conditions see http://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||||||||
15 | ** information use the contact form at http://www.qt.io/contact-us. | - | ||||||||||||||||||||||||
16 | ** | - | ||||||||||||||||||||||||
17 | ** GNU Lesser General Public License Usage | - | ||||||||||||||||||||||||
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||||||||||||||
19 | ** General Public License version 2.1 or version 3 as published by the Free | - | ||||||||||||||||||||||||
20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||||||||||||||||||||
21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||||||||||||||||||||
22 | ** following information to ensure the GNU Lesser General Public License | - | ||||||||||||||||||||||||
23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||||||||||||||||||||
24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||||||||||||||||||||
25 | ** | - | ||||||||||||||||||||||||
26 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||||||||||||||||||||
27 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||||||||||||||||||||
28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||||||||||||||||||||
29 | ** | - | ||||||||||||||||||||||||
30 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||||||||
31 | ** | - | ||||||||||||||||||||||||
32 | ****************************************************************************/ | - | ||||||||||||||||||||||||
33 | - | |||||||||||||||||||||||||
34 | #include "qplaintextedit_p.h" | - | ||||||||||||||||||||||||
35 | - | |||||||||||||||||||||||||
36 | - | |||||||||||||||||||||||||
37 | #include <qfont.h> | - | ||||||||||||||||||||||||
38 | #include <qpainter.h> | - | ||||||||||||||||||||||||
39 | #include <qevent.h> | - | ||||||||||||||||||||||||
40 | #include <qdebug.h> | - | ||||||||||||||||||||||||
41 | #include <qdrag.h> | - | ||||||||||||||||||||||||
42 | #include <qclipboard.h> | - | ||||||||||||||||||||||||
43 | #include <qmenu.h> | - | ||||||||||||||||||||||||
44 | #include <qstyle.h> | - | ||||||||||||||||||||||||
45 | #include <qtimer.h> | - | ||||||||||||||||||||||||
46 | #include "private/qtextdocumentlayout_p.h" | - | ||||||||||||||||||||||||
47 | #include "private/qabstracttextdocumentlayout_p.h" | - | ||||||||||||||||||||||||
48 | #include "qtextdocument.h" | - | ||||||||||||||||||||||||
49 | #include "private/qtextdocument_p.h" | - | ||||||||||||||||||||||||
50 | #include "qtextlist.h" | - | ||||||||||||||||||||||||
51 | #include "qaccessible.h" | - | ||||||||||||||||||||||||
52 | - | |||||||||||||||||||||||||
53 | #include <qtextformat.h> | - | ||||||||||||||||||||||||
54 | #include <qdatetime.h> | - | ||||||||||||||||||||||||
55 | #include <qapplication.h> | - | ||||||||||||||||||||||||
56 | #include <limits.h> | - | ||||||||||||||||||||||||
57 | #include <qtexttable.h> | - | ||||||||||||||||||||||||
58 | #include <qvariant.h> | - | ||||||||||||||||||||||||
59 | - | |||||||||||||||||||||||||
60 | #ifndef QT_NO_TEXTEDIT | - | ||||||||||||||||||||||||
61 | - | |||||||||||||||||||||||||
62 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||||||||
63 | - | |||||||||||||||||||||||||
64 | static inline bool shouldEnableInputMethod(QPlainTextEdit *plaintextedit) | - | ||||||||||||||||||||||||
65 | { | - | ||||||||||||||||||||||||
66 | return !plaintextedit->isReadOnly(); never executed: return !plaintextedit->isReadOnly(); | 0 | ||||||||||||||||||||||||
67 | } | - | ||||||||||||||||||||||||
68 | - | |||||||||||||||||||||||||
69 | class QPlainTextDocumentLayoutPrivate : public QAbstractTextDocumentLayoutPrivate | - | ||||||||||||||||||||||||
70 | { | - | ||||||||||||||||||||||||
71 | Q_DECLARE_PUBLIC(QPlainTextDocumentLayout) | - | ||||||||||||||||||||||||
72 | public: | - | ||||||||||||||||||||||||
73 | QPlainTextDocumentLayoutPrivate() { | - | ||||||||||||||||||||||||
74 | mainViewPrivate = 0; | - | ||||||||||||||||||||||||
75 | width = 0; | - | ||||||||||||||||||||||||
76 | maximumWidth = 0; | - | ||||||||||||||||||||||||
77 | maximumWidthBlockNumber = 0; | - | ||||||||||||||||||||||||
78 | blockCount = 1; | - | ||||||||||||||||||||||||
79 | blockUpdate = blockDocumentSizeChanged = false; | - | ||||||||||||||||||||||||
80 | cursorWidth = 1; | - | ||||||||||||||||||||||||
81 | textLayoutFlags = 0; | - | ||||||||||||||||||||||||
82 | } never executed: end of block | 0 | ||||||||||||||||||||||||
83 | - | |||||||||||||||||||||||||
84 | qreal width; | - | ||||||||||||||||||||||||
85 | qreal maximumWidth; | - | ||||||||||||||||||||||||
86 | int maximumWidthBlockNumber; | - | ||||||||||||||||||||||||
87 | int blockCount; | - | ||||||||||||||||||||||||
88 | QPlainTextEditPrivate *mainViewPrivate; | - | ||||||||||||||||||||||||
89 | bool blockUpdate; | - | ||||||||||||||||||||||||
90 | bool blockDocumentSizeChanged; | - | ||||||||||||||||||||||||
91 | int cursorWidth; | - | ||||||||||||||||||||||||
92 | int textLayoutFlags; | - | ||||||||||||||||||||||||
93 | - | |||||||||||||||||||||||||
94 | void layoutBlock(const QTextBlock &block); | - | ||||||||||||||||||||||||
95 | qreal blockWidth(const QTextBlock &block); | - | ||||||||||||||||||||||||
96 | - | |||||||||||||||||||||||||
97 | void relayout(); | - | ||||||||||||||||||||||||
98 | }; | - | ||||||||||||||||||||||||
99 | - | |||||||||||||||||||||||||
100 | - | |||||||||||||||||||||||||
101 | - | |||||||||||||||||||||||||
102 | /*! \class QPlainTextDocumentLayout | - | ||||||||||||||||||||||||
103 | \since 4.4 | - | ||||||||||||||||||||||||
104 | \brief The QPlainTextDocumentLayout class implements a plain text layout for QTextDocument | - | ||||||||||||||||||||||||
105 | - | |||||||||||||||||||||||||
106 | \ingroup richtext-processing | - | ||||||||||||||||||||||||
107 | \inmodule QtWidgets | - | ||||||||||||||||||||||||
108 | - | |||||||||||||||||||||||||
109 | A QPlainTextDocumentLayout is required for text documents that can | - | ||||||||||||||||||||||||
110 | be display or edited in a QPlainTextEdit. See | - | ||||||||||||||||||||||||
111 | QTextDocument::setDocumentLayout(). | - | ||||||||||||||||||||||||
112 | - | |||||||||||||||||||||||||
113 | QPlainTextDocumentLayout uses the QAbstractTextDocumentLayout API | - | ||||||||||||||||||||||||
114 | that QTextDocument requires, but redefines it partially in order to | - | ||||||||||||||||||||||||
115 | support plain text better. For instances, it does not operate on | - | ||||||||||||||||||||||||
116 | vertical pixels, but on paragraphs (called blocks) instead. The | - | ||||||||||||||||||||||||
117 | height of a document is identical to the number of paragraphs it | - | ||||||||||||||||||||||||
118 | contains. The layout also doesn't support tables or nested frames, | - | ||||||||||||||||||||||||
119 | or any sort of advanced text layout that goes beyond a list of | - | ||||||||||||||||||||||||
120 | paragraphs with syntax highlighting. | - | ||||||||||||||||||||||||
121 | - | |||||||||||||||||||||||||
122 | */ | - | ||||||||||||||||||||||||
123 | - | |||||||||||||||||||||||||
124 | - | |||||||||||||||||||||||||
125 | - | |||||||||||||||||||||||||
126 | /*! | - | ||||||||||||||||||||||||
127 | Constructs a plain text document layout for the text \a document. | - | ||||||||||||||||||||||||
128 | */ | - | ||||||||||||||||||||||||
129 | QPlainTextDocumentLayout::QPlainTextDocumentLayout(QTextDocument *document) | - | ||||||||||||||||||||||||
130 | :QAbstractTextDocumentLayout(* new QPlainTextDocumentLayoutPrivate, document) { | - | ||||||||||||||||||||||||
131 | } never executed: end of block | 0 | ||||||||||||||||||||||||
132 | /*! | - | ||||||||||||||||||||||||
133 | Destructs a plain text document layout. | - | ||||||||||||||||||||||||
134 | */ | - | ||||||||||||||||||||||||
135 | QPlainTextDocumentLayout::~QPlainTextDocumentLayout() {} | - | ||||||||||||||||||||||||
136 | - | |||||||||||||||||||||||||
137 | - | |||||||||||||||||||||||||
138 | /*! | - | ||||||||||||||||||||||||
139 | \reimp | - | ||||||||||||||||||||||||
140 | */ | - | ||||||||||||||||||||||||
141 | void QPlainTextDocumentLayout::draw(QPainter *, const PaintContext &) | - | ||||||||||||||||||||||||
142 | { | - | ||||||||||||||||||||||||
143 | } | - | ||||||||||||||||||||||||
144 | - | |||||||||||||||||||||||||
145 | /*! | - | ||||||||||||||||||||||||
146 | \reimp | - | ||||||||||||||||||||||||
147 | */ | - | ||||||||||||||||||||||||
148 | int QPlainTextDocumentLayout::hitTest(const QPointF &, Qt::HitTestAccuracy ) const | - | ||||||||||||||||||||||||
149 | { | - | ||||||||||||||||||||||||
150 | // this function is used from | - | ||||||||||||||||||||||||
151 | // QAbstractTextDocumentLayout::anchorAt(), but is not | - | ||||||||||||||||||||||||
152 | // implementable in a plain text document layout, because the | - | ||||||||||||||||||||||||
153 | // layout depends on the top block and top line which depends on | - | ||||||||||||||||||||||||
154 | // the view | - | ||||||||||||||||||||||||
155 | return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||
156 | } | - | ||||||||||||||||||||||||
157 | - | |||||||||||||||||||||||||
158 | /*! | - | ||||||||||||||||||||||||
159 | \reimp | - | ||||||||||||||||||||||||
160 | */ | - | ||||||||||||||||||||||||
161 | int QPlainTextDocumentLayout::pageCount() const | - | ||||||||||||||||||||||||
162 | { never executed: return 1; }return 1; never executed: return 1; | 0 | ||||||||||||||||||||||||
163 | - | |||||||||||||||||||||||||
164 | /*! | - | ||||||||||||||||||||||||
165 | \reimp | - | ||||||||||||||||||||||||
166 | */ | - | ||||||||||||||||||||||||
167 | QSizeF QPlainTextDocumentLayout::documentSize() const | - | ||||||||||||||||||||||||
168 | { | - | ||||||||||||||||||||||||
169 | Q_D(const QPlainTextDocumentLayout); | - | ||||||||||||||||||||||||
170 | return QSizeF(d->maximumWidth, document()->lineCount()); never executed: return QSizeF(d->maximumWidth, document()->lineCount()); | 0 | ||||||||||||||||||||||||
171 | } | - | ||||||||||||||||||||||||
172 | - | |||||||||||||||||||||||||
173 | /*! | - | ||||||||||||||||||||||||
174 | \reimp | - | ||||||||||||||||||||||||
175 | */ | - | ||||||||||||||||||||||||
176 | QRectF QPlainTextDocumentLayout::frameBoundingRect(QTextFrame *) const | - | ||||||||||||||||||||||||
177 | { | - | ||||||||||||||||||||||||
178 | Q_D(const QPlainTextDocumentLayout); | - | ||||||||||||||||||||||||
179 | return QRectF(0, 0, qMax(d->width, d->maximumWidth), qreal(INT_MAX)); never executed: return QRectF(0, 0, qMax(d->width, d->maximumWidth), qreal(2147483647)); | 0 | ||||||||||||||||||||||||
180 | } | - | ||||||||||||||||||||||||
181 | - | |||||||||||||||||||||||||
182 | /*! | - | ||||||||||||||||||||||||
183 | \reimp | - | ||||||||||||||||||||||||
184 | */ | - | ||||||||||||||||||||||||
185 | QRectF QPlainTextDocumentLayout::blockBoundingRect(const QTextBlock &block) const | - | ||||||||||||||||||||||||
186 | { | - | ||||||||||||||||||||||||
187 | if (!block.isValid()) { return QRectF(); } never executed: return QRectF();
| 0 | ||||||||||||||||||||||||
188 | QTextLayout *tl = block.layout(); | - | ||||||||||||||||||||||||
189 | if (!tl->lineCount())
| 0 | ||||||||||||||||||||||||
190 | const_cast<QPlainTextDocumentLayout*>(this)->layoutBlock(block); never executed: const_cast<QPlainTextDocumentLayout*>(this)->layoutBlock(block); | 0 | ||||||||||||||||||||||||
191 | QRectF br; | - | ||||||||||||||||||||||||
192 | if (block.isVisible()) {
| 0 | ||||||||||||||||||||||||
193 | br = QRectF(QPointF(0, 0), tl->boundingRect().bottomRight()); | - | ||||||||||||||||||||||||
194 | if (tl->lineCount() == 1)
| 0 | ||||||||||||||||||||||||
195 | br.setWidth(qMax(br.width(), tl->lineAt(0).naturalTextWidth())); never executed: br.setWidth(qMax(br.width(), tl->lineAt(0).naturalTextWidth())); | 0 | ||||||||||||||||||||||||
196 | qreal margin = document()->documentMargin(); | - | ||||||||||||||||||||||||
197 | br.adjust(0, 0, margin, 0); | - | ||||||||||||||||||||||||
198 | if (!block.next().isValid())
| 0 | ||||||||||||||||||||||||
199 | br.adjust(0, 0, 0, margin); never executed: br.adjust(0, 0, 0, margin); | 0 | ||||||||||||||||||||||||
200 | } never executed: end of block | 0 | ||||||||||||||||||||||||
201 | return br; never executed: return br; | 0 | ||||||||||||||||||||||||
202 | - | |||||||||||||||||||||||||
203 | } | - | ||||||||||||||||||||||||
204 | - | |||||||||||||||||||||||||
205 | /*! | - | ||||||||||||||||||||||||
206 | Ensures that \a block has a valid layout | - | ||||||||||||||||||||||||
207 | */ | - | ||||||||||||||||||||||||
208 | void QPlainTextDocumentLayout::ensureBlockLayout(const QTextBlock &block) const | - | ||||||||||||||||||||||||
209 | { | - | ||||||||||||||||||||||||
210 | if (!block.isValid())
| 0 | ||||||||||||||||||||||||
211 | return; never executed: return; | 0 | ||||||||||||||||||||||||
212 | QTextLayout *tl = block.layout(); | - | ||||||||||||||||||||||||
213 | if (!tl->lineCount())
| 0 | ||||||||||||||||||||||||
214 | const_cast<QPlainTextDocumentLayout*>(this)->layoutBlock(block); never executed: const_cast<QPlainTextDocumentLayout*>(this)->layoutBlock(block); | 0 | ||||||||||||||||||||||||
215 | } never executed: end of block | 0 | ||||||||||||||||||||||||
216 | - | |||||||||||||||||||||||||
217 | - | |||||||||||||||||||||||||
218 | /*! \property QPlainTextDocumentLayout::cursorWidth | - | ||||||||||||||||||||||||
219 | - | |||||||||||||||||||||||||
220 | This property specifies the width of the cursor in pixels. The default value is 1. | - | ||||||||||||||||||||||||
221 | */ | - | ||||||||||||||||||||||||
222 | void QPlainTextDocumentLayout::setCursorWidth(int width) | - | ||||||||||||||||||||||||
223 | { | - | ||||||||||||||||||||||||
224 | Q_D(QPlainTextDocumentLayout); | - | ||||||||||||||||||||||||
225 | d->cursorWidth = width; | - | ||||||||||||||||||||||||
226 | } never executed: end of block | 0 | ||||||||||||||||||||||||
227 | - | |||||||||||||||||||||||||
228 | int QPlainTextDocumentLayout::cursorWidth() const | - | ||||||||||||||||||||||||
229 | { | - | ||||||||||||||||||||||||
230 | Q_D(const QPlainTextDocumentLayout); | - | ||||||||||||||||||||||||
231 | return d->cursorWidth; never executed: return d->cursorWidth; | 0 | ||||||||||||||||||||||||
232 | } | - | ||||||||||||||||||||||||
233 | - | |||||||||||||||||||||||||
234 | QPlainTextDocumentLayoutPrivate *QPlainTextDocumentLayout::priv() const | - | ||||||||||||||||||||||||
235 | { | - | ||||||||||||||||||||||||
236 | Q_D(const QPlainTextDocumentLayout); | - | ||||||||||||||||||||||||
237 | return const_cast<QPlainTextDocumentLayoutPrivate*>(d); never executed: return const_cast<QPlainTextDocumentLayoutPrivate*>(d); | 0 | ||||||||||||||||||||||||
238 | } | - | ||||||||||||||||||||||||
239 | - | |||||||||||||||||||||||||
240 | - | |||||||||||||||||||||||||
241 | /*! | - | ||||||||||||||||||||||||
242 | - | |||||||||||||||||||||||||
243 | Requests a complete update on all views. | - | ||||||||||||||||||||||||
244 | */ | - | ||||||||||||||||||||||||
245 | void QPlainTextDocumentLayout::requestUpdate() | - | ||||||||||||||||||||||||
246 | { | - | ||||||||||||||||||||||||
247 | emit update(QRectF(0., -document()->documentMargin(), 1000000000., 1000000000.)); | - | ||||||||||||||||||||||||
248 | } never executed: end of block | 0 | ||||||||||||||||||||||||
249 | - | |||||||||||||||||||||||||
250 | - | |||||||||||||||||||||||||
251 | void QPlainTextDocumentLayout::setTextWidth(qreal newWidth) | - | ||||||||||||||||||||||||
252 | { | - | ||||||||||||||||||||||||
253 | Q_D(QPlainTextDocumentLayout); | - | ||||||||||||||||||||||||
254 | d->width = d->maximumWidth = newWidth; | - | ||||||||||||||||||||||||
255 | d->relayout(); | - | ||||||||||||||||||||||||
256 | } never executed: end of block | 0 | ||||||||||||||||||||||||
257 | - | |||||||||||||||||||||||||
258 | qreal QPlainTextDocumentLayout::textWidth() const | - | ||||||||||||||||||||||||
259 | { | - | ||||||||||||||||||||||||
260 | Q_D(const QPlainTextDocumentLayout); | - | ||||||||||||||||||||||||
261 | return d->width; never executed: return d->width; | 0 | ||||||||||||||||||||||||
262 | } | - | ||||||||||||||||||||||||
263 | - | |||||||||||||||||||||||||
264 | void QPlainTextDocumentLayoutPrivate::relayout() | - | ||||||||||||||||||||||||
265 | { | - | ||||||||||||||||||||||||
266 | Q_Q(QPlainTextDocumentLayout); | - | ||||||||||||||||||||||||
267 | QTextBlock block = q->document()->firstBlock(); | - | ||||||||||||||||||||||||
268 | while (block.isValid()) {
| 0 | ||||||||||||||||||||||||
269 | block.layout()->clearLayout(); | - | ||||||||||||||||||||||||
270 | block.setLineCount(block.isVisible() ? 1 : 0); | - | ||||||||||||||||||||||||
271 | block = block.next(); | - | ||||||||||||||||||||||||
272 | } never executed: end of block | 0 | ||||||||||||||||||||||||
273 | emit q->update(); | - | ||||||||||||||||||||||||
274 | } never executed: end of block | 0 | ||||||||||||||||||||||||
275 | - | |||||||||||||||||||||||||
276 | - | |||||||||||||||||||||||||
277 | /*! \reimp | - | ||||||||||||||||||||||||
278 | */ | - | ||||||||||||||||||||||||
279 | void QPlainTextDocumentLayout::documentChanged(int from, int charsRemoved, int charsAdded) | - | ||||||||||||||||||||||||
280 | { | - | ||||||||||||||||||||||||
281 | Q_D(QPlainTextDocumentLayout); | - | ||||||||||||||||||||||||
282 | QTextDocument *doc = document(); | - | ||||||||||||||||||||||||
283 | int newBlockCount = doc->blockCount(); | - | ||||||||||||||||||||||||
284 | int charsChanged = charsRemoved + charsAdded; | - | ||||||||||||||||||||||||
285 | - | |||||||||||||||||||||||||
286 | QTextBlock changeStartBlock = doc->findBlock(from); | - | ||||||||||||||||||||||||
287 | QTextBlock changeEndBlock = doc->findBlock(qMax(0, from + charsChanged - 1)); | - | ||||||||||||||||||||||||
288 | - | |||||||||||||||||||||||||
289 | if (changeStartBlock == changeEndBlock && newBlockCount == d->blockCount) {
| 0 | ||||||||||||||||||||||||
290 | QTextBlock block = changeStartBlock; | - | ||||||||||||||||||||||||
291 | if (block.isValid() && block.length()) {
| 0 | ||||||||||||||||||||||||
292 | QRectF oldBr = blockBoundingRect(block); | - | ||||||||||||||||||||||||
293 | layoutBlock(block); | - | ||||||||||||||||||||||||
294 | QRectF newBr = blockBoundingRect(block); | - | ||||||||||||||||||||||||
295 | if (newBr.height() == oldBr.height()) {
| 0 | ||||||||||||||||||||||||
296 | if (!d->blockUpdate)
| 0 | ||||||||||||||||||||||||
297 | emit updateBlock(block); never executed: updateBlock(block); | 0 | ||||||||||||||||||||||||
298 | return; never executed: return; | 0 | ||||||||||||||||||||||||
299 | } | - | ||||||||||||||||||||||||
300 | } never executed: end of block | 0 | ||||||||||||||||||||||||
301 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
302 | QTextBlock block = changeStartBlock; | - | ||||||||||||||||||||||||
303 | do { | - | ||||||||||||||||||||||||
304 | block.clearLayout(); | - | ||||||||||||||||||||||||
305 | if (block == changeEndBlock)
| 0 | ||||||||||||||||||||||||
306 | break; never executed: break; | 0 | ||||||||||||||||||||||||
307 | block = block.next(); | - | ||||||||||||||||||||||||
308 | } while(block.isValid()); never executed: end of block
| 0 | ||||||||||||||||||||||||
309 | } never executed: end of block | 0 | ||||||||||||||||||||||||
310 | - | |||||||||||||||||||||||||
311 | if (newBlockCount != d->blockCount) {
| 0 | ||||||||||||||||||||||||
312 | - | |||||||||||||||||||||||||
313 | int changeEnd = changeEndBlock.blockNumber(); | - | ||||||||||||||||||||||||
314 | int blockDiff = newBlockCount - d->blockCount; | - | ||||||||||||||||||||||||
315 | int oldChangeEnd = changeEnd - blockDiff; | - | ||||||||||||||||||||||||
316 | - | |||||||||||||||||||||||||
317 | if (d->maximumWidthBlockNumber > oldChangeEnd)
| 0 | ||||||||||||||||||||||||
318 | d->maximumWidthBlockNumber += blockDiff; never executed: d->maximumWidthBlockNumber += blockDiff; | 0 | ||||||||||||||||||||||||
319 | - | |||||||||||||||||||||||||
320 | d->blockCount = newBlockCount; | - | ||||||||||||||||||||||||
321 | if (d->blockCount == 1)
| 0 | ||||||||||||||||||||||||
322 | d->maximumWidth = blockWidth(doc->firstBlock()); never executed: d->maximumWidth = blockWidth(doc->firstBlock()); | 0 | ||||||||||||||||||||||||
323 | - | |||||||||||||||||||||||||
324 | if (!d->blockDocumentSizeChanged)
| 0 | ||||||||||||||||||||||||
325 | emit documentSizeChanged(documentSize()); never executed: documentSizeChanged(documentSize()); | 0 | ||||||||||||||||||||||||
326 | - | |||||||||||||||||||||||||
327 | if (blockDiff == 1 && changeEnd == newBlockCount -1 ) {
| 0 | ||||||||||||||||||||||||
328 | if (!d->blockUpdate) {
| 0 | ||||||||||||||||||||||||
329 | QTextBlock b = changeStartBlock; | - | ||||||||||||||||||||||||
330 | for(;;) { | - | ||||||||||||||||||||||||
331 | emit updateBlock(b); | - | ||||||||||||||||||||||||
332 | if (b == changeEndBlock)
| 0 | ||||||||||||||||||||||||
333 | break; never executed: break; | 0 | ||||||||||||||||||||||||
334 | b = b.next(); | - | ||||||||||||||||||||||||
335 | } never executed: end of block | 0 | ||||||||||||||||||||||||
336 | } never executed: end of block | 0 | ||||||||||||||||||||||||
337 | return; never executed: return; | 0 | ||||||||||||||||||||||||
338 | } | - | ||||||||||||||||||||||||
339 | } never executed: end of block | 0 | ||||||||||||||||||||||||
340 | - | |||||||||||||||||||||||||
341 | if (!d->blockUpdate)
| 0 | ||||||||||||||||||||||||
342 | emit update(QRectF(0., -doc->documentMargin(), 1000000000., 1000000000.)); // optimization potential never executed: update(QRectF(0., -doc->documentMargin(), 1000000000., 1000000000.)); | 0 | ||||||||||||||||||||||||
343 | } never executed: end of block | 0 | ||||||||||||||||||||||||
344 | - | |||||||||||||||||||||||||
345 | - | |||||||||||||||||||||||||
346 | void QPlainTextDocumentLayout::layoutBlock(const QTextBlock &block) | - | ||||||||||||||||||||||||
347 | { | - | ||||||||||||||||||||||||
348 | Q_D(QPlainTextDocumentLayout); | - | ||||||||||||||||||||||||
349 | QTextDocument *doc = document(); | - | ||||||||||||||||||||||||
350 | qreal margin = doc->documentMargin(); | - | ||||||||||||||||||||||||
351 | qreal blockMaximumWidth = 0; | - | ||||||||||||||||||||||||
352 | - | |||||||||||||||||||||||||
353 | qreal height = 0; | - | ||||||||||||||||||||||||
354 | QTextLayout *tl = block.layout(); | - | ||||||||||||||||||||||||
355 | QTextOption option = doc->defaultTextOption(); | - | ||||||||||||||||||||||||
356 | tl->setTextOption(option); | - | ||||||||||||||||||||||||
357 | - | |||||||||||||||||||||||||
358 | int extraMargin = 0; | - | ||||||||||||||||||||||||
359 | if (option.flags() & QTextOption::AddSpaceForLineAndParagraphSeparators) {
| 0 | ||||||||||||||||||||||||
360 | QFontMetrics fm(block.charFormat().font()); | - | ||||||||||||||||||||||||
361 | extraMargin += fm.width(QChar(0x21B5)); | - | ||||||||||||||||||||||||
362 | } never executed: end of block | 0 | ||||||||||||||||||||||||
363 | tl->beginLayout(); | - | ||||||||||||||||||||||||
364 | qreal availableWidth = d->width; | - | ||||||||||||||||||||||||
365 | if (availableWidth <= 0) {
| 0 | ||||||||||||||||||||||||
366 | availableWidth = qreal(INT_MAX); // similar to text edit with pageSize.width == 0 | - | ||||||||||||||||||||||||
367 | } never executed: end of block | 0 | ||||||||||||||||||||||||
368 | availableWidth -= 2*margin + extraMargin; | - | ||||||||||||||||||||||||
369 | while (1) { | - | ||||||||||||||||||||||||
370 | QTextLine line = tl->createLine(); | - | ||||||||||||||||||||||||
371 | if (!line.isValid())
| 0 | ||||||||||||||||||||||||
372 | break; never executed: break; | 0 | ||||||||||||||||||||||||
373 | line.setLeadingIncluded(true); | - | ||||||||||||||||||||||||
374 | line.setLineWidth(availableWidth); | - | ||||||||||||||||||||||||
375 | line.setPosition(QPointF(margin, height)); | - | ||||||||||||||||||||||||
376 | height += line.height(); | - | ||||||||||||||||||||||||
377 | blockMaximumWidth = qMax(blockMaximumWidth, line.naturalTextWidth() + 2*margin); | - | ||||||||||||||||||||||||
378 | } never executed: end of block | 0 | ||||||||||||||||||||||||
379 | tl->endLayout(); | - | ||||||||||||||||||||||||
380 | - | |||||||||||||||||||||||||
381 | int previousLineCount = doc->lineCount(); | - | ||||||||||||||||||||||||
382 | const_cast<QTextBlock&>(block).setLineCount(block.isVisible() ? tl->lineCount() : 0); | - | ||||||||||||||||||||||||
383 | int lineCount = doc->lineCount(); | - | ||||||||||||||||||||||||
384 | - | |||||||||||||||||||||||||
385 | bool emitDocumentSizeChanged = previousLineCount != lineCount; | - | ||||||||||||||||||||||||
386 | if (blockMaximumWidth > d->maximumWidth) {
| 0 | ||||||||||||||||||||||||
387 | // new longest line | - | ||||||||||||||||||||||||
388 | d->maximumWidth = blockMaximumWidth; | - | ||||||||||||||||||||||||
389 | d->maximumWidthBlockNumber = block.blockNumber(); | - | ||||||||||||||||||||||||
390 | emitDocumentSizeChanged = true; | - | ||||||||||||||||||||||||
391 | } else if (block.blockNumber() == d->maximumWidthBlockNumber && blockMaximumWidth < d->maximumWidth) { never executed: end of block
| 0 | ||||||||||||||||||||||||
392 | // longest line shrinking | - | ||||||||||||||||||||||||
393 | QTextBlock b = doc->firstBlock(); | - | ||||||||||||||||||||||||
394 | d->maximumWidth = 0; | - | ||||||||||||||||||||||||
395 | QTextBlock maximumBlock; | - | ||||||||||||||||||||||||
396 | while (b.isValid()) {
| 0 | ||||||||||||||||||||||||
397 | qreal blockMaximumWidth = blockWidth(b); | - | ||||||||||||||||||||||||
398 | if (blockMaximumWidth > d->maximumWidth) {
| 0 | ||||||||||||||||||||||||
399 | d->maximumWidth = blockMaximumWidth; | - | ||||||||||||||||||||||||
400 | maximumBlock = b; | - | ||||||||||||||||||||||||
401 | } never executed: end of block | 0 | ||||||||||||||||||||||||
402 | b = b.next(); | - | ||||||||||||||||||||||||
403 | } never executed: end of block | 0 | ||||||||||||||||||||||||
404 | if (maximumBlock.isValid()) {
| 0 | ||||||||||||||||||||||||
405 | d->maximumWidthBlockNumber = maximumBlock.blockNumber(); | - | ||||||||||||||||||||||||
406 | emitDocumentSizeChanged = true; | - | ||||||||||||||||||||||||
407 | } never executed: end of block | 0 | ||||||||||||||||||||||||
408 | } never executed: end of block | 0 | ||||||||||||||||||||||||
409 | if (emitDocumentSizeChanged && !d->blockDocumentSizeChanged)
| 0 | ||||||||||||||||||||||||
410 | emit documentSizeChanged(documentSize()); never executed: documentSizeChanged(documentSize()); | 0 | ||||||||||||||||||||||||
411 | } never executed: end of block | 0 | ||||||||||||||||||||||||
412 | - | |||||||||||||||||||||||||
413 | qreal QPlainTextDocumentLayout::blockWidth(const QTextBlock &block) | - | ||||||||||||||||||||||||
414 | { | - | ||||||||||||||||||||||||
415 | QTextLayout *layout = block.layout(); | - | ||||||||||||||||||||||||
416 | if (!layout->lineCount())
| 0 | ||||||||||||||||||||||||
417 | return 0; // only for layouted blocks never executed: return 0; | 0 | ||||||||||||||||||||||||
418 | qreal blockWidth = 0; | - | ||||||||||||||||||||||||
419 | for (int i = 0; i < layout->lineCount(); ++i) {
| 0 | ||||||||||||||||||||||||
420 | QTextLine line = layout->lineAt(i); | - | ||||||||||||||||||||||||
421 | blockWidth = qMax(line.naturalTextWidth() + 8, blockWidth); | - | ||||||||||||||||||||||||
422 | } never executed: end of block | 0 | ||||||||||||||||||||||||
423 | return blockWidth; never executed: return blockWidth; | 0 | ||||||||||||||||||||||||
424 | } | - | ||||||||||||||||||||||||
425 | - | |||||||||||||||||||||||||
426 | - | |||||||||||||||||||||||||
427 | QPlainTextEditControl::QPlainTextEditControl(QPlainTextEdit *parent) | - | ||||||||||||||||||||||||
428 | : QWidgetTextControl(parent), textEdit(parent), | - | ||||||||||||||||||||||||
429 | topBlock(0) | - | ||||||||||||||||||||||||
430 | { | - | ||||||||||||||||||||||||
431 | setAcceptRichText(false); | - | ||||||||||||||||||||||||
432 | } never executed: end of block | 0 | ||||||||||||||||||||||||
433 | - | |||||||||||||||||||||||||
434 | void QPlainTextEditPrivate::_q_cursorPositionChanged() | - | ||||||||||||||||||||||||
435 | { | - | ||||||||||||||||||||||||
436 | pageUpDownLastCursorYIsValid = false; | - | ||||||||||||||||||||||||
437 | Q_Q(QPlainTextEdit); | - | ||||||||||||||||||||||||
438 | #ifndef QT_NO_ACCESSIBILITY | - | ||||||||||||||||||||||||
439 | QAccessibleTextCursorEvent ev(q, q->textCursor().position()); | - | ||||||||||||||||||||||||
440 | QAccessible::updateAccessibility(&ev); | - | ||||||||||||||||||||||||
441 | #endif | - | ||||||||||||||||||||||||
442 | emit q->cursorPositionChanged(); | - | ||||||||||||||||||||||||
443 | } never executed: end of block | 0 | ||||||||||||||||||||||||
444 | - | |||||||||||||||||||||||||
445 | void QPlainTextEditPrivate::_q_verticalScrollbarActionTriggered(int action) { | - | ||||||||||||||||||||||||
446 | if (action == QAbstractSlider::SliderPageStepAdd) {
| 0 | ||||||||||||||||||||||||
447 | pageUpDown(QTextCursor::Down, QTextCursor::MoveAnchor, false); | - | ||||||||||||||||||||||||
448 | } else if (action == QAbstractSlider::SliderPageStepSub) { never executed: end of block
| 0 | ||||||||||||||||||||||||
449 | pageUpDown(QTextCursor::Up, QTextCursor::MoveAnchor, false); | - | ||||||||||||||||||||||||
450 | } never executed: end of block | 0 | ||||||||||||||||||||||||
451 | } never executed: end of block | 0 | ||||||||||||||||||||||||
452 | - | |||||||||||||||||||||||||
453 | QMimeData *QPlainTextEditControl::createMimeDataFromSelection() const { | - | ||||||||||||||||||||||||
454 | QPlainTextEdit *ed = qobject_cast<QPlainTextEdit *>(parent()); | - | ||||||||||||||||||||||||
455 | if (!ed)
| 0 | ||||||||||||||||||||||||
456 | return QWidgetTextControl::createMimeDataFromSelection(); never executed: return QWidgetTextControl::createMimeDataFromSelection(); | 0 | ||||||||||||||||||||||||
457 | return ed->createMimeDataFromSelection(); never executed: return ed->createMimeDataFromSelection(); | 0 | ||||||||||||||||||||||||
458 | } | - | ||||||||||||||||||||||||
459 | bool QPlainTextEditControl::canInsertFromMimeData(const QMimeData *source) const { | - | ||||||||||||||||||||||||
460 | QPlainTextEdit *ed = qobject_cast<QPlainTextEdit *>(parent()); | - | ||||||||||||||||||||||||
461 | if (!ed)
| 0 | ||||||||||||||||||||||||
462 | return QWidgetTextControl::canInsertFromMimeData(source); never executed: return QWidgetTextControl::canInsertFromMimeData(source); | 0 | ||||||||||||||||||||||||
463 | return ed->canInsertFromMimeData(source); never executed: return ed->canInsertFromMimeData(source); | 0 | ||||||||||||||||||||||||
464 | } | - | ||||||||||||||||||||||||
465 | void QPlainTextEditControl::insertFromMimeData(const QMimeData *source) { | - | ||||||||||||||||||||||||
466 | QPlainTextEdit *ed = qobject_cast<QPlainTextEdit *>(parent()); | - | ||||||||||||||||||||||||
467 | if (!ed)
| 0 | ||||||||||||||||||||||||
468 | QWidgetTextControl::insertFromMimeData(source); never executed: QWidgetTextControl::insertFromMimeData(source); | 0 | ||||||||||||||||||||||||
469 | else | - | ||||||||||||||||||||||||
470 | ed->insertFromMimeData(source); never executed: ed->insertFromMimeData(source); | 0 | ||||||||||||||||||||||||
471 | } | - | ||||||||||||||||||||||||
472 | - | |||||||||||||||||||||||||
473 | qreal QPlainTextEditPrivate::verticalOffset(int topBlock, int topLine) const | - | ||||||||||||||||||||||||
474 | { | - | ||||||||||||||||||||||||
475 | qreal offset = 0; | - | ||||||||||||||||||||||||
476 | QTextDocument *doc = control->document(); | - | ||||||||||||||||||||||||
477 | - | |||||||||||||||||||||||||
478 | if (topLine) {
| 0 | ||||||||||||||||||||||||
479 | QTextBlock currentBlock = doc->findBlockByNumber(topBlock); | - | ||||||||||||||||||||||||
480 | QPlainTextDocumentLayout *documentLayout = qobject_cast<QPlainTextDocumentLayout*>(doc->documentLayout()); | - | ||||||||||||||||||||||||
481 | Q_ASSERT(documentLayout); | - | ||||||||||||||||||||||||
482 | QRectF r = documentLayout->blockBoundingRect(currentBlock); | - | ||||||||||||||||||||||||
483 | Q_UNUSED(r); | - | ||||||||||||||||||||||||
484 | QTextLayout *layout = currentBlock.layout(); | - | ||||||||||||||||||||||||
485 | if (layout && topLine <= layout->lineCount()) {
| 0 | ||||||||||||||||||||||||
486 | QTextLine line = layout->lineAt(topLine - 1); | - | ||||||||||||||||||||||||
487 | const QRectF lr = line.naturalTextRect(); | - | ||||||||||||||||||||||||
488 | offset = lr.bottom(); | - | ||||||||||||||||||||||||
489 | } never executed: end of block | 0 | ||||||||||||||||||||||||
490 | } never executed: end of block | 0 | ||||||||||||||||||||||||
491 | if (topBlock == 0 && topLine == 0)
| 0 | ||||||||||||||||||||||||
492 | offset -= doc->documentMargin(); // top margin never executed: offset -= doc->documentMargin(); | 0 | ||||||||||||||||||||||||
493 | return offset; never executed: return offset; | 0 | ||||||||||||||||||||||||
494 | } | - | ||||||||||||||||||||||||
495 | - | |||||||||||||||||||||||||
496 | - | |||||||||||||||||||||||||
497 | qreal QPlainTextEditPrivate::verticalOffset() const { | - | ||||||||||||||||||||||||
498 | return verticalOffset(control->topBlock, topLine) + topLineFracture; never executed: return verticalOffset(control->topBlock, topLine) + topLineFracture; | 0 | ||||||||||||||||||||||||
499 | } | - | ||||||||||||||||||||||||
500 | - | |||||||||||||||||||||||||
501 | - | |||||||||||||||||||||||||
502 | QTextBlock QPlainTextEditControl::firstVisibleBlock() const | - | ||||||||||||||||||||||||
503 | { | - | ||||||||||||||||||||||||
504 | return document()->findBlockByNumber(topBlock); never executed: return document()->findBlockByNumber(topBlock); | 0 | ||||||||||||||||||||||||
505 | } | - | ||||||||||||||||||||||||
506 | - | |||||||||||||||||||||||||
507 | - | |||||||||||||||||||||||||
508 | - | |||||||||||||||||||||||||
509 | int QPlainTextEditControl::hitTest(const QPointF &point, Qt::HitTestAccuracy ) const { | - | ||||||||||||||||||||||||
510 | int currentBlockNumber = topBlock; | - | ||||||||||||||||||||||||
511 | QTextBlock currentBlock = document()->findBlockByNumber(currentBlockNumber); | - | ||||||||||||||||||||||||
512 | if (!currentBlock.isValid())
| 0 | ||||||||||||||||||||||||
513 | return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||
514 | - | |||||||||||||||||||||||||
515 | QPlainTextDocumentLayout *documentLayout = qobject_cast<QPlainTextDocumentLayout*>(document()->documentLayout()); | - | ||||||||||||||||||||||||
516 | Q_ASSERT(documentLayout); | - | ||||||||||||||||||||||||
517 | - | |||||||||||||||||||||||||
518 | QPointF offset; | - | ||||||||||||||||||||||||
519 | QRectF r = documentLayout->blockBoundingRect(currentBlock); | - | ||||||||||||||||||||||||
520 | while (currentBlock.next().isValid() && r.bottom() + offset.y() <= point.y()) {
| 0 | ||||||||||||||||||||||||
521 | offset.ry() += r.height(); | - | ||||||||||||||||||||||||
522 | currentBlock = currentBlock.next(); | - | ||||||||||||||||||||||||
523 | ++currentBlockNumber; | - | ||||||||||||||||||||||||
524 | r = documentLayout->blockBoundingRect(currentBlock); | - | ||||||||||||||||||||||||
525 | } never executed: end of block | 0 | ||||||||||||||||||||||||
526 | while (currentBlock.previous().isValid() && r.top() + offset.y() > point.y()) {
| 0 | ||||||||||||||||||||||||
527 | offset.ry() -= r.height(); | - | ||||||||||||||||||||||||
528 | currentBlock = currentBlock.previous(); | - | ||||||||||||||||||||||||
529 | --currentBlockNumber; | - | ||||||||||||||||||||||||
530 | r = documentLayout->blockBoundingRect(currentBlock); | - | ||||||||||||||||||||||||
531 | } never executed: end of block | 0 | ||||||||||||||||||||||||
532 | - | |||||||||||||||||||||||||
533 | - | |||||||||||||||||||||||||
534 | if (!currentBlock.isValid())
| 0 | ||||||||||||||||||||||||
535 | return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||
536 | QTextLayout *layout = currentBlock.layout(); | - | ||||||||||||||||||||||||
537 | int off = 0; | - | ||||||||||||||||||||||||
538 | QPointF pos = point - offset; | - | ||||||||||||||||||||||||
539 | for (int i = 0; i < layout->lineCount(); ++i) {
| 0 | ||||||||||||||||||||||||
540 | QTextLine line = layout->lineAt(i); | - | ||||||||||||||||||||||||
541 | const QRectF lr = line.naturalTextRect(); | - | ||||||||||||||||||||||||
542 | if (lr.top() > pos.y()) {
| 0 | ||||||||||||||||||||||||
543 | off = qMin(off, line.textStart()); | - | ||||||||||||||||||||||||
544 | } else if (lr.bottom() <= pos.y()) { never executed: end of block
| 0 | ||||||||||||||||||||||||
545 | off = qMax(off, line.textStart() + line.textLength()); | - | ||||||||||||||||||||||||
546 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
547 | off = line.xToCursor(pos.x(), overwriteMode() ? | - | ||||||||||||||||||||||||
548 | QTextLine::CursorOnCharacter : QTextLine::CursorBetweenCharacters); | - | ||||||||||||||||||||||||
549 | break; never executed: break; | 0 | ||||||||||||||||||||||||
550 | } | - | ||||||||||||||||||||||||
551 | } | - | ||||||||||||||||||||||||
552 | - | |||||||||||||||||||||||||
553 | return currentBlock.position() + off; never executed: return currentBlock.position() + off; | 0 | ||||||||||||||||||||||||
554 | } | - | ||||||||||||||||||||||||
555 | - | |||||||||||||||||||||||||
556 | QRectF QPlainTextEditControl::blockBoundingRect(const QTextBlock &block) const { | - | ||||||||||||||||||||||||
557 | int currentBlockNumber = topBlock; | - | ||||||||||||||||||||||||
558 | int blockNumber = block.blockNumber(); | - | ||||||||||||||||||||||||
559 | QTextBlock currentBlock = document()->findBlockByNumber(currentBlockNumber); | - | ||||||||||||||||||||||||
560 | if (!currentBlock.isValid())
| 0 | ||||||||||||||||||||||||
561 | return QRectF(); never executed: return QRectF(); | 0 | ||||||||||||||||||||||||
562 | Q_ASSERT(currentBlock.blockNumber() == currentBlockNumber); | - | ||||||||||||||||||||||||
563 | QTextDocument *doc = document(); | - | ||||||||||||||||||||||||
564 | QPlainTextDocumentLayout *documentLayout = qobject_cast<QPlainTextDocumentLayout*>(doc->documentLayout()); | - | ||||||||||||||||||||||||
565 | Q_ASSERT(documentLayout); | - | ||||||||||||||||||||||||
566 | - | |||||||||||||||||||||||||
567 | QPointF offset; | - | ||||||||||||||||||||||||
568 | if (!block.isValid())
| 0 | ||||||||||||||||||||||||
569 | return QRectF(); never executed: return QRectF(); | 0 | ||||||||||||||||||||||||
570 | QRectF r = documentLayout->blockBoundingRect(currentBlock); | - | ||||||||||||||||||||||||
571 | int maxVerticalOffset = r.height(); | - | ||||||||||||||||||||||||
572 | while (currentBlockNumber < blockNumber && offset.y() - maxVerticalOffset <= 2* textEdit->viewport()->height()) {
| 0 | ||||||||||||||||||||||||
573 | offset.ry() += r.height(); | - | ||||||||||||||||||||||||
574 | currentBlock = currentBlock.next(); | - | ||||||||||||||||||||||||
575 | ++currentBlockNumber; | - | ||||||||||||||||||||||||
576 | if (!currentBlock.isVisible()) {
| 0 | ||||||||||||||||||||||||
577 | currentBlock = doc->findBlockByLineNumber(currentBlock.firstLineNumber()); | - | ||||||||||||||||||||||||
578 | currentBlockNumber = currentBlock.blockNumber(); | - | ||||||||||||||||||||||||
579 | } never executed: end of block | 0 | ||||||||||||||||||||||||
580 | r = documentLayout->blockBoundingRect(currentBlock); | - | ||||||||||||||||||||||||
581 | } never executed: end of block | 0 | ||||||||||||||||||||||||
582 | while (currentBlockNumber > blockNumber && offset.y() + maxVerticalOffset >= -textEdit->viewport()->height()) {
| 0 | ||||||||||||||||||||||||
583 | currentBlock = currentBlock.previous(); | - | ||||||||||||||||||||||||
584 | --currentBlockNumber; | - | ||||||||||||||||||||||||
585 | while (!currentBlock.isVisible()) {
| 0 | ||||||||||||||||||||||||
586 | currentBlock = currentBlock.previous(); | - | ||||||||||||||||||||||||
587 | --currentBlockNumber; | - | ||||||||||||||||||||||||
588 | } never executed: end of block | 0 | ||||||||||||||||||||||||
589 | if (!currentBlock.isValid())
| 0 | ||||||||||||||||||||||||
590 | break; never executed: break; | 0 | ||||||||||||||||||||||||
591 | - | |||||||||||||||||||||||||
592 | r = documentLayout->blockBoundingRect(currentBlock); | - | ||||||||||||||||||||||||
593 | offset.ry() -= r.height(); | - | ||||||||||||||||||||||||
594 | } never executed: end of block | 0 | ||||||||||||||||||||||||
595 | - | |||||||||||||||||||||||||
596 | if (currentBlockNumber != blockNumber) {
| 0 | ||||||||||||||||||||||||
597 | // fallback for blocks out of reach. Give it some geometry at | - | ||||||||||||||||||||||||
598 | // least, and ensure the layout is up to date. | - | ||||||||||||||||||||||||
599 | r = documentLayout->blockBoundingRect(block); | - | ||||||||||||||||||||||||
600 | if (currentBlockNumber > blockNumber)
| 0 | ||||||||||||||||||||||||
601 | offset.ry() -= r.height(); never executed: offset.ry() -= r.height(); | 0 | ||||||||||||||||||||||||
602 | } never executed: end of block | 0 | ||||||||||||||||||||||||
603 | r.translate(offset); | - | ||||||||||||||||||||||||
604 | return r; never executed: return r; | 0 | ||||||||||||||||||||||||
605 | } | - | ||||||||||||||||||||||||
606 | - | |||||||||||||||||||||||||
607 | QString QPlainTextEditControl::anchorAt(const QPointF &pos) const | - | ||||||||||||||||||||||||
608 | { | - | ||||||||||||||||||||||||
609 | return textEdit->anchorAt(pos.toPoint()); never executed: return textEdit->anchorAt(pos.toPoint()); | 0 | ||||||||||||||||||||||||
610 | } | - | ||||||||||||||||||||||||
611 | - | |||||||||||||||||||||||||
612 | void QPlainTextEditPrivate::setTopLine(int visualTopLine, int dx) | - | ||||||||||||||||||||||||
613 | { | - | ||||||||||||||||||||||||
614 | QTextDocument *doc = control->document(); | - | ||||||||||||||||||||||||
615 | QTextBlock block = doc->findBlockByLineNumber(visualTopLine); | - | ||||||||||||||||||||||||
616 | int blockNumber = block.blockNumber(); | - | ||||||||||||||||||||||||
617 | int lineNumber = visualTopLine - block.firstLineNumber(); | - | ||||||||||||||||||||||||
618 | setTopBlock(blockNumber, lineNumber, dx); | - | ||||||||||||||||||||||||
619 | } never executed: end of block | 0 | ||||||||||||||||||||||||
620 | - | |||||||||||||||||||||||||
621 | void QPlainTextEditPrivate::setTopBlock(int blockNumber, int lineNumber, int dx) | - | ||||||||||||||||||||||||
622 | { | - | ||||||||||||||||||||||||
623 | Q_Q(QPlainTextEdit); | - | ||||||||||||||||||||||||
624 | blockNumber = qMax(0, blockNumber); | - | ||||||||||||||||||||||||
625 | lineNumber = qMax(0, lineNumber); | - | ||||||||||||||||||||||||
626 | QTextDocument *doc = control->document(); | - | ||||||||||||||||||||||||
627 | QTextBlock block = doc->findBlockByNumber(blockNumber); | - | ||||||||||||||||||||||||
628 | - | |||||||||||||||||||||||||
629 | int newTopLine = block.firstLineNumber() + lineNumber; | - | ||||||||||||||||||||||||
630 | int maxTopLine = vbar->maximum(); | - | ||||||||||||||||||||||||
631 | - | |||||||||||||||||||||||||
632 | if (newTopLine > maxTopLine) {
| 0 | ||||||||||||||||||||||||
633 | block = doc->findBlockByLineNumber(maxTopLine); | - | ||||||||||||||||||||||||
634 | blockNumber = block.blockNumber(); | - | ||||||||||||||||||||||||
635 | lineNumber = maxTopLine - block.firstLineNumber(); | - | ||||||||||||||||||||||||
636 | } never executed: end of block | 0 | ||||||||||||||||||||||||
637 | - | |||||||||||||||||||||||||
638 | { | - | ||||||||||||||||||||||||
639 | const QSignalBlocker blocker(vbar); | - | ||||||||||||||||||||||||
640 | vbar->setValue(newTopLine); | - | ||||||||||||||||||||||||
641 | } | - | ||||||||||||||||||||||||
642 | - | |||||||||||||||||||||||||
643 | if (!dx && blockNumber == control->topBlock && lineNumber == topLine)
| 0 | ||||||||||||||||||||||||
644 | return; never executed: return; | 0 | ||||||||||||||||||||||||
645 | - | |||||||||||||||||||||||||
646 | if (viewport->updatesEnabled() && viewport->isVisible()) {
| 0 | ||||||||||||||||||||||||
647 | int dy = 0; | - | ||||||||||||||||||||||||
648 | if (doc->findBlockByNumber(control->topBlock).isValid()) {
| 0 | ||||||||||||||||||||||||
649 | qreal realdy = -q->blockBoundingGeometry(block).y() | - | ||||||||||||||||||||||||
650 | + verticalOffset() - verticalOffset(blockNumber, lineNumber); | - | ||||||||||||||||||||||||
651 | dy = (int)realdy; | - | ||||||||||||||||||||||||
652 | topLineFracture = realdy - dy; | - | ||||||||||||||||||||||||
653 | } never executed: end of block | 0 | ||||||||||||||||||||||||
654 | control->topBlock = blockNumber; | - | ||||||||||||||||||||||||
655 | topLine = lineNumber; | - | ||||||||||||||||||||||||
656 | - | |||||||||||||||||||||||||
657 | { | - | ||||||||||||||||||||||||
658 | const QSignalBlocker blocker(vbar); | - | ||||||||||||||||||||||||
659 | vbar->setValue(block.firstLineNumber() + lineNumber); | - | ||||||||||||||||||||||||
660 | } | - | ||||||||||||||||||||||||
661 | - | |||||||||||||||||||||||||
662 | if (dx || dy) {
| 0 | ||||||||||||||||||||||||
663 | viewport->scroll(q->isRightToLeft() ? -dx : dx, dy); | - | ||||||||||||||||||||||||
664 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
665 | viewport->update(); | - | ||||||||||||||||||||||||
666 | topLineFracture = 0; | - | ||||||||||||||||||||||||
667 | } never executed: end of block | 0 | ||||||||||||||||||||||||
668 | emit q->updateRequest(viewport->rect(), dy); | - | ||||||||||||||||||||||||
669 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
670 | control->topBlock = blockNumber; | - | ||||||||||||||||||||||||
671 | topLine = lineNumber; | - | ||||||||||||||||||||||||
672 | topLineFracture = 0; | - | ||||||||||||||||||||||||
673 | } never executed: end of block | 0 | ||||||||||||||||||||||||
674 | - | |||||||||||||||||||||||||
675 | } | - | ||||||||||||||||||||||||
676 | - | |||||||||||||||||||||||||
677 | - | |||||||||||||||||||||||||
678 | - | |||||||||||||||||||||||||
679 | void QPlainTextEditPrivate::ensureVisible(int position, bool center, bool forceCenter) { | - | ||||||||||||||||||||||||
680 | Q_Q(QPlainTextEdit); | - | ||||||||||||||||||||||||
681 | QRectF visible = QRectF(viewport->rect()).translated(-q->contentOffset()); | - | ||||||||||||||||||||||||
682 | QTextBlock block = control->document()->findBlock(position); | - | ||||||||||||||||||||||||
683 | if (!block.isValid())
| 0 | ||||||||||||||||||||||||
684 | return; never executed: return; | 0 | ||||||||||||||||||||||||
685 | QRectF br = control->blockBoundingRect(block); | - | ||||||||||||||||||||||||
686 | if (!br.isValid())
| 0 | ||||||||||||||||||||||||
687 | return; never executed: return; | 0 | ||||||||||||||||||||||||
688 | QTextLine line = block.layout()->lineForTextPosition(position - block.position()); | - | ||||||||||||||||||||||||
689 | Q_ASSERT(line.isValid()); | - | ||||||||||||||||||||||||
690 | QRectF lr = line.naturalTextRect().translated(br.topLeft()); | - | ||||||||||||||||||||||||
691 | - | |||||||||||||||||||||||||
692 | if (lr.bottom() >= visible.bottom() || (center && lr.top() < visible.top()) || forceCenter){
| 0 | ||||||||||||||||||||||||
693 | - | |||||||||||||||||||||||||
694 | qreal height = visible.height(); | - | ||||||||||||||||||||||||
695 | if (center)
| 0 | ||||||||||||||||||||||||
696 | height /= 2; never executed: height /= 2; | 0 | ||||||||||||||||||||||||
697 | - | |||||||||||||||||||||||||
698 | qreal h = center ? line.naturalTextRect().center().y() : line.naturalTextRect().bottom();
| 0 | ||||||||||||||||||||||||
699 | - | |||||||||||||||||||||||||
700 | QTextBlock previousVisibleBlock = block; | - | ||||||||||||||||||||||||
701 | while (h < height && block.previous().isValid()) {
| 0 | ||||||||||||||||||||||||
702 | previousVisibleBlock = block; | - | ||||||||||||||||||||||||
703 | do { | - | ||||||||||||||||||||||||
704 | block = block.previous(); | - | ||||||||||||||||||||||||
705 | } while (!block.isVisible() && block.previous().isValid()); never executed: end of block
| 0 | ||||||||||||||||||||||||
706 | h += q->blockBoundingRect(block).height(); | - | ||||||||||||||||||||||||
707 | } never executed: end of block | 0 | ||||||||||||||||||||||||
708 | - | |||||||||||||||||||||||||
709 | int l = 0; | - | ||||||||||||||||||||||||
710 | int lineCount = block.layout()->lineCount(); | - | ||||||||||||||||||||||||
711 | qreal voffset = verticalOffset(block.blockNumber(), 0); | - | ||||||||||||||||||||||||
712 | while (l < lineCount) {
| 0 | ||||||||||||||||||||||||
713 | QRectF lineRect = block.layout()->lineAt(l).naturalTextRect(); | - | ||||||||||||||||||||||||
714 | if (h - voffset - lineRect.top() <= height)
| 0 | ||||||||||||||||||||||||
715 | break; never executed: break; | 0 | ||||||||||||||||||||||||
716 | ++l; | - | ||||||||||||||||||||||||
717 | } never executed: end of block | 0 | ||||||||||||||||||||||||
718 | - | |||||||||||||||||||||||||
719 | if (l >= lineCount) {
| 0 | ||||||||||||||||||||||||
720 | block = previousVisibleBlock; | - | ||||||||||||||||||||||||
721 | l = 0; | - | ||||||||||||||||||||||||
722 | } never executed: end of block | 0 | ||||||||||||||||||||||||
723 | setTopBlock(block.blockNumber(), l); | - | ||||||||||||||||||||||||
724 | } else if (lr.top() < visible.top()) { never executed: end of block
| 0 | ||||||||||||||||||||||||
725 | setTopBlock(block.blockNumber(), line.lineNumber()); | - | ||||||||||||||||||||||||
726 | } never executed: end of block | 0 | ||||||||||||||||||||||||
727 | - | |||||||||||||||||||||||||
728 | } never executed: end of block | 0 | ||||||||||||||||||||||||
729 | - | |||||||||||||||||||||||||
730 | - | |||||||||||||||||||||||||
731 | void QPlainTextEditPrivate::updateViewport() | - | ||||||||||||||||||||||||
732 | { | - | ||||||||||||||||||||||||
733 | Q_Q(QPlainTextEdit); | - | ||||||||||||||||||||||||
734 | viewport->update(); | - | ||||||||||||||||||||||||
735 | emit q->updateRequest(viewport->rect(), 0); | - | ||||||||||||||||||||||||
736 | } never executed: end of block | 0 | ||||||||||||||||||||||||
737 | - | |||||||||||||||||||||||||
738 | QPlainTextEditPrivate::QPlainTextEditPrivate() | - | ||||||||||||||||||||||||
739 | : control(0), | - | ||||||||||||||||||||||||
740 | tabChangesFocus(false), | - | ||||||||||||||||||||||||
741 | lineWrap(QPlainTextEdit::WidgetWidth), | - | ||||||||||||||||||||||||
742 | wordWrap(QTextOption::WrapAtWordBoundaryOrAnywhere), | - | ||||||||||||||||||||||||
743 | clickCausedFocus(0),topLine(0),topLineFracture(0), | - | ||||||||||||||||||||||||
744 | pageUpDownLastCursorYIsValid(false) | - | ||||||||||||||||||||||||
745 | { | - | ||||||||||||||||||||||||
746 | showCursorOnInitialShow = true; | - | ||||||||||||||||||||||||
747 | backgroundVisible = false; | - | ||||||||||||||||||||||||
748 | centerOnScroll = false; | - | ||||||||||||||||||||||||
749 | inDrag = false; | - | ||||||||||||||||||||||||
750 | } never executed: end of block | 0 | ||||||||||||||||||||||||
751 | - | |||||||||||||||||||||||||
752 | - | |||||||||||||||||||||||||
753 | void QPlainTextEditPrivate::init(const QString &txt) | - | ||||||||||||||||||||||||
754 | { | - | ||||||||||||||||||||||||
755 | Q_Q(QPlainTextEdit); | - | ||||||||||||||||||||||||
756 | control = new QPlainTextEditControl(q); | - | ||||||||||||||||||||||||
757 | - | |||||||||||||||||||||||||
758 | QTextDocument *doc = new QTextDocument(control); | - | ||||||||||||||||||||||||
759 | QAbstractTextDocumentLayout *layout = new QPlainTextDocumentLayout(doc); | - | ||||||||||||||||||||||||
760 | doc->setDocumentLayout(layout); | - | ||||||||||||||||||||||||
761 | control->setDocument(doc); | - | ||||||||||||||||||||||||
762 | - | |||||||||||||||||||||||||
763 | control->setPalette(q->palette()); | - | ||||||||||||||||||||||||
764 | - | |||||||||||||||||||||||||
765 | QObject::connect(vbar, SIGNAL(actionTriggered(int)), q, SLOT(_q_verticalScrollbarActionTriggered(int))); | - | ||||||||||||||||||||||||
766 | - | |||||||||||||||||||||||||
767 | QObject::connect(control, SIGNAL(microFocusChanged()), q, SLOT(updateMicroFocus())); | - | ||||||||||||||||||||||||
768 | QObject::connect(control, SIGNAL(documentSizeChanged(QSizeF)), q, SLOT(_q_adjustScrollbars())); | - | ||||||||||||||||||||||||
769 | QObject::connect(control, SIGNAL(blockCountChanged(int)), q, SIGNAL(blockCountChanged(int))); | - | ||||||||||||||||||||||||
770 | QObject::connect(control, SIGNAL(updateRequest(QRectF)), q, SLOT(_q_repaintContents(QRectF))); | - | ||||||||||||||||||||||||
771 | QObject::connect(control, SIGNAL(modificationChanged(bool)), q, SIGNAL(modificationChanged(bool))); | - | ||||||||||||||||||||||||
772 | - | |||||||||||||||||||||||||
773 | QObject::connect(control, SIGNAL(textChanged()), q, SIGNAL(textChanged())); | - | ||||||||||||||||||||||||
774 | QObject::connect(control, SIGNAL(undoAvailable(bool)), q, SIGNAL(undoAvailable(bool))); | - | ||||||||||||||||||||||||
775 | QObject::connect(control, SIGNAL(redoAvailable(bool)), q, SIGNAL(redoAvailable(bool))); | - | ||||||||||||||||||||||||
776 | QObject::connect(control, SIGNAL(copyAvailable(bool)), q, SIGNAL(copyAvailable(bool))); | - | ||||||||||||||||||||||||
777 | QObject::connect(control, SIGNAL(selectionChanged()), q, SIGNAL(selectionChanged())); | - | ||||||||||||||||||||||||
778 | QObject::connect(control, SIGNAL(cursorPositionChanged()), q, SLOT(_q_cursorPositionChanged())); | - | ||||||||||||||||||||||||
779 | - | |||||||||||||||||||||||||
780 | QObject::connect(control, SIGNAL(textChanged()), q, SLOT(updateMicroFocus())); | - | ||||||||||||||||||||||||
781 | - | |||||||||||||||||||||||||
782 | // set a null page size initially to avoid any relayouting until the textedit | - | ||||||||||||||||||||||||
783 | // is shown. relayoutDocument() will take care of setting the page size to the | - | ||||||||||||||||||||||||
784 | // viewport dimensions later. | - | ||||||||||||||||||||||||
785 | doc->setTextWidth(-1); | - | ||||||||||||||||||||||||
786 | doc->documentLayout()->setPaintDevice(viewport); | - | ||||||||||||||||||||||||
787 | doc->setDefaultFont(q->font()); | - | ||||||||||||||||||||||||
788 | - | |||||||||||||||||||||||||
789 | - | |||||||||||||||||||||||||
790 | if (!txt.isEmpty())
| 0 | ||||||||||||||||||||||||
791 | control->setPlainText(txt); never executed: control->setPlainText(txt); | 0 | ||||||||||||||||||||||||
792 | - | |||||||||||||||||||||||||
793 | hbar->setSingleStep(20); | - | ||||||||||||||||||||||||
794 | vbar->setSingleStep(1); | - | ||||||||||||||||||||||||
795 | - | |||||||||||||||||||||||||
796 | viewport->setBackgroundRole(QPalette::Base); | - | ||||||||||||||||||||||||
797 | q->setAcceptDrops(true); | - | ||||||||||||||||||||||||
798 | q->setFocusPolicy(Qt::StrongFocus); | - | ||||||||||||||||||||||||
799 | q->setAttribute(Qt::WA_KeyCompression); | - | ||||||||||||||||||||||||
800 | q->setAttribute(Qt::WA_InputMethodEnabled); | - | ||||||||||||||||||||||||
801 | q->setInputMethodHints(Qt::ImhMultiLine); | - | ||||||||||||||||||||||||
802 | - | |||||||||||||||||||||||||
803 | #ifndef QT_NO_CURSOR | - | ||||||||||||||||||||||||
804 | viewport->setCursor(Qt::IBeamCursor); | - | ||||||||||||||||||||||||
805 | #endif | - | ||||||||||||||||||||||||
806 | originalOffsetY = 0; | - | ||||||||||||||||||||||||
807 | #ifdef Q_DEAD_CODE_FROM_QT4_WIN | - | ||||||||||||||||||||||||
808 | setSingleFingerPanEnabled(true); | - | ||||||||||||||||||||||||
809 | #endif | - | ||||||||||||||||||||||||
810 | } never executed: end of block | 0 | ||||||||||||||||||||||||
811 | - | |||||||||||||||||||||||||
812 | void QPlainTextEditPrivate::_q_repaintContents(const QRectF &contentsRect) | - | ||||||||||||||||||||||||
813 | { | - | ||||||||||||||||||||||||
814 | Q_Q(QPlainTextEdit); | - | ||||||||||||||||||||||||
815 | if (!contentsRect.isValid()) {
| 0 | ||||||||||||||||||||||||
816 | updateViewport(); | - | ||||||||||||||||||||||||
817 | return; never executed: return; | 0 | ||||||||||||||||||||||||
818 | } | - | ||||||||||||||||||||||||
819 | const int xOffset = horizontalOffset(); | - | ||||||||||||||||||||||||
820 | const int yOffset = (int)verticalOffset(); | - | ||||||||||||||||||||||||
821 | const QRect visibleRect(xOffset, yOffset, viewport->width(), viewport->height()); | - | ||||||||||||||||||||||||
822 | - | |||||||||||||||||||||||||
823 | QRect r = contentsRect.adjusted(-1, -1, 1, 1).intersected(visibleRect).toAlignedRect(); | - | ||||||||||||||||||||||||
824 | if (r.isEmpty())
| 0 | ||||||||||||||||||||||||
825 | return; never executed: return; | 0 | ||||||||||||||||||||||||
826 | - | |||||||||||||||||||||||||
827 | r.translate(-xOffset, -yOffset); | - | ||||||||||||||||||||||||
828 | viewport->update(r); | - | ||||||||||||||||||||||||
829 | emit q->updateRequest(r, 0); | - | ||||||||||||||||||||||||
830 | } never executed: end of block | 0 | ||||||||||||||||||||||||
831 | - | |||||||||||||||||||||||||
832 | void QPlainTextEditPrivate::pageUpDown(QTextCursor::MoveOperation op, QTextCursor::MoveMode moveMode, bool moveCursor) | - | ||||||||||||||||||||||||
833 | { | - | ||||||||||||||||||||||||
834 | - | |||||||||||||||||||||||||
835 | Q_Q(QPlainTextEdit); | - | ||||||||||||||||||||||||
836 | - | |||||||||||||||||||||||||
837 | QTextCursor cursor = control->textCursor(); | - | ||||||||||||||||||||||||
838 | if (moveCursor) {
| 0 | ||||||||||||||||||||||||
839 | ensureCursorVisible(); | - | ||||||||||||||||||||||||
840 | if (!pageUpDownLastCursorYIsValid)
| 0 | ||||||||||||||||||||||||
841 | pageUpDownLastCursorY = control->cursorRect(cursor).top() - verticalOffset(); never executed: pageUpDownLastCursorY = control->cursorRect(cursor).top() - verticalOffset(); | 0 | ||||||||||||||||||||||||
842 | } never executed: end of block | 0 | ||||||||||||||||||||||||
843 | - | |||||||||||||||||||||||||
844 | qreal lastY = pageUpDownLastCursorY; | - | ||||||||||||||||||||||||
845 | - | |||||||||||||||||||||||||
846 | - | |||||||||||||||||||||||||
847 | if (op == QTextCursor::Down) {
| 0 | ||||||||||||||||||||||||
848 | QRectF visible = QRectF(viewport->rect()).translated(-q->contentOffset()); | - | ||||||||||||||||||||||||
849 | QTextBlock firstVisibleBlock = q->firstVisibleBlock(); | - | ||||||||||||||||||||||||
850 | QTextBlock block = firstVisibleBlock; | - | ||||||||||||||||||||||||
851 | QRectF br = q->blockBoundingRect(block); | - | ||||||||||||||||||||||||
852 | qreal h = 0; | - | ||||||||||||||||||||||||
853 | int atEnd = false; | - | ||||||||||||||||||||||||
854 | while (h + br.height() <= visible.bottom()) {
| 0 | ||||||||||||||||||||||||
855 | if (!block.next().isValid()) {
| 0 | ||||||||||||||||||||||||
856 | atEnd = true; | - | ||||||||||||||||||||||||
857 | lastY = visible.bottom(); // set cursor to last line | - | ||||||||||||||||||||||||
858 | break; never executed: break; | 0 | ||||||||||||||||||||||||
859 | } | - | ||||||||||||||||||||||||
860 | h += br.height(); | - | ||||||||||||||||||||||||
861 | block = block.next(); | - | ||||||||||||||||||||||||
862 | br = q->blockBoundingRect(block); | - | ||||||||||||||||||||||||
863 | } never executed: end of block | 0 | ||||||||||||||||||||||||
864 | - | |||||||||||||||||||||||||
865 | if (!atEnd) {
| 0 | ||||||||||||||||||||||||
866 | int line = 0; | - | ||||||||||||||||||||||||
867 | qreal diff = visible.bottom() - h; | - | ||||||||||||||||||||||||
868 | int lineCount = block.layout()->lineCount(); | - | ||||||||||||||||||||||||
869 | while (line < lineCount - 1) {
| 0 | ||||||||||||||||||||||||
870 | if (block.layout()->lineAt(line).naturalTextRect().bottom() > diff) {
| 0 | ||||||||||||||||||||||||
871 | // the first line that did not completely fit the screen | - | ||||||||||||||||||||||||
872 | break; never executed: break; | 0 | ||||||||||||||||||||||||
873 | } | - | ||||||||||||||||||||||||
874 | ++line; | - | ||||||||||||||||||||||||
875 | } never executed: end of block | 0 | ||||||||||||||||||||||||
876 | setTopBlock(block.blockNumber(), line); | - | ||||||||||||||||||||||||
877 | } never executed: end of block | 0 | ||||||||||||||||||||||||
878 | - | |||||||||||||||||||||||||
879 | if (moveCursor) {
| 0 | ||||||||||||||||||||||||
880 | // move using movePosition to keep the cursor's x | - | ||||||||||||||||||||||||
881 | lastY += verticalOffset(); | - | ||||||||||||||||||||||||
882 | bool moved = false; | - | ||||||||||||||||||||||||
883 | do { | - | ||||||||||||||||||||||||
884 | moved = cursor.movePosition(op, moveMode); | - | ||||||||||||||||||||||||
885 | } while (moved && control->cursorRect(cursor).top() < lastY); never executed: end of block
| 0 | ||||||||||||||||||||||||
886 | } never executed: end of block | 0 | ||||||||||||||||||||||||
887 | - | |||||||||||||||||||||||||
888 | } else if (op == QTextCursor::Up) { never executed: end of block
| 0 | ||||||||||||||||||||||||
889 | - | |||||||||||||||||||||||||
890 | QRectF visible = QRectF(viewport->rect()).translated(-q->contentOffset()); | - | ||||||||||||||||||||||||
891 | visible.translate(0, -visible.height()); // previous page | - | ||||||||||||||||||||||||
892 | QTextBlock block = q->firstVisibleBlock(); | - | ||||||||||||||||||||||||
893 | qreal h = 0; | - | ||||||||||||||||||||||||
894 | while (h >= visible.top()) {
| 0 | ||||||||||||||||||||||||
895 | if (!block.previous().isValid()) {
| 0 | ||||||||||||||||||||||||
896 | if (control->topBlock == 0 && topLine == 0) {
| 0 | ||||||||||||||||||||||||
897 | lastY = 0; // set cursor to first line | - | ||||||||||||||||||||||||
898 | } never executed: end of block | 0 | ||||||||||||||||||||||||
899 | break; never executed: break; | 0 | ||||||||||||||||||||||||
900 | } | - | ||||||||||||||||||||||||
901 | block = block.previous(); | - | ||||||||||||||||||||||||
902 | QRectF br = q->blockBoundingRect(block); | - | ||||||||||||||||||||||||
903 | h -= br.height(); | - | ||||||||||||||||||||||||
904 | } never executed: end of block | 0 | ||||||||||||||||||||||||
905 | - | |||||||||||||||||||||||||
906 | int line = 0; | - | ||||||||||||||||||||||||
907 | if (block.isValid()) {
| 0 | ||||||||||||||||||||||||
908 | qreal diff = visible.top() - h; | - | ||||||||||||||||||||||||
909 | int lineCount = block.layout()->lineCount(); | - | ||||||||||||||||||||||||
910 | while (line < lineCount) {
| 0 | ||||||||||||||||||||||||
911 | if (block.layout()->lineAt(line).naturalTextRect().top() >= diff)
| 0 | ||||||||||||||||||||||||
912 | break; never executed: break; | 0 | ||||||||||||||||||||||||
913 | ++line; | - | ||||||||||||||||||||||||
914 | } never executed: end of block | 0 | ||||||||||||||||||||||||
915 | if (line == lineCount) {
| 0 | ||||||||||||||||||||||||
916 | if (block.next().isValid() && block.next() != q->firstVisibleBlock()) {
| 0 | ||||||||||||||||||||||||
917 | block = block.next(); | - | ||||||||||||||||||||||||
918 | line = 0; | - | ||||||||||||||||||||||||
919 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
920 | --line; | - | ||||||||||||||||||||||||
921 | } never executed: end of block | 0 | ||||||||||||||||||||||||
922 | } | - | ||||||||||||||||||||||||
923 | } never executed: end of block | 0 | ||||||||||||||||||||||||
924 | setTopBlock(block.blockNumber(), line); | - | ||||||||||||||||||||||||
925 | - | |||||||||||||||||||||||||
926 | if (moveCursor) {
| 0 | ||||||||||||||||||||||||
927 | cursor.setVisualNavigation(true); | - | ||||||||||||||||||||||||
928 | // move using movePosition to keep the cursor's x | - | ||||||||||||||||||||||||
929 | lastY += verticalOffset(); | - | ||||||||||||||||||||||||
930 | bool moved = false; | - | ||||||||||||||||||||||||
931 | do { | - | ||||||||||||||||||||||||
932 | moved = cursor.movePosition(op, moveMode); | - | ||||||||||||||||||||||||
933 | } while (moved && control->cursorRect(cursor).top() > lastY); never executed: end of block
| 0 | ||||||||||||||||||||||||
934 | } never executed: end of block | 0 | ||||||||||||||||||||||||
935 | } never executed: end of block | 0 | ||||||||||||||||||||||||
936 | - | |||||||||||||||||||||||||
937 | if (moveCursor) {
| 0 | ||||||||||||||||||||||||
938 | control->setTextCursor(cursor); | - | ||||||||||||||||||||||||
939 | pageUpDownLastCursorYIsValid = true; | - | ||||||||||||||||||||||||
940 | } never executed: end of block | 0 | ||||||||||||||||||||||||
941 | } never executed: end of block | 0 | ||||||||||||||||||||||||
942 | - | |||||||||||||||||||||||||
943 | #ifndef QT_NO_SCROLLBAR | - | ||||||||||||||||||||||||
944 | - | |||||||||||||||||||||||||
945 | void QPlainTextEditPrivate::_q_adjustScrollbars() | - | ||||||||||||||||||||||||
946 | { | - | ||||||||||||||||||||||||
947 | Q_Q(QPlainTextEdit); | - | ||||||||||||||||||||||||
948 | QTextDocument *doc = control->document(); | - | ||||||||||||||||||||||||
949 | QPlainTextDocumentLayout *documentLayout = qobject_cast<QPlainTextDocumentLayout*>(doc->documentLayout()); | - | ||||||||||||||||||||||||
950 | Q_ASSERT(documentLayout); | - | ||||||||||||||||||||||||
951 | bool documentSizeChangedBlocked = documentLayout->priv()->blockDocumentSizeChanged; | - | ||||||||||||||||||||||||
952 | documentLayout->priv()->blockDocumentSizeChanged = true; | - | ||||||||||||||||||||||||
953 | qreal margin = doc->documentMargin(); | - | ||||||||||||||||||||||||
954 | - | |||||||||||||||||||||||||
955 | int vmax = 0; | - | ||||||||||||||||||||||||
956 | - | |||||||||||||||||||||||||
957 | int vSliderLength = 0; | - | ||||||||||||||||||||||||
958 | if (!centerOnScroll && q->isVisible()) {
| 0 | ||||||||||||||||||||||||
959 | QTextBlock block = doc->lastBlock(); | - | ||||||||||||||||||||||||
960 | const qreal visible = viewport->rect().height() - margin - 1; | - | ||||||||||||||||||||||||
961 | qreal y = 0; | - | ||||||||||||||||||||||||
962 | int visibleFromBottom = 0; | - | ||||||||||||||||||||||||
963 | - | |||||||||||||||||||||||||
964 | while (block.isValid()) {
| 0 | ||||||||||||||||||||||||
965 | if (!block.isVisible()) {
| 0 | ||||||||||||||||||||||||
966 | block = block.previous(); | - | ||||||||||||||||||||||||
967 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||
968 | } | - | ||||||||||||||||||||||||
969 | y += documentLayout->blockBoundingRect(block).height(); | - | ||||||||||||||||||||||||
970 | - | |||||||||||||||||||||||||
971 | QTextLayout *layout = block.layout(); | - | ||||||||||||||||||||||||
972 | int layoutLineCount = layout->lineCount(); | - | ||||||||||||||||||||||||
973 | if (y > visible) {
| 0 | ||||||||||||||||||||||||
974 | int lineNumber = 0; | - | ||||||||||||||||||||||||
975 | while (lineNumber < layoutLineCount) {
| 0 | ||||||||||||||||||||||||
976 | QTextLine line = layout->lineAt(lineNumber); | - | ||||||||||||||||||||||||
977 | const QRectF lr = line.naturalTextRect(); | - | ||||||||||||||||||||||||
978 | if (lr.top() >= y - visible)
| 0 | ||||||||||||||||||||||||
979 | break; never executed: break; | 0 | ||||||||||||||||||||||||
980 | ++lineNumber; | - | ||||||||||||||||||||||||
981 | } never executed: end of block | 0 | ||||||||||||||||||||||||
982 | if (lineNumber < layoutLineCount)
| 0 | ||||||||||||||||||||||||
983 | visibleFromBottom += (layoutLineCount - lineNumber); never executed: visibleFromBottom += (layoutLineCount - lineNumber); | 0 | ||||||||||||||||||||||||
984 | break; never executed: break; | 0 | ||||||||||||||||||||||||
985 | - | |||||||||||||||||||||||||
986 | } | - | ||||||||||||||||||||||||
987 | visibleFromBottom += layoutLineCount; | - | ||||||||||||||||||||||||
988 | block = block.previous(); | - | ||||||||||||||||||||||||
989 | } never executed: end of block | 0 | ||||||||||||||||||||||||
990 | vmax = qMax(0, doc->lineCount() - visibleFromBottom); | - | ||||||||||||||||||||||||
991 | vSliderLength = visibleFromBottom; | - | ||||||||||||||||||||||||
992 | - | |||||||||||||||||||||||||
993 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
994 | vmax = qMax(0, doc->lineCount() - 1); | - | ||||||||||||||||||||||||
995 | int lineSpacing = q->fontMetrics().lineSpacing(); | - | ||||||||||||||||||||||||
996 | vSliderLength = lineSpacing != 0 ? viewport->height() / lineSpacing : 0;
| 0 | ||||||||||||||||||||||||
997 | } never executed: end of block | 0 | ||||||||||||||||||||||||
998 | - | |||||||||||||||||||||||||
999 | - | |||||||||||||||||||||||||
1000 | - | |||||||||||||||||||||||||
1001 | QSizeF documentSize = documentLayout->documentSize(); | - | ||||||||||||||||||||||||
1002 | vbar->setRange(0, qMax(0, vmax)); | - | ||||||||||||||||||||||||
1003 | vbar->setPageStep(vSliderLength); | - | ||||||||||||||||||||||||
1004 | int visualTopLine = vmax; | - | ||||||||||||||||||||||||
1005 | QTextBlock firstVisibleBlock = q->firstVisibleBlock(); | - | ||||||||||||||||||||||||
1006 | if (firstVisibleBlock.isValid())
| 0 | ||||||||||||||||||||||||
1007 | visualTopLine = firstVisibleBlock.firstLineNumber() + topLine; never executed: visualTopLine = firstVisibleBlock.firstLineNumber() + topLine; | 0 | ||||||||||||||||||||||||
1008 | - | |||||||||||||||||||||||||
1009 | { | - | ||||||||||||||||||||||||
1010 | const QSignalBlocker blocker(vbar); | - | ||||||||||||||||||||||||
1011 | vbar->setValue(visualTopLine); | - | ||||||||||||||||||||||||
1012 | } | - | ||||||||||||||||||||||||
1013 | - | |||||||||||||||||||||||||
1014 | hbar->setRange(0, (int)documentSize.width() - viewport->width()); | - | ||||||||||||||||||||||||
1015 | hbar->setPageStep(viewport->width()); | - | ||||||||||||||||||||||||
1016 | documentLayout->priv()->blockDocumentSizeChanged = documentSizeChangedBlocked; | - | ||||||||||||||||||||||||
1017 | setTopLine(vbar->value()); | - | ||||||||||||||||||||||||
1018 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1019 | - | |||||||||||||||||||||||||
1020 | #endif | - | ||||||||||||||||||||||||
1021 | - | |||||||||||||||||||||||||
1022 | - | |||||||||||||||||||||||||
1023 | void QPlainTextEditPrivate::ensureViewportLayouted() | - | ||||||||||||||||||||||||
1024 | { | - | ||||||||||||||||||||||||
1025 | } | - | ||||||||||||||||||||||||
1026 | - | |||||||||||||||||||||||||
1027 | /*! | - | ||||||||||||||||||||||||
1028 | \class QPlainTextEdit | - | ||||||||||||||||||||||||
1029 | \since 4.4 | - | ||||||||||||||||||||||||
1030 | \brief The QPlainTextEdit class provides a widget that is used to edit and display | - | ||||||||||||||||||||||||
1031 | plain text. | - | ||||||||||||||||||||||||
1032 | - | |||||||||||||||||||||||||
1033 | \ingroup richtext-processing | - | ||||||||||||||||||||||||
1034 | \inmodule QtWidgets | - | ||||||||||||||||||||||||
1035 | - | |||||||||||||||||||||||||
1036 | \tableofcontents | - | ||||||||||||||||||||||||
1037 | - | |||||||||||||||||||||||||
1038 | \section1 Introduction and Concepts | - | ||||||||||||||||||||||||
1039 | - | |||||||||||||||||||||||||
1040 | QPlainTextEdit is an advanced viewer/editor supporting plain | - | ||||||||||||||||||||||||
1041 | text. It is optimized to handle large documents and to respond | - | ||||||||||||||||||||||||
1042 | quickly to user input. | - | ||||||||||||||||||||||||
1043 | - | |||||||||||||||||||||||||
1044 | QPlainText uses very much the same technology and concepts as | - | ||||||||||||||||||||||||
1045 | QTextEdit, but is optimized for plain text handling. | - | ||||||||||||||||||||||||
1046 | - | |||||||||||||||||||||||||
1047 | QPlainTextEdit works on paragraphs and characters. A paragraph is | - | ||||||||||||||||||||||||
1048 | a formatted string which is word-wrapped to fit into the width of | - | ||||||||||||||||||||||||
1049 | the widget. By default when reading plain text, one newline | - | ||||||||||||||||||||||||
1050 | signifies a paragraph. A document consists of zero or more | - | ||||||||||||||||||||||||
1051 | paragraphs. Paragraphs are separated by hard line breaks. Each | - | ||||||||||||||||||||||||
1052 | character within a paragraph has its own attributes, for example, | - | ||||||||||||||||||||||||
1053 | font and color. | - | ||||||||||||||||||||||||
1054 | - | |||||||||||||||||||||||||
1055 | The shape of the mouse cursor on a QPlainTextEdit is | - | ||||||||||||||||||||||||
1056 | Qt::IBeamCursor by default. It can be changed through the | - | ||||||||||||||||||||||||
1057 | viewport()'s cursor property. | - | ||||||||||||||||||||||||
1058 | - | |||||||||||||||||||||||||
1059 | \section1 Using QPlainTextEdit as a Display Widget | - | ||||||||||||||||||||||||
1060 | - | |||||||||||||||||||||||||
1061 | The text is set or replaced using setPlainText() which deletes the | - | ||||||||||||||||||||||||
1062 | existing text and replaces it with the text passed to setPlainText(). | - | ||||||||||||||||||||||||
1063 | - | |||||||||||||||||||||||||
1064 | Text can be inserted using the QTextCursor class or using the | - | ||||||||||||||||||||||||
1065 | convenience functions insertPlainText(), appendPlainText() or | - | ||||||||||||||||||||||||
1066 | paste(). | - | ||||||||||||||||||||||||
1067 | - | |||||||||||||||||||||||||
1068 | By default, the text edit wraps words at whitespace to fit within | - | ||||||||||||||||||||||||
1069 | the text edit widget. The setLineWrapMode() function is used to | - | ||||||||||||||||||||||||
1070 | specify the kind of line wrap you want, \l WidgetWidth or \l | - | ||||||||||||||||||||||||
1071 | NoWrap if you don't want any wrapping. If you use word wrap to | - | ||||||||||||||||||||||||
1072 | the widget's width \l WidgetWidth, you can specify whether to | - | ||||||||||||||||||||||||
1073 | break on whitespace or anywhere with setWordWrapMode(). | - | ||||||||||||||||||||||||
1074 | - | |||||||||||||||||||||||||
1075 | The find() function can be used to find and select a given string | - | ||||||||||||||||||||||||
1076 | within the text. | - | ||||||||||||||||||||||||
1077 | - | |||||||||||||||||||||||||
1078 | If you want to limit the total number of paragraphs in a | - | ||||||||||||||||||||||||
1079 | QPlainTextEdit, as it is for example useful in a log viewer, then | - | ||||||||||||||||||||||||
1080 | you can use the maximumBlockCount property. The combination of | - | ||||||||||||||||||||||||
1081 | setMaximumBlockCount() and appendPlainText() turns QPlainTextEdit | - | ||||||||||||||||||||||||
1082 | into an efficient viewer for log text. The scrolling can be | - | ||||||||||||||||||||||||
1083 | reduced with the centerOnScroll() property, making the log viewer | - | ||||||||||||||||||||||||
1084 | even faster. Text can be formatted in a limited way, either using | - | ||||||||||||||||||||||||
1085 | a syntax highlighter (see below), or by appending html-formatted | - | ||||||||||||||||||||||||
1086 | text with appendHtml(). While QPlainTextEdit does not support | - | ||||||||||||||||||||||||
1087 | complex rich text rendering with tables and floats, it does | - | ||||||||||||||||||||||||
1088 | support limited paragraph-based formatting that you may need in a | - | ||||||||||||||||||||||||
1089 | log viewer. | - | ||||||||||||||||||||||||
1090 | - | |||||||||||||||||||||||||
1091 | \section2 Read-only Key Bindings | - | ||||||||||||||||||||||||
1092 | - | |||||||||||||||||||||||||
1093 | When QPlainTextEdit is used read-only the key bindings are limited to | - | ||||||||||||||||||||||||
1094 | navigation, and text may only be selected with the mouse: | - | ||||||||||||||||||||||||
1095 | \table | - | ||||||||||||||||||||||||
1096 | \header \li Keypresses \li Action | - | ||||||||||||||||||||||||
1097 | \row \li Qt::UpArrow \li Moves one line up. | - | ||||||||||||||||||||||||
1098 | \row \li Qt::DownArrow \li Moves one line down. | - | ||||||||||||||||||||||||
1099 | \row \li Qt::LeftArrow \li Moves one character to the left. | - | ||||||||||||||||||||||||
1100 | \row \li Qt::RightArrow \li Moves one character to the right. | - | ||||||||||||||||||||||||
1101 | \row \li PageUp \li Moves one (viewport) page up. | - | ||||||||||||||||||||||||
1102 | \row \li PageDown \li Moves one (viewport) page down. | - | ||||||||||||||||||||||||
1103 | \row \li Home \li Moves to the beginning of the text. | - | ||||||||||||||||||||||||
1104 | \row \li End \li Moves to the end of the text. | - | ||||||||||||||||||||||||
1105 | \row \li Alt+Wheel | - | ||||||||||||||||||||||||
1106 | \li Scrolls the page horizontally (the Wheel is the mouse wheel). | - | ||||||||||||||||||||||||
1107 | \row \li Ctrl+Wheel \li Zooms the text. | - | ||||||||||||||||||||||||
1108 | \row \li Ctrl+A \li Selects all text. | - | ||||||||||||||||||||||||
1109 | \endtable | - | ||||||||||||||||||||||||
1110 | - | |||||||||||||||||||||||||
1111 | - | |||||||||||||||||||||||||
1112 | \section1 Using QPlainTextEdit as an Editor | - | ||||||||||||||||||||||||
1113 | - | |||||||||||||||||||||||||
1114 | All the information about using QPlainTextEdit as a display widget also | - | ||||||||||||||||||||||||
1115 | applies here. | - | ||||||||||||||||||||||||
1116 | - | |||||||||||||||||||||||||
1117 | Selection of text is handled by the QTextCursor class, which provides | - | ||||||||||||||||||||||||
1118 | functionality for creating selections, retrieving the text contents or | - | ||||||||||||||||||||||||
1119 | deleting selections. You can retrieve the object that corresponds with | - | ||||||||||||||||||||||||
1120 | the user-visible cursor using the textCursor() method. If you want to set | - | ||||||||||||||||||||||||
1121 | a selection in QPlainTextEdit just create one on a QTextCursor object and | - | ||||||||||||||||||||||||
1122 | then make that cursor the visible cursor using setCursor(). The selection | - | ||||||||||||||||||||||||
1123 | can be copied to the clipboard with copy(), or cut to the clipboard with | - | ||||||||||||||||||||||||
1124 | cut(). The entire text can be selected using selectAll(). | - | ||||||||||||||||||||||||
1125 | - | |||||||||||||||||||||||||
1126 | QPlainTextEdit holds a QTextDocument object which can be retrieved using the | - | ||||||||||||||||||||||||
1127 | document() method. You can also set your own document object using setDocument(). | - | ||||||||||||||||||||||||
1128 | QTextDocument emits a textChanged() signal if the text changes and it also | - | ||||||||||||||||||||||||
1129 | provides a isModified() function which will return true if the text has been | - | ||||||||||||||||||||||||
1130 | modified since it was either loaded or since the last call to setModified | - | ||||||||||||||||||||||||
1131 | with false as argument. In addition it provides methods for undo and redo. | - | ||||||||||||||||||||||||
1132 | - | |||||||||||||||||||||||||
1133 | \section2 Syntax Highlighting | - | ||||||||||||||||||||||||
1134 | - | |||||||||||||||||||||||||
1135 | Just like QTextEdit, QPlainTextEdit works together with | - | ||||||||||||||||||||||||
1136 | QSyntaxHighlighter. | - | ||||||||||||||||||||||||
1137 | - | |||||||||||||||||||||||||
1138 | \section2 Editing Key Bindings | - | ||||||||||||||||||||||||
1139 | - | |||||||||||||||||||||||||
1140 | The list of key bindings which are implemented for editing: | - | ||||||||||||||||||||||||
1141 | \table | - | ||||||||||||||||||||||||
1142 | \header \li Keypresses \li Action | - | ||||||||||||||||||||||||
1143 | \row \li Backspace \li Deletes the character to the left of the cursor. | - | ||||||||||||||||||||||||
1144 | \row \li Delete \li Deletes the character to the right of the cursor. | - | ||||||||||||||||||||||||
1145 | \row \li Ctrl+C \li Copy the selected text to the clipboard. | - | ||||||||||||||||||||||||
1146 | \row \li Ctrl+Insert \li Copy the selected text to the clipboard. | - | ||||||||||||||||||||||||
1147 | \row \li Ctrl+K \li Deletes to the end of the line. | - | ||||||||||||||||||||||||
1148 | \row \li Ctrl+V \li Pastes the clipboard text into text edit. | - | ||||||||||||||||||||||||
1149 | \row \li Shift+Insert \li Pastes the clipboard text into text edit. | - | ||||||||||||||||||||||||
1150 | \row \li Ctrl+X \li Deletes the selected text and copies it to the clipboard. | - | ||||||||||||||||||||||||
1151 | \row \li Shift+Delete \li Deletes the selected text and copies it to the clipboard. | - | ||||||||||||||||||||||||
1152 | \row \li Ctrl+Z \li Undoes the last operation. | - | ||||||||||||||||||||||||
1153 | \row \li Ctrl+Y \li Redoes the last operation. | - | ||||||||||||||||||||||||
1154 | \row \li LeftArrow \li Moves the cursor one character to the left. | - | ||||||||||||||||||||||||
1155 | \row \li Ctrl+LeftArrow \li Moves the cursor one word to the left. | - | ||||||||||||||||||||||||
1156 | \row \li RightArrow \li Moves the cursor one character to the right. | - | ||||||||||||||||||||||||
1157 | \row \li Ctrl+RightArrow \li Moves the cursor one word to the right. | - | ||||||||||||||||||||||||
1158 | \row \li UpArrow \li Moves the cursor one line up. | - | ||||||||||||||||||||||||
1159 | \row \li Ctrl+UpArrow \li Moves the cursor one word up. | - | ||||||||||||||||||||||||
1160 | \row \li DownArrow \li Moves the cursor one line down. | - | ||||||||||||||||||||||||
1161 | \row \li Ctrl+Down Arrow \li Moves the cursor one word down. | - | ||||||||||||||||||||||||
1162 | \row \li PageUp \li Moves the cursor one page up. | - | ||||||||||||||||||||||||
1163 | \row \li PageDown \li Moves the cursor one page down. | - | ||||||||||||||||||||||||
1164 | \row \li Home \li Moves the cursor to the beginning of the line. | - | ||||||||||||||||||||||||
1165 | \row \li Ctrl+Home \li Moves the cursor to the beginning of the text. | - | ||||||||||||||||||||||||
1166 | \row \li End \li Moves the cursor to the end of the line. | - | ||||||||||||||||||||||||
1167 | \row \li Ctrl+End \li Moves the cursor to the end of the text. | - | ||||||||||||||||||||||||
1168 | \row \li Alt+Wheel \li Scrolls the page horizontally (the Wheel is the mouse wheel). | - | ||||||||||||||||||||||||
1169 | \row \li Ctrl+Wheel \li Zooms the text. | - | ||||||||||||||||||||||||
1170 | \endtable | - | ||||||||||||||||||||||||
1171 | - | |||||||||||||||||||||||||
1172 | To select (mark) text hold down the Shift key whilst pressing one | - | ||||||||||||||||||||||||
1173 | of the movement keystrokes, for example, \e{Shift+Right Arrow} | - | ||||||||||||||||||||||||
1174 | will select the character to the right, and \e{Shift+Ctrl+Right | - | ||||||||||||||||||||||||
1175 | Arrow} will select the word to the right, etc. | - | ||||||||||||||||||||||||
1176 | - | |||||||||||||||||||||||||
1177 | \section1 Differences to QTextEdit | - | ||||||||||||||||||||||||
1178 | - | |||||||||||||||||||||||||
1179 | QPlainTextEdit is a thin class, implemented by using most of the | - | ||||||||||||||||||||||||
1180 | technology that is behind QTextEdit and QTextDocument. Its | - | ||||||||||||||||||||||||
1181 | performance benefits over QTextEdit stem mostly from using a | - | ||||||||||||||||||||||||
1182 | different and simplified text layout called | - | ||||||||||||||||||||||||
1183 | QPlainTextDocumentLayout on the text document (see | - | ||||||||||||||||||||||||
1184 | QTextDocument::setDocumentLayout()). The plain text document layout | - | ||||||||||||||||||||||||
1185 | does not support tables nor embedded frames, and \e{replaces a | - | ||||||||||||||||||||||||
1186 | pixel-exact height calculation with a line-by-line respectively | - | ||||||||||||||||||||||||
1187 | paragraph-by-paragraph scrolling approach}. This makes it possible | - | ||||||||||||||||||||||||
1188 | to handle significantly larger documents, and still resize the | - | ||||||||||||||||||||||||
1189 | editor with line wrap enabled in real time. It also makes for a | - | ||||||||||||||||||||||||
1190 | fast log viewer (see setMaximumBlockCount()). | - | ||||||||||||||||||||||||
1191 | - | |||||||||||||||||||||||||
1192 | - | |||||||||||||||||||||||||
1193 | \sa QTextDocument, QTextCursor, {Application Example}, | - | ||||||||||||||||||||||||
1194 | {Code Editor Example}, {Syntax Highlighter Example}, | - | ||||||||||||||||||||||||
1195 | {Rich Text Processing} | - | ||||||||||||||||||||||||
1196 | - | |||||||||||||||||||||||||
1197 | */ | - | ||||||||||||||||||||||||
1198 | - | |||||||||||||||||||||||||
1199 | /*! | - | ||||||||||||||||||||||||
1200 | \property QPlainTextEdit::plainText | - | ||||||||||||||||||||||||
1201 | - | |||||||||||||||||||||||||
1202 | This property gets and sets the plain text editor's contents. The previous | - | ||||||||||||||||||||||||
1203 | contents are removed and undo/redo history is reset when this property is set. | - | ||||||||||||||||||||||||
1204 | - | |||||||||||||||||||||||||
1205 | By default, for an editor with no contents, this property contains an empty string. | - | ||||||||||||||||||||||||
1206 | */ | - | ||||||||||||||||||||||||
1207 | - | |||||||||||||||||||||||||
1208 | /*! | - | ||||||||||||||||||||||||
1209 | \property QPlainTextEdit::undoRedoEnabled | - | ||||||||||||||||||||||||
1210 | \brief whether undo and redo are enabled | - | ||||||||||||||||||||||||
1211 | - | |||||||||||||||||||||||||
1212 | Users are only able to undo or redo actions if this property is | - | ||||||||||||||||||||||||
1213 | true, and if there is an action that can be undone (or redone). | - | ||||||||||||||||||||||||
1214 | - | |||||||||||||||||||||||||
1215 | By default, this property is \c true. | - | ||||||||||||||||||||||||
1216 | */ | - | ||||||||||||||||||||||||
1217 | - | |||||||||||||||||||||||||
1218 | /*! | - | ||||||||||||||||||||||||
1219 | \enum QPlainTextEdit::LineWrapMode | - | ||||||||||||||||||||||||
1220 | - | |||||||||||||||||||||||||
1221 | \value NoWrap | - | ||||||||||||||||||||||||
1222 | \value WidgetWidth | - | ||||||||||||||||||||||||
1223 | */ | - | ||||||||||||||||||||||||
1224 | - | |||||||||||||||||||||||||
1225 | - | |||||||||||||||||||||||||
1226 | /*! | - | ||||||||||||||||||||||||
1227 | Constructs an empty QPlainTextEdit with parent \a | - | ||||||||||||||||||||||||
1228 | parent. | - | ||||||||||||||||||||||||
1229 | */ | - | ||||||||||||||||||||||||
1230 | QPlainTextEdit::QPlainTextEdit(QWidget *parent) | - | ||||||||||||||||||||||||
1231 | : QAbstractScrollArea(*new QPlainTextEditPrivate, parent) | - | ||||||||||||||||||||||||
1232 | { | - | ||||||||||||||||||||||||
1233 | Q_D(QPlainTextEdit); | - | ||||||||||||||||||||||||
1234 | d->init(); | - | ||||||||||||||||||||||||
1235 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1236 | - | |||||||||||||||||||||||||
1237 | /*! | - | ||||||||||||||||||||||||
1238 | \internal | - | ||||||||||||||||||||||||
1239 | */ | - | ||||||||||||||||||||||||
1240 | QPlainTextEdit::QPlainTextEdit(QPlainTextEditPrivate &dd, QWidget *parent) | - | ||||||||||||||||||||||||
1241 | : QAbstractScrollArea(dd, parent) | - | ||||||||||||||||||||||||
1242 | { | - | ||||||||||||||||||||||||
1243 | Q_D(QPlainTextEdit); | - | ||||||||||||||||||||||||
1244 | d->init(); | - | ||||||||||||||||||||||||
1245 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1246 | - | |||||||||||||||||||||||||
1247 | /*! | - | ||||||||||||||||||||||||
1248 | Constructs a QPlainTextEdit with parent \a parent. The text edit will display | - | ||||||||||||||||||||||||
1249 | the plain text \a text. | - | ||||||||||||||||||||||||
1250 | */ | - | ||||||||||||||||||||||||
1251 | QPlainTextEdit::QPlainTextEdit(const QString &text, QWidget *parent) | - | ||||||||||||||||||||||||
1252 | : QAbstractScrollArea(*new QPlainTextEditPrivate, parent) | - | ||||||||||||||||||||||||
1253 | { | - | ||||||||||||||||||||||||
1254 | Q_D(QPlainTextEdit); | - | ||||||||||||||||||||||||
1255 | d->init(text); | - | ||||||||||||||||||||||||
1256 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1257 | - | |||||||||||||||||||||||||
1258 | - | |||||||||||||||||||||||||
1259 | /*! | - | ||||||||||||||||||||||||
1260 | Destructor. | - | ||||||||||||||||||||||||
1261 | */ | - | ||||||||||||||||||||||||
1262 | QPlainTextEdit::~QPlainTextEdit() | - | ||||||||||||||||||||||||
1263 | { | - | ||||||||||||||||||||||||
1264 | Q_D(QPlainTextEdit); | - | ||||||||||||||||||||||||
1265 | if (d->documentLayoutPtr) {
| 0 | ||||||||||||||||||||||||
1266 | if (d->documentLayoutPtr->priv()->mainViewPrivate == d)
| 0 | ||||||||||||||||||||||||
1267 | d->documentLayoutPtr->priv()->mainViewPrivate = 0; never executed: d->documentLayoutPtr->priv()->mainViewPrivate = 0; | 0 | ||||||||||||||||||||||||
1268 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1269 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1270 | - | |||||||||||||||||||||||||
1271 | /*! | - | ||||||||||||||||||||||||
1272 | Makes \a document the new document of the text editor. | - | ||||||||||||||||||||||||
1273 | - | |||||||||||||||||||||||||
1274 | The parent QObject of the provided document remains the owner | - | ||||||||||||||||||||||||
1275 | of the object. If the current document is a child of the text | - | ||||||||||||||||||||||||
1276 | editor, then it is deleted. | - | ||||||||||||||||||||||||
1277 | - | |||||||||||||||||||||||||
1278 | The document must have a document layout that inherits | - | ||||||||||||||||||||||||
1279 | QPlainTextDocumentLayout (see QTextDocument::setDocumentLayout()). | - | ||||||||||||||||||||||||
1280 | - | |||||||||||||||||||||||||
1281 | \sa document() | - | ||||||||||||||||||||||||
1282 | */ | - | ||||||||||||||||||||||||
1283 | void QPlainTextEdit::setDocument(QTextDocument *document) | - | ||||||||||||||||||||||||
1284 | { | - | ||||||||||||||||||||||||
1285 | Q_D(QPlainTextEdit); | - | ||||||||||||||||||||||||
1286 | QPlainTextDocumentLayout *documentLayout = 0; | - | ||||||||||||||||||||||||
1287 | - | |||||||||||||||||||||||||
1288 | if (!document) {
| 0 | ||||||||||||||||||||||||
1289 | document = new QTextDocument(d->control); | - | ||||||||||||||||||||||||
1290 | documentLayout = new QPlainTextDocumentLayout(document); | - | ||||||||||||||||||||||||
1291 | document->setDocumentLayout(documentLayout); | - | ||||||||||||||||||||||||
1292 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
1293 | documentLayout = qobject_cast<QPlainTextDocumentLayout*>(document->documentLayout()); | - | ||||||||||||||||||||||||
1294 | if (!documentLayout) {
| 0 | ||||||||||||||||||||||||
1295 | qWarning("QPlainTextEdit::setDocument: Document set does not support QPlainTextDocumentLayout"); | - | ||||||||||||||||||||||||
1296 | return; never executed: return; | 0 | ||||||||||||||||||||||||
1297 | } | - | ||||||||||||||||||||||||
1298 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1299 | d->control->setDocument(document); | - | ||||||||||||||||||||||||
1300 | if (!documentLayout->priv()->mainViewPrivate)
| 0 | ||||||||||||||||||||||||
1301 | documentLayout->priv()->mainViewPrivate = d; never executed: documentLayout->priv()->mainViewPrivate = d; | 0 | ||||||||||||||||||||||||
1302 | d->documentLayoutPtr = documentLayout; | - | ||||||||||||||||||||||||
1303 | d->updateDefaultTextOption(); | - | ||||||||||||||||||||||||
1304 | d->relayoutDocument(); | - | ||||||||||||||||||||||||
1305 | d->_q_adjustScrollbars(); | - | ||||||||||||||||||||||||
1306 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1307 | - | |||||||||||||||||||||||||
1308 | /*! | - | ||||||||||||||||||||||||
1309 | Returns a pointer to the underlying document. | - | ||||||||||||||||||||||||
1310 | - | |||||||||||||||||||||||||
1311 | \sa setDocument() | - | ||||||||||||||||||||||||
1312 | */ | - | ||||||||||||||||||||||||
1313 | QTextDocument *QPlainTextEdit::document() const | - | ||||||||||||||||||||||||
1314 | { | - | ||||||||||||||||||||||||
1315 | Q_D(const QPlainTextEdit); | - | ||||||||||||||||||||||||
1316 | return d->control->document(); never executed: return d->control->document(); | 0 | ||||||||||||||||||||||||
1317 | } | - | ||||||||||||||||||||||||
1318 | - | |||||||||||||||||||||||||
1319 | /*! | - | ||||||||||||||||||||||||
1320 | \since 5.3 | - | ||||||||||||||||||||||||
1321 | - | |||||||||||||||||||||||||
1322 | \property QPlainTextEdit::placeholderText | - | ||||||||||||||||||||||||
1323 | \brief the editor placeholder text | - | ||||||||||||||||||||||||
1324 | - | |||||||||||||||||||||||||
1325 | Setting this property makes the editor display a grayed-out | - | ||||||||||||||||||||||||
1326 | placeholder text as long as the document() is empty. | - | ||||||||||||||||||||||||
1327 | - | |||||||||||||||||||||||||
1328 | By default, this property contains an empty string. | - | ||||||||||||||||||||||||
1329 | - | |||||||||||||||||||||||||
1330 | \sa document() | - | ||||||||||||||||||||||||
1331 | */ | - | ||||||||||||||||||||||||
1332 | void QPlainTextEdit::setPlaceholderText(const QString &placeholderText) | - | ||||||||||||||||||||||||
1333 | { | - | ||||||||||||||||||||||||
1334 | Q_D(QPlainTextEdit); | - | ||||||||||||||||||||||||
1335 | if (d->placeholderText != placeholderText) {
| 0 | ||||||||||||||||||||||||
1336 | d->placeholderText = placeholderText; | - | ||||||||||||||||||||||||
1337 | if (d->control->document()->isEmpty())
| 0 | ||||||||||||||||||||||||
1338 | d->viewport->update(); never executed: d->viewport->update(); | 0 | ||||||||||||||||||||||||
1339 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1340 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1341 | - | |||||||||||||||||||||||||
1342 | QString QPlainTextEdit::placeholderText() const | - | ||||||||||||||||||||||||
1343 | { | - | ||||||||||||||||||||||||
1344 | Q_D(const QPlainTextEdit); | - | ||||||||||||||||||||||||
1345 | return d->placeholderText; never executed: return d->placeholderText; | 0 | ||||||||||||||||||||||||
1346 | } | - | ||||||||||||||||||||||||
1347 | - | |||||||||||||||||||||||||
1348 | /*! | - | ||||||||||||||||||||||||
1349 | Sets the visible \a cursor. | - | ||||||||||||||||||||||||
1350 | */ | - | ||||||||||||||||||||||||
1351 | void QPlainTextEdit::setTextCursor(const QTextCursor &cursor) | - | ||||||||||||||||||||||||
1352 | { | - | ||||||||||||||||||||||||
1353 | doSetTextCursor(cursor); | - | ||||||||||||||||||||||||
1354 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1355 | - | |||||||||||||||||||||||||
1356 | /*! | - | ||||||||||||||||||||||||
1357 | \internal | - | ||||||||||||||||||||||||
1358 | - | |||||||||||||||||||||||||
1359 | This provides a hook for subclasses to intercept cursor changes. | - | ||||||||||||||||||||||||
1360 | */ | - | ||||||||||||||||||||||||
1361 | - | |||||||||||||||||||||||||
1362 | void QPlainTextEdit::doSetTextCursor(const QTextCursor &cursor) | - | ||||||||||||||||||||||||
1363 | { | - | ||||||||||||||||||||||||
1364 | Q_D(QPlainTextEdit); | - | ||||||||||||||||||||||||
1365 | d->control->setTextCursor(cursor); | - | ||||||||||||||||||||||||
1366 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1367 | - | |||||||||||||||||||||||||
1368 | /*! | - | ||||||||||||||||||||||||
1369 | Returns a copy of the QTextCursor that represents the currently visible cursor. | - | ||||||||||||||||||||||||
1370 | Note that changes on the returned cursor do not affect QPlainTextEdit's cursor; use | - | ||||||||||||||||||||||||
1371 | setTextCursor() to update the visible cursor. | - | ||||||||||||||||||||||||
1372 | */ | - | ||||||||||||||||||||||||
1373 | QTextCursor QPlainTextEdit::textCursor() const | - | ||||||||||||||||||||||||
1374 | { | - | ||||||||||||||||||||||||
1375 | Q_D(const QPlainTextEdit); | - | ||||||||||||||||||||||||
1376 | return d->control->textCursor(); never executed: return d->control->textCursor(); | 0 | ||||||||||||||||||||||||
1377 | } | - | ||||||||||||||||||||||||
1378 | - | |||||||||||||||||||||||||
1379 | /*! | - | ||||||||||||||||||||||||
1380 | Returns the reference of the anchor at position \a pos, or an | - | ||||||||||||||||||||||||
1381 | empty string if no anchor exists at that point. | - | ||||||||||||||||||||||||
1382 | - | |||||||||||||||||||||||||
1383 | \since 4.7 | - | ||||||||||||||||||||||||
1384 | */ | - | ||||||||||||||||||||||||
1385 | QString QPlainTextEdit::anchorAt(const QPoint &pos) const | - | ||||||||||||||||||||||||
1386 | { | - | ||||||||||||||||||||||||
1387 | Q_D(const QPlainTextEdit); | - | ||||||||||||||||||||||||
1388 | int cursorPos = d->control->hitTest(pos + QPointF(d->horizontalOffset(), | - | ||||||||||||||||||||||||
1389 | d->verticalOffset()), | - | ||||||||||||||||||||||||
1390 | Qt::ExactHit); | - | ||||||||||||||||||||||||
1391 | if (cursorPos < 0)
| 0 | ||||||||||||||||||||||||
1392 | return QString(); never executed: return QString(); | 0 | ||||||||||||||||||||||||
1393 | - | |||||||||||||||||||||||||
1394 | QTextDocumentPrivate *pieceTable = document()->docHandle(); | - | ||||||||||||||||||||||||
1395 | QTextDocumentPrivate::FragmentIterator it = pieceTable->find(cursorPos); | - | ||||||||||||||||||||||||
1396 | QTextCharFormat fmt = pieceTable->formatCollection()->charFormat(it->format); | - | ||||||||||||||||||||||||
1397 | return fmt.anchorHref(); never executed: return fmt.anchorHref(); | 0 | ||||||||||||||||||||||||
1398 | } | - | ||||||||||||||||||||||||
1399 | - | |||||||||||||||||||||||||
1400 | /*! | - | ||||||||||||||||||||||||
1401 | Undoes the last operation. | - | ||||||||||||||||||||||||
1402 | - | |||||||||||||||||||||||||
1403 | If there is no operation to undo, i.e. there is no undo step in | - | ||||||||||||||||||||||||
1404 | the undo/redo history, nothing happens. | - | ||||||||||||||||||||||||
1405 | - | |||||||||||||||||||||||||
1406 | \sa redo() | - | ||||||||||||||||||||||||
1407 | */ | - | ||||||||||||||||||||||||
1408 | void QPlainTextEdit::undo() | - | ||||||||||||||||||||||||
1409 | { | - | ||||||||||||||||||||||||
1410 | Q_D(QPlainTextEdit); | - | ||||||||||||||||||||||||
1411 | d->control->undo(); | - | ||||||||||||||||||||||||
1412 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1413 | - | |||||||||||||||||||||||||
1414 | void QPlainTextEdit::redo() | - | ||||||||||||||||||||||||
1415 | { | - | ||||||||||||||||||||||||
1416 | Q_D(QPlainTextEdit); | - | ||||||||||||||||||||||||
1417 | d->control->redo(); | - | ||||||||||||||||||||||||
1418 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1419 | - | |||||||||||||||||||||||||
1420 | /*! | - | ||||||||||||||||||||||||
1421 | \fn void QPlainTextEdit::redo() | - | ||||||||||||||||||||||||
1422 | - | |||||||||||||||||||||||||
1423 | Redoes the last operation. | - | ||||||||||||||||||||||||
1424 | - | |||||||||||||||||||||||||
1425 | If there is no operation to redo, i.e. there is no redo step in | - | ||||||||||||||||||||||||
1426 | the undo/redo history, nothing happens. | - | ||||||||||||||||||||||||
1427 | - | |||||||||||||||||||||||||
1428 | \sa undo() | - | ||||||||||||||||||||||||
1429 | */ | - | ||||||||||||||||||||||||
1430 | - | |||||||||||||||||||||||||
1431 | #ifndef QT_NO_CLIPBOARD | - | ||||||||||||||||||||||||
1432 | /*! | - | ||||||||||||||||||||||||
1433 | Copies the selected text to the clipboard and deletes it from | - | ||||||||||||||||||||||||
1434 | the text edit. | - | ||||||||||||||||||||||||
1435 | - | |||||||||||||||||||||||||
1436 | If there is no selected text nothing happens. | - | ||||||||||||||||||||||||
1437 | - | |||||||||||||||||||||||||
1438 | \sa copy(), paste() | - | ||||||||||||||||||||||||
1439 | */ | - | ||||||||||||||||||||||||
1440 | - | |||||||||||||||||||||||||
1441 | void QPlainTextEdit::cut() | - | ||||||||||||||||||||||||
1442 | { | - | ||||||||||||||||||||||||
1443 | Q_D(QPlainTextEdit); | - | ||||||||||||||||||||||||
1444 | d->control->cut(); | - | ||||||||||||||||||||||||
1445 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1446 | - | |||||||||||||||||||||||||
1447 | /*! | - | ||||||||||||||||||||||||
1448 | Copies any selected text to the clipboard. | - | ||||||||||||||||||||||||
1449 | - | |||||||||||||||||||||||||
1450 | \sa copyAvailable() | - | ||||||||||||||||||||||||
1451 | */ | - | ||||||||||||||||||||||||
1452 | - | |||||||||||||||||||||||||
1453 | void QPlainTextEdit::copy() | - | ||||||||||||||||||||||||
1454 | { | - | ||||||||||||||||||||||||
1455 | Q_D(QPlainTextEdit); | - | ||||||||||||||||||||||||
1456 | d->control->copy(); | - | ||||||||||||||||||||||||
1457 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1458 | - | |||||||||||||||||||||||||
1459 | /*! | - | ||||||||||||||||||||||||
1460 | Pastes the text from the clipboard into the text edit at the | - | ||||||||||||||||||||||||
1461 | current cursor position. | - | ||||||||||||||||||||||||
1462 | - | |||||||||||||||||||||||||
1463 | If there is no text in the clipboard nothing happens. | - | ||||||||||||||||||||||||
1464 | - | |||||||||||||||||||||||||
1465 | To change the behavior of this function, i.e. to modify what | - | ||||||||||||||||||||||||
1466 | QPlainTextEdit can paste and how it is being pasted, reimplement the | - | ||||||||||||||||||||||||
1467 | virtual canInsertFromMimeData() and insertFromMimeData() | - | ||||||||||||||||||||||||
1468 | functions. | - | ||||||||||||||||||||||||
1469 | - | |||||||||||||||||||||||||
1470 | \sa cut(), copy() | - | ||||||||||||||||||||||||
1471 | */ | - | ||||||||||||||||||||||||
1472 | - | |||||||||||||||||||||||||
1473 | void QPlainTextEdit::paste() | - | ||||||||||||||||||||||||
1474 | { | - | ||||||||||||||||||||||||
1475 | Q_D(QPlainTextEdit); | - | ||||||||||||||||||||||||
1476 | d->control->paste(); | - | ||||||||||||||||||||||||
1477 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1478 | #endif | - | ||||||||||||||||||||||||
1479 | - | |||||||||||||||||||||||||
1480 | /*! | - | ||||||||||||||||||||||||
1481 | Deletes all the text in the text edit. | - | ||||||||||||||||||||||||
1482 | - | |||||||||||||||||||||||||
1483 | Note that the undo/redo history is cleared by this function. | - | ||||||||||||||||||||||||
1484 | - | |||||||||||||||||||||||||
1485 | \sa cut(), setPlainText() | - | ||||||||||||||||||||||||
1486 | */ | - | ||||||||||||||||||||||||
1487 | void QPlainTextEdit::clear() | - | ||||||||||||||||||||||||
1488 | { | - | ||||||||||||||||||||||||
1489 | Q_D(QPlainTextEdit); | - | ||||||||||||||||||||||||
1490 | // clears and sets empty content | - | ||||||||||||||||||||||||
1491 | d->control->topBlock = d->topLine = d->topLineFracture = 0; | - | ||||||||||||||||||||||||
1492 | d->control->clear(); | - | ||||||||||||||||||||||||
1493 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1494 | - | |||||||||||||||||||||||||
1495 | - | |||||||||||||||||||||||||
1496 | /*! | - | ||||||||||||||||||||||||
1497 | Selects all text. | - | ||||||||||||||||||||||||
1498 | - | |||||||||||||||||||||||||
1499 | \sa copy(), cut(), textCursor() | - | ||||||||||||||||||||||||
1500 | */ | - | ||||||||||||||||||||||||
1501 | void QPlainTextEdit::selectAll() | - | ||||||||||||||||||||||||
1502 | { | - | ||||||||||||||||||||||||
1503 | Q_D(QPlainTextEdit); | - | ||||||||||||||||||||||||
1504 | d->control->selectAll(); | - | ||||||||||||||||||||||||
1505 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1506 | - | |||||||||||||||||||||||||
1507 | /*! \internal | - | ||||||||||||||||||||||||
1508 | */ | - | ||||||||||||||||||||||||
1509 | bool QPlainTextEdit::event(QEvent *e) | - | ||||||||||||||||||||||||
1510 | { | - | ||||||||||||||||||||||||
1511 | Q_D(QPlainTextEdit); | - | ||||||||||||||||||||||||
1512 | - | |||||||||||||||||||||||||
1513 | #ifndef QT_NO_CONTEXTMENU | - | ||||||||||||||||||||||||
1514 | if (e->type() == QEvent::ContextMenu
| 0 | ||||||||||||||||||||||||
1515 | && static_cast<QContextMenuEvent *>(e)->reason() == QContextMenuEvent::Keyboard) {
| 0 | ||||||||||||||||||||||||
1516 | ensureCursorVisible(); | - | ||||||||||||||||||||||||
1517 | const QPoint cursorPos = cursorRect().center(); | - | ||||||||||||||||||||||||
1518 | QContextMenuEvent ce(QContextMenuEvent::Keyboard, cursorPos, d->viewport->mapToGlobal(cursorPos)); | - | ||||||||||||||||||||||||
1519 | ce.setAccepted(e->isAccepted()); | - | ||||||||||||||||||||||||
1520 | const bool result = QAbstractScrollArea::event(&ce); | - | ||||||||||||||||||||||||
1521 | e->setAccepted(ce.isAccepted()); | - | ||||||||||||||||||||||||
1522 | return result; never executed: return result; | 0 | ||||||||||||||||||||||||
1523 | } | - | ||||||||||||||||||||||||
1524 | #endif // QT_NO_CONTEXTMENU | - | ||||||||||||||||||||||||
1525 | if (e->type() == QEvent::ShortcutOverride
| 0 | ||||||||||||||||||||||||
1526 | || e->type() == QEvent::ToolTip) {
| 0 | ||||||||||||||||||||||||
1527 | d->sendControlEvent(e); | - | ||||||||||||||||||||||||
1528 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1529 | #ifdef QT_KEYPAD_NAVIGATION | - | ||||||||||||||||||||||||
1530 | else if (e->type() == QEvent::EnterEditFocus || e->type() == QEvent::LeaveEditFocus) { | - | ||||||||||||||||||||||||
1531 | if (QApplication::keypadNavigationEnabled()) | - | ||||||||||||||||||||||||
1532 | d->sendControlEvent(e); | - | ||||||||||||||||||||||||
1533 | } | - | ||||||||||||||||||||||||
1534 | #endif | - | ||||||||||||||||||||||||
1535 | #ifndef QT_NO_GESTURES | - | ||||||||||||||||||||||||
1536 | else if (e->type() == QEvent::Gesture) {
| 0 | ||||||||||||||||||||||||
1537 | QGestureEvent *ge = static_cast<QGestureEvent *>(e); | - | ||||||||||||||||||||||||
1538 | QPanGesture *g = static_cast<QPanGesture *>(ge->gesture(Qt::PanGesture)); | - | ||||||||||||||||||||||||
1539 | if (g) {
| 0 | ||||||||||||||||||||||||
1540 | QScrollBar *hBar = horizontalScrollBar(); | - | ||||||||||||||||||||||||
1541 | QScrollBar *vBar = verticalScrollBar(); | - | ||||||||||||||||||||||||
1542 | if (g->state() == Qt::GestureStarted)
| 0 | ||||||||||||||||||||||||
1543 | d->originalOffsetY = vBar->value(); never executed: d->originalOffsetY = vBar->value(); | 0 | ||||||||||||||||||||||||
1544 | QPointF offset = g->offset(); | - | ||||||||||||||||||||||||
1545 | if (!offset.isNull()) {
| 0 | ||||||||||||||||||||||||
1546 | if (QApplication::isRightToLeft())
| 0 | ||||||||||||||||||||||||
1547 | offset.rx() *= -1; never executed: offset.rx() *= -1; | 0 | ||||||||||||||||||||||||
1548 | // QPlainTextEdit scrolls by lines only in vertical direction | - | ||||||||||||||||||||||||
1549 | QFontMetrics fm(document()->defaultFont()); | - | ||||||||||||||||||||||||
1550 | int lineHeight = fm.height(); | - | ||||||||||||||||||||||||
1551 | int newX = hBar->value() - g->delta().x(); | - | ||||||||||||||||||||||||
1552 | int newY = d->originalOffsetY - offset.y()/lineHeight; | - | ||||||||||||||||||||||||
1553 | hBar->setValue(newX); | - | ||||||||||||||||||||||||
1554 | vBar->setValue(newY); | - | ||||||||||||||||||||||||
1555 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1556 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1557 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||
1558 | } | - | ||||||||||||||||||||||||
1559 | #endif // QT_NO_GESTURES | - | ||||||||||||||||||||||||
1560 | return QAbstractScrollArea::event(e); never executed: return QAbstractScrollArea::event(e); | 0 | ||||||||||||||||||||||||
1561 | } | - | ||||||||||||||||||||||||
1562 | - | |||||||||||||||||||||||||
1563 | /*! \internal | - | ||||||||||||||||||||||||
1564 | */ | - | ||||||||||||||||||||||||
1565 | - | |||||||||||||||||||||||||
1566 | void QPlainTextEdit::timerEvent(QTimerEvent *e) | - | ||||||||||||||||||||||||
1567 | { | - | ||||||||||||||||||||||||
1568 | Q_D(QPlainTextEdit); | - | ||||||||||||||||||||||||
1569 | if (e->timerId() == d->autoScrollTimer.timerId()) {
| 0 | ||||||||||||||||||||||||
1570 | QRect visible = d->viewport->rect(); | - | ||||||||||||||||||||||||
1571 | QPoint pos; | - | ||||||||||||||||||||||||
1572 | if (d->inDrag) {
| 0 | ||||||||||||||||||||||||
1573 | pos = d->autoScrollDragPos; | - | ||||||||||||||||||||||||
1574 | visible.adjust(qMin(visible.width()/3,20), qMin(visible.height()/3,20), | - | ||||||||||||||||||||||||
1575 | -qMin(visible.width()/3,20), -qMin(visible.height()/3,20)); | - | ||||||||||||||||||||||||
1576 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
1577 | const QPoint globalPos = QCursor::pos(); | - | ||||||||||||||||||||||||
1578 | pos = d->viewport->mapFromGlobal(globalPos); | - | ||||||||||||||||||||||||
1579 | QMouseEvent ev(QEvent::MouseMove, pos, d->viewport->mapTo(d->viewport->topLevelWidget(), pos), globalPos, | - | ||||||||||||||||||||||||
1580 | Qt::LeftButton, Qt::LeftButton, Qt::NoModifier); | - | ||||||||||||||||||||||||
1581 | mouseMoveEvent(&ev); | - | ||||||||||||||||||||||||
1582 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1583 | int deltaY = qMax(pos.y() - visible.top(), visible.bottom() - pos.y()) - visible.height(); | - | ||||||||||||||||||||||||
1584 | int deltaX = qMax(pos.x() - visible.left(), visible.right() - pos.x()) - visible.width(); | - | ||||||||||||||||||||||||
1585 | int delta = qMax(deltaX, deltaY); | - | ||||||||||||||||||||||||
1586 | if (delta >= 0) {
| 0 | ||||||||||||||||||||||||
1587 | if (delta < 7)
| 0 | ||||||||||||||||||||||||
1588 | delta = 7; never executed: delta = 7; | 0 | ||||||||||||||||||||||||
1589 | int timeout = 4900 / (delta * delta); | - | ||||||||||||||||||||||||
1590 | d->autoScrollTimer.start(timeout, this); | - | ||||||||||||||||||||||||
1591 | - | |||||||||||||||||||||||||
1592 | if (deltaY > 0)
| 0 | ||||||||||||||||||||||||
1593 | d->vbar->triggerAction(pos.y() < visible.center().y() ? never executed: d->vbar->triggerAction(pos.y() < visible.center().y() ? QAbstractSlider::SliderSingleStepSub : QAbstractSlider::SliderSingleStepAdd); | 0 | ||||||||||||||||||||||||
1594 | QAbstractSlider::SliderSingleStepSub never executed: d->vbar->triggerAction(pos.y() < visible.center().y() ? QAbstractSlider::SliderSingleStepSub : QAbstractSlider::SliderSingleStepAdd); | 0 | ||||||||||||||||||||||||
1595 | : QAbstractSlider::SliderSingleStepAdd); never executed: d->vbar->triggerAction(pos.y() < visible.center().y() ? QAbstractSlider::SliderSingleStepSub : QAbstractSlider::SliderSingleStepAdd); | 0 | ||||||||||||||||||||||||
1596 | if (deltaX > 0)
| 0 | ||||||||||||||||||||||||
1597 | d->hbar->triggerAction(pos.x() < visible.center().x() ? never executed: d->hbar->triggerAction(pos.x() < visible.center().x() ? QAbstractSlider::SliderSingleStepSub : QAbstractSlider::SliderSingleStepAdd); | 0 | ||||||||||||||||||||||||
1598 | QAbstractSlider::SliderSingleStepSub never executed: d->hbar->triggerAction(pos.x() < visible.center().x() ? QAbstractSlider::SliderSingleStepSub : QAbstractSlider::SliderSingleStepAdd); | 0 | ||||||||||||||||||||||||
1599 | : QAbstractSlider::SliderSingleStepAdd); never executed: d->hbar->triggerAction(pos.x() < visible.center().x() ? QAbstractSlider::SliderSingleStepSub : QAbstractSlider::SliderSingleStepAdd); | 0 | ||||||||||||||||||||||||
1600 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1601 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1602 | #ifdef QT_KEYPAD_NAVIGATION | - | ||||||||||||||||||||||||
1603 | else if (e->timerId() == d->deleteAllTimer.timerId()) { | - | ||||||||||||||||||||||||
1604 | d->deleteAllTimer.stop(); | - | ||||||||||||||||||||||||
1605 | clear(); | - | ||||||||||||||||||||||||
1606 | } | - | ||||||||||||||||||||||||
1607 | #endif | - | ||||||||||||||||||||||||
1608 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1609 | - | |||||||||||||||||||||||||
1610 | /*! | - | ||||||||||||||||||||||||
1611 | Changes the text of the text edit to the string \a text. | - | ||||||||||||||||||||||||
1612 | Any previous text is removed. | - | ||||||||||||||||||||||||
1613 | - | |||||||||||||||||||||||||
1614 | \a text is interpreted as plain text. | - | ||||||||||||||||||||||||
1615 | - | |||||||||||||||||||||||||
1616 | Note that the undo/redo history is cleared by this function. | - | ||||||||||||||||||||||||
1617 | - | |||||||||||||||||||||||||
1618 | \sa toPlainText() | - | ||||||||||||||||||||||||
1619 | */ | - | ||||||||||||||||||||||||
1620 | - | |||||||||||||||||||||||||
1621 | void QPlainTextEdit::setPlainText(const QString &text) | - | ||||||||||||||||||||||||
1622 | { | - | ||||||||||||||||||||||||
1623 | Q_D(QPlainTextEdit); | - | ||||||||||||||||||||||||
1624 | d->control->setPlainText(text); | - | ||||||||||||||||||||||||
1625 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1626 | - | |||||||||||||||||||||||||
1627 | /*! | - | ||||||||||||||||||||||||
1628 | \fn QString QPlainTextEdit::toPlainText() const | - | ||||||||||||||||||||||||
1629 | - | |||||||||||||||||||||||||
1630 | Returns the text of the text edit as plain text. | - | ||||||||||||||||||||||||
1631 | - | |||||||||||||||||||||||||
1632 | \sa QPlainTextEdit::setPlainText() | - | ||||||||||||||||||||||||
1633 | */ | - | ||||||||||||||||||||||||
1634 | - | |||||||||||||||||||||||||
1635 | /*! \reimp | - | ||||||||||||||||||||||||
1636 | */ | - | ||||||||||||||||||||||||
1637 | void QPlainTextEdit::keyPressEvent(QKeyEvent *e) | - | ||||||||||||||||||||||||
1638 | { | - | ||||||||||||||||||||||||
1639 | Q_D(QPlainTextEdit); | - | ||||||||||||||||||||||||
1640 | - | |||||||||||||||||||||||||
1641 | #ifdef QT_KEYPAD_NAVIGATION | - | ||||||||||||||||||||||||
1642 | switch (e->key()) { | - | ||||||||||||||||||||||||
1643 | case Qt::Key_Select: | - | ||||||||||||||||||||||||
1644 | if (QApplication::keypadNavigationEnabled()) { | - | ||||||||||||||||||||||||
1645 | if (!(d->control->textInteractionFlags() & Qt::LinksAccessibleByKeyboard)) | - | ||||||||||||||||||||||||
1646 | setEditFocus(!hasEditFocus()); | - | ||||||||||||||||||||||||
1647 | else { | - | ||||||||||||||||||||||||
1648 | if (!hasEditFocus()) | - | ||||||||||||||||||||||||
1649 | setEditFocus(true); | - | ||||||||||||||||||||||||
1650 | else { | - | ||||||||||||||||||||||||
1651 | QTextCursor cursor = d->control->textCursor(); | - | ||||||||||||||||||||||||
1652 | QTextCharFormat charFmt = cursor.charFormat(); | - | ||||||||||||||||||||||||
1653 | if (!cursor.hasSelection() || charFmt.anchorHref().isEmpty()) { | - | ||||||||||||||||||||||||
1654 | setEditFocus(false); | - | ||||||||||||||||||||||||
1655 | } | - | ||||||||||||||||||||||||
1656 | } | - | ||||||||||||||||||||||||
1657 | } | - | ||||||||||||||||||||||||
1658 | } | - | ||||||||||||||||||||||||
1659 | break; | - | ||||||||||||||||||||||||
1660 | case Qt::Key_Back: | - | ||||||||||||||||||||||||
1661 | case Qt::Key_No: | - | ||||||||||||||||||||||||
1662 | if (!QApplication::keypadNavigationEnabled() | - | ||||||||||||||||||||||||
1663 | || (QApplication::keypadNavigationEnabled() && !hasEditFocus())) { | - | ||||||||||||||||||||||||
1664 | e->ignore(); | - | ||||||||||||||||||||||||
1665 | return; | - | ||||||||||||||||||||||||
1666 | } | - | ||||||||||||||||||||||||
1667 | break; | - | ||||||||||||||||||||||||
1668 | default: | - | ||||||||||||||||||||||||
1669 | if (QApplication::keypadNavigationEnabled()) { | - | ||||||||||||||||||||||||
1670 | if (!hasEditFocus() && !(e->modifiers() & Qt::ControlModifier)) { | - | ||||||||||||||||||||||||
1671 | if (e->text()[0].isPrint()) { | - | ||||||||||||||||||||||||
1672 | setEditFocus(true); | - | ||||||||||||||||||||||||
1673 | clear(); | - | ||||||||||||||||||||||||
1674 | } else { | - | ||||||||||||||||||||||||
1675 | e->ignore(); | - | ||||||||||||||||||||||||
1676 | return; | - | ||||||||||||||||||||||||
1677 | } | - | ||||||||||||||||||||||||
1678 | } | - | ||||||||||||||||||||||||
1679 | } | - | ||||||||||||||||||||||||
1680 | break; | - | ||||||||||||||||||||||||
1681 | } | - | ||||||||||||||||||||||||
1682 | #endif | - | ||||||||||||||||||||||||
1683 | - | |||||||||||||||||||||||||
1684 | #ifndef QT_NO_SHORTCUT | - | ||||||||||||||||||||||||
1685 | - | |||||||||||||||||||||||||
1686 | Qt::TextInteractionFlags tif = d->control->textInteractionFlags(); | - | ||||||||||||||||||||||||
1687 | - | |||||||||||||||||||||||||
1688 | if (tif & Qt::TextSelectableByKeyboard){
| 0 | ||||||||||||||||||||||||
1689 | if (e == QKeySequence::SelectPreviousPage) {
| 0 | ||||||||||||||||||||||||
1690 | e->accept(); | - | ||||||||||||||||||||||||
1691 | d->pageUpDown(QTextCursor::Up, QTextCursor::KeepAnchor); | - | ||||||||||||||||||||||||
1692 | return; never executed: return; | 0 | ||||||||||||||||||||||||
1693 | } else if (e ==QKeySequence::SelectNextPage) {
| 0 | ||||||||||||||||||||||||
1694 | e->accept(); | - | ||||||||||||||||||||||||
1695 | d->pageUpDown(QTextCursor::Down, QTextCursor::KeepAnchor); | - | ||||||||||||||||||||||||
1696 | return; never executed: return; | 0 | ||||||||||||||||||||||||
1697 | } | - | ||||||||||||||||||||||||
1698 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1699 | if (tif & (Qt::TextSelectableByKeyboard | Qt::TextEditable)) {
| 0 | ||||||||||||||||||||||||
1700 | if (e == QKeySequence::MoveToPreviousPage) {
| 0 | ||||||||||||||||||||||||
1701 | e->accept(); | - | ||||||||||||||||||||||||
1702 | d->pageUpDown(QTextCursor::Up, QTextCursor::MoveAnchor); | - | ||||||||||||||||||||||||
1703 | return; never executed: return; | 0 | ||||||||||||||||||||||||
1704 | } else if (e == QKeySequence::MoveToNextPage) {
| 0 | ||||||||||||||||||||||||
1705 | e->accept(); | - | ||||||||||||||||||||||||
1706 | d->pageUpDown(QTextCursor::Down, QTextCursor::MoveAnchor); | - | ||||||||||||||||||||||||
1707 | return; never executed: return; | 0 | ||||||||||||||||||||||||
1708 | } | - | ||||||||||||||||||||||||
1709 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1710 | - | |||||||||||||||||||||||||
1711 | if (!(tif & Qt::TextEditable)) {
| 0 | ||||||||||||||||||||||||
1712 | switch (e->key()) { | - | ||||||||||||||||||||||||
1713 | case Qt::Key_Space: never executed: case Qt::Key_Space: | 0 | ||||||||||||||||||||||||
1714 | e->accept(); | - | ||||||||||||||||||||||||
1715 | if (e->modifiers() & Qt::ShiftModifier)
| 0 | ||||||||||||||||||||||||
1716 | d->vbar->triggerAction(QAbstractSlider::SliderPageStepSub); never executed: d->vbar->triggerAction(QAbstractSlider::SliderPageStepSub); | 0 | ||||||||||||||||||||||||
1717 | else | - | ||||||||||||||||||||||||
1718 | d->vbar->triggerAction(QAbstractSlider::SliderPageStepAdd); never executed: d->vbar->triggerAction(QAbstractSlider::SliderPageStepAdd); | 0 | ||||||||||||||||||||||||
1719 | break; never executed: break; | 0 | ||||||||||||||||||||||||
1720 | default: never executed: default: | 0 | ||||||||||||||||||||||||
1721 | d->sendControlEvent(e); | - | ||||||||||||||||||||||||
1722 | if (!e->isAccepted() && e->modifiers() == Qt::NoModifier) {
| 0 | ||||||||||||||||||||||||
1723 | if (e->key() == Qt::Key_Home) {
| 0 | ||||||||||||||||||||||||
1724 | d->vbar->triggerAction(QAbstractSlider::SliderToMinimum); | - | ||||||||||||||||||||||||
1725 | e->accept(); | - | ||||||||||||||||||||||||
1726 | } else if (e->key() == Qt::Key_End) { never executed: end of block
| 0 | ||||||||||||||||||||||||
1727 | d->vbar->triggerAction(QAbstractSlider::SliderToMaximum); | - | ||||||||||||||||||||||||
1728 | e->accept(); | - | ||||||||||||||||||||||||
1729 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1730 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1731 | if (!e->isAccepted()) {
| 0 | ||||||||||||||||||||||||
1732 | QAbstractScrollArea::keyPressEvent(e); | - | ||||||||||||||||||||||||
1733 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1734 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1735 | return; never executed: return; | 0 | ||||||||||||||||||||||||
1736 | } | - | ||||||||||||||||||||||||
1737 | #endif // QT_NO_SHORTCUT | - | ||||||||||||||||||||||||
1738 | - | |||||||||||||||||||||||||
1739 | d->sendControlEvent(e); | - | ||||||||||||||||||||||||
1740 | #ifdef QT_KEYPAD_NAVIGATION | - | ||||||||||||||||||||||||
1741 | if (!e->isAccepted()) { | - | ||||||||||||||||||||||||
1742 | switch (e->key()) { | - | ||||||||||||||||||||||||
1743 | case Qt::Key_Up: | - | ||||||||||||||||||||||||
1744 | case Qt::Key_Down: | - | ||||||||||||||||||||||||
1745 | if (QApplication::keypadNavigationEnabled()) { | - | ||||||||||||||||||||||||
1746 | // Cursor position didn't change, so we want to leave | - | ||||||||||||||||||||||||
1747 | // these keys to change focus. | - | ||||||||||||||||||||||||
1748 | e->ignore(); | - | ||||||||||||||||||||||||
1749 | return; | - | ||||||||||||||||||||||||
1750 | } | - | ||||||||||||||||||||||||
1751 | break; | - | ||||||||||||||||||||||||
1752 | case Qt::Key_Left: | - | ||||||||||||||||||||||||
1753 | case Qt::Key_Right: | - | ||||||||||||||||||||||||
1754 | if (QApplication::keypadNavigationEnabled() | - | ||||||||||||||||||||||||
1755 | && QApplication::navigationMode() == Qt::NavigationModeKeypadDirectional) { | - | ||||||||||||||||||||||||
1756 | // Same as for Key_Up and Key_Down. | - | ||||||||||||||||||||||||
1757 | e->ignore(); | - | ||||||||||||||||||||||||
1758 | return; | - | ||||||||||||||||||||||||
1759 | } | - | ||||||||||||||||||||||||
1760 | break; | - | ||||||||||||||||||||||||
1761 | case Qt::Key_Back: | - | ||||||||||||||||||||||||
1762 | if (!e->isAutoRepeat()) { | - | ||||||||||||||||||||||||
1763 | if (QApplication::keypadNavigationEnabled()) { | - | ||||||||||||||||||||||||
1764 | if (document()->isEmpty()) { | - | ||||||||||||||||||||||||
1765 | setEditFocus(false); | - | ||||||||||||||||||||||||
1766 | e->accept(); | - | ||||||||||||||||||||||||
1767 | } else if (!d->deleteAllTimer.isActive()) { | - | ||||||||||||||||||||||||
1768 | e->accept(); | - | ||||||||||||||||||||||||
1769 | d->deleteAllTimer.start(750, this); | - | ||||||||||||||||||||||||
1770 | } | - | ||||||||||||||||||||||||
1771 | } else { | - | ||||||||||||||||||||||||
1772 | e->ignore(); | - | ||||||||||||||||||||||||
1773 | return; | - | ||||||||||||||||||||||||
1774 | } | - | ||||||||||||||||||||||||
1775 | } | - | ||||||||||||||||||||||||
1776 | break; | - | ||||||||||||||||||||||||
1777 | default: break; | - | ||||||||||||||||||||||||
1778 | } | - | ||||||||||||||||||||||||
1779 | } | - | ||||||||||||||||||||||||
1780 | #endif | - | ||||||||||||||||||||||||
1781 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1782 | - | |||||||||||||||||||||||||
1783 | /*! \reimp | - | ||||||||||||||||||||||||
1784 | */ | - | ||||||||||||||||||||||||
1785 | void QPlainTextEdit::keyReleaseEvent(QKeyEvent *e) | - | ||||||||||||||||||||||||
1786 | { | - | ||||||||||||||||||||||||
1787 | #ifdef QT_KEYPAD_NAVIGATION | - | ||||||||||||||||||||||||
1788 | Q_D(QPlainTextEdit); | - | ||||||||||||||||||||||||
1789 | if (QApplication::keypadNavigationEnabled()) { | - | ||||||||||||||||||||||||
1790 | if (!e->isAutoRepeat() && e->key() == Qt::Key_Back | - | ||||||||||||||||||||||||
1791 | && d->deleteAllTimer.isActive()) { | - | ||||||||||||||||||||||||
1792 | d->deleteAllTimer.stop(); | - | ||||||||||||||||||||||||
1793 | QTextCursor cursor = d->control->textCursor(); | - | ||||||||||||||||||||||||
1794 | QTextBlockFormat blockFmt = cursor.blockFormat(); | - | ||||||||||||||||||||||||
1795 | - | |||||||||||||||||||||||||
1796 | QTextList *list = cursor.currentList(); | - | ||||||||||||||||||||||||
1797 | if (list && cursor.atBlockStart()) { | - | ||||||||||||||||||||||||
1798 | list->remove(cursor.block()); | - | ||||||||||||||||||||||||
1799 | } else if (cursor.atBlockStart() && blockFmt.indent() > 0) { | - | ||||||||||||||||||||||||
1800 | blockFmt.setIndent(blockFmt.indent() - 1); | - | ||||||||||||||||||||||||
1801 | cursor.setBlockFormat(blockFmt); | - | ||||||||||||||||||||||||
1802 | } else { | - | ||||||||||||||||||||||||
1803 | cursor.deletePreviousChar(); | - | ||||||||||||||||||||||||
1804 | } | - | ||||||||||||||||||||||||
1805 | setTextCursor(cursor); | - | ||||||||||||||||||||||||
1806 | } | - | ||||||||||||||||||||||||
1807 | } | - | ||||||||||||||||||||||||
1808 | #else | - | ||||||||||||||||||||||||
1809 | QWidget::keyReleaseEvent(e); | - | ||||||||||||||||||||||||
1810 | #endif | - | ||||||||||||||||||||||||
1811 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1812 | - | |||||||||||||||||||||||||
1813 | /*! | - | ||||||||||||||||||||||||
1814 | Loads the resource specified by the given \a type and \a name. | - | ||||||||||||||||||||||||
1815 | - | |||||||||||||||||||||||||
1816 | This function is an extension of QTextDocument::loadResource(). | - | ||||||||||||||||||||||||
1817 | - | |||||||||||||||||||||||||
1818 | \sa QTextDocument::loadResource() | - | ||||||||||||||||||||||||
1819 | */ | - | ||||||||||||||||||||||||
1820 | QVariant QPlainTextEdit::loadResource(int type, const QUrl &name) | - | ||||||||||||||||||||||||
1821 | { | - | ||||||||||||||||||||||||
1822 | Q_UNUSED(type); | - | ||||||||||||||||||||||||
1823 | Q_UNUSED(name); | - | ||||||||||||||||||||||||
1824 | return QVariant(); never executed: return QVariant(); | 0 | ||||||||||||||||||||||||
1825 | } | - | ||||||||||||||||||||||||
1826 | - | |||||||||||||||||||||||||
1827 | /*! \reimp | - | ||||||||||||||||||||||||
1828 | */ | - | ||||||||||||||||||||||||
1829 | void QPlainTextEdit::resizeEvent(QResizeEvent *e) | - | ||||||||||||||||||||||||
1830 | { | - | ||||||||||||||||||||||||
1831 | Q_D(QPlainTextEdit); | - | ||||||||||||||||||||||||
1832 | if (e->oldSize().width() != e->size().width())
| 0 | ||||||||||||||||||||||||
1833 | d->relayoutDocument(); never executed: d->relayoutDocument(); | 0 | ||||||||||||||||||||||||
1834 | d->_q_adjustScrollbars(); | - | ||||||||||||||||||||||||
1835 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1836 | - | |||||||||||||||||||||||||
1837 | void QPlainTextEditPrivate::relayoutDocument() | - | ||||||||||||||||||||||||
1838 | { | - | ||||||||||||||||||||||||
1839 | QTextDocument *doc = control->document(); | - | ||||||||||||||||||||||||
1840 | QPlainTextDocumentLayout *documentLayout = qobject_cast<QPlainTextDocumentLayout*>(doc->documentLayout()); | - | ||||||||||||||||||||||||
1841 | Q_ASSERT(documentLayout); | - | ||||||||||||||||||||||||
1842 | documentLayoutPtr = documentLayout; | - | ||||||||||||||||||||||||
1843 | - | |||||||||||||||||||||||||
1844 | int width = viewport->width(); | - | ||||||||||||||||||||||||
1845 | - | |||||||||||||||||||||||||
1846 | if (documentLayout->priv()->mainViewPrivate == 0
| 0 | ||||||||||||||||||||||||
1847 | || documentLayout->priv()->mainViewPrivate == this
| 0 | ||||||||||||||||||||||||
1848 | || width > documentLayout->textWidth()) {
| 0 | ||||||||||||||||||||||||
1849 | documentLayout->priv()->mainViewPrivate = this; | - | ||||||||||||||||||||||||
1850 | documentLayout->setTextWidth(width); | - | ||||||||||||||||||||||||
1851 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1852 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1853 | - | |||||||||||||||||||||||||
1854 | static void fillBackground(QPainter *p, const QRectF &rect, QBrush brush, QRectF gradientRect = QRectF()) | - | ||||||||||||||||||||||||
1855 | { | - | ||||||||||||||||||||||||
1856 | p->save(); | - | ||||||||||||||||||||||||
1857 | if (brush.style() >= Qt::LinearGradientPattern && brush.style() <= Qt::ConicalGradientPattern) {
| 0 | ||||||||||||||||||||||||
1858 | if (!gradientRect.isNull()) {
| 0 | ||||||||||||||||||||||||
1859 | QTransform m = QTransform::fromTranslate(gradientRect.left(), gradientRect.top()); | - | ||||||||||||||||||||||||
1860 | m.scale(gradientRect.width(), gradientRect.height()); | - | ||||||||||||||||||||||||
1861 | brush.setTransform(m); | - | ||||||||||||||||||||||||
1862 | const_cast<QGradient *>(brush.gradient())->setCoordinateMode(QGradient::LogicalMode); | - | ||||||||||||||||||||||||
1863 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1864 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
1865 | p->setBrushOrigin(rect.topLeft()); | - | ||||||||||||||||||||||||
1866 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1867 | p->fillRect(rect, brush); | - | ||||||||||||||||||||||||
1868 | p->restore(); | - | ||||||||||||||||||||||||
1869 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1870 | - | |||||||||||||||||||||||||
1871 | - | |||||||||||||||||||||||||
1872 | - | |||||||||||||||||||||||||
1873 | /*! \reimp | - | ||||||||||||||||||||||||
1874 | */ | - | ||||||||||||||||||||||||
1875 | void QPlainTextEdit::paintEvent(QPaintEvent *e) | - | ||||||||||||||||||||||||
1876 | { | - | ||||||||||||||||||||||||
1877 | QPainter painter(viewport()); | - | ||||||||||||||||||||||||
1878 | Q_ASSERT(qobject_cast<QPlainTextDocumentLayout*>(document()->documentLayout())); | - | ||||||||||||||||||||||||
1879 | - | |||||||||||||||||||||||||
1880 | QPointF offset(contentOffset()); | - | ||||||||||||||||||||||||
1881 | - | |||||||||||||||||||||||||
1882 | QRect er = e->rect(); | - | ||||||||||||||||||||||||
1883 | QRect viewportRect = viewport()->rect(); | - | ||||||||||||||||||||||||
1884 | - | |||||||||||||||||||||||||
1885 | bool editable = !isReadOnly(); | - | ||||||||||||||||||||||||
1886 | - | |||||||||||||||||||||||||
1887 | QTextBlock block = firstVisibleBlock(); | - | ||||||||||||||||||||||||
1888 | qreal maximumWidth = document()->documentLayout()->documentSize().width(); | - | ||||||||||||||||||||||||
1889 | - | |||||||||||||||||||||||||
1890 | // Set a brush origin so that the WaveUnderline knows where the wave started | - | ||||||||||||||||||||||||
1891 | painter.setBrushOrigin(offset); | - | ||||||||||||||||||||||||
1892 | - | |||||||||||||||||||||||||
1893 | // keep right margin clean from full-width selection | - | ||||||||||||||||||||||||
1894 | int maxX = offset.x() + qMax((qreal)viewportRect.width(), maximumWidth) | - | ||||||||||||||||||||||||
1895 | - document()->documentMargin(); | - | ||||||||||||||||||||||||
1896 | er.setRight(qMin(er.right(), maxX)); | - | ||||||||||||||||||||||||
1897 | painter.setClipRect(er); | - | ||||||||||||||||||||||||
1898 | - | |||||||||||||||||||||||||
1899 | - | |||||||||||||||||||||||||
1900 | QAbstractTextDocumentLayout::PaintContext context = getPaintContext(); | - | ||||||||||||||||||||||||
1901 | - | |||||||||||||||||||||||||
1902 | while (block.isValid()) {
| 0 | ||||||||||||||||||||||||
1903 | - | |||||||||||||||||||||||||
1904 | QRectF r = blockBoundingRect(block).translated(offset); | - | ||||||||||||||||||||||||
1905 | QTextLayout *layout = block.layout(); | - | ||||||||||||||||||||||||
1906 | - | |||||||||||||||||||||||||
1907 | if (!block.isVisible()) {
| 0 | ||||||||||||||||||||||||
1908 | offset.ry() += r.height(); | - | ||||||||||||||||||||||||
1909 | block = block.next(); | - | ||||||||||||||||||||||||
1910 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||
1911 | } | - | ||||||||||||||||||||||||
1912 | - | |||||||||||||||||||||||||
1913 | if (r.bottom() >= er.top() && r.top() <= er.bottom()) {
| 0 | ||||||||||||||||||||||||
1914 | - | |||||||||||||||||||||||||
1915 | QTextBlockFormat blockFormat = block.blockFormat(); | - | ||||||||||||||||||||||||
1916 | - | |||||||||||||||||||||||||
1917 | QBrush bg = blockFormat.background(); | - | ||||||||||||||||||||||||
1918 | if (bg != Qt::NoBrush) {
| 0 | ||||||||||||||||||||||||
1919 | QRectF contentsRect = r; | - | ||||||||||||||||||||||||
1920 | contentsRect.setWidth(qMax(r.width(), maximumWidth)); | - | ||||||||||||||||||||||||
1921 | fillBackground(&painter, contentsRect, bg); | - | ||||||||||||||||||||||||
1922 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1923 | - | |||||||||||||||||||||||||
1924 | - | |||||||||||||||||||||||||
1925 | QVector<QTextLayout::FormatRange> selections; | - | ||||||||||||||||||||||||
1926 | int blpos = block.position(); | - | ||||||||||||||||||||||||
1927 | int bllen = block.length(); | - | ||||||||||||||||||||||||
1928 | for (int i = 0; i < context.selections.size(); ++i) {
| 0 | ||||||||||||||||||||||||
1929 | const QAbstractTextDocumentLayout::Selection &range = context.selections.at(i); | - | ||||||||||||||||||||||||
1930 | const int selStart = range.cursor.selectionStart() - blpos; | - | ||||||||||||||||||||||||
1931 | const int selEnd = range.cursor.selectionEnd() - blpos; | - | ||||||||||||||||||||||||
1932 | if (selStart < bllen && selEnd > 0
| 0 | ||||||||||||||||||||||||
1933 | && selEnd > selStart) {
| 0 | ||||||||||||||||||||||||
1934 | QTextLayout::FormatRange o; | - | ||||||||||||||||||||||||
1935 | o.start = selStart; | - | ||||||||||||||||||||||||
1936 | o.length = selEnd - selStart; | - | ||||||||||||||||||||||||
1937 | o.format = range.format; | - | ||||||||||||||||||||||||
1938 | selections.append(o); | - | ||||||||||||||||||||||||
1939 | } else if (!range.cursor.hasSelection() && range.format.hasProperty(QTextFormat::FullWidthSelection) never executed: end of block
| 0 | ||||||||||||||||||||||||
1940 | && block.contains(range.cursor.position())) {
| 0 | ||||||||||||||||||||||||
1941 | // for full width selections we don't require an actual selection, just | - | ||||||||||||||||||||||||
1942 | // a position to specify the line. that's more convenience in usage. | - | ||||||||||||||||||||||||
1943 | QTextLayout::FormatRange o; | - | ||||||||||||||||||||||||
1944 | QTextLine l = layout->lineForTextPosition(range.cursor.position() - blpos); | - | ||||||||||||||||||||||||
1945 | o.start = l.textStart(); | - | ||||||||||||||||||||||||
1946 | o.length = l.textLength(); | - | ||||||||||||||||||||||||
1947 | if (o.start + o.length == bllen - 1)
| 0 | ||||||||||||||||||||||||
1948 | ++o.length; // include newline never executed: ++o.length; | 0 | ||||||||||||||||||||||||
1949 | o.format = range.format; | - | ||||||||||||||||||||||||
1950 | selections.append(o); | - | ||||||||||||||||||||||||
1951 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1952 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1953 | - | |||||||||||||||||||||||||
1954 | bool drawCursor = ((editable || (textInteractionFlags() & Qt::TextSelectableByKeyboard))
| 0 | ||||||||||||||||||||||||
1955 | && context.cursorPosition >= blpos
| 0 | ||||||||||||||||||||||||
1956 | && context.cursorPosition < blpos + bllen);
| 0 | ||||||||||||||||||||||||
1957 | - | |||||||||||||||||||||||||
1958 | bool drawCursorAsBlock = drawCursor && overwriteMode() ;
| 0 | ||||||||||||||||||||||||
1959 | - | |||||||||||||||||||||||||
1960 | if (drawCursorAsBlock) {
| 0 | ||||||||||||||||||||||||
1961 | if (context.cursorPosition == blpos + bllen - 1) {
| 0 | ||||||||||||||||||||||||
1962 | drawCursorAsBlock = false; | - | ||||||||||||||||||||||||
1963 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
1964 | QTextLayout::FormatRange o; | - | ||||||||||||||||||||||||
1965 | o.start = context.cursorPosition - blpos; | - | ||||||||||||||||||||||||
1966 | o.length = 1; | - | ||||||||||||||||||||||||
1967 | o.format.setForeground(palette().base()); | - | ||||||||||||||||||||||||
1968 | o.format.setBackground(palette().text()); | - | ||||||||||||||||||||||||
1969 | selections.append(o); | - | ||||||||||||||||||||||||
1970 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1971 | } | - | ||||||||||||||||||||||||
1972 | - | |||||||||||||||||||||||||
1973 | - | |||||||||||||||||||||||||
1974 | if (!placeholderText().isEmpty() && document()->isEmpty()) {
| 0 | ||||||||||||||||||||||||
1975 | Q_D(QPlainTextEdit); | - | ||||||||||||||||||||||||
1976 | QColor col = d->control->palette().text().color(); | - | ||||||||||||||||||||||||
1977 | col.setAlpha(128); | - | ||||||||||||||||||||||||
1978 | painter.setPen(col); | - | ||||||||||||||||||||||||
1979 | const int margin = int(document()->documentMargin()); | - | ||||||||||||||||||||||||
1980 | painter.drawText(r.adjusted(margin, 0, 0, 0), Qt::AlignTop | Qt::TextWordWrap, placeholderText()); | - | ||||||||||||||||||||||||
1981 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
1982 | layout->draw(&painter, offset, selections, er); | - | ||||||||||||||||||||||||
1983 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1984 | if ((drawCursor && !drawCursorAsBlock)
| 0 | ||||||||||||||||||||||||
1985 | || (editable && context.cursorPosition < -1
| 0 | ||||||||||||||||||||||||
1986 | && !layout->preeditAreaText().isEmpty())) {
| 0 | ||||||||||||||||||||||||
1987 | int cpos = context.cursorPosition; | - | ||||||||||||||||||||||||
1988 | if (cpos < -1)
| 0 | ||||||||||||||||||||||||
1989 | cpos = layout->preeditAreaPosition() - (cpos + 2); never executed: cpos = layout->preeditAreaPosition() - (cpos + 2); | 0 | ||||||||||||||||||||||||
1990 | else | - | ||||||||||||||||||||||||
1991 | cpos -= blpos; never executed: cpos -= blpos; | 0 | ||||||||||||||||||||||||
1992 | layout->drawCursor(&painter, offset, cpos, cursorWidth()); | - | ||||||||||||||||||||||||
1993 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1994 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1995 | - | |||||||||||||||||||||||||
1996 | offset.ry() += r.height(); | - | ||||||||||||||||||||||||
1997 | if (offset.y() > viewportRect.height())
| 0 | ||||||||||||||||||||||||
1998 | break; never executed: break; | 0 | ||||||||||||||||||||||||
1999 | block = block.next(); | - | ||||||||||||||||||||||||
2000 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2001 | - | |||||||||||||||||||||||||
2002 | if (backgroundVisible() && !block.isValid() && offset.y() <= er.bottom()
| 0 | ||||||||||||||||||||||||
2003 | && (centerOnScroll() || verticalScrollBar()->maximum() == verticalScrollBar()->minimum())) {
| 0 | ||||||||||||||||||||||||
2004 | painter.fillRect(QRect(QPoint((int)er.left(), (int)offset.y()), er.bottomRight()), palette().background()); | - | ||||||||||||||||||||||||
2005 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2006 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2007 | - | |||||||||||||||||||||||||
2008 | - | |||||||||||||||||||||||||
2009 | void QPlainTextEditPrivate::updateDefaultTextOption() | - | ||||||||||||||||||||||||
2010 | { | - | ||||||||||||||||||||||||
2011 | QTextDocument *doc = control->document(); | - | ||||||||||||||||||||||||
2012 | - | |||||||||||||||||||||||||
2013 | QTextOption opt = doc->defaultTextOption(); | - | ||||||||||||||||||||||||
2014 | QTextOption::WrapMode oldWrapMode = opt.wrapMode(); | - | ||||||||||||||||||||||||
2015 | - | |||||||||||||||||||||||||
2016 | if (lineWrap == QPlainTextEdit::NoWrap)
| 0 | ||||||||||||||||||||||||
2017 | opt.setWrapMode(QTextOption::NoWrap); never executed: opt.setWrapMode(QTextOption::NoWrap); | 0 | ||||||||||||||||||||||||
2018 | else | - | ||||||||||||||||||||||||
2019 | opt.setWrapMode(wordWrap); never executed: opt.setWrapMode(wordWrap); | 0 | ||||||||||||||||||||||||
2020 | - | |||||||||||||||||||||||||
2021 | if (opt.wrapMode() != oldWrapMode)
| 0 | ||||||||||||||||||||||||
2022 | doc->setDefaultTextOption(opt); never executed: doc->setDefaultTextOption(opt); | 0 | ||||||||||||||||||||||||
2023 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2024 | - | |||||||||||||||||||||||||
2025 | - | |||||||||||||||||||||||||
2026 | /*! \reimp | - | ||||||||||||||||||||||||
2027 | */ | - | ||||||||||||||||||||||||
2028 | void QPlainTextEdit::mousePressEvent(QMouseEvent *e) | - | ||||||||||||||||||||||||
2029 | { | - | ||||||||||||||||||||||||
2030 | Q_D(QPlainTextEdit); | - | ||||||||||||||||||||||||
2031 | #ifdef QT_KEYPAD_NAVIGATION | - | ||||||||||||||||||||||||
2032 | if (QApplication::keypadNavigationEnabled() && !hasEditFocus()) | - | ||||||||||||||||||||||||
2033 | setEditFocus(true); | - | ||||||||||||||||||||||||
2034 | #endif | - | ||||||||||||||||||||||||
2035 | d->sendControlEvent(e); | - | ||||||||||||||||||||||||
2036 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2037 | - | |||||||||||||||||||||||||
2038 | /*! \reimp | - | ||||||||||||||||||||||||
2039 | */ | - | ||||||||||||||||||||||||
2040 | void QPlainTextEdit::mouseMoveEvent(QMouseEvent *e) | - | ||||||||||||||||||||||||
2041 | { | - | ||||||||||||||||||||||||
2042 | Q_D(QPlainTextEdit); | - | ||||||||||||||||||||||||
2043 | d->inDrag = false; // paranoia | - | ||||||||||||||||||||||||
2044 | const QPoint pos = e->pos(); | - | ||||||||||||||||||||||||
2045 | d->sendControlEvent(e); | - | ||||||||||||||||||||||||
2046 | if (!(e->buttons() & Qt::LeftButton))
| 0 | ||||||||||||||||||||||||
2047 | return; never executed: return; | 0 | ||||||||||||||||||||||||
2048 | if (e->source() == Qt::MouseEventNotSynthesized) {
| 0 | ||||||||||||||||||||||||
2049 | const QRect visible = d->viewport->rect(); | - | ||||||||||||||||||||||||
2050 | if (visible.contains(pos))
| 0 | ||||||||||||||||||||||||
2051 | d->autoScrollTimer.stop(); never executed: d->autoScrollTimer.stop(); | 0 | ||||||||||||||||||||||||
2052 | else if (!d->autoScrollTimer.isActive())
| 0 | ||||||||||||||||||||||||
2053 | d->autoScrollTimer.start(100, this); never executed: d->autoScrollTimer.start(100, this); | 0 | ||||||||||||||||||||||||
2054 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2055 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2056 | - | |||||||||||||||||||||||||
2057 | /*! \reimp | - | ||||||||||||||||||||||||
2058 | */ | - | ||||||||||||||||||||||||
2059 | void QPlainTextEdit::mouseReleaseEvent(QMouseEvent *e) | - | ||||||||||||||||||||||||
2060 | { | - | ||||||||||||||||||||||||
2061 | Q_D(QPlainTextEdit); | - | ||||||||||||||||||||||||
2062 | d->sendControlEvent(e); | - | ||||||||||||||||||||||||
2063 | if (e->source() == Qt::MouseEventNotSynthesized && d->autoScrollTimer.isActive()) {
| 0 | ||||||||||||||||||||||||
2064 | d->autoScrollTimer.stop(); | - | ||||||||||||||||||||||||
2065 | d->ensureCursorVisible(); | - | ||||||||||||||||||||||||
2066 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2067 | - | |||||||||||||||||||||||||
2068 | if (!isReadOnly() && rect().contains(e->pos()))
| 0 | ||||||||||||||||||||||||
2069 | d->handleSoftwareInputPanel(e->button(), d->clickCausedFocus); never executed: d->handleSoftwareInputPanel(e->button(), d->clickCausedFocus); | 0 | ||||||||||||||||||||||||
2070 | d->clickCausedFocus = 0; | - | ||||||||||||||||||||||||
2071 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2072 | - | |||||||||||||||||||||||||
2073 | /*! \reimp | - | ||||||||||||||||||||||||
2074 | */ | - | ||||||||||||||||||||||||
2075 | void QPlainTextEdit::mouseDoubleClickEvent(QMouseEvent *e) | - | ||||||||||||||||||||||||
2076 | { | - | ||||||||||||||||||||||||
2077 | Q_D(QPlainTextEdit); | - | ||||||||||||||||||||||||
2078 | d->sendControlEvent(e); | - | ||||||||||||||||||||||||
2079 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2080 | - | |||||||||||||||||||||||||
2081 | /*! \reimp | - | ||||||||||||||||||||||||
2082 | */ | - | ||||||||||||||||||||||||
2083 | bool QPlainTextEdit::focusNextPrevChild(bool next) | - | ||||||||||||||||||||||||
2084 | { | - | ||||||||||||||||||||||||
2085 | Q_D(const QPlainTextEdit); | - | ||||||||||||||||||||||||
2086 | if (!d->tabChangesFocus && d->control->textInteractionFlags() & Qt::TextEditable)
| 0 | ||||||||||||||||||||||||
2087 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
2088 | return QAbstractScrollArea::focusNextPrevChild(next); never executed: return QAbstractScrollArea::focusNextPrevChild(next); | 0 | ||||||||||||||||||||||||
2089 | } | - | ||||||||||||||||||||||||
2090 | - | |||||||||||||||||||||||||
2091 | #ifndef QT_NO_CONTEXTMENU | - | ||||||||||||||||||||||||
2092 | /*! | - | ||||||||||||||||||||||||
2093 | \fn void QPlainTextEdit::contextMenuEvent(QContextMenuEvent *event) | - | ||||||||||||||||||||||||
2094 | - | |||||||||||||||||||||||||
2095 | Shows the standard context menu created with createStandardContextMenu(). | - | ||||||||||||||||||||||||
2096 | - | |||||||||||||||||||||||||
2097 | If you do not want the text edit to have a context menu, you can set | - | ||||||||||||||||||||||||
2098 | its \l contextMenuPolicy to Qt::NoContextMenu. If you want to | - | ||||||||||||||||||||||||
2099 | customize the context menu, reimplement this function. If you want | - | ||||||||||||||||||||||||
2100 | to extend the standard context menu, reimplement this function, call | - | ||||||||||||||||||||||||
2101 | createStandardContextMenu() and extend the menu returned. | - | ||||||||||||||||||||||||
2102 | - | |||||||||||||||||||||||||
2103 | Information about the event is passed in the \a event object. | - | ||||||||||||||||||||||||
2104 | - | |||||||||||||||||||||||||
2105 | \snippet code/src_gui_widgets_qplaintextedit.cpp 0 | - | ||||||||||||||||||||||||
2106 | */ | - | ||||||||||||||||||||||||
2107 | void QPlainTextEdit::contextMenuEvent(QContextMenuEvent *e) | - | ||||||||||||||||||||||||
2108 | { | - | ||||||||||||||||||||||||
2109 | Q_D(QPlainTextEdit); | - | ||||||||||||||||||||||||
2110 | d->sendControlEvent(e); | - | ||||||||||||||||||||||||
2111 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2112 | #endif // QT_NO_CONTEXTMENU | - | ||||||||||||||||||||||||
2113 | - | |||||||||||||||||||||||||
2114 | #ifndef QT_NO_DRAGANDDROP | - | ||||||||||||||||||||||||
2115 | /*! \reimp | - | ||||||||||||||||||||||||
2116 | */ | - | ||||||||||||||||||||||||
2117 | void QPlainTextEdit::dragEnterEvent(QDragEnterEvent *e) | - | ||||||||||||||||||||||||
2118 | { | - | ||||||||||||||||||||||||
2119 | Q_D(QPlainTextEdit); | - | ||||||||||||||||||||||||
2120 | d->inDrag = true; | - | ||||||||||||||||||||||||
2121 | d->sendControlEvent(e); | - | ||||||||||||||||||||||||
2122 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2123 | - | |||||||||||||||||||||||||
2124 | /*! \reimp | - | ||||||||||||||||||||||||
2125 | */ | - | ||||||||||||||||||||||||
2126 | void QPlainTextEdit::dragLeaveEvent(QDragLeaveEvent *e) | - | ||||||||||||||||||||||||
2127 | { | - | ||||||||||||||||||||||||
2128 | Q_D(QPlainTextEdit); | - | ||||||||||||||||||||||||
2129 | d->inDrag = false; | - | ||||||||||||||||||||||||
2130 | d->autoScrollTimer.stop(); | - | ||||||||||||||||||||||||
2131 | d->sendControlEvent(e); | - | ||||||||||||||||||||||||
2132 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2133 | - | |||||||||||||||||||||||||
2134 | /*! \reimp | - | ||||||||||||||||||||||||
2135 | */ | - | ||||||||||||||||||||||||
2136 | void QPlainTextEdit::dragMoveEvent(QDragMoveEvent *e) | - | ||||||||||||||||||||||||
2137 | { | - | ||||||||||||||||||||||||
2138 | Q_D(QPlainTextEdit); | - | ||||||||||||||||||||||||
2139 | d->autoScrollDragPos = e->pos(); | - | ||||||||||||||||||||||||
2140 | if (!d->autoScrollTimer.isActive())
| 0 | ||||||||||||||||||||||||
2141 | d->autoScrollTimer.start(100, this); never executed: d->autoScrollTimer.start(100, this); | 0 | ||||||||||||||||||||||||
2142 | d->sendControlEvent(e); | - | ||||||||||||||||||||||||
2143 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2144 | - | |||||||||||||||||||||||||
2145 | /*! \reimp | - | ||||||||||||||||||||||||
2146 | */ | - | ||||||||||||||||||||||||
2147 | void QPlainTextEdit::dropEvent(QDropEvent *e) | - | ||||||||||||||||||||||||
2148 | { | - | ||||||||||||||||||||||||
2149 | Q_D(QPlainTextEdit); | - | ||||||||||||||||||||||||
2150 | d->inDrag = false; | - | ||||||||||||||||||||||||
2151 | d->autoScrollTimer.stop(); | - | ||||||||||||||||||||||||
2152 | d->sendControlEvent(e); | - | ||||||||||||||||||||||||
2153 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2154 | - | |||||||||||||||||||||||||
2155 | #endif // QT_NO_DRAGANDDROP | - | ||||||||||||||||||||||||
2156 | - | |||||||||||||||||||||||||
2157 | /*! \reimp | - | ||||||||||||||||||||||||
2158 | */ | - | ||||||||||||||||||||||||
2159 | void QPlainTextEdit::inputMethodEvent(QInputMethodEvent *e) | - | ||||||||||||||||||||||||
2160 | { | - | ||||||||||||||||||||||||
2161 | Q_D(QPlainTextEdit); | - | ||||||||||||||||||||||||
2162 | #ifdef QT_KEYPAD_NAVIGATION | - | ||||||||||||||||||||||||
2163 | if (d->control->textInteractionFlags() & Qt::TextEditable | - | ||||||||||||||||||||||||
2164 | && QApplication::keypadNavigationEnabled() | - | ||||||||||||||||||||||||
2165 | && !hasEditFocus()) { | - | ||||||||||||||||||||||||
2166 | setEditFocus(true); | - | ||||||||||||||||||||||||
2167 | selectAll(); // so text is replaced rather than appended to | - | ||||||||||||||||||||||||
2168 | } | - | ||||||||||||||||||||||||
2169 | #endif | - | ||||||||||||||||||||||||
2170 | d->sendControlEvent(e); | - | ||||||||||||||||||||||||
2171 | ensureCursorVisible(); | - | ||||||||||||||||||||||||
2172 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2173 | - | |||||||||||||||||||||||||
2174 | /*!\reimp | - | ||||||||||||||||||||||||
2175 | */ | - | ||||||||||||||||||||||||
2176 | void QPlainTextEdit::scrollContentsBy(int dx, int /*dy*/) | - | ||||||||||||||||||||||||
2177 | { | - | ||||||||||||||||||||||||
2178 | Q_D(QPlainTextEdit); | - | ||||||||||||||||||||||||
2179 | d->setTopLine(d->vbar->value(), dx); | - | ||||||||||||||||||||||||
2180 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2181 | - | |||||||||||||||||||||||||
2182 | /*!\reimp | - | ||||||||||||||||||||||||
2183 | */ | - | ||||||||||||||||||||||||
2184 | QVariant QPlainTextEdit::inputMethodQuery(Qt::InputMethodQuery property) const | - | ||||||||||||||||||||||||
2185 | { | - | ||||||||||||||||||||||||
2186 | return inputMethodQuery(property, QVariant()); never executed: return inputMethodQuery(property, QVariant()); | 0 | ||||||||||||||||||||||||
2187 | } | - | ||||||||||||||||||||||||
2188 | - | |||||||||||||||||||||||||
2189 | /*!\internal | - | ||||||||||||||||||||||||
2190 | */ | - | ||||||||||||||||||||||||
2191 | QVariant QPlainTextEdit::inputMethodQuery(Qt::InputMethodQuery query, QVariant argument) const | - | ||||||||||||||||||||||||
2192 | { | - | ||||||||||||||||||||||||
2193 | Q_D(const QPlainTextEdit); | - | ||||||||||||||||||||||||
2194 | if (query == Qt::ImHints)
| 0 | ||||||||||||||||||||||||
2195 | return QWidget::inputMethodQuery(query); never executed: return QWidget::inputMethodQuery(query); | 0 | ||||||||||||||||||||||||
2196 | const QVariant v = d->control->inputMethodQuery(query, argument); | - | ||||||||||||||||||||||||
2197 | const QPointF offset = contentOffset(); | - | ||||||||||||||||||||||||
2198 | switch (v.type()) { | - | ||||||||||||||||||||||||
2199 | case QVariant::RectF: never executed: case QVariant::RectF: | 0 | ||||||||||||||||||||||||
2200 | return v.toRectF().translated(offset); never executed: return v.toRectF().translated(offset); | 0 | ||||||||||||||||||||||||
2201 | case QVariant::PointF: never executed: case QVariant::PointF: | 0 | ||||||||||||||||||||||||
2202 | return v.toPointF() + offset; never executed: return v.toPointF() + offset; | 0 | ||||||||||||||||||||||||
2203 | case QVariant::Rect: never executed: case QVariant::Rect: | 0 | ||||||||||||||||||||||||
2204 | return v.toRect().translated(offset.toPoint()); never executed: return v.toRect().translated(offset.toPoint()); | 0 | ||||||||||||||||||||||||
2205 | case QVariant::Point: never executed: case QVariant::Point: | 0 | ||||||||||||||||||||||||
2206 | return v.toPoint() + offset.toPoint(); never executed: return v.toPoint() + offset.toPoint(); | 0 | ||||||||||||||||||||||||
2207 | default: never executed: default: | 0 | ||||||||||||||||||||||||
2208 | break; never executed: break; | 0 | ||||||||||||||||||||||||
2209 | } | - | ||||||||||||||||||||||||
2210 | return v; never executed: return v; | 0 | ||||||||||||||||||||||||
2211 | } | - | ||||||||||||||||||||||||
2212 | - | |||||||||||||||||||||||||
2213 | /*! \reimp | - | ||||||||||||||||||||||||
2214 | */ | - | ||||||||||||||||||||||||
2215 | void QPlainTextEdit::focusInEvent(QFocusEvent *e) | - | ||||||||||||||||||||||||
2216 | { | - | ||||||||||||||||||||||||
2217 | Q_D(QPlainTextEdit); | - | ||||||||||||||||||||||||
2218 | if (e->reason() == Qt::MouseFocusReason) {
| 0 | ||||||||||||||||||||||||
2219 | d->clickCausedFocus = 1; | - | ||||||||||||||||||||||||
2220 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2221 | QAbstractScrollArea::focusInEvent(e); | - | ||||||||||||||||||||||||
2222 | d->sendControlEvent(e); | - | ||||||||||||||||||||||||
2223 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2224 | - | |||||||||||||||||||||||||
2225 | /*! \reimp | - | ||||||||||||||||||||||||
2226 | */ | - | ||||||||||||||||||||||||
2227 | void QPlainTextEdit::focusOutEvent(QFocusEvent *e) | - | ||||||||||||||||||||||||
2228 | { | - | ||||||||||||||||||||||||
2229 | Q_D(QPlainTextEdit); | - | ||||||||||||||||||||||||
2230 | QAbstractScrollArea::focusOutEvent(e); | - | ||||||||||||||||||||||||
2231 | d->sendControlEvent(e); | - | ||||||||||||||||||||||||
2232 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2233 | - | |||||||||||||||||||||||||
2234 | /*! \reimp | - | ||||||||||||||||||||||||
2235 | */ | - | ||||||||||||||||||||||||
2236 | void QPlainTextEdit::showEvent(QShowEvent *) | - | ||||||||||||||||||||||||
2237 | { | - | ||||||||||||||||||||||||
2238 | Q_D(QPlainTextEdit); | - | ||||||||||||||||||||||||
2239 | if (d->showCursorOnInitialShow) {
| 0 | ||||||||||||||||||||||||
2240 | d->showCursorOnInitialShow = false; | - | ||||||||||||||||||||||||
2241 | ensureCursorVisible(); | - | ||||||||||||||||||||||||
2242 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2243 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2244 | - | |||||||||||||||||||||||||
2245 | /*! \reimp | - | ||||||||||||||||||||||||
2246 | */ | - | ||||||||||||||||||||||||
2247 | void QPlainTextEdit::changeEvent(QEvent *e) | - | ||||||||||||||||||||||||
2248 | { | - | ||||||||||||||||||||||||
2249 | Q_D(QPlainTextEdit); | - | ||||||||||||||||||||||||
2250 | QAbstractScrollArea::changeEvent(e); | - | ||||||||||||||||||||||||
2251 | if (e->type() == QEvent::ApplicationFontChange
| 0 | ||||||||||||||||||||||||
2252 | || e->type() == QEvent::FontChange) {
| 0 | ||||||||||||||||||||||||
2253 | d->control->document()->setDefaultFont(font()); | - | ||||||||||||||||||||||||
2254 | } else if(e->type() == QEvent::ActivationChange) { never executed: end of block
| 0 | ||||||||||||||||||||||||
2255 | if (!isActiveWindow())
| 0 | ||||||||||||||||||||||||
2256 | d->autoScrollTimer.stop(); never executed: d->autoScrollTimer.stop(); | 0 | ||||||||||||||||||||||||
2257 | } else if (e->type() == QEvent::EnabledChange) { never executed: end of block
| 0 | ||||||||||||||||||||||||
2258 | e->setAccepted(isEnabled()); | - | ||||||||||||||||||||||||
2259 | d->sendControlEvent(e); | - | ||||||||||||||||||||||||
2260 | } else if (e->type() == QEvent::PaletteChange) { never executed: end of block
| 0 | ||||||||||||||||||||||||
2261 | d->control->setPalette(palette()); | - | ||||||||||||||||||||||||
2262 | } else if (e->type() == QEvent::LayoutDirectionChange) { never executed: end of block
| 0 | ||||||||||||||||||||||||
2263 | d->sendControlEvent(e); | - | ||||||||||||||||||||||||
2264 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2265 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2266 | - | |||||||||||||||||||||||||
2267 | /*! \reimp | - | ||||||||||||||||||||||||
2268 | */ | - | ||||||||||||||||||||||||
2269 | #ifndef QT_NO_WHEELEVENT | - | ||||||||||||||||||||||||
2270 | void QPlainTextEdit::wheelEvent(QWheelEvent *e) | - | ||||||||||||||||||||||||
2271 | { | - | ||||||||||||||||||||||||
2272 | Q_D(QPlainTextEdit); | - | ||||||||||||||||||||||||
2273 | if (!(d->control->textInteractionFlags() & Qt::TextEditable)) {
| 0 | ||||||||||||||||||||||||
2274 | if (e->modifiers() & Qt::ControlModifier) {
| 0 | ||||||||||||||||||||||||
2275 | float delta = e->angleDelta().y() / 120.f; | - | ||||||||||||||||||||||||
2276 | zoomInF(delta); | - | ||||||||||||||||||||||||
2277 | return; never executed: return; | 0 | ||||||||||||||||||||||||
2278 | } | - | ||||||||||||||||||||||||
2279 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2280 | QAbstractScrollArea::wheelEvent(e); | - | ||||||||||||||||||||||||
2281 | updateMicroFocus(); | - | ||||||||||||||||||||||||
2282 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2283 | #endif | - | ||||||||||||||||||||||||
2284 | - | |||||||||||||||||||||||||
2285 | /*! | - | ||||||||||||||||||||||||
2286 | \fn QPlainTextEdit::zoomIn(int range) | - | ||||||||||||||||||||||||
2287 | - | |||||||||||||||||||||||||
2288 | Zooms in on the text by making the base font size \a range | - | ||||||||||||||||||||||||
2289 | points larger and recalculating all font sizes to be the new size. | - | ||||||||||||||||||||||||
2290 | This does not change the size of any images. | - | ||||||||||||||||||||||||
2291 | - | |||||||||||||||||||||||||
2292 | \sa zoomOut() | - | ||||||||||||||||||||||||
2293 | */ | - | ||||||||||||||||||||||||
2294 | void QPlainTextEdit::zoomIn(int range) | - | ||||||||||||||||||||||||
2295 | { | - | ||||||||||||||||||||||||
2296 | zoomInF(range); | - | ||||||||||||||||||||||||
2297 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2298 | - | |||||||||||||||||||||||||
2299 | /*! | - | ||||||||||||||||||||||||
2300 | \fn QPlainTextEdit::zoomOut(int range) | - | ||||||||||||||||||||||||
2301 | - | |||||||||||||||||||||||||
2302 | \overload | - | ||||||||||||||||||||||||
2303 | - | |||||||||||||||||||||||||
2304 | Zooms out on the text by making the base font size \a range points | - | ||||||||||||||||||||||||
2305 | smaller and recalculating all font sizes to be the new size. This | - | ||||||||||||||||||||||||
2306 | does not change the size of any images. | - | ||||||||||||||||||||||||
2307 | - | |||||||||||||||||||||||||
2308 | \sa zoomIn() | - | ||||||||||||||||||||||||
2309 | */ | - | ||||||||||||||||||||||||
2310 | void QPlainTextEdit::zoomOut(int range) | - | ||||||||||||||||||||||||
2311 | { | - | ||||||||||||||||||||||||
2312 | zoomInF(-range); | - | ||||||||||||||||||||||||
2313 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2314 | - | |||||||||||||||||||||||||
2315 | /*! | - | ||||||||||||||||||||||||
2316 | \internal | - | ||||||||||||||||||||||||
2317 | */ | - | ||||||||||||||||||||||||
2318 | void QPlainTextEdit::zoomInF(float range) | - | ||||||||||||||||||||||||
2319 | { | - | ||||||||||||||||||||||||
2320 | if (range == 0.f)
| 0 | ||||||||||||||||||||||||
2321 | return; never executed: return; | 0 | ||||||||||||||||||||||||
2322 | QFont f = font(); | - | ||||||||||||||||||||||||
2323 | const float newSize = f.pointSizeF() + range; | - | ||||||||||||||||||||||||
2324 | if (newSize <= 0)
| 0 | ||||||||||||||||||||||||
2325 | return; never executed: return; | 0 | ||||||||||||||||||||||||
2326 | f.setPointSizeF(newSize); | - | ||||||||||||||||||||||||
2327 | setFont(f); | - | ||||||||||||||||||||||||
2328 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2329 | - | |||||||||||||||||||||||||
2330 | #ifndef QT_NO_CONTEXTMENU | - | ||||||||||||||||||||||||
2331 | /*! This function creates the standard context menu which is shown | - | ||||||||||||||||||||||||
2332 | when the user clicks on the text edit with the right mouse | - | ||||||||||||||||||||||||
2333 | button. It is called from the default contextMenuEvent() handler. | - | ||||||||||||||||||||||||
2334 | The popup menu's ownership is transferred to the caller. | - | ||||||||||||||||||||||||
2335 | - | |||||||||||||||||||||||||
2336 | We recommend that you use the createStandardContextMenu(QPoint) version instead | - | ||||||||||||||||||||||||
2337 | which will enable the actions that are sensitive to where the user clicked. | - | ||||||||||||||||||||||||
2338 | */ | - | ||||||||||||||||||||||||
2339 | - | |||||||||||||||||||||||||
2340 | QMenu *QPlainTextEdit::createStandardContextMenu() | - | ||||||||||||||||||||||||
2341 | { | - | ||||||||||||||||||||||||
2342 | Q_D(QPlainTextEdit); | - | ||||||||||||||||||||||||
2343 | return d->control->createStandardContextMenu(QPointF(), this); never executed: return d->control->createStandardContextMenu(QPointF(), this); | 0 | ||||||||||||||||||||||||
2344 | } | - | ||||||||||||||||||||||||
2345 | - | |||||||||||||||||||||||||
2346 | /*! | - | ||||||||||||||||||||||||
2347 | \since 5.5 | - | ||||||||||||||||||||||||
2348 | This function creates the standard context menu which is shown | - | ||||||||||||||||||||||||
2349 | when the user clicks on the text edit with the right mouse | - | ||||||||||||||||||||||||
2350 | button. It is called from the default contextMenuEvent() handler | - | ||||||||||||||||||||||||
2351 | and it takes the \a position in document coordinates where the mouse click was. | - | ||||||||||||||||||||||||
2352 | This can enable actions that are sensitive to the position where the user clicked. | - | ||||||||||||||||||||||||
2353 | The popup menu's ownership is transferred to the caller. | - | ||||||||||||||||||||||||
2354 | */ | - | ||||||||||||||||||||||||
2355 | - | |||||||||||||||||||||||||
2356 | QMenu *QPlainTextEdit::createStandardContextMenu(const QPoint &position) | - | ||||||||||||||||||||||||
2357 | { | - | ||||||||||||||||||||||||
2358 | Q_D(QPlainTextEdit); | - | ||||||||||||||||||||||||
2359 | return d->control->createStandardContextMenu(position, this); never executed: return d->control->createStandardContextMenu(position, this); | 0 | ||||||||||||||||||||||||
2360 | } | - | ||||||||||||||||||||||||
2361 | #endif // QT_NO_CONTEXTMENU | - | ||||||||||||||||||||||||
2362 | - | |||||||||||||||||||||||||
2363 | /*! | - | ||||||||||||||||||||||||
2364 | returns a QTextCursor at position \a pos (in viewport coordinates). | - | ||||||||||||||||||||||||
2365 | */ | - | ||||||||||||||||||||||||
2366 | QTextCursor QPlainTextEdit::cursorForPosition(const QPoint &pos) const | - | ||||||||||||||||||||||||
2367 | { | - | ||||||||||||||||||||||||
2368 | Q_D(const QPlainTextEdit); | - | ||||||||||||||||||||||||
2369 | return d->control->cursorForPosition(d->mapToContents(pos)); never executed: return d->control->cursorForPosition(d->mapToContents(pos)); | 0 | ||||||||||||||||||||||||
2370 | } | - | ||||||||||||||||||||||||
2371 | - | |||||||||||||||||||||||||
2372 | /*! | - | ||||||||||||||||||||||||
2373 | returns a rectangle (in viewport coordinates) that includes the | - | ||||||||||||||||||||||||
2374 | \a cursor. | - | ||||||||||||||||||||||||
2375 | */ | - | ||||||||||||||||||||||||
2376 | QRect QPlainTextEdit::cursorRect(const QTextCursor &cursor) const | - | ||||||||||||||||||||||||
2377 | { | - | ||||||||||||||||||||||||
2378 | Q_D(const QPlainTextEdit); | - | ||||||||||||||||||||||||
2379 | if (cursor.isNull())
| 0 | ||||||||||||||||||||||||
2380 | return QRect(); never executed: return QRect(); | 0 | ||||||||||||||||||||||||
2381 | - | |||||||||||||||||||||||||
2382 | QRect r = d->control->cursorRect(cursor).toRect(); | - | ||||||||||||||||||||||||
2383 | r.translate(-d->horizontalOffset(),-(int)d->verticalOffset()); | - | ||||||||||||||||||||||||
2384 | return r; never executed: return r; | 0 | ||||||||||||||||||||||||
2385 | } | - | ||||||||||||||||||||||||
2386 | - | |||||||||||||||||||||||||
2387 | /*! | - | ||||||||||||||||||||||||
2388 | returns a rectangle (in viewport coordinates) that includes the | - | ||||||||||||||||||||||||
2389 | cursor of the text edit. | - | ||||||||||||||||||||||||
2390 | */ | - | ||||||||||||||||||||||||
2391 | QRect QPlainTextEdit::cursorRect() const | - | ||||||||||||||||||||||||
2392 | { | - | ||||||||||||||||||||||||
2393 | Q_D(const QPlainTextEdit); | - | ||||||||||||||||||||||||
2394 | QRect r = d->control->cursorRect().toRect(); | - | ||||||||||||||||||||||||
2395 | r.translate(-d->horizontalOffset(),-(int)d->verticalOffset()); | - | ||||||||||||||||||||||||
2396 | return r; never executed: return r; | 0 | ||||||||||||||||||||||||
2397 | } | - | ||||||||||||||||||||||||
2398 | - | |||||||||||||||||||||||||
2399 | - | |||||||||||||||||||||||||
2400 | /*! | - | ||||||||||||||||||||||||
2401 | \property QPlainTextEdit::overwriteMode | - | ||||||||||||||||||||||||
2402 | \brief whether text entered by the user will overwrite existing text | - | ||||||||||||||||||||||||
2403 | - | |||||||||||||||||||||||||
2404 | As with many text editors, the plain text editor widget can be configured | - | ||||||||||||||||||||||||
2405 | to insert or overwrite existing text with new text entered by the user. | - | ||||||||||||||||||||||||
2406 | - | |||||||||||||||||||||||||
2407 | If this property is \c true, existing text is overwritten, character-for-character | - | ||||||||||||||||||||||||
2408 | by new text; otherwise, text is inserted at the cursor position, displacing | - | ||||||||||||||||||||||||
2409 | existing text. | - | ||||||||||||||||||||||||
2410 | - | |||||||||||||||||||||||||
2411 | By default, this property is \c false (new text does not overwrite existing text). | - | ||||||||||||||||||||||||
2412 | */ | - | ||||||||||||||||||||||||
2413 | - | |||||||||||||||||||||||||
2414 | bool QPlainTextEdit::overwriteMode() const | - | ||||||||||||||||||||||||
2415 | { | - | ||||||||||||||||||||||||
2416 | Q_D(const QPlainTextEdit); | - | ||||||||||||||||||||||||
2417 | return d->control->overwriteMode(); never executed: return d->control->overwriteMode(); | 0 | ||||||||||||||||||||||||
2418 | } | - | ||||||||||||||||||||||||
2419 | - | |||||||||||||||||||||||||
2420 | void QPlainTextEdit::setOverwriteMode(bool overwrite) | - | ||||||||||||||||||||||||
2421 | { | - | ||||||||||||||||||||||||
2422 | Q_D(QPlainTextEdit); | - | ||||||||||||||||||||||||
2423 | d->control->setOverwriteMode(overwrite); | - | ||||||||||||||||||||||||
2424 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2425 | - | |||||||||||||||||||||||||
2426 | /*! | - | ||||||||||||||||||||||||
2427 | \property QPlainTextEdit::tabStopWidth | - | ||||||||||||||||||||||||
2428 | \brief the tab stop width in pixels | - | ||||||||||||||||||||||||
2429 | - | |||||||||||||||||||||||||
2430 | By default, this property contains a value of 80. | - | ||||||||||||||||||||||||
2431 | */ | - | ||||||||||||||||||||||||
2432 | - | |||||||||||||||||||||||||
2433 | int QPlainTextEdit::tabStopWidth() const | - | ||||||||||||||||||||||||
2434 | { | - | ||||||||||||||||||||||||
2435 | Q_D(const QPlainTextEdit); | - | ||||||||||||||||||||||||
2436 | return qRound(d->control->document()->defaultTextOption().tabStop()); never executed: return qRound(d->control->document()->defaultTextOption().tabStop()); | 0 | ||||||||||||||||||||||||
2437 | } | - | ||||||||||||||||||||||||
2438 | - | |||||||||||||||||||||||||
2439 | void QPlainTextEdit::setTabStopWidth(int width) | - | ||||||||||||||||||||||||
2440 | { | - | ||||||||||||||||||||||||
2441 | Q_D(QPlainTextEdit); | - | ||||||||||||||||||||||||
2442 | QTextOption opt = d->control->document()->defaultTextOption(); | - | ||||||||||||||||||||||||
2443 | if (opt.tabStop() == width || width < 0)
| 0 | ||||||||||||||||||||||||
2444 | return; never executed: return; | 0 | ||||||||||||||||||||||||
2445 | opt.setTabStop(width); | - | ||||||||||||||||||||||||
2446 | d->control->document()->setDefaultTextOption(opt); | - | ||||||||||||||||||||||||
2447 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2448 | - | |||||||||||||||||||||||||
2449 | /*! | - | ||||||||||||||||||||||||
2450 | \property QPlainTextEdit::cursorWidth | - | ||||||||||||||||||||||||
2451 | - | |||||||||||||||||||||||||
2452 | This property specifies the width of the cursor in pixels. The default value is 1. | - | ||||||||||||||||||||||||
2453 | */ | - | ||||||||||||||||||||||||
2454 | int QPlainTextEdit::cursorWidth() const | - | ||||||||||||||||||||||||
2455 | { | - | ||||||||||||||||||||||||
2456 | Q_D(const QPlainTextEdit); | - | ||||||||||||||||||||||||
2457 | return d->control->cursorWidth(); never executed: return d->control->cursorWidth(); | 0 | ||||||||||||||||||||||||
2458 | } | - | ||||||||||||||||||||||||
2459 | - | |||||||||||||||||||||||||
2460 | void QPlainTextEdit::setCursorWidth(int width) | - | ||||||||||||||||||||||||
2461 | { | - | ||||||||||||||||||||||||
2462 | Q_D(QPlainTextEdit); | - | ||||||||||||||||||||||||
2463 | d->control->setCursorWidth(width); | - | ||||||||||||||||||||||||
2464 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2465 | - | |||||||||||||||||||||||||
2466 | - | |||||||||||||||||||||||||
2467 | - | |||||||||||||||||||||||||
2468 | /*! | - | ||||||||||||||||||||||||
2469 | This function allows temporarily marking certain regions in the document | - | ||||||||||||||||||||||||
2470 | with a given color, specified as \a selections. This can be useful for | - | ||||||||||||||||||||||||
2471 | example in a programming editor to mark a whole line of text with a given | - | ||||||||||||||||||||||||
2472 | background color to indicate the existence of a breakpoint. | - | ||||||||||||||||||||||||
2473 | - | |||||||||||||||||||||||||
2474 | \sa QTextEdit::ExtraSelection, extraSelections() | - | ||||||||||||||||||||||||
2475 | */ | - | ||||||||||||||||||||||||
2476 | void QPlainTextEdit::setExtraSelections(const QList<QTextEdit::ExtraSelection> &selections) | - | ||||||||||||||||||||||||
2477 | { | - | ||||||||||||||||||||||||
2478 | Q_D(QPlainTextEdit); | - | ||||||||||||||||||||||||
2479 | d->control->setExtraSelections(selections); | - | ||||||||||||||||||||||||
2480 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2481 | - | |||||||||||||||||||||||||
2482 | /*! | - | ||||||||||||||||||||||||
2483 | Returns previously set extra selections. | - | ||||||||||||||||||||||||
2484 | - | |||||||||||||||||||||||||
2485 | \sa setExtraSelections() | - | ||||||||||||||||||||||||
2486 | */ | - | ||||||||||||||||||||||||
2487 | QList<QTextEdit::ExtraSelection> QPlainTextEdit::extraSelections() const | - | ||||||||||||||||||||||||
2488 | { | - | ||||||||||||||||||||||||
2489 | Q_D(const QPlainTextEdit); | - | ||||||||||||||||||||||||
2490 | return d->control->extraSelections(); never executed: return d->control->extraSelections(); | 0 | ||||||||||||||||||||||||
2491 | } | - | ||||||||||||||||||||||||
2492 | - | |||||||||||||||||||||||||
2493 | /*! | - | ||||||||||||||||||||||||
2494 | This function returns a new MIME data object to represent the contents | - | ||||||||||||||||||||||||
2495 | of the text edit's current selection. It is called when the selection needs | - | ||||||||||||||||||||||||
2496 | to be encapsulated into a new QMimeData object; for example, when a drag | - | ||||||||||||||||||||||||
2497 | and drop operation is started, or when data is copied to the clipboard. | - | ||||||||||||||||||||||||
2498 | - | |||||||||||||||||||||||||
2499 | If you reimplement this function, note that the ownership of the returned | - | ||||||||||||||||||||||||
2500 | QMimeData object is passed to the caller. The selection can be retrieved | - | ||||||||||||||||||||||||
2501 | by using the textCursor() function. | - | ||||||||||||||||||||||||
2502 | */ | - | ||||||||||||||||||||||||
2503 | QMimeData *QPlainTextEdit::createMimeDataFromSelection() const | - | ||||||||||||||||||||||||
2504 | { | - | ||||||||||||||||||||||||
2505 | Q_D(const QPlainTextEdit); | - | ||||||||||||||||||||||||
2506 | return d->control->QWidgetTextControl::createMimeDataFromSelection(); never executed: return d->control->QWidgetTextControl::createMimeDataFromSelection(); | 0 | ||||||||||||||||||||||||
2507 | } | - | ||||||||||||||||||||||||
2508 | - | |||||||||||||||||||||||||
2509 | /*! | - | ||||||||||||||||||||||||
2510 | This function returns \c true if the contents of the MIME data object, specified | - | ||||||||||||||||||||||||
2511 | by \a source, can be decoded and inserted into the document. It is called | - | ||||||||||||||||||||||||
2512 | for example when during a drag operation the mouse enters this widget and it | - | ||||||||||||||||||||||||
2513 | is necessary to determine whether it is possible to accept the drag. | - | ||||||||||||||||||||||||
2514 | */ | - | ||||||||||||||||||||||||
2515 | bool QPlainTextEdit::canInsertFromMimeData(const QMimeData *source) const | - | ||||||||||||||||||||||||
2516 | { | - | ||||||||||||||||||||||||
2517 | Q_D(const QPlainTextEdit); | - | ||||||||||||||||||||||||
2518 | return d->control->QWidgetTextControl::canInsertFromMimeData(source); never executed: return d->control->QWidgetTextControl::canInsertFromMimeData(source); | 0 | ||||||||||||||||||||||||
2519 | } | - | ||||||||||||||||||||||||
2520 | - | |||||||||||||||||||||||||
2521 | /*! | - | ||||||||||||||||||||||||
2522 | This function inserts the contents of the MIME data object, specified | - | ||||||||||||||||||||||||
2523 | by \a source, into the text edit at the current cursor position. It is | - | ||||||||||||||||||||||||
2524 | called whenever text is inserted as the result of a clipboard paste | - | ||||||||||||||||||||||||
2525 | operation, or when the text edit accepts data from a drag and drop | - | ||||||||||||||||||||||||
2526 | operation. | - | ||||||||||||||||||||||||
2527 | */ | - | ||||||||||||||||||||||||
2528 | void QPlainTextEdit::insertFromMimeData(const QMimeData *source) | - | ||||||||||||||||||||||||
2529 | { | - | ||||||||||||||||||||||||
2530 | Q_D(QPlainTextEdit); | - | ||||||||||||||||||||||||
2531 | d->control->QWidgetTextControl::insertFromMimeData(source); | - | ||||||||||||||||||||||||
2532 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2533 | - | |||||||||||||||||||||||||
2534 | /*! | - | ||||||||||||||||||||||||
2535 | \property QPlainTextEdit::readOnly | - | ||||||||||||||||||||||||
2536 | \brief whether the text edit is read-only | - | ||||||||||||||||||||||||
2537 | - | |||||||||||||||||||||||||
2538 | In a read-only text edit the user can only navigate through the | - | ||||||||||||||||||||||||
2539 | text and select text; modifying the text is not possible. | - | ||||||||||||||||||||||||
2540 | - | |||||||||||||||||||||||||
2541 | This property's default is false. | - | ||||||||||||||||||||||||
2542 | */ | - | ||||||||||||||||||||||||
2543 | - | |||||||||||||||||||||||||
2544 | bool QPlainTextEdit::isReadOnly() const | - | ||||||||||||||||||||||||
2545 | { | - | ||||||||||||||||||||||||
2546 | Q_D(const QPlainTextEdit); | - | ||||||||||||||||||||||||
2547 | return !(d->control->textInteractionFlags() & Qt::TextEditable); never executed: return !(d->control->textInteractionFlags() & Qt::TextEditable); | 0 | ||||||||||||||||||||||||
2548 | } | - | ||||||||||||||||||||||||
2549 | - | |||||||||||||||||||||||||
2550 | void QPlainTextEdit::setReadOnly(bool ro) | - | ||||||||||||||||||||||||
2551 | { | - | ||||||||||||||||||||||||
2552 | Q_D(QPlainTextEdit); | - | ||||||||||||||||||||||||
2553 | Qt::TextInteractionFlags flags = Qt::NoTextInteraction; | - | ||||||||||||||||||||||||
2554 | if (ro) {
| 0 | ||||||||||||||||||||||||
2555 | flags = Qt::TextSelectableByMouse; | - | ||||||||||||||||||||||||
2556 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
2557 | flags = Qt::TextEditorInteraction; | - | ||||||||||||||||||||||||
2558 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2559 | setAttribute(Qt::WA_InputMethodEnabled, shouldEnableInputMethod(this)); | - | ||||||||||||||||||||||||
2560 | d->control->setTextInteractionFlags(flags); | - | ||||||||||||||||||||||||
2561 | QEvent event(QEvent::ReadOnlyChange); | - | ||||||||||||||||||||||||
2562 | QApplication::sendEvent(this, &event); | - | ||||||||||||||||||||||||
2563 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2564 | - | |||||||||||||||||||||||||
2565 | /*! | - | ||||||||||||||||||||||||
2566 | \property QPlainTextEdit::textInteractionFlags | - | ||||||||||||||||||||||||
2567 | - | |||||||||||||||||||||||||
2568 | Specifies how the label should interact with user input if it displays text. | - | ||||||||||||||||||||||||
2569 | - | |||||||||||||||||||||||||
2570 | If the flags contain either Qt::LinksAccessibleByKeyboard or Qt::TextSelectableByKeyboard | - | ||||||||||||||||||||||||
2571 | then the focus policy is also automatically set to Qt::ClickFocus. | - | ||||||||||||||||||||||||
2572 | - | |||||||||||||||||||||||||
2573 | The default value depends on whether the QPlainTextEdit is read-only | - | ||||||||||||||||||||||||
2574 | or editable. | - | ||||||||||||||||||||||||
2575 | */ | - | ||||||||||||||||||||||||
2576 | - | |||||||||||||||||||||||||
2577 | void QPlainTextEdit::setTextInteractionFlags(Qt::TextInteractionFlags flags) | - | ||||||||||||||||||||||||
2578 | { | - | ||||||||||||||||||||||||
2579 | Q_D(QPlainTextEdit); | - | ||||||||||||||||||||||||
2580 | d->control->setTextInteractionFlags(flags); | - | ||||||||||||||||||||||||
2581 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2582 | - | |||||||||||||||||||||||||
2583 | Qt::TextInteractionFlags QPlainTextEdit::textInteractionFlags() const | - | ||||||||||||||||||||||||
2584 | { | - | ||||||||||||||||||||||||
2585 | Q_D(const QPlainTextEdit); | - | ||||||||||||||||||||||||
2586 | return d->control->textInteractionFlags(); never executed: return d->control->textInteractionFlags(); | 0 | ||||||||||||||||||||||||
2587 | } | - | ||||||||||||||||||||||||
2588 | - | |||||||||||||||||||||||||
2589 | /*! | - | ||||||||||||||||||||||||
2590 | Merges the properties specified in \a modifier into the current character | - | ||||||||||||||||||||||||
2591 | format by calling QTextCursor::mergeCharFormat on the editor's cursor. | - | ||||||||||||||||||||||||
2592 | If the editor has a selection then the properties of \a modifier are | - | ||||||||||||||||||||||||
2593 | directly applied to the selection. | - | ||||||||||||||||||||||||
2594 | - | |||||||||||||||||||||||||
2595 | \sa QTextCursor::mergeCharFormat() | - | ||||||||||||||||||||||||
2596 | */ | - | ||||||||||||||||||||||||
2597 | void QPlainTextEdit::mergeCurrentCharFormat(const QTextCharFormat &modifier) | - | ||||||||||||||||||||||||
2598 | { | - | ||||||||||||||||||||||||
2599 | Q_D(QPlainTextEdit); | - | ||||||||||||||||||||||||
2600 | d->control->mergeCurrentCharFormat(modifier); | - | ||||||||||||||||||||||||
2601 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2602 | - | |||||||||||||||||||||||||
2603 | /*! | - | ||||||||||||||||||||||||
2604 | Sets the char format that is be used when inserting new text to \a | - | ||||||||||||||||||||||||
2605 | format by calling QTextCursor::setCharFormat() on the editor's | - | ||||||||||||||||||||||||
2606 | cursor. If the editor has a selection then the char format is | - | ||||||||||||||||||||||||
2607 | directly applied to the selection. | - | ||||||||||||||||||||||||
2608 | */ | - | ||||||||||||||||||||||||
2609 | void QPlainTextEdit::setCurrentCharFormat(const QTextCharFormat &format) | - | ||||||||||||||||||||||||
2610 | { | - | ||||||||||||||||||||||||
2611 | Q_D(QPlainTextEdit); | - | ||||||||||||||||||||||||
2612 | d->control->setCurrentCharFormat(format); | - | ||||||||||||||||||||||||
2613 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2614 | - | |||||||||||||||||||||||||
2615 | /*! | - | ||||||||||||||||||||||||
2616 | Returns the char format that is used when inserting new text. | - | ||||||||||||||||||||||||
2617 | */ | - | ||||||||||||||||||||||||
2618 | QTextCharFormat QPlainTextEdit::currentCharFormat() const | - | ||||||||||||||||||||||||
2619 | { | - | ||||||||||||||||||||||||
2620 | Q_D(const QPlainTextEdit); | - | ||||||||||||||||||||||||
2621 | return d->control->currentCharFormat(); never executed: return d->control->currentCharFormat(); | 0 | ||||||||||||||||||||||||
2622 | } | - | ||||||||||||||||||||||||
2623 | - | |||||||||||||||||||||||||
2624 | - | |||||||||||||||||||||||||
2625 | - | |||||||||||||||||||||||||
2626 | /*! | - | ||||||||||||||||||||||||
2627 | Convenience slot that inserts \a text at the current | - | ||||||||||||||||||||||||
2628 | cursor position. | - | ||||||||||||||||||||||||
2629 | - | |||||||||||||||||||||||||
2630 | It is equivalent to | - | ||||||||||||||||||||||||
2631 | - | |||||||||||||||||||||||||
2632 | \snippet code/src_gui_widgets_qplaintextedit.cpp 1 | - | ||||||||||||||||||||||||
2633 | */ | - | ||||||||||||||||||||||||
2634 | void QPlainTextEdit::insertPlainText(const QString &text) | - | ||||||||||||||||||||||||
2635 | { | - | ||||||||||||||||||||||||
2636 | Q_D(QPlainTextEdit); | - | ||||||||||||||||||||||||
2637 | d->control->insertPlainText(text); | - | ||||||||||||||||||||||||
2638 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2639 | - | |||||||||||||||||||||||||
2640 | - | |||||||||||||||||||||||||
2641 | /*! | - | ||||||||||||||||||||||||
2642 | Moves the cursor by performing the given \a operation. | - | ||||||||||||||||||||||||
2643 | - | |||||||||||||||||||||||||
2644 | If \a mode is QTextCursor::KeepAnchor, the cursor selects the text it moves over. | - | ||||||||||||||||||||||||
2645 | This is the same effect that the user achieves when they hold down the Shift key | - | ||||||||||||||||||||||||
2646 | and move the cursor with the cursor keys. | - | ||||||||||||||||||||||||
2647 | - | |||||||||||||||||||||||||
2648 | \sa QTextCursor::movePosition() | - | ||||||||||||||||||||||||
2649 | */ | - | ||||||||||||||||||||||||
2650 | void QPlainTextEdit::moveCursor(QTextCursor::MoveOperation operation, QTextCursor::MoveMode mode) | - | ||||||||||||||||||||||||
2651 | { | - | ||||||||||||||||||||||||
2652 | Q_D(QPlainTextEdit); | - | ||||||||||||||||||||||||
2653 | d->control->moveCursor(operation, mode); | - | ||||||||||||||||||||||||
2654 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2655 | - | |||||||||||||||||||||||||
2656 | /*! | - | ||||||||||||||||||||||||
2657 | Returns whether text can be pasted from the clipboard into the textedit. | - | ||||||||||||||||||||||||
2658 | */ | - | ||||||||||||||||||||||||
2659 | bool QPlainTextEdit::canPaste() const | - | ||||||||||||||||||||||||
2660 | { | - | ||||||||||||||||||||||||
2661 | Q_D(const QPlainTextEdit); | - | ||||||||||||||||||||||||
2662 | return d->control->canPaste(); never executed: return d->control->canPaste(); | 0 | ||||||||||||||||||||||||
2663 | } | - | ||||||||||||||||||||||||
2664 | - | |||||||||||||||||||||||||
2665 | /*! | - | ||||||||||||||||||||||||
2666 | Convenience function to print the text edit's document to the given \a printer. This | - | ||||||||||||||||||||||||
2667 | is equivalent to calling the print method on the document directly except that this | - | ||||||||||||||||||||||||
2668 | function also supports QPrinter::Selection as print range. | - | ||||||||||||||||||||||||
2669 | - | |||||||||||||||||||||||||
2670 | \sa QTextDocument::print() | - | ||||||||||||||||||||||||
2671 | */ | - | ||||||||||||||||||||||||
2672 | #ifndef QT_NO_PRINTER | - | ||||||||||||||||||||||||
2673 | void QPlainTextEdit::print(QPagedPaintDevice *printer) const | - | ||||||||||||||||||||||||
2674 | { | - | ||||||||||||||||||||||||
2675 | Q_D(const QPlainTextEdit); | - | ||||||||||||||||||||||||
2676 | d->control->print(printer); | - | ||||||||||||||||||||||||
2677 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2678 | #endif | - | ||||||||||||||||||||||||
2679 | - | |||||||||||||||||||||||||
2680 | /*! \property QPlainTextEdit::tabChangesFocus | - | ||||||||||||||||||||||||
2681 | \brief whether \uicontrol Tab changes focus or is accepted as input | - | ||||||||||||||||||||||||
2682 | - | |||||||||||||||||||||||||
2683 | In some occasions text edits should not allow the user to input | - | ||||||||||||||||||||||||
2684 | tabulators or change indentation using the \uicontrol Tab key, as this breaks | - | ||||||||||||||||||||||||
2685 | the focus chain. The default is false. | - | ||||||||||||||||||||||||
2686 | - | |||||||||||||||||||||||||
2687 | */ | - | ||||||||||||||||||||||||
2688 | - | |||||||||||||||||||||||||
2689 | bool QPlainTextEdit::tabChangesFocus() const | - | ||||||||||||||||||||||||
2690 | { | - | ||||||||||||||||||||||||
2691 | Q_D(const QPlainTextEdit); | - | ||||||||||||||||||||||||
2692 | return d->tabChangesFocus; never executed: return d->tabChangesFocus; | 0 | ||||||||||||||||||||||||
2693 | } | - | ||||||||||||||||||||||||
2694 | - | |||||||||||||||||||||||||
2695 | void QPlainTextEdit::setTabChangesFocus(bool b) | - | ||||||||||||||||||||||||
2696 | { | - | ||||||||||||||||||||||||
2697 | Q_D(QPlainTextEdit); | - | ||||||||||||||||||||||||
2698 | d->tabChangesFocus = b; | - | ||||||||||||||||||||||||
2699 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2700 | - | |||||||||||||||||||||||||
2701 | /*! | - | ||||||||||||||||||||||||
2702 | \property QPlainTextEdit::documentTitle | - | ||||||||||||||||||||||||
2703 | \brief the title of the document parsed from the text. | - | ||||||||||||||||||||||||
2704 | - | |||||||||||||||||||||||||
2705 | By default, this property contains an empty string. | - | ||||||||||||||||||||||||
2706 | */ | - | ||||||||||||||||||||||||
2707 | - | |||||||||||||||||||||||||
2708 | /*! | - | ||||||||||||||||||||||||
2709 | \property QPlainTextEdit::lineWrapMode | - | ||||||||||||||||||||||||
2710 | \brief the line wrap mode | - | ||||||||||||||||||||||||
2711 | - | |||||||||||||||||||||||||
2712 | The default mode is WidgetWidth which causes words to be | - | ||||||||||||||||||||||||
2713 | wrapped at the right edge of the text edit. Wrapping occurs at | - | ||||||||||||||||||||||||
2714 | whitespace, keeping whole words intact. If you want wrapping to | - | ||||||||||||||||||||||||
2715 | occur within words use setWordWrapMode(). | - | ||||||||||||||||||||||||
2716 | */ | - | ||||||||||||||||||||||||
2717 | - | |||||||||||||||||||||||||
2718 | QPlainTextEdit::LineWrapMode QPlainTextEdit::lineWrapMode() const | - | ||||||||||||||||||||||||
2719 | { | - | ||||||||||||||||||||||||
2720 | Q_D(const QPlainTextEdit); | - | ||||||||||||||||||||||||
2721 | return d->lineWrap; never executed: return d->lineWrap; | 0 | ||||||||||||||||||||||||
2722 | } | - | ||||||||||||||||||||||||
2723 | - | |||||||||||||||||||||||||
2724 | void QPlainTextEdit::setLineWrapMode(LineWrapMode wrap) | - | ||||||||||||||||||||||||
2725 | { | - | ||||||||||||||||||||||||
2726 | Q_D(QPlainTextEdit); | - | ||||||||||||||||||||||||
2727 | if (d->lineWrap == wrap)
| 0 | ||||||||||||||||||||||||
2728 | return; never executed: return; | 0 | ||||||||||||||||||||||||
2729 | d->lineWrap = wrap; | - | ||||||||||||||||||||||||
2730 | d->updateDefaultTextOption(); | - | ||||||||||||||||||||||||
2731 | d->relayoutDocument(); | - | ||||||||||||||||||||||||
2732 | d->_q_adjustScrollbars(); | - | ||||||||||||||||||||||||
2733 | ensureCursorVisible(); | - | ||||||||||||||||||||||||
2734 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2735 | - | |||||||||||||||||||||||||
2736 | /*! | - | ||||||||||||||||||||||||
2737 | \property QPlainTextEdit::wordWrapMode | - | ||||||||||||||||||||||||
2738 | \brief the mode QPlainTextEdit will use when wrapping text by words | - | ||||||||||||||||||||||||
2739 | - | |||||||||||||||||||||||||
2740 | By default, this property is set to QTextOption::WrapAtWordBoundaryOrAnywhere. | - | ||||||||||||||||||||||||
2741 | - | |||||||||||||||||||||||||
2742 | \sa QTextOption::WrapMode | - | ||||||||||||||||||||||||
2743 | */ | - | ||||||||||||||||||||||||
2744 | - | |||||||||||||||||||||||||
2745 | QTextOption::WrapMode QPlainTextEdit::wordWrapMode() const | - | ||||||||||||||||||||||||
2746 | { | - | ||||||||||||||||||||||||
2747 | Q_D(const QPlainTextEdit); | - | ||||||||||||||||||||||||
2748 | return d->wordWrap; never executed: return d->wordWrap; | 0 | ||||||||||||||||||||||||
2749 | } | - | ||||||||||||||||||||||||
2750 | - | |||||||||||||||||||||||||
2751 | void QPlainTextEdit::setWordWrapMode(QTextOption::WrapMode mode) | - | ||||||||||||||||||||||||
2752 | { | - | ||||||||||||||||||||||||
2753 | Q_D(QPlainTextEdit); | - | ||||||||||||||||||||||||
2754 | if (mode == d->wordWrap)
| 0 | ||||||||||||||||||||||||
2755 | return; never executed: return; | 0 | ||||||||||||||||||||||||
2756 | d->wordWrap = mode; | - | ||||||||||||||||||||||||
2757 | d->updateDefaultTextOption(); | - | ||||||||||||||||||||||||
2758 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2759 | - | |||||||||||||||||||||||||
2760 | /*! | - | ||||||||||||||||||||||||
2761 | \property QPlainTextEdit::backgroundVisible | - | ||||||||||||||||||||||||
2762 | \brief whether the palette background is visible outside the document area | - | ||||||||||||||||||||||||
2763 | - | |||||||||||||||||||||||||
2764 | If set to true, the plain text edit paints the palette background | - | ||||||||||||||||||||||||
2765 | on the viewport area not covered by the text document. Otherwise, | - | ||||||||||||||||||||||||
2766 | if set to false, it won't. The feature makes it possible for | - | ||||||||||||||||||||||||
2767 | the user to visually distinguish between the area of the document, | - | ||||||||||||||||||||||||
2768 | painted with the base color of the palette, and the empty | - | ||||||||||||||||||||||||
2769 | area not covered by any document. | - | ||||||||||||||||||||||||
2770 | - | |||||||||||||||||||||||||
2771 | The default is false. | - | ||||||||||||||||||||||||
2772 | */ | - | ||||||||||||||||||||||||
2773 | - | |||||||||||||||||||||||||
2774 | bool QPlainTextEdit::backgroundVisible() const | - | ||||||||||||||||||||||||
2775 | { | - | ||||||||||||||||||||||||
2776 | Q_D(const QPlainTextEdit); | - | ||||||||||||||||||||||||
2777 | return d->backgroundVisible; never executed: return d->backgroundVisible; | 0 | ||||||||||||||||||||||||
2778 | } | - | ||||||||||||||||||||||||
2779 | - | |||||||||||||||||||||||||
2780 | void QPlainTextEdit::setBackgroundVisible(bool visible) | - | ||||||||||||||||||||||||
2781 | { | - | ||||||||||||||||||||||||
2782 | Q_D(QPlainTextEdit); | - | ||||||||||||||||||||||||
2783 | if (visible == d->backgroundVisible)
| 0 | ||||||||||||||||||||||||
2784 | return; never executed: return; | 0 | ||||||||||||||||||||||||
2785 | d->backgroundVisible = visible; | - | ||||||||||||||||||||||||
2786 | d->updateViewport(); | - | ||||||||||||||||||||||||
2787 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2788 | - | |||||||||||||||||||||||||
2789 | /*! | - | ||||||||||||||||||||||||
2790 | \property QPlainTextEdit::centerOnScroll | - | ||||||||||||||||||||||||
2791 | \brief whether the cursor should be centered on screen | - | ||||||||||||||||||||||||
2792 | - | |||||||||||||||||||||||||
2793 | If set to true, the plain text edit scrolls the document | - | ||||||||||||||||||||||||
2794 | vertically to make the cursor visible at the center of the | - | ||||||||||||||||||||||||
2795 | viewport. This also allows the text edit to scroll below the end | - | ||||||||||||||||||||||||
2796 | of the document. Otherwise, if set to false, the plain text edit | - | ||||||||||||||||||||||||
2797 | scrolls the smallest amount possible to ensure the cursor is | - | ||||||||||||||||||||||||
2798 | visible. The same algorithm is applied to any new line appended | - | ||||||||||||||||||||||||
2799 | through appendPlainText(). | - | ||||||||||||||||||||||||
2800 | - | |||||||||||||||||||||||||
2801 | The default is false. | - | ||||||||||||||||||||||||
2802 | - | |||||||||||||||||||||||||
2803 | \sa centerCursor(), ensureCursorVisible() | - | ||||||||||||||||||||||||
2804 | */ | - | ||||||||||||||||||||||||
2805 | - | |||||||||||||||||||||||||
2806 | bool QPlainTextEdit::centerOnScroll() const | - | ||||||||||||||||||||||||
2807 | { | - | ||||||||||||||||||||||||
2808 | Q_D(const QPlainTextEdit); | - | ||||||||||||||||||||||||
2809 | return d->centerOnScroll; never executed: return d->centerOnScroll; | 0 | ||||||||||||||||||||||||
2810 | } | - | ||||||||||||||||||||||||
2811 | - | |||||||||||||||||||||||||
2812 | void QPlainTextEdit::setCenterOnScroll(bool enabled) | - | ||||||||||||||||||||||||
2813 | { | - | ||||||||||||||||||||||||
2814 | Q_D(QPlainTextEdit); | - | ||||||||||||||||||||||||
2815 | if (enabled == d->centerOnScroll)
| 0 | ||||||||||||||||||||||||
2816 | return; never executed: return; | 0 | ||||||||||||||||||||||||
2817 | d->centerOnScroll = enabled; | - | ||||||||||||||||||||||||
2818 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2819 | - | |||||||||||||||||||||||||
2820 | - | |||||||||||||||||||||||||
2821 | - | |||||||||||||||||||||||||
2822 | /*! | - | ||||||||||||||||||||||||
2823 | Finds the next occurrence of the string, \a exp, using the given | - | ||||||||||||||||||||||||
2824 | \a options. Returns \c true if \a exp was found and changes the | - | ||||||||||||||||||||||||
2825 | cursor to select the match; otherwise returns \c false. | - | ||||||||||||||||||||||||
2826 | */ | - | ||||||||||||||||||||||||
2827 | bool QPlainTextEdit::find(const QString &exp, QTextDocument::FindFlags options) | - | ||||||||||||||||||||||||
2828 | { | - | ||||||||||||||||||||||||
2829 | Q_D(QPlainTextEdit); | - | ||||||||||||||||||||||||
2830 | return d->control->find(exp, options); never executed: return d->control->find(exp, options); | 0 | ||||||||||||||||||||||||
2831 | } | - | ||||||||||||||||||||||||
2832 | - | |||||||||||||||||||||||||
2833 | /*! | - | ||||||||||||||||||||||||
2834 | \fn bool QPlainTextEdit::find(const QRegExp &exp, QTextDocument::FindFlags options) | - | ||||||||||||||||||||||||
2835 | - | |||||||||||||||||||||||||
2836 | \since 5.3 | - | ||||||||||||||||||||||||
2837 | \overload | - | ||||||||||||||||||||||||
2838 | - | |||||||||||||||||||||||||
2839 | Finds the next occurrence, matching the regular expression, \a exp, using the given | - | ||||||||||||||||||||||||
2840 | \a options. The QTextDocument::FindCaseSensitively option is ignored for this overload, | - | ||||||||||||||||||||||||
2841 | use QRegExp::caseSensitivity instead. | - | ||||||||||||||||||||||||
2842 | - | |||||||||||||||||||||||||
2843 | Returns \c true if a match was found and changes the cursor to select the match; | - | ||||||||||||||||||||||||
2844 | otherwise returns \c false. | - | ||||||||||||||||||||||||
2845 | */ | - | ||||||||||||||||||||||||
2846 | #ifndef QT_NO_REGEXP | - | ||||||||||||||||||||||||
2847 | bool QPlainTextEdit::find(const QRegExp &exp, QTextDocument::FindFlags options) | - | ||||||||||||||||||||||||
2848 | { | - | ||||||||||||||||||||||||
2849 | Q_D(QPlainTextEdit); | - | ||||||||||||||||||||||||
2850 | return d->control->find(exp, options); never executed: return d->control->find(exp, options); | 0 | ||||||||||||||||||||||||
2851 | } | - | ||||||||||||||||||||||||
2852 | #endif | - | ||||||||||||||||||||||||
2853 | - | |||||||||||||||||||||||||
2854 | /*! | - | ||||||||||||||||||||||||
2855 | \fn void QPlainTextEdit::copyAvailable(bool yes) | - | ||||||||||||||||||||||||
2856 | - | |||||||||||||||||||||||||
2857 | This signal is emitted when text is selected or de-selected in the | - | ||||||||||||||||||||||||
2858 | text edit. | - | ||||||||||||||||||||||||
2859 | - | |||||||||||||||||||||||||
2860 | When text is selected this signal will be emitted with \a yes set | - | ||||||||||||||||||||||||
2861 | to true. If no text has been selected or if the selected text is | - | ||||||||||||||||||||||||
2862 | de-selected this signal is emitted with \a yes set to false. | - | ||||||||||||||||||||||||
2863 | - | |||||||||||||||||||||||||
2864 | If \a yes is true then copy() can be used to copy the selection to | - | ||||||||||||||||||||||||
2865 | the clipboard. If \a yes is false then copy() does nothing. | - | ||||||||||||||||||||||||
2866 | - | |||||||||||||||||||||||||
2867 | \sa selectionChanged() | - | ||||||||||||||||||||||||
2868 | */ | - | ||||||||||||||||||||||||
2869 | - | |||||||||||||||||||||||||
2870 | - | |||||||||||||||||||||||||
2871 | /*! | - | ||||||||||||||||||||||||
2872 | \fn void QPlainTextEdit::selectionChanged() | - | ||||||||||||||||||||||||
2873 | - | |||||||||||||||||||||||||
2874 | This signal is emitted whenever the selection changes. | - | ||||||||||||||||||||||||
2875 | - | |||||||||||||||||||||||||
2876 | \sa copyAvailable() | - | ||||||||||||||||||||||||
2877 | */ | - | ||||||||||||||||||||||||
2878 | - | |||||||||||||||||||||||||
2879 | /*! | - | ||||||||||||||||||||||||
2880 | \fn void QPlainTextEdit::cursorPositionChanged() | - | ||||||||||||||||||||||||
2881 | - | |||||||||||||||||||||||||
2882 | This signal is emitted whenever the position of the | - | ||||||||||||||||||||||||
2883 | cursor changed. | - | ||||||||||||||||||||||||
2884 | */ | - | ||||||||||||||||||||||||
2885 | - | |||||||||||||||||||||||||
2886 | - | |||||||||||||||||||||||||
2887 | - | |||||||||||||||||||||||||
2888 | /*! | - | ||||||||||||||||||||||||
2889 | \fn void QPlainTextEdit::updateRequest(const QRect &rect, int dy) | - | ||||||||||||||||||||||||
2890 | - | |||||||||||||||||||||||||
2891 | This signal is emitted when the text document needs an update of | - | ||||||||||||||||||||||||
2892 | the specified \a rect. If the text is scrolled, \a rect will cover | - | ||||||||||||||||||||||||
2893 | the entire viewport area. If the text is scrolled vertically, \a | - | ||||||||||||||||||||||||
2894 | dy carries the amount of pixels the viewport was scrolled. | - | ||||||||||||||||||||||||
2895 | - | |||||||||||||||||||||||||
2896 | The purpose of the signal is to support extra widgets in plain | - | ||||||||||||||||||||||||
2897 | text edit subclasses that e.g. show line numbers, breakpoints, or | - | ||||||||||||||||||||||||
2898 | other extra information. | - | ||||||||||||||||||||||||
2899 | */ | - | ||||||||||||||||||||||||
2900 | - | |||||||||||||||||||||||||
2901 | /*! \fn void QPlainTextEdit::blockCountChanged(int newBlockCount); | - | ||||||||||||||||||||||||
2902 | - | |||||||||||||||||||||||||
2903 | This signal is emitted whenever the block count changes. The new | - | ||||||||||||||||||||||||
2904 | block count is passed in \a newBlockCount. | - | ||||||||||||||||||||||||
2905 | */ | - | ||||||||||||||||||||||||
2906 | - | |||||||||||||||||||||||||
2907 | /*! \fn void QPlainTextEdit::modificationChanged(bool changed); | - | ||||||||||||||||||||||||
2908 | - | |||||||||||||||||||||||||
2909 | This signal is emitted whenever the content of the document | - | ||||||||||||||||||||||||
2910 | changes in a way that affects the modification state. If \a | - | ||||||||||||||||||||||||
2911 | changed is true, the document has been modified; otherwise it is | - | ||||||||||||||||||||||||
2912 | false. | - | ||||||||||||||||||||||||
2913 | - | |||||||||||||||||||||||||
2914 | For example, calling setModified(false) on a document and then | - | ||||||||||||||||||||||||
2915 | inserting text causes the signal to get emitted. If you undo that | - | ||||||||||||||||||||||||
2916 | operation, causing the document to return to its original | - | ||||||||||||||||||||||||
2917 | unmodified state, the signal will get emitted again. | - | ||||||||||||||||||||||||
2918 | */ | - | ||||||||||||||||||||||||
2919 | - | |||||||||||||||||||||||||
2920 | - | |||||||||||||||||||||||||
2921 | - | |||||||||||||||||||||||||
2922 | - | |||||||||||||||||||||||||
2923 | void QPlainTextEditPrivate::append(const QString &text, Qt::TextFormat format) | - | ||||||||||||||||||||||||
2924 | { | - | ||||||||||||||||||||||||
2925 | Q_Q(QPlainTextEdit); | - | ||||||||||||||||||||||||
2926 | - | |||||||||||||||||||||||||
2927 | QTextDocument *document = control->document(); | - | ||||||||||||||||||||||||
2928 | QPlainTextDocumentLayout *documentLayout = qobject_cast<QPlainTextDocumentLayout*>(document->documentLayout()); | - | ||||||||||||||||||||||||
2929 | Q_ASSERT(documentLayout); | - | ||||||||||||||||||||||||
2930 | - | |||||||||||||||||||||||||
2931 | int maximumBlockCount = document->maximumBlockCount(); | - | ||||||||||||||||||||||||
2932 | if (maximumBlockCount)
| 0 | ||||||||||||||||||||||||
2933 | document->setMaximumBlockCount(0); never executed: document->setMaximumBlockCount(0); | 0 | ||||||||||||||||||||||||
2934 | - | |||||||||||||||||||||||||
2935 | const bool atBottom = q->isVisible()
| 0 | ||||||||||||||||||||||||
2936 | && (control->blockBoundingRect(document->lastBlock()).bottom() - verticalOffset()
| 0 | ||||||||||||||||||||||||
2937 | <= viewport->rect().bottom());
| 0 | ||||||||||||||||||||||||
2938 | - | |||||||||||||||||||||||||
2939 | if (!q->isVisible())
| 0 | ||||||||||||||||||||||||
2940 | showCursorOnInitialShow = true; never executed: showCursorOnInitialShow = true; | 0 | ||||||||||||||||||||||||
2941 | - | |||||||||||||||||||||||||
2942 | bool documentSizeChangedBlocked = documentLayout->priv()->blockDocumentSizeChanged; | - | ||||||||||||||||||||||||
2943 | documentLayout->priv()->blockDocumentSizeChanged = true; | - | ||||||||||||||||||||||||
2944 | - | |||||||||||||||||||||||||
2945 | if (format == Qt::RichText)
| 0 | ||||||||||||||||||||||||
2946 | control->appendHtml(text); never executed: control->appendHtml(text); | 0 | ||||||||||||||||||||||||
2947 | else if (format == Qt::PlainText)
| 0 | ||||||||||||||||||||||||
2948 | control->appendPlainText(text); never executed: control->appendPlainText(text); | 0 | ||||||||||||||||||||||||
2949 | else | - | ||||||||||||||||||||||||
2950 | control->append(text); never executed: control->append(text); | 0 | ||||||||||||||||||||||||
2951 | - | |||||||||||||||||||||||||
2952 | if (maximumBlockCount > 0) {
| 0 | ||||||||||||||||||||||||
2953 | if (document->blockCount() > maximumBlockCount) {
| 0 | ||||||||||||||||||||||||
2954 | bool blockUpdate = false; | - | ||||||||||||||||||||||||
2955 | if (control->topBlock) {
| 0 | ||||||||||||||||||||||||
2956 | control->topBlock--; | - | ||||||||||||||||||||||||
2957 | blockUpdate = true; | - | ||||||||||||||||||||||||
2958 | emit q->updateRequest(viewport->rect(), 0); | - | ||||||||||||||||||||||||
2959 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2960 | - | |||||||||||||||||||||||||
2961 | bool updatesBlocked = documentLayout->priv()->blockUpdate; | - | ||||||||||||||||||||||||
2962 | documentLayout->priv()->blockUpdate = blockUpdate; | - | ||||||||||||||||||||||||
2963 | QTextCursor cursor(document); | - | ||||||||||||||||||||||||
2964 | cursor.movePosition(QTextCursor::NextBlock, QTextCursor::KeepAnchor); | - | ||||||||||||||||||||||||
2965 | cursor.removeSelectedText(); | - | ||||||||||||||||||||||||
2966 | documentLayout->priv()->blockUpdate = updatesBlocked; | - | ||||||||||||||||||||||||
2967 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2968 | document->setMaximumBlockCount(maximumBlockCount); | - | ||||||||||||||||||||||||
2969 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2970 | - | |||||||||||||||||||||||||
2971 | documentLayout->priv()->blockDocumentSizeChanged = documentSizeChangedBlocked; | - | ||||||||||||||||||||||||
2972 | _q_adjustScrollbars(); | - | ||||||||||||||||||||||||
2973 | - | |||||||||||||||||||||||||
2974 | - | |||||||||||||||||||||||||
2975 | if (atBottom) {
| 0 | ||||||||||||||||||||||||
2976 | const bool needScroll = !centerOnScroll
| 0 | ||||||||||||||||||||||||
2977 | || control->blockBoundingRect(document->lastBlock()).bottom() - verticalOffset()
| 0 | ||||||||||||||||||||||||
2978 | > viewport->rect().bottom();
| 0 | ||||||||||||||||||||||||
2979 | if (needScroll)
| 0 | ||||||||||||||||||||||||
2980 | vbar->setValue(vbar->maximum()); never executed: vbar->setValue(vbar->maximum()); | 0 | ||||||||||||||||||||||||
2981 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2982 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2983 | - | |||||||||||||||||||||||||
2984 | - | |||||||||||||||||||||||||
2985 | /*! | - | ||||||||||||||||||||||||
2986 | Appends a new paragraph with \a text to the end of the text edit. | - | ||||||||||||||||||||||||
2987 | - | |||||||||||||||||||||||||
2988 | \sa appendHtml() | - | ||||||||||||||||||||||||
2989 | */ | - | ||||||||||||||||||||||||
2990 | - | |||||||||||||||||||||||||
2991 | void QPlainTextEdit::appendPlainText(const QString &text) | - | ||||||||||||||||||||||||
2992 | { | - | ||||||||||||||||||||||||
2993 | Q_D(QPlainTextEdit); | - | ||||||||||||||||||||||||
2994 | d->append(text, Qt::PlainText); | - | ||||||||||||||||||||||||
2995 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2996 | - | |||||||||||||||||||||||||
2997 | /*! | - | ||||||||||||||||||||||||
2998 | Appends a new paragraph with \a html to the end of the text edit. | - | ||||||||||||||||||||||||
2999 | - | |||||||||||||||||||||||||
3000 | appendPlainText() | - | ||||||||||||||||||||||||
3001 | */ | - | ||||||||||||||||||||||||
3002 | - | |||||||||||||||||||||||||
3003 | void QPlainTextEdit::appendHtml(const QString &html) | - | ||||||||||||||||||||||||
3004 | { | - | ||||||||||||||||||||||||
3005 | Q_D(QPlainTextEdit); | - | ||||||||||||||||||||||||
3006 | d->append(html, Qt::RichText); | - | ||||||||||||||||||||||||
3007 | } never executed: end of block | 0 | ||||||||||||||||||||||||
3008 | - | |||||||||||||||||||||||||
3009 | void QPlainTextEditPrivate::ensureCursorVisible(bool center) | - | ||||||||||||||||||||||||
3010 | { | - | ||||||||||||||||||||||||
3011 | Q_Q(QPlainTextEdit); | - | ||||||||||||||||||||||||
3012 | QRect visible = viewport->rect(); | - | ||||||||||||||||||||||||
3013 | QRect cr = q->cursorRect(); | - | ||||||||||||||||||||||||
3014 | if (cr.top() < visible.top() || cr.bottom() > visible.bottom()) {
| 0 | ||||||||||||||||||||||||
3015 | ensureVisible(control->textCursor().position(), center); | - | ||||||||||||||||||||||||
3016 | } never executed: end of block | 0 | ||||||||||||||||||||||||
3017 | - | |||||||||||||||||||||||||
3018 | const bool rtl = q->isRightToLeft(); | - | ||||||||||||||||||||||||
3019 | if (cr.left() < visible.left() || cr.right() > visible.right()) {
| 0 | ||||||||||||||||||||||||
3020 | int x = cr.center().x() + horizontalOffset() - visible.width()/2; | - | ||||||||||||||||||||||||
3021 | hbar->setValue(rtl ? hbar->maximum() - x : x); | - | ||||||||||||||||||||||||
3022 | } never executed: end of block | 0 | ||||||||||||||||||||||||
3023 | } never executed: end of block | 0 | ||||||||||||||||||||||||
3024 | - | |||||||||||||||||||||||||
3025 | /*! | - | ||||||||||||||||||||||||
3026 | Ensures that the cursor is visible by scrolling the text edit if | - | ||||||||||||||||||||||||
3027 | necessary. | - | ||||||||||||||||||||||||
3028 | - | |||||||||||||||||||||||||
3029 | \sa centerCursor(), centerOnScroll | - | ||||||||||||||||||||||||
3030 | */ | - | ||||||||||||||||||||||||
3031 | void QPlainTextEdit::ensureCursorVisible() | - | ||||||||||||||||||||||||
3032 | { | - | ||||||||||||||||||||||||
3033 | Q_D(QPlainTextEdit); | - | ||||||||||||||||||||||||
3034 | d->ensureCursorVisible(d->centerOnScroll); | - | ||||||||||||||||||||||||
3035 | } never executed: end of block | 0 | ||||||||||||||||||||||||
3036 | - | |||||||||||||||||||||||||
3037 | - | |||||||||||||||||||||||||
3038 | /*! Scrolls the document in order to center the cursor vertically. | - | ||||||||||||||||||||||||
3039 | - | |||||||||||||||||||||||||
3040 | \sa ensureCursorVisible(), centerOnScroll | - | ||||||||||||||||||||||||
3041 | */ | - | ||||||||||||||||||||||||
3042 | void QPlainTextEdit::centerCursor() | - | ||||||||||||||||||||||||
3043 | { | - | ||||||||||||||||||||||||
3044 | Q_D(QPlainTextEdit); | - | ||||||||||||||||||||||||
3045 | d->ensureVisible(textCursor().position(), true, true); | - | ||||||||||||||||||||||||
3046 | } never executed: end of block | 0 | ||||||||||||||||||||||||
3047 | - | |||||||||||||||||||||||||
3048 | /*! | - | ||||||||||||||||||||||||
3049 | Returns the first visible block. | - | ||||||||||||||||||||||||
3050 | - | |||||||||||||||||||||||||
3051 | \sa blockBoundingRect() | - | ||||||||||||||||||||||||
3052 | */ | - | ||||||||||||||||||||||||
3053 | QTextBlock QPlainTextEdit::firstVisibleBlock() const | - | ||||||||||||||||||||||||
3054 | { | - | ||||||||||||||||||||||||
3055 | Q_D(const QPlainTextEdit); | - | ||||||||||||||||||||||||
3056 | return d->control->firstVisibleBlock(); never executed: return d->control->firstVisibleBlock(); | 0 | ||||||||||||||||||||||||
3057 | } | - | ||||||||||||||||||||||||
3058 | - | |||||||||||||||||||||||||
3059 | /*! Returns the content's origin in viewport coordinates. | - | ||||||||||||||||||||||||
3060 | - | |||||||||||||||||||||||||
3061 | The origin of the content of a plain text edit is always the top | - | ||||||||||||||||||||||||
3062 | left corner of the first visible text block. The content offset | - | ||||||||||||||||||||||||
3063 | is different from (0,0) when the text has been scrolled | - | ||||||||||||||||||||||||
3064 | horizontally, or when the first visible block has been scrolled | - | ||||||||||||||||||||||||
3065 | partially off the screen, i.e. the visible text does not start | - | ||||||||||||||||||||||||
3066 | with the first line of the first visible block, or when the first | - | ||||||||||||||||||||||||
3067 | visible block is the very first block and the editor displays a | - | ||||||||||||||||||||||||
3068 | margin. | - | ||||||||||||||||||||||||
3069 | - | |||||||||||||||||||||||||
3070 | \sa firstVisibleBlock(), horizontalScrollBar(), verticalScrollBar() | - | ||||||||||||||||||||||||
3071 | */ | - | ||||||||||||||||||||||||
3072 | QPointF QPlainTextEdit::contentOffset() const | - | ||||||||||||||||||||||||
3073 | { | - | ||||||||||||||||||||||||
3074 | Q_D(const QPlainTextEdit); | - | ||||||||||||||||||||||||
3075 | return QPointF(-d->horizontalOffset(), -d->verticalOffset()); never executed: return QPointF(-d->horizontalOffset(), -d->verticalOffset()); | 0 | ||||||||||||||||||||||||
3076 | } | - | ||||||||||||||||||||||||
3077 | - | |||||||||||||||||||||||||
3078 | - | |||||||||||||||||||||||||
3079 | /*! Returns the bounding rectangle of the text \a block in content | - | ||||||||||||||||||||||||
3080 | coordinates. Translate the rectangle with the contentOffset() to get | - | ||||||||||||||||||||||||
3081 | visual coordinates on the viewport. | - | ||||||||||||||||||||||||
3082 | - | |||||||||||||||||||||||||
3083 | \sa firstVisibleBlock(), blockBoundingRect() | - | ||||||||||||||||||||||||
3084 | */ | - | ||||||||||||||||||||||||
3085 | QRectF QPlainTextEdit::blockBoundingGeometry(const QTextBlock &block) const | - | ||||||||||||||||||||||||
3086 | { | - | ||||||||||||||||||||||||
3087 | Q_D(const QPlainTextEdit); | - | ||||||||||||||||||||||||
3088 | return d->control->blockBoundingRect(block); never executed: return d->control->blockBoundingRect(block); | 0 | ||||||||||||||||||||||||
3089 | } | - | ||||||||||||||||||||||||
3090 | - | |||||||||||||||||||||||||
3091 | /*! | - | ||||||||||||||||||||||||
3092 | Returns the bounding rectangle of the text \a block in the block's own coordinates. | - | ||||||||||||||||||||||||
3093 | - | |||||||||||||||||||||||||
3094 | \sa blockBoundingGeometry() | - | ||||||||||||||||||||||||
3095 | */ | - | ||||||||||||||||||||||||
3096 | QRectF QPlainTextEdit::blockBoundingRect(const QTextBlock &block) const | - | ||||||||||||||||||||||||
3097 | { | - | ||||||||||||||||||||||||
3098 | QPlainTextDocumentLayout *documentLayout = qobject_cast<QPlainTextDocumentLayout*>(document()->documentLayout()); | - | ||||||||||||||||||||||||
3099 | Q_ASSERT(documentLayout); | - | ||||||||||||||||||||||||
3100 | return documentLayout->blockBoundingRect(block); never executed: return documentLayout->blockBoundingRect(block); | 0 | ||||||||||||||||||||||||
3101 | } | - | ||||||||||||||||||||||||
3102 | - | |||||||||||||||||||||||||
3103 | /*! | - | ||||||||||||||||||||||||
3104 | \property QPlainTextEdit::blockCount | - | ||||||||||||||||||||||||
3105 | \brief the number of text blocks in the document. | - | ||||||||||||||||||||||||
3106 | - | |||||||||||||||||||||||||
3107 | By default, in an empty document, this property contains a value of 1. | - | ||||||||||||||||||||||||
3108 | */ | - | ||||||||||||||||||||||||
3109 | int QPlainTextEdit::blockCount() const | - | ||||||||||||||||||||||||
3110 | { | - | ||||||||||||||||||||||||
3111 | return document()->blockCount(); never executed: return document()->blockCount(); | 0 | ||||||||||||||||||||||||
3112 | } | - | ||||||||||||||||||||||||
3113 | - | |||||||||||||||||||||||||
3114 | /*! Returns the paint context for the viewport(), useful only when | - | ||||||||||||||||||||||||
3115 | reimplementing paintEvent(). | - | ||||||||||||||||||||||||
3116 | */ | - | ||||||||||||||||||||||||
3117 | QAbstractTextDocumentLayout::PaintContext QPlainTextEdit::getPaintContext() const | - | ||||||||||||||||||||||||
3118 | { | - | ||||||||||||||||||||||||
3119 | Q_D(const QPlainTextEdit); | - | ||||||||||||||||||||||||
3120 | return d->control->getPaintContext(d->viewport); never executed: return d->control->getPaintContext(d->viewport); | 0 | ||||||||||||||||||||||||
3121 | } | - | ||||||||||||||||||||||||
3122 | - | |||||||||||||||||||||||||
3123 | /*! | - | ||||||||||||||||||||||||
3124 | \property QPlainTextEdit::maximumBlockCount | - | ||||||||||||||||||||||||
3125 | \brief the limit for blocks in the document. | - | ||||||||||||||||||||||||
3126 | - | |||||||||||||||||||||||||
3127 | Specifies the maximum number of blocks the document may have. If there are | - | ||||||||||||||||||||||||
3128 | more blocks in the document that specified with this property blocks are removed | - | ||||||||||||||||||||||||
3129 | from the beginning of the document. | - | ||||||||||||||||||||||||
3130 | - | |||||||||||||||||||||||||
3131 | A negative or zero value specifies that the document may contain an unlimited | - | ||||||||||||||||||||||||
3132 | amount of blocks. | - | ||||||||||||||||||||||||
3133 | - | |||||||||||||||||||||||||
3134 | The default value is 0. | - | ||||||||||||||||||||||||
3135 | - | |||||||||||||||||||||||||
3136 | Note that setting this property will apply the limit immediately to the document | - | ||||||||||||||||||||||||
3137 | contents. Setting this property also disables the undo redo history. | - | ||||||||||||||||||||||||
3138 | - | |||||||||||||||||||||||||
3139 | */ | - | ||||||||||||||||||||||||
3140 | - | |||||||||||||||||||||||||
3141 | - | |||||||||||||||||||||||||
3142 | /*! | - | ||||||||||||||||||||||||
3143 | \fn void QPlainTextEdit::textChanged() | - | ||||||||||||||||||||||||
3144 | - | |||||||||||||||||||||||||
3145 | This signal is emitted whenever the document's content changes; for | - | ||||||||||||||||||||||||
3146 | example, when text is inserted or deleted, or when formatting is applied. | - | ||||||||||||||||||||||||
3147 | */ | - | ||||||||||||||||||||||||
3148 | - | |||||||||||||||||||||||||
3149 | /*! | - | ||||||||||||||||||||||||
3150 | \fn void QPlainTextEdit::undoAvailable(bool available) | - | ||||||||||||||||||||||||
3151 | - | |||||||||||||||||||||||||
3152 | This signal is emitted whenever undo operations become available | - | ||||||||||||||||||||||||
3153 | (\a available is true) or unavailable (\a available is false). | - | ||||||||||||||||||||||||
3154 | */ | - | ||||||||||||||||||||||||
3155 | - | |||||||||||||||||||||||||
3156 | /*! | - | ||||||||||||||||||||||||
3157 | \fn void QPlainTextEdit::redoAvailable(bool available) | - | ||||||||||||||||||||||||
3158 | - | |||||||||||||||||||||||||
3159 | This signal is emitted whenever redo operations become available | - | ||||||||||||||||||||||||
3160 | (\a available is true) or unavailable (\a available is false). | - | ||||||||||||||||||||||||
3161 | */ | - | ||||||||||||||||||||||||
3162 | - | |||||||||||||||||||||||||
3163 | QT_END_NAMESPACE | - | ||||||||||||||||||||||||
3164 | - | |||||||||||||||||||||||||
3165 | #include "moc_qplaintextedit.cpp" | - | ||||||||||||||||||||||||
3166 | #include "moc_qplaintextedit_p.cpp" | - | ||||||||||||||||||||||||
3167 | - | |||||||||||||||||||||||||
3168 | #endif // QT_NO_TEXTEDIT | - | ||||||||||||||||||||||||
Source code | Switch to Preprocessed file |