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