qplaintextedit.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/widgets/widgets/qplaintextedit.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2016 The Qt Company Ltd.-
4** Contact: https://www.qt.io/licensing/-
5**-
6** This file is part of the QtWidgets module of the Qt Toolkit.-
7**-
8** $QT_BEGIN_LICENSE:LGPL$-
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 https://www.qt.io/terms-conditions. For further-
15** information use the contact form at https://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 3 as published by the Free Software-
20** Foundation and appearing in the file LICENSE.LGPL3 included in the-
21** packaging of this file. Please review the following information to-
22** ensure the GNU Lesser General Public License version 3 requirements-
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.-
24**-
25** GNU General Public License Usage-
26** Alternatively, this file may be used under the terms of the GNU-
27** General Public License version 2.0 or (at your option) the GNU General-
28** Public license version 3 or any later version approved by the KDE Free-
29** Qt Foundation. The licenses are as published by the Free Software-
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3-
31** included in the packaging of this file. Please review the following-
32** information to ensure the GNU General Public License requirements will-
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and-
34** https://www.gnu.org/licenses/gpl-3.0.html.-
35**-
36** $QT_END_LICENSE$-
37**-
38****************************************************************************/-
39-
40#include "qplaintextedit_p.h"-
41-
42-
43#include <qfont.h>-
44#include <qpainter.h>-
45#include <qevent.h>-
46#include <qdebug.h>-
47#include <qdrag.h>-
48#include <qclipboard.h>-
49#include <qmenu.h>-
50#include <qstyle.h>-
51#include <qtimer.h>-
52#include "private/qtextdocumentlayout_p.h"-
53#include "private/qabstracttextdocumentlayout_p.h"-
54#include "qtextdocument.h"-
55#include "private/qtextdocument_p.h"-
56#include "qtextlist.h"-
57#include "qaccessible.h"-
58-
59#include <qtextformat.h>-
60#include <qdatetime.h>-
61#include <qapplication.h>-
62#include <limits.h>-
63#include <qtexttable.h>-
64#include <qvariant.h>-
65-
66#ifndef QT_NO_TEXTEDIT-
67-
68QT_BEGIN_NAMESPACE-
69-
70static inline bool shouldEnableInputMethod(QPlainTextEdit *plaintextedit)-
71{-
72 return !plaintextedit->isReadOnly();
never executed: return !plaintextedit->isReadOnly();
0
73}-
74-
75class QPlainTextDocumentLayoutPrivate : public QAbstractTextDocumentLayoutPrivate-
76{-
77 Q_DECLARE_PUBLIC(QPlainTextDocumentLayout)-
78public:-
79 QPlainTextDocumentLayoutPrivate() {-
80 mainViewPrivate = 0;-
81 width = 0;-
82 maximumWidth = 0;-
83 maximumWidthBlockNumber = 0;-
84 blockCount = 1;-
85 blockUpdate = blockDocumentSizeChanged = false;-
86 cursorWidth = 1;-
87 textLayoutFlags = 0;-
88 }
never executed: end of block
0
89-
90 qreal width;-
91 qreal maximumWidth;-
92 int maximumWidthBlockNumber;-
93 int blockCount;-
94 QPlainTextEditPrivate *mainViewPrivate;-
95 bool blockUpdate;-
96 bool blockDocumentSizeChanged;-
97 int cursorWidth;-
98 int textLayoutFlags;-
99-
100 void layoutBlock(const QTextBlock &block);-
101 qreal blockWidth(const QTextBlock &block);-
102-
103 void relayout();-
104};-
105-
106-
107-
108/*! \class QPlainTextDocumentLayout-
109 \since 4.4-
110 \brief The QPlainTextDocumentLayout class implements a plain text layout for QTextDocument-
111-
112 \ingroup richtext-processing-
113 \inmodule QtWidgets-
114-
115 A QPlainTextDocumentLayout is required for text documents that can-
116 be display or edited in a QPlainTextEdit. See-
117 QTextDocument::setDocumentLayout().-
118-
119 QPlainTextDocumentLayout uses the QAbstractTextDocumentLayout API-
120 that QTextDocument requires, but redefines it partially in order to-
121 support plain text better. For instances, it does not operate on-
122 vertical pixels, but on paragraphs (called blocks) instead. The-
123 height of a document is identical to the number of paragraphs it-
124 contains. The layout also doesn't support tables or nested frames,-
125 or any sort of advanced text layout that goes beyond a list of-
126 paragraphs with syntax highlighting.-
127-
128*/-
129-
130-
131-
132/*!-
133 Constructs a plain text document layout for the text \a document.-
134 */-
135QPlainTextDocumentLayout::QPlainTextDocumentLayout(QTextDocument *document)-
136 :QAbstractTextDocumentLayout(* new QPlainTextDocumentLayoutPrivate, document) {-
137}
never executed: end of block
0
138/*!-
139 Destructs a plain text document layout.-
140 */-
141QPlainTextDocumentLayout::~QPlainTextDocumentLayout() {}-
142-
143-
144/*!-
145 \reimp-
146 */-
147void QPlainTextDocumentLayout::draw(QPainter *, const PaintContext &)-
148{-
149}-
150-
151/*!-
152 \reimp-
153 */-
154int QPlainTextDocumentLayout::hitTest(const QPointF &, Qt::HitTestAccuracy ) const-
155{-
156// this function is used from-
157// QAbstractTextDocumentLayout::anchorAt(), but is not-
158// implementable in a plain text document layout, because the-
159// layout depends on the top block and top line which depends on-
160// the view-
161 return -1;
never executed: return -1;
0
162}-
163-
164/*!-
165 \reimp-
166 */-
167int QPlainTextDocumentLayout::pageCount() const-
168{
never executed: return 1;
return 1; }
never executed: return 1;
0
169-
170/*!-
171 \reimp-
172 */-
173QSizeF QPlainTextDocumentLayout::documentSize() const-
174{-
175 Q_D(const QPlainTextDocumentLayout);-
176 return QSizeF(d->maximumWidth, document()->lineCount());
never executed: return QSizeF(d->maximumWidth, document()->lineCount());
0
177}-
178-
179/*!-
180 \reimp-
181 */-
182QRectF QPlainTextDocumentLayout::frameBoundingRect(QTextFrame *) const-
183{-
184 Q_D(const QPlainTextDocumentLayout);-
185 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
186}-
187-
188/*!-
189 \reimp-
190 */-
191QRectF QPlainTextDocumentLayout::blockBoundingRect(const QTextBlock &block) const-
192{-
193 if (!block.isValid()) { return QRectF(); }
never executed: return QRectF();
!block.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
194 QTextLayout *tl = block.layout();-
195 if (!tl->lineCount())
!tl->lineCount()Description
TRUEnever evaluated
FALSEnever evaluated
0
196 const_cast<QPlainTextDocumentLayout*>(this)->layoutBlock(block);
never executed: const_cast<QPlainTextDocumentLayout*>(this)->layoutBlock(block);
0
197 QRectF br;-
198 if (block.isVisible()) {
block.isVisible()Description
TRUEnever evaluated
FALSEnever evaluated
0
199 br = QRectF(QPointF(0, 0), tl->boundingRect().bottomRight());-
200 if (tl->lineCount() == 1)
tl->lineCount() == 1Description
TRUEnever evaluated
FALSEnever evaluated
0
201 br.setWidth(qMax(br.width(), tl->lineAt(0).naturalTextWidth()));
never executed: br.setWidth(qMax(br.width(), tl->lineAt(0).naturalTextWidth()));
0
202 qreal margin = document()->documentMargin();-
203 br.adjust(0, 0, margin, 0);-
204 if (!block.next().isValid())
!block.next().isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
205 br.adjust(0, 0, 0, margin);
never executed: br.adjust(0, 0, 0, margin);
0
206 }
never executed: end of block
0
207 return br;
never executed: return br;
0
208-
209}-
210-
211/*!-
212 Ensures that \a block has a valid layout-
213 */-
214void QPlainTextDocumentLayout::ensureBlockLayout(const QTextBlock &block) const-
215{-
216 if (!block.isValid())
!block.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
217 return;
never executed: return;
0
218 QTextLayout *tl = block.layout();-
219 if (!tl->lineCount())
!tl->lineCount()Description
TRUEnever evaluated
FALSEnever evaluated
0
220 const_cast<QPlainTextDocumentLayout*>(this)->layoutBlock(block);
never executed: const_cast<QPlainTextDocumentLayout*>(this)->layoutBlock(block);
0
221}
never executed: end of block
0
222-
223-
224/*! \property QPlainTextDocumentLayout::cursorWidth-
225-
226 This property specifies the width of the cursor in pixels. The default value is 1.-
227*/-
228void QPlainTextDocumentLayout::setCursorWidth(int width)-
229{-
230 Q_D(QPlainTextDocumentLayout);-
231 d->cursorWidth = width;-
232}
never executed: end of block
0
233-
234int QPlainTextDocumentLayout::cursorWidth() const-
235{-
236 Q_D(const QPlainTextDocumentLayout);-
237 return d->cursorWidth;
never executed: return d->cursorWidth;
0
238}-
239-
240QPlainTextDocumentLayoutPrivate *QPlainTextDocumentLayout::priv() const-
241{-
242 Q_D(const QPlainTextDocumentLayout);-
243 return const_cast<QPlainTextDocumentLayoutPrivate*>(d);
never executed: return const_cast<QPlainTextDocumentLayoutPrivate*>(d);
0
244}-
245-
246-
247/*!-
248-
249 Requests a complete update on all views.-
250 */-
251void QPlainTextDocumentLayout::requestUpdate()-
252{-
253 emit update(QRectF(0., -document()->documentMargin(), 1000000000., 1000000000.));-
254}
never executed: end of block
0
255-
256-
257void QPlainTextDocumentLayout::setTextWidth(qreal newWidth)-
258{-
259 Q_D(QPlainTextDocumentLayout);-
260 d->width = d->maximumWidth = newWidth;-
261 d->relayout();-
262}
never executed: end of block
0
263-
264qreal QPlainTextDocumentLayout::textWidth() const-
265{-
266 Q_D(const QPlainTextDocumentLayout);-
267 return d->width;
never executed: return d->width;
0
268}-
269-
270void QPlainTextDocumentLayoutPrivate::relayout()-
271{-
272 Q_Q(QPlainTextDocumentLayout);-
273 QTextBlock block = q->document()->firstBlock();-
274 while (block.isValid()) {
block.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
275 block.layout()->clearLayout();-
276 block.setLineCount(block.isVisible() ? 1 : 0);-
277 block = block.next();-
278 }
never executed: end of block
0
279 emit q->update();-
280}
never executed: end of block
0
281-
282-
283/*! \reimp-
284 */-
285void QPlainTextDocumentLayout::documentChanged(int from, int charsRemoved, int charsAdded)-
286{-
287 Q_D(QPlainTextDocumentLayout);-
288 QTextDocument *doc = document();-
289 int newBlockCount = doc->blockCount();-
290 int charsChanged = charsRemoved + charsAdded;-
291-
292 QTextBlock changeStartBlock = doc->findBlock(from);-
293 QTextBlock changeEndBlock = doc->findBlock(qMax(0, from + charsChanged - 1));-
294-
295 if (changeStartBlock == changeEndBlock && newBlockCount == d->blockCount) {
changeStartBlo...changeEndBlockDescription
TRUEnever evaluated
FALSEnever evaluated
newBlockCount == d->blockCountDescription
TRUEnever evaluated
FALSEnever evaluated
0
296 QTextBlock block = changeStartBlock;-
297 if (block.isValid() && block.length()) {
block.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
block.length()Description
TRUEnever evaluated
FALSEnever evaluated
0
298 QRectF oldBr = blockBoundingRect(block);-
299 layoutBlock(block);-
300 QRectF newBr = blockBoundingRect(block);-
301 if (newBr.height() == oldBr.height()) {
newBr.height()...oldBr.height()Description
TRUEnever evaluated
FALSEnever evaluated
0
302 if (!d->blockUpdate)
!d->blockUpdateDescription
TRUEnever evaluated
FALSEnever evaluated
0
303 emit updateBlock(block);
never executed: updateBlock(block);
0
304 return;
never executed: return;
0
305 }-
306 }
never executed: end of block
0
307 } else {
never executed: end of block
0
308 QTextBlock block = changeStartBlock;-
309 do {-
310 block.clearLayout();-
311 if (block == changeEndBlock)
block == changeEndBlockDescription
TRUEnever evaluated
FALSEnever evaluated
0
312 break;
never executed: break;
0
313 block = block.next();-
314 } while(block.isValid());
never executed: end of block
block.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
315 }
never executed: end of block
0
316-
317 if (newBlockCount != d->blockCount) {
newBlockCount != d->blockCountDescription
TRUEnever evaluated
FALSEnever evaluated
0
318-
319 int changeEnd = changeEndBlock.blockNumber();-
320 int blockDiff = newBlockCount - d->blockCount;-
321 int oldChangeEnd = changeEnd - blockDiff;-
322-
323 if (d->maximumWidthBlockNumber > oldChangeEnd)
d->maximumWidt...> oldChangeEndDescription
TRUEnever evaluated
FALSEnever evaluated
0
324 d->maximumWidthBlockNumber += blockDiff;
never executed: d->maximumWidthBlockNumber += blockDiff;
0
325-
326 d->blockCount = newBlockCount;-
327 if (d->blockCount == 1)
d->blockCount == 1Description
TRUEnever evaluated
FALSEnever evaluated
0
328 d->maximumWidth = blockWidth(doc->firstBlock());
never executed: d->maximumWidth = blockWidth(doc->firstBlock());
0
329-
330 if (!d->blockDocumentSizeChanged)
!d->blockDocumentSizeChangedDescription
TRUEnever evaluated
FALSEnever evaluated
0
331 emit documentSizeChanged(documentSize());
never executed: documentSizeChanged(documentSize());
0
332-
333 if (blockDiff == 1 && changeEnd == newBlockCount -1 ) {
blockDiff == 1Description
TRUEnever evaluated
FALSEnever evaluated
changeEnd == newBlockCount -1Description
TRUEnever evaluated
FALSEnever evaluated
0
334 if (!d->blockUpdate) {
!d->blockUpdateDescription
TRUEnever evaluated
FALSEnever evaluated
0
335 QTextBlock b = changeStartBlock;-
336 for(;;) {-
337 emit updateBlock(b);-
338 if (b == changeEndBlock)
b == changeEndBlockDescription
TRUEnever evaluated
FALSEnever evaluated
0
339 break;
never executed: break;
0
340 b = b.next();-
341 }
never executed: end of block
0
342 }
never executed: end of block
0
343 return;
never executed: return;
0
344 }-
345 }
never executed: end of block
0
346-
347 if (!d->blockUpdate)
!d->blockUpdateDescription
TRUEnever evaluated
FALSEnever evaluated
0
348 emit update(QRectF(0., -doc->documentMargin(), 1000000000., 1000000000.)); // optimization potential
never executed: update(QRectF(0., -doc->documentMargin(), 1000000000., 1000000000.));
0
349}
never executed: end of block
0
350-
351-
352void QPlainTextDocumentLayout::layoutBlock(const QTextBlock &block)-
353{-
354 Q_D(QPlainTextDocumentLayout);-
355 QTextDocument *doc = document();-
356 qreal margin = doc->documentMargin();-
357 qreal blockMaximumWidth = 0;-
358-
359 qreal height = 0;-
360 QTextLayout *tl = block.layout();-
361 QTextOption option = doc->defaultTextOption();-
362 tl->setTextOption(option);-
363-
364 int extraMargin = 0;-
365 if (option.flags() & QTextOption::AddSpaceForLineAndParagraphSeparators) {
option.flags()...raphSeparatorsDescription
TRUEnever evaluated
FALSEnever evaluated
0
366 QFontMetrics fm(block.charFormat().font());-
367 extraMargin += fm.width(QChar(0x21B5));-
368 }
never executed: end of block
0
369 tl->beginLayout();-
370 qreal availableWidth = d->width;-
371 if (availableWidth <= 0) {
availableWidth <= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
372 availableWidth = qreal(INT_MAX); // similar to text edit with pageSize.width == 0-
373 }
never executed: end of block
0
374 availableWidth -= 2*margin + extraMargin;-
375 while (1) {-
376 QTextLine line = tl->createLine();-
377 if (!line.isValid())
!line.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
378 break;
never executed: break;
0
379 line.setLeadingIncluded(true);-
380 line.setLineWidth(availableWidth);-
381 line.setPosition(QPointF(margin, height));-
382 height += line.height();-
383 blockMaximumWidth = qMax(blockMaximumWidth, line.naturalTextWidth() + 2*margin);-
384 }
never executed: end of block
0
385 tl->endLayout();-
386-
387 int previousLineCount = doc->lineCount();-
388 const_cast<QTextBlock&>(block).setLineCount(block.isVisible() ? tl->lineCount() : 0);-
389 int lineCount = doc->lineCount();-
390-
391 bool emitDocumentSizeChanged = previousLineCount != lineCount;-
392 if (blockMaximumWidth > d->maximumWidth) {
blockMaximumWi...->maximumWidthDescription
TRUEnever evaluated
FALSEnever evaluated
0
393 // new longest line-
394 d->maximumWidth = blockMaximumWidth;-
395 d->maximumWidthBlockNumber = block.blockNumber();-
396 emitDocumentSizeChanged = true;-
397 } else if (block.blockNumber() == d->maximumWidthBlockNumber && blockMaximumWidth < d->maximumWidth) {
never executed: end of block
block.blockNum...dthBlockNumberDescription
TRUEnever evaluated
FALSEnever evaluated
blockMaximumWi...->maximumWidthDescription
TRUEnever evaluated
FALSEnever evaluated
0
398 // longest line shrinking-
399 QTextBlock b = doc->firstBlock();-
400 d->maximumWidth = 0;-
401 QTextBlock maximumBlock;-
402 while (b.isValid()) {
b.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
403 qreal blockMaximumWidth = blockWidth(b);-
404 if (blockMaximumWidth > d->maximumWidth) {
blockMaximumWi...->maximumWidthDescription
TRUEnever evaluated
FALSEnever evaluated
0
405 d->maximumWidth = blockMaximumWidth;-
406 maximumBlock = b;-
407 }
never executed: end of block
0
408 b = b.next();-
409 }
never executed: end of block
0
410 if (maximumBlock.isValid()) {
maximumBlock.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
411 d->maximumWidthBlockNumber = maximumBlock.blockNumber();-
412 emitDocumentSizeChanged = true;-
413 }
never executed: end of block
0
414 }
never executed: end of block
0
415 if (emitDocumentSizeChanged && !d->blockDocumentSizeChanged)
emitDocumentSizeChangedDescription
TRUEnever evaluated
FALSEnever evaluated
!d->blockDocumentSizeChangedDescription
TRUEnever evaluated
FALSEnever evaluated
0
416 emit documentSizeChanged(documentSize());
never executed: documentSizeChanged(documentSize());
0
417}
never executed: end of block
0
418-
419qreal QPlainTextDocumentLayout::blockWidth(const QTextBlock &block)-
420{-
421 QTextLayout *layout = block.layout();-
422 if (!layout->lineCount())
!layout->lineCount()Description
TRUEnever evaluated
FALSEnever evaluated
0
423 return 0; // only for layouted blocks
never executed: return 0;
0
424 qreal blockWidth = 0;-
425 for (int i = 0; i < layout->lineCount(); ++i) {
i < layout->lineCount()Description
TRUEnever evaluated
FALSEnever evaluated
0
426 QTextLine line = layout->lineAt(i);-
427 blockWidth = qMax(line.naturalTextWidth() + 8, blockWidth);-
428 }
never executed: end of block
0
429 return blockWidth;
never executed: return blockWidth;
0
430}-
431-
432-
433QPlainTextEditControl::QPlainTextEditControl(QPlainTextEdit *parent)-
434 : QWidgetTextControl(parent), textEdit(parent),-
435 topBlock(0)-
436{-
437 setAcceptRichText(false);-
438}
never executed: end of block
0
439-
440void QPlainTextEditPrivate::_q_cursorPositionChanged()-
441{-
442 pageUpDownLastCursorYIsValid = false;-
443 Q_Q(QPlainTextEdit);-
444#ifndef QT_NO_ACCESSIBILITY-
445 QAccessibleTextCursorEvent ev(q, q->textCursor().position());-
446 QAccessible::updateAccessibility(&ev);-
447#endif-
448 emit q->cursorPositionChanged();-
449}
never executed: end of block
0
450-
451void QPlainTextEditPrivate::_q_verticalScrollbarActionTriggered(int action) {-
452 if (action == QAbstractSlider::SliderPageStepAdd) {
action == QAbs...derPageStepAddDescription
TRUEnever evaluated
FALSEnever evaluated
0
453 pageUpDown(QTextCursor::Down, QTextCursor::MoveAnchor, false);-
454 } else if (action == QAbstractSlider::SliderPageStepSub) {
never executed: end of block
action == QAbs...derPageStepSubDescription
TRUEnever evaluated
FALSEnever evaluated
0
455 pageUpDown(QTextCursor::Up, QTextCursor::MoveAnchor, false);-
456 }
never executed: end of block
0
457}
never executed: end of block
0
458-
459QMimeData *QPlainTextEditControl::createMimeDataFromSelection() const {-
460 QPlainTextEdit *ed = qobject_cast<QPlainTextEdit *>(parent());-
461 if (!ed)
!edDescription
TRUEnever evaluated
FALSEnever evaluated
0
462 return QWidgetTextControl::createMimeDataFromSelection();
never executed: return QWidgetTextControl::createMimeDataFromSelection();
0
463 return ed->createMimeDataFromSelection();
never executed: return ed->createMimeDataFromSelection();
0
464 }-
465bool QPlainTextEditControl::canInsertFromMimeData(const QMimeData *source) const {-
466 QPlainTextEdit *ed = qobject_cast<QPlainTextEdit *>(parent());-
467 if (!ed)
!edDescription
TRUEnever evaluated
FALSEnever evaluated
0
468 return QWidgetTextControl::canInsertFromMimeData(source);
never executed: return QWidgetTextControl::canInsertFromMimeData(source);
0
469 return ed->canInsertFromMimeData(source);
never executed: return ed->canInsertFromMimeData(source);
0
470}-
471void QPlainTextEditControl::insertFromMimeData(const QMimeData *source) {-
472 QPlainTextEdit *ed = qobject_cast<QPlainTextEdit *>(parent());-
473 if (!ed)
!edDescription
TRUEnever evaluated
FALSEnever evaluated
0
474 QWidgetTextControl::insertFromMimeData(source);
never executed: QWidgetTextControl::insertFromMimeData(source);
0
475 else-
476 ed->insertFromMimeData(source);
never executed: ed->insertFromMimeData(source);
0
477}-
478-
479qreal QPlainTextEditPrivate::verticalOffset(int topBlock, int topLine) const-
480{-
481 qreal offset = 0;-
482 QTextDocument *doc = control->document();-
483-
484 if (topLine) {
topLineDescription
TRUEnever evaluated
FALSEnever evaluated
0
485 QTextBlock currentBlock = doc->findBlockByNumber(topBlock);-
486 QPlainTextDocumentLayout *documentLayout = qobject_cast<QPlainTextDocumentLayout*>(doc->documentLayout());-
487 Q_ASSERT(documentLayout);-
488 QRectF r = documentLayout->blockBoundingRect(currentBlock);-
489 Q_UNUSED(r);-
490 QTextLayout *layout = currentBlock.layout();-
491 if (layout && topLine <= layout->lineCount()) {
layoutDescription
TRUEnever evaluated
FALSEnever evaluated
topLine <= layout->lineCount()Description
TRUEnever evaluated
FALSEnever evaluated
0
492 QTextLine line = layout->lineAt(topLine - 1);-
493 const QRectF lr = line.naturalTextRect();-
494 offset = lr.bottom();-
495 }
never executed: end of block
0
496 }
never executed: end of block
0
497 if (topBlock == 0 && topLine == 0)
topBlock == 0Description
TRUEnever evaluated
FALSEnever evaluated
topLine == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
498 offset -= doc->documentMargin(); // top margin
never executed: offset -= doc->documentMargin();
0
499 return offset;
never executed: return offset;
0
500}-
501-
502-
503qreal QPlainTextEditPrivate::verticalOffset() const {-
504 return verticalOffset(control->topBlock, topLine) + topLineFracture;
never executed: return verticalOffset(control->topBlock, topLine) + topLineFracture;
0
505}-
506-
507-
508QTextBlock QPlainTextEditControl::firstVisibleBlock() const-
509{-
510 return document()->findBlockByNumber(topBlock);
never executed: return document()->findBlockByNumber(topBlock);
0
511}-
512-
513-
514-
515int QPlainTextEditControl::hitTest(const QPointF &point, Qt::HitTestAccuracy ) const {-
516 int currentBlockNumber = topBlock;-
517 QTextBlock currentBlock = document()->findBlockByNumber(currentBlockNumber);-
518 if (!currentBlock.isValid())
!currentBlock.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
519 return -1;
never executed: return -1;
0
520-
521 QPlainTextDocumentLayout *documentLayout = qobject_cast<QPlainTextDocumentLayout*>(document()->documentLayout());-
522 Q_ASSERT(documentLayout);-
523-
524 QPointF offset;-
525 QRectF r = documentLayout->blockBoundingRect(currentBlock);-
526 while (currentBlock.next().isValid() && r.bottom() + offset.y() <= point.y()) {
currentBlock.next().isValid()Description
TRUEnever evaluated
FALSEnever evaluated
r.bottom() + o...) <= point.y()Description
TRUEnever evaluated
FALSEnever evaluated
0
527 offset.ry() += r.height();-
528 currentBlock = currentBlock.next();-
529 ++currentBlockNumber;-
530 r = documentLayout->blockBoundingRect(currentBlock);-
531 }
never executed: end of block
0
532 while (currentBlock.previous().isValid() && r.top() + offset.y() > point.y()) {
currentBlock.p...us().isValid()Description
TRUEnever evaluated
FALSEnever evaluated
r.top() + offs...() > point.y()Description
TRUEnever evaluated
FALSEnever evaluated
0
533 offset.ry() -= r.height();-
534 currentBlock = currentBlock.previous();-
535 --currentBlockNumber;-
536 r = documentLayout->blockBoundingRect(currentBlock);-
537 }
never executed: end of block
0
538-
539-
540 if (!currentBlock.isValid())
!currentBlock.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
541 return -1;
never executed: return -1;
0
542 QTextLayout *layout = currentBlock.layout();-
543 int off = 0;-
544 QPointF pos = point - offset;-
545 for (int i = 0; i < layout->lineCount(); ++i) {
i < layout->lineCount()Description
TRUEnever evaluated
FALSEnever evaluated
0
546 QTextLine line = layout->lineAt(i);-
547 const QRectF lr = line.naturalTextRect();-
548 if (lr.top() > pos.y()) {
lr.top() > pos.y()Description
TRUEnever evaluated
FALSEnever evaluated
0
549 off = qMin(off, line.textStart());-
550 } else if (lr.bottom() <= pos.y()) {
never executed: end of block
lr.bottom() <= pos.y()Description
TRUEnever evaluated
FALSEnever evaluated
0
551 off = qMax(off, line.textStart() + line.textLength());-
552 } else {
never executed: end of block
0
553 off = line.xToCursor(pos.x(), overwriteMode() ?-
554 QTextLine::CursorOnCharacter : QTextLine::CursorBetweenCharacters);-
555 break;
never executed: break;
0
556 }-
557 }-
558-
559 return currentBlock.position() + off;
never executed: return currentBlock.position() + off;
0
560}-
561-
562QRectF QPlainTextEditControl::blockBoundingRect(const QTextBlock &block) const {-
563 int currentBlockNumber = topBlock;-
564 int blockNumber = block.blockNumber();-
565 QTextBlock currentBlock = document()->findBlockByNumber(currentBlockNumber);-
566 if (!currentBlock.isValid())
!currentBlock.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
567 return QRectF();
never executed: return QRectF();
0
568 Q_ASSERT(currentBlock.blockNumber() == currentBlockNumber);-
569 QTextDocument *doc = document();-
570 QPlainTextDocumentLayout *documentLayout = qobject_cast<QPlainTextDocumentLayout*>(doc->documentLayout());-
571 Q_ASSERT(documentLayout);-
572-
573 QPointF offset;-
574 if (!block.isValid())
!block.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
575 return QRectF();
never executed: return QRectF();
0
576 QRectF r = documentLayout->blockBoundingRect(currentBlock);-
577 int maxVerticalOffset = r.height();-
578 while (currentBlockNumber < blockNumber && offset.y() - maxVerticalOffset <= 2* textEdit->viewport()->height()) {
currentBlockNu... < blockNumberDescription
TRUEnever evaluated
FALSEnever evaluated
offset.y() - m...rt()->height()Description
TRUEnever evaluated
FALSEnever evaluated
0
579 offset.ry() += r.height();-
580 currentBlock = currentBlock.next();-
581 ++currentBlockNumber;-
582 if (!currentBlock.isVisible()) {
!currentBlock.isVisible()Description
TRUEnever evaluated
FALSEnever evaluated
0
583 currentBlock = doc->findBlockByLineNumber(currentBlock.firstLineNumber());-
584 currentBlockNumber = currentBlock.blockNumber();-
585 }
never executed: end of block
0
586 r = documentLayout->blockBoundingRect(currentBlock);-
587 }
never executed: end of block
0
588 while (currentBlockNumber > blockNumber && offset.y() + maxVerticalOffset >= -textEdit->viewport()->height()) {
currentBlockNu... > blockNumberDescription
TRUEnever evaluated
FALSEnever evaluated
offset.y() + m...rt()->height()Description
TRUEnever evaluated
FALSEnever evaluated
0
589 currentBlock = currentBlock.previous();-
590 --currentBlockNumber;-
591 while (!currentBlock.isVisible()) {
!currentBlock.isVisible()Description
TRUEnever evaluated
FALSEnever evaluated
0
592 currentBlock = currentBlock.previous();-
593 --currentBlockNumber;-
594 }
never executed: end of block
0
595 if (!currentBlock.isValid())
!currentBlock.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
596 break;
never executed: break;
0
597-
598 r = documentLayout->blockBoundingRect(currentBlock);-
599 offset.ry() -= r.height();-
600 }
never executed: end of block
0
601-
602 if (currentBlockNumber != blockNumber) {
currentBlockNu...!= blockNumberDescription
TRUEnever evaluated
FALSEnever evaluated
0
603 // fallback for blocks out of reach. Give it some geometry at-
604 // least, and ensure the layout is up to date.-
605 r = documentLayout->blockBoundingRect(block);-
606 if (currentBlockNumber > blockNumber)
currentBlockNu... > blockNumberDescription
TRUEnever evaluated
FALSEnever evaluated
0
607 offset.ry() -= r.height();
never executed: offset.ry() -= r.height();
0
608 }
never executed: end of block
0
609 r.translate(offset);-
610 return r;
never executed: return r;
0
611}-
612-
613QString QPlainTextEditControl::anchorAt(const QPointF &pos) const-
614{-
615 return textEdit->anchorAt(pos.toPoint());
never executed: return textEdit->anchorAt(pos.toPoint());
0
616}-
617-
618void QPlainTextEditPrivate::setTopLine(int visualTopLine, int dx)-
619{-
620 QTextDocument *doc = control->document();-
621 QTextBlock block = doc->findBlockByLineNumber(visualTopLine);-
622 int blockNumber = block.blockNumber();-
623 int lineNumber = visualTopLine - block.firstLineNumber();-
624 setTopBlock(blockNumber, lineNumber, dx);-
625}
never executed: end of block
0
626-
627void QPlainTextEditPrivate::setTopBlock(int blockNumber, int lineNumber, int dx)-
628{-
629 Q_Q(QPlainTextEdit);-
630 blockNumber = qMax(0, blockNumber);-
631 lineNumber = qMax(0, lineNumber);-
632 QTextDocument *doc = control->document();-
633 QTextBlock block = doc->findBlockByNumber(blockNumber);-
634-
635 int newTopLine = block.firstLineNumber() + lineNumber;-
636 int maxTopLine = vbar->maximum();-
637-
638 if (newTopLine > maxTopLine) {
newTopLine > maxTopLineDescription
TRUEnever evaluated
FALSEnever evaluated
0
639 block = doc->findBlockByLineNumber(maxTopLine);-
640 blockNumber = block.blockNumber();-
641 lineNumber = maxTopLine - block.firstLineNumber();-
642 }
never executed: end of block
0
643-
644 {-
645 const QSignalBlocker blocker(vbar);-
646 vbar->setValue(newTopLine);-
647 }-
648-
649 if (!dx && blockNumber == control->topBlock && lineNumber == topLine)
!dxDescription
TRUEnever evaluated
FALSEnever evaluated
blockNumber ==...trol->topBlockDescription
TRUEnever evaluated
FALSEnever evaluated
lineNumber == topLineDescription
TRUEnever evaluated
FALSEnever evaluated
0
650 return;
never executed: return;
0
651-
652 if (viewport->updatesEnabled() && viewport->isVisible()) {
viewport->updatesEnabled()Description
TRUEnever evaluated
FALSEnever evaluated
viewport->isVisible()Description
TRUEnever evaluated
FALSEnever evaluated
0
653 int dy = 0;-
654 if (doc->findBlockByNumber(control->topBlock).isValid()) {
doc->findBlock...ock).isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
655 qreal realdy = -q->blockBoundingGeometry(block).y()-
656 + verticalOffset() - verticalOffset(blockNumber, lineNumber);-
657 dy = (int)realdy;-
658 topLineFracture = realdy - dy;-
659 }
never executed: end of block
0
660 control->topBlock = blockNumber;-
661 topLine = lineNumber;-
662-
663 {-
664 const QSignalBlocker blocker(vbar);-
665 vbar->setValue(block.firstLineNumber() + lineNumber);-
666 }-
667-
668 if (dx || dy) {
dxDescription
TRUEnever evaluated
FALSEnever evaluated
dyDescription
TRUEnever evaluated
FALSEnever evaluated
0
669 viewport->scroll(q->isRightToLeft() ? -dx : dx, dy);-
670 QGuiApplication::inputMethod()->update(Qt::ImCursorRectangle | Qt::ImAnchorRectangle);-
671 } else {
never executed: end of block
0
672 viewport->update();-
673 topLineFracture = 0;-
674 }
never executed: end of block
0
675 emit q->updateRequest(viewport->rect(), dy);-
676 } else {
never executed: end of block
0
677 control->topBlock = blockNumber;-
678 topLine = lineNumber;-
679 topLineFracture = 0;-
680 }
never executed: end of block
0
681-
682}-
683-
684-
685-
686void QPlainTextEditPrivate::ensureVisible(int position, bool center, bool forceCenter) {-
687 Q_Q(QPlainTextEdit);-
688 QRectF visible = QRectF(viewport->rect()).translated(-q->contentOffset());-
689 QTextBlock block = control->document()->findBlock(position);-
690 if (!block.isValid())
!block.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
691 return;
never executed: return;
0
692 QRectF br = control->blockBoundingRect(block);-
693 if (!br.isValid())
!br.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
694 return;
never executed: return;
0
695 QTextLine line = block.layout()->lineForTextPosition(position - block.position());-
696 Q_ASSERT(line.isValid());-
697 QRectF lr = line.naturalTextRect().translated(br.topLeft());-
698-
699 if (lr.bottom() >= visible.bottom() || (center && lr.top() < visible.top()) || forceCenter){
lr.bottom() >=...sible.bottom()Description
TRUEnever evaluated
FALSEnever evaluated
centerDescription
TRUEnever evaluated
FALSEnever evaluated
lr.top() < visible.top()Description
TRUEnever evaluated
FALSEnever evaluated
forceCenterDescription
TRUEnever evaluated
FALSEnever evaluated
0
700-
701 qreal height = visible.height();-
702 if (center)
centerDescription
TRUEnever evaluated
FALSEnever evaluated
0
703 height /= 2;
never executed: height /= 2;
0
704-
705 qreal h = center ? line.naturalTextRect().center().y() : line.naturalTextRect().bottom();
centerDescription
TRUEnever evaluated
FALSEnever evaluated
0
706-
707 QTextBlock previousVisibleBlock = block;-
708 while (h < height && block.previous().isValid()) {
h < heightDescription
TRUEnever evaluated
FALSEnever evaluated
block.previous().isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
709 previousVisibleBlock = block;-
710 do {-
711 block = block.previous();-
712 } while (!block.isVisible() && block.previous().isValid());
never executed: end of block
!block.isVisible()Description
TRUEnever evaluated
FALSEnever evaluated
block.previous().isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
713 h += q->blockBoundingRect(block).height();-
714 }
never executed: end of block
0
715-
716 int l = 0;-
717 int lineCount = block.layout()->lineCount();-
718 qreal voffset = verticalOffset(block.blockNumber(), 0);-
719 while (l < lineCount) {
l < lineCountDescription
TRUEnever evaluated
FALSEnever evaluated
0
720 QRectF lineRect = block.layout()->lineAt(l).naturalTextRect();-
721 if (h - voffset - lineRect.top() <= height)
h - voffset - ...op() <= heightDescription
TRUEnever evaluated
FALSEnever evaluated
0
722 break;
never executed: break;
0
723 ++l;-
724 }
never executed: end of block
0
725-
726 if (l >= lineCount) {
l >= lineCountDescription
TRUEnever evaluated
FALSEnever evaluated
0
727 block = previousVisibleBlock;-
728 l = 0;-
729 }
never executed: end of block
0
730 setTopBlock(block.blockNumber(), l);-
731 } else if (lr.top() < visible.top()) {
never executed: end of block
lr.top() < visible.top()Description
TRUEnever evaluated
FALSEnever evaluated
0
732 setTopBlock(block.blockNumber(), line.lineNumber());-
733 }
never executed: end of block
0
734-
735}
never executed: end of block
0
736-
737-
738void QPlainTextEditPrivate::updateViewport()-
739{-
740 Q_Q(QPlainTextEdit);-
741 viewport->update();-
742 emit q->updateRequest(viewport->rect(), 0);-
743}
never executed: end of block
0
744-
745QPlainTextEditPrivate::QPlainTextEditPrivate()-
746 : control(0),-
747 tabChangesFocus(false),-
748 lineWrap(QPlainTextEdit::WidgetWidth),-
749 wordWrap(QTextOption::WrapAtWordBoundaryOrAnywhere),-
750 clickCausedFocus(0),topLine(0),topLineFracture(0),-
751 pageUpDownLastCursorYIsValid(false)-
752{-
753 showCursorOnInitialShow = true;-
754 backgroundVisible = false;-
755 centerOnScroll = false;-
756 inDrag = false;-
757}
never executed: end of block
0
758-
759-
760void QPlainTextEditPrivate::init(const QString &txt)-
761{-
762 Q_Q(QPlainTextEdit);-
763 control = new QPlainTextEditControl(q);-
764-
765 QTextDocument *doc = new QTextDocument(control);-
766 QAbstractTextDocumentLayout *layout = new QPlainTextDocumentLayout(doc);-
767 doc->setDocumentLayout(layout);-
768 control->setDocument(doc);-
769-
770 control->setPalette(q->palette());-
771-
772 QObject::connect(vbar, SIGNAL(actionTriggered(int)), q, SLOT(_q_verticalScrollbarActionTriggered(int)));-
773-
774 QObject::connect(control, SIGNAL(microFocusChanged()), q, SLOT(updateMicroFocus()));-
775 QObject::connect(control, SIGNAL(documentSizeChanged(QSizeF)), q, SLOT(_q_adjustScrollbars()));-
776 QObject::connect(control, SIGNAL(blockCountChanged(int)), q, SIGNAL(blockCountChanged(int)));-
777 QObject::connect(control, SIGNAL(updateRequest(QRectF)), q, SLOT(_q_repaintContents(QRectF)));-
778 QObject::connect(control, SIGNAL(modificationChanged(bool)), q, SIGNAL(modificationChanged(bool)));-
779-
780 QObject::connect(control, SIGNAL(textChanged()), q, SIGNAL(textChanged()));-
781 QObject::connect(control, SIGNAL(undoAvailable(bool)), q, SIGNAL(undoAvailable(bool)));-
782 QObject::connect(control, SIGNAL(redoAvailable(bool)), q, SIGNAL(redoAvailable(bool)));-
783 QObject::connect(control, SIGNAL(copyAvailable(bool)), q, SIGNAL(copyAvailable(bool)));-
784 QObject::connect(control, SIGNAL(selectionChanged()), q, SIGNAL(selectionChanged()));-
785 QObject::connect(control, SIGNAL(cursorPositionChanged()), q, SLOT(_q_cursorPositionChanged()));-
786-
787 QObject::connect(control, SIGNAL(textChanged()), q, SLOT(updateMicroFocus()));-
788-
789 // set a null page size initially to avoid any relayouting until the textedit-
790 // is shown. relayoutDocument() will take care of setting the page size to the-
791 // viewport dimensions later.-
792 doc->setTextWidth(-1);-
793 doc->documentLayout()->setPaintDevice(viewport);-
794 doc->setDefaultFont(q->font());-
795-
796-
797 if (!txt.isEmpty())
!txt.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
798 control->setPlainText(txt);
never executed: control->setPlainText(txt);
0
799-
800 hbar->setSingleStep(20);-
801 vbar->setSingleStep(1);-
802-
803 viewport->setBackgroundRole(QPalette::Base);-
804 q->setAcceptDrops(true);-
805 q->setFocusPolicy(Qt::StrongFocus);-
806 q->setAttribute(Qt::WA_KeyCompression);-
807 q->setAttribute(Qt::WA_InputMethodEnabled);-
808 q->setInputMethodHints(Qt::ImhMultiLine);-
809-
810#ifndef QT_NO_CURSOR-
811 viewport->setCursor(Qt::IBeamCursor);-
812#endif-
813 originalOffsetY = 0;-
814#ifdef Q_DEAD_CODE_FROM_QT4_WIN-
815 setSingleFingerPanEnabled(true);-
816#endif-
817}
never executed: end of block
0
818-
819void QPlainTextEditPrivate::_q_repaintContents(const QRectF &contentsRect)-
820{-
821 Q_Q(QPlainTextEdit);-
822 if (!contentsRect.isValid()) {
!contentsRect.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
823 updateViewport();-
824 return;
never executed: return;
0
825 }-
826 const int xOffset = horizontalOffset();-
827 const int yOffset = (int)verticalOffset();-
828 const QRect visibleRect(xOffset, yOffset, viewport->width(), viewport->height());-
829-
830 QRect r = contentsRect.adjusted(-1, -1, 1, 1).intersected(visibleRect).toAlignedRect();-
831 if (r.isEmpty())
r.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
832 return;
never executed: return;
0
833-
834 r.translate(-xOffset, -yOffset);-
835 viewport->update(r);-
836 emit q->updateRequest(r, 0);-
837}
never executed: end of block
0
838-
839void QPlainTextEditPrivate::pageUpDown(QTextCursor::MoveOperation op, QTextCursor::MoveMode moveMode, bool moveCursor)-
840{-
841-
842 Q_Q(QPlainTextEdit);-
843-
844 QTextCursor cursor = control->textCursor();-
845 if (moveCursor) {
moveCursorDescription
TRUEnever evaluated
FALSEnever evaluated
0
846 ensureCursorVisible();-
847 if (!pageUpDownLastCursorYIsValid)
!pageUpDownLastCursorYIsValidDescription
TRUEnever evaluated
FALSEnever evaluated
0
848 pageUpDownLastCursorY = control->cursorRect(cursor).top() - verticalOffset();
never executed: pageUpDownLastCursorY = control->cursorRect(cursor).top() - verticalOffset();
0
849 }
never executed: end of block
0
850-
851 qreal lastY = pageUpDownLastCursorY;-
852-
853-
854 if (op == QTextCursor::Down) {
op == QTextCursor::DownDescription
TRUEnever evaluated
FALSEnever evaluated
0
855 QRectF visible = QRectF(viewport->rect()).translated(-q->contentOffset());-
856 QTextBlock firstVisibleBlock = q->firstVisibleBlock();-
857 QTextBlock block = firstVisibleBlock;-
858 QRectF br = q->blockBoundingRect(block);-
859 qreal h = 0;-
860 int atEnd = false;-
861 while (h + br.height() <= visible.bottom()) {
h + br.height(...sible.bottom()Description
TRUEnever evaluated
FALSEnever evaluated
0
862 if (!block.next().isValid()) {
!block.next().isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
863 atEnd = true;-
864 lastY = visible.bottom(); // set cursor to last line-
865 break;
never executed: break;
0
866 }-
867 h += br.height();-
868 block = block.next();-
869 br = q->blockBoundingRect(block);-
870 }
never executed: end of block
0
871-
872 if (!atEnd) {
!atEndDescription
TRUEnever evaluated
FALSEnever evaluated
0
873 int line = 0;-
874 qreal diff = visible.bottom() - h;-
875 int lineCount = block.layout()->lineCount();-
876 while (line < lineCount - 1) {
line < lineCount - 1Description
TRUEnever evaluated
FALSEnever evaluated
0
877 if (block.layout()->lineAt(line).naturalTextRect().bottom() > diff) {
block.layout()...ottom() > diffDescription
TRUEnever evaluated
FALSEnever evaluated
0
878 // the first line that did not completely fit the screen-
879 break;
never executed: break;
0
880 }-
881 ++line;-
882 }
never executed: end of block
0
883 setTopBlock(block.blockNumber(), line);-
884 }
never executed: end of block
0
885-
886 if (moveCursor) {
moveCursorDescription
TRUEnever evaluated
FALSEnever evaluated
0
887 // move using movePosition to keep the cursor's x-
888 lastY += verticalOffset();-
889 bool moved = false;-
890 do {-
891 moved = cursor.movePosition(op, moveMode);-
892 } while (moved && control->cursorRect(cursor).top() < lastY);
never executed: end of block
movedDescription
TRUEnever evaluated
FALSEnever evaluated
control->curso....top() < lastYDescription
TRUEnever evaluated
FALSEnever evaluated
0
893 }
never executed: end of block
0
894-
895 } else if (op == QTextCursor::Up) {
never executed: end of block
op == QTextCursor::UpDescription
TRUEnever evaluated
FALSEnever evaluated
0
896-
897 QRectF visible = QRectF(viewport->rect()).translated(-q->contentOffset());-
898 visible.translate(0, -visible.height()); // previous page-
899 QTextBlock block = q->firstVisibleBlock();-
900 qreal h = 0;-
901 while (h >= visible.top()) {
h >= visible.top()Description
TRUEnever evaluated
FALSEnever evaluated
0
902 if (!block.previous().isValid()) {
!block.previous().isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
903 if (control->topBlock == 0 && topLine == 0) {
control->topBlock == 0Description
TRUEnever evaluated
FALSEnever evaluated
topLine == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
904 lastY = 0; // set cursor to first line-
905 }
never executed: end of block
0
906 break;
never executed: break;
0
907 }-
908 block = block.previous();-
909 QRectF br = q->blockBoundingRect(block);-
910 h -= br.height();-
911 }
never executed: end of block
0
912-
913 int line = 0;-
914 if (block.isValid()) {
block.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
915 qreal diff = visible.top() - h;-
916 int lineCount = block.layout()->lineCount();-
917 while (line < lineCount) {
line < lineCountDescription
TRUEnever evaluated
FALSEnever evaluated
0
918 if (block.layout()->lineAt(line).naturalTextRect().top() >= diff)
block.layout()....top() >= diffDescription
TRUEnever evaluated
FALSEnever evaluated
0
919 break;
never executed: break;
0
920 ++line;-
921 }
never executed: end of block
0
922 if (line == lineCount) {
line == lineCountDescription
TRUEnever evaluated
FALSEnever evaluated
0
923 if (block.next().isValid() && block.next() != q->firstVisibleBlock()) {
block.next().isValid()Description
TRUEnever evaluated
FALSEnever evaluated
block.next() !...VisibleBlock()Description
TRUEnever evaluated
FALSEnever evaluated
0
924 block = block.next();-
925 line = 0;-
926 } else {
never executed: end of block
0
927 --line;-
928 }
never executed: end of block
0
929 }-
930 }
never executed: end of block
0
931 setTopBlock(block.blockNumber(), line);-
932-
933 if (moveCursor) {
moveCursorDescription
TRUEnever evaluated
FALSEnever evaluated
0
934 cursor.setVisualNavigation(true);-
935 // move using movePosition to keep the cursor's x-
936 lastY += verticalOffset();-
937 bool moved = false;-
938 do {-
939 moved = cursor.movePosition(op, moveMode);-
940 } while (moved && control->cursorRect(cursor).top() > lastY);
never executed: end of block
movedDescription
TRUEnever evaluated
FALSEnever evaluated
control->curso....top() > lastYDescription
TRUEnever evaluated
FALSEnever evaluated
0
941 }
never executed: end of block
0
942 }
never executed: end of block
0
943-
944 if (moveCursor) {
moveCursorDescription
TRUEnever evaluated
FALSEnever evaluated
0
945 control->setTextCursor(cursor);-
946 pageUpDownLastCursorYIsValid = true;-
947 }
never executed: end of block
0
948}
never executed: end of block
0
949-
950#ifndef QT_NO_SCROLLBAR-
951-
952void QPlainTextEditPrivate::_q_adjustScrollbars()-
953{-
954 Q_Q(QPlainTextEdit);-
955 QTextDocument *doc = control->document();-
956 QPlainTextDocumentLayout *documentLayout = qobject_cast<QPlainTextDocumentLayout*>(doc->documentLayout());-
957 Q_ASSERT(documentLayout);-
958 bool documentSizeChangedBlocked = documentLayout->priv()->blockDocumentSizeChanged;-
959 documentLayout->priv()->blockDocumentSizeChanged = true;-
960 qreal margin = doc->documentMargin();-
961-
962 int vmax = 0;-
963-
964 int vSliderLength = 0;-
965 if (!centerOnScroll && q->isVisible()) {
!centerOnScrollDescription
TRUEnever evaluated
FALSEnever evaluated
q->isVisible()Description
TRUEnever evaluated
FALSEnever evaluated
0
966 QTextBlock block = doc->lastBlock();-
967 const qreal visible = viewport->rect().height() - margin - 1;-
968 qreal y = 0;-
969 int visibleFromBottom = 0;-
970-
971 while (block.isValid()) {
block.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
972 if (!block.isVisible()) {
!block.isVisible()Description
TRUEnever evaluated
FALSEnever evaluated
0
973 block = block.previous();-
974 continue;
never executed: continue;
0
975 }-
976 y += documentLayout->blockBoundingRect(block).height();-
977-
978 QTextLayout *layout = block.layout();-
979 int layoutLineCount = layout->lineCount();-
980 if (y > visible) {
y > visibleDescription
TRUEnever evaluated
FALSEnever evaluated
0
981 int lineNumber = 0;-
982 while (lineNumber < layoutLineCount) {
lineNumber < layoutLineCountDescription
TRUEnever evaluated
FALSEnever evaluated
0
983 QTextLine line = layout->lineAt(lineNumber);-
984 const QRectF lr = line.naturalTextRect();-
985 if (lr.top() >= y - visible)
lr.top() >= y - visibleDescription
TRUEnever evaluated
FALSEnever evaluated
0
986 break;
never executed: break;
0
987 ++lineNumber;-
988 }
never executed: end of block
0
989 if (lineNumber < layoutLineCount)
lineNumber < layoutLineCountDescription
TRUEnever evaluated
FALSEnever evaluated
0
990 visibleFromBottom += (layoutLineCount - lineNumber);
never executed: visibleFromBottom += (layoutLineCount - lineNumber);
0
991 break;
never executed: break;
0
992-
993 }-
994 visibleFromBottom += layoutLineCount;-
995 block = block.previous();-
996 }
never executed: end of block
0
997 vmax = qMax(0, doc->lineCount() - visibleFromBottom);-
998 vSliderLength = visibleFromBottom;-
999-
1000 } else {
never executed: end of block
0
1001 vmax = qMax(0, doc->lineCount() - 1);-
1002 int lineSpacing = q->fontMetrics().lineSpacing();-
1003 vSliderLength = lineSpacing != 0 ? viewport->height() / lineSpacing : 0;
lineSpacing != 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1004 }
never executed: end of block
0
1005-
1006-
1007-
1008 QSizeF documentSize = documentLayout->documentSize();-
1009 vbar->setRange(0, qMax(0, vmax));-
1010 vbar->setPageStep(vSliderLength);-
1011 int visualTopLine = vmax;-
1012 QTextBlock firstVisibleBlock = q->firstVisibleBlock();-
1013 if (firstVisibleBlock.isValid())
firstVisibleBlock.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
1014 visualTopLine = firstVisibleBlock.firstLineNumber() + topLine;
never executed: visualTopLine = firstVisibleBlock.firstLineNumber() + topLine;
0
1015-
1016 {-
1017 const QSignalBlocker blocker(vbar);-
1018 vbar->setValue(visualTopLine);-
1019 }-
1020-
1021 hbar->setRange(0, (int)documentSize.width() - viewport->width());-
1022 hbar->setPageStep(viewport->width());-
1023 documentLayout->priv()->blockDocumentSizeChanged = documentSizeChangedBlocked;-
1024 setTopLine(vbar->value());-
1025}
never executed: end of block
0
1026-
1027#endif-
1028-
1029-
1030void QPlainTextEditPrivate::ensureViewportLayouted()-
1031{-
1032}-
1033-
1034/*!-
1035 \class QPlainTextEdit-
1036 \since 4.4-
1037 \brief The QPlainTextEdit class provides a widget that is used to edit and display-
1038 plain text.-
1039-
1040 \ingroup richtext-processing-
1041 \inmodule QtWidgets-
1042-
1043 \tableofcontents-
1044-
1045 \section1 Introduction and Concepts-
1046-
1047 QPlainTextEdit is an advanced viewer/editor supporting plain-
1048 text. It is optimized to handle large documents and to respond-
1049 quickly to user input.-
1050-
1051 QPlainText uses very much the same technology and concepts as-
1052 QTextEdit, but is optimized for plain text handling.-
1053-
1054 QPlainTextEdit works on paragraphs and characters. A paragraph is-
1055 a formatted string which is word-wrapped to fit into the width of-
1056 the widget. By default when reading plain text, one newline-
1057 signifies a paragraph. A document consists of zero or more-
1058 paragraphs. Paragraphs are separated by hard line breaks. Each-
1059 character within a paragraph has its own attributes, for example,-
1060 font and color.-
1061-
1062 The shape of the mouse cursor on a QPlainTextEdit is-
1063 Qt::IBeamCursor by default. It can be changed through the-
1064 viewport()'s cursor property.-
1065-
1066 \section1 Using QPlainTextEdit as a Display Widget-
1067-
1068 The text is set or replaced using setPlainText() which deletes the-
1069 existing text and replaces it with the text passed to setPlainText().-
1070-
1071 Text can be inserted using the QTextCursor class or using the-
1072 convenience functions insertPlainText(), appendPlainText() or-
1073 paste().-
1074-
1075 By default, the text edit wraps words at whitespace to fit within-
1076 the text edit widget. The setLineWrapMode() function is used to-
1077 specify the kind of line wrap you want, \l WidgetWidth or \l-
1078 NoWrap if you don't want any wrapping. If you use word wrap to-
1079 the widget's width \l WidgetWidth, you can specify whether to-
1080 break on whitespace or anywhere with setWordWrapMode().-
1081-
1082 The find() function can be used to find and select a given string-
1083 within the text.-
1084-
1085 If you want to limit the total number of paragraphs in a-
1086 QPlainTextEdit, as it is for example useful in a log viewer, then-
1087 you can use the maximumBlockCount property. The combination of-
1088 setMaximumBlockCount() and appendPlainText() turns QPlainTextEdit-
1089 into an efficient viewer for log text. The scrolling can be-
1090 reduced with the centerOnScroll() property, making the log viewer-
1091 even faster. Text can be formatted in a limited way, either using-
1092 a syntax highlighter (see below), or by appending html-formatted-
1093 text with appendHtml(). While QPlainTextEdit does not support-
1094 complex rich text rendering with tables and floats, it does-
1095 support limited paragraph-based formatting that you may need in a-
1096 log viewer.-
1097-
1098 \section2 Read-only Key Bindings-
1099-
1100 When QPlainTextEdit is used read-only the key bindings are limited to-
1101 navigation, and text may only be selected with the mouse:-
1102 \table-
1103 \header \li Keypresses \li Action-
1104 \row \li Qt::UpArrow \li Moves one line up.-
1105 \row \li Qt::DownArrow \li Moves one line down.-
1106 \row \li Qt::LeftArrow \li Moves one character to the left.-
1107 \row \li Qt::RightArrow \li Moves one character to the right.-
1108 \row \li PageUp \li Moves one (viewport) page up.-
1109 \row \li PageDown \li Moves one (viewport) page down.-
1110 \row \li Home \li Moves to the beginning of the text.-
1111 \row \li End \li Moves to the end of the text.-
1112 \row \li Alt+Wheel-
1113 \li Scrolls the page horizontally (the Wheel is the mouse wheel).-
1114 \row \li Ctrl+Wheel \li Zooms the text.-
1115 \row \li Ctrl+A \li Selects all text.-
1116 \endtable-
1117-
1118-
1119 \section1 Using QPlainTextEdit as an Editor-
1120-
1121 All the information about using QPlainTextEdit as a display widget also-
1122 applies here.-
1123-
1124 Selection of text is handled by the QTextCursor class, which provides-
1125 functionality for creating selections, retrieving the text contents or-
1126 deleting selections. You can retrieve the object that corresponds with-
1127 the user-visible cursor using the textCursor() method. If you want to set-
1128 a selection in QPlainTextEdit just create one on a QTextCursor object and-
1129 then make that cursor the visible cursor using setCursor(). The selection-
1130 can be copied to the clipboard with copy(), or cut to the clipboard with-
1131 cut(). The entire text can be selected using selectAll().-
1132-
1133 QPlainTextEdit holds a QTextDocument object which can be retrieved using the-
1134 document() method. You can also set your own document object using setDocument().-
1135 QTextDocument emits a textChanged() signal if the text changes and it also-
1136 provides a isModified() function which will return true if the text has been-
1137 modified since it was either loaded or since the last call to setModified-
1138 with false as argument. In addition it provides methods for undo and redo.-
1139-
1140 \section2 Syntax Highlighting-
1141-
1142 Just like QTextEdit, QPlainTextEdit works together with-
1143 QSyntaxHighlighter.-
1144-
1145 \section2 Editing Key Bindings-
1146-
1147 The list of key bindings which are implemented for editing:-
1148 \table-
1149 \header \li Keypresses \li Action-
1150 \row \li Backspace \li Deletes the character to the left of the cursor.-
1151 \row \li Delete \li Deletes the character to the right of the cursor.-
1152 \row \li Ctrl+C \li Copy the selected text to the clipboard.-
1153 \row \li Ctrl+Insert \li Copy the selected text to the clipboard.-
1154 \row \li Ctrl+K \li Deletes to the end of the line.-
1155 \row \li Ctrl+V \li Pastes the clipboard text into text edit.-
1156 \row \li Shift+Insert \li Pastes the clipboard text into text edit.-
1157 \row \li Ctrl+X \li Deletes the selected text and copies it to the clipboard.-
1158 \row \li Shift+Delete \li Deletes the selected text and copies it to the clipboard.-
1159 \row \li Ctrl+Z \li Undoes the last operation.-
1160 \row \li Ctrl+Y \li Redoes the last operation.-
1161 \row \li LeftArrow \li Moves the cursor one character to the left.-
1162 \row \li Ctrl+LeftArrow \li Moves the cursor one word to the left.-
1163 \row \li RightArrow \li Moves the cursor one character to the right.-
1164 \row \li Ctrl+RightArrow \li Moves the cursor one word to the right.-
1165 \row \li UpArrow \li Moves the cursor one line up.-
1166 \row \li Ctrl+UpArrow \li Moves the cursor one word up.-
1167 \row \li DownArrow \li Moves the cursor one line down.-
1168 \row \li Ctrl+Down Arrow \li Moves the cursor one word down.-
1169 \row \li PageUp \li Moves the cursor one page up.-
1170 \row \li PageDown \li Moves the cursor one page down.-
1171 \row \li Home \li Moves the cursor to the beginning of the line.-
1172 \row \li Ctrl+Home \li Moves the cursor to the beginning of the text.-
1173 \row \li End \li Moves the cursor to the end of the line.-
1174 \row \li Ctrl+End \li Moves the cursor to the end of the text.-
1175 \row \li Alt+Wheel \li Scrolls the page horizontally (the Wheel is the mouse wheel).-
1176 \row \li Ctrl+Wheel \li Zooms the text.-
1177 \endtable-
1178-
1179 To select (mark) text hold down the Shift key whilst pressing one-
1180 of the movement keystrokes, for example, \e{Shift+Right Arrow}-
1181 will select the character to the right, and \e{Shift+Ctrl+Right-
1182 Arrow} will select the word to the right, etc.-
1183-
1184 \section1 Differences to QTextEdit-
1185-
1186 QPlainTextEdit is a thin class, implemented by using most of the-
1187 technology that is behind QTextEdit and QTextDocument. Its-
1188 performance benefits over QTextEdit stem mostly from using a-
1189 different and simplified text layout called-
1190 QPlainTextDocumentLayout on the text document (see-
1191 QTextDocument::setDocumentLayout()). The plain text document layout-
1192 does not support tables nor embedded frames, and \e{replaces a-
1193 pixel-exact height calculation with a line-by-line respectively-
1194 paragraph-by-paragraph scrolling approach}. This makes it possible-
1195 to handle significantly larger documents, and still resize the-
1196 editor with line wrap enabled in real time. It also makes for a-
1197 fast log viewer (see setMaximumBlockCount()).-
1198-
1199-
1200 \sa QTextDocument, QTextCursor, {Application Example},-
1201 {Code Editor Example}, {Syntax Highlighter Example},-
1202 {Rich Text Processing}-
1203-
1204*/-
1205-
1206/*!-
1207 \property QPlainTextEdit::plainText-
1208-
1209 This property gets and sets the plain text editor's contents. The previous-
1210 contents are removed and undo/redo history is reset when this property is set.-
1211-
1212 By default, for an editor with no contents, this property contains an empty string.-
1213*/-
1214-
1215/*!-
1216 \property QPlainTextEdit::undoRedoEnabled-
1217 \brief whether undo and redo are enabled-
1218-
1219 Users are only able to undo or redo actions if this property is-
1220 true, and if there is an action that can be undone (or redone).-
1221-
1222 By default, this property is \c true.-
1223*/-
1224-
1225/*!-
1226 \enum QPlainTextEdit::LineWrapMode-
1227-
1228 \value NoWrap-
1229 \value WidgetWidth-
1230*/-
1231-
1232-
1233/*!-
1234 Constructs an empty QPlainTextEdit with parent \a-
1235 parent.-
1236*/-
1237QPlainTextEdit::QPlainTextEdit(QWidget *parent)-
1238 : QAbstractScrollArea(*new QPlainTextEditPrivate, parent)-
1239{-
1240 Q_D(QPlainTextEdit);-
1241 d->init();-
1242}
never executed: end of block
0
1243-
1244/*!-
1245 \internal-
1246*/-
1247QPlainTextEdit::QPlainTextEdit(QPlainTextEditPrivate &dd, QWidget *parent)-
1248 : QAbstractScrollArea(dd, parent)-
1249{-
1250 Q_D(QPlainTextEdit);-
1251 d->init();-
1252}
never executed: end of block
0
1253-
1254/*!-
1255 Constructs a QPlainTextEdit with parent \a parent. The text edit will display-
1256 the plain text \a text.-
1257*/-
1258QPlainTextEdit::QPlainTextEdit(const QString &text, QWidget *parent)-
1259 : QAbstractScrollArea(*new QPlainTextEditPrivate, parent)-
1260{-
1261 Q_D(QPlainTextEdit);-
1262 d->init(text);-
1263}
never executed: end of block
0
1264-
1265-
1266/*!-
1267 Destructor.-
1268*/-
1269QPlainTextEdit::~QPlainTextEdit()-
1270{-
1271 Q_D(QPlainTextEdit);-
1272 if (d->documentLayoutPtr) {
d->documentLayoutPtrDescription
TRUEnever evaluated
FALSEnever evaluated
0
1273 if (d->documentLayoutPtr->priv()->mainViewPrivate == d)
d->documentLay...ewPrivate == dDescription
TRUEnever evaluated
FALSEnever evaluated
0
1274 d->documentLayoutPtr->priv()->mainViewPrivate = 0;
never executed: d->documentLayoutPtr->priv()->mainViewPrivate = 0;
0
1275 }
never executed: end of block
0
1276}
never executed: end of block
0
1277-
1278/*!-
1279 Makes \a document the new document of the text editor.-
1280-
1281 The parent QObject of the provided document remains the owner-
1282 of the object. If the current document is a child of the text-
1283 editor, then it is deleted.-
1284-
1285 The document must have a document layout that inherits-
1286 QPlainTextDocumentLayout (see QTextDocument::setDocumentLayout()).-
1287-
1288 \sa document()-
1289*/-
1290void QPlainTextEdit::setDocument(QTextDocument *document)-
1291{-
1292 Q_D(QPlainTextEdit);-
1293 QPlainTextDocumentLayout *documentLayout = 0;-
1294-
1295 if (!document) {
!documentDescription
TRUEnever evaluated
FALSEnever evaluated
0
1296 document = new QTextDocument(d->control);-
1297 documentLayout = new QPlainTextDocumentLayout(document);-
1298 document->setDocumentLayout(documentLayout);-
1299 } else {
never executed: end of block
0
1300 documentLayout = qobject_cast<QPlainTextDocumentLayout*>(document->documentLayout());-
1301 if (Q_UNLIKELY(!documentLayout)) {
__builtin_expe...ayout), false)Description
TRUEnever evaluated
FALSEnever evaluated
0
1302 qWarning("QPlainTextEdit::setDocument: Document set does not support QPlainTextDocumentLayout");-
1303 return;
never executed: return;
0
1304 }-
1305 }
never executed: end of block
0
1306 d->control->setDocument(document);-
1307 if (!documentLayout->priv()->mainViewPrivate)
!documentLayou...ainViewPrivateDescription
TRUEnever evaluated
FALSEnever evaluated
0
1308 documentLayout->priv()->mainViewPrivate = d;
never executed: documentLayout->priv()->mainViewPrivate = d;
0
1309 d->documentLayoutPtr = documentLayout;-
1310 d->updateDefaultTextOption();-
1311 d->relayoutDocument();-
1312 d->_q_adjustScrollbars();-
1313}
never executed: end of block
0
1314-
1315/*!-
1316 Returns a pointer to the underlying document.-
1317-
1318 \sa setDocument()-
1319*/-
1320QTextDocument *QPlainTextEdit::document() const-
1321{-
1322 Q_D(const QPlainTextEdit);-
1323 return d->control->document();
never executed: return d->control->document();
0
1324}-
1325-
1326/*!-
1327 \since 5.3-
1328-
1329 \property QPlainTextEdit::placeholderText-
1330 \brief the editor placeholder text-
1331-
1332 Setting this property makes the editor display a grayed-out-
1333 placeholder text as long as the document() is empty.-
1334-
1335 By default, this property contains an empty string.-
1336-
1337 \sa document()-
1338*/-
1339void QPlainTextEdit::setPlaceholderText(const QString &placeholderText)-
1340{-
1341 Q_D(QPlainTextEdit);-
1342 if (d->placeholderText != placeholderText) {
d->placeholder...laceholderTextDescription
TRUEnever evaluated
FALSEnever evaluated
0
1343 d->placeholderText = placeholderText;-
1344 if (d->control->document()->isEmpty())
d->control->do...t()->isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
1345 d->viewport->update();
never executed: d->viewport->update();
0
1346 }
never executed: end of block
0
1347}
never executed: end of block
0
1348-
1349QString QPlainTextEdit::placeholderText() const-
1350{-
1351 Q_D(const QPlainTextEdit);-
1352 return d->placeholderText;
never executed: return d->placeholderText;
0
1353}-
1354-
1355/*!-
1356 Sets the visible \a cursor.-
1357*/-
1358void QPlainTextEdit::setTextCursor(const QTextCursor &cursor)-
1359{-
1360 doSetTextCursor(cursor);-
1361}
never executed: end of block
0
1362-
1363/*!-
1364 \internal-
1365-
1366 This provides a hook for subclasses to intercept cursor changes.-
1367*/-
1368-
1369void QPlainTextEdit::doSetTextCursor(const QTextCursor &cursor)-
1370{-
1371 Q_D(QPlainTextEdit);-
1372 d->control->setTextCursor(cursor);-
1373}
never executed: end of block
0
1374-
1375/*!-
1376 Returns a copy of the QTextCursor that represents the currently visible cursor.-
1377 Note that changes on the returned cursor do not affect QPlainTextEdit's cursor; use-
1378 setTextCursor() to update the visible cursor.-
1379 */-
1380QTextCursor QPlainTextEdit::textCursor() const-
1381{-
1382 Q_D(const QPlainTextEdit);-
1383 return d->control->textCursor();
never executed: return d->control->textCursor();
0
1384}-
1385-
1386/*!-
1387 Returns the reference of the anchor at position \a pos, or an-
1388 empty string if no anchor exists at that point.-
1389-
1390 \since 4.7-
1391 */-
1392QString QPlainTextEdit::anchorAt(const QPoint &pos) const-
1393{-
1394 Q_D(const QPlainTextEdit);-
1395 int cursorPos = d->control->hitTest(pos + QPointF(d->horizontalOffset(),-
1396 d->verticalOffset()),-
1397 Qt::ExactHit);-
1398 if (cursorPos < 0)
cursorPos < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1399 return QString();
never executed: return QString();
0
1400-
1401 QTextDocumentPrivate *pieceTable = document()->docHandle();-
1402 QTextDocumentPrivate::FragmentIterator it = pieceTable->find(cursorPos);-
1403 QTextCharFormat fmt = pieceTable->formatCollection()->charFormat(it->format);-
1404 return fmt.anchorHref();
never executed: return fmt.anchorHref();
0
1405}-
1406-
1407/*!-
1408 Undoes the last operation.-
1409-
1410 If there is no operation to undo, i.e. there is no undo step in-
1411 the undo/redo history, nothing happens.-
1412-
1413 \sa redo()-
1414*/-
1415void QPlainTextEdit::undo()-
1416{-
1417 Q_D(QPlainTextEdit);-
1418 d->control->undo();-
1419}
never executed: end of block
0
1420-
1421void QPlainTextEdit::redo()-
1422{-
1423 Q_D(QPlainTextEdit);-
1424 d->control->redo();-
1425}
never executed: end of block
0
1426-
1427/*!-
1428 \fn void QPlainTextEdit::redo()-
1429-
1430 Redoes the last operation.-
1431-
1432 If there is no operation to redo, i.e. there is no redo step in-
1433 the undo/redo history, nothing happens.-
1434-
1435 \sa undo()-
1436*/-
1437-
1438#ifndef QT_NO_CLIPBOARD-
1439/*!-
1440 Copies the selected text to the clipboard and deletes it from-
1441 the text edit.-
1442-
1443 If there is no selected text nothing happens.-
1444-
1445 \sa copy(), paste()-
1446*/-
1447-
1448void QPlainTextEdit::cut()-
1449{-
1450 Q_D(QPlainTextEdit);-
1451 d->control->cut();-
1452}
never executed: end of block
0
1453-
1454/*!-
1455 Copies any selected text to the clipboard.-
1456-
1457 \sa copyAvailable()-
1458*/-
1459-
1460void QPlainTextEdit::copy()-
1461{-
1462 Q_D(QPlainTextEdit);-
1463 d->control->copy();-
1464}
never executed: end of block
0
1465-
1466/*!-
1467 Pastes the text from the clipboard into the text edit at the-
1468 current cursor position.-
1469-
1470 If there is no text in the clipboard nothing happens.-
1471-
1472 To change the behavior of this function, i.e. to modify what-
1473 QPlainTextEdit can paste and how it is being pasted, reimplement the-
1474 virtual canInsertFromMimeData() and insertFromMimeData()-
1475 functions.-
1476-
1477 \sa cut(), copy()-
1478*/-
1479-
1480void QPlainTextEdit::paste()-
1481{-
1482 Q_D(QPlainTextEdit);-
1483 d->control->paste();-
1484}
never executed: end of block
0
1485#endif-
1486-
1487/*!-
1488 Deletes all the text in the text edit.-
1489-
1490 Note that the undo/redo history is cleared by this function.-
1491-
1492 \sa cut(), setPlainText()-
1493*/-
1494void QPlainTextEdit::clear()-
1495{-
1496 Q_D(QPlainTextEdit);-
1497 // clears and sets empty content-
1498 d->control->topBlock = d->topLine = d->topLineFracture = 0;-
1499 d->control->clear();-
1500}
never executed: end of block
0
1501-
1502-
1503/*!-
1504 Selects all text.-
1505-
1506 \sa copy(), cut(), textCursor()-
1507 */-
1508void QPlainTextEdit::selectAll()-
1509{-
1510 Q_D(QPlainTextEdit);-
1511 d->control->selectAll();-
1512}
never executed: end of block
0
1513-
1514/*! \internal-
1515*/-
1516bool QPlainTextEdit::event(QEvent *e)-
1517{-
1518 Q_D(QPlainTextEdit);-
1519-
1520#ifndef QT_NO_CONTEXTMENU-
1521 if (e->type() == QEvent::ContextMenu
e->type() == Q...t::ContextMenuDescription
TRUEnever evaluated
FALSEnever evaluated
0
1522 && static_cast<QContextMenuEvent *>(e)->reason() == QContextMenuEvent::Keyboard) {
static_cast<QC...vent::KeyboardDescription
TRUEnever evaluated
FALSEnever evaluated
0
1523 ensureCursorVisible();-
1524 const QPoint cursorPos = cursorRect().center();-
1525 QContextMenuEvent ce(QContextMenuEvent::Keyboard, cursorPos, d->viewport->mapToGlobal(cursorPos));-
1526 ce.setAccepted(e->isAccepted());-
1527 const bool result = QAbstractScrollArea::event(&ce);-
1528 e->setAccepted(ce.isAccepted());-
1529 return result;
never executed: return result;
0
1530 }-
1531#endif // QT_NO_CONTEXTMENU-
1532 if (e->type() == QEvent::ShortcutOverride
e->type() == Q...ortcutOverrideDescription
TRUEnever evaluated
FALSEnever evaluated
0
1533 || e->type() == QEvent::ToolTip) {
e->type() == QEvent::ToolTipDescription
TRUEnever evaluated
FALSEnever evaluated
0
1534 d->sendControlEvent(e);-
1535 }
never executed: end of block
0
1536#ifdef QT_KEYPAD_NAVIGATION-
1537 else if (e->type() == QEvent::EnterEditFocus || e->type() == QEvent::LeaveEditFocus) {-
1538 if (QApplication::keypadNavigationEnabled())-
1539 d->sendControlEvent(e);-
1540 }-
1541#endif-
1542#ifndef QT_NO_GESTURES-
1543 else if (e->type() == QEvent::Gesture) {
e->type() == QEvent::GestureDescription
TRUEnever evaluated
FALSEnever evaluated
0
1544 QGestureEvent *ge = static_cast<QGestureEvent *>(e);-
1545 QPanGesture *g = static_cast<QPanGesture *>(ge->gesture(Qt::PanGesture));-
1546 if (g) {
gDescription
TRUEnever evaluated
FALSEnever evaluated
0
1547 QScrollBar *hBar = horizontalScrollBar();-
1548 QScrollBar *vBar = verticalScrollBar();-
1549 if (g->state() == Qt::GestureStarted)
g->state() == ...GestureStartedDescription
TRUEnever evaluated
FALSEnever evaluated
0
1550 d->originalOffsetY = vBar->value();
never executed: d->originalOffsetY = vBar->value();
0
1551 QPointF offset = g->offset();-
1552 if (!offset.isNull()) {
!offset.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
0
1553 if (QApplication::isRightToLeft())
QApplication::isRightToLeft()Description
TRUEnever evaluated
FALSEnever evaluated
0
1554 offset.rx() *= -1;
never executed: offset.rx() *= -1;
0
1555 // QPlainTextEdit scrolls by lines only in vertical direction-
1556 QFontMetrics fm(document()->defaultFont());-
1557 int lineHeight = fm.height();-
1558 int newX = hBar->value() - g->delta().x();-
1559 int newY = d->originalOffsetY - offset.y()/lineHeight;-
1560 hBar->setValue(newX);-
1561 vBar->setValue(newY);-
1562 }
never executed: end of block
0
1563 }
never executed: end of block
0
1564 return true;
never executed: return true;
0
1565 }-
1566#endif // QT_NO_GESTURES-
1567 return QAbstractScrollArea::event(e);
never executed: return QAbstractScrollArea::event(e);
0
1568}-
1569-
1570/*! \internal-
1571*/-
1572-
1573void QPlainTextEdit::timerEvent(QTimerEvent *e)-
1574{-
1575 Q_D(QPlainTextEdit);-
1576 if (e->timerId() == d->autoScrollTimer.timerId()) {
e->timerId() =...imer.timerId()Description
TRUEnever evaluated
FALSEnever evaluated
0
1577 QRect visible = d->viewport->rect();-
1578 QPoint pos;-
1579 if (d->inDrag) {
d->inDragDescription
TRUEnever evaluated
FALSEnever evaluated
0
1580 pos = d->autoScrollDragPos;-
1581 visible.adjust(qMin(visible.width()/3,20), qMin(visible.height()/3,20),-
1582 -qMin(visible.width()/3,20), -qMin(visible.height()/3,20));-
1583 } else {
never executed: end of block
0
1584 const QPoint globalPos = QCursor::pos();-
1585 pos = d->viewport->mapFromGlobal(globalPos);-
1586 QMouseEvent ev(QEvent::MouseMove, pos, d->viewport->mapTo(d->viewport->topLevelWidget(), pos), globalPos,-
1587 Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);-
1588 mouseMoveEvent(&ev);-
1589 }
never executed: end of block
0
1590 int deltaY = qMax(pos.y() - visible.top(), visible.bottom() - pos.y()) - visible.height();-
1591 int deltaX = qMax(pos.x() - visible.left(), visible.right() - pos.x()) - visible.width();-
1592 int delta = qMax(deltaX, deltaY);-
1593 if (delta >= 0) {
delta >= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1594 if (delta < 7)
delta < 7Description
TRUEnever evaluated
FALSEnever evaluated
0
1595 delta = 7;
never executed: delta = 7;
0
1596 int timeout = 4900 / (delta * delta);-
1597 d->autoScrollTimer.start(timeout, this);-
1598-
1599 if (deltaY > 0)
deltaY > 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1600 d->vbar->triggerAction(pos.y() < visible.center().y() ?
never executed: d->vbar->triggerAction(pos.y() < visible.center().y() ? QAbstractSlider::SliderSingleStepSub : QAbstractSlider::SliderSingleStepAdd);
0
1601 QAbstractSlider::SliderSingleStepSub
never executed: d->vbar->triggerAction(pos.y() < visible.center().y() ? QAbstractSlider::SliderSingleStepSub : QAbstractSlider::SliderSingleStepAdd);
0
1602 : QAbstractSlider::SliderSingleStepAdd);
never executed: d->vbar->triggerAction(pos.y() < visible.center().y() ? QAbstractSlider::SliderSingleStepSub : QAbstractSlider::SliderSingleStepAdd);
0
1603 if (deltaX > 0)
deltaX > 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1604 d->hbar->triggerAction(pos.x() < visible.center().x() ?
never executed: d->hbar->triggerAction(pos.x() < visible.center().x() ? QAbstractSlider::SliderSingleStepSub : QAbstractSlider::SliderSingleStepAdd);
0
1605 QAbstractSlider::SliderSingleStepSub
never executed: d->hbar->triggerAction(pos.x() < visible.center().x() ? QAbstractSlider::SliderSingleStepSub : QAbstractSlider::SliderSingleStepAdd);
0
1606 : QAbstractSlider::SliderSingleStepAdd);
never executed: d->hbar->triggerAction(pos.x() < visible.center().x() ? QAbstractSlider::SliderSingleStepSub : QAbstractSlider::SliderSingleStepAdd);
0
1607 }
never executed: end of block
0
1608 }
never executed: end of block
0
1609#ifdef QT_KEYPAD_NAVIGATION-
1610 else if (e->timerId() == d->deleteAllTimer.timerId()) {-
1611 d->deleteAllTimer.stop();-
1612 clear();-
1613 }-
1614#endif-
1615}
never executed: end of block
0
1616-
1617/*!-
1618 Changes the text of the text edit to the string \a text.-
1619 Any previous text is removed.-
1620-
1621 \a text is interpreted as plain text.-
1622-
1623 Note that the undo/redo history is cleared by this function.-
1624-
1625 \sa toPlainText()-
1626*/-
1627-
1628void QPlainTextEdit::setPlainText(const QString &text)-
1629{-
1630 Q_D(QPlainTextEdit);-
1631 d->control->setPlainText(text);-
1632}
never executed: end of block
0
1633-
1634/*!-
1635 \fn QString QPlainTextEdit::toPlainText() const-
1636-
1637 Returns the text of the text edit as plain text.-
1638-
1639 \sa QPlainTextEdit::setPlainText()-
1640 */-
1641-
1642/*! \reimp-
1643*/-
1644void QPlainTextEdit::keyPressEvent(QKeyEvent *e)-
1645{-
1646 Q_D(QPlainTextEdit);-
1647-
1648#ifdef QT_KEYPAD_NAVIGATION-
1649 switch (e->key()) {-
1650 case Qt::Key_Select:-
1651 if (QApplication::keypadNavigationEnabled()) {-
1652 if (!(d->control->textInteractionFlags() & Qt::LinksAccessibleByKeyboard))-
1653 setEditFocus(!hasEditFocus());-
1654 else {-
1655 if (!hasEditFocus())-
1656 setEditFocus(true);-
1657 else {-
1658 QTextCursor cursor = d->control->textCursor();-
1659 QTextCharFormat charFmt = cursor.charFormat();-
1660 if (!cursor.hasSelection() || charFmt.anchorHref().isEmpty()) {-
1661 setEditFocus(false);-
1662 }-
1663 }-
1664 }-
1665 }-
1666 break;-
1667 case Qt::Key_Back:-
1668 case Qt::Key_No:-
1669 if (!QApplication::keypadNavigationEnabled()-
1670 || (QApplication::keypadNavigationEnabled() && !hasEditFocus())) {-
1671 e->ignore();-
1672 return;-
1673 }-
1674 break;-
1675 default:-
1676 if (QApplication::keypadNavigationEnabled()) {-
1677 if (!hasEditFocus() && !(e->modifiers() & Qt::ControlModifier)) {-
1678 if (e->text()[0].isPrint()) {-
1679 setEditFocus(true);-
1680 clear();-
1681 } else {-
1682 e->ignore();-
1683 return;-
1684 }-
1685 }-
1686 }-
1687 break;-
1688 }-
1689#endif-
1690-
1691#ifndef QT_NO_SHORTCUT-
1692-
1693 Qt::TextInteractionFlags tif = d->control->textInteractionFlags();-
1694-
1695 if (tif & Qt::TextSelectableByKeyboard){
tif & Qt::Text...ableByKeyboardDescription
TRUEnever evaluated
FALSEnever evaluated
0
1696 if (e == QKeySequence::SelectPreviousPage) {
e == QKeySeque...ctPreviousPageDescription
TRUEnever evaluated
FALSEnever evaluated
0
1697 e->accept();-
1698 d->pageUpDown(QTextCursor::Up, QTextCursor::KeepAnchor);-
1699 return;
never executed: return;
0
1700 } else if (e ==QKeySequence::SelectNextPage) {
e ==QKeySequen...SelectNextPageDescription
TRUEnever evaluated
FALSEnever evaluated
0
1701 e->accept();-
1702 d->pageUpDown(QTextCursor::Down, QTextCursor::KeepAnchor);-
1703 return;
never executed: return;
0
1704 }-
1705 }
never executed: end of block
0
1706 if (tif & (Qt::TextSelectableByKeyboard | Qt::TextEditable)) {
tif & (Qt::Tex...:TextEditable)Description
TRUEnever evaluated
FALSEnever evaluated
0
1707 if (e == QKeySequence::MoveToPreviousPage) {
e == QKeySeque...ToPreviousPageDescription
TRUEnever evaluated
FALSEnever evaluated
0
1708 e->accept();-
1709 d->pageUpDown(QTextCursor::Up, QTextCursor::MoveAnchor);-
1710 return;
never executed: return;
0
1711 } else if (e == QKeySequence::MoveToNextPage) {
e == QKeySeque...MoveToNextPageDescription
TRUEnever evaluated
FALSEnever evaluated
0
1712 e->accept();-
1713 d->pageUpDown(QTextCursor::Down, QTextCursor::MoveAnchor);-
1714 return;
never executed: return;
0
1715 }-
1716 }
never executed: end of block
0
1717-
1718 if (!(tif & Qt::TextEditable)) {
!(tif & Qt::TextEditable)Description
TRUEnever evaluated
FALSEnever evaluated
0
1719 switch (e->key()) {-
1720 case Qt::Key_Space:
never executed: case Qt::Key_Space:
0
1721 e->accept();-
1722 if (e->modifiers() & Qt::ShiftModifier)
e->modifiers()...:ShiftModifierDescription
TRUEnever evaluated
FALSEnever evaluated
0
1723 d->vbar->triggerAction(QAbstractSlider::SliderPageStepSub);
never executed: d->vbar->triggerAction(QAbstractSlider::SliderPageStepSub);
0
1724 else-
1725 d->vbar->triggerAction(QAbstractSlider::SliderPageStepAdd);
never executed: d->vbar->triggerAction(QAbstractSlider::SliderPageStepAdd);
0
1726 break;
never executed: break;
0
1727 default:
never executed: default:
0
1728 d->sendControlEvent(e);-
1729 if (!e->isAccepted() && e->modifiers() == Qt::NoModifier) {
!e->isAccepted()Description
TRUEnever evaluated
FALSEnever evaluated
e->modifiers()...Qt::NoModifierDescription
TRUEnever evaluated
FALSEnever evaluated
0
1730 if (e->key() == Qt::Key_Home) {
e->key() == Qt::Key_HomeDescription
TRUEnever evaluated
FALSEnever evaluated
0
1731 d->vbar->triggerAction(QAbstractSlider::SliderToMinimum);-
1732 e->accept();-
1733 } else if (e->key() == Qt::Key_End) {
never executed: end of block
e->key() == Qt::Key_EndDescription
TRUEnever evaluated
FALSEnever evaluated
0
1734 d->vbar->triggerAction(QAbstractSlider::SliderToMaximum);-
1735 e->accept();-
1736 }
never executed: end of block
0
1737 }
never executed: end of block
0
1738 if (!e->isAccepted()) {
!e->isAccepted()Description
TRUEnever evaluated
FALSEnever evaluated
0
1739 QAbstractScrollArea::keyPressEvent(e);-
1740 }
never executed: end of block
0
1741 }
never executed: end of block
0
1742 return;
never executed: return;
0
1743 }-
1744#endif // QT_NO_SHORTCUT-
1745-
1746 d->sendControlEvent(e);-
1747#ifdef QT_KEYPAD_NAVIGATION-
1748 if (!e->isAccepted()) {-
1749 switch (e->key()) {-
1750 case Qt::Key_Up:-
1751 case Qt::Key_Down:-
1752 if (QApplication::keypadNavigationEnabled()) {-
1753 // Cursor position didn't change, so we want to leave-
1754 // these keys to change focus.-
1755 e->ignore();-
1756 return;-
1757 }-
1758 break;-
1759 case Qt::Key_Left:-
1760 case Qt::Key_Right:-
1761 if (QApplication::keypadNavigationEnabled()-
1762 && QApplication::navigationMode() == Qt::NavigationModeKeypadDirectional) {-
1763 // Same as for Key_Up and Key_Down.-
1764 e->ignore();-
1765 return;-
1766 }-
1767 break;-
1768 case Qt::Key_Back:-
1769 if (!e->isAutoRepeat()) {-
1770 if (QApplication::keypadNavigationEnabled()) {-
1771 if (document()->isEmpty()) {-
1772 setEditFocus(false);-
1773 e->accept();-
1774 } else if (!d->deleteAllTimer.isActive()) {-
1775 e->accept();-
1776 d->deleteAllTimer.start(750, this);-
1777 }-
1778 } else {-
1779 e->ignore();-
1780 return;-
1781 }-
1782 }-
1783 break;-
1784 default: break;-
1785 }-
1786 }-
1787#endif-
1788}
never executed: end of block
0
1789-
1790/*! \reimp-
1791*/-
1792void QPlainTextEdit::keyReleaseEvent(QKeyEvent *e)-
1793{-
1794#ifdef QT_KEYPAD_NAVIGATION-
1795 Q_D(QPlainTextEdit);-
1796 if (QApplication::keypadNavigationEnabled()) {-
1797 if (!e->isAutoRepeat() && e->key() == Qt::Key_Back-
1798 && d->deleteAllTimer.isActive()) {-
1799 d->deleteAllTimer.stop();-
1800 QTextCursor cursor = d->control->textCursor();-
1801 QTextBlockFormat blockFmt = cursor.blockFormat();-
1802-
1803 QTextList *list = cursor.currentList();-
1804 if (list && cursor.atBlockStart()) {-
1805 list->remove(cursor.block());-
1806 } else if (cursor.atBlockStart() && blockFmt.indent() > 0) {-
1807 blockFmt.setIndent(blockFmt.indent() - 1);-
1808 cursor.setBlockFormat(blockFmt);-
1809 } else {-
1810 cursor.deletePreviousChar();-
1811 }-
1812 setTextCursor(cursor);-
1813 }-
1814 }-
1815#else-
1816 QWidget::keyReleaseEvent(e);-
1817#endif-
1818}
never executed: end of block
0
1819-
1820/*!-
1821 Loads the resource specified by the given \a type and \a name.-
1822-
1823 This function is an extension of QTextDocument::loadResource().-
1824-
1825 \sa QTextDocument::loadResource()-
1826*/-
1827QVariant QPlainTextEdit::loadResource(int type, const QUrl &name)-
1828{-
1829 Q_UNUSED(type);-
1830 Q_UNUSED(name);-
1831 return QVariant();
never executed: return QVariant();
0
1832}-
1833-
1834/*! \reimp-
1835*/-
1836void QPlainTextEdit::resizeEvent(QResizeEvent *e)-
1837{-
1838 Q_D(QPlainTextEdit);-
1839 if (e->oldSize().width() != e->size().width())
e->oldSize().w...size().width()Description
TRUEnever evaluated
FALSEnever evaluated
0
1840 d->relayoutDocument();
never executed: d->relayoutDocument();
0
1841 d->_q_adjustScrollbars();-
1842}
never executed: end of block
0
1843-
1844void QPlainTextEditPrivate::relayoutDocument()-
1845{-
1846 QTextDocument *doc = control->document();-
1847 QPlainTextDocumentLayout *documentLayout = qobject_cast<QPlainTextDocumentLayout*>(doc->documentLayout());-
1848 Q_ASSERT(documentLayout);-
1849 documentLayoutPtr = documentLayout;-
1850-
1851 int width = viewport->width();-
1852-
1853 if (documentLayout->priv()->mainViewPrivate == 0
documentLayout...ewPrivate == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1854 || documentLayout->priv()->mainViewPrivate == this
documentLayout...rivate == thisDescription
TRUEnever evaluated
FALSEnever evaluated
0
1855 || width > documentLayout->textWidth()) {
width > docume...t->textWidth()Description
TRUEnever evaluated
FALSEnever evaluated
0
1856 documentLayout->priv()->mainViewPrivate = this;-
1857 documentLayout->setTextWidth(width);-
1858 }
never executed: end of block
0
1859}
never executed: end of block
0
1860-
1861static void fillBackground(QPainter *p, const QRectF &rect, QBrush brush, const QRectF &gradientRect = QRectF())-
1862{-
1863 p->save();-
1864 if (brush.style() >= Qt::LinearGradientPattern && brush.style() <= Qt::ConicalGradientPattern) {
brush.style() ...radientPatternDescription
TRUEnever evaluated
FALSEnever evaluated
brush.style() ...radientPatternDescription
TRUEnever evaluated
FALSEnever evaluated
0
1865 if (!gradientRect.isNull()) {
!gradientRect.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
0
1866 QTransform m = QTransform::fromTranslate(gradientRect.left(), gradientRect.top());-
1867 m.scale(gradientRect.width(), gradientRect.height());-
1868 brush.setTransform(m);-
1869 const_cast<QGradient *>(brush.gradient())->setCoordinateMode(QGradient::LogicalMode);-
1870 }
never executed: end of block
0
1871 } else {
never executed: end of block
0
1872 p->setBrushOrigin(rect.topLeft());-
1873 }
never executed: end of block
0
1874 p->fillRect(rect, brush);-
1875 p->restore();-
1876}
never executed: end of block
0
1877-
1878-
1879-
1880/*! \reimp-
1881*/-
1882void QPlainTextEdit::paintEvent(QPaintEvent *e)-
1883{-
1884 QPainter painter(viewport());-
1885 Q_ASSERT(qobject_cast<QPlainTextDocumentLayout*>(document()->documentLayout()));-
1886-
1887 QPointF offset(contentOffset());-
1888-
1889 QRect er = e->rect();-
1890 QRect viewportRect = viewport()->rect();-
1891-
1892 bool editable = !isReadOnly();-
1893-
1894 QTextBlock block = firstVisibleBlock();-
1895 qreal maximumWidth = document()->documentLayout()->documentSize().width();-
1896-
1897 // Set a brush origin so that the WaveUnderline knows where the wave started-
1898 painter.setBrushOrigin(offset);-
1899-
1900 // keep right margin clean from full-width selection-
1901 int maxX = offset.x() + qMax((qreal)viewportRect.width(), maximumWidth)-
1902 - document()->documentMargin();-
1903 er.setRight(qMin(er.right(), maxX));-
1904 painter.setClipRect(er);-
1905-
1906-
1907 QAbstractTextDocumentLayout::PaintContext context = getPaintContext();-
1908-
1909 while (block.isValid()) {
block.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
1910-
1911 QRectF r = blockBoundingRect(block).translated(offset);-
1912 QTextLayout *layout = block.layout();-
1913-
1914 if (!block.isVisible()) {
!block.isVisible()Description
TRUEnever evaluated
FALSEnever evaluated
0
1915 offset.ry() += r.height();-
1916 block = block.next();-
1917 continue;
never executed: continue;
0
1918 }-
1919-
1920 if (r.bottom() >= er.top() && r.top() <= er.bottom()) {
r.bottom() >= er.top()Description
TRUEnever evaluated
FALSEnever evaluated
r.top() <= er.bottom()Description
TRUEnever evaluated
FALSEnever evaluated
0
1921-
1922 QTextBlockFormat blockFormat = block.blockFormat();-
1923-
1924 QBrush bg = blockFormat.background();-
1925 if (bg != Qt::NoBrush) {
bg != Qt::NoBrushDescription
TRUEnever evaluated
FALSEnever evaluated
0
1926 QRectF contentsRect = r;-
1927 contentsRect.setWidth(qMax(r.width(), maximumWidth));-
1928 fillBackground(&painter, contentsRect, bg);-
1929 }
never executed: end of block
0
1930-
1931-
1932 QVector<QTextLayout::FormatRange> selections;-
1933 int blpos = block.position();-
1934 int bllen = block.length();-
1935 for (int i = 0; i < context.selections.size(); ++i) {
i < context.selections.size()Description
TRUEnever evaluated
FALSEnever evaluated
0
1936 const QAbstractTextDocumentLayout::Selection &range = context.selections.at(i);-
1937 const int selStart = range.cursor.selectionStart() - blpos;-
1938 const int selEnd = range.cursor.selectionEnd() - blpos;-
1939 if (selStart < bllen && selEnd > 0
selStart < bllenDescription
TRUEnever evaluated
FALSEnever evaluated
selEnd > 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1940 && selEnd > selStart) {
selEnd > selStartDescription
TRUEnever evaluated
FALSEnever evaluated
0
1941 QTextLayout::FormatRange o;-
1942 o.start = selStart;-
1943 o.length = selEnd - selStart;-
1944 o.format = range.format;-
1945 selections.append(o);-
1946 } else if (!range.cursor.hasSelection() && range.format.hasProperty(QTextFormat::FullWidthSelection)
never executed: end of block
!range.cursor.hasSelection()Description
TRUEnever evaluated
FALSEnever evaluated
range.format.h...idthSelection)Description
TRUEnever evaluated
FALSEnever evaluated
0
1947 && block.contains(range.cursor.position())) {
block.contains...or.position())Description
TRUEnever evaluated
FALSEnever evaluated
0
1948 // for full width selections we don't require an actual selection, just-
1949 // a position to specify the line. that's more convenience in usage.-
1950 QTextLayout::FormatRange o;-
1951 QTextLine l = layout->lineForTextPosition(range.cursor.position() - blpos);-
1952 o.start = l.textStart();-
1953 o.length = l.textLength();-
1954 if (o.start + o.length == bllen - 1)
o.start + o.le...h == bllen - 1Description
TRUEnever evaluated
FALSEnever evaluated
0
1955 ++o.length; // include newline
never executed: ++o.length;
0
1956 o.format = range.format;-
1957 selections.append(o);-
1958 }
never executed: end of block
0
1959 }
never executed: end of block
0
1960-
1961 bool drawCursor = ((editable || (textInteractionFlags() & Qt::TextSelectableByKeyboard))
editableDescription
TRUEnever evaluated
FALSEnever evaluated
(textInteracti...bleByKeyboard)Description
TRUEnever evaluated
FALSEnever evaluated
0
1962 && context.cursorPosition >= blpos
context.cursor...ition >= blposDescription
TRUEnever evaluated
FALSEnever evaluated
0
1963 && context.cursorPosition < blpos + bllen);
context.cursor... blpos + bllenDescription
TRUEnever evaluated
FALSEnever evaluated
0
1964-
1965 bool drawCursorAsBlock = drawCursor && overwriteMode() ;
drawCursorDescription
TRUEnever evaluated
FALSEnever evaluated
overwriteMode()Description
TRUEnever evaluated
FALSEnever evaluated
0
1966-
1967 if (drawCursorAsBlock) {
drawCursorAsBlockDescription
TRUEnever evaluated
FALSEnever evaluated
0
1968 if (context.cursorPosition == blpos + bllen - 1) {
context.cursor...os + bllen - 1Description
TRUEnever evaluated
FALSEnever evaluated
0
1969 drawCursorAsBlock = false;-
1970 } else {
never executed: end of block
0
1971 QTextLayout::FormatRange o;-
1972 o.start = context.cursorPosition - blpos;-
1973 o.length = 1;-
1974 o.format.setForeground(palette().base());-
1975 o.format.setBackground(palette().text());-
1976 selections.append(o);-
1977 }
never executed: end of block
0
1978 }-
1979-
1980-
1981 if (!placeholderText().isEmpty() && document()->isEmpty()) {
!placeholderText().isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
document()->isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
1982 Q_D(QPlainTextEdit);-
1983 QColor col = d->control->palette().text().color();-
1984 col.setAlpha(128);-
1985 painter.setPen(col);-
1986 const int margin = int(document()->documentMargin());-
1987 painter.drawText(r.adjusted(margin, 0, 0, 0), Qt::AlignTop | Qt::TextWordWrap, placeholderText());-
1988 } else {
never executed: end of block
0
1989 layout->draw(&painter, offset, selections, er);-
1990 }
never executed: end of block
0
1991 if ((drawCursor && !drawCursorAsBlock)
drawCursorDescription
TRUEnever evaluated
FALSEnever evaluated
!drawCursorAsBlockDescription
TRUEnever evaluated
FALSEnever evaluated
0
1992 || (editable && context.cursorPosition < -1
editableDescription
TRUEnever evaluated
FALSEnever evaluated
context.cursorPosition < -1Description
TRUEnever evaluated
FALSEnever evaluated
0
1993 && !layout->preeditAreaText().isEmpty())) {
!layout->preed...xt().isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
1994 int cpos = context.cursorPosition;-
1995 if (cpos < -1)
cpos < -1Description
TRUEnever evaluated
FALSEnever evaluated
0
1996 cpos = layout->preeditAreaPosition() - (cpos + 2);
never executed: cpos = layout->preeditAreaPosition() - (cpos + 2);
0
1997 else-
1998 cpos -= blpos;
never executed: cpos -= blpos;
0
1999 layout->drawCursor(&painter, offset, cpos, cursorWidth());-
2000 }
never executed: end of block
0
2001 }
never executed: end of block
0
2002-
2003 offset.ry() += r.height();-
2004 if (offset.y() > viewportRect.height())
offset.y() > v...tRect.height()Description
TRUEnever evaluated
FALSEnever evaluated
0
2005 break;
never executed: break;
0
2006 block = block.next();-
2007 }
never executed: end of block
0
2008-
2009 if (backgroundVisible() && !block.isValid() && offset.y() <= er.bottom()
backgroundVisible()Description
TRUEnever evaluated
FALSEnever evaluated
!block.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
offset.y() <= er.bottom()Description
TRUEnever evaluated
FALSEnever evaluated
0
2010 && (centerOnScroll() || verticalScrollBar()->maximum() == verticalScrollBar()->minimum())) {
centerOnScroll()Description
TRUEnever evaluated
FALSEnever evaluated
verticalScroll...r()->minimum()Description
TRUEnever evaluated
FALSEnever evaluated
0
2011 painter.fillRect(QRect(QPoint((int)er.left(), (int)offset.y()), er.bottomRight()), palette().background());-
2012 }
never executed: end of block
0
2013}
never executed: end of block
0
2014-
2015-
2016void QPlainTextEditPrivate::updateDefaultTextOption()-
2017{-
2018 QTextDocument *doc = control->document();-
2019-
2020 QTextOption opt = doc->defaultTextOption();-
2021 QTextOption::WrapMode oldWrapMode = opt.wrapMode();-
2022-
2023 if (lineWrap == QPlainTextEdit::NoWrap)
lineWrap == QP...xtEdit::NoWrapDescription
TRUEnever evaluated
FALSEnever evaluated
0
2024 opt.setWrapMode(QTextOption::NoWrap);
never executed: opt.setWrapMode(QTextOption::NoWrap);
0
2025 else-
2026 opt.setWrapMode(wordWrap);
never executed: opt.setWrapMode(wordWrap);
0
2027-
2028 if (opt.wrapMode() != oldWrapMode)
opt.wrapMode() != oldWrapModeDescription
TRUEnever evaluated
FALSEnever evaluated
0
2029 doc->setDefaultTextOption(opt);
never executed: doc->setDefaultTextOption(opt);
0
2030}
never executed: end of block
0
2031-
2032-
2033/*! \reimp-
2034*/-
2035void QPlainTextEdit::mousePressEvent(QMouseEvent *e)-
2036{-
2037 Q_D(QPlainTextEdit);-
2038#ifdef QT_KEYPAD_NAVIGATION-
2039 if (QApplication::keypadNavigationEnabled() && !hasEditFocus())-
2040 setEditFocus(true);-
2041#endif-
2042 d->sendControlEvent(e);-
2043}
never executed: end of block
0
2044-
2045/*! \reimp-
2046*/-
2047void QPlainTextEdit::mouseMoveEvent(QMouseEvent *e)-
2048{-
2049 Q_D(QPlainTextEdit);-
2050 d->inDrag = false; // paranoia-
2051 const QPoint pos = e->pos();-
2052 d->sendControlEvent(e);-
2053 if (!(e->buttons() & Qt::LeftButton))
!(e->buttons()...t::LeftButton)Description
TRUEnever evaluated
FALSEnever evaluated
0
2054 return;
never executed: return;
0
2055 if (e->source() == Qt::MouseEventNotSynthesized) {
e->source() ==...NotSynthesizedDescription
TRUEnever evaluated
FALSEnever evaluated
0
2056 const QRect visible = d->viewport->rect();-
2057 if (visible.contains(pos))
visible.contains(pos)Description
TRUEnever evaluated
FALSEnever evaluated
0
2058 d->autoScrollTimer.stop();
never executed: d->autoScrollTimer.stop();
0
2059 else if (!d->autoScrollTimer.isActive())
!d->autoScrollTimer.isActive()Description
TRUEnever evaluated
FALSEnever evaluated
0
2060 d->autoScrollTimer.start(100, this);
never executed: d->autoScrollTimer.start(100, this);
0
2061 }
never executed: end of block
0
2062}
never executed: end of block
0
2063-
2064/*! \reimp-
2065*/-
2066void QPlainTextEdit::mouseReleaseEvent(QMouseEvent *e)-
2067{-
2068 Q_D(QPlainTextEdit);-
2069 d->sendControlEvent(e);-
2070 if (e->source() == Qt::MouseEventNotSynthesized && d->autoScrollTimer.isActive()) {
e->source() ==...NotSynthesizedDescription
TRUEnever evaluated
FALSEnever evaluated
d->autoScrollTimer.isActive()Description
TRUEnever evaluated
FALSEnever evaluated
0
2071 d->autoScrollTimer.stop();-
2072 d->ensureCursorVisible();-
2073 }
never executed: end of block
0
2074-
2075 if (!isReadOnly() && rect().contains(e->pos()))
!isReadOnly()Description
TRUEnever evaluated
FALSEnever evaluated
rect().contains(e->pos())Description
TRUEnever evaluated
FALSEnever evaluated
0
2076 d->handleSoftwareInputPanel(e->button(), d->clickCausedFocus);
never executed: d->handleSoftwareInputPanel(e->button(), d->clickCausedFocus);
0
2077 d->clickCausedFocus = 0;-
2078}
never executed: end of block
0
2079-
2080/*! \reimp-
2081*/-
2082void QPlainTextEdit::mouseDoubleClickEvent(QMouseEvent *e)-
2083{-
2084 Q_D(QPlainTextEdit);-
2085 d->sendControlEvent(e);-
2086}
never executed: end of block
0
2087-
2088/*! \reimp-
2089*/-
2090bool QPlainTextEdit::focusNextPrevChild(bool next)-
2091{-
2092 Q_D(const QPlainTextEdit);-
2093 if (!d->tabChangesFocus && d->control->textInteractionFlags() & Qt::TextEditable)
!d->tabChangesFocusDescription
TRUEnever evaluated
FALSEnever evaluated
d->control->te...::TextEditableDescription
TRUEnever evaluated
FALSEnever evaluated
0
2094 return false;
never executed: return false;
0
2095 return QAbstractScrollArea::focusNextPrevChild(next);
never executed: return QAbstractScrollArea::focusNextPrevChild(next);
0
2096}-
2097-
2098#ifndef QT_NO_CONTEXTMENU-
2099/*!-
2100 \fn void QPlainTextEdit::contextMenuEvent(QContextMenuEvent *event)-
2101-
2102 Shows the standard context menu created with createStandardContextMenu().-
2103-
2104 If you do not want the text edit to have a context menu, you can set-
2105 its \l contextMenuPolicy to Qt::NoContextMenu. If you want to-
2106 customize the context menu, reimplement this function. If you want-
2107 to extend the standard context menu, reimplement this function, call-
2108 createStandardContextMenu() and extend the menu returned.-
2109-
2110 Information about the event is passed in the \a event object.-
2111-
2112 \snippet code/src_gui_widgets_qplaintextedit.cpp 0-
2113*/-
2114void QPlainTextEdit::contextMenuEvent(QContextMenuEvent *e)-
2115{-
2116 Q_D(QPlainTextEdit);-
2117 d->sendControlEvent(e);-
2118}
never executed: end of block
0
2119#endif // QT_NO_CONTEXTMENU-
2120-
2121#ifndef QT_NO_DRAGANDDROP-
2122/*! \reimp-
2123*/-
2124void QPlainTextEdit::dragEnterEvent(QDragEnterEvent *e)-
2125{-
2126 Q_D(QPlainTextEdit);-
2127 d->inDrag = true;-
2128 d->sendControlEvent(e);-
2129}
never executed: end of block
0
2130-
2131/*! \reimp-
2132*/-
2133void QPlainTextEdit::dragLeaveEvent(QDragLeaveEvent *e)-
2134{-
2135 Q_D(QPlainTextEdit);-
2136 d->inDrag = false;-
2137 d->autoScrollTimer.stop();-
2138 d->sendControlEvent(e);-
2139}
never executed: end of block
0
2140-
2141/*! \reimp-
2142*/-
2143void QPlainTextEdit::dragMoveEvent(QDragMoveEvent *e)-
2144{-
2145 Q_D(QPlainTextEdit);-
2146 d->autoScrollDragPos = e->pos();-
2147 if (!d->autoScrollTimer.isActive())
!d->autoScrollTimer.isActive()Description
TRUEnever evaluated
FALSEnever evaluated
0
2148 d->autoScrollTimer.start(100, this);
never executed: d->autoScrollTimer.start(100, this);
0
2149 d->sendControlEvent(e);-
2150}
never executed: end of block
0
2151-
2152/*! \reimp-
2153*/-
2154void QPlainTextEdit::dropEvent(QDropEvent *e)-
2155{-
2156 Q_D(QPlainTextEdit);-
2157 d->inDrag = false;-
2158 d->autoScrollTimer.stop();-
2159 d->sendControlEvent(e);-
2160}
never executed: end of block
0
2161-
2162#endif // QT_NO_DRAGANDDROP-
2163-
2164/*! \reimp-
2165 */-
2166void QPlainTextEdit::inputMethodEvent(QInputMethodEvent *e)-
2167{-
2168 Q_D(QPlainTextEdit);-
2169#ifdef QT_KEYPAD_NAVIGATION-
2170 if (d->control->textInteractionFlags() & Qt::TextEditable-
2171 && QApplication::keypadNavigationEnabled()-
2172 && !hasEditFocus()) {-
2173 setEditFocus(true);-
2174 selectAll(); // so text is replaced rather than appended to-
2175 }-
2176#endif-
2177 d->sendControlEvent(e);-
2178 ensureCursorVisible();-
2179}
never executed: end of block
0
2180-
2181/*!\reimp-
2182*/-
2183void QPlainTextEdit::scrollContentsBy(int dx, int /*dy*/)-
2184{-
2185 Q_D(QPlainTextEdit);-
2186 d->setTopLine(d->vbar->value(), dx);-
2187}
never executed: end of block
0
2188-
2189/*!\reimp-
2190*/-
2191QVariant QPlainTextEdit::inputMethodQuery(Qt::InputMethodQuery property) const-
2192{-
2193 return inputMethodQuery(property, QVariant());
never executed: return inputMethodQuery(property, QVariant());
0
2194}-
2195-
2196/*!\internal-
2197 */-
2198QVariant QPlainTextEdit::inputMethodQuery(Qt::InputMethodQuery query, QVariant argument) const-
2199{-
2200 Q_D(const QPlainTextEdit);-
2201 switch (query) {-
2202 case Qt::ImHints:
never executed: case Qt::ImHints:
0
2203 case Qt::ImInputItemClipRectangle:
never executed: case Qt::ImInputItemClipRectangle:
0
2204 return QWidget::inputMethodQuery(query);
never executed: return QWidget::inputMethodQuery(query);
0
2205 default:
never executed: default:
0
2206 break;
never executed: break;
0
2207 }-
2208-
2209 const QPointF offset = contentOffset();-
2210 switch (argument.type()) {-
2211 case QVariant::RectF:
never executed: case QVariant::RectF:
0
2212 argument = argument.toRectF().translated(-offset);-
2213 break;
never executed: break;
0
2214 case QVariant::PointF:
never executed: case QVariant::PointF:
0
2215 argument = argument.toPointF() - offset;-
2216 break;
never executed: break;
0
2217 case QVariant::Rect:
never executed: case QVariant::Rect:
0
2218 argument = argument.toRect().translated(-offset.toPoint());-
2219 break;
never executed: break;
0
2220 case QVariant::Point:
never executed: case QVariant::Point:
0
2221 argument = argument.toPoint() - offset;-
2222 break;
never executed: break;
0
2223 default:
never executed: default:
0
2224 break;
never executed: break;
0
2225 }-
2226-
2227 const QVariant v = d->control->inputMethodQuery(query, argument);-
2228 switch (v.type()) {-
2229 case QVariant::RectF:
never executed: case QVariant::RectF:
0
2230 return v.toRectF().translated(offset);
never executed: return v.toRectF().translated(offset);
0
2231 case QVariant::PointF:
never executed: case QVariant::PointF:
0
2232 return v.toPointF() + offset;
never executed: return v.toPointF() + offset;
0
2233 case QVariant::Rect:
never executed: case QVariant::Rect:
0
2234 return v.toRect().translated(offset.toPoint());
never executed: return v.toRect().translated(offset.toPoint());
0
2235 case QVariant::Point:
never executed: case QVariant::Point:
0
2236 return v.toPoint() + offset.toPoint();
never executed: return v.toPoint() + offset.toPoint();
0
2237 default:
never executed: default:
0
2238 break;
never executed: break;
0
2239 }-
2240 return v;
never executed: return v;
0
2241}-
2242-
2243/*! \reimp-
2244*/-
2245void QPlainTextEdit::focusInEvent(QFocusEvent *e)-
2246{-
2247 Q_D(QPlainTextEdit);-
2248 if (e->reason() == Qt::MouseFocusReason) {
e->reason() ==...useFocusReasonDescription
TRUEnever evaluated
FALSEnever evaluated
0
2249 d->clickCausedFocus = 1;-
2250 }
never executed: end of block
0
2251 QAbstractScrollArea::focusInEvent(e);-
2252 d->sendControlEvent(e);-
2253}
never executed: end of block
0
2254-
2255/*! \reimp-
2256*/-
2257void QPlainTextEdit::focusOutEvent(QFocusEvent *e)-
2258{-
2259 Q_D(QPlainTextEdit);-
2260 QAbstractScrollArea::focusOutEvent(e);-
2261 d->sendControlEvent(e);-
2262}
never executed: end of block
0
2263-
2264/*! \reimp-
2265*/-
2266void QPlainTextEdit::showEvent(QShowEvent *)-
2267{-
2268 Q_D(QPlainTextEdit);-
2269 if (d->showCursorOnInitialShow) {
d->showCursorOnInitialShowDescription
TRUEnever evaluated
FALSEnever evaluated
0
2270 d->showCursorOnInitialShow = false;-
2271 ensureCursorVisible();-
2272 }
never executed: end of block
0
2273}
never executed: end of block
0
2274-
2275/*! \reimp-
2276*/-
2277void QPlainTextEdit::changeEvent(QEvent *e)-
2278{-
2279 Q_D(QPlainTextEdit);-
2280 QAbstractScrollArea::changeEvent(e);-
2281 if (e->type() == QEvent::ApplicationFontChange
e->type() == Q...tionFontChangeDescription
TRUEnever evaluated
FALSEnever evaluated
0
2282 || e->type() == QEvent::FontChange) {
e->type() == Q...nt::FontChangeDescription
TRUEnever evaluated
FALSEnever evaluated
0
2283 d->control->document()->setDefaultFont(font());-
2284 } else if(e->type() == QEvent::ActivationChange) {
never executed: end of block
e->type() == Q...tivationChangeDescription
TRUEnever evaluated
FALSEnever evaluated
0
2285 if (!isActiveWindow())
!isActiveWindow()Description
TRUEnever evaluated
FALSEnever evaluated
0
2286 d->autoScrollTimer.stop();
never executed: d->autoScrollTimer.stop();
0
2287 } else if (e->type() == QEvent::EnabledChange) {
never executed: end of block
e->type() == Q...:EnabledChangeDescription
TRUEnever evaluated
FALSEnever evaluated
0
2288 e->setAccepted(isEnabled());-
2289 d->sendControlEvent(e);-
2290 } else if (e->type() == QEvent::PaletteChange) {
never executed: end of block
e->type() == Q...:PaletteChangeDescription
TRUEnever evaluated
FALSEnever evaluated
0
2291 d->control->setPalette(palette());-
2292 } else if (e->type() == QEvent::LayoutDirectionChange) {
never executed: end of block
e->type() == Q...irectionChangeDescription
TRUEnever evaluated
FALSEnever evaluated
0
2293 d->sendControlEvent(e);-
2294 }
never executed: end of block
0
2295}
never executed: end of block
0
2296-
2297/*! \reimp-
2298*/-
2299#ifndef QT_NO_WHEELEVENT-
2300void QPlainTextEdit::wheelEvent(QWheelEvent *e)-
2301{-
2302 Q_D(QPlainTextEdit);-
2303 if (!(d->control->textInteractionFlags() & Qt::TextEditable)) {
!(d->control->...:TextEditable)Description
TRUEnever evaluated
FALSEnever evaluated
0
2304 if (e->modifiers() & Qt::ControlModifier) {
e->modifiers()...ontrolModifierDescription
TRUEnever evaluated
FALSEnever evaluated
0
2305 float delta = e->angleDelta().y() / 120.f;-
2306 zoomInF(delta);-
2307 return;
never executed: return;
0
2308 }-
2309 }
never executed: end of block
0
2310 QAbstractScrollArea::wheelEvent(e);-
2311 updateMicroFocus();-
2312}
never executed: end of block
0
2313#endif-
2314-
2315/*!-
2316 \fn QPlainTextEdit::zoomIn(int range)-
2317-
2318 Zooms in on the text by making the base font size \a range-
2319 points larger and recalculating all font sizes to be the new size.-
2320 This does not change the size of any images.-
2321-
2322 \sa zoomOut()-
2323*/-
2324void QPlainTextEdit::zoomIn(int range)-
2325{-
2326 zoomInF(range);-
2327}
never executed: end of block
0
2328-
2329/*!-
2330 \fn QPlainTextEdit::zoomOut(int range)-
2331-
2332 \overload-
2333-
2334 Zooms out on the text by making the base font size \a range points-
2335 smaller and recalculating all font sizes to be the new size. This-
2336 does not change the size of any images.-
2337-
2338 \sa zoomIn()-
2339*/-
2340void QPlainTextEdit::zoomOut(int range)-
2341{-
2342 zoomInF(-range);-
2343}
never executed: end of block
0
2344-
2345/*!-
2346 \internal-
2347*/-
2348void QPlainTextEdit::zoomInF(float range)-
2349{-
2350 if (range == 0.f)
range == 0.fDescription
TRUEnever evaluated
FALSEnever evaluated
0
2351 return;
never executed: return;
0
2352 QFont f = font();-
2353 const float newSize = f.pointSizeF() + range;-
2354 if (newSize <= 0)
newSize <= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
2355 return;
never executed: return;
0
2356 f.setPointSizeF(newSize);-
2357 setFont(f);-
2358}
never executed: end of block
0
2359-
2360#ifndef QT_NO_CONTEXTMENU-
2361/*! This function creates the standard context menu which is shown-
2362 when the user clicks on the text edit with the right mouse-
2363 button. It is called from the default contextMenuEvent() handler.-
2364 The popup menu's ownership is transferred to the caller.-
2365-
2366 We recommend that you use the createStandardContextMenu(QPoint) version instead-
2367 which will enable the actions that are sensitive to where the user clicked.-
2368*/-
2369-
2370QMenu *QPlainTextEdit::createStandardContextMenu()-
2371{-
2372 Q_D(QPlainTextEdit);-
2373 return d->control->createStandardContextMenu(QPointF(), this);
never executed: return d->control->createStandardContextMenu(QPointF(), this);
0
2374}-
2375-
2376/*!-
2377 \since 5.5-
2378 This function creates the standard context menu which is shown-
2379 when the user clicks on the text edit with the right mouse-
2380 button. It is called from the default contextMenuEvent() handler-
2381 and it takes the \a position in document coordinates where the mouse click was.-
2382 This can enable actions that are sensitive to the position where the user clicked.-
2383 The popup menu's ownership is transferred to the caller.-
2384*/-
2385-
2386QMenu *QPlainTextEdit::createStandardContextMenu(const QPoint &position)-
2387{-
2388 Q_D(QPlainTextEdit);-
2389 return d->control->createStandardContextMenu(position, this);
never executed: return d->control->createStandardContextMenu(position, this);
0
2390}-
2391#endif // QT_NO_CONTEXTMENU-
2392-
2393/*!-
2394 returns a QTextCursor at position \a pos (in viewport coordinates).-
2395*/-
2396QTextCursor QPlainTextEdit::cursorForPosition(const QPoint &pos) const-
2397{-
2398 Q_D(const QPlainTextEdit);-
2399 return d->control->cursorForPosition(d->mapToContents(pos));
never executed: return d->control->cursorForPosition(d->mapToContents(pos));
0
2400}-
2401-
2402/*!-
2403 returns a rectangle (in viewport coordinates) that includes the-
2404 \a cursor.-
2405 */-
2406QRect QPlainTextEdit::cursorRect(const QTextCursor &cursor) const-
2407{-
2408 Q_D(const QPlainTextEdit);-
2409 if (cursor.isNull())
cursor.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
0
2410 return QRect();
never executed: return QRect();
0
2411-
2412 QRect r = d->control->cursorRect(cursor).toRect();-
2413 r.translate(-d->horizontalOffset(),-(int)d->verticalOffset());-
2414 return r;
never executed: return r;
0
2415}-
2416-
2417/*!-
2418 returns a rectangle (in viewport coordinates) that includes the-
2419 cursor of the text edit.-
2420 */-
2421QRect QPlainTextEdit::cursorRect() const-
2422{-
2423 Q_D(const QPlainTextEdit);-
2424 QRect r = d->control->cursorRect().toRect();-
2425 r.translate(-d->horizontalOffset(),-(int)d->verticalOffset());-
2426 return r;
never executed: return r;
0
2427}-
2428-
2429-
2430/*!-
2431 \property QPlainTextEdit::overwriteMode-
2432 \brief whether text entered by the user will overwrite existing text-
2433-
2434 As with many text editors, the plain text editor widget can be configured-
2435 to insert or overwrite existing text with new text entered by the user.-
2436-
2437 If this property is \c true, existing text is overwritten, character-for-character-
2438 by new text; otherwise, text is inserted at the cursor position, displacing-
2439 existing text.-
2440-
2441 By default, this property is \c false (new text does not overwrite existing text).-
2442*/-
2443-
2444bool QPlainTextEdit::overwriteMode() const-
2445{-
2446 Q_D(const QPlainTextEdit);-
2447 return d->control->overwriteMode();
never executed: return d->control->overwriteMode();
0
2448}-
2449-
2450void QPlainTextEdit::setOverwriteMode(bool overwrite)-
2451{-
2452 Q_D(QPlainTextEdit);-
2453 d->control->setOverwriteMode(overwrite);-
2454}
never executed: end of block
0
2455-
2456/*!-
2457 \property QPlainTextEdit::tabStopWidth-
2458 \brief the tab stop width in pixels-
2459-
2460 By default, this property contains a value of 80.-
2461*/-
2462-
2463int QPlainTextEdit::tabStopWidth() const-
2464{-
2465 Q_D(const QPlainTextEdit);-
2466 return qRound(d->control->document()->defaultTextOption().tabStop());
never executed: return qRound(d->control->document()->defaultTextOption().tabStop());
0
2467}-
2468-
2469void QPlainTextEdit::setTabStopWidth(int width)-
2470{-
2471 Q_D(QPlainTextEdit);-
2472 QTextOption opt = d->control->document()->defaultTextOption();-
2473 if (opt.tabStop() == width || width < 0)
opt.tabStop() == widthDescription
TRUEnever evaluated
FALSEnever evaluated
width < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
2474 return;
never executed: return;
0
2475 opt.setTabStop(width);-
2476 d->control->document()->setDefaultTextOption(opt);-
2477}
never executed: end of block
0
2478-
2479/*!-
2480 \property QPlainTextEdit::cursorWidth-
2481-
2482 This property specifies the width of the cursor in pixels. The default value is 1.-
2483*/-
2484int QPlainTextEdit::cursorWidth() const-
2485{-
2486 Q_D(const QPlainTextEdit);-
2487 return d->control->cursorWidth();
never executed: return d->control->cursorWidth();
0
2488}-
2489-
2490void QPlainTextEdit::setCursorWidth(int width)-
2491{-
2492 Q_D(QPlainTextEdit);-
2493 d->control->setCursorWidth(width);-
2494}
never executed: end of block
0
2495-
2496-
2497-
2498/*!-
2499 This function allows temporarily marking certain regions in the document-
2500 with a given color, specified as \a selections. This can be useful for-
2501 example in a programming editor to mark a whole line of text with a given-
2502 background color to indicate the existence of a breakpoint.-
2503-
2504 \sa QTextEdit::ExtraSelection, extraSelections()-
2505*/-
2506void QPlainTextEdit::setExtraSelections(const QList<QTextEdit::ExtraSelection> &selections)-
2507{-
2508 Q_D(QPlainTextEdit);-
2509 d->control->setExtraSelections(selections);-
2510}
never executed: end of block
0
2511-
2512/*!-
2513 Returns previously set extra selections.-
2514-
2515 \sa setExtraSelections()-
2516*/-
2517QList<QTextEdit::ExtraSelection> QPlainTextEdit::extraSelections() const-
2518{-
2519 Q_D(const QPlainTextEdit);-
2520 return d->control->extraSelections();
never executed: return d->control->extraSelections();
0
2521}-
2522-
2523/*!-
2524 This function returns a new MIME data object to represent the contents-
2525 of the text edit's current selection. It is called when the selection needs-
2526 to be encapsulated into a new QMimeData object; for example, when a drag-
2527 and drop operation is started, or when data is copied to the clipboard.-
2528-
2529 If you reimplement this function, note that the ownership of the returned-
2530 QMimeData object is passed to the caller. The selection can be retrieved-
2531 by using the textCursor() function.-
2532*/-
2533QMimeData *QPlainTextEdit::createMimeDataFromSelection() const-
2534{-
2535 Q_D(const QPlainTextEdit);-
2536 return d->control->QWidgetTextControl::createMimeDataFromSelection();
never executed: return d->control->QWidgetTextControl::createMimeDataFromSelection();
0
2537}-
2538-
2539/*!-
2540 This function returns \c true if the contents of the MIME data object, specified-
2541 by \a source, can be decoded and inserted into the document. It is called-
2542 for example when during a drag operation the mouse enters this widget and it-
2543 is necessary to determine whether it is possible to accept the drag.-
2544 */-
2545bool QPlainTextEdit::canInsertFromMimeData(const QMimeData *source) const-
2546{-
2547 Q_D(const QPlainTextEdit);-
2548 return d->control->QWidgetTextControl::canInsertFromMimeData(source);
never executed: return d->control->QWidgetTextControl::canInsertFromMimeData(source);
0
2549}-
2550-
2551/*!-
2552 This function inserts the contents of the MIME data object, specified-
2553 by \a source, into the text edit at the current cursor position. It is-
2554 called whenever text is inserted as the result of a clipboard paste-
2555 operation, or when the text edit accepts data from a drag and drop-
2556 operation.-
2557*/-
2558void QPlainTextEdit::insertFromMimeData(const QMimeData *source)-
2559{-
2560 Q_D(QPlainTextEdit);-
2561 d->control->QWidgetTextControl::insertFromMimeData(source);-
2562}
never executed: end of block
0
2563-
2564/*!-
2565 \property QPlainTextEdit::readOnly-
2566 \brief whether the text edit is read-only-
2567-
2568 In a read-only text edit the user can only navigate through the-
2569 text and select text; modifying the text is not possible.-
2570-
2571 This property's default is false.-
2572*/-
2573-
2574bool QPlainTextEdit::isReadOnly() const-
2575{-
2576 Q_D(const QPlainTextEdit);-
2577 return !(d->control->textInteractionFlags() & Qt::TextEditable);
never executed: return !(d->control->textInteractionFlags() & Qt::TextEditable);
0
2578}-
2579-
2580void QPlainTextEdit::setReadOnly(bool ro)-
2581{-
2582 Q_D(QPlainTextEdit);-
2583 Qt::TextInteractionFlags flags = Qt::NoTextInteraction;-
2584 if (ro) {
roDescription
TRUEnever evaluated
FALSEnever evaluated
0
2585 flags = Qt::TextSelectableByMouse;-
2586 } else {
never executed: end of block
0
2587 flags = Qt::TextEditorInteraction;-
2588 }
never executed: end of block
0
2589 setAttribute(Qt::WA_InputMethodEnabled, shouldEnableInputMethod(this));-
2590 d->control->setTextInteractionFlags(flags);-
2591 QEvent event(QEvent::ReadOnlyChange);-
2592 QApplication::sendEvent(this, &event);-
2593}
never executed: end of block
0
2594-
2595/*!-
2596 \property QPlainTextEdit::textInteractionFlags-
2597-
2598 Specifies how the label should interact with user input if it displays text.-
2599-
2600 If the flags contain either Qt::LinksAccessibleByKeyboard or Qt::TextSelectableByKeyboard-
2601 then the focus policy is also automatically set to Qt::ClickFocus.-
2602-
2603 The default value depends on whether the QPlainTextEdit is read-only-
2604 or editable.-
2605*/-
2606-
2607void QPlainTextEdit::setTextInteractionFlags(Qt::TextInteractionFlags flags)-
2608{-
2609 Q_D(QPlainTextEdit);-
2610 d->control->setTextInteractionFlags(flags);-
2611}
never executed: end of block
0
2612-
2613Qt::TextInteractionFlags QPlainTextEdit::textInteractionFlags() const-
2614{-
2615 Q_D(const QPlainTextEdit);-
2616 return d->control->textInteractionFlags();
never executed: return d->control->textInteractionFlags();
0
2617}-
2618-
2619/*!-
2620 Merges the properties specified in \a modifier into the current character-
2621 format by calling QTextCursor::mergeCharFormat on the editor's cursor.-
2622 If the editor has a selection then the properties of \a modifier are-
2623 directly applied to the selection.-
2624-
2625 \sa QTextCursor::mergeCharFormat()-
2626 */-
2627void QPlainTextEdit::mergeCurrentCharFormat(const QTextCharFormat &modifier)-
2628{-
2629 Q_D(QPlainTextEdit);-
2630 d->control->mergeCurrentCharFormat(modifier);-
2631}
never executed: end of block
0
2632-
2633/*!-
2634 Sets the char format that is be used when inserting new text to \a-
2635 format by calling QTextCursor::setCharFormat() on the editor's-
2636 cursor. If the editor has a selection then the char format is-
2637 directly applied to the selection.-
2638 */-
2639void QPlainTextEdit::setCurrentCharFormat(const QTextCharFormat &format)-
2640{-
2641 Q_D(QPlainTextEdit);-
2642 d->control->setCurrentCharFormat(format);-
2643}
never executed: end of block
0
2644-
2645/*!-
2646 Returns the char format that is used when inserting new text.-
2647 */-
2648QTextCharFormat QPlainTextEdit::currentCharFormat() const-
2649{-
2650 Q_D(const QPlainTextEdit);-
2651 return d->control->currentCharFormat();
never executed: return d->control->currentCharFormat();
0
2652}-
2653-
2654-
2655-
2656/*!-
2657 Convenience slot that inserts \a text at the current-
2658 cursor position.-
2659-
2660 It is equivalent to-
2661-
2662 \snippet code/src_gui_widgets_qplaintextedit.cpp 1-
2663 */-
2664void QPlainTextEdit::insertPlainText(const QString &text)-
2665{-
2666 Q_D(QPlainTextEdit);-
2667 d->control->insertPlainText(text);-
2668}
never executed: end of block
0
2669-
2670-
2671/*!-
2672 Moves the cursor by performing the given \a operation.-
2673-
2674 If \a mode is QTextCursor::KeepAnchor, the cursor selects the text it moves over.-
2675 This is the same effect that the user achieves when they hold down the Shift key-
2676 and move the cursor with the cursor keys.-
2677-
2678 \sa QTextCursor::movePosition()-
2679*/-
2680void QPlainTextEdit::moveCursor(QTextCursor::MoveOperation operation, QTextCursor::MoveMode mode)-
2681{-
2682 Q_D(QPlainTextEdit);-
2683 d->control->moveCursor(operation, mode);-
2684}
never executed: end of block
0
2685-
2686/*!-
2687 Returns whether text can be pasted from the clipboard into the textedit.-
2688*/-
2689bool QPlainTextEdit::canPaste() const-
2690{-
2691 Q_D(const QPlainTextEdit);-
2692 return d->control->canPaste();
never executed: return d->control->canPaste();
0
2693}-
2694-
2695/*!-
2696 Convenience function to print the text edit's document to the given \a printer. This-
2697 is equivalent to calling the print method on the document directly except that this-
2698 function also supports QPrinter::Selection as print range.-
2699-
2700 \sa QTextDocument::print()-
2701*/-
2702#ifndef QT_NO_PRINTER-
2703void QPlainTextEdit::print(QPagedPaintDevice *printer) const-
2704{-
2705 Q_D(const QPlainTextEdit);-
2706 d->control->print(printer);-
2707}
never executed: end of block
0
2708#endif-
2709-
2710/*! \property QPlainTextEdit::tabChangesFocus-
2711 \brief whether \uicontrol Tab changes focus or is accepted as input-
2712-
2713 In some occasions text edits should not allow the user to input-
2714 tabulators or change indentation using the \uicontrol Tab key, as this breaks-
2715 the focus chain. The default is false.-
2716-
2717*/-
2718-
2719bool QPlainTextEdit::tabChangesFocus() const-
2720{-
2721 Q_D(const QPlainTextEdit);-
2722 return d->tabChangesFocus;
never executed: return d->tabChangesFocus;
0
2723}-
2724-
2725void QPlainTextEdit::setTabChangesFocus(bool b)-
2726{-
2727 Q_D(QPlainTextEdit);-
2728 d->tabChangesFocus = b;-
2729}
never executed: end of block
0
2730-
2731/*!-
2732 \property QPlainTextEdit::documentTitle-
2733 \brief the title of the document parsed from the text.-
2734-
2735 By default, this property contains an empty string.-
2736*/-
2737-
2738/*!-
2739 \property QPlainTextEdit::lineWrapMode-
2740 \brief the line wrap mode-
2741-
2742 The default mode is WidgetWidth which causes words to be-
2743 wrapped at the right edge of the text edit. Wrapping occurs at-
2744 whitespace, keeping whole words intact. If you want wrapping to-
2745 occur within words use setWordWrapMode().-
2746*/-
2747-
2748QPlainTextEdit::LineWrapMode QPlainTextEdit::lineWrapMode() const-
2749{-
2750 Q_D(const QPlainTextEdit);-
2751 return d->lineWrap;
never executed: return d->lineWrap;
0
2752}-
2753-
2754void QPlainTextEdit::setLineWrapMode(LineWrapMode wrap)-
2755{-
2756 Q_D(QPlainTextEdit);-
2757 if (d->lineWrap == wrap)
d->lineWrap == wrapDescription
TRUEnever evaluated
FALSEnever evaluated
0
2758 return;
never executed: return;
0
2759 d->lineWrap = wrap;-
2760 d->updateDefaultTextOption();-
2761 d->relayoutDocument();-
2762 d->_q_adjustScrollbars();-
2763 ensureCursorVisible();-
2764}
never executed: end of block
0
2765-
2766/*!-
2767 \property QPlainTextEdit::wordWrapMode-
2768 \brief the mode QPlainTextEdit will use when wrapping text by words-
2769-
2770 By default, this property is set to QTextOption::WrapAtWordBoundaryOrAnywhere.-
2771-
2772 \sa QTextOption::WrapMode-
2773*/-
2774-
2775QTextOption::WrapMode QPlainTextEdit::wordWrapMode() const-
2776{-
2777 Q_D(const QPlainTextEdit);-
2778 return d->wordWrap;
never executed: return d->wordWrap;
0
2779}-
2780-
2781void QPlainTextEdit::setWordWrapMode(QTextOption::WrapMode mode)-
2782{-
2783 Q_D(QPlainTextEdit);-
2784 if (mode == d->wordWrap)
mode == d->wordWrapDescription
TRUEnever evaluated
FALSEnever evaluated
0
2785 return;
never executed: return;
0
2786 d->wordWrap = mode;-
2787 d->updateDefaultTextOption();-
2788}
never executed: end of block
0
2789-
2790/*!-
2791 \property QPlainTextEdit::backgroundVisible-
2792 \brief whether the palette background is visible outside the document area-
2793-
2794 If set to true, the plain text edit paints the palette background-
2795 on the viewport area not covered by the text document. Otherwise,-
2796 if set to false, it won't. The feature makes it possible for-
2797 the user to visually distinguish between the area of the document,-
2798 painted with the base color of the palette, and the empty-
2799 area not covered by any document.-
2800-
2801 The default is false.-
2802*/-
2803-
2804bool QPlainTextEdit::backgroundVisible() const-
2805{-
2806 Q_D(const QPlainTextEdit);-
2807 return d->backgroundVisible;
never executed: return d->backgroundVisible;
0
2808}-
2809-
2810void QPlainTextEdit::setBackgroundVisible(bool visible)-
2811{-
2812 Q_D(QPlainTextEdit);-
2813 if (visible == d->backgroundVisible)
visible == d->...kgroundVisibleDescription
TRUEnever evaluated
FALSEnever evaluated
0
2814 return;
never executed: return;
0
2815 d->backgroundVisible = visible;-
2816 d->updateViewport();-
2817}
never executed: end of block
0
2818-
2819/*!-
2820 \property QPlainTextEdit::centerOnScroll-
2821 \brief whether the cursor should be centered on screen-
2822-
2823 If set to true, the plain text edit scrolls the document-
2824 vertically to make the cursor visible at the center of the-
2825 viewport. This also allows the text edit to scroll below the end-
2826 of the document. Otherwise, if set to false, the plain text edit-
2827 scrolls the smallest amount possible to ensure the cursor is-
2828 visible. The same algorithm is applied to any new line appended-
2829 through appendPlainText().-
2830-
2831 The default is false.-
2832-
2833 \sa centerCursor(), ensureCursorVisible()-
2834*/-
2835-
2836bool QPlainTextEdit::centerOnScroll() const-
2837{-
2838 Q_D(const QPlainTextEdit);-
2839 return d->centerOnScroll;
never executed: return d->centerOnScroll;
0
2840}-
2841-
2842void QPlainTextEdit::setCenterOnScroll(bool enabled)-
2843{-
2844 Q_D(QPlainTextEdit);-
2845 if (enabled == d->centerOnScroll)
enabled == d->centerOnScrollDescription
TRUEnever evaluated
FALSEnever evaluated
0
2846 return;
never executed: return;
0
2847 d->centerOnScroll = enabled;-
2848}
never executed: end of block
0
2849-
2850-
2851-
2852/*!-
2853 Finds the next occurrence of the string, \a exp, using the given-
2854 \a options. Returns \c true if \a exp was found and changes the-
2855 cursor to select the match; otherwise returns \c false.-
2856*/-
2857bool QPlainTextEdit::find(const QString &exp, QTextDocument::FindFlags options)-
2858{-
2859 Q_D(QPlainTextEdit);-
2860 return d->control->find(exp, options);
never executed: return d->control->find(exp, options);
0
2861}-
2862-
2863/*!-
2864 \fn bool QPlainTextEdit::find(const QRegExp &exp, QTextDocument::FindFlags options)-
2865-
2866 \since 5.3-
2867 \overload-
2868-
2869 Finds the next occurrence, matching the regular expression, \a exp, using the given-
2870 \a options. The QTextDocument::FindCaseSensitively option is ignored for this overload,-
2871 use QRegExp::caseSensitivity instead.-
2872-
2873 Returns \c true if a match was found and changes the cursor to select the match;-
2874 otherwise returns \c false.-
2875*/-
2876#ifndef QT_NO_REGEXP-
2877bool QPlainTextEdit::find(const QRegExp &exp, QTextDocument::FindFlags options)-
2878{-
2879 Q_D(QPlainTextEdit);-
2880 return d->control->find(exp, options);
never executed: return d->control->find(exp, options);
0
2881}-
2882#endif-
2883-
2884/*!-
2885 \fn void QPlainTextEdit::copyAvailable(bool yes)-
2886-
2887 This signal is emitted when text is selected or de-selected in the-
2888 text edit.-
2889-
2890 When text is selected this signal will be emitted with \a yes set-
2891 to true. If no text has been selected or if the selected text is-
2892 de-selected this signal is emitted with \a yes set to false.-
2893-
2894 If \a yes is true then copy() can be used to copy the selection to-
2895 the clipboard. If \a yes is false then copy() does nothing.-
2896-
2897 \sa selectionChanged()-
2898*/-
2899-
2900-
2901/*!-
2902 \fn void QPlainTextEdit::selectionChanged()-
2903-
2904 This signal is emitted whenever the selection changes.-
2905-
2906 \sa copyAvailable()-
2907*/-
2908-
2909/*!-
2910 \fn void QPlainTextEdit::cursorPositionChanged()-
2911-
2912 This signal is emitted whenever the position of the-
2913 cursor changed.-
2914*/-
2915-
2916-
2917-
2918/*!-
2919 \fn void QPlainTextEdit::updateRequest(const QRect &rect, int dy)-
2920-
2921 This signal is emitted when the text document needs an update of-
2922 the specified \a rect. If the text is scrolled, \a rect will cover-
2923 the entire viewport area. If the text is scrolled vertically, \a-
2924 dy carries the amount of pixels the viewport was scrolled.-
2925-
2926 The purpose of the signal is to support extra widgets in plain-
2927 text edit subclasses that e.g. show line numbers, breakpoints, or-
2928 other extra information.-
2929*/-
2930-
2931/*! \fn void QPlainTextEdit::blockCountChanged(int newBlockCount);-
2932-
2933 This signal is emitted whenever the block count changes. The new-
2934 block count is passed in \a newBlockCount.-
2935*/-
2936-
2937/*! \fn void QPlainTextEdit::modificationChanged(bool changed);-
2938-
2939 This signal is emitted whenever the content of the document-
2940 changes in a way that affects the modification state. If \a-
2941 changed is true, the document has been modified; otherwise it is-
2942 false.-
2943-
2944 For example, calling setModified(false) on a document and then-
2945 inserting text causes the signal to get emitted. If you undo that-
2946 operation, causing the document to return to its original-
2947 unmodified state, the signal will get emitted again.-
2948*/-
2949-
2950-
2951-
2952-
2953void QPlainTextEditPrivate::append(const QString &text, Qt::TextFormat format)-
2954{-
2955 Q_Q(QPlainTextEdit);-
2956-
2957 QTextDocument *document = control->document();-
2958 QPlainTextDocumentLayout *documentLayout = qobject_cast<QPlainTextDocumentLayout*>(document->documentLayout());-
2959 Q_ASSERT(documentLayout);-
2960-
2961 int maximumBlockCount = document->maximumBlockCount();-
2962 if (maximumBlockCount)
maximumBlockCountDescription
TRUEnever evaluated
FALSEnever evaluated
0
2963 document->setMaximumBlockCount(0);
never executed: document->setMaximumBlockCount(0);
0
2964-
2965 const bool atBottom = q->isVisible()
q->isVisible()Description
TRUEnever evaluated
FALSEnever evaluated
0
2966 && (control->blockBoundingRect(document->lastBlock()).bottom() - verticalOffset()
(control->bloc...ct().bottom())Description
TRUEnever evaluated
FALSEnever evaluated
0
2967 <= viewport->rect().bottom());
(control->bloc...ct().bottom())Description
TRUEnever evaluated
FALSEnever evaluated
0
2968-
2969 if (!q->isVisible())
!q->isVisible()Description
TRUEnever evaluated
FALSEnever evaluated
0
2970 showCursorOnInitialShow = true;
never executed: showCursorOnInitialShow = true;
0
2971-
2972 bool documentSizeChangedBlocked = documentLayout->priv()->blockDocumentSizeChanged;-
2973 documentLayout->priv()->blockDocumentSizeChanged = true;-
2974-
2975 if (format == Qt::RichText)
format == Qt::RichTextDescription
TRUEnever evaluated
FALSEnever evaluated
0
2976 control->appendHtml(text);
never executed: control->appendHtml(text);
0
2977 else if (format == Qt::PlainText)
format == Qt::PlainTextDescription
TRUEnever evaluated
FALSEnever evaluated
0
2978 control->appendPlainText(text);
never executed: control->appendPlainText(text);
0
2979 else-
2980 control->append(text);
never executed: control->append(text);
0
2981-
2982 if (maximumBlockCount > 0) {
maximumBlockCount > 0Description
TRUEnever evaluated
FALSEnever evaluated
0
2983 if (document->blockCount() > maximumBlockCount) {
document->bloc...imumBlockCountDescription
TRUEnever evaluated
FALSEnever evaluated
0
2984 bool blockUpdate = false;-
2985 if (control->topBlock) {
control->topBlockDescription
TRUEnever evaluated
FALSEnever evaluated
0
2986 control->topBlock--;-
2987 blockUpdate = true;-
2988 emit q->updateRequest(viewport->rect(), 0);-
2989 }
never executed: end of block
0
2990-
2991 bool updatesBlocked = documentLayout->priv()->blockUpdate;-
2992 documentLayout->priv()->blockUpdate = blockUpdate;-
2993 QTextCursor cursor(document);-
2994 cursor.movePosition(QTextCursor::NextBlock, QTextCursor::KeepAnchor);-
2995 cursor.removeSelectedText();-
2996 documentLayout->priv()->blockUpdate = updatesBlocked;-
2997 }
never executed: end of block
0
2998 document->setMaximumBlockCount(maximumBlockCount);-
2999 }
never executed: end of block
0
3000-
3001 documentLayout->priv()->blockDocumentSizeChanged = documentSizeChangedBlocked;-
3002 _q_adjustScrollbars();-
3003-
3004-
3005 if (atBottom) {
atBottomDescription
TRUEnever evaluated
FALSEnever evaluated
0
3006 const bool needScroll = !centerOnScroll
!centerOnScrollDescription
TRUEnever evaluated
FALSEnever evaluated
0
3007 || control->blockBoundingRect(document->lastBlock()).bottom() - verticalOffset()
control->block...ect().bottom()Description
TRUEnever evaluated
FALSEnever evaluated
0
3008 > viewport->rect().bottom();
control->block...ect().bottom()Description
TRUEnever evaluated
FALSEnever evaluated
0
3009 if (needScroll)
needScrollDescription
TRUEnever evaluated
FALSEnever evaluated
0
3010 vbar->setValue(vbar->maximum());
never executed: vbar->setValue(vbar->maximum());
0
3011 }
never executed: end of block
0
3012}
never executed: end of block
0
3013-
3014-
3015/*!-
3016 Appends a new paragraph with \a text to the end of the text edit.-
3017-
3018 \sa appendHtml()-
3019*/-
3020-
3021void QPlainTextEdit::appendPlainText(const QString &text)-
3022{-
3023 Q_D(QPlainTextEdit);-
3024 d->append(text, Qt::PlainText);-
3025}
never executed: end of block
0
3026-
3027/*!-
3028 Appends a new paragraph with \a html to the end of the text edit.-
3029-
3030 appendPlainText()-
3031*/-
3032-
3033void QPlainTextEdit::appendHtml(const QString &html)-
3034{-
3035 Q_D(QPlainTextEdit);-
3036 d->append(html, Qt::RichText);-
3037}
never executed: end of block
0
3038-
3039void QPlainTextEditPrivate::ensureCursorVisible(bool center)-
3040{-
3041 Q_Q(QPlainTextEdit);-
3042 QRect visible = viewport->rect();-
3043 QRect cr = q->cursorRect();-
3044 if (cr.top() < visible.top() || cr.bottom() > visible.bottom()) {
cr.top() < visible.top()Description
TRUEnever evaluated
FALSEnever evaluated
cr.bottom() > visible.bottom()Description
TRUEnever evaluated
FALSEnever evaluated
0
3045 ensureVisible(control->textCursor().position(), center);-
3046 }
never executed: end of block
0
3047-
3048 const bool rtl = q->isRightToLeft();-
3049 if (cr.left() < visible.left() || cr.right() > visible.right()) {
cr.left() < visible.left()Description
TRUEnever evaluated
FALSEnever evaluated
cr.right() > visible.right()Description
TRUEnever evaluated
FALSEnever evaluated
0
3050 int x = cr.center().x() + horizontalOffset() - visible.width()/2;-
3051 hbar->setValue(rtl ? hbar->maximum() - x : x);-
3052 }
never executed: end of block
0
3053}
never executed: end of block
0
3054-
3055/*!-
3056 Ensures that the cursor is visible by scrolling the text edit if-
3057 necessary.-
3058-
3059 \sa centerCursor(), centerOnScroll-
3060*/-
3061void QPlainTextEdit::ensureCursorVisible()-
3062{-
3063 Q_D(QPlainTextEdit);-
3064 d->ensureCursorVisible(d->centerOnScroll);-
3065}
never executed: end of block
0
3066-
3067-
3068/*! Scrolls the document in order to center the cursor vertically.-
3069-
3070\sa ensureCursorVisible(), centerOnScroll-
3071 */-
3072void QPlainTextEdit::centerCursor()-
3073{-
3074 Q_D(QPlainTextEdit);-
3075 d->ensureVisible(textCursor().position(), true, true);-
3076}
never executed: end of block
0
3077-
3078/*!-
3079 Returns the first visible block.-
3080-
3081 \sa blockBoundingRect()-
3082 */-
3083QTextBlock QPlainTextEdit::firstVisibleBlock() const-
3084{-
3085 Q_D(const QPlainTextEdit);-
3086 return d->control->firstVisibleBlock();
never executed: return d->control->firstVisibleBlock();
0
3087}-
3088-
3089/*! Returns the content's origin in viewport coordinates.-
3090-
3091 The origin of the content of a plain text edit is always the top-
3092 left corner of the first visible text block. The content offset-
3093 is different from (0,0) when the text has been scrolled-
3094 horizontally, or when the first visible block has been scrolled-
3095 partially off the screen, i.e. the visible text does not start-
3096 with the first line of the first visible block, or when the first-
3097 visible block is the very first block and the editor displays a-
3098 margin.-
3099-
3100 \sa firstVisibleBlock(), horizontalScrollBar(), verticalScrollBar()-
3101 */-
3102QPointF QPlainTextEdit::contentOffset() const-
3103{-
3104 Q_D(const QPlainTextEdit);-
3105 return QPointF(-d->horizontalOffset(), -d->verticalOffset());
never executed: return QPointF(-d->horizontalOffset(), -d->verticalOffset());
0
3106}-
3107-
3108-
3109/*! Returns the bounding rectangle of the text \a block in content-
3110 coordinates. Translate the rectangle with the contentOffset() to get-
3111 visual coordinates on the viewport.-
3112-
3113 \sa firstVisibleBlock(), blockBoundingRect()-
3114 */-
3115QRectF QPlainTextEdit::blockBoundingGeometry(const QTextBlock &block) const-
3116{-
3117 Q_D(const QPlainTextEdit);-
3118 return d->control->blockBoundingRect(block);
never executed: return d->control->blockBoundingRect(block);
0
3119}-
3120-
3121/*!-
3122 Returns the bounding rectangle of the text \a block in the block's own coordinates.-
3123-
3124 \sa blockBoundingGeometry()-
3125 */-
3126QRectF QPlainTextEdit::blockBoundingRect(const QTextBlock &block) const-
3127{-
3128 QPlainTextDocumentLayout *documentLayout = qobject_cast<QPlainTextDocumentLayout*>(document()->documentLayout());-
3129 Q_ASSERT(documentLayout);-
3130 return documentLayout->blockBoundingRect(block);
never executed: return documentLayout->blockBoundingRect(block);
0
3131}-
3132-
3133/*!-
3134 \property QPlainTextEdit::blockCount-
3135 \brief the number of text blocks in the document.-
3136-
3137 By default, in an empty document, this property contains a value of 1.-
3138*/-
3139int QPlainTextEdit::blockCount() const-
3140{-
3141 return document()->blockCount();
never executed: return document()->blockCount();
0
3142}-
3143-
3144/*! Returns the paint context for the viewport(), useful only when-
3145 reimplementing paintEvent().-
3146 */-
3147QAbstractTextDocumentLayout::PaintContext QPlainTextEdit::getPaintContext() const-
3148{-
3149 Q_D(const QPlainTextEdit);-
3150 return d->control->getPaintContext(d->viewport);
never executed: return d->control->getPaintContext(d->viewport);
0
3151}-
3152-
3153/*!-
3154 \property QPlainTextEdit::maximumBlockCount-
3155 \brief the limit for blocks in the document.-
3156-
3157 Specifies the maximum number of blocks the document may have. If there are-
3158 more blocks in the document that specified with this property blocks are removed-
3159 from the beginning of the document.-
3160-
3161 A negative or zero value specifies that the document may contain an unlimited-
3162 amount of blocks.-
3163-
3164 The default value is 0.-
3165-
3166 Note that setting this property will apply the limit immediately to the document-
3167 contents. Setting this property also disables the undo redo history.-
3168-
3169*/-
3170-
3171-
3172/*!-
3173 \fn void QPlainTextEdit::textChanged()-
3174-
3175 This signal is emitted whenever the document's content changes; for-
3176 example, when text is inserted or deleted, or when formatting is applied.-
3177*/-
3178-
3179/*!-
3180 \fn void QPlainTextEdit::undoAvailable(bool available)-
3181-
3182 This signal is emitted whenever undo operations become available-
3183 (\a available is true) or unavailable (\a available is false).-
3184*/-
3185-
3186/*!-
3187 \fn void QPlainTextEdit::redoAvailable(bool available)-
3188-
3189 This signal is emitted whenever redo operations become available-
3190 (\a available is true) or unavailable (\a available is false).-
3191*/-
3192-
3193QT_END_NAMESPACE-
3194-
3195#include "moc_qplaintextedit.cpp"-
3196#include "moc_qplaintextedit_p.cpp"-
3197-
3198#endif // QT_NO_TEXTEDIT-
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9