Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/quick/items/qquicktextcontrol.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /**************************************************************************** | - | ||||||||||||||||||||||||
2 | ** | - | ||||||||||||||||||||||||
3 | ** Copyright (C) 2016 The Qt Company Ltd. | - | ||||||||||||||||||||||||
4 | ** Contact: https://www.qt.io/licensing/ | - | ||||||||||||||||||||||||
5 | ** | - | ||||||||||||||||||||||||
6 | ** This file is part of the QtGui module of the Qt Toolkit. | - | ||||||||||||||||||||||||
7 | ** | - | ||||||||||||||||||||||||
8 | ** $QT_BEGIN_LICENSE:LGPL$ | - | ||||||||||||||||||||||||
9 | ** Commercial License Usage | - | ||||||||||||||||||||||||
10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||||||||||||||
11 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||||||||||||||
12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||||||||||||||
13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||||||||||||||
14 | ** and conditions see https://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||||||||
15 | ** information use the contact form at https://www.qt.io/contact-us. | - | ||||||||||||||||||||||||
16 | ** | - | ||||||||||||||||||||||||
17 | ** GNU Lesser General Public License Usage | - | ||||||||||||||||||||||||
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||||||||||||||
19 | ** General Public License version 3 as published by the Free Software | - | ||||||||||||||||||||||||
20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | - | ||||||||||||||||||||||||
21 | ** packaging of this file. Please review the following information to | - | ||||||||||||||||||||||||
22 | ** ensure the GNU Lesser General Public License version 3 requirements | - | ||||||||||||||||||||||||
23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | - | ||||||||||||||||||||||||
24 | ** | - | ||||||||||||||||||||||||
25 | ** GNU General Public License Usage | - | ||||||||||||||||||||||||
26 | ** Alternatively, this file may be used under the terms of the GNU | - | ||||||||||||||||||||||||
27 | ** General Public License version 2.0 or (at your option) the GNU General | - | ||||||||||||||||||||||||
28 | ** Public license version 3 or any later version approved by the KDE Free | - | ||||||||||||||||||||||||
29 | ** Qt Foundation. The licenses are as published by the Free Software | - | ||||||||||||||||||||||||
30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | - | ||||||||||||||||||||||||
31 | ** included in the packaging of this file. Please review the following | - | ||||||||||||||||||||||||
32 | ** information to ensure the GNU General Public License requirements will | - | ||||||||||||||||||||||||
33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | - | ||||||||||||||||||||||||
34 | ** https://www.gnu.org/licenses/gpl-3.0.html. | - | ||||||||||||||||||||||||
35 | ** | - | ||||||||||||||||||||||||
36 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||||||||
37 | ** | - | ||||||||||||||||||||||||
38 | ****************************************************************************/ | - | ||||||||||||||||||||||||
39 | - | |||||||||||||||||||||||||
40 | #include "qquicktextcontrol_p.h" | - | ||||||||||||||||||||||||
41 | #include "qquicktextcontrol_p_p.h" | - | ||||||||||||||||||||||||
42 | - | |||||||||||||||||||||||||
43 | #ifndef QT_NO_TEXTCONTROL | - | ||||||||||||||||||||||||
44 | - | |||||||||||||||||||||||||
45 | #include <qcoreapplication.h> | - | ||||||||||||||||||||||||
46 | #include <qfont.h> | - | ||||||||||||||||||||||||
47 | #include <qfontmetrics.h> | - | ||||||||||||||||||||||||
48 | #include <qevent.h> | - | ||||||||||||||||||||||||
49 | #include <qdebug.h> | - | ||||||||||||||||||||||||
50 | #include <qclipboard.h> | - | ||||||||||||||||||||||||
51 | #include <qtimer.h> | - | ||||||||||||||||||||||||
52 | #include <qinputmethod.h> | - | ||||||||||||||||||||||||
53 | #include "private/qtextdocumentlayout_p.h" | - | ||||||||||||||||||||||||
54 | #include "private/qabstracttextdocumentlayout_p.h" | - | ||||||||||||||||||||||||
55 | #include "qtextdocument.h" | - | ||||||||||||||||||||||||
56 | #include "private/qtextdocument_p.h" | - | ||||||||||||||||||||||||
57 | #include "qtextlist.h" | - | ||||||||||||||||||||||||
58 | #include "qtextdocumentwriter.h" | - | ||||||||||||||||||||||||
59 | #include "private/qtextcursor_p.h" | - | ||||||||||||||||||||||||
60 | #include <QtCore/qloggingcategory.h> | - | ||||||||||||||||||||||||
61 | - | |||||||||||||||||||||||||
62 | #include <qtextformat.h> | - | ||||||||||||||||||||||||
63 | #include <qdatetime.h> | - | ||||||||||||||||||||||||
64 | #include <qbuffer.h> | - | ||||||||||||||||||||||||
65 | #include <qguiapplication.h> | - | ||||||||||||||||||||||||
66 | #include <limits.h> | - | ||||||||||||||||||||||||
67 | #include <qtexttable.h> | - | ||||||||||||||||||||||||
68 | #include <qvariant.h> | - | ||||||||||||||||||||||||
69 | #include <qurl.h> | - | ||||||||||||||||||||||||
70 | #include <qstylehints.h> | - | ||||||||||||||||||||||||
71 | #include <qmetaobject.h> | - | ||||||||||||||||||||||||
72 | - | |||||||||||||||||||||||||
73 | #include <private/qqmlglobal_p.h> | - | ||||||||||||||||||||||||
74 | - | |||||||||||||||||||||||||
75 | // ### these should come from QStyleHints | - | ||||||||||||||||||||||||
76 | const int textCursorWidth = 1; | - | ||||||||||||||||||||||||
77 | - | |||||||||||||||||||||||||
78 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||||||||
79 | Q_DECLARE_LOGGING_CATEGORY(DBG_HOVER_TRACE) | - | ||||||||||||||||||||||||
80 | - | |||||||||||||||||||||||||
81 | // could go into QTextCursor... | - | ||||||||||||||||||||||||
82 | static QTextLine currentTextLine(const QTextCursor &cursor) | - | ||||||||||||||||||||||||
83 | { | - | ||||||||||||||||||||||||
84 | const QTextBlock block = cursor.block(); | - | ||||||||||||||||||||||||
85 | if (!block.isValid())
| 0-232 | ||||||||||||||||||||||||
86 | return QTextLine(); never executed: return QTextLine(); | 0 | ||||||||||||||||||||||||
87 | - | |||||||||||||||||||||||||
88 | const QTextLayout *layout = block.layout(); | - | ||||||||||||||||||||||||
89 | if (!layout)
| 0-232 | ||||||||||||||||||||||||
90 | return QTextLine(); never executed: return QTextLine(); | 0 | ||||||||||||||||||||||||
91 | - | |||||||||||||||||||||||||
92 | const int relativePos = cursor.position() - block.position(); | - | ||||||||||||||||||||||||
93 | return layout->lineForTextPosition(relativePos); executed 232 times by 1 test: return layout->lineForTextPosition(relativePos); Executed by:
| 232 | ||||||||||||||||||||||||
94 | } | - | ||||||||||||||||||||||||
95 | - | |||||||||||||||||||||||||
96 | QQuickTextControlPrivate::QQuickTextControlPrivate() | - | ||||||||||||||||||||||||
97 | : doc(nullptr), | - | ||||||||||||||||||||||||
98 | #if QT_CONFIG(im) | - | ||||||||||||||||||||||||
99 | preeditCursor(0), | - | ||||||||||||||||||||||||
100 | #endif | - | ||||||||||||||||||||||||
101 | interactionFlags(Qt::TextEditorInteraction), | - | ||||||||||||||||||||||||
102 | cursorOn(false), | - | ||||||||||||||||||||||||
103 | cursorIsFocusIndicator(false), | - | ||||||||||||||||||||||||
104 | mousePressed(false), | - | ||||||||||||||||||||||||
105 | lastSelectionState(false), | - | ||||||||||||||||||||||||
106 | ignoreAutomaticScrollbarAdjustement(false), | - | ||||||||||||||||||||||||
107 | overwriteMode(false), | - | ||||||||||||||||||||||||
108 | acceptRichText(true), | - | ||||||||||||||||||||||||
109 | cursorVisible(false), | - | ||||||||||||||||||||||||
110 | cursorBlinkingEnabled(false), | - | ||||||||||||||||||||||||
111 | hasFocus(false), | - | ||||||||||||||||||||||||
112 | hadSelectionOnMousePress(false), | - | ||||||||||||||||||||||||
113 | wordSelectionEnabled(false), | - | ||||||||||||||||||||||||
114 | hasImState(false), | - | ||||||||||||||||||||||||
115 | cursorRectangleChanged(false), | - | ||||||||||||||||||||||||
116 | lastSelectionStart(-1), | - | ||||||||||||||||||||||||
117 | lastSelectionEnd(-1) | - | ||||||||||||||||||||||||
118 | {} executed 1080 times by 6 tests: end of block Executed by:
| 1080 | ||||||||||||||||||||||||
119 | - | |||||||||||||||||||||||||
120 | bool QQuickTextControlPrivate::cursorMoveKeyEvent(QKeyEvent *e) | - | ||||||||||||||||||||||||
121 | { | - | ||||||||||||||||||||||||
122 | #if !QT_CONFIG(shortcut) | - | ||||||||||||||||||||||||
123 | Q_UNUSED(e); | - | ||||||||||||||||||||||||
124 | #endif | - | ||||||||||||||||||||||||
125 | - | |||||||||||||||||||||||||
126 | Q_Q(QQuickTextControl); | - | ||||||||||||||||||||||||
127 | if (cursor.isNull())
| 0-890 | ||||||||||||||||||||||||
128 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
129 | - | |||||||||||||||||||||||||
130 | const QTextCursor oldSelection = cursor; | - | ||||||||||||||||||||||||
131 | const int oldCursorPos = cursor.position(); | - | ||||||||||||||||||||||||
132 | - | |||||||||||||||||||||||||
133 | QTextCursor::MoveMode mode = QTextCursor::MoveAnchor; | - | ||||||||||||||||||||||||
134 | QTextCursor::MoveOperation op = QTextCursor::NoMove; | - | ||||||||||||||||||||||||
135 | - | |||||||||||||||||||||||||
136 | if (false) { dead code: { } | - | ||||||||||||||||||||||||
137 | } dead code: { } | - | ||||||||||||||||||||||||
138 | #if QT_CONFIG(shortcut) | - | ||||||||||||||||||||||||
139 | if (e == QKeySequence::MoveToNextChar) {
| 28-862 | ||||||||||||||||||||||||
140 | op = QTextCursor::Right; | - | ||||||||||||||||||||||||
141 | } executed 28 times by 2 tests: end of block Executed by:
| 28 | ||||||||||||||||||||||||
142 | else if (e == QKeySequence::MoveToPreviousChar) {
| 26-836 | ||||||||||||||||||||||||
143 | op = QTextCursor::Left; | - | ||||||||||||||||||||||||
144 | } executed 26 times by 1 test: end of block Executed by:
| 26 | ||||||||||||||||||||||||
145 | else if (e == QKeySequence::SelectNextChar) {
| 22-814 | ||||||||||||||||||||||||
146 | op = QTextCursor::Right; | - | ||||||||||||||||||||||||
147 | mode = QTextCursor::KeepAnchor; | - | ||||||||||||||||||||||||
148 | } executed 22 times by 1 test: end of block Executed by:
| 22 | ||||||||||||||||||||||||
149 | else if (e == QKeySequence::SelectPreviousChar) {
| 26-788 | ||||||||||||||||||||||||
150 | op = QTextCursor::Left; | - | ||||||||||||||||||||||||
151 | mode = QTextCursor::KeepAnchor; | - | ||||||||||||||||||||||||
152 | } executed 26 times by 1 test: end of block Executed by:
| 26 | ||||||||||||||||||||||||
153 | else if (e == QKeySequence::SelectNextWord) {
| 6-782 | ||||||||||||||||||||||||
154 | op = QTextCursor::WordRight; | - | ||||||||||||||||||||||||
155 | mode = QTextCursor::KeepAnchor; | - | ||||||||||||||||||||||||
156 | } executed 6 times by 1 test: end of block Executed by:
| 6 | ||||||||||||||||||||||||
157 | else if (e == QKeySequence::SelectPreviousWord) {
| 6-776 | ||||||||||||||||||||||||
158 | op = QTextCursor::WordLeft; | - | ||||||||||||||||||||||||
159 | mode = QTextCursor::KeepAnchor; | - | ||||||||||||||||||||||||
160 | } executed 6 times by 1 test: end of block Executed by:
| 6 | ||||||||||||||||||||||||
161 | else if (e == QKeySequence::SelectStartOfLine) {
| 6-770 | ||||||||||||||||||||||||
162 | op = QTextCursor::StartOfLine; | - | ||||||||||||||||||||||||
163 | mode = QTextCursor::KeepAnchor; | - | ||||||||||||||||||||||||
164 | } executed 6 times by 1 test: end of block Executed by:
| 6 | ||||||||||||||||||||||||
165 | else if (e == QKeySequence::SelectEndOfLine) {
| 4-766 | ||||||||||||||||||||||||
166 | op = QTextCursor::EndOfLine; | - | ||||||||||||||||||||||||
167 | mode = QTextCursor::KeepAnchor; | - | ||||||||||||||||||||||||
168 | } executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||||||||||||||
169 | else if (e == QKeySequence::SelectStartOfBlock) {
| 0-766 | ||||||||||||||||||||||||
170 | op = QTextCursor::StartOfBlock; | - | ||||||||||||||||||||||||
171 | mode = QTextCursor::KeepAnchor; | - | ||||||||||||||||||||||||
172 | } never executed: end of block | 0 | ||||||||||||||||||||||||
173 | else if (e == QKeySequence::SelectEndOfBlock) {
| 0-766 | ||||||||||||||||||||||||
174 | op = QTextCursor::EndOfBlock; | - | ||||||||||||||||||||||||
175 | mode = QTextCursor::KeepAnchor; | - | ||||||||||||||||||||||||
176 | } never executed: end of block | 0 | ||||||||||||||||||||||||
177 | else if (e == QKeySequence::SelectStartOfDocument) {
| 0-766 | ||||||||||||||||||||||||
178 | op = QTextCursor::Start; | - | ||||||||||||||||||||||||
179 | mode = QTextCursor::KeepAnchor; | - | ||||||||||||||||||||||||
180 | } never executed: end of block | 0 | ||||||||||||||||||||||||
181 | else if (e == QKeySequence::SelectEndOfDocument) {
| 2-764 | ||||||||||||||||||||||||
182 | op = QTextCursor::End; | - | ||||||||||||||||||||||||
183 | mode = QTextCursor::KeepAnchor; | - | ||||||||||||||||||||||||
184 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||||||||
185 | else if (e == QKeySequence::SelectPreviousLine) {
| 0-764 | ||||||||||||||||||||||||
186 | op = QTextCursor::Up; | - | ||||||||||||||||||||||||
187 | mode = QTextCursor::KeepAnchor; | - | ||||||||||||||||||||||||
188 | } never executed: end of block | 0 | ||||||||||||||||||||||||
189 | else if (e == QKeySequence::SelectNextLine) {
| 0-764 | ||||||||||||||||||||||||
190 | op = QTextCursor::Down; | - | ||||||||||||||||||||||||
191 | mode = QTextCursor::KeepAnchor; | - | ||||||||||||||||||||||||
192 | { | - | ||||||||||||||||||||||||
193 | QTextBlock block = cursor.block(); | - | ||||||||||||||||||||||||
194 | QTextLine line = currentTextLine(cursor); | - | ||||||||||||||||||||||||
195 | if (!block.next().isValid()
| 0 | ||||||||||||||||||||||||
196 | && line.isValid()
| 0 | ||||||||||||||||||||||||
197 | && line.lineNumber() == block.layout()->lineCount() - 1)
| 0 | ||||||||||||||||||||||||
198 | op = QTextCursor::End; never executed: op = QTextCursor::End; | 0 | ||||||||||||||||||||||||
199 | } | - | ||||||||||||||||||||||||
200 | } never executed: end of block | 0 | ||||||||||||||||||||||||
201 | else if (e == QKeySequence::MoveToNextWord) {
| 4-760 | ||||||||||||||||||||||||
202 | op = QTextCursor::WordRight; | - | ||||||||||||||||||||||||
203 | } executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||||||||||||||
204 | else if (e == QKeySequence::MoveToPreviousWord) {
| 4-756 | ||||||||||||||||||||||||
205 | op = QTextCursor::WordLeft; | - | ||||||||||||||||||||||||
206 | } executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||||||||||||||
207 | else if (e == QKeySequence::MoveToEndOfBlock) {
| 0-756 | ||||||||||||||||||||||||
208 | op = QTextCursor::EndOfBlock; | - | ||||||||||||||||||||||||
209 | } never executed: end of block | 0 | ||||||||||||||||||||||||
210 | else if (e == QKeySequence::MoveToStartOfBlock) {
| 0-756 | ||||||||||||||||||||||||
211 | op = QTextCursor::StartOfBlock; | - | ||||||||||||||||||||||||
212 | } never executed: end of block | 0 | ||||||||||||||||||||||||
213 | else if (e == QKeySequence::MoveToNextLine) {
| 0-756 | ||||||||||||||||||||||||
214 | op = QTextCursor::Down; | - | ||||||||||||||||||||||||
215 | } never executed: end of block | 0 | ||||||||||||||||||||||||
216 | else if (e == QKeySequence::MoveToPreviousLine) {
| 0-756 | ||||||||||||||||||||||||
217 | op = QTextCursor::Up; | - | ||||||||||||||||||||||||
218 | } never executed: end of block | 0 | ||||||||||||||||||||||||
219 | else if (e == QKeySequence::MoveToStartOfLine) {
| 10-746 | ||||||||||||||||||||||||
220 | op = QTextCursor::StartOfLine; | - | ||||||||||||||||||||||||
221 | } executed 10 times by 1 test: end of block Executed by:
| 10 | ||||||||||||||||||||||||
222 | else if (e == QKeySequence::MoveToEndOfLine) {
| 2-744 | ||||||||||||||||||||||||
223 | op = QTextCursor::EndOfLine; | - | ||||||||||||||||||||||||
224 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||||||||
225 | else if (e == QKeySequence::MoveToStartOfDocument) {
| 0-744 | ||||||||||||||||||||||||
226 | op = QTextCursor::Start; | - | ||||||||||||||||||||||||
227 | } never executed: end of block | 0 | ||||||||||||||||||||||||
228 | else if (e == QKeySequence::MoveToEndOfDocument) {
| 0-744 | ||||||||||||||||||||||||
229 | op = QTextCursor::End; | - | ||||||||||||||||||||||||
230 | } never executed: end of block | 0 | ||||||||||||||||||||||||
231 | #endif // shortcut | - | ||||||||||||||||||||||||
232 | else { | - | ||||||||||||||||||||||||
233 | return false; executed 744 times by 2 tests: return false; Executed by:
| 744 | ||||||||||||||||||||||||
234 | } | - | ||||||||||||||||||||||||
235 | - | |||||||||||||||||||||||||
236 | // Except for pageup and pagedown, OS X has very different behavior, we don't do it all, but | - | ||||||||||||||||||||||||
237 | // here's the breakdown: | - | ||||||||||||||||||||||||
238 | // Shift still works as an anchor, but only one of the other keys can be down Ctrl (Command), | - | ||||||||||||||||||||||||
239 | // Alt (Option), or Meta (Control). | - | ||||||||||||||||||||||||
240 | // Command/Control + Left/Right -- Move to left or right of the line | - | ||||||||||||||||||||||||
241 | // + Up/Down -- Move to top bottom of the file. (Control doesn't move the cursor) | - | ||||||||||||||||||||||||
242 | // Option + Left/Right -- Move one word Left/right. | - | ||||||||||||||||||||||||
243 | // + Up/Down -- Begin/End of Paragraph. | - | ||||||||||||||||||||||||
244 | // Home/End Top/Bottom of file. (usually don't move the cursor, but will select) | - | ||||||||||||||||||||||||
245 | - | |||||||||||||||||||||||||
246 | bool visualNavigation = cursor.visualNavigation(); | - | ||||||||||||||||||||||||
247 | cursor.setVisualNavigation(true); | - | ||||||||||||||||||||||||
248 | const bool moved = cursor.movePosition(op, mode); | - | ||||||||||||||||||||||||
249 | cursor.setVisualNavigation(visualNavigation); | - | ||||||||||||||||||||||||
250 | - | |||||||||||||||||||||||||
251 | bool isNavigationEvent | - | ||||||||||||||||||||||||
252 | = e->key() == Qt::Key_Up
| 0-146 | ||||||||||||||||||||||||
253 | || e->key() == Qt::Key_Down
| 0-146 | ||||||||||||||||||||||||
254 | || e->key() == Qt::Key_Left
| 46-100 | ||||||||||||||||||||||||
255 | || e->key() == Qt::Key_Right;
| 48-52 | ||||||||||||||||||||||||
256 | - | |||||||||||||||||||||||||
257 | if (moved) {
| 18-128 | ||||||||||||||||||||||||
258 | if (cursor.position() != oldCursorPos)
| 0-128 | ||||||||||||||||||||||||
259 | emit q->cursorPositionChanged(); executed 128 times by 2 tests: q->cursorPositionChanged(); Executed by:
| 128 | ||||||||||||||||||||||||
260 | q->updateCursorRectangle(true); | - | ||||||||||||||||||||||||
261 | } else if (isNavigationEvent && oldSelection.anchor() == cursor.anchor()) { executed 128 times by 2 tests: end of block Executed by:
| 0-128 | ||||||||||||||||||||||||
262 | return false; executed 14 times by 2 tests: return false; Executed by:
| 14 | ||||||||||||||||||||||||
263 | } | - | ||||||||||||||||||||||||
264 | - | |||||||||||||||||||||||||
265 | selectionChanged(/*forceEmitSelectionChanged =*/(mode == QTextCursor::KeepAnchor)); | - | ||||||||||||||||||||||||
266 | - | |||||||||||||||||||||||||
267 | repaintOldAndNewSelection(oldSelection); | - | ||||||||||||||||||||||||
268 | - | |||||||||||||||||||||||||
269 | return true; executed 132 times by 2 tests: return true; Executed by:
| 132 | ||||||||||||||||||||||||
270 | } | - | ||||||||||||||||||||||||
271 | - | |||||||||||||||||||||||||
272 | void QQuickTextControlPrivate::updateCurrentCharFormat() | - | ||||||||||||||||||||||||
273 | { | - | ||||||||||||||||||||||||
274 | Q_Q(QQuickTextControl); | - | ||||||||||||||||||||||||
275 | - | |||||||||||||||||||||||||
276 | QTextCharFormat fmt = cursor.charFormat(); | - | ||||||||||||||||||||||||
277 | if (fmt == lastCharFormat)
| 10-7560 | ||||||||||||||||||||||||
278 | return; executed 7560 times by 6 tests: return; Executed by:
| 7560 | ||||||||||||||||||||||||
279 | lastCharFormat = fmt; | - | ||||||||||||||||||||||||
280 | - | |||||||||||||||||||||||||
281 | emit q->currentCharFormatChanged(fmt); | - | ||||||||||||||||||||||||
282 | cursorRectangleChanged = true; | - | ||||||||||||||||||||||||
283 | } executed 10 times by 1 test: end of block Executed by:
| 10 | ||||||||||||||||||||||||
284 | - | |||||||||||||||||||||||||
285 | void QQuickTextControlPrivate::setContent(Qt::TextFormat format, const QString &text) | - | ||||||||||||||||||||||||
286 | { | - | ||||||||||||||||||||||||
287 | Q_Q(QQuickTextControl); | - | ||||||||||||||||||||||||
288 | - | |||||||||||||||||||||||||
289 | #if QT_CONFIG(im) | - | ||||||||||||||||||||||||
290 | cancelPreedit(); | - | ||||||||||||||||||||||||
291 | #endif | - | ||||||||||||||||||||||||
292 | - | |||||||||||||||||||||||||
293 | // for use when called from setPlainText. we may want to re-use the currently | - | ||||||||||||||||||||||||
294 | // set char format then. | - | ||||||||||||||||||||||||
295 | const QTextCharFormat charFormatForInsertion = cursor.charFormat(); | - | ||||||||||||||||||||||||
296 | - | |||||||||||||||||||||||||
297 | bool previousUndoRedoState = doc->isUndoRedoEnabled(); | - | ||||||||||||||||||||||||
298 | doc->setUndoRedoEnabled(false); | - | ||||||||||||||||||||||||
299 | - | |||||||||||||||||||||||||
300 | const int oldCursorPos = cursor.position(); | - | ||||||||||||||||||||||||
301 | - | |||||||||||||||||||||||||
302 | // avoid multiple textChanged() signals being emitted | - | ||||||||||||||||||||||||
303 | qmlobject_disconnect(doc, QTextDocument, SIGNAL(contentsChanged()), q, QQuickTextControl, SIGNAL(textChanged())); executed 10 times by 5 tests: end of block Executed by:
never executed: methodIdx = QQuickTextControl::staticMetaObject.indexOfSlot(method+1); executed 10 times by 5 tests: methodIdx = QQuickTextControl::staticMetaObject.indexOfSignal(method+1); Executed by:
| 0-1058 | ||||||||||||||||||||||||
304 | - | |||||||||||||||||||||||||
305 | if (!text.isEmpty()) {
| 24-1044 | ||||||||||||||||||||||||
306 | // clear 'our' cursor for insertion to prevent | - | ||||||||||||||||||||||||
307 | // the emission of the cursorPositionChanged() signal. | - | ||||||||||||||||||||||||
308 | // instead we emit it only once at the end instead of | - | ||||||||||||||||||||||||
309 | // at the end of the document after loading and when | - | ||||||||||||||||||||||||
310 | // positioning the cursor again to the start of the | - | ||||||||||||||||||||||||
311 | // document. | - | ||||||||||||||||||||||||
312 | cursor = QTextCursor(); | - | ||||||||||||||||||||||||
313 | if (format == Qt::PlainText) {
| 94-950 | ||||||||||||||||||||||||
314 | QTextCursor formatCursor(doc); | - | ||||||||||||||||||||||||
315 | // put the setPlainText and the setCharFormat into one edit block, | - | ||||||||||||||||||||||||
316 | // so that the syntax highlight triggers only /once/ for the entire | - | ||||||||||||||||||||||||
317 | // document, not twice. | - | ||||||||||||||||||||||||
318 | formatCursor.beginEditBlock(); | - | ||||||||||||||||||||||||
319 | doc->setPlainText(text); | - | ||||||||||||||||||||||||
320 | doc->setUndoRedoEnabled(false); | - | ||||||||||||||||||||||||
321 | formatCursor.select(QTextCursor::Document); | - | ||||||||||||||||||||||||
322 | formatCursor.setCharFormat(charFormatForInsertion); | - | ||||||||||||||||||||||||
323 | formatCursor.endEditBlock(); | - | ||||||||||||||||||||||||
324 | } else { executed 950 times by 5 tests: end of block Executed by:
| 950 | ||||||||||||||||||||||||
325 | #if QT_CONFIG(texthtmlparser) | - | ||||||||||||||||||||||||
326 | doc->setHtml(text); | - | ||||||||||||||||||||||||
327 | #else | - | ||||||||||||||||||||||||
328 | doc->setPlainText(text); | - | ||||||||||||||||||||||||
329 | #endif | - | ||||||||||||||||||||||||
330 | doc->setUndoRedoEnabled(false); | - | ||||||||||||||||||||||||
331 | } executed 94 times by 3 tests: end of block Executed by:
| 94 | ||||||||||||||||||||||||
332 | cursor = QTextCursor(doc); | - | ||||||||||||||||||||||||
333 | } else { executed 1044 times by 5 tests: end of block Executed by:
| 1044 | ||||||||||||||||||||||||
334 | doc->clear(); | - | ||||||||||||||||||||||||
335 | } executed 24 times by 1 test: end of block Executed by:
| 24 | ||||||||||||||||||||||||
336 | cursor.setCharFormat(charFormatForInsertion); | - | ||||||||||||||||||||||||
337 | - | |||||||||||||||||||||||||
338 | qmlobject_connect(doc, QTextDocument, SIGNAL(contentsChanged()), q, QQuickTextControl, SIGNAL(textChanged())); executed 10 times by 5 tests: end of block Executed by:
never executed: methodIdx = QQuickTextControl::staticMetaObject.indexOfSlot(method+1); executed 10 times by 5 tests: methodIdx = QQuickTextControl::staticMetaObject.indexOfSignal(method+1); Executed by:
| 0-1058 | ||||||||||||||||||||||||
339 | emit q->textChanged(); | - | ||||||||||||||||||||||||
340 | doc->setUndoRedoEnabled(previousUndoRedoState); | - | ||||||||||||||||||||||||
341 | _q_updateCurrentCharFormatAndSelection(); | - | ||||||||||||||||||||||||
342 | doc->setModified(false); | - | ||||||||||||||||||||||||
343 | - | |||||||||||||||||||||||||
344 | q->updateCursorRectangle(true); | - | ||||||||||||||||||||||||
345 | if (cursor.position() != oldCursorPos)
| 20-1048 | ||||||||||||||||||||||||
346 | emit q->cursorPositionChanged(); executed 20 times by 1 test: q->cursorPositionChanged(); Executed by:
| 20 | ||||||||||||||||||||||||
347 | } executed 1068 times by 5 tests: end of block Executed by:
| 1068 | ||||||||||||||||||||||||
348 | - | |||||||||||||||||||||||||
349 | void QQuickTextControlPrivate::setCursorPosition(const QPointF &pos) | - | ||||||||||||||||||||||||
350 | { | - | ||||||||||||||||||||||||
351 | Q_Q(QQuickTextControl); | - | ||||||||||||||||||||||||
352 | const int cursorPos = q->hitTest(pos, Qt::FuzzyHit); | - | ||||||||||||||||||||||||
353 | if (cursorPos == -1)
| 0-106 | ||||||||||||||||||||||||
354 | return; never executed: return; | 0 | ||||||||||||||||||||||||
355 | cursor.setPosition(cursorPos); | - | ||||||||||||||||||||||||
356 | } executed 106 times by 1 test: end of block Executed by:
| 106 | ||||||||||||||||||||||||
357 | - | |||||||||||||||||||||||||
358 | void QQuickTextControlPrivate::setCursorPosition(int pos, QTextCursor::MoveMode mode) | - | ||||||||||||||||||||||||
359 | { | - | ||||||||||||||||||||||||
360 | cursor.setPosition(pos, mode); | - | ||||||||||||||||||||||||
361 | - | |||||||||||||||||||||||||
362 | if (mode != QTextCursor::KeepAnchor) {
| 132-332 | ||||||||||||||||||||||||
363 | selectedWordOnDoubleClick = QTextCursor(); | - | ||||||||||||||||||||||||
364 | selectedBlockOnTripleClick = QTextCursor(); | - | ||||||||||||||||||||||||
365 | } executed 332 times by 1 test: end of block Executed by:
| 332 | ||||||||||||||||||||||||
366 | } executed 464 times by 1 test: end of block Executed by:
| 464 | ||||||||||||||||||||||||
367 | - | |||||||||||||||||||||||||
368 | void QQuickTextControlPrivate::repaintCursor() | - | ||||||||||||||||||||||||
369 | { | - | ||||||||||||||||||||||||
370 | Q_Q(QQuickTextControl); | - | ||||||||||||||||||||||||
371 | emit q->updateCursorRequest(); | - | ||||||||||||||||||||||||
372 | } executed 2022 times by 6 tests: end of block Executed by:
| 2022 | ||||||||||||||||||||||||
373 | - | |||||||||||||||||||||||||
374 | void QQuickTextControlPrivate::repaintOldAndNewSelection(const QTextCursor &oldSelection) | - | ||||||||||||||||||||||||
375 | { | - | ||||||||||||||||||||||||
376 | Q_Q(QQuickTextControl); | - | ||||||||||||||||||||||||
377 | if (cursor.hasSelection()
| 1376-2266 | ||||||||||||||||||||||||
378 | && oldSelection.hasSelection()
| 568-808 | ||||||||||||||||||||||||
379 | && cursor.currentFrame() == oldSelection.currentFrame()
| 0-808 | ||||||||||||||||||||||||
380 | && !cursor.hasComplexSelection()
| 0-808 | ||||||||||||||||||||||||
381 | && !oldSelection.hasComplexSelection()
| 0-808 | ||||||||||||||||||||||||
382 | && cursor.anchor() == oldSelection.anchor()
| 156-652 | ||||||||||||||||||||||||
383 | ) { | - | ||||||||||||||||||||||||
384 | QTextCursor differenceSelection(doc); | - | ||||||||||||||||||||||||
385 | differenceSelection.setPosition(oldSelection.position()); | - | ||||||||||||||||||||||||
386 | differenceSelection.setPosition(cursor.position(), QTextCursor::KeepAnchor); | - | ||||||||||||||||||||||||
387 | emit q->updateRequest(); | - | ||||||||||||||||||||||||
388 | } else { executed 652 times by 1 test: end of block Executed by:
| 652 | ||||||||||||||||||||||||
389 | if (!oldSelection.hasSelection() && !cursor.hasSelection()) {
| 344-2646 | ||||||||||||||||||||||||
390 | if (!oldSelection.isNull())
| 936-1142 | ||||||||||||||||||||||||
391 | emit q->updateCursorRequest(); executed 1142 times by 3 tests: q->updateCursorRequest(); Executed by:
| 1142 | ||||||||||||||||||||||||
392 | emit q->updateCursorRequest(); | - | ||||||||||||||||||||||||
393 | - | |||||||||||||||||||||||||
394 | } else { executed 2078 times by 3 tests: end of block Executed by:
| 2078 | ||||||||||||||||||||||||
395 | if (!oldSelection.isNull())
| 26-886 | ||||||||||||||||||||||||
396 | emit q->updateRequest(); executed 886 times by 1 test: q->updateRequest(); Executed by:
| 886 | ||||||||||||||||||||||||
397 | emit q->updateRequest(); | - | ||||||||||||||||||||||||
398 | } executed 912 times by 1 test: end of block Executed by:
| 912 | ||||||||||||||||||||||||
399 | } | - | ||||||||||||||||||||||||
400 | } | - | ||||||||||||||||||||||||
401 | - | |||||||||||||||||||||||||
402 | void QQuickTextControlPrivate::selectionChanged(bool forceEmitSelectionChanged /*=false*/) | - | ||||||||||||||||||||||||
403 | { | - | ||||||||||||||||||||||||
404 | Q_Q(QQuickTextControl); | - | ||||||||||||||||||||||||
405 | if (forceEmitSelectionChanged) {
| 792-7852 | ||||||||||||||||||||||||
406 | #if QT_CONFIG(im) | - | ||||||||||||||||||||||||
407 | if (hasFocus)
| 22-770 | ||||||||||||||||||||||||
408 | qGuiApp->inputMethod()->update(Qt::ImCurrentSelection); executed 770 times by 1 test: (static_cast<QGuiApplication *>(QCoreApplication::instance()))->inputMethod()->update(Qt::ImCurrentSelection); Executed by:
| 770 | ||||||||||||||||||||||||
409 | #endif | - | ||||||||||||||||||||||||
410 | emit q->selectionChanged(); | - | ||||||||||||||||||||||||
411 | } executed 792 times by 1 test: end of block Executed by:
| 792 | ||||||||||||||||||||||||
412 | - | |||||||||||||||||||||||||
413 | bool current = cursor.hasSelection(); | - | ||||||||||||||||||||||||
414 | int selectionStart = cursor.selectionStart(); | - | ||||||||||||||||||||||||
415 | int selectionEnd = cursor.selectionEnd(); | - | ||||||||||||||||||||||||
416 | if (current == lastSelectionState && (!current || (selectionStart == lastSelectionStart && selectionEnd == lastSelectionEnd)))
| 184-7890 | ||||||||||||||||||||||||
417 | return; executed 7484 times by 6 tests: return; Executed by:
| 7484 | ||||||||||||||||||||||||
418 | - | |||||||||||||||||||||||||
419 | if (lastSelectionState != current) {
| 406-754 | ||||||||||||||||||||||||
420 | lastSelectionState = current; | - | ||||||||||||||||||||||||
421 | emit q->copyAvailable(current); | - | ||||||||||||||||||||||||
422 | } executed 754 times by 1 test: end of block Executed by:
| 754 | ||||||||||||||||||||||||
423 | - | |||||||||||||||||||||||||
424 | lastSelectionStart = selectionStart; | - | ||||||||||||||||||||||||
425 | lastSelectionEnd = selectionEnd; | - | ||||||||||||||||||||||||
426 | - | |||||||||||||||||||||||||
427 | if (!forceEmitSelectionChanged) {
| 184-976 | ||||||||||||||||||||||||
428 | #if QT_CONFIG(im) | - | ||||||||||||||||||||||||
429 | if (hasFocus)
| 422-554 | ||||||||||||||||||||||||
430 | qGuiApp->inputMethod()->update(Qt::ImCurrentSelection); executed 422 times by 1 test: (static_cast<QGuiApplication *>(QCoreApplication::instance()))->inputMethod()->update(Qt::ImCurrentSelection); Executed by:
| 422 | ||||||||||||||||||||||||
431 | #endif | - | ||||||||||||||||||||||||
432 | emit q->selectionChanged(); | - | ||||||||||||||||||||||||
433 | } executed 976 times by 1 test: end of block Executed by:
| 976 | ||||||||||||||||||||||||
434 | q->updateCursorRectangle(true); | - | ||||||||||||||||||||||||
435 | } executed 1160 times by 1 test: end of block Executed by:
| 1160 | ||||||||||||||||||||||||
436 | - | |||||||||||||||||||||||||
437 | void QQuickTextControlPrivate::_q_updateCurrentCharFormatAndSelection() | - | ||||||||||||||||||||||||
438 | { | - | ||||||||||||||||||||||||
439 | updateCurrentCharFormat(); | - | ||||||||||||||||||||||||
440 | selectionChanged(); | - | ||||||||||||||||||||||||
441 | } executed 6768 times by 6 tests: end of block Executed by:
| 6768 | ||||||||||||||||||||||||
442 | - | |||||||||||||||||||||||||
443 | #if QT_CONFIG(clipboard) | - | ||||||||||||||||||||||||
444 | void QQuickTextControlPrivate::setClipboardSelection() | - | ||||||||||||||||||||||||
445 | { | - | ||||||||||||||||||||||||
446 | QClipboard *clipboard = QGuiApplication::clipboard(); | - | ||||||||||||||||||||||||
447 | if (!cursor.hasSelection() || !clipboard->supportsSelection())
| 0-872 | ||||||||||||||||||||||||
448 | return; executed 872 times by 2 tests: return; Executed by:
| 872 | ||||||||||||||||||||||||
449 | Q_Q(QQuickTextControl); | - | ||||||||||||||||||||||||
450 | QMimeData *data = q->createMimeDataFromSelection(); | - | ||||||||||||||||||||||||
451 | clipboard->setMimeData(data, QClipboard::Selection); | - | ||||||||||||||||||||||||
452 | } executed 604 times by 1 test: end of block Executed by:
| 604 | ||||||||||||||||||||||||
453 | #endif | - | ||||||||||||||||||||||||
454 | - | |||||||||||||||||||||||||
455 | void QQuickTextControlPrivate::_q_updateCursorPosChanged(const QTextCursor &someCursor) | - | ||||||||||||||||||||||||
456 | { | - | ||||||||||||||||||||||||
457 | Q_Q(QQuickTextControl); | - | ||||||||||||||||||||||||
458 | if (someCursor.isCopyOf(cursor)) {
| 1042-1056 | ||||||||||||||||||||||||
459 | emit q->cursorPositionChanged(); | - | ||||||||||||||||||||||||
460 | q->updateCursorRectangle(true); | - | ||||||||||||||||||||||||
461 | } executed 1042 times by 1 test: end of block Executed by:
| 1042 | ||||||||||||||||||||||||
462 | } executed 2098 times by 5 tests: end of block Executed by:
| 2098 | ||||||||||||||||||||||||
463 | - | |||||||||||||||||||||||||
464 | void QQuickTextControlPrivate::setBlinkingCursorEnabled(bool enable) | - | ||||||||||||||||||||||||
465 | { | - | ||||||||||||||||||||||||
466 | if (cursorBlinkingEnabled == enable)
| 454-490 | ||||||||||||||||||||||||
467 | return; executed 454 times by 3 tests: return; Executed by:
| 454 | ||||||||||||||||||||||||
468 | - | |||||||||||||||||||||||||
469 | cursorBlinkingEnabled = enable; | - | ||||||||||||||||||||||||
470 | updateCursorFlashTime(); | - | ||||||||||||||||||||||||
471 | - | |||||||||||||||||||||||||
472 | if (enable)
| 112-378 | ||||||||||||||||||||||||
473 | connect(qApp->styleHints(), &QStyleHints::cursorFlashTimeChanged, this, &QQuickTextControlPrivate::updateCursorFlashTime); executed 378 times by 4 tests: connect((static_cast<QGuiApplication *>(QCoreApplication::instance()))->styleHints(), &QStyleHints::cursorFlashTimeChanged, this, &QQuickTextControlPrivate::updateCursorFlashTime); Executed by:
| 378 | ||||||||||||||||||||||||
474 | else | - | ||||||||||||||||||||||||
475 | disconnect(qApp->styleHints(), &QStyleHints::cursorFlashTimeChanged, this, &QQuickTextControlPrivate::updateCursorFlashTime); executed 112 times by 3 tests: disconnect((static_cast<QGuiApplication *>(QCoreApplication::instance()))->styleHints(), &QStyleHints::cursorFlashTimeChanged, this, &QQuickTextControlPrivate::updateCursorFlashTime); Executed by:
| 112 | ||||||||||||||||||||||||
476 | } | - | ||||||||||||||||||||||||
477 | - | |||||||||||||||||||||||||
478 | void QQuickTextControlPrivate::updateCursorFlashTime() | - | ||||||||||||||||||||||||
479 | { | - | ||||||||||||||||||||||||
480 | // Note: cursorOn represents the current blinking state controlled by a timer, and | - | ||||||||||||||||||||||||
481 | // should not be confused with cursorVisible or cursorBlinkingEnabled. However, we | - | ||||||||||||||||||||||||
482 | // interpretate a cursorFlashTime of 0 to mean "always on, never blink". | - | ||||||||||||||||||||||||
483 | cursorOn = true; | - | ||||||||||||||||||||||||
484 | int flashTime = QGuiApplication::styleHints()->cursorFlashTime(); | - | ||||||||||||||||||||||||
485 | - | |||||||||||||||||||||||||
486 | if (cursorBlinkingEnabled && flashTime >= 2)
| 0-378 | ||||||||||||||||||||||||
487 | cursorBlinkTimer.start(flashTime / 2, q_func()); executed 378 times by 4 tests: cursorBlinkTimer.start(flashTime / 2, q_func()); Executed by:
| 378 | ||||||||||||||||||||||||
488 | else | - | ||||||||||||||||||||||||
489 | cursorBlinkTimer.stop(); executed 112 times by 3 tests: cursorBlinkTimer.stop(); Executed by:
| 112 | ||||||||||||||||||||||||
490 | - | |||||||||||||||||||||||||
491 | repaintCursor(); | - | ||||||||||||||||||||||||
492 | } executed 490 times by 4 tests: end of block Executed by:
| 490 | ||||||||||||||||||||||||
493 | - | |||||||||||||||||||||||||
494 | void QQuickTextControlPrivate::extendWordwiseSelection(int suggestedNewPosition, qreal mouseXPosition) | - | ||||||||||||||||||||||||
495 | { | - | ||||||||||||||||||||||||
496 | Q_Q(QQuickTextControl); | - | ||||||||||||||||||||||||
497 | - | |||||||||||||||||||||||||
498 | // if inside the initial selected word keep that | - | ||||||||||||||||||||||||
499 | if (suggestedNewPosition >= selectedWordOnDoubleClick.selectionStart()
| 32-50 | ||||||||||||||||||||||||
500 | && suggestedNewPosition <= selectedWordOnDoubleClick.selectionEnd()) {
| 18-32 | ||||||||||||||||||||||||
501 | q->setTextCursor(selectedWordOnDoubleClick); | - | ||||||||||||||||||||||||
502 | return; executed 18 times by 1 test: return; Executed by:
| 18 | ||||||||||||||||||||||||
503 | } | - | ||||||||||||||||||||||||
504 | - | |||||||||||||||||||||||||
505 | QTextCursor curs = selectedWordOnDoubleClick; | - | ||||||||||||||||||||||||
506 | curs.setPosition(suggestedNewPosition, QTextCursor::KeepAnchor); | - | ||||||||||||||||||||||||
507 | - | |||||||||||||||||||||||||
508 | if (!curs.movePosition(QTextCursor::StartOfWord))
| 0-64 | ||||||||||||||||||||||||
509 | return; never executed: return; | 0 | ||||||||||||||||||||||||
510 | const int wordStartPos = curs.position(); | - | ||||||||||||||||||||||||
511 | - | |||||||||||||||||||||||||
512 | const int blockPos = curs.block().position(); | - | ||||||||||||||||||||||||
513 | const QPointF blockCoordinates = q->blockBoundingRect(curs.block()).topLeft(); | - | ||||||||||||||||||||||||
514 | - | |||||||||||||||||||||||||
515 | QTextLine line = currentTextLine(curs); | - | ||||||||||||||||||||||||
516 | if (!line.isValid())
| 0-64 | ||||||||||||||||||||||||
517 | return; never executed: return; | 0 | ||||||||||||||||||||||||
518 | - | |||||||||||||||||||||||||
519 | const qreal wordStartX = line.cursorToX(curs.position() - blockPos) + blockCoordinates.x(); | - | ||||||||||||||||||||||||
520 | - | |||||||||||||||||||||||||
521 | if (!curs.movePosition(QTextCursor::EndOfWord))
| 0-64 | ||||||||||||||||||||||||
522 | return; never executed: return; | 0 | ||||||||||||||||||||||||
523 | const int wordEndPos = curs.position(); | - | ||||||||||||||||||||||||
524 | - | |||||||||||||||||||||||||
525 | const QTextLine otherLine = currentTextLine(curs); | - | ||||||||||||||||||||||||
526 | if (otherLine.textStart() != line.textStart()
| 0-64 | ||||||||||||||||||||||||
527 | || wordEndPos == wordStartPos)
| 0-64 | ||||||||||||||||||||||||
528 | return; never executed: return; | 0 | ||||||||||||||||||||||||
529 | - | |||||||||||||||||||||||||
530 | const qreal wordEndX = line.cursorToX(curs.position() - blockPos) + blockCoordinates.x(); | - | ||||||||||||||||||||||||
531 | - | |||||||||||||||||||||||||
532 | if (!wordSelectionEnabled && (mouseXPosition < wordStartX || mouseXPosition > wordEndX))
| 0-32 | ||||||||||||||||||||||||
533 | return; never executed: return; | 0 | ||||||||||||||||||||||||
534 | - | |||||||||||||||||||||||||
535 | if (suggestedNewPosition < selectedWordOnDoubleClick.position()) {
| 32 | ||||||||||||||||||||||||
536 | cursor.setPosition(selectedWordOnDoubleClick.selectionEnd()); | - | ||||||||||||||||||||||||
537 | setCursorPosition(wordStartPos, QTextCursor::KeepAnchor); | - | ||||||||||||||||||||||||
538 | } else { executed 32 times by 1 test: end of block Executed by:
| 32 | ||||||||||||||||||||||||
539 | cursor.setPosition(selectedWordOnDoubleClick.selectionStart()); | - | ||||||||||||||||||||||||
540 | setCursorPosition(wordEndPos, QTextCursor::KeepAnchor); | - | ||||||||||||||||||||||||
541 | } executed 32 times by 1 test: end of block Executed by:
| 32 | ||||||||||||||||||||||||
542 | - | |||||||||||||||||||||||||
543 | if (interactionFlags & Qt::TextSelectableByMouse) {
| 0-64 | ||||||||||||||||||||||||
544 | #if QT_CONFIG(clipboard) | - | ||||||||||||||||||||||||
545 | setClipboardSelection(); | - | ||||||||||||||||||||||||
546 | #endif | - | ||||||||||||||||||||||||
547 | selectionChanged(true); | - | ||||||||||||||||||||||||
548 | } executed 64 times by 1 test: end of block Executed by:
| 64 | ||||||||||||||||||||||||
549 | } executed 64 times by 1 test: end of block Executed by:
| 64 | ||||||||||||||||||||||||
550 | - | |||||||||||||||||||||||||
551 | void QQuickTextControlPrivate::extendBlockwiseSelection(int suggestedNewPosition) | - | ||||||||||||||||||||||||
552 | { | - | ||||||||||||||||||||||||
553 | Q_Q(QQuickTextControl); | - | ||||||||||||||||||||||||
554 | - | |||||||||||||||||||||||||
555 | // if inside the initial selected line keep that | - | ||||||||||||||||||||||||
556 | if (suggestedNewPosition >= selectedBlockOnTripleClick.selectionStart()
| 12-56 | ||||||||||||||||||||||||
557 | && suggestedNewPosition <= selectedBlockOnTripleClick.selectionEnd()) {
| 20-36 | ||||||||||||||||||||||||
558 | q->setTextCursor(selectedBlockOnTripleClick); | - | ||||||||||||||||||||||||
559 | return; executed 36 times by 1 test: return; Executed by:
| 36 | ||||||||||||||||||||||||
560 | } | - | ||||||||||||||||||||||||
561 | - | |||||||||||||||||||||||||
562 | if (suggestedNewPosition < selectedBlockOnTripleClick.position()) {
| 12-20 | ||||||||||||||||||||||||
563 | cursor.setPosition(selectedBlockOnTripleClick.selectionEnd()); | - | ||||||||||||||||||||||||
564 | cursor.setPosition(suggestedNewPosition, QTextCursor::KeepAnchor); | - | ||||||||||||||||||||||||
565 | cursor.movePosition(QTextCursor::StartOfBlock, QTextCursor::KeepAnchor); | - | ||||||||||||||||||||||||
566 | } else { executed 12 times by 1 test: end of block Executed by:
| 12 | ||||||||||||||||||||||||
567 | cursor.setPosition(selectedBlockOnTripleClick.selectionStart()); | - | ||||||||||||||||||||||||
568 | cursor.setPosition(suggestedNewPosition, QTextCursor::KeepAnchor); | - | ||||||||||||||||||||||||
569 | cursor.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor); | - | ||||||||||||||||||||||||
570 | cursor.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor); | - | ||||||||||||||||||||||||
571 | } executed 20 times by 1 test: end of block Executed by:
| 20 | ||||||||||||||||||||||||
572 | - | |||||||||||||||||||||||||
573 | if (interactionFlags & Qt::TextSelectableByMouse) {
| 0-32 | ||||||||||||||||||||||||
574 | #if QT_CONFIG(clipboard) | - | ||||||||||||||||||||||||
575 | setClipboardSelection(); | - | ||||||||||||||||||||||||
576 | #endif | - | ||||||||||||||||||||||||
577 | selectionChanged(true); | - | ||||||||||||||||||||||||
578 | } executed 32 times by 1 test: end of block Executed by:
| 32 | ||||||||||||||||||||||||
579 | } executed 32 times by 1 test: end of block Executed by:
| 32 | ||||||||||||||||||||||||
580 | - | |||||||||||||||||||||||||
581 | void QQuickTextControl::undo() | - | ||||||||||||||||||||||||
582 | { | - | ||||||||||||||||||||||||
583 | Q_D(QQuickTextControl); | - | ||||||||||||||||||||||||
584 | d->repaintSelection(); | - | ||||||||||||||||||||||||
585 | const int oldCursorPos = d->cursor.position(); | - | ||||||||||||||||||||||||
586 | d->doc->undo(&d->cursor); | - | ||||||||||||||||||||||||
587 | if (d->cursor.position() != oldCursorPos)
| 24-88 | ||||||||||||||||||||||||
588 | emit cursorPositionChanged(); executed 88 times by 1 test: cursorPositionChanged(); Executed by:
| 88 | ||||||||||||||||||||||||
589 | updateCursorRectangle(true); | - | ||||||||||||||||||||||||
590 | } executed 112 times by 1 test: end of block Executed by:
| 112 | ||||||||||||||||||||||||
591 | - | |||||||||||||||||||||||||
592 | void QQuickTextControl::redo() | - | ||||||||||||||||||||||||
593 | { | - | ||||||||||||||||||||||||
594 | Q_D(QQuickTextControl); | - | ||||||||||||||||||||||||
595 | d->repaintSelection(); | - | ||||||||||||||||||||||||
596 | const int oldCursorPos = d->cursor.position(); | - | ||||||||||||||||||||||||
597 | d->doc->redo(&d->cursor); | - | ||||||||||||||||||||||||
598 | if (d->cursor.position() != oldCursorPos)
| 2-6 | ||||||||||||||||||||||||
599 | emit cursorPositionChanged(); executed 6 times by 1 test: cursorPositionChanged(); Executed by:
| 6 | ||||||||||||||||||||||||
600 | updateCursorRectangle(true); | - | ||||||||||||||||||||||||
601 | } executed 8 times by 1 test: end of block Executed by:
| 8 | ||||||||||||||||||||||||
602 | - | |||||||||||||||||||||||||
603 | void QQuickTextControl::clear() | - | ||||||||||||||||||||||||
604 | { | - | ||||||||||||||||||||||||
605 | Q_D(QQuickTextControl); | - | ||||||||||||||||||||||||
606 | d->cursor.select(QTextCursor::Document); | - | ||||||||||||||||||||||||
607 | d->cursor.removeSelectedText(); | - | ||||||||||||||||||||||||
608 | } executed 6 times by 1 test: end of block Executed by:
| 6 | ||||||||||||||||||||||||
609 | - | |||||||||||||||||||||||||
610 | QQuickTextControl::QQuickTextControl(QTextDocument *doc, QObject *parent) | - | ||||||||||||||||||||||||
611 | : QInputControl(TextEdit, *new QQuickTextControlPrivate, parent) | - | ||||||||||||||||||||||||
612 | { | - | ||||||||||||||||||||||||
613 | Q_D(QQuickTextControl); | - | ||||||||||||||||||||||||
614 | Q_ASSERT(doc); | - | ||||||||||||||||||||||||
615 | - | |||||||||||||||||||||||||
616 | QAbstractTextDocumentLayout *layout = doc->documentLayout(); | - | ||||||||||||||||||||||||
617 | qmlobject_connect(layout, QAbstractTextDocumentLayout, SIGNAL(update(QRectF)), this, QQuickTextControl, SIGNAL(updateRequest())); executed 12 times by 6 tests: end of block Executed by:
never executed: methodIdx = QQuickTextControl::staticMetaObject.indexOfSlot(method+1); executed 12 times by 6 tests: methodIdx = QQuickTextControl::staticMetaObject.indexOfSignal(method+1); Executed by:
| 0-1068 | ||||||||||||||||||||||||
618 | qmlobject_connect(layout, QAbstractTextDocumentLayout, SIGNAL(updateBlock(QTextBlock)), this, QQuickTextControl, SIGNAL(updateRequest())); executed 12 times by 6 tests: end of block Executed by:
never executed: methodIdx = QQuickTextControl::staticMetaObject.indexOfSlot(method+1); executed 12 times by 6 tests: methodIdx = QQuickTextControl::staticMetaObject.indexOfSignal(method+1); Executed by:
| 0-1068 | ||||||||||||||||||||||||
619 | qmlobject_connect(doc, QTextDocument, SIGNAL(contentsChanged()), this, QQuickTextControl, SIGNAL(textChanged())); executed 12 times by 6 tests: end of block Executed by:
never executed: methodIdx = QQuickTextControl::staticMetaObject.indexOfSlot(method+1); executed 12 times by 6 tests: methodIdx = QQuickTextControl::staticMetaObject.indexOfSignal(method+1); Executed by:
| 0-1068 | ||||||||||||||||||||||||
620 | qmlobject_connect(doc, QTextDocument, SIGNAL(contentsChanged()), this, QQuickTextControl, SLOT(_q_updateCurrentCharFormatAndSelection())); executed 12 times by 6 tests: end of block Executed by:
executed 12 times by 6 tests: methodIdx = QQuickTextControl::staticMetaObject.indexOfSlot(method+1); Executed by:
never executed: methodIdx = QQuickTextControl::staticMetaObject.indexOfSignal(method+1);
| 0-1068 | ||||||||||||||||||||||||
621 | qmlobject_connect(doc, QTextDocument, SIGNAL(cursorPositionChanged(QTextCursor)), this, QQuickTextControl, SLOT(_q_updateCursorPosChanged(QTextCursor))); executed 12 times by 6 tests: end of block Executed by:
executed 12 times by 6 tests: methodIdx = QQuickTextControl::staticMetaObject.indexOfSlot(method+1); Executed by:
never executed: methodIdx = QQuickTextControl::staticMetaObject.indexOfSignal(method+1);
| 0-1068 | ||||||||||||||||||||||||
622 | connect(doc, &QTextDocument::contentsChange, this, &QQuickTextControl::contentsChange); | - | ||||||||||||||||||||||||
623 | - | |||||||||||||||||||||||||
624 | layout->setProperty("cursorWidth", textCursorWidth); | - | ||||||||||||||||||||||||
625 | - | |||||||||||||||||||||||||
626 | d->doc = doc; | - | ||||||||||||||||||||||||
627 | d->cursor = QTextCursor(doc); | - | ||||||||||||||||||||||||
628 | d->lastCharFormat = d->cursor.charFormat(); | - | ||||||||||||||||||||||||
629 | doc->setPageSize(QSizeF(0, 0)); | - | ||||||||||||||||||||||||
630 | doc->setModified(false); | - | ||||||||||||||||||||||||
631 | doc->setUndoRedoEnabled(true); | - | ||||||||||||||||||||||||
632 | } executed 1080 times by 6 tests: end of block Executed by:
| 1080 | ||||||||||||||||||||||||
633 | - | |||||||||||||||||||||||||
634 | QQuickTextControl::~QQuickTextControl() | - | ||||||||||||||||||||||||
635 | { | - | ||||||||||||||||||||||||
636 | } | - | ||||||||||||||||||||||||
637 | - | |||||||||||||||||||||||||
638 | QTextDocument *QQuickTextControl::document() const | - | ||||||||||||||||||||||||
639 | { | - | ||||||||||||||||||||||||
640 | Q_D(const QQuickTextControl); | - | ||||||||||||||||||||||||
641 | return d->doc; executed 548 times by 2 tests: return d->doc; Executed by:
| 548 | ||||||||||||||||||||||||
642 | } | - | ||||||||||||||||||||||||
643 | - | |||||||||||||||||||||||||
644 | void QQuickTextControl::updateCursorRectangle(bool force) | - | ||||||||||||||||||||||||
645 | { | - | ||||||||||||||||||||||||
646 | Q_D(QQuickTextControl); | - | ||||||||||||||||||||||||
647 | const bool update = d->cursorRectangleChanged || force;
| 8-7102 | ||||||||||||||||||||||||
648 | d->cursorRectangleChanged = false; | - | ||||||||||||||||||||||||
649 | if (update)
| 108-7002 | ||||||||||||||||||||||||
650 | emit cursorRectangleChanged(); executed 7002 times by 5 tests: cursorRectangleChanged(); Executed by:
| 7002 | ||||||||||||||||||||||||
651 | } executed 7110 times by 5 tests: end of block Executed by:
| 7110 | ||||||||||||||||||||||||
652 | - | |||||||||||||||||||||||||
653 | void QQuickTextControl::setTextCursor(const QTextCursor &cursor) | - | ||||||||||||||||||||||||
654 | { | - | ||||||||||||||||||||||||
655 | Q_D(QQuickTextControl); | - | ||||||||||||||||||||||||
656 | #if QT_CONFIG(im) | - | ||||||||||||||||||||||||
657 | d->commitPreedit(); | - | ||||||||||||||||||||||||
658 | #endif | - | ||||||||||||||||||||||||
659 | d->cursorIsFocusIndicator = false; | - | ||||||||||||||||||||||||
660 | const bool posChanged = cursor.position() != d->cursor.position(); | - | ||||||||||||||||||||||||
661 | const QTextCursor oldSelection = d->cursor; | - | ||||||||||||||||||||||||
662 | d->cursor = cursor; | - | ||||||||||||||||||||||||
663 | d->cursorOn = d->hasFocus && (d->interactionFlags & Qt::TextEditable);
| 358-866 | ||||||||||||||||||||||||
664 | d->_q_updateCurrentCharFormatAndSelection(); | - | ||||||||||||||||||||||||
665 | updateCursorRectangle(true); | - | ||||||||||||||||||||||||
666 | d->repaintOldAndNewSelection(oldSelection); | - | ||||||||||||||||||||||||
667 | if (posChanged)
| 240-984 | ||||||||||||||||||||||||
668 | emit cursorPositionChanged(); executed 984 times by 1 test: cursorPositionChanged(); Executed by:
| 984 | ||||||||||||||||||||||||
669 | } executed 1224 times by 1 test: end of block Executed by:
| 1224 | ||||||||||||||||||||||||
670 | - | |||||||||||||||||||||||||
671 | QTextCursor QQuickTextControl::textCursor() const | - | ||||||||||||||||||||||||
672 | { | - | ||||||||||||||||||||||||
673 | Q_D(const QQuickTextControl); | - | ||||||||||||||||||||||||
674 | return d->cursor; executed 37450 times by 6 tests: return d->cursor; Executed by:
| 37450 | ||||||||||||||||||||||||
675 | } | - | ||||||||||||||||||||||||
676 | - | |||||||||||||||||||||||||
677 | #if QT_CONFIG(clipboard) | - | ||||||||||||||||||||||||
678 | - | |||||||||||||||||||||||||
679 | void QQuickTextControl::cut() | - | ||||||||||||||||||||||||
680 | { | - | ||||||||||||||||||||||||
681 | Q_D(QQuickTextControl); | - | ||||||||||||||||||||||||
682 | if (!(d->interactionFlags & Qt::TextEditable) || !d->cursor.hasSelection())
| 2-6 | ||||||||||||||||||||||||
683 | return; executed 4 times by 1 test: return; Executed by:
| 4 | ||||||||||||||||||||||||
684 | copy(); | - | ||||||||||||||||||||||||
685 | d->cursor.removeSelectedText(); | - | ||||||||||||||||||||||||
686 | } executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||||||||||||||
687 | - | |||||||||||||||||||||||||
688 | void QQuickTextControl::copy() | - | ||||||||||||||||||||||||
689 | { | - | ||||||||||||||||||||||||
690 | Q_D(QQuickTextControl); | - | ||||||||||||||||||||||||
691 | if (!d->cursor.hasSelection())
| 2-10 | ||||||||||||||||||||||||
692 | return; executed 2 times by 1 test: return; Executed by:
| 2 | ||||||||||||||||||||||||
693 | QMimeData *data = createMimeDataFromSelection(); | - | ||||||||||||||||||||||||
694 | QGuiApplication::clipboard()->setMimeData(data); | - | ||||||||||||||||||||||||
695 | } executed 10 times by 1 test: end of block Executed by:
| 10 | ||||||||||||||||||||||||
696 | - | |||||||||||||||||||||||||
697 | void QQuickTextControl::paste(QClipboard::Mode mode) | - | ||||||||||||||||||||||||
698 | { | - | ||||||||||||||||||||||||
699 | const QMimeData *md = QGuiApplication::clipboard()->mimeData(mode); | - | ||||||||||||||||||||||||
700 | if (md)
| 0-14 | ||||||||||||||||||||||||
701 | insertFromMimeData(md); executed 14 times by 1 test: insertFromMimeData(md); Executed by:
| 14 | ||||||||||||||||||||||||
702 | } executed 14 times by 1 test: end of block Executed by:
| 14 | ||||||||||||||||||||||||
703 | #endif | - | ||||||||||||||||||||||||
704 | - | |||||||||||||||||||||||||
705 | void QQuickTextControl::selectAll() | - | ||||||||||||||||||||||||
706 | { | - | ||||||||||||||||||||||||
707 | Q_D(QQuickTextControl); | - | ||||||||||||||||||||||||
708 | const int selectionLength = qAbs(d->cursor.position() - d->cursor.anchor()); | - | ||||||||||||||||||||||||
709 | d->cursor.select(QTextCursor::Document); | - | ||||||||||||||||||||||||
710 | d->selectionChanged(selectionLength != qAbs(d->cursor.position() - d->cursor.anchor())); | - | ||||||||||||||||||||||||
711 | d->cursorIsFocusIndicator = false; | - | ||||||||||||||||||||||||
712 | emit updateRequest(); | - | ||||||||||||||||||||||||
713 | } executed 16 times by 1 test: end of block Executed by:
| 16 | ||||||||||||||||||||||||
714 | - | |||||||||||||||||||||||||
715 | void QQuickTextControl::processEvent(QEvent *e, const QPointF &coordinateOffset) | - | ||||||||||||||||||||||||
716 | { | - | ||||||||||||||||||||||||
717 | QMatrix m; | - | ||||||||||||||||||||||||
718 | m.translate(coordinateOffset.x(), coordinateOffset.y()); | - | ||||||||||||||||||||||||
719 | processEvent(e, m); | - | ||||||||||||||||||||||||
720 | } executed 4734 times by 3 tests: end of block Executed by:
| 4734 | ||||||||||||||||||||||||
721 | - | |||||||||||||||||||||||||
722 | void QQuickTextControl::processEvent(QEvent *e, const QMatrix &matrix) | - | ||||||||||||||||||||||||
723 | { | - | ||||||||||||||||||||||||
724 | Q_D(QQuickTextControl); | - | ||||||||||||||||||||||||
725 | if (d->interactionFlags == Qt::NoTextInteraction) {
| 0-4734 | ||||||||||||||||||||||||
726 | e->ignore(); | - | ||||||||||||||||||||||||
727 | return; never executed: return; | 0 | ||||||||||||||||||||||||
728 | } | - | ||||||||||||||||||||||||
729 | - | |||||||||||||||||||||||||
730 | switch (e->type()) { | - | ||||||||||||||||||||||||
731 | case QEvent::KeyPress: executed 1028 times by 3 tests: case QEvent::KeyPress: Executed by:
| 1028 | ||||||||||||||||||||||||
732 | d->keyPressEvent(static_cast<QKeyEvent *>(e)); | - | ||||||||||||||||||||||||
733 | break; executed 1028 times by 3 tests: break; Executed by:
| 1028 | ||||||||||||||||||||||||
734 | case QEvent::KeyRelease: executed 1012 times by 2 tests: case QEvent::KeyRelease: Executed by:
| 1012 | ||||||||||||||||||||||||
735 | d->keyReleaseEvent(static_cast<QKeyEvent *>(e)); | - | ||||||||||||||||||||||||
736 | break; executed 1012 times by 2 tests: break; Executed by:
| 1012 | ||||||||||||||||||||||||
737 | case QEvent::MouseButtonPress: { executed 514 times by 1 test: case QEvent::MouseButtonPress: Executed by:
| 514 | ||||||||||||||||||||||||
738 | QMouseEvent *ev = static_cast<QMouseEvent *>(e); | - | ||||||||||||||||||||||||
739 | d->mousePressEvent(ev, matrix.map(ev->localPos())); | - | ||||||||||||||||||||||||
740 | break; } executed 514 times by 1 test: break; Executed by:
| 514 | ||||||||||||||||||||||||
741 | case QEvent::MouseMove: { executed 138 times by 1 test: case QEvent::MouseMove: Executed by:
| 138 | ||||||||||||||||||||||||
742 | QMouseEvent *ev = static_cast<QMouseEvent *>(e); | - | ||||||||||||||||||||||||
743 | d->mouseMoveEvent(ev, matrix.map(ev->localPos())); | - | ||||||||||||||||||||||||
744 | break; } executed 138 times by 1 test: break; Executed by:
| 138 | ||||||||||||||||||||||||
745 | case QEvent::MouseButtonRelease: { executed 514 times by 1 test: case QEvent::MouseButtonRelease: Executed by:
| 514 | ||||||||||||||||||||||||
746 | QMouseEvent *ev = static_cast<QMouseEvent *>(e); | - | ||||||||||||||||||||||||
747 | d->mouseReleaseEvent(ev, matrix.map(ev->localPos())); | - | ||||||||||||||||||||||||
748 | break; } executed 514 times by 1 test: break; Executed by:
| 514 | ||||||||||||||||||||||||
749 | case QEvent::MouseButtonDblClick: { executed 104 times by 1 test: case QEvent::MouseButtonDblClick: Executed by:
| 104 | ||||||||||||||||||||||||
750 | QMouseEvent *ev = static_cast<QMouseEvent *>(e); | - | ||||||||||||||||||||||||
751 | d->mouseDoubleClickEvent(ev, matrix.map(ev->localPos())); | - | ||||||||||||||||||||||||
752 | break; } executed 104 times by 1 test: break; Executed by:
| 104 | ||||||||||||||||||||||||
753 | case QEvent::HoverEnter: executed 2 times by 1 test: case QEvent::HoverEnter: Executed by:
| 2 | ||||||||||||||||||||||||
754 | case QEvent::HoverMove: executed 6 times by 1 test: case QEvent::HoverMove: Executed by:
| 6 | ||||||||||||||||||||||||
755 | case QEvent::HoverLeave: { never executed: case QEvent::HoverLeave: | 0 | ||||||||||||||||||||||||
756 | QHoverEvent *ev = static_cast<QHoverEvent *>(e); | - | ||||||||||||||||||||||||
757 | d->hoverEvent(ev, matrix.map(ev->posF())); | - | ||||||||||||||||||||||||
758 | break; } executed 8 times by 1 test: break; Executed by:
| 8 | ||||||||||||||||||||||||
759 | #if QT_CONFIG(im) | - | ||||||||||||||||||||||||
760 | case QEvent::InputMethod: executed 324 times by 1 test: case QEvent::InputMethod: Executed by:
| 324 | ||||||||||||||||||||||||
761 | d->inputMethodEvent(static_cast<QInputMethodEvent *>(e)); | - | ||||||||||||||||||||||||
762 | break; executed 324 times by 1 test: break; Executed by:
| 324 | ||||||||||||||||||||||||
763 | #endif | - | ||||||||||||||||||||||||
764 | case QEvent::FocusIn: executed 338 times by 3 tests: case QEvent::FocusIn: Executed by:
| 338 | ||||||||||||||||||||||||
765 | case QEvent::FocusOut: executed 94 times by 3 tests: case QEvent::FocusOut: Executed by:
| 94 | ||||||||||||||||||||||||
766 | d->focusEvent(static_cast<QFocusEvent *>(e)); | - | ||||||||||||||||||||||||
767 | break; executed 432 times by 3 tests: break; Executed by:
| 432 | ||||||||||||||||||||||||
768 | - | |||||||||||||||||||||||||
769 | case QEvent::ShortcutOverride: executed 660 times by 2 tests: case QEvent::ShortcutOverride: Executed by:
| 660 | ||||||||||||||||||||||||
770 | if (d->interactionFlags & Qt::TextEditable) {
| 40-620 | ||||||||||||||||||||||||
771 | QKeyEvent* ke = static_cast<QKeyEvent *>(e); | - | ||||||||||||||||||||||||
772 | if (isCommonTextEditShortcut(ke))
| 70-550 | ||||||||||||||||||||||||
773 | ke->accept(); executed 550 times by 2 tests: ke->accept(); Executed by:
| 550 | ||||||||||||||||||||||||
774 | } executed 620 times by 2 tests: end of block Executed by:
| 620 | ||||||||||||||||||||||||
775 | break; executed 660 times by 2 tests: break; Executed by:
| 660 | ||||||||||||||||||||||||
776 | default: never executed: default: | 0 | ||||||||||||||||||||||||
777 | break; never executed: break; | 0 | ||||||||||||||||||||||||
778 | } | - | ||||||||||||||||||||||||
779 | } | - | ||||||||||||||||||||||||
780 | - | |||||||||||||||||||||||||
781 | bool QQuickTextControl::event(QEvent *e) | - | ||||||||||||||||||||||||
782 | { | - | ||||||||||||||||||||||||
783 | return QObject::event(e); executed 346 times by 1 test: return QObject::event(e); Executed by:
| 346 | ||||||||||||||||||||||||
784 | } | - | ||||||||||||||||||||||||
785 | - | |||||||||||||||||||||||||
786 | void QQuickTextControl::timerEvent(QTimerEvent *e) | - | ||||||||||||||||||||||||
787 | { | - | ||||||||||||||||||||||||
788 | Q_D(QQuickTextControl); | - | ||||||||||||||||||||||||
789 | if (e->timerId() == d->cursorBlinkTimer.timerId()) {
| 0-346 | ||||||||||||||||||||||||
790 | d->cursorOn = !d->cursorOn; | - | ||||||||||||||||||||||||
791 | - | |||||||||||||||||||||||||
792 | d->repaintCursor(); | - | ||||||||||||||||||||||||
793 | } else if (e->timerId() == d->tripleClickTimer.timerId()) { executed 346 times by 1 test: end of block Executed by:
| 0-346 | ||||||||||||||||||||||||
794 | d->tripleClickTimer.stop(); | - | ||||||||||||||||||||||||
795 | } never executed: end of block | 0 | ||||||||||||||||||||||||
796 | } executed 346 times by 1 test: end of block Executed by:
| 346 | ||||||||||||||||||||||||
797 | - | |||||||||||||||||||||||||
798 | void QQuickTextControl::setPlainText(const QString &text) | - | ||||||||||||||||||||||||
799 | { | - | ||||||||||||||||||||||||
800 | Q_D(QQuickTextControl); | - | ||||||||||||||||||||||||
801 | d->setContent(Qt::PlainText, text); | - | ||||||||||||||||||||||||
802 | } executed 968 times by 5 tests: end of block Executed by:
| 968 | ||||||||||||||||||||||||
803 | - | |||||||||||||||||||||||||
804 | void QQuickTextControl::setHtml(const QString &text) | - | ||||||||||||||||||||||||
805 | { | - | ||||||||||||||||||||||||
806 | Q_D(QQuickTextControl); | - | ||||||||||||||||||||||||
807 | d->setContent(Qt::RichText, text); | - | ||||||||||||||||||||||||
808 | } executed 100 times by 3 tests: end of block Executed by:
| 100 | ||||||||||||||||||||||||
809 | - | |||||||||||||||||||||||||
810 | - | |||||||||||||||||||||||||
811 | void QQuickTextControlPrivate::keyReleaseEvent(QKeyEvent *e) | - | ||||||||||||||||||||||||
812 | { | - | ||||||||||||||||||||||||
813 | if (e->key() == Qt::Key_Back) {
| 0-1012 | ||||||||||||||||||||||||
814 | e->ignore(); | - | ||||||||||||||||||||||||
815 | return; never executed: return; | 0 | ||||||||||||||||||||||||
816 | } | - | ||||||||||||||||||||||||
817 | return; executed 1012 times by 2 tests: return; Executed by:
| 1012 | ||||||||||||||||||||||||
818 | } | - | ||||||||||||||||||||||||
819 | - | |||||||||||||||||||||||||
820 | void QQuickTextControlPrivate::keyPressEvent(QKeyEvent *e) | - | ||||||||||||||||||||||||
821 | { | - | ||||||||||||||||||||||||
822 | Q_Q(QQuickTextControl); | - | ||||||||||||||||||||||||
823 | - | |||||||||||||||||||||||||
824 | if (e->key() == Qt::Key_Back) {
| 0-1028 | ||||||||||||||||||||||||
825 | e->ignore(); | - | ||||||||||||||||||||||||
826 | return; never executed: return; | 0 | ||||||||||||||||||||||||
827 | } | - | ||||||||||||||||||||||||
828 | - | |||||||||||||||||||||||||
829 | #if QT_CONFIG(shortcut) | - | ||||||||||||||||||||||||
830 | if (e == QKeySequence::SelectAll) {
| 2-1026 | ||||||||||||||||||||||||
831 | e->accept(); | - | ||||||||||||||||||||||||
832 | q->selectAll(); | - | ||||||||||||||||||||||||
833 | #if QT_CONFIG(clipboard) | - | ||||||||||||||||||||||||
834 | setClipboardSelection(); | - | ||||||||||||||||||||||||
835 | #endif | - | ||||||||||||||||||||||||
836 | return; executed 2 times by 1 test: return; Executed by:
| 2 | ||||||||||||||||||||||||
837 | } | - | ||||||||||||||||||||||||
838 | #if QT_CONFIG(clipboard) | - | ||||||||||||||||||||||||
839 | else if (e == QKeySequence::Copy) {
| 2-1024 | ||||||||||||||||||||||||
840 | e->accept(); | - | ||||||||||||||||||||||||
841 | q->copy(); | - | ||||||||||||||||||||||||
842 | return; executed 2 times by 1 test: return; Executed by:
| 2 | ||||||||||||||||||||||||
843 | } | - | ||||||||||||||||||||||||
844 | #endif | - | ||||||||||||||||||||||||
845 | #endif // shortcut | - | ||||||||||||||||||||||||
846 | - | |||||||||||||||||||||||||
847 | if (interactionFlags & Qt::TextSelectableByKeyboard | - | ||||||||||||||||||||||||
848 | && cursorMoveKeyEvent(e))
| 132-758 | ||||||||||||||||||||||||
849 | goto accept; executed 132 times by 2 tests: goto accept; Executed by:
| 132 | ||||||||||||||||||||||||
850 | - | |||||||||||||||||||||||||
851 | if (!(interactionFlags & Qt::TextEditable)) {
| 126-766 | ||||||||||||||||||||||||
852 | e->ignore(); | - | ||||||||||||||||||||||||
853 | return; executed 126 times by 2 tests: return; Executed by:
| 126 | ||||||||||||||||||||||||
854 | } | - | ||||||||||||||||||||||||
855 | - | |||||||||||||||||||||||||
856 | if (e->key() == Qt::Key_Direction_L || e->key() == Qt::Key_Direction_R) {
| 10-728 | ||||||||||||||||||||||||
857 | QTextBlockFormat fmt; | - | ||||||||||||||||||||||||
858 | fmt.setLayoutDirection((e->key() == Qt::Key_Direction_L) ? Qt::LeftToRight : Qt::RightToLeft); | - | ||||||||||||||||||||||||
859 | cursor.mergeBlockFormat(fmt); | - | ||||||||||||||||||||||||
860 | goto accept; executed 48 times by 1 test: goto accept; Executed by:
| 48 | ||||||||||||||||||||||||
861 | } | - | ||||||||||||||||||||||||
862 | - | |||||||||||||||||||||||||
863 | // schedule a repaint of the region of the cursor, as when we move it we | - | ||||||||||||||||||||||||
864 | // want to make sure the old cursor disappears (not noticeable when moving | - | ||||||||||||||||||||||||
865 | // only a few pixels but noticeable when jumping between cells in tables for | - | ||||||||||||||||||||||||
866 | // example) | - | ||||||||||||||||||||||||
867 | repaintSelection(); | - | ||||||||||||||||||||||||
868 | - | |||||||||||||||||||||||||
869 | if (e->key() == Qt::Key_Backspace && !(e->modifiers() & ~Qt::ShiftModifier)) {
| 2-710 | ||||||||||||||||||||||||
870 | QTextBlockFormat blockFmt = cursor.blockFormat(); | - | ||||||||||||||||||||||||
871 | QTextList *list = cursor.currentList(); | - | ||||||||||||||||||||||||
872 | if (list && cursor.atBlockStart() && !cursor.hasSelection()) {
| 0-6 | ||||||||||||||||||||||||
873 | list->remove(cursor.block()); | - | ||||||||||||||||||||||||
874 | } else if (cursor.atBlockStart() && blockFmt.indent() > 0) { never executed: end of block
| 0-6 | ||||||||||||||||||||||||
875 | blockFmt.setIndent(blockFmt.indent() - 1); | - | ||||||||||||||||||||||||
876 | cursor.setBlockFormat(blockFmt); | - | ||||||||||||||||||||||||
877 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
878 | QTextCursor localCursor = cursor; | - | ||||||||||||||||||||||||
879 | localCursor.deletePreviousChar(); | - | ||||||||||||||||||||||||
880 | } executed 6 times by 1 test: end of block Executed by:
| 6 | ||||||||||||||||||||||||
881 | goto accept; executed 6 times by 1 test: goto accept; Executed by:
| 6 | ||||||||||||||||||||||||
882 | } | - | ||||||||||||||||||||||||
883 | #if QT_CONFIG(shortcut) | - | ||||||||||||||||||||||||
884 | else if (e == QKeySequence::InsertParagraphSeparator) {
| 2-710 | ||||||||||||||||||||||||
885 | cursor.insertBlock(); | - | ||||||||||||||||||||||||
886 | e->accept(); | - | ||||||||||||||||||||||||
887 | goto accept; executed 2 times by 1 test: goto accept; Executed by:
| 2 | ||||||||||||||||||||||||
888 | } else if (e == QKeySequence::InsertLineSeparator) {
| 0-710 | ||||||||||||||||||||||||
889 | cursor.insertText(QString(QChar::LineSeparator)); | - | ||||||||||||||||||||||||
890 | e->accept(); | - | ||||||||||||||||||||||||
891 | goto accept; never executed: goto accept; | 0 | ||||||||||||||||||||||||
892 | } | - | ||||||||||||||||||||||||
893 | #endif | - | ||||||||||||||||||||||||
894 | if (false) { dead code: { } | - | ||||||||||||||||||||||||
895 | } dead code: { } | - | ||||||||||||||||||||||||
896 | #if QT_CONFIG(shortcut) | - | ||||||||||||||||||||||||
897 | else if (e == QKeySequence::Undo) {
| 4-706 | ||||||||||||||||||||||||
898 | q->undo(); | - | ||||||||||||||||||||||||
899 | } executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||||||||||||||
900 | else if (e == QKeySequence::Redo) {
| 0-706 | ||||||||||||||||||||||||
901 | q->redo(); | - | ||||||||||||||||||||||||
902 | } never executed: end of block | 0 | ||||||||||||||||||||||||
903 | #if QT_CONFIG(clipboard) | - | ||||||||||||||||||||||||
904 | else if (e == QKeySequence::Cut) {
| 2-704 | ||||||||||||||||||||||||
905 | q->cut(); | - | ||||||||||||||||||||||||
906 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||||||||
907 | else if (e == QKeySequence::Paste) {
| 4-700 | ||||||||||||||||||||||||
908 | QClipboard::Mode mode = QClipboard::Clipboard; | - | ||||||||||||||||||||||||
909 | q->paste(mode); | - | ||||||||||||||||||||||||
910 | } executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||||||||||||||
911 | #endif | - | ||||||||||||||||||||||||
912 | else if (e == QKeySequence::Delete) {
| 10-690 | ||||||||||||||||||||||||
913 | QTextCursor localCursor = cursor; | - | ||||||||||||||||||||||||
914 | localCursor.deleteChar(); | - | ||||||||||||||||||||||||
915 | } executed 10 times by 1 test: end of block Executed by:
| 10 | ||||||||||||||||||||||||
916 | else if (e == QKeySequence::DeleteEndOfWord) {
| 2-688 | ||||||||||||||||||||||||
917 | if (!cursor.hasSelection())
| 0-2 | ||||||||||||||||||||||||
918 | cursor.movePosition(QTextCursor::NextWord, QTextCursor::KeepAnchor); executed 2 times by 1 test: cursor.movePosition(QTextCursor::NextWord, QTextCursor::KeepAnchor); Executed by:
| 2 | ||||||||||||||||||||||||
919 | cursor.removeSelectedText(); | - | ||||||||||||||||||||||||
920 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||||||||
921 | else if (e == QKeySequence::DeleteStartOfWord) {
| 2-686 | ||||||||||||||||||||||||
922 | if (!cursor.hasSelection())
| 0-2 | ||||||||||||||||||||||||
923 | cursor.movePosition(QTextCursor::PreviousWord, QTextCursor::KeepAnchor); executed 2 times by 1 test: cursor.movePosition(QTextCursor::PreviousWord, QTextCursor::KeepAnchor); Executed by:
| 2 | ||||||||||||||||||||||||
924 | cursor.removeSelectedText(); | - | ||||||||||||||||||||||||
925 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||||||||
926 | else if (e == QKeySequence::DeleteEndOfLine) {
| 2-684 | ||||||||||||||||||||||||
927 | QTextBlock block = cursor.block(); | - | ||||||||||||||||||||||||
928 | if (cursor.position() == block.position() + block.length() - 2)
| 0-2 | ||||||||||||||||||||||||
929 | cursor.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor); never executed: cursor.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor); | 0 | ||||||||||||||||||||||||
930 | else | - | ||||||||||||||||||||||||
931 | cursor.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor); executed 2 times by 1 test: cursor.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor); Executed by:
| 2 | ||||||||||||||||||||||||
932 | cursor.removeSelectedText(); | - | ||||||||||||||||||||||||
933 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||||||||
934 | #endif // shortcut | - | ||||||||||||||||||||||||
935 | else { | - | ||||||||||||||||||||||||
936 | goto process; executed 684 times by 3 tests: goto process; Executed by:
| 684 | ||||||||||||||||||||||||
937 | } | - | ||||||||||||||||||||||||
938 | goto accept; executed 26 times by 1 test: goto accept; Executed by:
| 26 | ||||||||||||||||||||||||
939 | - | |||||||||||||||||||||||||
940 | process: | - | ||||||||||||||||||||||||
941 | { | - | ||||||||||||||||||||||||
942 | if (q->isAcceptableInput(e)) {
| 96-588 | ||||||||||||||||||||||||
943 | if (overwriteMode
| 20-568 | ||||||||||||||||||||||||
944 | // no need to call deleteChar() if we have a selection, insertText | - | ||||||||||||||||||||||||
945 | // does it already | - | ||||||||||||||||||||||||
946 | && !cursor.hasSelection()
| 0-20 | ||||||||||||||||||||||||
947 | && !cursor.atBlockEnd()) {
| 10 | ||||||||||||||||||||||||
948 | cursor.deleteChar(); | - | ||||||||||||||||||||||||
949 | } executed 10 times by 1 test: end of block Executed by:
| 10 | ||||||||||||||||||||||||
950 | - | |||||||||||||||||||||||||
951 | cursor.insertText(e->text()); | - | ||||||||||||||||||||||||
952 | selectionChanged(); | - | ||||||||||||||||||||||||
953 | } else { executed 588 times by 1 test: end of block Executed by:
| 588 | ||||||||||||||||||||||||
954 | e->ignore(); | - | ||||||||||||||||||||||||
955 | return; executed 96 times by 3 tests: return; Executed by:
| 96 | ||||||||||||||||||||||||
956 | } | - | ||||||||||||||||||||||||
957 | } | - | ||||||||||||||||||||||||
958 | - | |||||||||||||||||||||||||
959 | accept: code before this statement executed 588 times by 1 test: accept: Executed by:
| 588 | ||||||||||||||||||||||||
960 | - | |||||||||||||||||||||||||
961 | #if QT_CONFIG(clipboard) | - | ||||||||||||||||||||||||
962 | setClipboardSelection(); | - | ||||||||||||||||||||||||
963 | #endif | - | ||||||||||||||||||||||||
964 | - | |||||||||||||||||||||||||
965 | e->accept(); | - | ||||||||||||||||||||||||
966 | cursorOn = true; | - | ||||||||||||||||||||||||
967 | - | |||||||||||||||||||||||||
968 | q->updateCursorRectangle(true); | - | ||||||||||||||||||||||||
969 | updateCurrentCharFormat(); | - | ||||||||||||||||||||||||
970 | } executed 802 times by 2 tests: end of block Executed by:
| 802 | ||||||||||||||||||||||||
971 | - | |||||||||||||||||||||||||
972 | QRectF QQuickTextControlPrivate::rectForPosition(int position) const | - | ||||||||||||||||||||||||
973 | { | - | ||||||||||||||||||||||||
974 | Q_Q(const QQuickTextControl); | - | ||||||||||||||||||||||||
975 | const QTextBlock block = doc->findBlock(position); | - | ||||||||||||||||||||||||
976 | if (!block.isValid())
| 0-2696 | ||||||||||||||||||||||||
977 | return QRectF(); never executed: return QRectF(); | 0 | ||||||||||||||||||||||||
978 | const QTextLayout *layout = block.layout(); | - | ||||||||||||||||||||||||
979 | const QPointF layoutPos = q->blockBoundingRect(block).topLeft(); | - | ||||||||||||||||||||||||
980 | int relativePos = position - block.position(); | - | ||||||||||||||||||||||||
981 | #if QT_CONFIG(im) | - | ||||||||||||||||||||||||
982 | if (preeditCursor != 0) {
| 58-2638 | ||||||||||||||||||||||||
983 | int preeditPos = layout->preeditAreaPosition(); | - | ||||||||||||||||||||||||
984 | if (relativePos == preeditPos)
| 12-46 | ||||||||||||||||||||||||
985 | relativePos += preeditCursor; executed 46 times by 1 test: relativePos += preeditCursor; Executed by:
| 46 | ||||||||||||||||||||||||
986 | else if (relativePos > preeditPos)
| 0-12 | ||||||||||||||||||||||||
987 | relativePos += layout->preeditAreaText().length(); executed 12 times by 1 test: relativePos += layout->preeditAreaText().length(); Executed by:
| 12 | ||||||||||||||||||||||||
988 | } executed 58 times by 1 test: end of block Executed by:
| 58 | ||||||||||||||||||||||||
989 | #endif | - | ||||||||||||||||||||||||
990 | QTextLine line = layout->lineForTextPosition(relativePos); | - | ||||||||||||||||||||||||
991 | - | |||||||||||||||||||||||||
992 | QRectF r; | - | ||||||||||||||||||||||||
993 | - | |||||||||||||||||||||||||
994 | if (line.isValid()) {
| 0-2696 | ||||||||||||||||||||||||
995 | qreal x = line.cursorToX(relativePos); | - | ||||||||||||||||||||||||
996 | qreal w = 0; | - | ||||||||||||||||||||||||
997 | if (overwriteMode) {
| 0-2696 | ||||||||||||||||||||||||
998 | if (relativePos < line.textLength() - line.textStart())
| 0 | ||||||||||||||||||||||||
999 | w = line.cursorToX(relativePos + 1) - x; never executed: w = line.cursorToX(relativePos + 1) - x; | 0 | ||||||||||||||||||||||||
1000 | else | - | ||||||||||||||||||||||||
1001 | w = QFontMetrics(block.layout()->font()).width(QLatin1Char(' ')); // in sync with QTextLine::draw() never executed: w = QFontMetrics(block.layout()->font()).width(QLatin1Char(' ')); | 0 | ||||||||||||||||||||||||
1002 | } | - | ||||||||||||||||||||||||
1003 | r = QRectF(layoutPos.x() + x, layoutPos.y() + line.y(), textCursorWidth + w, line.height()); | - | ||||||||||||||||||||||||
1004 | } else { executed 2696 times by 3 tests: end of block Executed by:
| 2696 | ||||||||||||||||||||||||
1005 | r = QRectF(layoutPos.x(), layoutPos.y(), textCursorWidth, 10); // #### correct height | - | ||||||||||||||||||||||||
1006 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1007 | - | |||||||||||||||||||||||||
1008 | return r; executed 2696 times by 3 tests: return r; Executed by:
| 2696 | ||||||||||||||||||||||||
1009 | } | - | ||||||||||||||||||||||||
1010 | - | |||||||||||||||||||||||||
1011 | void QQuickTextControlPrivate::mousePressEvent(QMouseEvent *e, const QPointF &pos) | - | ||||||||||||||||||||||||
1012 | { | - | ||||||||||||||||||||||||
1013 | Q_Q(QQuickTextControl); | - | ||||||||||||||||||||||||
1014 | - | |||||||||||||||||||||||||
1015 | mousePressed = (interactionFlags & Qt::TextSelectableByMouse) && (e->button() & Qt::LeftButton);
| 2-472 | ||||||||||||||||||||||||
1016 | mousePressPos = pos.toPoint(); | - | ||||||||||||||||||||||||
1017 | - | |||||||||||||||||||||||||
1018 | if (sendMouseEventToInputContext(e, pos))
| 0-514 | ||||||||||||||||||||||||
1019 | return; never executed: return; | 0 | ||||||||||||||||||||||||
1020 | - | |||||||||||||||||||||||||
1021 | if (interactionFlags & Qt::LinksAccessibleByMouse) {
| 0-514 | ||||||||||||||||||||||||
1022 | anchorOnMousePress = q->anchorAt(pos); | - | ||||||||||||||||||||||||
1023 | - | |||||||||||||||||||||||||
1024 | if (cursorIsFocusIndicator) {
| 124-390 | ||||||||||||||||||||||||
1025 | cursorIsFocusIndicator = false; | - | ||||||||||||||||||||||||
1026 | repaintSelection(); | - | ||||||||||||||||||||||||
1027 | cursor.clearSelection(); | - | ||||||||||||||||||||||||
1028 | } executed 124 times by 1 test: end of block Executed by:
| 124 | ||||||||||||||||||||||||
1029 | } executed 514 times by 1 test: end of block Executed by:
| 514 | ||||||||||||||||||||||||
1030 | if (e->button() & Qt::MiddleButton) {
| 2-512 | ||||||||||||||||||||||||
1031 | return; executed 2 times by 1 test: return; Executed by:
| 2 | ||||||||||||||||||||||||
1032 | } else if (!(e->button() & Qt::LeftButton)) {
| 0-512 | ||||||||||||||||||||||||
1033 | e->ignore(); | - | ||||||||||||||||||||||||
1034 | return; never executed: return; | 0 | ||||||||||||||||||||||||
1035 | } else if (!(interactionFlags & (Qt::TextSelectableByMouse | Qt::TextEditable))) {
| 8-504 | ||||||||||||||||||||||||
1036 | if (!(interactionFlags & Qt::LinksAccessibleByMouse))
| 0-8 | ||||||||||||||||||||||||
1037 | e->ignore(); never executed: e->ignore(); | 0 | ||||||||||||||||||||||||
1038 | return; executed 8 times by 1 test: return; Executed by:
| 8 | ||||||||||||||||||||||||
1039 | } | - | ||||||||||||||||||||||||
1040 | - | |||||||||||||||||||||||||
1041 | cursorIsFocusIndicator = false; | - | ||||||||||||||||||||||||
1042 | const QTextCursor oldSelection = cursor; | - | ||||||||||||||||||||||||
1043 | const int oldCursorPos = cursor.position(); | - | ||||||||||||||||||||||||
1044 | - | |||||||||||||||||||||||||
1045 | #if QT_CONFIG(im) | - | ||||||||||||||||||||||||
1046 | commitPreedit(); | - | ||||||||||||||||||||||||
1047 | #endif | - | ||||||||||||||||||||||||
1048 | - | |||||||||||||||||||||||||
1049 | if (tripleClickTimer.isActive()
| 104-400 | ||||||||||||||||||||||||
1050 | && ((pos - tripleClickPoint).toPoint().manhattanLength() < QGuiApplication::styleHints()->startDragDistance())) {
| 18-86 | ||||||||||||||||||||||||
1051 | - | |||||||||||||||||||||||||
1052 | cursor.movePosition(QTextCursor::StartOfBlock); | - | ||||||||||||||||||||||||
1053 | cursor.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor); | - | ||||||||||||||||||||||||
1054 | cursor.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor); | - | ||||||||||||||||||||||||
1055 | selectedBlockOnTripleClick = cursor; | - | ||||||||||||||||||||||||
1056 | - | |||||||||||||||||||||||||
1057 | anchorOnMousePress = QString(); | - | ||||||||||||||||||||||||
1058 | - | |||||||||||||||||||||||||
1059 | tripleClickTimer.stop(); | - | ||||||||||||||||||||||||
1060 | } else { executed 86 times by 1 test: end of block Executed by:
| 86 | ||||||||||||||||||||||||
1061 | int cursorPos = q->hitTest(pos, Qt::FuzzyHit); | - | ||||||||||||||||||||||||
1062 | if (cursorPos == -1) {
| 0-418 | ||||||||||||||||||||||||
1063 | e->ignore(); | - | ||||||||||||||||||||||||
1064 | return; never executed: return; | 0 | ||||||||||||||||||||||||
1065 | } | - | ||||||||||||||||||||||||
1066 | - | |||||||||||||||||||||||||
1067 | if (e->modifiers() == Qt::ShiftModifier && (interactionFlags & Qt::TextSelectableByMouse)) {
| 92-326 | ||||||||||||||||||||||||
1068 | if (wordSelectionEnabled && !selectedWordOnDoubleClick.hasSelection()) {
| 0-64 | ||||||||||||||||||||||||
1069 | selectedWordOnDoubleClick = cursor; | - | ||||||||||||||||||||||||
1070 | selectedWordOnDoubleClick.select(QTextCursor::WordUnderCursor); | - | ||||||||||||||||||||||||
1071 | } executed 22 times by 1 test: end of block Executed by:
| 22 | ||||||||||||||||||||||||
1072 | - | |||||||||||||||||||||||||
1073 | if (selectedBlockOnTripleClick.hasSelection())
| 34-52 | ||||||||||||||||||||||||
1074 | extendBlockwiseSelection(cursorPos); executed 34 times by 1 test: extendBlockwiseSelection(cursorPos); Executed by:
| 34 | ||||||||||||||||||||||||
1075 | else if (selectedWordOnDoubleClick.hasSelection())
| 12-40 | ||||||||||||||||||||||||
1076 | extendWordwiseSelection(cursorPos, pos.x()); executed 40 times by 1 test: extendWordwiseSelection(cursorPos, pos.x()); Executed by:
| 40 | ||||||||||||||||||||||||
1077 | else if (!wordSelectionEnabled)
| 0-12 | ||||||||||||||||||||||||
1078 | setCursorPosition(cursorPos, QTextCursor::KeepAnchor); executed 12 times by 1 test: setCursorPosition(cursorPos, QTextCursor::KeepAnchor); Executed by:
| 12 | ||||||||||||||||||||||||
1079 | } else { executed 86 times by 1 test: end of block Executed by:
| 86 | ||||||||||||||||||||||||
1080 | setCursorPosition(cursorPos); | - | ||||||||||||||||||||||||
1081 | } executed 332 times by 1 test: end of block Executed by:
| 332 | ||||||||||||||||||||||||
1082 | } | - | ||||||||||||||||||||||||
1083 | - | |||||||||||||||||||||||||
1084 | if (cursor.position() != oldCursorPos) {
| 114-390 | ||||||||||||||||||||||||
1085 | q->updateCursorRectangle(true); | - | ||||||||||||||||||||||||
1086 | emit q->cursorPositionChanged(); | - | ||||||||||||||||||||||||
1087 | } executed 390 times by 1 test: end of block Executed by:
| 390 | ||||||||||||||||||||||||
1088 | if (interactionFlags & Qt::TextEditable)
| 12-492 | ||||||||||||||||||||||||
1089 | _q_updateCurrentCharFormatAndSelection(); executed 492 times by 1 test: _q_updateCurrentCharFormatAndSelection(); Executed by:
| 492 | ||||||||||||||||||||||||
1090 | else | - | ||||||||||||||||||||||||
1091 | selectionChanged(); executed 12 times by 1 test: selectionChanged(); Executed by:
| 12 | ||||||||||||||||||||||||
1092 | repaintOldAndNewSelection(oldSelection); | - | ||||||||||||||||||||||||
1093 | hadSelectionOnMousePress = cursor.hasSelection(); | - | ||||||||||||||||||||||||
1094 | } executed 504 times by 1 test: end of block Executed by:
| 504 | ||||||||||||||||||||||||
1095 | - | |||||||||||||||||||||||||
1096 | void QQuickTextControlPrivate::mouseMoveEvent(QMouseEvent *e, const QPointF &mousePos) | - | ||||||||||||||||||||||||
1097 | { | - | ||||||||||||||||||||||||
1098 | Q_Q(QQuickTextControl); | - | ||||||||||||||||||||||||
1099 | - | |||||||||||||||||||||||||
1100 | if ((e->buttons() & Qt::LeftButton)) {
| 0-138 | ||||||||||||||||||||||||
1101 | const bool editable = interactionFlags & Qt::TextEditable; | - | ||||||||||||||||||||||||
1102 | - | |||||||||||||||||||||||||
1103 | if (!(mousePressed
| 6-132 | ||||||||||||||||||||||||
1104 | || editable
| 0-6 | ||||||||||||||||||||||||
1105 | || selectedWordOnDoubleClick.hasSelection()
| 0 | ||||||||||||||||||||||||
1106 | || selectedBlockOnTripleClick.hasSelection()))
| 0 | ||||||||||||||||||||||||
1107 | return; never executed: return; | 0 | ||||||||||||||||||||||||
1108 | - | |||||||||||||||||||||||||
1109 | const QTextCursor oldSelection = cursor; | - | ||||||||||||||||||||||||
1110 | const int oldCursorPos = cursor.position(); | - | ||||||||||||||||||||||||
1111 | - | |||||||||||||||||||||||||
1112 | if (!mousePressed)
| 6-132 | ||||||||||||||||||||||||
1113 | return; executed 6 times by 1 test: return; Executed by:
| 6 | ||||||||||||||||||||||||
1114 | - | |||||||||||||||||||||||||
1115 | const qreal mouseX = qreal(mousePos.x()); | - | ||||||||||||||||||||||||
1116 | - | |||||||||||||||||||||||||
1117 | int newCursorPos = q->hitTest(mousePos, Qt::FuzzyHit); | - | ||||||||||||||||||||||||
1118 | - | |||||||||||||||||||||||||
1119 | #if QT_CONFIG(im) | - | ||||||||||||||||||||||||
1120 | if (isPreediting()) {
| 0-132 | ||||||||||||||||||||||||
1121 | // note: oldCursorPos not including preedit | - | ||||||||||||||||||||||||
1122 | int selectionStartPos = q->hitTest(mousePressPos, Qt::FuzzyHit); | - | ||||||||||||||||||||||||
1123 | if (newCursorPos != selectionStartPos) {
| 0 | ||||||||||||||||||||||||
1124 | commitPreedit(); | - | ||||||||||||||||||||||||
1125 | // commit invalidates positions | - | ||||||||||||||||||||||||
1126 | newCursorPos = q->hitTest(mousePos, Qt::FuzzyHit); | - | ||||||||||||||||||||||||
1127 | selectionStartPos = q->hitTest(mousePressPos, Qt::FuzzyHit); | - | ||||||||||||||||||||||||
1128 | setCursorPosition(selectionStartPos); | - | ||||||||||||||||||||||||
1129 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1130 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1131 | #endif | - | ||||||||||||||||||||||||
1132 | - | |||||||||||||||||||||||||
1133 | if (newCursorPos == -1)
| 0-132 | ||||||||||||||||||||||||
1134 | return; never executed: return; | 0 | ||||||||||||||||||||||||
1135 | - | |||||||||||||||||||||||||
1136 | if (wordSelectionEnabled && !selectedWordOnDoubleClick.hasSelection()) {
| 0-108 | ||||||||||||||||||||||||
1137 | selectedWordOnDoubleClick = cursor; | - | ||||||||||||||||||||||||
1138 | selectedWordOnDoubleClick.select(QTextCursor::WordUnderCursor); | - | ||||||||||||||||||||||||
1139 | } executed 24 times by 1 test: end of block Executed by:
| 24 | ||||||||||||||||||||||||
1140 | - | |||||||||||||||||||||||||
1141 | if (selectedBlockOnTripleClick.hasSelection())
| 34-98 | ||||||||||||||||||||||||
1142 | extendBlockwiseSelection(newCursorPos); executed 34 times by 1 test: extendBlockwiseSelection(newCursorPos); Executed by:
| 34 | ||||||||||||||||||||||||
1143 | else if (selectedWordOnDoubleClick.hasSelection())
| 42-56 | ||||||||||||||||||||||||
1144 | extendWordwiseSelection(newCursorPos, mouseX); executed 42 times by 1 test: extendWordwiseSelection(newCursorPos, mouseX); Executed by:
| 42 | ||||||||||||||||||||||||
1145 | #if QT_CONFIG(im) | - | ||||||||||||||||||||||||
1146 | else if (!isPreediting())
| 0-56 | ||||||||||||||||||||||||
1147 | setCursorPosition(newCursorPos, QTextCursor::KeepAnchor); executed 56 times by 1 test: setCursorPosition(newCursorPos, QTextCursor::KeepAnchor); Executed by:
| 56 | ||||||||||||||||||||||||
1148 | #endif | - | ||||||||||||||||||||||||
1149 | - | |||||||||||||||||||||||||
1150 | if (interactionFlags & Qt::TextEditable) {
| 0-132 | ||||||||||||||||||||||||
1151 | if (cursor.position() != oldCursorPos) {
| 26-106 | ||||||||||||||||||||||||
1152 | emit q->cursorPositionChanged(); | - | ||||||||||||||||||||||||
1153 | } executed 106 times by 1 test: end of block Executed by:
| 106 | ||||||||||||||||||||||||
1154 | _q_updateCurrentCharFormatAndSelection(); | - | ||||||||||||||||||||||||
1155 | #if QT_CONFIG(im) | - | ||||||||||||||||||||||||
1156 | if (qGuiApp)
| 0-132 | ||||||||||||||||||||||||
1157 | qGuiApp->inputMethod()->update(Qt::ImQueryInput); executed 132 times by 1 test: (static_cast<QGuiApplication *>(QCoreApplication::instance()))->inputMethod()->update(Qt::ImQueryInput); Executed by:
| 132 | ||||||||||||||||||||||||
1158 | #endif | - | ||||||||||||||||||||||||
1159 | } else if (cursor.position() != oldCursorPos) { executed 132 times by 1 test: end of block Executed by:
| 0-132 | ||||||||||||||||||||||||
1160 | emit q->cursorPositionChanged(); | - | ||||||||||||||||||||||||
1161 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1162 | selectionChanged(true); | - | ||||||||||||||||||||||||
1163 | repaintOldAndNewSelection(oldSelection); | - | ||||||||||||||||||||||||
1164 | } executed 132 times by 1 test: end of block Executed by:
| 132 | ||||||||||||||||||||||||
1165 | - | |||||||||||||||||||||||||
1166 | sendMouseEventToInputContext(e, mousePos); | - | ||||||||||||||||||||||||
1167 | } executed 132 times by 1 test: end of block Executed by:
| 132 | ||||||||||||||||||||||||
1168 | - | |||||||||||||||||||||||||
1169 | void QQuickTextControlPrivate::mouseReleaseEvent(QMouseEvent *e, const QPointF &pos) | - | ||||||||||||||||||||||||
1170 | { | - | ||||||||||||||||||||||||
1171 | Q_Q(QQuickTextControl); | - | ||||||||||||||||||||||||
1172 | - | |||||||||||||||||||||||||
1173 | if (sendMouseEventToInputContext(e, pos))
| 0-514 | ||||||||||||||||||||||||
1174 | return; never executed: return; | 0 | ||||||||||||||||||||||||
1175 | - | |||||||||||||||||||||||||
1176 | const QTextCursor oldSelection = cursor; | - | ||||||||||||||||||||||||
1177 | const int oldCursorPos = cursor.position(); | - | ||||||||||||||||||||||||
1178 | - | |||||||||||||||||||||||||
1179 | if (mousePressed) {
| 42-472 | ||||||||||||||||||||||||
1180 | mousePressed = false; | - | ||||||||||||||||||||||||
1181 | #if QT_CONFIG(clipboard) | - | ||||||||||||||||||||||||
1182 | setClipboardSelection(); | - | ||||||||||||||||||||||||
1183 | selectionChanged(true); | - | ||||||||||||||||||||||||
1184 | } else if (e->button() == Qt::MidButton executed 472 times by 1 test: end of block Executed by:
| 2-472 | ||||||||||||||||||||||||
1185 | && (interactionFlags & Qt::TextEditable) | - | ||||||||||||||||||||||||
1186 | && QGuiApplication::clipboard()->supportsSelection()) {
| 0-2 | ||||||||||||||||||||||||
1187 | setCursorPosition(pos); | - | ||||||||||||||||||||||||
1188 | const QMimeData *md = QGuiApplication::clipboard()->mimeData(QClipboard::Selection); | - | ||||||||||||||||||||||||
1189 | if (md)
| 0-2 | ||||||||||||||||||||||||
1190 | q->insertFromMimeData(md); executed 2 times by 1 test: q->insertFromMimeData(md); Executed by:
| 2 | ||||||||||||||||||||||||
1191 | #endif | - | ||||||||||||||||||||||||
1192 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||||||||
1193 | - | |||||||||||||||||||||||||
1194 | repaintOldAndNewSelection(oldSelection); | - | ||||||||||||||||||||||||
1195 | - | |||||||||||||||||||||||||
1196 | if (cursor.position() != oldCursorPos) {
| 2-512 | ||||||||||||||||||||||||
1197 | emit q->cursorPositionChanged(); | - | ||||||||||||||||||||||||
1198 | q->updateCursorRectangle(true); | - | ||||||||||||||||||||||||
1199 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||||||||
1200 | - | |||||||||||||||||||||||||
1201 | if (interactionFlags & Qt::LinksAccessibleByMouse) {
| 0-514 | ||||||||||||||||||||||||
1202 | if (!(e->button() & Qt::LeftButton))
| 2-512 | ||||||||||||||||||||||||
1203 | return; executed 2 times by 1 test: return; Executed by:
| 2 | ||||||||||||||||||||||||
1204 | - | |||||||||||||||||||||||||
1205 | const QString anchor = q->anchorAt(pos); | - | ||||||||||||||||||||||||
1206 | - | |||||||||||||||||||||||||
1207 | if (anchor.isEmpty())
| 4-508 | ||||||||||||||||||||||||
1208 | return; executed 508 times by 1 test: return; Executed by:
| 508 | ||||||||||||||||||||||||
1209 | - | |||||||||||||||||||||||||
1210 | if (!cursor.hasSelection()
| 0-4 | ||||||||||||||||||||||||
1211 | || (anchor == anchorOnMousePress && hadSelectionOnMousePress)) {
| 0 | ||||||||||||||||||||||||
1212 | - | |||||||||||||||||||||||||
1213 | const int anchorPos = q->hitTest(pos, Qt::ExactHit); | - | ||||||||||||||||||||||||
1214 | if (anchorPos != -1) {
| 0-4 | ||||||||||||||||||||||||
1215 | cursor.setPosition(anchorPos); | - | ||||||||||||||||||||||||
1216 | - | |||||||||||||||||||||||||
1217 | QString anchor = anchorOnMousePress; | - | ||||||||||||||||||||||||
1218 | anchorOnMousePress = QString(); | - | ||||||||||||||||||||||||
1219 | activateLinkUnderCursor(anchor); | - | ||||||||||||||||||||||||
1220 | } executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||||||||||||||
1221 | } executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||||||||||||||
1222 | } executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||||||||||||||
1223 | } executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||||||||||||||
1224 | - | |||||||||||||||||||||||||
1225 | void QQuickTextControlPrivate::mouseDoubleClickEvent(QMouseEvent *e, const QPointF &pos) | - | ||||||||||||||||||||||||
1226 | { | - | ||||||||||||||||||||||||
1227 | Q_Q(QQuickTextControl); | - | ||||||||||||||||||||||||
1228 | - | |||||||||||||||||||||||||
1229 | if (e->button() == Qt::LeftButton && (interactionFlags & Qt::TextSelectableByMouse)) {
| 0-104 | ||||||||||||||||||||||||
1230 | #if QT_CONFIG(im) | - | ||||||||||||||||||||||||
1231 | commitPreedit(); | - | ||||||||||||||||||||||||
1232 | #endif | - | ||||||||||||||||||||||||
1233 | - | |||||||||||||||||||||||||
1234 | const QTextCursor oldSelection = cursor; | - | ||||||||||||||||||||||||
1235 | setCursorPosition(pos); | - | ||||||||||||||||||||||||
1236 | QTextLine line = currentTextLine(cursor); | - | ||||||||||||||||||||||||
1237 | bool doEmit = false; | - | ||||||||||||||||||||||||
1238 | if (line.isValid() && line.textLength()) {
| 0-104 | ||||||||||||||||||||||||
1239 | cursor.select(QTextCursor::WordUnderCursor); | - | ||||||||||||||||||||||||
1240 | doEmit = true; | - | ||||||||||||||||||||||||
1241 | } executed 104 times by 1 test: end of block Executed by:
| 104 | ||||||||||||||||||||||||
1242 | repaintOldAndNewSelection(oldSelection); | - | ||||||||||||||||||||||||
1243 | - | |||||||||||||||||||||||||
1244 | cursorIsFocusIndicator = false; | - | ||||||||||||||||||||||||
1245 | selectedWordOnDoubleClick = cursor; | - | ||||||||||||||||||||||||
1246 | - | |||||||||||||||||||||||||
1247 | tripleClickPoint = pos; | - | ||||||||||||||||||||||||
1248 | tripleClickTimer.start(QGuiApplication::styleHints()->mouseDoubleClickInterval(), q); | - | ||||||||||||||||||||||||
1249 | if (doEmit) {
| 0-104 | ||||||||||||||||||||||||
1250 | selectionChanged(); | - | ||||||||||||||||||||||||
1251 | #if QT_CONFIG(clipboard) | - | ||||||||||||||||||||||||
1252 | setClipboardSelection(); | - | ||||||||||||||||||||||||
1253 | #endif | - | ||||||||||||||||||||||||
1254 | emit q->cursorPositionChanged(); | - | ||||||||||||||||||||||||
1255 | q->updateCursorRectangle(true); | - | ||||||||||||||||||||||||
1256 | } executed 104 times by 1 test: end of block Executed by:
| 104 | ||||||||||||||||||||||||
1257 | } else if (!sendMouseEventToInputContext(e, pos)) { executed 104 times by 1 test: end of block Executed by:
| 0-104 | ||||||||||||||||||||||||
1258 | e->ignore(); | - | ||||||||||||||||||||||||
1259 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1260 | } executed 104 times by 1 test: end of block Executed by:
| 104 | ||||||||||||||||||||||||
1261 | - | |||||||||||||||||||||||||
1262 | bool QQuickTextControlPrivate::sendMouseEventToInputContext(QMouseEvent *e, const QPointF &pos) | - | ||||||||||||||||||||||||
1263 | { | - | ||||||||||||||||||||||||
1264 | #if QT_CONFIG(im) | - | ||||||||||||||||||||||||
1265 | Q_Q(QQuickTextControl); | - | ||||||||||||||||||||||||
1266 | - | |||||||||||||||||||||||||
1267 | Q_UNUSED(e); | - | ||||||||||||||||||||||||
1268 | - | |||||||||||||||||||||||||
1269 | if (isPreediting()) {
| 0-1160 | ||||||||||||||||||||||||
1270 | QTextLayout *layout = cursor.block().layout(); | - | ||||||||||||||||||||||||
1271 | int cursorPos = q->hitTest(pos, Qt::FuzzyHit) - cursor.position(); | - | ||||||||||||||||||||||||
1272 | - | |||||||||||||||||||||||||
1273 | if (cursorPos >= 0 && cursorPos <= layout->preeditAreaText().length()) {
| 0 | ||||||||||||||||||||||||
1274 | if (e->type() == QEvent::MouseButtonRelease) {
| 0 | ||||||||||||||||||||||||
1275 | QGuiApplication::inputMethod()->invokeAction(QInputMethod::Click, cursorPos); | - | ||||||||||||||||||||||||
1276 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1277 | - | |||||||||||||||||||||||||
1278 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||
1279 | } | - | ||||||||||||||||||||||||
1280 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1281 | #else | - | ||||||||||||||||||||||||
1282 | Q_UNUSED(e); | - | ||||||||||||||||||||||||
1283 | Q_UNUSED(pos); | - | ||||||||||||||||||||||||
1284 | #endif | - | ||||||||||||||||||||||||
1285 | return false; executed 1160 times by 1 test: return false; Executed by:
| 1160 | ||||||||||||||||||||||||
1286 | } | - | ||||||||||||||||||||||||
1287 | - | |||||||||||||||||||||||||
1288 | #if QT_CONFIG(im) | - | ||||||||||||||||||||||||
1289 | void QQuickTextControlPrivate::inputMethodEvent(QInputMethodEvent *e) | - | ||||||||||||||||||||||||
1290 | { | - | ||||||||||||||||||||||||
1291 | Q_Q(QQuickTextControl); | - | ||||||||||||||||||||||||
1292 | if (!(interactionFlags & Qt::TextEditable) || cursor.isNull()) {
| 0-324 | ||||||||||||||||||||||||
1293 | e->ignore(); | - | ||||||||||||||||||||||||
1294 | return; never executed: return; | 0 | ||||||||||||||||||||||||
1295 | } | - | ||||||||||||||||||||||||
1296 | bool isGettingInput = !e->commitString().isEmpty()
| 136-188 | ||||||||||||||||||||||||
1297 | || e->preeditString() != cursor.block().layout()->preeditAreaText()
| 44-144 | ||||||||||||||||||||||||
1298 | || e->replacementLength() > 0;
| 36-108 | ||||||||||||||||||||||||
1299 | bool forceSelectionChanged = false; | - | ||||||||||||||||||||||||
1300 | - | |||||||||||||||||||||||||
1301 | cursor.beginEditBlock(); | - | ||||||||||||||||||||||||
1302 | if (isGettingInput) {
| 36-288 | ||||||||||||||||||||||||
1303 | cursor.removeSelectedText(); | - | ||||||||||||||||||||||||
1304 | } executed 288 times by 1 test: end of block Executed by:
| 288 | ||||||||||||||||||||||||
1305 | - | |||||||||||||||||||||||||
1306 | QTextBlock block; | - | ||||||||||||||||||||||||
1307 | - | |||||||||||||||||||||||||
1308 | // insert commit string | - | ||||||||||||||||||||||||
1309 | if (!e->commitString().isEmpty() || e->replacementLength()) {
| 80-188 | ||||||||||||||||||||||||
1310 | if (e->commitString().endsWith(QChar::LineFeed))
| 0-244 | ||||||||||||||||||||||||
1311 | block = cursor.block(); // Remember the block where the preedit text is never executed: block = cursor.block(); | 0 | ||||||||||||||||||||||||
1312 | QTextCursor c = cursor; | - | ||||||||||||||||||||||||
1313 | c.setPosition(c.position() + e->replacementStart()); | - | ||||||||||||||||||||||||
1314 | c.setPosition(c.position() + e->replacementLength(), QTextCursor::KeepAnchor); | - | ||||||||||||||||||||||||
1315 | c.insertText(e->commitString()); | - | ||||||||||||||||||||||||
1316 | } executed 244 times by 1 test: end of block Executed by:
| 244 | ||||||||||||||||||||||||
1317 | - | |||||||||||||||||||||||||
1318 | for (int i = 0; i < e->attributes().size(); ++i) {
| 34-324 | ||||||||||||||||||||||||
1319 | const QInputMethodEvent::Attribute &a = e->attributes().at(i); | - | ||||||||||||||||||||||||
1320 | if (a.type == QInputMethodEvent::Selection) {
| 4-30 | ||||||||||||||||||||||||
1321 | QTextCursor oldCursor = cursor; | - | ||||||||||||||||||||||||
1322 | int blockStart = a.start + cursor.block().position(); | - | ||||||||||||||||||||||||
1323 | cursor.setPosition(blockStart, QTextCursor::MoveAnchor); | - | ||||||||||||||||||||||||
1324 | cursor.setPosition(blockStart + a.length, QTextCursor::KeepAnchor); | - | ||||||||||||||||||||||||
1325 | repaintOldAndNewSelection(oldCursor); | - | ||||||||||||||||||||||||
1326 | forceSelectionChanged = true; | - | ||||||||||||||||||||||||
1327 | } executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||||||||||||||
1328 | } executed 34 times by 1 test: end of block Executed by:
| 34 | ||||||||||||||||||||||||
1329 | - | |||||||||||||||||||||||||
1330 | if (!block.isValid())
| 0-324 | ||||||||||||||||||||||||
1331 | block = cursor.block(); executed 324 times by 1 test: block = cursor.block(); Executed by:
| 324 | ||||||||||||||||||||||||
1332 | - | |||||||||||||||||||||||||
1333 | QTextLayout *layout = block.layout(); | - | ||||||||||||||||||||||||
1334 | if (isGettingInput) {
| 36-288 | ||||||||||||||||||||||||
1335 | layout->setPreeditArea(cursor.position() - block.position(), e->preeditString()); | - | ||||||||||||||||||||||||
1336 | emit q->preeditTextChanged(); | - | ||||||||||||||||||||||||
1337 | } executed 288 times by 1 test: end of block Executed by:
| 288 | ||||||||||||||||||||||||
1338 | QVector<QTextLayout::FormatRange> overrides; | - | ||||||||||||||||||||||||
1339 | const int oldPreeditCursor = preeditCursor; | - | ||||||||||||||||||||||||
1340 | preeditCursor = e->preeditString().length(); | - | ||||||||||||||||||||||||
1341 | hasImState = !e->preeditString().isEmpty(); | - | ||||||||||||||||||||||||
1342 | cursorVisible = true; | - | ||||||||||||||||||||||||
1343 | for (int i = 0; i < e->attributes().size(); ++i) {
| 34-324 | ||||||||||||||||||||||||
1344 | const QInputMethodEvent::Attribute &a = e->attributes().at(i); | - | ||||||||||||||||||||||||
1345 | if (a.type == QInputMethodEvent::Cursor) {
| 6-28 | ||||||||||||||||||||||||
1346 | hasImState = true; | - | ||||||||||||||||||||||||
1347 | preeditCursor = a.start; | - | ||||||||||||||||||||||||
1348 | cursorVisible = a.length != 0; | - | ||||||||||||||||||||||||
1349 | } else if (a.type == QInputMethodEvent::TextFormat) { executed 28 times by 1 test: end of block Executed by:
| 2-28 | ||||||||||||||||||||||||
1350 | hasImState = true; | - | ||||||||||||||||||||||||
1351 | QTextCharFormat f = qvariant_cast<QTextFormat>(a.value).toCharFormat(); | - | ||||||||||||||||||||||||
1352 | if (f.isValid()) {
| 0-2 | ||||||||||||||||||||||||
1353 | QTextLayout::FormatRange o; | - | ||||||||||||||||||||||||
1354 | o.start = a.start + cursor.position() - block.position(); | - | ||||||||||||||||||||||||
1355 | o.length = a.length; | - | ||||||||||||||||||||||||
1356 | o.format = f; | - | ||||||||||||||||||||||||
1357 | overrides.append(o); | - | ||||||||||||||||||||||||
1358 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||||||||
1359 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||||||||
1360 | } executed 34 times by 1 test: end of block Executed by:
| 34 | ||||||||||||||||||||||||
1361 | layout->setFormats(overrides); | - | ||||||||||||||||||||||||
1362 | - | |||||||||||||||||||||||||
1363 | cursor.endEditBlock(); | - | ||||||||||||||||||||||||
1364 | - | |||||||||||||||||||||||||
1365 | QTextCursorPrivate *cursor_d = QTextCursorPrivate::getPrivate(&cursor); | - | ||||||||||||||||||||||||
1366 | if (cursor_d)
| 0-324 | ||||||||||||||||||||||||
1367 | cursor_d->setX(); executed 324 times by 1 test: cursor_d->setX(); Executed by:
| 324 | ||||||||||||||||||||||||
1368 | q->updateCursorRectangle(oldPreeditCursor != preeditCursor || forceSelectionChanged || isGettingInput); | - | ||||||||||||||||||||||||
1369 | selectionChanged(forceSelectionChanged); | - | ||||||||||||||||||||||||
1370 | } executed 324 times by 1 test: end of block Executed by:
| 324 | ||||||||||||||||||||||||
1371 | - | |||||||||||||||||||||||||
1372 | QVariant QQuickTextControl::inputMethodQuery(Qt::InputMethodQuery property) const | - | ||||||||||||||||||||||||
1373 | { | - | ||||||||||||||||||||||||
1374 | return inputMethodQuery(property, QVariant()); never executed: return inputMethodQuery(property, QVariant()); | 0 | ||||||||||||||||||||||||
1375 | } | - | ||||||||||||||||||||||||
1376 | - | |||||||||||||||||||||||||
1377 | QVariant QQuickTextControl::inputMethodQuery(Qt::InputMethodQuery property, QVariant argument) const | - | ||||||||||||||||||||||||
1378 | { | - | ||||||||||||||||||||||||
1379 | Q_D(const QQuickTextControl); | - | ||||||||||||||||||||||||
1380 | QTextBlock block = d->cursor.block(); | - | ||||||||||||||||||||||||
1381 | switch (property) { | - | ||||||||||||||||||||||||
1382 | case Qt::ImCursorRectangle: executed 26 times by 1 test: case Qt::ImCursorRectangle: Executed by:
| 26 | ||||||||||||||||||||||||
1383 | return cursorRect(); executed 26 times by 1 test: return cursorRect(); Executed by:
| 26 | ||||||||||||||||||||||||
1384 | case Qt::ImAnchorRectangle: never executed: case Qt::ImAnchorRectangle: | 0 | ||||||||||||||||||||||||
1385 | return anchorRect(); never executed: return anchorRect(); | 0 | ||||||||||||||||||||||||
1386 | case Qt::ImFont: never executed: case Qt::ImFont: | 0 | ||||||||||||||||||||||||
1387 | return QVariant(d->cursor.charFormat().font()); never executed: return QVariant(d->cursor.charFormat().font()); | 0 | ||||||||||||||||||||||||
1388 | case Qt::ImCursorPosition: { never executed: case Qt::ImCursorPosition: | 0 | ||||||||||||||||||||||||
1389 | const QPointF pt = argument.toPointF(); | - | ||||||||||||||||||||||||
1390 | if (!pt.isNull())
| 0 | ||||||||||||||||||||||||
1391 | return QVariant(d->doc->documentLayout()->hitTest(pt, Qt::FuzzyHit) - block.position()); never executed: return QVariant(d->doc->documentLayout()->hitTest(pt, Qt::FuzzyHit) - block.position()); | 0 | ||||||||||||||||||||||||
1392 | return QVariant(d->cursor.position() - block.position()); never executed: return QVariant(d->cursor.position() - block.position()); | 0 | ||||||||||||||||||||||||
1393 | } | - | ||||||||||||||||||||||||
1394 | case Qt::ImSurroundingText: never executed: case Qt::ImSurroundingText: | 0 | ||||||||||||||||||||||||
1395 | return QVariant(block.text()); never executed: return QVariant(block.text()); | 0 | ||||||||||||||||||||||||
1396 | case Qt::ImCurrentSelection: never executed: case Qt::ImCurrentSelection: | 0 | ||||||||||||||||||||||||
1397 | return QVariant(d->cursor.selectedText()); never executed: return QVariant(d->cursor.selectedText()); | 0 | ||||||||||||||||||||||||
1398 | case Qt::ImMaximumTextLength: never executed: case Qt::ImMaximumTextLength: | 0 | ||||||||||||||||||||||||
1399 | return QVariant(); // No limit. never executed: return QVariant(); | 0 | ||||||||||||||||||||||||
1400 | case Qt::ImAnchorPosition: never executed: case Qt::ImAnchorPosition: | 0 | ||||||||||||||||||||||||
1401 | return QVariant(d->cursor.anchor() - block.position()); never executed: return QVariant(d->cursor.anchor() - block.position()); | 0 | ||||||||||||||||||||||||
1402 | case Qt::ImAbsolutePosition: never executed: case Qt::ImAbsolutePosition: | 0 | ||||||||||||||||||||||||
1403 | return QVariant(d->cursor.anchor()); never executed: return QVariant(d->cursor.anchor()); | 0 | ||||||||||||||||||||||||
1404 | case Qt::ImTextAfterCursor: never executed: case Qt::ImTextAfterCursor: | 0 | ||||||||||||||||||||||||
1405 | { | - | ||||||||||||||||||||||||
1406 | int maxLength = argument.isValid() ? argument.toInt() : 1024;
| 0 | ||||||||||||||||||||||||
1407 | QTextCursor tmpCursor = d->cursor; | - | ||||||||||||||||||||||||
1408 | int localPos = d->cursor.position() - block.position(); | - | ||||||||||||||||||||||||
1409 | QString result = block.text().mid(localPos); | - | ||||||||||||||||||||||||
1410 | while (result.length() < maxLength) {
| 0 | ||||||||||||||||||||||||
1411 | int currentBlock = tmpCursor.blockNumber(); | - | ||||||||||||||||||||||||
1412 | tmpCursor.movePosition(QTextCursor::NextBlock); | - | ||||||||||||||||||||||||
1413 | if (tmpCursor.blockNumber() == currentBlock)
| 0 | ||||||||||||||||||||||||
1414 | break; never executed: break; | 0 | ||||||||||||||||||||||||
1415 | result += QLatin1Char('\n') + tmpCursor.block().text(); | - | ||||||||||||||||||||||||
1416 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1417 | return QVariant(result); never executed: return QVariant(result); | 0 | ||||||||||||||||||||||||
1418 | } | - | ||||||||||||||||||||||||
1419 | case Qt::ImTextBeforeCursor: never executed: case Qt::ImTextBeforeCursor: | 0 | ||||||||||||||||||||||||
1420 | { | - | ||||||||||||||||||||||||
1421 | int maxLength = argument.isValid() ? argument.toInt() : 1024;
| 0 | ||||||||||||||||||||||||
1422 | QTextCursor tmpCursor = d->cursor; | - | ||||||||||||||||||||||||
1423 | int localPos = d->cursor.position() - block.position(); | - | ||||||||||||||||||||||||
1424 | int numBlocks = 0; | - | ||||||||||||||||||||||||
1425 | int resultLen = localPos; | - | ||||||||||||||||||||||||
1426 | while (resultLen < maxLength) {
| 0 | ||||||||||||||||||||||||
1427 | int currentBlock = tmpCursor.blockNumber(); | - | ||||||||||||||||||||||||
1428 | tmpCursor.movePosition(QTextCursor::PreviousBlock); | - | ||||||||||||||||||||||||
1429 | if (tmpCursor.blockNumber() == currentBlock)
| 0 | ||||||||||||||||||||||||
1430 | break; never executed: break; | 0 | ||||||||||||||||||||||||
1431 | numBlocks++; | - | ||||||||||||||||||||||||
1432 | resultLen += tmpCursor.block().length(); | - | ||||||||||||||||||||||||
1433 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1434 | QString result; | - | ||||||||||||||||||||||||
1435 | while (numBlocks) {
| 0 | ||||||||||||||||||||||||
1436 | result += tmpCursor.block().text() + QLatin1Char('\n'); | - | ||||||||||||||||||||||||
1437 | tmpCursor.movePosition(QTextCursor::NextBlock); | - | ||||||||||||||||||||||||
1438 | --numBlocks; | - | ||||||||||||||||||||||||
1439 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1440 | result += block.text().midRef(0,localPos); | - | ||||||||||||||||||||||||
1441 | return QVariant(result); never executed: return QVariant(result); | 0 | ||||||||||||||||||||||||
1442 | } | - | ||||||||||||||||||||||||
1443 | default: never executed: default: | 0 | ||||||||||||||||||||||||
1444 | return QVariant(); never executed: return QVariant(); | 0 | ||||||||||||||||||||||||
1445 | } | - | ||||||||||||||||||||||||
1446 | } | - | ||||||||||||||||||||||||
1447 | #endif // im | - | ||||||||||||||||||||||||
1448 | - | |||||||||||||||||||||||||
1449 | void QQuickTextControlPrivate::focusEvent(QFocusEvent *e) | - | ||||||||||||||||||||||||
1450 | { | - | ||||||||||||||||||||||||
1451 | Q_Q(QQuickTextControl); | - | ||||||||||||||||||||||||
1452 | emit q->updateRequest(); | - | ||||||||||||||||||||||||
1453 | hasFocus = e->gotFocus(); | - | ||||||||||||||||||||||||
1454 | if (e->gotFocus()) {
| 94-338 | ||||||||||||||||||||||||
1455 | setBlinkingCursorEnabled(interactionFlags & (Qt::TextEditable | Qt::TextSelectableByKeyboard)); | - | ||||||||||||||||||||||||
1456 | } else { executed 338 times by 3 tests: end of block Executed by:
| 338 | ||||||||||||||||||||||||
1457 | setBlinkingCursorEnabled(false); | - | ||||||||||||||||||||||||
1458 | - | |||||||||||||||||||||||||
1459 | if (cursorIsFocusIndicator
| 4-90 | ||||||||||||||||||||||||
1460 | && e->reason() != Qt::ActiveWindowFocusReason
| 6-84 | ||||||||||||||||||||||||
1461 | && e->reason() != Qt::PopupFocusReason
| 0-84 | ||||||||||||||||||||||||
1462 | && cursor.hasSelection()) {
| 8-76 | ||||||||||||||||||||||||
1463 | cursor.clearSelection(); | - | ||||||||||||||||||||||||
1464 | emit q->selectionChanged(); | - | ||||||||||||||||||||||||
1465 | } executed 8 times by 1 test: end of block Executed by:
| 8 | ||||||||||||||||||||||||
1466 | } executed 94 times by 3 tests: end of block Executed by:
| 94 | ||||||||||||||||||||||||
1467 | } | - | ||||||||||||||||||||||||
1468 | - | |||||||||||||||||||||||||
1469 | void QQuickTextControlPrivate::hoverEvent(QHoverEvent *e, const QPointF &pos) | - | ||||||||||||||||||||||||
1470 | { | - | ||||||||||||||||||||||||
1471 | Q_Q(QQuickTextControl); | - | ||||||||||||||||||||||||
1472 | - | |||||||||||||||||||||||||
1473 | QString link; | - | ||||||||||||||||||||||||
1474 | if (e->type() != QEvent::HoverLeave)
| 0-8 | ||||||||||||||||||||||||
1475 | link = q->anchorAt(pos); executed 8 times by 1 test: link = q->anchorAt(pos); Executed by:
| 8 | ||||||||||||||||||||||||
1476 | - | |||||||||||||||||||||||||
1477 | if (hoveredLink != link) {
| 0-8 | ||||||||||||||||||||||||
1478 | hoveredLink = link; | - | ||||||||||||||||||||||||
1479 | emit q->linkHovered(link); | - | ||||||||||||||||||||||||
1480 | } executed 8 times by 1 test: end of block Executed by:
| 8 | ||||||||||||||||||||||||
1481 | qCDebug(DBG_HOVER_TRACE) << q << e->type() << pos << "hoveredLink" << hoveredLink; never executed: QMessageLogger(__FILE__, 1481, __PRETTY_FUNCTION__, DBG_HOVER_TRACE().categoryName()).debug() << q << e->type() << pos << "hoveredLink" << hoveredLink;
| 0-8 | ||||||||||||||||||||||||
1482 | } executed 8 times by 1 test: end of block Executed by:
| 8 | ||||||||||||||||||||||||
1483 | - | |||||||||||||||||||||||||
1484 | bool QQuickTextControl::hasImState() const | - | ||||||||||||||||||||||||
1485 | { | - | ||||||||||||||||||||||||
1486 | Q_D(const QQuickTextControl); | - | ||||||||||||||||||||||||
1487 | return d->hasImState; executed 672 times by 1 test: return d->hasImState; Executed by:
| 672 | ||||||||||||||||||||||||
1488 | } | - | ||||||||||||||||||||||||
1489 | - | |||||||||||||||||||||||||
1490 | bool QQuickTextControl::overwriteMode() const | - | ||||||||||||||||||||||||
1491 | { | - | ||||||||||||||||||||||||
1492 | Q_D(const QQuickTextControl); | - | ||||||||||||||||||||||||
1493 | return d->overwriteMode; executed 6 times by 1 test: return d->overwriteMode; Executed by:
| 6 | ||||||||||||||||||||||||
1494 | } | - | ||||||||||||||||||||||||
1495 | - | |||||||||||||||||||||||||
1496 | void QQuickTextControl::setOverwriteMode(bool overwrite) | - | ||||||||||||||||||||||||
1497 | { | - | ||||||||||||||||||||||||
1498 | Q_D(QQuickTextControl); | - | ||||||||||||||||||||||||
1499 | if (d->overwriteMode == overwrite)
| 0-10 | ||||||||||||||||||||||||
1500 | return; never executed: return; | 0 | ||||||||||||||||||||||||
1501 | d->overwriteMode = overwrite; | - | ||||||||||||||||||||||||
1502 | emit overwriteModeChanged(overwrite); | - | ||||||||||||||||||||||||
1503 | } executed 10 times by 1 test: end of block Executed by:
| 10 | ||||||||||||||||||||||||
1504 | - | |||||||||||||||||||||||||
1505 | bool QQuickTextControl::cursorVisible() const | - | ||||||||||||||||||||||||
1506 | { | - | ||||||||||||||||||||||||
1507 | Q_D(const QQuickTextControl); | - | ||||||||||||||||||||||||
1508 | return d->cursorVisible; executed 324 times by 1 test: return d->cursorVisible; Executed by:
| 324 | ||||||||||||||||||||||||
1509 | } | - | ||||||||||||||||||||||||
1510 | - | |||||||||||||||||||||||||
1511 | void QQuickTextControl::setCursorVisible(bool visible) | - | ||||||||||||||||||||||||
1512 | { | - | ||||||||||||||||||||||||
1513 | Q_D(QQuickTextControl); | - | ||||||||||||||||||||||||
1514 | d->cursorVisible = visible; | - | ||||||||||||||||||||||||
1515 | d->setBlinkingCursorEnabled(d->cursorVisible | - | ||||||||||||||||||||||||
1516 | && (d->interactionFlags & (Qt::TextEditable | Qt::TextSelectableByKeyboard))); | - | ||||||||||||||||||||||||
1517 | } executed 482 times by 4 tests: end of block Executed by:
| 482 | ||||||||||||||||||||||||
1518 | - | |||||||||||||||||||||||||
1519 | QRectF QQuickTextControl::anchorRect() const | - | ||||||||||||||||||||||||
1520 | { | - | ||||||||||||||||||||||||
1521 | Q_D(const QQuickTextControl); | - | ||||||||||||||||||||||||
1522 | QRectF rect; | - | ||||||||||||||||||||||||
1523 | QTextCursor cursor = d->cursor; | - | ||||||||||||||||||||||||
1524 | if (!cursor.isNull()) {
| 0 | ||||||||||||||||||||||||
1525 | rect = d->rectForPosition(cursor.anchor()); | - | ||||||||||||||||||||||||
1526 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1527 | return rect; never executed: return rect; | 0 | ||||||||||||||||||||||||
1528 | } | - | ||||||||||||||||||||||||
1529 | - | |||||||||||||||||||||||||
1530 | QRectF QQuickTextControl::cursorRect(const QTextCursor &cursor) const | - | ||||||||||||||||||||||||
1531 | { | - | ||||||||||||||||||||||||
1532 | Q_D(const QQuickTextControl); | - | ||||||||||||||||||||||||
1533 | if (cursor.isNull())
| 0-2696 | ||||||||||||||||||||||||
1534 | return QRectF(); never executed: return QRectF(); | 0 | ||||||||||||||||||||||||
1535 | - | |||||||||||||||||||||||||
1536 | return d->rectForPosition(cursor.position()); executed 2696 times by 3 tests: return d->rectForPosition(cursor.position()); Executed by:
| 2696 | ||||||||||||||||||||||||
1537 | } | - | ||||||||||||||||||||||||
1538 | - | |||||||||||||||||||||||||
1539 | QRectF QQuickTextControl::cursorRect() const | - | ||||||||||||||||||||||||
1540 | { | - | ||||||||||||||||||||||||
1541 | Q_D(const QQuickTextControl); | - | ||||||||||||||||||||||||
1542 | return cursorRect(d->cursor); executed 2356 times by 3 tests: return cursorRect(d->cursor); Executed by:
| 2356 | ||||||||||||||||||||||||
1543 | } | - | ||||||||||||||||||||||||
1544 | - | |||||||||||||||||||||||||
1545 | QString QQuickTextControl::hoveredLink() const | - | ||||||||||||||||||||||||
1546 | { | - | ||||||||||||||||||||||||
1547 | Q_D(const QQuickTextControl); | - | ||||||||||||||||||||||||
1548 | return d->hoveredLink; executed 8 times by 1 test: return d->hoveredLink; Executed by:
| 8 | ||||||||||||||||||||||||
1549 | } | - | ||||||||||||||||||||||||
1550 | - | |||||||||||||||||||||||||
1551 | QString QQuickTextControl::anchorAt(const QPointF &pos) const | - | ||||||||||||||||||||||||
1552 | { | - | ||||||||||||||||||||||||
1553 | Q_D(const QQuickTextControl); | - | ||||||||||||||||||||||||
1554 | return d->doc->documentLayout()->anchorAt(pos); executed 1042 times by 1 test: return d->doc->documentLayout()->anchorAt(pos); Executed by:
| 1042 | ||||||||||||||||||||||||
1555 | } | - | ||||||||||||||||||||||||
1556 | - | |||||||||||||||||||||||||
1557 | void QQuickTextControl::setAcceptRichText(bool accept) | - | ||||||||||||||||||||||||
1558 | { | - | ||||||||||||||||||||||||
1559 | Q_D(QQuickTextControl); | - | ||||||||||||||||||||||||
1560 | d->acceptRichText = accept; | - | ||||||||||||||||||||||||
1561 | } executed 1212 times by 6 tests: end of block Executed by:
| 1212 | ||||||||||||||||||||||||
1562 | - | |||||||||||||||||||||||||
1563 | void QQuickTextControl::moveCursor(QTextCursor::MoveOperation op, QTextCursor::MoveMode mode) | - | ||||||||||||||||||||||||
1564 | { | - | ||||||||||||||||||||||||
1565 | Q_D(QQuickTextControl); | - | ||||||||||||||||||||||||
1566 | const QTextCursor oldSelection = d->cursor; | - | ||||||||||||||||||||||||
1567 | const bool moved = d->cursor.movePosition(op, mode); | - | ||||||||||||||||||||||||
1568 | d->_q_updateCurrentCharFormatAndSelection(); | - | ||||||||||||||||||||||||
1569 | updateCursorRectangle(true); | - | ||||||||||||||||||||||||
1570 | d->repaintOldAndNewSelection(oldSelection); | - | ||||||||||||||||||||||||
1571 | if (moved)
| 26-36 | ||||||||||||||||||||||||
1572 | emit cursorPositionChanged(); executed 36 times by 1 test: cursorPositionChanged(); Executed by:
| 36 | ||||||||||||||||||||||||
1573 | } executed 62 times by 2 tests: end of block Executed by:
| 62 | ||||||||||||||||||||||||
1574 | - | |||||||||||||||||||||||||
1575 | bool QQuickTextControl::canPaste() const | - | ||||||||||||||||||||||||
1576 | { | - | ||||||||||||||||||||||||
1577 | #if QT_CONFIG(clipboard) | - | ||||||||||||||||||||||||
1578 | Q_D(const QQuickTextControl); | - | ||||||||||||||||||||||||
1579 | if (d->interactionFlags & Qt::TextEditable) {
| 44-4992 | ||||||||||||||||||||||||
1580 | const QMimeData *md = QGuiApplication::clipboard()->mimeData(); | - | ||||||||||||||||||||||||
1581 | return md && canInsertFromMimeData(md); executed 4992 times by 1 test: return md && canInsertFromMimeData(md); Executed by:
| 4992 | ||||||||||||||||||||||||
1582 | } | - | ||||||||||||||||||||||||
1583 | #endif | - | ||||||||||||||||||||||||
1584 | return false; executed 44 times by 2 tests: return false; Executed by:
| 44 | ||||||||||||||||||||||||
1585 | } | - | ||||||||||||||||||||||||
1586 | - | |||||||||||||||||||||||||
1587 | void QQuickTextControl::setCursorIsFocusIndicator(bool b) | - | ||||||||||||||||||||||||
1588 | { | - | ||||||||||||||||||||||||
1589 | Q_D(QQuickTextControl); | - | ||||||||||||||||||||||||
1590 | d->cursorIsFocusIndicator = b; | - | ||||||||||||||||||||||||
1591 | d->repaintCursor(); | - | ||||||||||||||||||||||||
1592 | } executed 1186 times by 6 tests: end of block Executed by:
| 1186 | ||||||||||||||||||||||||
1593 | - | |||||||||||||||||||||||||
1594 | void QQuickTextControl::setWordSelectionEnabled(bool enabled) | - | ||||||||||||||||||||||||
1595 | { | - | ||||||||||||||||||||||||
1596 | Q_D(QQuickTextControl); | - | ||||||||||||||||||||||||
1597 | d->wordSelectionEnabled = enabled; | - | ||||||||||||||||||||||||
1598 | } executed 30 times by 1 test: end of block Executed by:
| 30 | ||||||||||||||||||||||||
1599 | - | |||||||||||||||||||||||||
1600 | QMimeData *QQuickTextControl::createMimeDataFromSelection() const | - | ||||||||||||||||||||||||
1601 | { | - | ||||||||||||||||||||||||
1602 | Q_D(const QQuickTextControl); | - | ||||||||||||||||||||||||
1603 | const QTextDocumentFragment fragment(d->cursor); | - | ||||||||||||||||||||||||
1604 | return new QQuickTextEditMimeData(fragment); executed 614 times by 1 test: return new QQuickTextEditMimeData(fragment); Executed by:
| 614 | ||||||||||||||||||||||||
1605 | } | - | ||||||||||||||||||||||||
1606 | - | |||||||||||||||||||||||||
1607 | bool QQuickTextControl::canInsertFromMimeData(const QMimeData *source) const | - | ||||||||||||||||||||||||
1608 | { | - | ||||||||||||||||||||||||
1609 | Q_D(const QQuickTextControl); | - | ||||||||||||||||||||||||
1610 | if (d->acceptRichText)
| 386-4606 | ||||||||||||||||||||||||
1611 | return source->hasText() executed 386 times by 1 test: return source->hasText() || source->hasHtml() || source->hasFormat(QLatin1String("application/x-qrichtext")) || source->hasFormat(QLatin1String("application/x-qt-richtext")); Executed by:
| 386 | ||||||||||||||||||||||||
1612 | || source->hasHtml() executed 386 times by 1 test: return source->hasText() || source->hasHtml() || source->hasFormat(QLatin1String("application/x-qrichtext")) || source->hasFormat(QLatin1String("application/x-qt-richtext")); Executed by:
| 386 | ||||||||||||||||||||||||
1613 | || source->hasFormat(QLatin1String("application/x-qrichtext")) executed 386 times by 1 test: return source->hasText() || source->hasHtml() || source->hasFormat(QLatin1String("application/x-qrichtext")) || source->hasFormat(QLatin1String("application/x-qt-richtext")); Executed by:
| 386 | ||||||||||||||||||||||||
1614 | || source->hasFormat(QLatin1String("application/x-qt-richtext")); executed 386 times by 1 test: return source->hasText() || source->hasHtml() || source->hasFormat(QLatin1String("application/x-qrichtext")) || source->hasFormat(QLatin1String("application/x-qt-richtext")); Executed by:
| 386 | ||||||||||||||||||||||||
1615 | else | - | ||||||||||||||||||||||||
1616 | return source->hasText(); executed 4606 times by 1 test: return source->hasText(); Executed by:
| 4606 | ||||||||||||||||||||||||
1617 | } | - | ||||||||||||||||||||||||
1618 | - | |||||||||||||||||||||||||
1619 | void QQuickTextControl::insertFromMimeData(const QMimeData *source) | - | ||||||||||||||||||||||||
1620 | { | - | ||||||||||||||||||||||||
1621 | Q_D(QQuickTextControl); | - | ||||||||||||||||||||||||
1622 | if (!(d->interactionFlags & Qt::TextEditable) || !source)
| 0-14 | ||||||||||||||||||||||||
1623 | return; executed 2 times by 1 test: return; Executed by:
| 2 | ||||||||||||||||||||||||
1624 | - | |||||||||||||||||||||||||
1625 | bool hasData = false; | - | ||||||||||||||||||||||||
1626 | QTextDocumentFragment fragment; | - | ||||||||||||||||||||||||
1627 | #if QT_CONFIG(texthtmlparser) | - | ||||||||||||||||||||||||
1628 | if (source->hasFormat(QLatin1String("application/x-qrichtext")) && d->acceptRichText) {
| 0-14 | ||||||||||||||||||||||||
1629 | // x-qrichtext is always UTF-8 (taken from Qt3 since we don't use it anymore). | - | ||||||||||||||||||||||||
1630 | const QString richtext = QLatin1String("<meta name=\"qrichtext\" content=\"1\" />") | - | ||||||||||||||||||||||||
1631 | + QString::fromUtf8(source->data(QLatin1String("application/x-qrichtext"))); | - | ||||||||||||||||||||||||
1632 | fragment = QTextDocumentFragment::fromHtml(richtext, d->doc); | - | ||||||||||||||||||||||||
1633 | hasData = true; | - | ||||||||||||||||||||||||
1634 | } else if (source->hasHtml() && d->acceptRichText) { never executed: end of block
| 0-14 | ||||||||||||||||||||||||
1635 | fragment = QTextDocumentFragment::fromHtml(source->html(), d->doc); | - | ||||||||||||||||||||||||
1636 | hasData = true; | - | ||||||||||||||||||||||||
1637 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
1638 | QString text = source->text(); | - | ||||||||||||||||||||||||
1639 | if (!text.isNull()) {
| 2-12 | ||||||||||||||||||||||||
1640 | fragment = QTextDocumentFragment::fromPlainText(text); | - | ||||||||||||||||||||||||
1641 | hasData = true; | - | ||||||||||||||||||||||||
1642 | } executed 12 times by 1 test: end of block Executed by:
| 12 | ||||||||||||||||||||||||
1643 | } executed 14 times by 1 test: end of block Executed by:
| 14 | ||||||||||||||||||||||||
1644 | #else | - | ||||||||||||||||||||||||
1645 | fragment = QTextDocumentFragment::fromPlainText(source->text()); | - | ||||||||||||||||||||||||
1646 | #endif // texthtmlparser | - | ||||||||||||||||||||||||
1647 | - | |||||||||||||||||||||||||
1648 | if (hasData)
| 2-12 | ||||||||||||||||||||||||
1649 | d->cursor.insertFragment(fragment); executed 12 times by 1 test: d->cursor.insertFragment(fragment); Executed by:
| 12 | ||||||||||||||||||||||||
1650 | updateCursorRectangle(true); | - | ||||||||||||||||||||||||
1651 | } executed 14 times by 1 test: end of block Executed by:
| 14 | ||||||||||||||||||||||||
1652 | - | |||||||||||||||||||||||||
1653 | void QQuickTextControlPrivate::activateLinkUnderCursor(QString href) | - | ||||||||||||||||||||||||
1654 | { | - | ||||||||||||||||||||||||
1655 | QTextCursor oldCursor = cursor; | - | ||||||||||||||||||||||||
1656 | - | |||||||||||||||||||||||||
1657 | if (href.isEmpty()) {
| 0-4 | ||||||||||||||||||||||||
1658 | QTextCursor tmp = cursor; | - | ||||||||||||||||||||||||
1659 | if (tmp.selectionStart() != tmp.position())
| 0 | ||||||||||||||||||||||||
1660 | tmp.setPosition(tmp.selectionStart()); never executed: tmp.setPosition(tmp.selectionStart()); | 0 | ||||||||||||||||||||||||
1661 | tmp.movePosition(QTextCursor::NextCharacter); | - | ||||||||||||||||||||||||
1662 | href = tmp.charFormat().anchorHref(); | - | ||||||||||||||||||||||||
1663 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1664 | if (href.isEmpty())
| 0-4 | ||||||||||||||||||||||||
1665 | return; never executed: return; | 0 | ||||||||||||||||||||||||
1666 | - | |||||||||||||||||||||||||
1667 | if (!cursor.hasSelection()) {
| 0-4 | ||||||||||||||||||||||||
1668 | QTextBlock block = cursor.block(); | - | ||||||||||||||||||||||||
1669 | const int cursorPos = cursor.position(); | - | ||||||||||||||||||||||||
1670 | - | |||||||||||||||||||||||||
1671 | QTextBlock::Iterator it = block.begin(); | - | ||||||||||||||||||||||||
1672 | QTextBlock::Iterator linkFragment; | - | ||||||||||||||||||||||||
1673 | - | |||||||||||||||||||||||||
1674 | for (; !it.atEnd(); ++it) {
| 0-8 | ||||||||||||||||||||||||
1675 | QTextFragment fragment = it.fragment(); | - | ||||||||||||||||||||||||
1676 | const int fragmentPos = fragment.position(); | - | ||||||||||||||||||||||||
1677 | if (fragmentPos <= cursorPos &&
| 0-8 | ||||||||||||||||||||||||
1678 | fragmentPos + fragment.length() |