qtextedit.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/widgets/widgets/qtextedit.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 "qtextedit_p.h"-
41#include "qlineedit.h"-
42#include "qtextbrowser.h"-
43-
44#ifndef QT_NO_TEXTEDIT-
45#include <qfont.h>-
46#include <qpainter.h>-
47#include <qevent.h>-
48#include <qdebug.h>-
49#include <qdrag.h>-
50#include <qclipboard.h>-
51#include <qmenu.h>-
52#include <qstyle.h>-
53#include <qtimer.h>-
54#ifndef QT_NO_ACCESSIBILITY-
55#include <qaccessible.h>-
56#endif-
57#include "private/qtextdocumentlayout_p.h"-
58#include "qtextdocument.h"-
59#include "private/qtextdocument_p.h"-
60#include "qtextlist.h"-
61#include "private/qwidgettextcontrol_p.h"-
62-
63#include <qtextformat.h>-
64#include <qdatetime.h>-
65#include <qapplication.h>-
66#include <limits.h>-
67#include <qtexttable.h>-
68#include <qvariant.h>-
69-
70#endif-
71-
72QT_BEGIN_NAMESPACE-
73-
74-
75#ifndef QT_NO_TEXTEDIT-
76static inline bool shouldEnableInputMethod(QTextEdit *textedit)-
77{-
78 return !textedit->isReadOnly();
never executed: return !textedit->isReadOnly();
0
79}-
80-
81class QTextEditControl : public QWidgetTextControl-
82{-
83public:-
84 inline QTextEditControl(QObject *parent) : QWidgetTextControl(parent) {}
never executed: end of block
0
85-
86 virtual QMimeData *createMimeDataFromSelection() const Q_DECL_OVERRIDE {-
87 QTextEdit *ed = qobject_cast<QTextEdit *>(parent());-
88 if (!ed)
!edDescription
TRUEnever evaluated
FALSEnever evaluated
0
89 return QWidgetTextControl::createMimeDataFromSelection();
never executed: return QWidgetTextControl::createMimeDataFromSelection();
0
90 return ed->createMimeDataFromSelection();
never executed: return ed->createMimeDataFromSelection();
0
91 }-
92 virtual bool canInsertFromMimeData(const QMimeData *source) const Q_DECL_OVERRIDE {-
93 QTextEdit *ed = qobject_cast<QTextEdit *>(parent());-
94 if (!ed)
!edDescription
TRUEnever evaluated
FALSEnever evaluated
0
95 return QWidgetTextControl::canInsertFromMimeData(source);
never executed: return QWidgetTextControl::canInsertFromMimeData(source);
0
96 return ed->canInsertFromMimeData(source);
never executed: return ed->canInsertFromMimeData(source);
0
97 }-
98 virtual void insertFromMimeData(const QMimeData *source) Q_DECL_OVERRIDE {-
99 QTextEdit *ed = qobject_cast<QTextEdit *>(parent());-
100 if (!ed)
!edDescription
TRUEnever evaluated
FALSEnever evaluated
0
101 QWidgetTextControl::insertFromMimeData(source);
never executed: QWidgetTextControl::insertFromMimeData(source);
0
102 else-
103 ed->insertFromMimeData(source);
never executed: ed->insertFromMimeData(source);
0
104 }-
105};-
106-
107QTextEditPrivate::QTextEditPrivate()-
108 : control(0),-
109 autoFormatting(QTextEdit::AutoNone), tabChangesFocus(false),-
110 lineWrap(QTextEdit::WidgetWidth), lineWrapColumnOrWidth(0),-
111 wordWrap(QTextOption::WrapAtWordBoundaryOrAnywhere), clickCausedFocus(0),-
112 textFormat(Qt::AutoText)-
113{-
114 ignoreAutomaticScrollbarAdjustment = false;-
115 preferRichText = false;-
116 showCursorOnInitialShow = true;-
117 inDrag = false;-
118}
never executed: end of block
0
119-
120void QTextEditPrivate::createAutoBulletList()-
121{-
122 QTextCursor cursor = control->textCursor();-
123 cursor.beginEditBlock();-
124-
125 QTextBlockFormat blockFmt = cursor.blockFormat();-
126-
127 QTextListFormat listFmt;-
128 listFmt.setStyle(QTextListFormat::ListDisc);-
129 listFmt.setIndent(blockFmt.indent() + 1);-
130-
131 blockFmt.setIndent(0);-
132 cursor.setBlockFormat(blockFmt);-
133-
134 cursor.createList(listFmt);-
135-
136 cursor.endEditBlock();-
137 control->setTextCursor(cursor);-
138}
never executed: end of block
0
139-
140void QTextEditPrivate::init(const QString &html)-
141{-
142 Q_Q(QTextEdit);-
143 control = new QTextEditControl(q);-
144 control->setPalette(q->palette());-
145-
146 QObject::connect(control, SIGNAL(microFocusChanged()), q, SLOT(updateMicroFocus()));-
147 QObject::connect(control, SIGNAL(documentSizeChanged(QSizeF)), q, SLOT(_q_adjustScrollbars()));-
148 QObject::connect(control, SIGNAL(updateRequest(QRectF)), q, SLOT(_q_repaintContents(QRectF)));-
149 QObject::connect(control, SIGNAL(visibilityRequest(QRectF)), q, SLOT(_q_ensureVisible(QRectF)));-
150 QObject::connect(control, SIGNAL(currentCharFormatChanged(QTextCharFormat)),-
151 q, SLOT(_q_currentCharFormatChanged(QTextCharFormat)));-
152-
153 QObject::connect(control, SIGNAL(textChanged()), q, SIGNAL(textChanged()));-
154 QObject::connect(control, SIGNAL(undoAvailable(bool)), q, SIGNAL(undoAvailable(bool)));-
155 QObject::connect(control, SIGNAL(redoAvailable(bool)), q, SIGNAL(redoAvailable(bool)));-
156 QObject::connect(control, SIGNAL(copyAvailable(bool)), q, SIGNAL(copyAvailable(bool)));-
157 QObject::connect(control, SIGNAL(selectionChanged()), q, SIGNAL(selectionChanged()));-
158 QObject::connect(control, SIGNAL(cursorPositionChanged()), q, SLOT(_q_cursorPositionChanged()));-
159-
160 QObject::connect(control, SIGNAL(textChanged()), q, SLOT(updateMicroFocus()));-
161-
162 QTextDocument *doc = control->document();-
163 // set a null page size initially to avoid any relayouting until the textedit-
164 // is shown. relayoutDocument() will take care of setting the page size to the-
165 // viewport dimensions later.-
166 doc->setPageSize(QSize(0, 0));-
167 doc->documentLayout()->setPaintDevice(viewport);-
168 doc->setDefaultFont(q->font());-
169 doc->setUndoRedoEnabled(false); // flush undo buffer.-
170 doc->setUndoRedoEnabled(true);-
171-
172 if (!html.isEmpty())
!html.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
173 control->setHtml(html);
never executed: control->setHtml(html);
0
174-
175 hbar->setSingleStep(20);-
176 vbar->setSingleStep(20);-
177-
178 viewport->setBackgroundRole(QPalette::Base);-
179 q->setAcceptDrops(true);-
180 q->setFocusPolicy(Qt::StrongFocus);-
181 q->setAttribute(Qt::WA_KeyCompression);-
182 q->setAttribute(Qt::WA_InputMethodEnabled);-
183 q->setInputMethodHints(Qt::ImhMultiLine);-
184#ifndef QT_NO_CURSOR-
185 viewport->setCursor(Qt::IBeamCursor);-
186#endif-
187#ifdef Q_DEAD_CODE_FROM_QT4_WIN-
188 setSingleFingerPanEnabled(true);-
189#endif-
190}
never executed: end of block
0
191-
192void QTextEditPrivate::_q_repaintContents(const QRectF &contentsRect)-
193{-
194 if (!contentsRect.isValid()) {
!contentsRect.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
195 viewport->update();-
196 return;
never executed: return;
0
197 }-
198 const int xOffset = horizontalOffset();-
199 const int yOffset = verticalOffset();-
200 const QRectF visibleRect(xOffset, yOffset, viewport->width(), viewport->height());-
201-
202 QRect r = contentsRect.intersected(visibleRect).toAlignedRect();-
203 if (r.isEmpty())
r.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
204 return;
never executed: return;
0
205-
206 r.translate(-xOffset, -yOffset);-
207 viewport->update(r);-
208}
never executed: end of block
0
209-
210void QTextEditPrivate::_q_cursorPositionChanged()-
211{-
212 Q_Q(QTextEdit);-
213 emit q->cursorPositionChanged();-
214#ifndef QT_NO_ACCESSIBILITY-
215 QAccessibleTextCursorEvent event(q, q->textCursor().position());-
216 QAccessible::updateAccessibility(&event);-
217#endif-
218}
never executed: end of block
0
219-
220void QTextEditPrivate::pageUpDown(QTextCursor::MoveOperation op, QTextCursor::MoveMode moveMode)-
221{-
222 QTextCursor cursor = control->textCursor();-
223 bool moved = false;-
224 qreal lastY = control->cursorRect(cursor).top();-
225 qreal distance = 0;-
226 // move using movePosition to keep the cursor's x-
227 do {-
228 qreal y = control->cursorRect(cursor).top();-
229 distance += qAbs(y - lastY);-
230 lastY = y;-
231 moved = cursor.movePosition(op, moveMode);-
232 } while (moved && distance < viewport->height());
never executed: end of block
movedDescription
TRUEnever evaluated
FALSEnever evaluated
distance < viewport->height()Description
TRUEnever evaluated
FALSEnever evaluated
0
233-
234 if (moved) {
movedDescription
TRUEnever evaluated
FALSEnever evaluated
0
235 if (op == QTextCursor::Up) {
op == QTextCursor::UpDescription
TRUEnever evaluated
FALSEnever evaluated
0
236 cursor.movePosition(QTextCursor::Down, moveMode);-
237 vbar->triggerAction(QAbstractSlider::SliderPageStepSub);-
238 } else {
never executed: end of block
0
239 cursor.movePosition(QTextCursor::Up, moveMode);-
240 vbar->triggerAction(QAbstractSlider::SliderPageStepAdd);-
241 }
never executed: end of block
0
242 }-
243 control->setTextCursor(cursor);-
244}
never executed: end of block
0
245-
246#ifndef QT_NO_SCROLLBAR-
247static QSize documentSize(QWidgetTextControl *control)-
248{-
249 QTextDocument *doc = control->document();-
250 QAbstractTextDocumentLayout *layout = doc->documentLayout();-
251-
252 QSize docSize;-
253-
254 if (QTextDocumentLayout *tlayout = qobject_cast<QTextDocumentLayout *>(layout)) {
QTextDocumentL...out *>(layout)Description
TRUEnever evaluated
FALSEnever evaluated
0
255 docSize = tlayout->dynamicDocumentSize().toSize();-
256 int percentageDone = tlayout->layoutStatus();-
257 // extrapolate height-
258 if (percentageDone > 0)
percentageDone > 0Description
TRUEnever evaluated
FALSEnever evaluated
0
259 docSize.setHeight(docSize.height() * 100 / percentageDone);
never executed: docSize.setHeight(docSize.height() * 100 / percentageDone);
0
260 } else {
never executed: end of block
0
261 docSize = layout->documentSize().toSize();-
262 }
never executed: end of block
0
263-
264 return docSize;
never executed: return docSize;
0
265}-
266-
267void QTextEditPrivate::_q_adjustScrollbars()-
268{-
269 if (ignoreAutomaticScrollbarAdjustment)
ignoreAutomati...lbarAdjustmentDescription
TRUEnever evaluated
FALSEnever evaluated
0
270 return;
never executed: return;
0
271 ignoreAutomaticScrollbarAdjustment = true; // avoid recursion, #106108-
272-
273 QSize viewportSize = viewport->size();-
274 QSize docSize = documentSize(control);-
275-
276 // due to the recursion guard we have to repeat this step a few times,-
277 // as adding/removing a scroll bar will cause the document or viewport-
278 // size to change-
279 // ideally we should loop until the viewport size and doc size stabilize,-
280 // but in corner cases they might fluctuate, so we need to limit the-
281 // number of iterations-
282 for (int i = 0; i < 4; ++i) {
i < 4Description
TRUEnever evaluated
FALSEnever evaluated
0
283 hbar->setRange(0, docSize.width() - viewportSize.width());-
284 hbar->setPageStep(viewportSize.width());-
285-
286 vbar->setRange(0, docSize.height() - viewportSize.height());-
287 vbar->setPageStep(viewportSize.height());-
288-
289 // if we are in left-to-right mode widening the document due to-
290 // lazy layouting does not require a repaint. If in right-to-left-
291 // the scroll bar has the value zero and it visually has the maximum-
292 // value (it is visually at the right), then widening the document-
293 // keeps it at value zero but visually adjusts it to the new maximum-
294 // on the right, hence we need an update.-
295 if (q_func()->isRightToLeft())
q_func()->isRightToLeft()Description
TRUEnever evaluated
FALSEnever evaluated
0
296 viewport->update();
never executed: viewport->update();
0
297-
298 _q_showOrHideScrollBars();-
299-
300 const QSize oldViewportSize = viewportSize;-
301 const QSize oldDocSize = docSize;-
302-
303 // make sure the document is layouted if the viewport width changes-
304 viewportSize = viewport->size();-
305 if (viewportSize.width() != oldViewportSize.width())
viewportSize.w...rtSize.width()Description
TRUEnever evaluated
FALSEnever evaluated
0
306 relayoutDocument();
never executed: relayoutDocument();
0
307-
308 docSize = documentSize(control);-
309 if (viewportSize == oldViewportSize && docSize == oldDocSize)
viewportSize =...ldViewportSizeDescription
TRUEnever evaluated
FALSEnever evaluated
docSize == oldDocSizeDescription
TRUEnever evaluated
FALSEnever evaluated
0
310 break;
never executed: break;
0
311 }
never executed: end of block
0
312 ignoreAutomaticScrollbarAdjustment = false;-
313}
never executed: end of block
0
314#endif-
315-
316// rect is in content coordinates-
317void QTextEditPrivate::_q_ensureVisible(const QRectF &_rect)-
318{-
319 const QRect rect = _rect.toRect();-
320 if ((vbar->isVisible() && vbar->maximum() < rect.bottom())
vbar->isVisible()Description
TRUEnever evaluated
FALSEnever evaluated
vbar->maximum(... rect.bottom()Description
TRUEnever evaluated
FALSEnever evaluated
0
321 || (hbar->isVisible() && hbar->maximum() < rect.right()))
hbar->isVisible()Description
TRUEnever evaluated
FALSEnever evaluated
hbar->maximum() < rect.right()Description
TRUEnever evaluated
FALSEnever evaluated
0
322 _q_adjustScrollbars();
never executed: _q_adjustScrollbars();
0
323 const int visibleWidth = viewport->width();-
324 const int visibleHeight = viewport->height();-
325 const bool rtl = q_func()->isRightToLeft();-
326-
327 if (rect.x() < horizontalOffset()) {
rect.x() < horizontalOffset()Description
TRUEnever evaluated
FALSEnever evaluated
0
328 if (rtl)
rtlDescription
TRUEnever evaluated
FALSEnever evaluated
0
329 hbar->setValue(hbar->maximum() - rect.x());
never executed: hbar->setValue(hbar->maximum() - rect.x());
0
330 else-
331 hbar->setValue(rect.x());
never executed: hbar->setValue(rect.x());
0
332 } else if (rect.x() + rect.width() > horizontalOffset() + visibleWidth) {
rect.x() + rec...+ visibleWidthDescription
TRUEnever evaluated
FALSEnever evaluated
0
333 if (rtl)
rtlDescription
TRUEnever evaluated
FALSEnever evaluated
0
334 hbar->setValue(hbar->maximum() - (rect.x() + rect.width() - visibleWidth));
never executed: hbar->setValue(hbar->maximum() - (rect.x() + rect.width() - visibleWidth));
0
335 else-
336 hbar->setValue(rect.x() + rect.width() - visibleWidth);
never executed: hbar->setValue(rect.x() + rect.width() - visibleWidth);
0
337 }-
338-
339 if (rect.y() < verticalOffset())
rect.y() < verticalOffset()Description
TRUEnever evaluated
FALSEnever evaluated
0
340 vbar->setValue(rect.y());
never executed: vbar->setValue(rect.y());
0
341 else if (rect.y() + rect.height() > verticalOffset() + visibleHeight)
rect.y() + rec... visibleHeightDescription
TRUEnever evaluated
FALSEnever evaluated
0
342 vbar->setValue(rect.y() + rect.height() - visibleHeight);
never executed: vbar->setValue(rect.y() + rect.height() - visibleHeight);
0
343}
never executed: end of block
0
344-
345/*!-
346 \class QTextEdit-
347 \brief The QTextEdit class provides a widget that is used to edit and display-
348 both plain and rich text.-
349-
350 \ingroup richtext-processing-
351 \inmodule QtWidgets-
352-
353 \tableofcontents-
354-
355 \section1 Introduction and Concepts-
356-
357 QTextEdit is an advanced WYSIWYG viewer/editor supporting rich-
358 text formatting using HTML-style tags. It is optimized to handle-
359 large documents and to respond quickly to user input.-
360-
361 QTextEdit works on paragraphs and characters. A paragraph is a-
362 formatted string which is word-wrapped to fit into the width of-
363 the widget. By default when reading plain text, one newline-
364 signifies a paragraph. A document consists of zero or more-
365 paragraphs. The words in the paragraph are aligned in accordance-
366 with the paragraph's alignment. Paragraphs are separated by hard-
367 line breaks. Each character within a paragraph has its own-
368 attributes, for example, font and color.-
369-
370 QTextEdit can display images, lists and tables. If the text is-
371 too large to view within the text edit's viewport, scroll bars will-
372 appear. The text edit can load both plain text and rich text files.-
373 Rich text is described using a subset of HTML 4 markup, refer to the-
374 \l {Supported HTML Subset} page for more information.-
375-
376 If you just need to display a small piece of rich text use QLabel.-
377-
378 The rich text support in Qt is designed to provide a fast, portable and-
379 efficient way to add reasonable online help facilities to-
380 applications, and to provide a basis for rich text editors. If-
381 you find the HTML support insufficient for your needs you may consider-
382 the use of Qt WebKit, which provides a full-featured web browser-
383 widget.-
384-
385 The shape of the mouse cursor on a QTextEdit is Qt::IBeamCursor by default.-
386 It can be changed through the viewport()'s cursor property.-
387-
388 \section1 Using QTextEdit as a Display Widget-
389-
390 QTextEdit can display a large HTML subset, including tables and-
391 images.-
392-
393 The text is set or replaced using setHtml() which deletes any-
394 existing text and replaces it with the text passed in the-
395 setHtml() call. If you call setHtml() with legacy HTML, and then-
396 call toHtml(), the text that is returned may have different markup,-
397 but will render the same. The entire text can be deleted with clear().-
398-
399 Text itself can be inserted using the QTextCursor class or using the-
400 convenience functions insertHtml(), insertPlainText(), append() or-
401 paste(). QTextCursor is also able to insert complex objects like tables-
402 or lists into the document, and it deals with creating selections-
403 and applying changes to selected text.-
404-
405 By default the text edit wraps words at whitespace to fit within-
406 the text edit widget. The setLineWrapMode() function is used to-
407 specify the kind of line wrap you want, or \l NoWrap if you don't-
408 want any wrapping. Call setLineWrapMode() to set a fixed pixel width-
409 \l FixedPixelWidth, or character column (e.g. 80 column) \l-
410 FixedColumnWidth with the pixels or columns specified with-
411 setLineWrapColumnOrWidth(). If you use word wrap to the widget's width-
412 \l WidgetWidth, you can specify whether to break on whitespace or-
413 anywhere with setWordWrapMode().-
414-
415 The find() function can be used to find and select a given string-
416 within the text.-
417-
418 If you want to limit the total number of paragraphs in a QTextEdit,-
419 as for example it is often useful in a log viewer, then you can use-
420 QTextDocument's maximumBlockCount property for that.-
421-
422 \section2 Read-only Key Bindings-
423-
424 When QTextEdit is used read-only the key bindings are limited to-
425 navigation, and text may only be selected with the mouse:-
426 \table-
427 \header \li Keypresses \li Action-
428 \row \li Up \li Moves one line up.-
429 \row \li Down \li Moves one line down.-
430 \row \li Left \li Moves one character to the left.-
431 \row \li Right \li Moves one character to the right.-
432 \row \li PageUp \li Moves one (viewport) page up.-
433 \row \li PageDown \li Moves one (viewport) page down.-
434 \row \li Home \li Moves to the beginning of the text.-
435 \row \li End \li Moves to the end of the text.-
436 \row \li Alt+Wheel-
437 \li Scrolls the page horizontally (the Wheel is the mouse wheel).-
438 \row \li Ctrl+Wheel \li Zooms the text.-
439 \row \li Ctrl+A \li Selects all text.-
440 \endtable-
441-
442 The text edit may be able to provide some meta-information. For-
443 example, the documentTitle() function will return the text from-
444 within HTML \c{<title>} tags.-
445-
446 \note Zooming into HTML documents only works if the font-size is not set to a fixed size.-
447-
448 \section1 Using QTextEdit as an Editor-
449-
450 All the information about using QTextEdit as a display widget also-
451 applies here.-
452-
453 The current char format's attributes are set with setFontItalic(),-
454 setFontWeight(), setFontUnderline(), setFontFamily(),-
455 setFontPointSize(), setTextColor() and setCurrentFont(). The current-
456 paragraph's alignment is set with setAlignment().-
457-
458 Selection of text is handled by the QTextCursor class, which provides-
459 functionality for creating selections, retrieving the text contents or-
460 deleting selections. You can retrieve the object that corresponds with-
461 the user-visible cursor using the textCursor() method. If you want to set-
462 a selection in QTextEdit just create one on a QTextCursor object and-
463 then make that cursor the visible cursor using setTextCursor(). The selection-
464 can be copied to the clipboard with copy(), or cut to the clipboard with-
465 cut(). The entire text can be selected using selectAll().-
466-
467 When the cursor is moved and the underlying formatting attributes change,-
468 the currentCharFormatChanged() signal is emitted to reflect the new attributes-
469 at the new cursor position.-
470-
471 The textChanged() signal is emitted whenever the text changes (as a result-
472 of setText() or through the editor itself).-
473-
474 QTextEdit holds a QTextDocument object which can be retrieved using the-
475 document() method. You can also set your own document object using setDocument().-
476-
477 QTextDocument provides an \l {QTextDocument::isModified()}{isModified()}-
478 function which will return true if the text has been modified since it was-
479 either loaded or since the last call to setModified with false as argument.-
480 In addition it provides methods for undo and redo.-
481-
482 \section2 Drag and Drop-
483-
484 QTextEdit also supports custom drag and drop behavior. By default,-
485 QTextEdit will insert plain text, HTML and rich text when the user drops-
486 data of these MIME types onto a document. Reimplement-
487 canInsertFromMimeData() and insertFromMimeData() to add support for-
488 additional MIME types.-
489-
490 For example, to allow the user to drag and drop an image onto a QTextEdit,-
491 you could the implement these functions in the following way:-
492-
493 \snippet textdocument-imagedrop/textedit.cpp 0-
494-
495 We add support for image MIME types by returning true. For all other-
496 MIME types, we use the default implementation.-
497-
498 \snippet textdocument-imagedrop/textedit.cpp 1-
499-
500 We unpack the image from the QVariant held by the MIME source and insert-
501 it into the document as a resource.-
502-
503 \section2 Editing Key Bindings-
504-
505 The list of key bindings which are implemented for editing:-
506 \table-
507 \header \li Keypresses \li Action-
508 \row \li Backspace \li Deletes the character to the left of the cursor.-
509 \row \li Delete \li Deletes the character to the right of the cursor.-
510 \row \li Ctrl+C \li Copy the selected text to the clipboard.-
511 \row \li Ctrl+Insert \li Copy the selected text to the clipboard.-
512 \row \li Ctrl+K \li Deletes to the end of the line.-
513 \row \li Ctrl+V \li Pastes the clipboard text into text edit.-
514 \row \li Shift+Insert \li Pastes the clipboard text into text edit.-
515 \row \li Ctrl+X \li Deletes the selected text and copies it to the clipboard.-
516 \row \li Shift+Delete \li Deletes the selected text and copies it to the clipboard.-
517 \row \li Ctrl+Z \li Undoes the last operation.-
518 \row \li Ctrl+Y \li Redoes the last operation.-
519 \row \li Left \li Moves the cursor one character to the left.-
520 \row \li Ctrl+Left \li Moves the cursor one word to the left.-
521 \row \li Right \li Moves the cursor one character to the right.-
522 \row \li Ctrl+Right \li Moves the cursor one word to the right.-
523 \row \li Up \li Moves the cursor one line up.-
524 \row \li Down \li Moves the cursor one line down.-
525 \row \li PageUp \li Moves the cursor one page up.-
526 \row \li PageDown \li Moves the cursor one page down.-
527 \row \li Home \li Moves the cursor to the beginning of the line.-
528 \row \li Ctrl+Home \li Moves the cursor to the beginning of the text.-
529 \row \li End \li Moves the cursor to the end of the line.-
530 \row \li Ctrl+End \li Moves the cursor to the end of the text.-
531 \row \li Alt+Wheel \li Scrolls the page horizontally (the Wheel is the mouse wheel).-
532 \endtable-
533-
534 To select (mark) text hold down the Shift key whilst pressing one-
535 of the movement keystrokes, for example, \e{Shift+Right}-
536 will select the character to the right, and \e{Shift+Ctrl+Right} will select the word to the right, etc.-
537-
538 \sa QTextDocument, QTextCursor, {Application Example},-
539 {Syntax Highlighter Example}, {Rich Text Processing}-
540*/-
541-
542/*!-
543 \property QTextEdit::plainText-
544 \since 4.3-
545-
546 This property gets and sets the text editor's contents as plain-
547 text. Previous contents are removed and undo/redo history is reset-
548 when the property is set.-
549-
550 If the text edit has another content type, it will not be replaced-
551 by plain text if you call toPlainText(). The only exception to this-
552 is the non-break space, \e{nbsp;}, that will be converted into-
553 standard space.-
554-
555 By default, for an editor with no contents, this property contains-
556 an empty string.-
557-
558 \sa html-
559*/-
560-
561/*!-
562 \property QTextEdit::undoRedoEnabled-
563 \brief whether undo and redo are enabled-
564-
565 Users are only able to undo or redo actions if this property is-
566 true, and if there is an action that can be undone (or redone).-
567*/-
568-
569/*!-
570 \enum QTextEdit::LineWrapMode-
571-
572 \value NoWrap-
573 \value WidgetWidth-
574 \value FixedPixelWidth-
575 \value FixedColumnWidth-
576*/-
577-
578/*!-
579 \enum QTextEdit::AutoFormattingFlag-
580-
581 \value AutoNone Don't do any automatic formatting.-
582 \value AutoBulletList Automatically create bullet lists (e.g. when-
583 the user enters an asterisk ('*') in the left most column, or-
584 presses Enter in an existing list item.-
585 \value AutoAll Apply all automatic formatting. Currently only-
586 automatic bullet lists are supported.-
587*/-
588-
589-
590/*!-
591 Constructs an empty QTextEdit with parent \a-
592 parent.-
593*/-
594QTextEdit::QTextEdit(QWidget *parent)-
595 : QAbstractScrollArea(*new QTextEditPrivate, parent)-
596{-
597 Q_D(QTextEdit);-
598 d->init();-
599}
never executed: end of block
0
600-
601/*!-
602 \internal-
603*/-
604QTextEdit::QTextEdit(QTextEditPrivate &dd, QWidget *parent)-
605 : QAbstractScrollArea(dd, parent)-
606{-
607 Q_D(QTextEdit);-
608 d->init();-
609}
never executed: end of block
0
610-
611/*!-
612 Constructs a QTextEdit with parent \a parent. The text edit will display-
613 the text \a text. The text is interpreted as html.-
614*/-
615QTextEdit::QTextEdit(const QString &text, QWidget *parent)-
616 : QAbstractScrollArea(*new QTextEditPrivate, parent)-
617{-
618 Q_D(QTextEdit);-
619 d->init(text);-
620}
never executed: end of block
0
621-
622-
623-
624/*!-
625 Destructor.-
626*/-
627QTextEdit::~QTextEdit()-
628{-
629}-
630-
631/*!-
632 Returns the point size of the font of the current format.-
633-
634 \sa setFontFamily(), setCurrentFont(), setFontPointSize()-
635*/-
636qreal QTextEdit::fontPointSize() const-
637{-
638 Q_D(const QTextEdit);-
639 return d->control->textCursor().charFormat().fontPointSize();
never executed: return d->control->textCursor().charFormat().fontPointSize();
0
640}-
641-
642/*!-
643 Returns the font family of the current format.-
644-
645 \sa setFontFamily(), setCurrentFont(), setFontPointSize()-
646*/-
647QString QTextEdit::fontFamily() const-
648{-
649 Q_D(const QTextEdit);-
650 return d->control->textCursor().charFormat().fontFamily();
never executed: return d->control->textCursor().charFormat().fontFamily();
0
651}-
652-
653/*!-
654 Returns the font weight of the current format.-
655-
656 \sa setFontWeight(), setCurrentFont(), setFontPointSize(), QFont::Weight-
657*/-
658int QTextEdit::fontWeight() const-
659{-
660 Q_D(const QTextEdit);-
661 return d->control->textCursor().charFormat().fontWeight();
never executed: return d->control->textCursor().charFormat().fontWeight();
0
662}-
663-
664/*!-
665 Returns \c true if the font of the current format is underlined; otherwise returns-
666 false.-
667-
668 \sa setFontUnderline()-
669*/-
670bool QTextEdit::fontUnderline() const-
671{-
672 Q_D(const QTextEdit);-
673 return d->control->textCursor().charFormat().fontUnderline();
never executed: return d->control->textCursor().charFormat().fontUnderline();
0
674}-
675-
676/*!-
677 Returns \c true if the font of the current format is italic; otherwise returns-
678 false.-
679-
680 \sa setFontItalic()-
681*/-
682bool QTextEdit::fontItalic() const-
683{-
684 Q_D(const QTextEdit);-
685 return d->control->textCursor().charFormat().fontItalic();
never executed: return d->control->textCursor().charFormat().fontItalic();
0
686}-
687-
688/*!-
689 Returns the text color of the current format.-
690-
691 \sa setTextColor()-
692*/-
693QColor QTextEdit::textColor() const-
694{-
695 Q_D(const QTextEdit);-
696 return d->control->textCursor().charFormat().foreground().color();
never executed: return d->control->textCursor().charFormat().foreground().color();
0
697}-
698-
699/*!-
700 \since 4.4-
701-
702 Returns the text background color of the current format.-
703-
704 \sa setTextBackgroundColor()-
705*/-
706QColor QTextEdit::textBackgroundColor() const-
707{-
708 Q_D(const QTextEdit);-
709 return d->control->textCursor().charFormat().background().color();
never executed: return d->control->textCursor().charFormat().background().color();
0
710}-
711-
712/*!-
713 Returns the font of the current format.-
714-
715 \sa setCurrentFont(), setFontFamily(), setFontPointSize()-
716*/-
717QFont QTextEdit::currentFont() const-
718{-
719 Q_D(const QTextEdit);-
720 return d->control->textCursor().charFormat().font();
never executed: return d->control->textCursor().charFormat().font();
0
721}-
722-
723/*!-
724 Sets the alignment of the current paragraph to \a a. Valid-
725 alignments are Qt::AlignLeft, Qt::AlignRight,-
726 Qt::AlignJustify and Qt::AlignCenter (which centers-
727 horizontally).-
728*/-
729void QTextEdit::setAlignment(Qt::Alignment a)-
730{-
731 Q_D(QTextEdit);-
732 QTextBlockFormat fmt;-
733 fmt.setAlignment(a);-
734 QTextCursor cursor = d->control->textCursor();-
735 cursor.mergeBlockFormat(fmt);-
736 d->control->setTextCursor(cursor);-
737}
never executed: end of block
0
738-
739/*!-
740 Returns the alignment of the current paragraph.-
741-
742 \sa setAlignment()-
743*/-
744Qt::Alignment QTextEdit::alignment() const-
745{-
746 Q_D(const QTextEdit);-
747 return d->control->textCursor().blockFormat().alignment();
never executed: return d->control->textCursor().blockFormat().alignment();
0
748}-
749-
750/*!-
751 \property QTextEdit::document-
752 \brief the underlying document of the text editor.-
753-
754 \note The editor \e{does not take ownership of the document} unless it-
755 is the document's parent object. The parent object of the provided document-
756 remains the owner of the object. If the previously assigned document is a-
757 child of the editor then it will be deleted.-
758*/-
759void QTextEdit::setDocument(QTextDocument *document)-
760{-
761 Q_D(QTextEdit);-
762 d->control->setDocument(document);-
763 d->updateDefaultTextOption();-
764 d->relayoutDocument();-
765}
never executed: end of block
0
766-
767QTextDocument *QTextEdit::document() const-
768{-
769 Q_D(const QTextEdit);-
770 return d->control->document();
never executed: return d->control->document();
0
771}-
772-
773/*!-
774 \since 5.2-
775-
776 \property QTextEdit::placeholderText-
777 \brief the editor placeholder text-
778-
779 Setting this property makes the editor display a grayed-out-
780 placeholder text as long as the document() is empty.-
781-
782 By default, this property contains an empty string.-
783-
784 \sa document()-
785*/-
786QString QTextEdit::placeholderText() const-
787{-
788 Q_D(const QTextEdit);-
789 return d->placeholderText;
never executed: return d->placeholderText;
0
790}-
791-
792void QTextEdit::setPlaceholderText(const QString &placeholderText)-
793{-
794 Q_D(QTextEdit);-
795 if (d->placeholderText != placeholderText) {
d->placeholder...laceholderTextDescription
TRUEnever evaluated
FALSEnever evaluated
0
796 d->placeholderText = placeholderText;-
797 if (d->control->document()->isEmpty())
d->control->do...t()->isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
798 d->viewport->update();
never executed: d->viewport->update();
0
799 }
never executed: end of block
0
800}
never executed: end of block
0
801-
802/*!-
803 Sets the visible \a cursor.-
804*/-
805void QTextEdit::setTextCursor(const QTextCursor &cursor)-
806{-
807 doSetTextCursor(cursor);-
808}
never executed: end of block
0
809-
810/*!-
811 \internal-
812-
813 This provides a hook for subclasses to intercept cursor changes.-
814*/-
815-
816void QTextEdit::doSetTextCursor(const QTextCursor &cursor)-
817{-
818 Q_D(QTextEdit);-
819 d->control->setTextCursor(cursor);-
820}
never executed: end of block
0
821-
822/*!-
823 Returns a copy of the QTextCursor that represents the currently visible cursor.-
824 Note that changes on the returned cursor do not affect QTextEdit's cursor; use-
825 setTextCursor() to update the visible cursor.-
826 */-
827QTextCursor QTextEdit::textCursor() const-
828{-
829 Q_D(const QTextEdit);-
830 return d->control->textCursor();
never executed: return d->control->textCursor();
0
831}-
832-
833/*!-
834 Sets the font family of the current format to \a fontFamily.-
835-
836 \sa fontFamily(), setCurrentFont()-
837*/-
838void QTextEdit::setFontFamily(const QString &fontFamily)-
839{-
840 QTextCharFormat fmt;-
841 fmt.setFontFamily(fontFamily);-
842 mergeCurrentCharFormat(fmt);-
843}
never executed: end of block
0
844-
845/*!-
846 Sets the point size of the current format to \a s.-
847-
848 Note that if \a s is zero or negative, the behavior of this-
849 function is not defined.-
850-
851 \sa fontPointSize(), setCurrentFont(), setFontFamily()-
852*/-
853void QTextEdit::setFontPointSize(qreal s)-
854{-
855 QTextCharFormat fmt;-
856 fmt.setFontPointSize(s);-
857 mergeCurrentCharFormat(fmt);-
858}
never executed: end of block
0
859-
860/*!-
861 \fn void QTextEdit::setFontWeight(int weight)-
862-
863 Sets the font weight of the current format to the given \a weight,-
864 where the value used is in the range defined by the QFont::Weight-
865 enum.-
866-
867 \sa fontWeight(), setCurrentFont(), setFontFamily()-
868*/-
869void QTextEdit::setFontWeight(int w)-
870{-
871 QTextCharFormat fmt;-
872 fmt.setFontWeight(w);-
873 mergeCurrentCharFormat(fmt);-
874}
never executed: end of block
0
875-
876/*!-
877 If \a underline is true, sets the current format to underline;-
878 otherwise sets the current format to non-underline.-
879-
880 \sa fontUnderline()-
881*/-
882void QTextEdit::setFontUnderline(bool underline)-
883{-
884 QTextCharFormat fmt;-
885 fmt.setFontUnderline(underline);-
886 mergeCurrentCharFormat(fmt);-
887}
never executed: end of block
0
888-
889/*!-
890 If \a italic is true, sets the current format to italic;-
891 otherwise sets the current format to non-italic.-
892-
893 \sa fontItalic()-
894*/-
895void QTextEdit::setFontItalic(bool italic)-
896{-
897 QTextCharFormat fmt;-
898 fmt.setFontItalic(italic);-
899 mergeCurrentCharFormat(fmt);-
900}
never executed: end of block
0
901-
902/*!-
903 Sets the text color of the current format to \a c.-
904-
905 \sa textColor()-
906*/-
907void QTextEdit::setTextColor(const QColor &c)-
908{-
909 QTextCharFormat fmt;-
910 fmt.setForeground(QBrush(c));-
911 mergeCurrentCharFormat(fmt);-
912}
never executed: end of block
0
913-
914/*!-
915 \since 4.4-
916-
917 Sets the text background color of the current format to \a c.-
918-
919 \sa textBackgroundColor()-
920*/-
921void QTextEdit::setTextBackgroundColor(const QColor &c)-
922{-
923 QTextCharFormat fmt;-
924 fmt.setBackground(QBrush(c));-
925 mergeCurrentCharFormat(fmt);-
926}
never executed: end of block
0
927-
928/*!-
929 Sets the font of the current format to \a f.-
930-
931 \sa currentFont(), setFontPointSize(), setFontFamily()-
932*/-
933void QTextEdit::setCurrentFont(const QFont &f)-
934{-
935 QTextCharFormat fmt;-
936 fmt.setFont(f);-
937 mergeCurrentCharFormat(fmt);-
938}
never executed: end of block
0
939-
940/*!-
941 \since 4.2-
942-
943 Undoes the last operation.-
944-
945 If there is no operation to undo, i.e. there is no undo step in-
946 the undo/redo history, nothing happens.-
947-
948 \sa redo()-
949*/-
950void QTextEdit::undo()-
951{-
952 Q_D(QTextEdit);-
953 d->control->undo();-
954}
never executed: end of block
0
955-
956void QTextEdit::redo()-
957{-
958 Q_D(QTextEdit);-
959 d->control->redo();-
960}
never executed: end of block
0
961-
962/*!-
963 \fn void QTextEdit::redo()-
964 \since 4.2-
965-
966 Redoes the last operation.-
967-
968 If there is no operation to redo, i.e. there is no redo step in-
969 the undo/redo history, nothing happens.-
970-
971 \sa undo()-
972*/-
973-
974#ifndef QT_NO_CLIPBOARD-
975/*!-
976 Copies the selected text to the clipboard and deletes it from-
977 the text edit.-
978-
979 If there is no selected text nothing happens.-
980-
981 \sa copy(), paste()-
982*/-
983-
984void QTextEdit::cut()-
985{-
986 Q_D(QTextEdit);-
987 d->control->cut();-
988}
never executed: end of block
0
989-
990/*!-
991 Copies any selected text to the clipboard.-
992-
993 \sa copyAvailable()-
994*/-
995-
996void QTextEdit::copy()-
997{-
998 Q_D(QTextEdit);-
999 d->control->copy();-
1000}
never executed: end of block
0
1001-
1002/*!-
1003 Pastes the text from the clipboard into the text edit at the-
1004 current cursor position.-
1005-
1006 If there is no text in the clipboard nothing happens.-
1007-
1008 To change the behavior of this function, i.e. to modify what-
1009 QTextEdit can paste and how it is being pasted, reimplement the-
1010 virtual canInsertFromMimeData() and insertFromMimeData()-
1011 functions.-
1012-
1013 \sa cut(), copy()-
1014*/-
1015-
1016void QTextEdit::paste()-
1017{-
1018 Q_D(QTextEdit);-
1019 d->control->paste();-
1020}
never executed: end of block
0
1021#endif-
1022-
1023/*!-
1024 Deletes all the text in the text edit.-
1025-
1026 Note that the undo/redo history is cleared by this function.-
1027-
1028 \sa cut(), setPlainText(), setHtml()-
1029*/-
1030void QTextEdit::clear()-
1031{-
1032 Q_D(QTextEdit);-
1033 // clears and sets empty content-
1034 d->control->clear();-
1035}
never executed: end of block
0
1036-
1037-
1038/*!-
1039 Selects all text.-
1040-
1041 \sa copy(), cut(), textCursor()-
1042 */-
1043void QTextEdit::selectAll()-
1044{-
1045 Q_D(QTextEdit);-
1046 d->control->selectAll();-
1047}
never executed: end of block
0
1048-
1049/*! \internal-
1050*/-
1051bool QTextEdit::event(QEvent *e)-
1052{-
1053 Q_D(QTextEdit);-
1054#ifndef QT_NO_CONTEXTMENU-
1055 if (e->type() == QEvent::ContextMenu
e->type() == Q...t::ContextMenuDescription
TRUEnever evaluated
FALSEnever evaluated
0
1056 && static_cast<QContextMenuEvent *>(e)->reason() == QContextMenuEvent::Keyboard) {
static_cast<QC...vent::KeyboardDescription
TRUEnever evaluated
FALSEnever evaluated
0
1057 Q_D(QTextEdit);-
1058 ensureCursorVisible();-
1059 const QPoint cursorPos = cursorRect().center();-
1060 QContextMenuEvent ce(QContextMenuEvent::Keyboard, cursorPos, d->viewport->mapToGlobal(cursorPos));-
1061 ce.setAccepted(e->isAccepted());-
1062 const bool result = QAbstractScrollArea::event(&ce);-
1063 e->setAccepted(ce.isAccepted());-
1064 return result;
never executed: return result;
0
1065 } else if (e->type() == QEvent::ShortcutOverride
e->type() == Q...ortcutOverrideDescription
TRUEnever evaluated
FALSEnever evaluated
0
1066 || e->type() == QEvent::ToolTip) {
e->type() == QEvent::ToolTipDescription
TRUEnever evaluated
FALSEnever evaluated
0
1067 d->sendControlEvent(e);-
1068 }
never executed: end of block
0
1069#else-
1070 Q_UNUSED(d)-
1071#endif // QT_NO_CONTEXTMENU-
1072#ifdef QT_KEYPAD_NAVIGATION-
1073 if (e->type() == QEvent::EnterEditFocus || e->type() == QEvent::LeaveEditFocus) {-
1074 if (QApplication::keypadNavigationEnabled())-
1075 d->sendControlEvent(e);-
1076 }-
1077#endif-
1078 return QAbstractScrollArea::event(e);
never executed: return QAbstractScrollArea::event(e);
0
1079}-
1080-
1081/*! \internal-
1082*/-
1083-
1084void QTextEdit::timerEvent(QTimerEvent *e)-
1085{-
1086 Q_D(QTextEdit);-
1087 if (e->timerId() == d->autoScrollTimer.timerId()) {
e->timerId() =...imer.timerId()Description
TRUEnever evaluated
FALSEnever evaluated
0
1088 QRect visible = d->viewport->rect();-
1089 QPoint pos;-
1090 if (d->inDrag) {
d->inDragDescription
TRUEnever evaluated
FALSEnever evaluated
0
1091 pos = d->autoScrollDragPos;-
1092 visible.adjust(qMin(visible.width()/3,20), qMin(visible.height()/3,20),-
1093 -qMin(visible.width()/3,20), -qMin(visible.height()/3,20));-
1094 } else {
never executed: end of block
0
1095 const QPoint globalPos = QCursor::pos();-
1096 pos = d->viewport->mapFromGlobal(globalPos);-
1097 QMouseEvent ev(QEvent::MouseMove, pos, mapTo(topLevelWidget(), pos), globalPos, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);-
1098 mouseMoveEvent(&ev);-
1099 }
never executed: end of block
0
1100 int deltaY = qMax(pos.y() - visible.top(), visible.bottom() - pos.y()) - visible.height();-
1101 int deltaX = qMax(pos.x() - visible.left(), visible.right() - pos.x()) - visible.width();-
1102 int delta = qMax(deltaX, deltaY);-
1103 if (delta >= 0) {
delta >= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1104 if (delta < 7)
delta < 7Description
TRUEnever evaluated
FALSEnever evaluated
0
1105 delta = 7;
never executed: delta = 7;
0
1106 int timeout = 4900 / (delta * delta);-
1107 d->autoScrollTimer.start(timeout, this);-
1108-
1109 if (deltaY > 0)
deltaY > 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1110 d->vbar->triggerAction(pos.y() < visible.center().y() ?
never executed: d->vbar->triggerAction(pos.y() < visible.center().y() ? QAbstractSlider::SliderSingleStepSub : QAbstractSlider::SliderSingleStepAdd);
0
1111 QAbstractSlider::SliderSingleStepSub
never executed: d->vbar->triggerAction(pos.y() < visible.center().y() ? QAbstractSlider::SliderSingleStepSub : QAbstractSlider::SliderSingleStepAdd);
0
1112 : QAbstractSlider::SliderSingleStepAdd);
never executed: d->vbar->triggerAction(pos.y() < visible.center().y() ? QAbstractSlider::SliderSingleStepSub : QAbstractSlider::SliderSingleStepAdd);
0
1113 if (deltaX > 0)
deltaX > 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1114 d->hbar->triggerAction(pos.x() < visible.center().x() ?
never executed: d->hbar->triggerAction(pos.x() < visible.center().x() ? QAbstractSlider::SliderSingleStepSub : QAbstractSlider::SliderSingleStepAdd);
0
1115 QAbstractSlider::SliderSingleStepSub
never executed: d->hbar->triggerAction(pos.x() < visible.center().x() ? QAbstractSlider::SliderSingleStepSub : QAbstractSlider::SliderSingleStepAdd);
0
1116 : QAbstractSlider::SliderSingleStepAdd);
never executed: d->hbar->triggerAction(pos.x() < visible.center().x() ? QAbstractSlider::SliderSingleStepSub : QAbstractSlider::SliderSingleStepAdd);
0
1117 }
never executed: end of block
0
1118 }
never executed: end of block
0
1119#ifdef QT_KEYPAD_NAVIGATION-
1120 else if (e->timerId() == d->deleteAllTimer.timerId()) {-
1121 d->deleteAllTimer.stop();-
1122 clear();-
1123 }-
1124#endif-
1125}
never executed: end of block
0
1126-
1127/*!-
1128 Changes the text of the text edit to the string \a text.-
1129 Any previous text is removed.-
1130-
1131 \a text is interpreted as plain text.-
1132-
1133 Note that the undo/redo history is cleared by this function.-
1134-
1135 \sa toPlainText()-
1136*/-
1137-
1138void QTextEdit::setPlainText(const QString &text)-
1139{-
1140 Q_D(QTextEdit);-
1141 d->control->setPlainText(text);-
1142 d->preferRichText = false;-
1143}
never executed: end of block
0
1144-
1145/*!-
1146 QString QTextEdit::toPlainText() const-
1147-
1148 Returns the text of the text edit as plain text.-
1149-
1150 \sa QTextEdit::setPlainText()-
1151 */-
1152QString QTextEdit::toPlainText() const-
1153{-
1154 Q_D(const QTextEdit);-
1155 return d->control->toPlainText();
never executed: return d->control->toPlainText();
0
1156}-
1157-
1158/*!-
1159 \property QTextEdit::html-
1160-
1161 This property provides an HTML interface to the text of the text edit.-
1162-
1163 toHtml() returns the text of the text edit as html.-
1164-
1165 setHtml() changes the text of the text edit. Any previous text is-
1166 removed and the undo/redo history is cleared. The input text is-
1167 interpreted as rich text in html format.-
1168-
1169 \note It is the responsibility of the caller to make sure that the-
1170 text is correctly decoded when a QString containing HTML is created-
1171 and passed to setHtml().-
1172-
1173 By default, for a newly-created, empty document, this property contains-
1174 text to describe an HTML 4.0 document with no body text.-
1175-
1176 \sa {Supported HTML Subset}, plainText-
1177*/-
1178-
1179#ifndef QT_NO_TEXTHTMLPARSER-
1180void QTextEdit::setHtml(const QString &text)-
1181{-
1182 Q_D(QTextEdit);-
1183 d->control->setHtml(text);-
1184 d->preferRichText = true;-
1185}
never executed: end of block
0
1186-
1187QString QTextEdit::toHtml() const-
1188{-
1189 Q_D(const QTextEdit);-
1190 return d->control->toHtml();
never executed: return d->control->toHtml();
0
1191}-
1192#endif-
1193-
1194-
1195/*! \reimp-
1196*/-
1197void QTextEdit::keyPressEvent(QKeyEvent *e)-
1198{-
1199 Q_D(QTextEdit);-
1200-
1201#ifdef QT_KEYPAD_NAVIGATION-
1202 switch (e->key()) {-
1203 case Qt::Key_Select:-
1204 if (QApplication::keypadNavigationEnabled()) {-
1205 // code assumes linksaccessible + editable isn't meaningful-
1206 if (d->control->textInteractionFlags() & Qt::TextEditable) {-
1207 setEditFocus(!hasEditFocus());-
1208 } else {-
1209 if (!hasEditFocus())-
1210 setEditFocus(true);-
1211 else {-
1212 QTextCursor cursor = d->control->textCursor();-
1213 QTextCharFormat charFmt = cursor.charFormat();-
1214 if (!(d->control->textInteractionFlags() & Qt::LinksAccessibleByKeyboard)-
1215 || !cursor.hasSelection() || charFmt.anchorHref().isEmpty()) {-
1216 e->accept();-
1217 return;-
1218 }-
1219 }-
1220 }-
1221 }-
1222 break;-
1223 case Qt::Key_Back:-
1224 case Qt::Key_No:-
1225 if (!QApplication::keypadNavigationEnabled()-
1226 || (QApplication::keypadNavigationEnabled() && !hasEditFocus())) {-
1227 e->ignore();-
1228 return;-
1229 }-
1230 break;-
1231 default:-
1232 if (QApplication::keypadNavigationEnabled()) {-
1233 if (!hasEditFocus() && !(e->modifiers() & Qt::ControlModifier)) {-
1234 if (e->text()[0].isPrint())-
1235 setEditFocus(true);-
1236 else {-
1237 e->ignore();-
1238 return;-
1239 }-
1240 }-
1241 }-
1242 break;-
1243 }-
1244#endif-
1245#ifndef QT_NO_SHORTCUT-
1246-
1247 Qt::TextInteractionFlags tif = d->control->textInteractionFlags();-
1248-
1249 if (tif & Qt::TextSelectableByKeyboard){
tif & Qt::Text...ableByKeyboardDescription
TRUEnever evaluated
FALSEnever evaluated
0
1250 if (e == QKeySequence::SelectPreviousPage) {
e == QKeySeque...ctPreviousPageDescription
TRUEnever evaluated
FALSEnever evaluated
0
1251 e->accept();-
1252 d->pageUpDown(QTextCursor::Up, QTextCursor::KeepAnchor);-
1253 return;
never executed: return;
0
1254 } else if (e ==QKeySequence::SelectNextPage) {
e ==QKeySequen...SelectNextPageDescription
TRUEnever evaluated
FALSEnever evaluated
0
1255 e->accept();-
1256 d->pageUpDown(QTextCursor::Down, QTextCursor::KeepAnchor);-
1257 return;
never executed: return;
0
1258 }-
1259 }
never executed: end of block
0
1260 if (tif & (Qt::TextSelectableByKeyboard | Qt::TextEditable)) {
tif & (Qt::Tex...:TextEditable)Description
TRUEnever evaluated
FALSEnever evaluated
0
1261 if (e == QKeySequence::MoveToPreviousPage) {
e == QKeySeque...ToPreviousPageDescription
TRUEnever evaluated
FALSEnever evaluated
0
1262 e->accept();-
1263 d->pageUpDown(QTextCursor::Up, QTextCursor::MoveAnchor);-
1264 return;
never executed: return;
0
1265 } else if (e == QKeySequence::MoveToNextPage) {
e == QKeySeque...MoveToNextPageDescription
TRUEnever evaluated
FALSEnever evaluated
0
1266 e->accept();-
1267 d->pageUpDown(QTextCursor::Down, QTextCursor::MoveAnchor);-
1268 return;
never executed: return;
0
1269 }-
1270 }
never executed: end of block
0
1271-
1272 if (!(tif & Qt::TextEditable)) {
!(tif & Qt::TextEditable)Description
TRUEnever evaluated
FALSEnever evaluated
0
1273 switch (e->key()) {-
1274 case Qt::Key_Space:
never executed: case Qt::Key_Space:
0
1275 e->accept();-
1276 if (e->modifiers() & Qt::ShiftModifier)
e->modifiers()...:ShiftModifierDescription
TRUEnever evaluated
FALSEnever evaluated
0
1277 d->vbar->triggerAction(QAbstractSlider::SliderPageStepSub);
never executed: d->vbar->triggerAction(QAbstractSlider::SliderPageStepSub);
0
1278 else-
1279 d->vbar->triggerAction(QAbstractSlider::SliderPageStepAdd);
never executed: d->vbar->triggerAction(QAbstractSlider::SliderPageStepAdd);
0
1280 break;
never executed: break;
0
1281 default:
never executed: default:
0
1282 d->sendControlEvent(e);-
1283 if (!e->isAccepted() && e->modifiers() == Qt::NoModifier) {
!e->isAccepted()Description
TRUEnever evaluated
FALSEnever evaluated
e->modifiers()...Qt::NoModifierDescription
TRUEnever evaluated
FALSEnever evaluated
0
1284 if (e->key() == Qt::Key_Home) {
e->key() == Qt::Key_HomeDescription
TRUEnever evaluated
FALSEnever evaluated
0
1285 d->vbar->triggerAction(QAbstractSlider::SliderToMinimum);-
1286 e->accept();-
1287 } else if (e->key() == Qt::Key_End) {
never executed: end of block
e->key() == Qt::Key_EndDescription
TRUEnever evaluated
FALSEnever evaluated
0
1288 d->vbar->triggerAction(QAbstractSlider::SliderToMaximum);-
1289 e->accept();-
1290 }
never executed: end of block
0
1291 }
never executed: end of block
0
1292 if (!e->isAccepted()) {
!e->isAccepted()Description
TRUEnever evaluated
FALSEnever evaluated
0
1293 QAbstractScrollArea::keyPressEvent(e);-
1294 }
never executed: end of block
0
1295 }
never executed: end of block
0
1296 return;
never executed: return;
0
1297 }-
1298#endif // QT_NO_SHORTCUT-
1299-
1300 {-
1301 QTextCursor cursor = d->control->textCursor();-
1302 const QString text = e->text();-
1303 if (cursor.atBlockStart()
cursor.atBlockStart()Description
TRUEnever evaluated
FALSEnever evaluated
0
1304 && (d->autoFormatting & AutoBulletList)
(d->autoFormat...utoBulletList)Description
TRUEnever evaluated
FALSEnever evaluated
0
1305 && (text.length() == 1)
(text.length() == 1)Description
TRUEnever evaluated
FALSEnever evaluated
0
1306 && (text.at(0) == QLatin1Char('-') || text.at(0) == QLatin1Char('*'))
text.at(0) == QLatin1Char('-')Description
TRUEnever evaluated
FALSEnever evaluated
text.at(0) == QLatin1Char('*')Description
TRUEnever evaluated
FALSEnever evaluated
0
1307 && (!cursor.currentList())) {
(!cursor.currentList())Description
TRUEnever evaluated
FALSEnever evaluated
0
1308-
1309 d->createAutoBulletList();-
1310 e->accept();-
1311 return;
never executed: return;
0
1312 }-
1313 }-
1314-
1315 d->sendControlEvent(e);-
1316#ifdef QT_KEYPAD_NAVIGATION-
1317 if (!e->isAccepted()) {-
1318 switch (e->key()) {-
1319 case Qt::Key_Up:-
1320 case Qt::Key_Down:-
1321 if (QApplication::keypadNavigationEnabled()) {-
1322 // Cursor position didn't change, so we want to leave-
1323 // these keys to change focus.-
1324 e->ignore();-
1325 return;-
1326 }-
1327 break;-
1328 case Qt::Key_Back:-
1329 if (!e->isAutoRepeat()) {-
1330 if (QApplication::keypadNavigationEnabled()) {-
1331 if (document()->isEmpty() || !(d->control->textInteractionFlags() & Qt::TextEditable)) {-
1332 setEditFocus(false);-
1333 e->accept();-
1334 } else if (!d->deleteAllTimer.isActive()) {-
1335 e->accept();-
1336 d->deleteAllTimer.start(750, this);-
1337 }-
1338 } else {-
1339 e->ignore();-
1340 return;-
1341 }-
1342 }-
1343 break;-
1344 default: break;-
1345 }-
1346 }-
1347#endif-
1348}
never executed: end of block
0
1349-
1350/*! \reimp-
1351*/-
1352void QTextEdit::keyReleaseEvent(QKeyEvent *e)-
1353{-
1354#ifdef QT_KEYPAD_NAVIGATION-
1355 Q_D(QTextEdit);-
1356 if (QApplication::keypadNavigationEnabled()) {-
1357 if (!e->isAutoRepeat() && e->key() == Qt::Key_Back-
1358 && d->deleteAllTimer.isActive()) {-
1359 d->deleteAllTimer.stop();-
1360 QTextCursor cursor = d->control->textCursor();-
1361 QTextBlockFormat blockFmt = cursor.blockFormat();-
1362-
1363 QTextList *list = cursor.currentList();-
1364 if (list && cursor.atBlockStart()) {-
1365 list->remove(cursor.block());-
1366 } else if (cursor.atBlockStart() && blockFmt.indent() > 0) {-
1367 blockFmt.setIndent(blockFmt.indent() - 1);-
1368 cursor.setBlockFormat(blockFmt);-
1369 } else {-
1370 cursor.deletePreviousChar();-
1371 }-
1372 setTextCursor(cursor);-
1373 e->accept();-
1374 return;-
1375 }-
1376 }-
1377#endif-
1378 e->ignore();-
1379}
never executed: end of block
0
1380-
1381/*!-
1382 Loads the resource specified by the given \a type and \a name.-
1383-
1384 This function is an extension of QTextDocument::loadResource().-
1385-
1386 \sa QTextDocument::loadResource()-
1387*/-
1388QVariant QTextEdit::loadResource(int type, const QUrl &name)-
1389{-
1390 Q_UNUSED(type);-
1391 Q_UNUSED(name);-
1392 return QVariant();
never executed: return QVariant();
0
1393}-
1394-
1395/*! \reimp-
1396*/-
1397void QTextEdit::resizeEvent(QResizeEvent *e)-
1398{-
1399 Q_D(QTextEdit);-
1400-
1401 if (d->lineWrap == NoWrap) {
d->lineWrap == NoWrapDescription
TRUEnever evaluated
FALSEnever evaluated
0
1402 QTextDocument *doc = d->control->document();-
1403 QVariant alignmentProperty = doc->documentLayout()->property("contentHasAlignment");-
1404-
1405 if (!doc->pageSize().isNull()
!doc->pageSize().isNull()Description
TRUEnever evaluated
FALSEnever evaluated
0
1406 && alignmentProperty.type() == QVariant::Bool
alignmentPrope...QVariant::BoolDescription
TRUEnever evaluated
FALSEnever evaluated
0
1407 && !alignmentProperty.toBool()) {
!alignmentProperty.toBool()Description
TRUEnever evaluated
FALSEnever evaluated
0
1408-
1409 d->_q_adjustScrollbars();-
1410 return;
never executed: return;
0
1411 }-
1412 }
never executed: end of block
0
1413-
1414 if (d->lineWrap != FixedPixelWidth
d->lineWrap != FixedPixelWidthDescription
TRUEnever evaluated
FALSEnever evaluated
0
1415 && e->oldSize().width() != e->size().width())
e->oldSize().w...size().width()Description
TRUEnever evaluated
FALSEnever evaluated
0
1416 d->relayoutDocument();
never executed: d->relayoutDocument();
0
1417 else-
1418 d->_q_adjustScrollbars();
never executed: d->_q_adjustScrollbars();
0
1419}-
1420-
1421void QTextEditPrivate::relayoutDocument()-
1422{-
1423 QTextDocument *doc = control->document();-
1424 QAbstractTextDocumentLayout *layout = doc->documentLayout();-
1425-
1426 if (QTextDocumentLayout *tlayout = qobject_cast<QTextDocumentLayout *>(layout)) {
QTextDocumentL...out *>(layout)Description
TRUEnever evaluated
FALSEnever evaluated
0
1427 if (lineWrap == QTextEdit::FixedColumnWidth)
lineWrap == QT...xedColumnWidthDescription
TRUEnever evaluated
FALSEnever evaluated
0
1428 tlayout->setFixedColumnWidth(lineWrapColumnOrWidth);
never executed: tlayout->setFixedColumnWidth(lineWrapColumnOrWidth);
0
1429 else-
1430 tlayout->setFixedColumnWidth(-1);
never executed: tlayout->setFixedColumnWidth(-1);
0
1431 }-
1432-
1433 QTextDocumentLayout *tlayout = qobject_cast<QTextDocumentLayout *>(layout);-
1434 QSize lastUsedSize;-
1435 if (tlayout)
tlayoutDescription
TRUEnever evaluated
FALSEnever evaluated
0
1436 lastUsedSize = tlayout->dynamicDocumentSize().toSize();
never executed: lastUsedSize = tlayout->dynamicDocumentSize().toSize();
0
1437 else-
1438 lastUsedSize = layout->documentSize().toSize();
never executed: lastUsedSize = layout->documentSize().toSize();
0
1439-
1440 // ignore calls to _q_adjustScrollbars caused by an emission of the-
1441 // usedSizeChanged() signal in the layout, as we're calling it-
1442 // later on our own anyway (or deliberately not) .-
1443 const bool oldIgnoreScrollbarAdjustment = ignoreAutomaticScrollbarAdjustment;-
1444 ignoreAutomaticScrollbarAdjustment = true;-
1445-
1446 int width = viewport->width();-
1447 if (lineWrap == QTextEdit::FixedPixelWidth)
lineWrap == QT...ixedPixelWidthDescription
TRUEnever evaluated
FALSEnever evaluated
0
1448 width = lineWrapColumnOrWidth;
never executed: width = lineWrapColumnOrWidth;
0
1449 else if (lineWrap == QTextEdit::NoWrap) {
lineWrap == QTextEdit::NoWrapDescription
TRUEnever evaluated
FALSEnever evaluated
0
1450 QVariant alignmentProperty = doc->documentLayout()->property("contentHasAlignment");-
1451 if (alignmentProperty.type() == QVariant::Bool && !alignmentProperty.toBool()) {
alignmentPrope...QVariant::BoolDescription
TRUEnever evaluated
FALSEnever evaluated
!alignmentProperty.toBool()Description
TRUEnever evaluated
FALSEnever evaluated
0
1452-
1453 width = 0;-
1454 }
never executed: end of block
0
1455 }
never executed: end of block
0
1456-
1457 doc->setPageSize(QSize(width, -1));-
1458 if (tlayout)
tlayoutDescription
TRUEnever evaluated
FALSEnever evaluated
0
1459 tlayout->ensureLayouted(verticalOffset() + viewport->height());
never executed: tlayout->ensureLayouted(verticalOffset() + viewport->height());
0
1460-
1461 ignoreAutomaticScrollbarAdjustment = oldIgnoreScrollbarAdjustment;-
1462-
1463 QSize usedSize;-
1464 if (tlayout)
tlayoutDescription
TRUEnever evaluated
FALSEnever evaluated
0
1465 usedSize = tlayout->dynamicDocumentSize().toSize();
never executed: usedSize = tlayout->dynamicDocumentSize().toSize();
0
1466 else-
1467 usedSize = layout->documentSize().toSize();
never executed: usedSize = layout->documentSize().toSize();
0
1468-
1469 // this is an obscure situation in the layout that can happen:-
1470 // if a character at the end of a line is the tallest one and therefore-
1471 // influencing the total height of the line and the line right below it-
1472 // is always taller though, then it can happen that if due to line breaking-
1473 // that tall character wraps into the lower line the document not only shrinks-
1474 // horizontally (causing the character to wrap in the first place) but also-
1475 // vertically, because the original line is now smaller and the one below kept-
1476 // its size. So a layout with less width _can_ take up less vertical space, too.-
1477 // If the wider case causes a vertical scroll bar to appear and the narrower one-
1478 // (narrower because the vertical scroll bar takes up horizontal space)) to disappear-
1479 // again then we have an endless loop, as _q_adjustScrollBars sets new ranges on the-
1480 // scroll bars, the QAbstractScrollArea will find out about it and try to show/hide-
1481 // the scroll bars again. That's why we try to detect this case here and break out.-
1482 //-
1483 // (if you change this please also check the layoutingLoop() testcase in-
1484 // QTextEdit's autotests)-
1485 if (lastUsedSize.isValid()
lastUsedSize.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
1486 && !vbar->isHidden()
!vbar->isHidden()Description
TRUEnever evaluated
FALSEnever evaluated
0
1487 && viewport->width() < lastUsedSize.width()
viewport->widt...edSize.width()Description
TRUEnever evaluated
FALSEnever evaluated
0
1488 && usedSize.height() < lastUsedSize.height()
usedSize.heigh...dSize.height()Description
TRUEnever evaluated
FALSEnever evaluated
0
1489 && usedSize.height() <= viewport->height())
usedSize.heigh...port->height()Description
TRUEnever evaluated
FALSEnever evaluated
0
1490 return;
never executed: return;
0
1491-
1492 _q_adjustScrollbars();-
1493}
never executed: end of block
0
1494-
1495void QTextEditPrivate::paint(QPainter *p, QPaintEvent *e)-
1496{-
1497 const int xOffset = horizontalOffset();-
1498 const int yOffset = verticalOffset();-
1499-
1500 QRect r = e->rect();-
1501 p->translate(-xOffset, -yOffset);-
1502 r.translate(xOffset, yOffset);-
1503-
1504 QTextDocument *doc = control->document();-
1505 QTextDocumentLayout *layout = qobject_cast<QTextDocumentLayout *>(doc->documentLayout());-
1506-
1507 // the layout might need to expand the root frame to-
1508 // the viewport if NoWrap is set-
1509 if (layout)
layoutDescription
TRUEnever evaluated
FALSEnever evaluated
0
1510 layout->setViewport(viewport->rect());
never executed: layout->setViewport(viewport->rect());
0
1511-
1512 control->drawContents(p, r, q_func());-
1513-
1514 if (layout)
layoutDescription
TRUEnever evaluated
FALSEnever evaluated
0
1515 layout->setViewport(QRect());
never executed: layout->setViewport(QRect());
0
1516-
1517 if (!placeholderText.isEmpty() && doc->isEmpty() && !control->isPreediting()) {
!placeholderText.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
doc->isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
!control->isPreediting()Description
TRUEnever evaluated
FALSEnever evaluated
0
1518 QColor col = control->palette().text().color();-
1519 col.setAlpha(128);-
1520 p->setPen(col);-
1521 const int margin = int(doc->documentMargin());-
1522 p->drawText(viewport->rect().adjusted(margin, margin, -margin, -margin), Qt::AlignTop | Qt::TextWordWrap, placeholderText);-
1523 }
never executed: end of block
0
1524}
never executed: end of block
0
1525-
1526/*! \fn void QTextEdit::paintEvent(QPaintEvent *event)-
1527-
1528This event handler can be reimplemented in a subclass to receive paint events passed in \a event.-
1529It is usually unnecessary to reimplement this function in a subclass of QTextEdit.-
1530-
1531\warning The underlying text document must not be modified from within a reimplementation-
1532of this function.-
1533*/-
1534void QTextEdit::paintEvent(QPaintEvent *e)-
1535{-
1536 Q_D(QTextEdit);-
1537 QPainter p(d->viewport);-
1538 d->paint(&p, e);-
1539}
never executed: end of block
0
1540-
1541void QTextEditPrivate::_q_currentCharFormatChanged(const QTextCharFormat &fmt)-
1542{-
1543 Q_Q(QTextEdit);-
1544 emit q->currentCharFormatChanged(fmt);-
1545}
never executed: end of block
0
1546-
1547void QTextEditPrivate::updateDefaultTextOption()-
1548{-
1549 QTextDocument *doc = control->document();-
1550-
1551 QTextOption opt = doc->defaultTextOption();-
1552 QTextOption::WrapMode oldWrapMode = opt.wrapMode();-
1553-
1554 if (lineWrap == QTextEdit::NoWrap)
lineWrap == QTextEdit::NoWrapDescription
TRUEnever evaluated
FALSEnever evaluated
0
1555 opt.setWrapMode(QTextOption::NoWrap);
never executed: opt.setWrapMode(QTextOption::NoWrap);
0
1556 else-
1557 opt.setWrapMode(wordWrap);
never executed: opt.setWrapMode(wordWrap);
0
1558-
1559 if (opt.wrapMode() != oldWrapMode)
opt.wrapMode() != oldWrapModeDescription
TRUEnever evaluated
FALSEnever evaluated
0
1560 doc->setDefaultTextOption(opt);
never executed: doc->setDefaultTextOption(opt);
0
1561}
never executed: end of block
0
1562-
1563/*! \reimp-
1564*/-
1565void QTextEdit::mousePressEvent(QMouseEvent *e)-
1566{-
1567 Q_D(QTextEdit);-
1568#ifdef QT_KEYPAD_NAVIGATION-
1569 if (QApplication::keypadNavigationEnabled() && !hasEditFocus())-
1570 setEditFocus(true);-
1571#endif-
1572 d->sendControlEvent(e);-
1573}
never executed: end of block
0
1574-
1575/*! \reimp-
1576*/-
1577void QTextEdit::mouseMoveEvent(QMouseEvent *e)-
1578{-
1579 Q_D(QTextEdit);-
1580 d->inDrag = false; // paranoia-
1581 const QPoint pos = e->pos();-
1582 d->sendControlEvent(e);-
1583 if (!(e->buttons() & Qt::LeftButton))
!(e->buttons()...t::LeftButton)Description
TRUEnever evaluated
FALSEnever evaluated
0
1584 return;
never executed: return;
0
1585 if (e->source() == Qt::MouseEventNotSynthesized) {
e->source() ==...NotSynthesizedDescription
TRUEnever evaluated
FALSEnever evaluated
0
1586 const QRect visible = d->viewport->rect();-
1587 if (visible.contains(pos))
visible.contains(pos)Description
TRUEnever evaluated
FALSEnever evaluated
0
1588 d->autoScrollTimer.stop();
never executed: d->autoScrollTimer.stop();
0
1589 else if (!d->autoScrollTimer.isActive())
!d->autoScrollTimer.isActive()Description
TRUEnever evaluated
FALSEnever evaluated
0
1590 d->autoScrollTimer.start(100, this);
never executed: d->autoScrollTimer.start(100, this);
0
1591 }
never executed: end of block
0
1592}
never executed: end of block
0
1593-
1594/*! \reimp-
1595*/-
1596void QTextEdit::mouseReleaseEvent(QMouseEvent *e)-
1597{-
1598 Q_D(QTextEdit);-
1599 d->sendControlEvent(e);-
1600 if (e->source() == Qt::MouseEventNotSynthesized && d->autoScrollTimer.isActive()) {
e->source() ==...NotSynthesizedDescription
TRUEnever evaluated
FALSEnever evaluated
d->autoScrollTimer.isActive()Description
TRUEnever evaluated
FALSEnever evaluated
0
1601 d->autoScrollTimer.stop();-
1602 ensureCursorVisible();-
1603 }
never executed: end of block
0
1604 if (!isReadOnly() && rect().contains(e->pos()))
!isReadOnly()Description
TRUEnever evaluated
FALSEnever evaluated
rect().contains(e->pos())Description
TRUEnever evaluated
FALSEnever evaluated
0
1605 d->handleSoftwareInputPanel(e->button(), d->clickCausedFocus);
never executed: d->handleSoftwareInputPanel(e->button(), d->clickCausedFocus);
0
1606 d->clickCausedFocus = 0;-
1607}
never executed: end of block
0
1608-
1609/*! \reimp-
1610*/-
1611void QTextEdit::mouseDoubleClickEvent(QMouseEvent *e)-
1612{-
1613 Q_D(QTextEdit);-
1614 d->sendControlEvent(e);-
1615}
never executed: end of block
0
1616-
1617/*! \reimp-
1618*/-
1619bool QTextEdit::focusNextPrevChild(bool next)-
1620{-
1621 Q_D(const QTextEdit);-
1622 if (!d->tabChangesFocus && d->control->textInteractionFlags() & Qt::TextEditable)
!d->tabChangesFocusDescription
TRUEnever evaluated
FALSEnever evaluated
d->control->te...::TextEditableDescription
TRUEnever evaluated
FALSEnever evaluated
0
1623 return false;
never executed: return false;
0
1624 return QAbstractScrollArea::focusNextPrevChild(next);
never executed: return QAbstractScrollArea::focusNextPrevChild(next);
0
1625}-
1626-
1627#ifndef QT_NO_CONTEXTMENU-
1628/*!-
1629 \fn void QTextEdit::contextMenuEvent(QContextMenuEvent *event)-
1630-
1631 Shows the standard context menu created with createStandardContextMenu().-
1632-
1633 If you do not want the text edit to have a context menu, you can set-
1634 its \l contextMenuPolicy to Qt::NoContextMenu. If you want to-
1635 customize the context menu, reimplement this function. If you want-
1636 to extend the standard context menu, reimplement this function, call-
1637 createStandardContextMenu() and extend the menu returned.-
1638-
1639 Information about the event is passed in the \a event object.-
1640-
1641 \snippet code/src_gui_widgets_qtextedit.cpp 0-
1642*/-
1643void QTextEdit::contextMenuEvent(QContextMenuEvent *e)-
1644{-
1645 Q_D(QTextEdit);-
1646 d->sendControlEvent(e);-
1647}
never executed: end of block
0
1648#endif // QT_NO_CONTEXTMENU-
1649-
1650#ifndef QT_NO_DRAGANDDROP-
1651/*! \reimp-
1652*/-
1653void QTextEdit::dragEnterEvent(QDragEnterEvent *e)-
1654{-
1655 Q_D(QTextEdit);-
1656 d->inDrag = true;-
1657 d->sendControlEvent(e);-
1658}
never executed: end of block
0
1659-
1660/*! \reimp-
1661*/-
1662void QTextEdit::dragLeaveEvent(QDragLeaveEvent *e)-
1663{-
1664 Q_D(QTextEdit);-
1665 d->inDrag = false;-
1666 d->autoScrollTimer.stop();-
1667 d->sendControlEvent(e);-
1668}
never executed: end of block
0
1669-
1670/*! \reimp-
1671*/-
1672void QTextEdit::dragMoveEvent(QDragMoveEvent *e)-
1673{-
1674 Q_D(QTextEdit);-
1675 d->autoScrollDragPos = e->pos();-
1676 if (!d->autoScrollTimer.isActive())
!d->autoScrollTimer.isActive()Description
TRUEnever evaluated
FALSEnever evaluated
0
1677 d->autoScrollTimer.start(100, this);
never executed: d->autoScrollTimer.start(100, this);
0
1678 d->sendControlEvent(e);-
1679}
never executed: end of block
0
1680-
1681/*! \reimp-
1682*/-
1683void QTextEdit::dropEvent(QDropEvent *e)-
1684{-
1685 Q_D(QTextEdit);-
1686 d->inDrag = false;-
1687 d->autoScrollTimer.stop();-
1688 d->sendControlEvent(e);-
1689}
never executed: end of block
0
1690-
1691#endif // QT_NO_DRAGANDDROP-
1692-
1693/*! \reimp-
1694 */-
1695void QTextEdit::inputMethodEvent(QInputMethodEvent *e)-
1696{-
1697 Q_D(QTextEdit);-
1698#ifdef QT_KEYPAD_NAVIGATION-
1699 if (d->control->textInteractionFlags() & Qt::TextEditable-
1700 && QApplication::keypadNavigationEnabled()-
1701 && !hasEditFocus())-
1702 setEditFocus(true);-
1703#endif-
1704 d->sendControlEvent(e);-
1705 ensureCursorVisible();-
1706}
never executed: end of block
0
1707-
1708/*!\reimp-
1709*/-
1710void QTextEdit::scrollContentsBy(int dx, int dy)-
1711{-
1712 Q_D(QTextEdit);-
1713 if (isRightToLeft())
isRightToLeft()Description
TRUEnever evaluated
FALSEnever evaluated
0
1714 dx = -dx;
never executed: dx = -dx;
0
1715 d->viewport->scroll(dx, dy);-
1716 QGuiApplication::inputMethod()->update(Qt::ImCursorRectangle | Qt::ImAnchorRectangle);-
1717}
never executed: end of block
0
1718-
1719/*!\reimp-
1720*/-
1721QVariant QTextEdit::inputMethodQuery(Qt::InputMethodQuery property) const-
1722{-
1723 return inputMethodQuery(property, QVariant());
never executed: return inputMethodQuery(property, QVariant());
0
1724}-
1725-
1726/*!\internal-
1727 */-
1728QVariant QTextEdit::inputMethodQuery(Qt::InputMethodQuery query, QVariant argument) const-
1729{-
1730 Q_D(const QTextEdit);-
1731 switch (query) {-
1732 case Qt::ImHints:
never executed: case Qt::ImHints:
0
1733 case Qt::ImInputItemClipRectangle:
never executed: case Qt::ImInputItemClipRectangle:
0
1734 return QWidget::inputMethodQuery(query);
never executed: return QWidget::inputMethodQuery(query);
0
1735 default:
never executed: default:
0
1736 break;
never executed: break;
0
1737 }-
1738-
1739 const QPointF offset(-d->horizontalOffset(), -d->verticalOffset());-
1740 switch (argument.type()) {-
1741 case QVariant::RectF:
never executed: case QVariant::RectF:
0
1742 argument = argument.toRectF().translated(-offset);-
1743 break;
never executed: break;
0
1744 case QVariant::PointF:
never executed: case QVariant::PointF:
0
1745 argument = argument.toPointF() - offset;-
1746 break;
never executed: break;
0
1747 case QVariant::Rect:
never executed: case QVariant::Rect:
0
1748 argument = argument.toRect().translated(-offset.toPoint());-
1749 break;
never executed: break;
0
1750 case QVariant::Point:
never executed: case QVariant::Point:
0
1751 argument = argument.toPoint() - offset;-
1752 break;
never executed: break;
0
1753 default:
never executed: default:
0
1754 break;
never executed: break;
0
1755 }-
1756-
1757 const QVariant v = d->control->inputMethodQuery(query, argument);-
1758 switch (v.type()) {-
1759 case QVariant::RectF:
never executed: case QVariant::RectF:
0
1760 return v.toRectF().translated(offset);
never executed: return v.toRectF().translated(offset);
0
1761 case QVariant::PointF:
never executed: case QVariant::PointF:
0
1762 return v.toPointF() + offset;
never executed: return v.toPointF() + offset;
0
1763 case QVariant::Rect:
never executed: case QVariant::Rect:
0
1764 return v.toRect().translated(offset.toPoint());
never executed: return v.toRect().translated(offset.toPoint());
0
1765 case QVariant::Point:
never executed: case QVariant::Point:
0
1766 return v.toPoint() + offset.toPoint();
never executed: return v.toPoint() + offset.toPoint();
0
1767 default:
never executed: default:
0
1768 break;
never executed: break;
0
1769 }-
1770 return v;
never executed: return v;
0
1771}-
1772-
1773/*! \reimp-
1774*/-
1775void QTextEdit::focusInEvent(QFocusEvent *e)-
1776{-
1777 Q_D(QTextEdit);-
1778 if (e->reason() == Qt::MouseFocusReason) {
e->reason() ==...useFocusReasonDescription
TRUEnever evaluated
FALSEnever evaluated
0
1779 d->clickCausedFocus = 1;-
1780 }
never executed: end of block
0
1781 QAbstractScrollArea::focusInEvent(e);-
1782 d->sendControlEvent(e);-
1783}
never executed: end of block
0
1784-
1785/*! \reimp-
1786*/-
1787void QTextEdit::focusOutEvent(QFocusEvent *e)-
1788{-
1789 Q_D(QTextEdit);-
1790 QAbstractScrollArea::focusOutEvent(e);-
1791 d->sendControlEvent(e);-
1792}
never executed: end of block
0
1793-
1794/*! \reimp-
1795*/-
1796void QTextEdit::showEvent(QShowEvent *)-
1797{-
1798 Q_D(QTextEdit);-
1799 if (!d->anchorToScrollToWhenVisible.isEmpty()) {
!d->anchorToSc...ible.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
1800 scrollToAnchor(d->anchorToScrollToWhenVisible);-
1801 d->anchorToScrollToWhenVisible.clear();-
1802 d->showCursorOnInitialShow = false;-
1803 } else if (d->showCursorOnInitialShow) {
never executed: end of block
d->showCursorOnInitialShowDescription
TRUEnever evaluated
FALSEnever evaluated
0
1804 d->showCursorOnInitialShow = false;-
1805 ensureCursorVisible();-
1806 }
never executed: end of block
0
1807}
never executed: end of block
0
1808-
1809/*! \reimp-
1810*/-
1811void QTextEdit::changeEvent(QEvent *e)-
1812{-
1813 Q_D(QTextEdit);-
1814 QAbstractScrollArea::changeEvent(e);-
1815 if (e->type() == QEvent::ApplicationFontChange
e->type() == Q...tionFontChangeDescription
TRUEnever evaluated
FALSEnever evaluated
0
1816 || e->type() == QEvent::FontChange) {
e->type() == Q...nt::FontChangeDescription
TRUEnever evaluated
FALSEnever evaluated
0
1817 d->control->document()->setDefaultFont(font());-
1818 } else if(e->type() == QEvent::ActivationChange) {
never executed: end of block
e->type() == Q...tivationChangeDescription
TRUEnever evaluated
FALSEnever evaluated
0
1819 if (!isActiveWindow())
!isActiveWindow()Description
TRUEnever evaluated
FALSEnever evaluated
0
1820 d->autoScrollTimer.stop();
never executed: d->autoScrollTimer.stop();
0
1821 } else if (e->type() == QEvent::EnabledChange) {
never executed: end of block
e->type() == Q...:EnabledChangeDescription
TRUEnever evaluated
FALSEnever evaluated
0
1822 e->setAccepted(isEnabled());-
1823 d->control->setPalette(palette());-
1824 d->sendControlEvent(e);-
1825 } else if (e->type() == QEvent::PaletteChange) {
never executed: end of block
e->type() == Q...:PaletteChangeDescription
TRUEnever evaluated
FALSEnever evaluated
0
1826 d->control->setPalette(palette());-
1827 } else if (e->type() == QEvent::LayoutDirectionChange) {
never executed: end of block
e->type() == Q...irectionChangeDescription
TRUEnever evaluated
FALSEnever evaluated
0
1828 d->sendControlEvent(e);-
1829 }
never executed: end of block
0
1830}
never executed: end of block
0
1831-
1832/*! \reimp-
1833*/-
1834#ifndef QT_NO_WHEELEVENT-
1835void QTextEdit::wheelEvent(QWheelEvent *e)-
1836{-
1837 Q_D(QTextEdit);-
1838 if (!(d->control->textInteractionFlags() & Qt::TextEditable)) {
!(d->control->...:TextEditable)Description
TRUEnever evaluated
FALSEnever evaluated
0
1839 if (e->modifiers() & Qt::ControlModifier) {
e->modifiers()...ontrolModifierDescription
TRUEnever evaluated
FALSEnever evaluated
0
1840 float delta = e->angleDelta().y() / 120.f;-
1841 zoomInF(delta);-
1842 return;
never executed: return;
0
1843 }-
1844 }
never executed: end of block
0
1845 QAbstractScrollArea::wheelEvent(e);-
1846 updateMicroFocus();-
1847}
never executed: end of block
0
1848#endif-
1849-
1850#ifndef QT_NO_CONTEXTMENU-
1851/*! This function creates the standard context menu which is shown-
1852 when the user clicks on the text edit with the right mouse-
1853 button. It is called from the default contextMenuEvent() handler.-
1854 The popup menu's ownership is transferred to the caller.-
1855-
1856 We recommend that you use the createStandardContextMenu(QPoint) version instead-
1857 which will enable the actions that are sensitive to where the user clicked.-
1858*/-
1859-
1860QMenu *QTextEdit::createStandardContextMenu()-
1861{-
1862 Q_D(QTextEdit);-
1863 return d->control->createStandardContextMenu(QPointF(), this);
never executed: return d->control->createStandardContextMenu(QPointF(), this);
0
1864}-
1865-
1866/*!-
1867 \since 4.4-
1868 This function creates the standard context menu which is shown-
1869 when the user clicks on the text edit with the right mouse-
1870 button. It is called from the default contextMenuEvent() handler-
1871 and it takes the \a position in document coordinates where the mouse click was.-
1872 This can enable actions that are sensitive to the position where the user clicked.-
1873 The popup menu's ownership is transferred to the caller.-
1874*/-
1875-
1876QMenu *QTextEdit::createStandardContextMenu(const QPoint &position)-
1877{-
1878 Q_D(QTextEdit);-
1879 return d->control->createStandardContextMenu(position, this);
never executed: return d->control->createStandardContextMenu(position, this);
0
1880}-
1881#endif // QT_NO_CONTEXTMENU-
1882-
1883/*!-
1884 returns a QTextCursor at position \a pos (in viewport coordinates).-
1885*/-
1886QTextCursor QTextEdit::cursorForPosition(const QPoint &pos) const-
1887{-
1888 Q_D(const QTextEdit);-
1889 return d->control->cursorForPosition(d->mapToContents(pos));
never executed: return d->control->cursorForPosition(d->mapToContents(pos));
0
1890}-
1891-
1892/*!-
1893 returns a rectangle (in viewport coordinates) that includes the-
1894 \a cursor.-
1895 */-
1896QRect QTextEdit::cursorRect(const QTextCursor &cursor) const-
1897{-
1898 Q_D(const QTextEdit);-
1899 if (cursor.isNull())
cursor.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
0
1900 return QRect();
never executed: return QRect();
0
1901-
1902 QRect r = d->control->cursorRect(cursor).toRect();-
1903 r.translate(-d->horizontalOffset(),-d->verticalOffset());-
1904 return r;
never executed: return r;
0
1905}-
1906-
1907/*!-
1908 returns a rectangle (in viewport coordinates) that includes the-
1909 cursor of the text edit.-
1910 */-
1911QRect QTextEdit::cursorRect() const-
1912{-
1913 Q_D(const QTextEdit);-
1914 QRect r = d->control->cursorRect().toRect();-
1915 r.translate(-d->horizontalOffset(),-d->verticalOffset());-
1916 return r;
never executed: return r;
0
1917}-
1918-
1919-
1920/*!-
1921 Returns the reference of the anchor at position \a pos, or an-
1922 empty string if no anchor exists at that point.-
1923*/-
1924QString QTextEdit::anchorAt(const QPoint& pos) const-
1925{-
1926 Q_D(const QTextEdit);-
1927 return d->control->anchorAt(d->mapToContents(pos));
never executed: return d->control->anchorAt(d->mapToContents(pos));
0
1928}-
1929-
1930/*!-
1931 \property QTextEdit::overwriteMode-
1932 \since 4.1-
1933 \brief whether text entered by the user will overwrite existing text-
1934-
1935 As with many text editors, the text editor widget can be configured-
1936 to insert or overwrite existing text with new text entered by the user.-
1937-
1938 If this property is \c true, existing text is overwritten, character-for-character-
1939 by new text; otherwise, text is inserted at the cursor position, displacing-
1940 existing text.-
1941-
1942 By default, this property is \c false (new text does not overwrite existing text).-
1943*/-
1944-
1945bool QTextEdit::overwriteMode() const-
1946{-
1947 Q_D(const QTextEdit);-
1948 return d->control->overwriteMode();
never executed: return d->control->overwriteMode();
0
1949}-
1950-
1951void QTextEdit::setOverwriteMode(bool overwrite)-
1952{-
1953 Q_D(QTextEdit);-
1954 d->control->setOverwriteMode(overwrite);-
1955}
never executed: end of block
0
1956-
1957/*!-
1958 \property QTextEdit::tabStopWidth-
1959 \brief the tab stop width in pixels-
1960 \since 4.1-
1961-
1962 By default, this property contains a value of 80 pixels.-
1963*/-
1964-
1965int QTextEdit::tabStopWidth() const-
1966{-
1967 Q_D(const QTextEdit);-
1968 return qRound(d->control->document()->defaultTextOption().tabStop());
never executed: return qRound(d->control->document()->defaultTextOption().tabStop());
0
1969}-
1970-
1971void QTextEdit::setTabStopWidth(int width)-
1972{-
1973 Q_D(QTextEdit);-
1974 QTextOption opt = d->control->document()->defaultTextOption();-
1975 if (opt.tabStop() == width || width < 0)
opt.tabStop() == widthDescription
TRUEnever evaluated
FALSEnever evaluated
width < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1976 return;
never executed: return;
0
1977 opt.setTabStop(width);-
1978 d->control->document()->setDefaultTextOption(opt);-
1979}
never executed: end of block
0
1980-
1981/*!-
1982 \since 4.2-
1983 \property QTextEdit::cursorWidth-
1984-
1985 This property specifies the width of the cursor in pixels. The default value is 1.-
1986*/-
1987int QTextEdit::cursorWidth() const-
1988{-
1989 Q_D(const QTextEdit);-
1990 return d->control->cursorWidth();
never executed: return d->control->cursorWidth();
0
1991}-
1992-
1993void QTextEdit::setCursorWidth(int width)-
1994{-
1995 Q_D(QTextEdit);-
1996 d->control->setCursorWidth(width);-
1997}
never executed: end of block
0
1998-
1999/*!-
2000 \property QTextEdit::acceptRichText-
2001 \brief whether the text edit accepts rich text insertions by the user-
2002 \since 4.1-
2003-
2004 When this propery is set to false text edit will accept only-
2005 plain text input from the user. For example through clipboard or drag and drop.-
2006-
2007 This property's default is true.-
2008*/-
2009-
2010bool QTextEdit::acceptRichText() const-
2011{-
2012 Q_D(const QTextEdit);-
2013 return d->control->acceptRichText();
never executed: return d->control->acceptRichText();
0
2014}-
2015-
2016void QTextEdit::setAcceptRichText(bool accept)-
2017{-
2018 Q_D(QTextEdit);-
2019 d->control->setAcceptRichText(accept);-
2020}
never executed: end of block
0
2021-
2022/*!-
2023 \class QTextEdit::ExtraSelection-
2024 \since 4.2-
2025 \inmodule QtWidgets-
2026-
2027 \brief The QTextEdit::ExtraSelection structure provides a way of specifying a-
2028 character format for a given selection in a document-
2029*/-
2030-
2031/*!-
2032 \variable QTextEdit::ExtraSelection::cursor-
2033 A cursor that contains a selection in a QTextDocument-
2034*/-
2035-
2036/*!-
2037 \variable QTextEdit::ExtraSelection::format-
2038 A format that is used to specify a foreground or background brush/color-
2039 for the selection.-
2040*/-
2041-
2042/*!-
2043 \since 4.2-
2044 This function allows temporarily marking certain regions in the document-
2045 with a given color, specified as \a selections. This can be useful for-
2046 example in a programming editor to mark a whole line of text with a given-
2047 background color to indicate the existence of a breakpoint.-
2048-
2049 \sa QTextEdit::ExtraSelection, extraSelections()-
2050*/-
2051void QTextEdit::setExtraSelections(const QList<ExtraSelection> &selections)-
2052{-
2053 Q_D(QTextEdit);-
2054 d->control->setExtraSelections(selections);-
2055}
never executed: end of block
0
2056-
2057/*!-
2058 \since 4.2-
2059 Returns previously set extra selections.-
2060-
2061 \sa setExtraSelections()-
2062*/-
2063QList<QTextEdit::ExtraSelection> QTextEdit::extraSelections() const-
2064{-
2065 Q_D(const QTextEdit);-
2066 return d->control->extraSelections();
never executed: return d->control->extraSelections();
0
2067}-
2068-
2069/*!-
2070 This function returns a new MIME data object to represent the contents-
2071 of the text edit's current selection. It is called when the selection needs-
2072 to be encapsulated into a new QMimeData object; for example, when a drag-
2073 and drop operation is started, or when data is copied to the clipboard.-
2074-
2075 If you reimplement this function, note that the ownership of the returned-
2076 QMimeData object is passed to the caller. The selection can be retrieved-
2077 by using the textCursor() function.-
2078*/-
2079QMimeData *QTextEdit::createMimeDataFromSelection() const-
2080{-
2081 Q_D(const QTextEdit);-
2082 return d->control->QWidgetTextControl::createMimeDataFromSelection();
never executed: return d->control->QWidgetTextControl::createMimeDataFromSelection();
0
2083}-
2084-
2085/*!-
2086 This function returns \c true if the contents of the MIME data object, specified-
2087 by \a source, can be decoded and inserted into the document. It is called-
2088 for example when during a drag operation the mouse enters this widget and it-
2089 is necessary to determine whether it is possible to accept the drag and drop-
2090 operation.-
2091-
2092 Reimplement this function to enable drag and drop support for additional MIME types.-
2093 */-
2094bool QTextEdit::canInsertFromMimeData(const QMimeData *source) const-
2095{-
2096 Q_D(const QTextEdit);-
2097 return d->control->QWidgetTextControl::canInsertFromMimeData(source);
never executed: return d->control->QWidgetTextControl::canInsertFromMimeData(source);
0
2098}-
2099-
2100/*!-
2101 This function inserts the contents of the MIME data object, specified-
2102 by \a source, into the text edit at the current cursor position. It is-
2103 called whenever text is inserted as the result of a clipboard paste-
2104 operation, or when the text edit accepts data from a drag and drop-
2105 operation.-
2106-
2107 Reimplement this function to enable drag and drop support for additional MIME types.-
2108 */-
2109void QTextEdit::insertFromMimeData(const QMimeData *source)-
2110{-
2111 Q_D(QTextEdit);-
2112 d->control->QWidgetTextControl::insertFromMimeData(source);-
2113}
never executed: end of block
0
2114-
2115/*!-
2116 \property QTextEdit::readOnly-
2117 \brief whether the text edit is read-only-
2118-
2119 In a read-only text edit the user can only navigate through the-
2120 text and select text; modifying the text is not possible.-
2121-
2122 This property's default is false.-
2123*/-
2124-
2125bool QTextEdit::isReadOnly() const-
2126{-
2127 Q_D(const QTextEdit);-
2128 return !(d->control->textInteractionFlags() & Qt::TextEditable);
never executed: return !(d->control->textInteractionFlags() & Qt::TextEditable);
0
2129}-
2130-
2131void QTextEdit::setReadOnly(bool ro)-
2132{-
2133 Q_D(QTextEdit);-
2134 Qt::TextInteractionFlags flags = Qt::NoTextInteraction;-
2135 if (ro) {
roDescription
TRUEnever evaluated
FALSEnever evaluated
0
2136 flags = Qt::TextSelectableByMouse;-
2137#ifndef QT_NO_TEXTBROWSER-
2138 if (qobject_cast<QTextBrowser *>(this))
qobject_cast<Q...owser *>(this)Description
TRUEnever evaluated
FALSEnever evaluated
0
2139 flags |= Qt::TextBrowserInteraction;
never executed: flags |= Qt::TextBrowserInteraction;
0
2140#endif-
2141 } else {
never executed: end of block
0
2142 flags = Qt::TextEditorInteraction;-
2143 }
never executed: end of block
0
2144 d->control->setTextInteractionFlags(flags);-
2145 setAttribute(Qt::WA_InputMethodEnabled, shouldEnableInputMethod(this));-
2146 QEvent event(QEvent::ReadOnlyChange);-
2147 QApplication::sendEvent(this, &event);-
2148}
never executed: end of block
0
2149-
2150/*!-
2151 \property QTextEdit::textInteractionFlags-
2152 \since 4.2-
2153-
2154 Specifies how the widget should interact with user input.-
2155-
2156 The default value depends on whether the QTextEdit is read-only-
2157 or editable, and whether it is a QTextBrowser or not.-
2158*/-
2159-
2160void QTextEdit::setTextInteractionFlags(Qt::TextInteractionFlags flags)-
2161{-
2162 Q_D(QTextEdit);-
2163 d->control->setTextInteractionFlags(flags);-
2164}
never executed: end of block
0
2165-
2166Qt::TextInteractionFlags QTextEdit::textInteractionFlags() const-
2167{-
2168 Q_D(const QTextEdit);-
2169 return d->control->textInteractionFlags();
never executed: return d->control->textInteractionFlags();
0
2170}-
2171-
2172/*!-
2173 Merges the properties specified in \a modifier into the current character-
2174 format by calling QTextCursor::mergeCharFormat on the editor's cursor.-
2175 If the editor has a selection then the properties of \a modifier are-
2176 directly applied to the selection.-
2177-
2178 \sa QTextCursor::mergeCharFormat()-
2179 */-
2180void QTextEdit::mergeCurrentCharFormat(const QTextCharFormat &modifier)-
2181{-
2182 Q_D(QTextEdit);-
2183 d->control->mergeCurrentCharFormat(modifier);-
2184}
never executed: end of block
0
2185-
2186/*!-
2187 Sets the char format that is be used when inserting new text to \a-
2188 format by calling QTextCursor::setCharFormat() on the editor's-
2189 cursor. If the editor has a selection then the char format is-
2190 directly applied to the selection.-
2191 */-
2192void QTextEdit::setCurrentCharFormat(const QTextCharFormat &format)-
2193{-
2194 Q_D(QTextEdit);-
2195 d->control->setCurrentCharFormat(format);-
2196}
never executed: end of block
0
2197-
2198/*!-
2199 Returns the char format that is used when inserting new text.-
2200 */-
2201QTextCharFormat QTextEdit::currentCharFormat() const-
2202{-
2203 Q_D(const QTextEdit);-
2204 return d->control->currentCharFormat();
never executed: return d->control->currentCharFormat();
0
2205}-
2206-
2207/*!-
2208 \property QTextEdit::autoFormatting-
2209 \brief the enabled set of auto formatting features-
2210-
2211 The value can be any combination of the values in the-
2212 AutoFormattingFlag enum. The default is AutoNone. Choose-
2213 AutoAll to enable all automatic formatting.-
2214-
2215 Currently, the only automatic formatting feature provided is-
2216 AutoBulletList; future versions of Qt may offer more.-
2217*/-
2218-
2219QTextEdit::AutoFormatting QTextEdit::autoFormatting() const-
2220{-
2221 Q_D(const QTextEdit);-
2222 return d->autoFormatting;
never executed: return d->autoFormatting;
0
2223}-
2224-
2225void QTextEdit::setAutoFormatting(AutoFormatting features)-
2226{-
2227 Q_D(QTextEdit);-
2228 d->autoFormatting = features;-
2229}
never executed: end of block
0
2230-
2231/*!-
2232 Convenience slot that inserts \a text at the current-
2233 cursor position.-
2234-
2235 It is equivalent to-
2236-
2237 \snippet code/src_gui_widgets_qtextedit.cpp 1-
2238 */-
2239void QTextEdit::insertPlainText(const QString &text)-
2240{-
2241 Q_D(QTextEdit);-
2242 d->control->insertPlainText(text);-
2243}
never executed: end of block
0
2244-
2245/*!-
2246 Convenience slot that inserts \a text which is assumed to be of-
2247 html formatting at the current cursor position.-
2248-
2249 It is equivalent to:-
2250-
2251 \snippet code/src_gui_widgets_qtextedit.cpp 2-
2252-
2253 \note When using this function with a style sheet, the style sheet will-
2254 only apply to the current block in the document. In order to apply a style-
2255 sheet throughout a document, use QTextDocument::setDefaultStyleSheet()-
2256 instead.-
2257 */-
2258#ifndef QT_NO_TEXTHTMLPARSER-
2259void QTextEdit::insertHtml(const QString &text)-
2260{-
2261 Q_D(QTextEdit);-
2262 d->control->insertHtml(text);-
2263}
never executed: end of block
0
2264#endif // QT_NO_TEXTHTMLPARSER-
2265-
2266/*!-
2267 Scrolls the text edit so that the anchor with the given \a name is-
2268 visible; does nothing if the \a name is empty, or is already-
2269 visible, or isn't found.-
2270*/-
2271void QTextEdit::scrollToAnchor(const QString &name)-
2272{-
2273 Q_D(QTextEdit);-
2274 if (name.isEmpty())
name.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
2275 return;
never executed: return;
0
2276-
2277 if (!isVisible()) {
!isVisible()Description
TRUEnever evaluated
FALSEnever evaluated
0
2278 d->anchorToScrollToWhenVisible = name;-
2279 return;
never executed: return;
0
2280 }-
2281-
2282 QPointF p = d->control->anchorPosition(name);-
2283 const int newPosition = qRound(p.y());-
2284 if ( d->vbar->maximum() < newPosition )
d->vbar->maxim... < newPositionDescription
TRUEnever evaluated
FALSEnever evaluated
0
2285 d->_q_adjustScrollbars();
never executed: d->_q_adjustScrollbars();
0
2286 d->vbar->setValue(newPosition);-
2287}
never executed: end of block
0
2288-
2289/*!-
2290 \fn QTextEdit::zoomIn(int range)-
2291-
2292 Zooms in on the text by making the base font size \a range-
2293 points larger and recalculating all font sizes to be the new size.-
2294 This does not change the size of any images.-
2295-
2296 \sa zoomOut()-
2297*/-
2298void QTextEdit::zoomIn(int range)-
2299{-
2300 zoomInF(range);-
2301}
never executed: end of block
0
2302-
2303/*!-
2304 \fn QTextEdit::zoomOut(int range)-
2305-
2306 \overload-
2307-
2308 Zooms out on the text by making the base font size \a range points-
2309 smaller and recalculating all font sizes to be the new size. This-
2310 does not change the size of any images.-
2311-
2312 \sa zoomIn()-
2313*/-
2314void QTextEdit::zoomOut(int range)-
2315{-
2316 zoomInF(-range);-
2317}
never executed: end of block
0
2318-
2319/*!-
2320 \internal-
2321*/-
2322void QTextEdit::zoomInF(float range)-
2323{-
2324 if (range == 0.f)
range == 0.fDescription
TRUEnever evaluated
FALSEnever evaluated
0
2325 return;
never executed: return;
0
2326 QFont f = font();-
2327 const float newSize = f.pointSizeF() + range;-
2328 if (newSize <= 0)
newSize <= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
2329 return;
never executed: return;
0
2330 f.setPointSizeF(newSize);-
2331 setFont(f);-
2332}
never executed: end of block
0
2333-
2334/*!-
2335 \since 4.2-
2336 Moves the cursor by performing the given \a operation.-
2337-
2338 If \a mode is QTextCursor::KeepAnchor, the cursor selects the text it moves over.-
2339 This is the same effect that the user achieves when they hold down the Shift key-
2340 and move the cursor with the cursor keys.-
2341-
2342 \sa QTextCursor::movePosition()-
2343*/-
2344void QTextEdit::moveCursor(QTextCursor::MoveOperation operation, QTextCursor::MoveMode mode)-
2345{-
2346 Q_D(QTextEdit);-
2347 d->control->moveCursor(operation, mode);-
2348}
never executed: end of block
0
2349-
2350/*!-
2351 \since 4.2-
2352 Returns whether text can be pasted from the clipboard into the textedit.-
2353*/-
2354bool QTextEdit::canPaste() const-
2355{-
2356 Q_D(const QTextEdit);-
2357 return d->control->canPaste();
never executed: return d->control->canPaste();
0
2358}-
2359-
2360/*!-
2361 \since 4.3-
2362 Convenience function to print the text edit's document to the given \a printer. This-
2363 is equivalent to calling the print method on the document directly except that this-
2364 function also supports QPrinter::Selection as print range.-
2365-
2366 \sa QTextDocument::print()-
2367*/-
2368#ifndef QT_NO_PRINTER-
2369void QTextEdit::print(QPagedPaintDevice *printer) const-
2370{-
2371 Q_D(const QTextEdit);-
2372 d->control->print(printer);-
2373}
never executed: end of block
0
2374#endif-
2375-
2376/*! \property QTextEdit::tabChangesFocus-
2377 \brief whether \uicontrol Tab changes focus or is accepted as input-
2378-
2379 In some occasions text edits should not allow the user to input-
2380 tabulators or change indentation using the \uicontrol Tab key, as this breaks-
2381 the focus chain. The default is false.-
2382-
2383*/-
2384-
2385bool QTextEdit::tabChangesFocus() const-
2386{-
2387 Q_D(const QTextEdit);-
2388 return d->tabChangesFocus;
never executed: return d->tabChangesFocus;
0
2389}-
2390-
2391void QTextEdit::setTabChangesFocus(bool b)-
2392{-
2393 Q_D(QTextEdit);-
2394 d->tabChangesFocus = b;-
2395}
never executed: end of block
0
2396-
2397/*!-
2398 \property QTextEdit::documentTitle-
2399 \brief the title of the document parsed from the text.-
2400-
2401 By default, for a newly-created, empty document, this property contains-
2402 an empty string.-
2403*/-
2404-
2405/*!-
2406 \property QTextEdit::lineWrapMode-
2407 \brief the line wrap mode-
2408-
2409 The default mode is WidgetWidth which causes words to be-
2410 wrapped at the right edge of the text edit. Wrapping occurs at-
2411 whitespace, keeping whole words intact. If you want wrapping to-
2412 occur within words use setWordWrapMode(). If you set a wrap mode of-
2413 FixedPixelWidth or FixedColumnWidth you should also call-
2414 setLineWrapColumnOrWidth() with the width you want.-
2415-
2416 \sa lineWrapColumnOrWidth-
2417*/-
2418-
2419QTextEdit::LineWrapMode QTextEdit::lineWrapMode() const-
2420{-
2421 Q_D(const QTextEdit);-
2422 return d->lineWrap;
never executed: return d->lineWrap;
0
2423}-
2424-
2425void QTextEdit::setLineWrapMode(LineWrapMode wrap)-
2426{-
2427 Q_D(QTextEdit);-
2428 if (d->lineWrap == wrap)
d->lineWrap == wrapDescription
TRUEnever evaluated
FALSEnever evaluated
0
2429 return;
never executed: return;
0
2430 d->lineWrap = wrap;-
2431 d->updateDefaultTextOption();-
2432 d->relayoutDocument();-
2433}
never executed: end of block
0
2434-
2435/*!-
2436 \property QTextEdit::lineWrapColumnOrWidth-
2437 \brief the position (in pixels or columns depending on the wrap mode) where text will be wrapped-
2438-
2439 If the wrap mode is FixedPixelWidth, the value is the number of-
2440 pixels from the left edge of the text edit at which text should be-
2441 wrapped. If the wrap mode is FixedColumnWidth, the value is the-
2442 column number (in character columns) from the left edge of the-
2443 text edit at which text should be wrapped.-
2444-
2445 By default, this property contains a value of 0.-
2446-
2447 \sa lineWrapMode-
2448*/-
2449-
2450int QTextEdit::lineWrapColumnOrWidth() const-
2451{-
2452 Q_D(const QTextEdit);-
2453 return d->lineWrapColumnOrWidth;
never executed: return d->lineWrapColumnOrWidth;
0
2454}-
2455-
2456void QTextEdit::setLineWrapColumnOrWidth(int w)-
2457{-
2458 Q_D(QTextEdit);-
2459 d->lineWrapColumnOrWidth = w;-
2460 d->relayoutDocument();-
2461}
never executed: end of block
0
2462-
2463/*!-
2464 \property QTextEdit::wordWrapMode-
2465 \brief the mode QTextEdit will use when wrapping text by words-
2466-
2467 By default, this property is set to QTextOption::WrapAtWordBoundaryOrAnywhere.-
2468-
2469 \sa QTextOption::WrapMode-
2470*/-
2471-
2472QTextOption::WrapMode QTextEdit::wordWrapMode() const-
2473{-
2474 Q_D(const QTextEdit);-
2475 return d->wordWrap;
never executed: return d->wordWrap;
0
2476}-
2477-
2478void QTextEdit::setWordWrapMode(QTextOption::WrapMode mode)-
2479{-
2480 Q_D(QTextEdit);-
2481 if (mode == d->wordWrap)
mode == d->wordWrapDescription
TRUEnever evaluated
FALSEnever evaluated
0
2482 return;
never executed: return;
0
2483 d->wordWrap = mode;-
2484 d->updateDefaultTextOption();-
2485}
never executed: end of block
0
2486-
2487/*!-
2488 Finds the next occurrence of the string, \a exp, using the given-
2489 \a options. Returns \c true if \a exp was found and changes the-
2490 cursor to select the match; otherwise returns \c false.-
2491*/-
2492bool QTextEdit::find(const QString &exp, QTextDocument::FindFlags options)-
2493{-
2494 Q_D(QTextEdit);-
2495 return d->control->find(exp, options);
never executed: return d->control->find(exp, options);
0
2496}-
2497-
2498/*!-
2499 \fn bool QTextEdit::find(const QRegExp &exp, QTextDocument::FindFlags options)-
2500-
2501 \since 5.3-
2502 \overload-
2503-
2504 Finds the next occurrence, matching the regular expression, \a exp, using the given-
2505 \a options. The QTextDocument::FindCaseSensitively option is ignored for this overload,-
2506 use QRegExp::caseSensitivity instead.-
2507-
2508 Returns \c true if a match was found and changes the cursor to select the match;-
2509 otherwise returns \c false.-
2510*/-
2511#ifndef QT_NO_REGEXP-
2512bool QTextEdit::find(const QRegExp &exp, QTextDocument::FindFlags options)-
2513{-
2514 Q_D(QTextEdit);-
2515 return d->control->find(exp, options);
never executed: return d->control->find(exp, options);
0
2516}-
2517#endif-
2518-
2519/*!-
2520 \fn void QTextEdit::copyAvailable(bool yes)-
2521-
2522 This signal is emitted when text is selected or de-selected in the-
2523 text edit.-
2524-
2525 When text is selected this signal will be emitted with \a yes set-
2526 to true. If no text has been selected or if the selected text is-
2527 de-selected this signal is emitted with \a yes set to false.-
2528-
2529 If \a yes is true then copy() can be used to copy the selection to-
2530 the clipboard. If \a yes is false then copy() does nothing.-
2531-
2532 \sa selectionChanged()-
2533*/-
2534-
2535/*!-
2536 \fn void QTextEdit::currentCharFormatChanged(const QTextCharFormat &f)-
2537-
2538 This signal is emitted if the current character format has changed, for-
2539 example caused by a change of the cursor position.-
2540-
2541 The new format is \a f.-
2542-
2543 \sa setCurrentCharFormat()-
2544*/-
2545-
2546/*!-
2547 \fn void QTextEdit::selectionChanged()-
2548-
2549 This signal is emitted whenever the selection changes.-
2550-
2551 \sa copyAvailable()-
2552*/-
2553-
2554/*!-
2555 \fn void QTextEdit::cursorPositionChanged()-
2556-
2557 This signal is emitted whenever the position of the-
2558 cursor changed.-
2559*/-
2560-
2561/*!-
2562 \since 4.2-
2563-
2564 Sets the text edit's \a text. The text can be plain text or HTML-
2565 and the text edit will try to guess the right format.-
2566-
2567 Use setHtml() or setPlainText() directly to avoid text edit's guessing.-
2568-
2569 \sa toPlainText(), toHtml()-
2570*/-
2571void QTextEdit::setText(const QString &text)-
2572{-
2573 Q_D(QTextEdit);-
2574 Qt::TextFormat format = d->textFormat;-
2575 if (d->textFormat == Qt::AutoText)
d->textFormat == Qt::AutoTextDescription
TRUEnever evaluated
FALSEnever evaluated
0
2576 format = Qt::mightBeRichText(text) ? Qt::RichText : Qt::PlainText;
never executed: format = Qt::mightBeRichText(text) ? Qt::RichText : Qt::PlainText;
Qt::mightBeRichText(text)Description
TRUEnever evaluated
FALSEnever evaluated
0
2577#ifndef QT_NO_TEXTHTMLPARSER-
2578 if (format == Qt::RichText)
format == Qt::RichTextDescription
TRUEnever evaluated
FALSEnever evaluated
0
2579 setHtml(text);
never executed: setHtml(text);
0
2580 else-
2581#endif-
2582 setPlainText(text);
never executed: setPlainText(text);
0
2583}-
2584-
2585-
2586/*!-
2587 Appends a new paragraph with \a text to the end of the text edit.-
2588-
2589 \note The new paragraph appended will have the same character format and-
2590 block format as the current paragraph, determined by the position of the cursor.-
2591-
2592 \sa currentCharFormat(), QTextCursor::blockFormat()-
2593*/-
2594-
2595void QTextEdit::append(const QString &text)-
2596{-
2597 Q_D(QTextEdit);-
2598 const bool atBottom = isReadOnly() ? d->verticalOffset() >= d->vbar->maximum() :
isReadOnly()Description
TRUEnever evaluated
FALSEnever evaluated
0
2599 d->control->textCursor().atEnd();-
2600 d->control->append(text);-
2601 if (atBottom)
atBottomDescription
TRUEnever evaluated
FALSEnever evaluated
0
2602 d->vbar->setValue(d->vbar->maximum());
never executed: d->vbar->setValue(d->vbar->maximum());
0
2603}
never executed: end of block
0
2604-
2605/*!-
2606 Ensures that the cursor is visible by scrolling the text edit if-
2607 necessary.-
2608*/-
2609void QTextEdit::ensureCursorVisible()-
2610{-
2611 Q_D(QTextEdit);-
2612 d->control->ensureCursorVisible();-
2613}
never executed: end of block
0
2614-
2615/*!-
2616 \fn void QTextEdit::textChanged()-
2617-
2618 This signal is emitted whenever the document's content changes; for-
2619 example, when text is inserted or deleted, or when formatting is applied.-
2620*/-
2621-
2622/*!-
2623 \fn void QTextEdit::undoAvailable(bool available)-
2624-
2625 This signal is emitted whenever undo operations become available-
2626 (\a available is true) or unavailable (\a available is false).-
2627*/-
2628-
2629/*!-
2630 \fn void QTextEdit::redoAvailable(bool available)-
2631-
2632 This signal is emitted whenever redo operations become available-
2633 (\a available is true) or unavailable (\a available is false).-
2634*/-
2635-
2636#endif // QT_NO_TEXTEDIT-
2637-
2638QT_END_NAMESPACE-
2639-
2640#include "moc_qtextedit.cpp"-
Source codeSwitch to Preprocessed file

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