qwidgettextcontrol.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/widgets/widgets/qwidgettextcontrol.cpp
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4-
5-
6-
7-
8-
9-
10static QTextLine currentTextLine(const QTextCursor &cursor)-
11{-
12 const QTextBlock block = cursor.block();-
13 if (!block.isValid())-
14 return QTextLine();-
15-
16 const QTextLayout *layout = block.layout();-
17 if (!layout)-
18 return QTextLine();-
19-
20 const int relativePos = cursor.position() - block.position();-
21 return layout->lineForTextPosition(relativePos);-
22}-
23-
24QWidgetTextControlPrivate::QWidgetTextControlPrivate()-
25 : doc(0), cursorOn(false), cursorVisible(false), cursorIsFocusIndicator(false),-
26-
27 interactionFlags(Qt::TextEditorInteraction),-
28-
29-
30-
31 dragEnabled(true),-
32-
33 mousePressed(false), mightStartDrag(false),-
34-
35 lastSelectionPosition(0), lastSelectionAnchor(0),-
36 ignoreAutomaticScrollbarAdjustement(false),-
37 overwriteMode(false),-
38 acceptRichText(true),-
39 preeditCursor(0), hideCursor(false),-
40 hasFocus(false),-
41-
42-
43-
44 isEnabled(true),-
45 hadSelectionOnMousePress(false),-
46 ignoreUnusedNavigationEvents(false),-
47 openExternalLinks(false),-
48 wordSelectionEnabled(false)-
49{}
never executed: end of block
0
50-
51bool QWidgetTextControlPrivate::cursorMoveKeyEvent(QKeyEvent *e)-
52{-
53-
54-
55-
56-
57 QWidgetTextControl * const q = q_func();-
58 if (cursor.isNull())-
59 return false;-
60-
61 const QTextCursor oldSelection = cursor;-
62 const int oldCursorPos = cursor.position();-
63-
64 QTextCursor::MoveMode mode = QTextCursor::MoveAnchor;-
65 QTextCursor::MoveOperation op = QTextCursor::NoMove;-
66-
67 if (false) {
dead code: { }
-
68 }
dead code: { }
-
69-
70 if (e == QKeySequence::MoveToNextChar) {-
71 op = QTextCursor::Right;-
72 }-
73 else if (e == QKeySequence::MoveToPreviousChar) {-
74 op = QTextCursor::Left;-
75 }-
76 else if (e == QKeySequence::SelectNextChar) {-
77 op = QTextCursor::Right;-
78 mode = QTextCursor::KeepAnchor;-
79 }-
80 else if (e == QKeySequence::SelectPreviousChar) {-
81 op = QTextCursor::Left;-
82 mode = QTextCursor::KeepAnchor;-
83 }-
84 else if (e == QKeySequence::SelectNextWord) {-
85 op = QTextCursor::WordRight;-
86 mode = QTextCursor::KeepAnchor;-
87 }-
88 else if (e == QKeySequence::SelectPreviousWord) {-
89 op = QTextCursor::WordLeft;-
90 mode = QTextCursor::KeepAnchor;-
91 }-
92 else if (e == QKeySequence::SelectStartOfLine) {-
93 op = QTextCursor::StartOfLine;-
94 mode = QTextCursor::KeepAnchor;-
95 }-
96 else if (e == QKeySequence::SelectEndOfLine) {-
97 op = QTextCursor::EndOfLine;-
98 mode = QTextCursor::KeepAnchor;-
99 }-
100 else if (e == QKeySequence::SelectStartOfBlock) {-
101 op = QTextCursor::StartOfBlock;-
102 mode = QTextCursor::KeepAnchor;-
103 }-
104 else if (e == QKeySequence::SelectEndOfBlock) {-
105 op = QTextCursor::EndOfBlock;-
106 mode = QTextCursor::KeepAnchor;-
107 }-
108 else if (e == QKeySequence::SelectStartOfDocument) {-
109 op = QTextCursor::Start;-
110 mode = QTextCursor::KeepAnchor;-
111 }-
112 else if (e == QKeySequence::SelectEndOfDocument) {-
113 op = QTextCursor::End;-
114 mode = QTextCursor::KeepAnchor;-
115 }-
116 else if (e == QKeySequence::SelectPreviousLine) {-
117 op = QTextCursor::Up;-
118 mode = QTextCursor::KeepAnchor;-
119 }-
120 else if (e == QKeySequence::SelectNextLine) {-
121 op = QTextCursor::Down;-
122 mode = QTextCursor::KeepAnchor;-
123 {-
124 QTextBlock block = cursor.block();-
125 QTextLine line = currentTextLine(cursor);-
126 if (!block.next().isValid()-
127 && line.isValid()-
128 && line.lineNumber() == block.layout()->lineCount() - 1)-
129 op = QTextCursor::End;-
130 }-
131 }-
132 else if (e == QKeySequence::MoveToNextWord) {-
133 op = QTextCursor::WordRight;-
134 }-
135 else if (e == QKeySequence::MoveToPreviousWord) {-
136 op = QTextCursor::WordLeft;-
137 }-
138 else if (e == QKeySequence::MoveToEndOfBlock) {-
139 op = QTextCursor::EndOfBlock;-
140 }-
141 else if (e == QKeySequence::MoveToStartOfBlock) {-
142 op = QTextCursor::StartOfBlock;-
143 }-
144 else if (e == QKeySequence::MoveToNextLine) {-
145 op = QTextCursor::Down;-
146 }-
147 else if (e == QKeySequence::MoveToPreviousLine) {-
148 op = QTextCursor::Up;-
149 }-
150 else if (e == QKeySequence::MoveToStartOfLine) {-
151 op = QTextCursor::StartOfLine;-
152 }-
153 else if (e == QKeySequence::MoveToEndOfLine) {-
154 op = QTextCursor::EndOfLine;-
155 }-
156 else if (e == QKeySequence::MoveToStartOfDocument) {-
157 op = QTextCursor::Start;-
158 }-
159 else if (e == QKeySequence::MoveToEndOfDocument) {-
160 op = QTextCursor::End;-
161 }-
162-
163 else {-
164 return false;-
165 }-
166 bool visualNavigation = cursor.visualNavigation();-
167 cursor.setVisualNavigation(true);-
168 const bool moved = cursor.movePosition(op, mode);-
169 cursor.setVisualNavigation(visualNavigation);-
170 q->ensureCursorVisible();-
171-
172 bool ignoreNavigationEvents = ignoreUnusedNavigationEvents;-
173 bool isNavigationEvent = e->key() == Qt::Key_Up || e->key() == Qt::Key_Down;-
174-
175-
176-
177-
178-
179-
180-
181 isNavigationEvent = isNavigationEvent || e->key() == Qt::Key_Left || e->key() == Qt::Key_Right;-
182-
183-
184 if (moved) {-
185 if (cursor.position() != oldCursorPos)-
186 q->cursorPositionChanged();-
187 q->microFocusChanged();-
188 } else if (ignoreNavigationEvents && isNavigationEvent && oldSelection.anchor() == cursor.anchor()) {-
189 return false;-
190 }-
191-
192 selectionChanged( (mode == QTextCursor::KeepAnchor));-
193-
194 repaintOldAndNewSelection(oldSelection);-
195-
196 return true;-
197}-
198-
199void QWidgetTextControlPrivate::updateCurrentCharFormat()-
200{-
201 QWidgetTextControl * const q = q_func();-
202-
203 QTextCharFormat fmt = cursor.charFormat();-
204 if (fmt == lastCharFormat)-
205 return;-
206 lastCharFormat = fmt;-
207-
208 q->currentCharFormatChanged(fmt);-
209 q->microFocusChanged();-
210}-
211-
212void QWidgetTextControlPrivate::indent()-
213{-
214 QTextBlockFormat blockFmt = cursor.blockFormat();-
215-
216 QTextList *list = cursor.currentList();-
217 if (!list) {-
218 QTextBlockFormat modifier;-
219 modifier.setIndent(blockFmt.indent() + 1);-
220 cursor.mergeBlockFormat(modifier);-
221 } else {-
222 QTextListFormat format = list->format();-
223 format.setIndent(format.indent() + 1);-
224-
225 if (list->itemNumber(cursor.block()) == 1)-
226 list->setFormat(format);-
227 else-
228 cursor.createList(format);-
229 }-
230}-
231-
232void QWidgetTextControlPrivate::outdent()-
233{-
234 QTextBlockFormat blockFmt = cursor.blockFormat();-
235-
236 QTextList *list = cursor.currentList();-
237-
238 if (!list) {-
239 QTextBlockFormat modifier;-
240 modifier.setIndent(blockFmt.indent() - 1);-
241 cursor.mergeBlockFormat(modifier);-
242 } else {-
243 QTextListFormat listFmt = list->format();-
244 listFmt.setIndent(listFmt.indent() - 1);-
245 list->setFormat(listFmt);-
246 }-
247}-
248-
249void QWidgetTextControlPrivate::gotoNextTableCell()-
250{-
251 QTextTable *table = cursor.currentTable();-
252 QTextTableCell cell = table->cellAt(cursor);-
253-
254 int newColumn = cell.column() + cell.columnSpan();-
255 int newRow = cell.row();-
256-
257 if (newColumn >= table->columns()) {-
258 newColumn = 0;-
259 ++newRow;-
260 if (newRow >= table->rows())-
261 table->insertRows(table->rows(), 1);-
262 }-
263-
264 cell = table->cellAt(newRow, newColumn);-
265 cursor = cell.firstCursorPosition();-
266}-
267-
268void QWidgetTextControlPrivate::gotoPreviousTableCell()-
269{-
270 QTextTable *table = cursor.currentTable();-
271 QTextTableCell cell = table->cellAt(cursor);-
272-
273 int newColumn = cell.column() - 1;-
274 int newRow = cell.row();-
275-
276 if (newColumn < 0) {-
277 newColumn = table->columns() - 1;-
278 --newRow;-
279 if (newRow < 0)-
280 return;-
281 }-
282-
283 cell = table->cellAt(newRow, newColumn);-
284 cursor = cell.firstCursorPosition();-
285}-
286-
287void QWidgetTextControlPrivate::createAutoBulletList()-
288{-
289 cursor.beginEditBlock();-
290-
291 QTextBlockFormat blockFmt = cursor.blockFormat();-
292-
293 QTextListFormat listFmt;-
294 listFmt.setStyle(QTextListFormat::ListDisc);-
295 listFmt.setIndent(blockFmt.indent() + 1);-
296-
297 blockFmt.setIndent(0);-
298 cursor.setBlockFormat(blockFmt);-
299-
300 cursor.createList(listFmt);-
301-
302 cursor.endEditBlock();-
303}-
304-
305void QWidgetTextControlPrivate::init(Qt::TextFormat format, const QString &text, QTextDocument *document)-
306{-
307 QWidgetTextControl * const q = q_func();-
308 setContent(format, text, document);-
309-
310 doc->setUndoRedoEnabled(interactionFlags & Qt::TextEditable);-
311 q->setCursorWidth(-1);-
312}-
313-
314void QWidgetTextControlPrivate::setContent(Qt::TextFormat format, const QString &text, QTextDocument *document)-
315{-
316 QWidgetTextControl * const q = q_func();-
317-
318-
319-
320 const QTextCharFormat charFormatForInsertion = cursor.charFormat();-
321-
322 bool clearDocument = true;-
323 if (!doc) {-
324 if (document) {-
325 doc = document;-
326 clearDocument = false;-
327 } else {-
328 palette = QApplication::palette("QWidgetTextControl");-
329 doc = new QTextDocument(q);-
330 }-
331 _q_documentLayoutChanged();-
332 cursor = QTextCursor(doc);-
333-
334-
335-
336 QObject::connect(doc, qFlagLocation("2""contentsChanged()" "\0" __FILE__ ":" "431""437"), q, qFlagLocation("1""_q_updateCurrentCharFormatAndSelection()" "\0" __FILE__ ":" "431""437"));-
337 QObject::connect(doc, qFlagLocation("2""cursorPositionChanged(QTextCursor)" "\0" __FILE__ ":" "432""438"), q, qFlagLocation("1""_q_emitCursorPosChanged(QTextCursor)" "\0" __FILE__ ":" "432""438"));-
338 QObject::connect(doc, qFlagLocation("2""documentLayoutChanged()" "\0" __FILE__ ":" "433""439"), q, qFlagLocation("1""_q_documentLayoutChanged()" "\0" __FILE__ ":" "433""439"));-
339-
340-
341 QObject::connect(doc, qFlagLocation("2""undoAvailable(bool)" "\0" __FILE__ ":" "436""442"), q, qFlagLocation("2""undoAvailable(bool)" "\0" __FILE__ ":" "436""442"));-
342 QObject::connect(doc, qFlagLocation("2""redoAvailable(bool)" "\0" __FILE__ ":" "437""443"), q, qFlagLocation("2""redoAvailable(bool)" "\0" __FILE__ ":" "437""443"));-
343 QObject::connect(doc, qFlagLocation("2""modificationChanged(bool)" "\0" __FILE__ ":" "438""444"), q, qFlagLocation("2""modificationChanged(bool)" "\0" __FILE__ ":" "438""444"));-
344 QObject::connect(doc, qFlagLocation("2""blockCountChanged(int)" "\0" __FILE__ ":" "439""445"), q, qFlagLocation("2""blockCountChanged(int)" "\0" __FILE__ ":" "439""445"));-
345 }-
346-
347 bool previousUndoRedoState = doc->isUndoRedoEnabled();-
348 if (!document)-
349 doc->setUndoRedoEnabled(false);-
350-
351-
352 static int contentsChangedIndex = QMetaMethod::fromSignal(&QTextDocument::contentsChanged).methodIndex();-
353 static int textChangedIndex = QMetaMethod::fromSignal(&QWidgetTextControl::textChanged).methodIndex();-
354-
355 QMetaObject::disconnect(doc, contentsChangedIndex, q, textChangedIndex);-
356-
357 if (!text.isEmpty()) {-
358-
359-
360-
361-
362-
363-
364 cursor = QTextCursor();-
365 if (format == Qt::PlainText) {-
366 QTextCursor formatCursor(doc);-
367-
368-
369-
370 formatCursor.beginEditBlock();-
371 doc->setPlainText(text);-
372 doc->setUndoRedoEnabled(false);-
373 formatCursor.select(QTextCursor::Document);-
374 formatCursor.setCharFormat(charFormatForInsertion);-
375 formatCursor.endEditBlock();-
376 } else {-
377-
378 doc->setHtml(text);-
379-
380-
381-
382 doc->setUndoRedoEnabled(false);-
383 }-
384 cursor = QTextCursor(doc);-
385 } else if (clearDocument) {-
386 doc->clear();-
387 }-
388 cursor.setCharFormat(charFormatForInsertion);-
389-
390 QMetaObject::connect(doc, contentsChangedIndex, q, textChangedIndex);-
391 q->textChanged();-
392 if (!document)-
393 doc->setUndoRedoEnabled(previousUndoRedoState);-
394 _q_updateCurrentCharFormatAndSelection();-
395 if (!document)-
396 doc->setModified(false);-
397-
398 q->ensureCursorVisible();-
399 q->cursorPositionChanged();-
400-
401 QObject::connect(doc, qFlagLocation("2""contentsChange(int,int,int)" "\0" __FILE__ ":" "496""502"), q, qFlagLocation("1""_q_contentsChanged(int,int,int)" "\0" __FILE__ ":" "496""502"), Qt::UniqueConnection);-
402}-
403-
404void QWidgetTextControlPrivate::startDrag()-
405{-
406-
407 QWidgetTextControl * const q = q_func();-
408 mousePressed = false;-
409 if (!contextWidget)-
410 return;-
411 QMimeData *data = q->createMimeDataFromSelection();-
412-
413 QDrag *drag = new QDrag(contextWidget);-
414 drag->setMimeData(data);-
415-
416 Qt::DropActions actions = Qt::CopyAction;-
417 Qt::DropAction action;-
418 if (interactionFlags & Qt::TextEditable) {-
419 actions |= Qt::MoveAction;-
420 action = drag->exec(actions, Qt::MoveAction);-
421 } else {-
422 action = drag->exec(actions, Qt::CopyAction);-
423 }-
424-
425 if (action == Qt::MoveAction && drag->target() != contextWidget)-
426 cursor.removeSelectedText();-
427-
428}-
429-
430void QWidgetTextControlPrivate::setCursorPosition(const QPointF &pos)-
431{-
432 QWidgetTextControl * const q = q_func();-
433 const int cursorPos = q->hitTest(pos, Qt::FuzzyHit);-
434 if (cursorPos == -1)-
435 return;-
436 cursor.setPosition(cursorPos);-
437}-
438-
439void QWidgetTextControlPrivate::setCursorPosition(int pos, QTextCursor::MoveMode mode)-
440{-
441 cursor.setPosition(pos, mode);-
442-
443 if (mode != QTextCursor::KeepAnchor) {-
444 selectedWordOnDoubleClick = QTextCursor();-
445 selectedBlockOnTrippleClick = QTextCursor();-
446 }-
447}-
448-
449void QWidgetTextControlPrivate::repaintCursor()-
450{-
451 QWidgetTextControl * const q = q_func();-
452 q->updateRequest(cursorRectPlusUnicodeDirectionMarkers(cursor));-
453}-
454-
455void QWidgetTextControlPrivate::repaintOldAndNewSelection(const QTextCursor &oldSelection)-
456{-
457 QWidgetTextControl * const q = q_func();-
458 if (cursor.hasSelection()-
459 && oldSelection.hasSelection()-
460 && cursor.currentFrame() == oldSelection.currentFrame()-
461 && !cursor.hasComplexSelection()-
462 && !oldSelection.hasComplexSelection()-
463 && cursor.anchor() == oldSelection.anchor()-
464 ) {-
465 QTextCursor differenceSelection(doc);-
466 differenceSelection.setPosition(oldSelection.position());-
467 differenceSelection.setPosition(cursor.position(), QTextCursor::KeepAnchor);-
468 q->updateRequest(q->selectionRect(differenceSelection));-
469 } else {-
470 if (!oldSelection.isNull())-
471 q->updateRequest(q->selectionRect(oldSelection) | cursorRectPlusUnicodeDirectionMarkers(oldSelection));-
472 q->updateRequest(q->selectionRect() | cursorRectPlusUnicodeDirectionMarkers(cursor));-
473 }-
474}-
475-
476void QWidgetTextControlPrivate::selectionChanged(bool forceEmitSelectionChanged )-
477{-
478 QWidgetTextControl * const q = q_func();-
479 if (forceEmitSelectionChanged) {-
480 q->selectionChanged();-
481-
482 if (q->parent() && q->parent()->isWidgetType()) {-
483 QAccessibleTextSelectionEvent ev(q->parent(), cursor.anchor(), cursor.position());-
484 QAccessible::updateAccessibility(&ev);-
485 }-
486-
487 }-
488-
489 if (cursor.position() == lastSelectionPosition-
490 && cursor.anchor() == lastSelectionAnchor)-
491 return;-
492-
493 bool selectionStateChange = (cursor.hasSelection()-
494 != (lastSelectionPosition != lastSelectionAnchor));-
495 if (selectionStateChange)-
496 q->copyAvailable(cursor.hasSelection());-
497-
498 if (!forceEmitSelectionChanged-
499 && (selectionStateChange-
500 || (cursor.hasSelection()-
501 && (cursor.position() != lastSelectionPosition-
502 || cursor.anchor() != lastSelectionAnchor)))) {-
503 q->selectionChanged();-
504-
505 if (q->parent() && q->parent()->isWidgetType()) {-
506 QAccessibleTextSelectionEvent ev(q->parent(), cursor.anchor(), cursor.position());-
507 QAccessible::updateAccessibility(&ev);-
508 }-
509-
510 }-
511 q->microFocusChanged();-
512 lastSelectionPosition = cursor.position();-
513 lastSelectionAnchor = cursor.anchor();-
514}-
515-
516void QWidgetTextControlPrivate::_q_updateCurrentCharFormatAndSelection()-
517{-
518 updateCurrentCharFormat();-
519 selectionChanged();-
520}-
521-
522-
523void QWidgetTextControlPrivate::setClipboardSelection()-
524{-
525 QClipboard *clipboard = QApplication::clipboard();-
526 if (!cursor.hasSelection() || !clipboard->supportsSelection())-
527 return;-
528 QWidgetTextControl * const q = q_func();-
529 QMimeData *data = q->createMimeDataFromSelection();-
530 clipboard->setMimeData(data, QClipboard::Selection);-
531}-
532-
533-
534void QWidgetTextControlPrivate::_q_emitCursorPosChanged(const QTextCursor &someCursor)-
535{-
536 QWidgetTextControl * const q = q_func();-
537 if (someCursor.isCopyOf(cursor)) {-
538 q->cursorPositionChanged();-
539 q->microFocusChanged();-
540 }-
541}-
542-
543void QWidgetTextControlPrivate::_q_contentsChanged(int from, int charsRemoved, int charsAdded)-
544{-
545-
546 QWidgetTextControl * const q = q_func();-
547-
548 if (QAccessible::isActive() && q->parent() && q->parent()->isWidgetType()) {-
549 QTextCursor tmp(doc);-
550 tmp.setPosition(from);-
551-
552-
553 tmp.setPosition(qMin(doc->characterCount() - 1, from + charsAdded), QTextCursor::KeepAnchor);-
554 QString newText = tmp.selectedText();-
555-
556-
557 QString oldText = QString(charsRemoved, QLatin1Char(' '));-
558-
559 QAccessibleEvent *ev = 0;-
560 if (charsRemoved == 0) {-
561 ev = new QAccessibleTextInsertEvent(q->parent(), from, newText);-
562 } else if (charsAdded == 0) {-
563 ev = new QAccessibleTextRemoveEvent(q->parent(), from, oldText);-
564 } else {-
565 ev = new QAccessibleTextUpdateEvent(q->parent(), from, oldText, newText);-
566 }-
567 QAccessible::updateAccessibility(ev);-
568 delete ev;-
569 }-
570-
571-
572-
573-
574-
575}-
576-
577void QWidgetTextControlPrivate::_q_documentLayoutChanged()-
578{-
579 QWidgetTextControl * const q = q_func();-
580 QAbstractTextDocumentLayout *layout = doc->documentLayout();-
581 QObject::connect(layout, qFlagLocation("2""update(QRectF)" "\0" __FILE__ ":" "676""682"), q, qFlagLocation("2""updateRequest(QRectF)" "\0" __FILE__ ":" "676""682"));-
582 QObject::connect(layout, qFlagLocation("2""updateBlock(QTextBlock)" "\0" __FILE__ ":" "677""683"), q, qFlagLocation("1""_q_updateBlock(QTextBlock)" "\0" __FILE__ ":" "677""683"));-
583 QObject::connect(layout, qFlagLocation("2""documentSizeChanged(QSizeF)" "\0" __FILE__ ":" "678""684"), q, qFlagLocation("2""documentSizeChanged(QSizeF)" "\0" __FILE__ ":" "678""684"));-
584-
585}-
586-
587void QWidgetTextControlPrivate::setBlinkingCursorEnabledsetCursorVisible(bool enablevisible)-
588{-
589 QWidgetTextControl * const qif (cursorVisible == visible
cursorVisible == visibleDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
590 return;
never executed: return;
0
591-
592 cursorVisible = q_funcvisible;-
593 updateCursorBlinking();-
594-
595 if (enable &&cursorVisible
cursorVisibleDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
596 connect((static_cast<
never executed: connect((static_cast<QApplication *>(QCoreApplication::instance()))->styleHints(), &QStyleHints::cursorFlashTimeChanged, this, &QWidgetTextControlPrivate::updateCursorBlinking);
never executed: connect((static_cast<QApplication *>(QCoreApplication::instance()))->styleHints(), &QStyleHints::cursorFlashTimeChanged, this, &QWidgetTextControlPrivate::updateCursorBlinking);
QApplication *>(QCoreApplication::cursorFlashTimeinstance()))->styleHints(), &QStyleHints::cursorFlashTimeChanged, this, &QWidgetTextControlPrivate::updateCursorBlinking);
never executed: connect((static_cast<QApplication *>(QCoreApplication::instance()))->styleHints(), &QStyleHints::cursorFlashTimeChanged, this, &QWidgetTextControlPrivate::updateCursorBlinking);
0
597 else-
598 disconnect((static_cast<QApplication *>(QCoreApplication::instance()))->styleHints(), &QStyleHints::cursorFlashTimeChanged, this, &QWidgetTextControlPrivate::updateCursorBlinking);
never executed: disconnect((static_cast<QApplication *>(QCoreApplication::instance()))->styleHints(), &QStyleHints::cursorFlashTimeChanged, this, &QWidgetTextControlPrivate::updateCursorBlinking);
0
599}-
600-
601void QWidgetTextControlPrivate::updateCursorBlinking()-
> 0){
603 cursorBlinkTimer.startstop();-
604 if (QApplicationcursorVisible
cursorVisibleDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
605 int flashTime = QGuiApplication::styleHints()->cursorFlashTime() /();-
606 if (flashTime >=
flashTime >= 2Description
TRUEnever evaluated
FALSEnever evaluated
flashTime >= 2Description
TRUEnever evaluated
FALSEnever evaluated
2, q);
flashTime >= 2Description
TRUEnever evaluated
FALSEnever evaluated
0
else
flashTime >= 2Description
TRUEnever evaluated
FALSEnever evaluated
)
607 cursorBlinkTimer.stop();start(flashTime / 2, q_func());
never executed: cursorBlinkTimer.start(flashTime / 2, q_func());
0
608 }
never executed: end of block
0
609-
610 cursorOn = enablecursorVisible;-
611 repaintCursor();-
612}
never executed: end of block
0
613-
614void QWidgetTextControlPrivate::extendWordwiseSelection(int suggestedNewPosition, qreal mouseXPosition)-
615{-
616 QWidgetTextControl * const q = q_func();-
617-
618-
619 if (suggestedNewPosition >= selectedWordOnDoubleClick.selectionStart()-
620 && suggestedNewPosition <= selectedWordOnDoubleClick.selectionEnd()) {-
621 q->setTextCursor(selectedWordOnDoubleClick);-
622 return;-
623 }-
624-
625 QTextCursor curs = selectedWordOnDoubleClick;-
626 curs.setPosition(suggestedNewPosition, QTextCursor::KeepAnchor);-
627-
628 if (!curs.movePosition(QTextCursor::StartOfWord))-
629 return;-
630 const int wordStartPos = curs.position();-
631-
632 const int blockPos = curs.block().position();-
633 const QPointF blockCoordinates = q->blockBoundingRect(curs.block()).topLeft();-
634-
635 QTextLine line = currentTextLine(curs);-
636 if (!line.isValid())-
637 return;-
638-
639 const qreal wordStartX = line.cursorToX(curs.position() - blockPos) + blockCoordinates.x();-
640-
641 if (!curs.movePosition(QTextCursor::EndOfWord))-
642 return;-
643 const int wordEndPos = curs.position();-
644-
645 const QTextLine otherLine = currentTextLine(curs);-
646 if (otherLine.textStart() != line.textStart()-
647 || wordEndPos == wordStartPos)-
648 return;-
649-
650 const qreal wordEndX = line.cursorToX(curs.position() - blockPos) + blockCoordinates.x();-
651-
652 if (!wordSelectionEnabled && (mouseXPosition < wordStartX || mouseXPosition > wordEndX))-
653 return;-
654-
655 if (wordSelectionEnabled) {-
656 if (suggestedNewPosition < selectedWordOnDoubleClick.position()) {-
657 cursor.setPosition(selectedWordOnDoubleClick.selectionEnd());-
658 setCursorPosition(wordStartPos, QTextCursor::KeepAnchor);-
659 } else {-
660 cursor.setPosition(selectedWordOnDoubleClick.selectionStart());-
661 setCursorPosition(wordEndPos, QTextCursor::KeepAnchor);-
662 }-
663 } else {-
664-
665-
666 if (suggestedNewPosition < selectedWordOnDoubleClick.position())-
667 cursor.setPosition(selectedWordOnDoubleClick.selectionEnd());-
668 else-
669 cursor.setPosition(selectedWordOnDoubleClick.selectionStart());-
670-
671 const qreal differenceToStart = mouseXPosition - wordStartX;-
672 const qreal differenceToEnd = wordEndX - mouseXPosition;-
673-
674 if (differenceToStart < differenceToEnd)-
675 setCursorPosition(wordStartPos, QTextCursor::KeepAnchor);-
676 else-
677 setCursorPosition(wordEndPos, QTextCursor::KeepAnchor);-
678 }-
679-
680 if (interactionFlags & Qt::TextSelectableByMouse) {-
681-
682 setClipboardSelection();-
683-
684 selectionChanged(true);-
685 }-
686}-
687-
688void QWidgetTextControlPrivate::extendBlockwiseSelection(int suggestedNewPosition)-
689{-
690 QWidgetTextControl * const q = q_func();-
691-
692-
693 if (suggestedNewPosition >= selectedBlockOnTrippleClick.selectionStart()-
694 && suggestedNewPosition <= selectedBlockOnTrippleClick.selectionEnd()) {-
695 q->setTextCursor(selectedBlockOnTrippleClick);-
696 return;-
697 }-
698-
699 if (suggestedNewPosition < selectedBlockOnTrippleClick.position()) {-
700 cursor.setPosition(selectedBlockOnTrippleClick.selectionEnd());-
701 cursor.setPosition(suggestedNewPosition, QTextCursor::KeepAnchor);-
702 cursor.movePosition(QTextCursor::StartOfBlock, QTextCursor::KeepAnchor);-
703 } else {-
704 cursor.setPosition(selectedBlockOnTrippleClick.selectionStart());-
705 cursor.setPosition(suggestedNewPosition, QTextCursor::KeepAnchor);-
706 cursor.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor);-
707 cursor.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor);-
708 }-
709-
710 if (interactionFlags & Qt::TextSelectableByMouse) {-
711-
712 setClipboardSelection();-
713-
714 selectionChanged(true);-
715 }-
716}-
717-
718void QWidgetTextControlPrivate::_q_deleteSelected()-
719{-
720 if (!(interactionFlags & Qt::TextEditable) || !cursor.hasSelection())-
721 return;-
722 cursor.removeSelectedText();-
723}-
724-
725void QWidgetTextControl::undo()-
726{-
727 QWidgetTextControlPrivate * const d = d_func();-
728 d->repaintSelection();-
729 const int oldCursorPos = d->cursor.position();-
730 d->doc->undo(&d->cursor);-
731 if (d->cursor.position() != oldCursorPos)-
732 cursorPositionChanged();-
733 microFocusChanged();-
734 ensureCursorVisible();-
735}-
736-
737void QWidgetTextControl::redo()-
738{-
739 QWidgetTextControlPrivate * const d = d_func();-
740 d->repaintSelection();-
741 const int oldCursorPos = d->cursor.position();-
742 d->doc->redo(&d->cursor);-
743 if (d->cursor.position() != oldCursorPos)-
744 cursorPositionChanged();-
745 microFocusChanged();-
746 ensureCursorVisible();-
747}-
748-
749QWidgetTextControl::QWidgetTextControl(QObject *parent)-
750 : QInputControl(QInputControl::TextEdit, *QObject(*new QWidgetTextControlPrivate, parent)-
751{-
752 QWidgetTextControlPrivate * const d = d_func();-
753 d->init();-
754}
never executed: end of block
0
755-
756QWidgetTextControl::QWidgetTextControl(const QString &text, QObject *parent)-
757 : QInputControl(QInputControl::TextEdit, *QObject(*new QWidgetTextControlPrivate, parent)-
758{-
759 QWidgetTextControlPrivate * const d = d_func();-
760 d->init(Qt::RichText, text);-
761}
never executed: end of block
0
762-
763QWidgetTextControl::QWidgetTextControl(QTextDocument *doc, QObject *parent)-
764 : QInputControl(QInputControl::TextEdit, *QObject(*new QWidgetTextControlPrivate, parent)-
765{-
766 QWidgetTextControlPrivate * const d = d_func();-
767 d->init(Qt::RichText, QString(), doc);-
768}
never executed: end of block
0
769-
770QWidgetTextControl::~QWidgetTextControl()-
771{-
772}-
773-
774void QWidgetTextControl::setDocument(QTextDocument *document)-
775{-
776 QWidgetTextControlPrivate * const d = d_func();-
777 if (d->doc == document)-
778 return;-
779-
780 d->doc->disconnect(this);-
781 d->doc->documentLayout()->disconnect(this);-
782 d->doc->documentLayout()->setPaintDevice(0);-
783-
784 if (d->doc->parent() == this)-
785 delete d->doc;-
786-
787 d->doc = 0;-
788 d->setContent(Qt::RichText, QString(), document);-
789}-
790-
791QTextDocument *QWidgetTextControl::document() const-
792{-
793 const QWidgetTextControlPrivate * const d = d_func();-
794 return d->doc;-
795}-
796-
797void QWidgetTextControl::setTextCursor(const QTextCursor &cursor)-
798{-
799 QWidgetTextControlPrivate * const d = d_func();-
800 d->cursorIsFocusIndicator = false;-
801 const bool posChanged = cursor.position() != d->cursor.position();-
802 const QTextCursor oldSelection = d->cursor;-
803 d->cursor = cursor;-
804 d->cursorOn = d->hasFocus-
805 && (d->interactionFlags & (Qt::TextSelectableByKeyboard | Qt::TextEditable));-
806 d->_q_updateCurrentCharFormatAndSelection();-
807 ensureCursorVisible();-
808 d->repaintOldAndNewSelection(oldSelection);-
809 if (posChanged)-
810 cursorPositionChanged();-
811}-
812-
813QTextCursor QWidgetTextControl::textCursor() const-
814{-
815 const QWidgetTextControlPrivate * const d = d_func();-
816 return d->cursor;-
817}-
818-
819-
820-
821void QWidgetTextControl::cut()-
822{-
823 QWidgetTextControlPrivate * const d = d_func();-
824 if (!(d->interactionFlags & Qt::TextEditable) || !d->cursor.hasSelection())-
825 return;-
826 copy();-
827 d->cursor.removeSelectedText();-
828}-
829-
830void QWidgetTextControl::copy()-
831{-
832 QWidgetTextControlPrivate * const d = d_func();-
833 if (!d->cursor.hasSelection())-
834 return;-
835 QMimeData *data = createMimeDataFromSelection();-
836 QApplication::clipboard()->setMimeData(data);-
837}-
838-
839void QWidgetTextControl::paste(QClipboard::Mode mode)-
840{-
841 const QMimeData *md = QApplication::clipboard()->mimeData(mode);-
842 if (md)-
843 insertFromMimeData(md);-
844}-
845-
846-
847void QWidgetTextControl::clear()-
848{-
849 QWidgetTextControlPrivate * const d = d_func();-
850-
851 d->extraSelections.clear();-
852 d->setContent();-
853}-
854-
855-
856void QWidgetTextControl::selectAll()-
857{-
858 QWidgetTextControlPrivate * const d = d_func();-
859 const int selectionLength = qAbs(d->cursor.position() - d->cursor.anchor());-
860 d->cursor.select(QTextCursor::Document);-
861 d->selectionChanged(selectionLength != qAbs(d->cursor.position() - d->cursor.anchor()));-
862 d->cursorIsFocusIndicator = false;-
863 updateRequest();-
864}-
865-
866void QWidgetTextControl::processEvent(QEvent *e, const QPointF &coordinateOffset, QWidget *contextWidget)-
867{-
868 QMatrix m;-
869 m.translate(coordinateOffset.x(), coordinateOffset.y());-
870 processEvent(e, m, contextWidget);-
871}-
872-
873void QWidgetTextControl::processEvent(QEvent *e, const QMatrix &matrix, QWidget *contextWidget)-
874{-
875 QWidgetTextControlPrivate * const d = d_func();-
876 if (d->interactionFlags == Qt::NoTextInteraction) {-
877 e->ignore();-
878 return;-
879 }-
880-
881 d->contextWidget = contextWidget;-
882-
883 if (!d->contextWidget) {-
884 switch (e->type()) {-
885-
886 case QEvent::GraphicsSceneMouseMove:-
887 case QEvent::GraphicsSceneMousePress:-
888 case QEvent::GraphicsSceneMouseRelease:-
889 case QEvent::GraphicsSceneMouseDoubleClick:-
890 case QEvent::GraphicsSceneContextMenu:-
891 case QEvent::GraphicsSceneHoverEnter:-
892 case QEvent::GraphicsSceneHoverMove:-
893 case QEvent::GraphicsSceneHoverLeave:-
894 case QEvent::GraphicsSceneHelp:-
895 case QEvent::GraphicsSceneDragEnter:-
896 case QEvent::GraphicsSceneDragMove:-
897 case QEvent::GraphicsSceneDragLeave:-
898 case QEvent::GraphicsSceneDrop: {-
899 QGraphicsSceneEvent *ev = static_cast<QGraphicsSceneEvent *>(e);-
900 d->contextWidget = ev->widget();-
901 break;-
902 }-
903-
904 default: break;-
905 };-
906 }-
907-
908 switch (e->type()) {-
909 case QEvent::KeyPress:-
910 d->keyPressEvent(static_cast<QKeyEvent *>(e));-
911 break;-
912 case QEvent::MouseButtonPress: {-
913 QMouseEvent *ev = static_cast<QMouseEvent *>(e);-
914 d->mousePressEvent(ev, ev->button(), matrix.map(ev->pos()), ev->modifiers(),-
915 ev->buttons(), ev->globalPos());-
916 break; }-
917 case QEvent::MouseMove: {-
918 QMouseEvent *ev = static_cast<QMouseEvent *>(e);-
919 d->mouseMoveEvent(ev, ev->button(), matrix.map(ev->pos()), ev->modifiers(),-
920 ev->buttons(), ev->globalPos());-
921 break; }-
922 case QEvent::MouseButtonRelease: {-
923 QMouseEvent *ev = static_cast<QMouseEvent *>(e);-
924 d->mouseReleaseEvent(ev, ev->button(), matrix.map(ev->pos()), ev->modifiers(),-
925 ev->buttons(), ev->globalPos());-
926 break; }-
927 case QEvent::MouseButtonDblClick: {-
928 QMouseEvent *ev = static_cast<QMouseEvent *>(e);-
929 d->mouseDoubleClickEvent(ev, ev->button(), matrix.map(ev->pos()), ev->modifiers(),-
930 ev->buttons(), ev->globalPos());-
931 break; }-
932 case QEvent::InputMethod:-
933 d->inputMethodEvent(static_cast<QInputMethodEvent *>(e));-
934 break;-
935-
936 case QEvent::ContextMenu: {-
937 QContextMenuEvent *ev = static_cast<QContextMenuEvent *>(e);-
938 d->contextMenuEvent(ev->globalPos(), matrix.map(ev->pos()), contextWidget);-
939 break; }-
940-
941 case QEvent::FocusIn:-
942 case QEvent::FocusOut:-
943 d->focusEvent(static_cast<QFocusEvent *>(e));-
944 break;-
945-
946 case QEvent::EnabledChange:-
947 d->isEnabled = e->isAccepted();-
948 break;-
949-
950-
951 case QEvent::ToolTip: {-
952 QHelpEvent *ev = static_cast<QHelpEvent *>(e);-
953 d->showToolTip(ev->globalPos(), matrix.map(ev->pos()), contextWidget);-
954 break;-
955 }-
956-
957-
958-
959 case QEvent::DragEnter: {-
960 QDragEnterEvent *ev = static_cast<QDragEnterEvent *>(e);-
961 if (d->dragEnterEvent(e, ev->mimeData()))-
962 ev->acceptProposedAction();-
963 break;-
964 }-
965 case QEvent::DragLeave:-
966 d->dragLeaveEvent();-
967 break;-
968 case QEvent::DragMove: {-
969 QDragMoveEvent *ev = static_cast<QDragMoveEvent *>(e);-
970 if (d->dragMoveEvent(e, ev->mimeData(), matrix.map(ev->pos())))-
971 ev->acceptProposedAction();-
972 break;-
973 }-
974 case QEvent::Drop: {-
975 QDropEvent *ev = static_cast<QDropEvent *>(e);-
976 if (d->dropEvent(ev->mimeData(), matrix.map(ev->pos()), ev->dropAction(), ev->source()))-
977 ev->acceptProposedAction();-
978 break;-
979 }-
980-
981-
982-
983 case QEvent::GraphicsSceneMousePress: {-
984 QGraphicsSceneMouseEvent *ev = static_cast<QGraphicsSceneMouseEvent *>(e);-
985 d->mousePressEvent(ev, ev->button(), matrix.map(ev->pos()), ev->modifiers(), ev->buttons(),-
986 ev->screenPos());-
987 break; }-
988 case QEvent::GraphicsSceneMouseMove: {-
989 QGraphicsSceneMouseEvent *ev = static_cast<QGraphicsSceneMouseEvent *>(e);-
990 d->mouseMoveEvent(ev, ev->button(), matrix.map(ev->pos()), ev->modifiers(), ev->buttons(),-
991 ev->screenPos());-
992 break; }-
993 case QEvent::GraphicsSceneMouseRelease: {-
994 QGraphicsSceneMouseEvent *ev = static_cast<QGraphicsSceneMouseEvent *>(e);-
995 d->mouseReleaseEvent(ev, ev->button(), matrix.map(ev->pos()), ev->modifiers(), ev->buttons(),-
996 ev->screenPos());-
997 break; }-
998 case QEvent::GraphicsSceneMouseDoubleClick: {-
999 QGraphicsSceneMouseEvent *ev = static_cast<QGraphicsSceneMouseEvent *>(e);-
1000 d->mouseDoubleClickEvent(ev, ev->button(), matrix.map(ev->pos()), ev->modifiers(), ev->buttons(),-
1001 ev->screenPos());-
1002 break; }-
1003 case QEvent::GraphicsSceneContextMenu: {-
1004 QGraphicsSceneContextMenuEvent *ev = static_cast<QGraphicsSceneContextMenuEvent *>(e);-
1005 d->contextMenuEvent(ev->screenPos(), matrix.map(ev->pos()), contextWidget);-
1006 break; }-
1007-
1008 case QEvent::GraphicsSceneHoverMove: {-
1009 QGraphicsSceneHoverEvent *ev = static_cast<QGraphicsSceneHoverEvent *>(e);-
1010 d->mouseMoveEvent(ev, Qt::NoButton, matrix.map(ev->pos()), ev->modifiers(),Qt::NoButton,-
1011 ev->screenPos());-
1012 break; }-
1013-
1014 case QEvent::GraphicsSceneDragEnter: {-
1015 QGraphicsSceneDragDropEvent *ev = static_cast<QGraphicsSceneDragDropEvent *>(e);-
1016 if (d->dragEnterEvent(e, ev->mimeData()))-
1017 ev->acceptProposedAction();-
1018 break; }-
1019 case QEvent::GraphicsSceneDragLeave:-
1020 d->dragLeaveEvent();-
1021 break;-
1022 case QEvent::GraphicsSceneDragMove: {-
1023 QGraphicsSceneDragDropEvent *ev = static_cast<QGraphicsSceneDragDropEvent *>(e);-
1024 if (d->dragMoveEvent(e, ev->mimeData(), matrix.map(ev->pos())))-
1025 ev->acceptProposedAction();-
1026 break; }-
1027 case QEvent::GraphicsSceneDrop: {-
1028 QGraphicsSceneDragDropEvent *ev = static_cast<QGraphicsSceneDragDropEvent *>(e);-
1029 if (d->dropEvent(ev->mimeData(), matrix.map(ev->pos()), ev->dropAction(), ev->source()))-
1030 ev->accept();-
1031 break; }-
1032 case QEvent::ShortcutOverride:-
1033 if (d->interactionFlags & Qt::TextEditable) {-
1034 QKeyEvent* ke = static_cast<QKeyEvent *>(e);-
1035 if (ke->modifiers() == Qt::NoModifier-
1036 || ke->modifiers() == Qt::ShiftModifier-
1037 || ke->modifiers() == Qt::KeypadModifier) {-
1038 if (ke->key() < Qt::Key_Escape) {-
1039 ke->accept();-
1040 } else {-
1041 switch (ke->key()) {-
1042 case Qt::Key_Return:-
1043 case Qt::Key_Enter:-
1044 case Qt::Key_Delete:-
1045 case Qt::Key_Home:-
1046 case Qt::Key_End:-
1047 case Qt::Key_Backspace:-
1048 case Qt::Key_Left:-
1049 case Qt::Key_Right:-
1050 case Qt::Key_Up:-
1051 case Qt::Key_Down:-
1052 case Qt::Key_Tab:-
1053 ke->accept();-
1054 default:-
1055 break;-
1056 }-
1057 }-
1058-
1059 } else if (ke == QKeySequence::Copy-
1060 || ke == QKeySequence::Paste-
1061 || ke == QKeySequence::Cut-
1062 || ke == QKeySequence::Redo-
1063 || ke == QKeySequence::Undo-
1064 || ke == QKeySequence::MoveToNextWord-
1065 || ke == QKeySequence::MoveToPreviousWord-
1066 || ke == QKeySequence::MoveToStartOfDocument-
1067 || ke == QKeySequence::MoveToEndOfDocument-
1068 || ke == QKeySequence::SelectNextWord-
1069 || ke == QKeySequence::SelectPreviousWord-
1070 || ke == QKeySequence::SelectStartOfLine-
1071 || ke == QKeySequence::SelectEndOfLine-
1072 || ke == QKeySequence::SelectStartOfBlock-
1073 || ke == QKeySequence::SelectEndOfBlock-
1074 || ke == QKeySequence::SelectStartOfDocument-
1075 || ke == QKeySequence::SelectEndOfDocument-
1076 || ke == QKeySequence::SelectAll-
1077 ) {-
1078 ke->accept();-
1079-
1080 }-
1081 }-
1082 break;-
1083 default:-
1084 break;-
1085 }-
1086}-
1087-
1088bool QWidgetTextControl::event(QEvent *e)-
1089{-
1090 return QObject::event(e);-
1091}-
1092-
1093void QWidgetTextControl::timerEvent(QTimerEvent *e)-
1094{-
1095 QWidgetTextControlPrivate * const d = d_func();-
1096 if (e->timerId() == d->cursorBlinkTimer.timerId()) {-
1097 d->cursorOn = !d->cursorOn;-
1098-
1099 if (d->cursor.hasSelection())-
1100 d->cursorOn &= (QApplication::style()->styleHint(QStyle::SH_BlinkCursorWhenTextSelected)-
1101 != 0);-
1102-
1103 d->repaintCursor();-
1104 } else if (e->timerId() == d->trippleClickTimer.timerId()) {-
1105 d->trippleClickTimer.stop();-
1106 }-
1107}-
1108-
1109void QWidgetTextControl::setPlainText(const QString &text)-
1110{-
1111 QWidgetTextControlPrivate * const d = d_func();-
1112 d->setContent(Qt::PlainText, text);-
1113}-
1114-
1115void QWidgetTextControl::setHtml(const QString &text)-
1116{-
1117 QWidgetTextControlPrivate * const d = d_func();-
1118 d->setContent(Qt::RichText, text);-
1119}-
1120-
1121void QWidgetTextControlPrivate::keyPressEvent(QKeyEvent *e)-
1122{-
1123 QWidgetTextControl * const q = q_func();-
1124-
1125 if (e == QKeySequence::SelectAll
e == QKeySequence::SelectAllDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
1126 e->accept();-
1127 q->selectAll();-
1128 return;
never executed: return;
0
1129 }-
1130-
1131 else if (e == QKeySequence::Copy
e == QKeySequence::CopyDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
1132 e->accept();-
1133 q->copy();-
1134 return;
never executed: return;
0
1135 }-
1136-
1137-
1138-
1139 if (interactionFlags & Qt::TextSelectableByKeyboard
interactionFla...ableByKeyboardDescription
TRUEnever evaluated
FALSEnever evaluated
0
1140 && cursorMoveKeyEvent(e)
cursorMoveKeyEvent(e)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
1141 goto
never executed: goto accept;
accept;
never executed: goto accept;
0
1142-
1143 if (interactionFlags & Qt::LinksAccessibleByKeyboard
interactionFla...ibleByKeyboardDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
1144 if ((e->key() == Qt::Key_Return
e->key() == Qt::Key_ReturnDescription
TRUEnever evaluated
FALSEnever evaluated
0
1145 || e->key() == Qt::Key_Enter
e->key() == Qt::Key_EnterDescription
TRUEnever evaluated
FALSEnever evaluated
0
1146-
1147-
1148-
1149 )-
1150 && cursor.hasSelection()
cursor.hasSelection()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
1151-
1152 e->accept();-
1153 activateLinkUnderCursor();-
1154 return;
never executed: return;
0
1155 }-
1156 }
never executed: end of block
0
1157-
1158 if (!(interactionFlags & Qt::TextEditable)
!(interactionF...:TextEditable)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
1159 e->ignore();-
1160 return;
never executed: return;
0
1161 }-
1162-
1163 if (e->key() == Qt::Key_Direction_L
e->key() == Qt...ey_Direction_LDescription
TRUEnever evaluated
FALSEnever evaluated
|| e->key() == Qt::Key_Direction_R
e->key() == Qt...ey_Direction_RDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
1164 QTextBlockFormat fmt;-
1165 fmt.setLayoutDirection((e->key() == Qt::Key_Direction_L) ? Qt::LeftToRight : Qt::RightToLeft);-
1166 cursor.mergeBlockFormat(fmt);-
1167 goto
never executed: goto accept;
accept;
never executed: goto accept;
0
1168 }-
1169-
1170-
1171-
1172-
1173-
1174 repaintSelection();-
1175-
1176 if (e->key() == Qt::Key_Backspace
e->key() == Qt::Key_BackspaceDescription
TRUEnever evaluated
FALSEnever evaluated
&& !(e->modifiers() & ~Qt::ShiftModifier)
!(e->modifiers...ShiftModifier)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
1177 QTextBlockFormat blockFmt = cursor.blockFormat();-
1178 QTextList *list = cursor.currentList();-
1179 if (list
listDescription
TRUEnever evaluated
FALSEnever evaluated
&& cursor.atBlockStart()
cursor.atBlockStart()Description
TRUEnever evaluated
FALSEnever evaluated
&& !cursor.hasSelection()
!cursor.hasSelection()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
1180 list->remove(cursor.block());-
1181 }
never executed: end of block
else if (cursor.atBlockStart()
cursor.atBlockStart()Description
TRUEnever evaluated
FALSEnever evaluated
&& blockFmt.indent() > 0
blockFmt.indent() > 0Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
1182 blockFmt.setIndent(blockFmt.indent() - 1);-
1183 cursor.setBlockFormat(blockFmt);-
1184 }
never executed: end of block
else {
0
1185 QTextCursor localCursor = cursor;-
1186 localCursor.deletePreviousChar();-
1187 }
never executed: end of block
0
1188 goto
never executed: goto accept;
accept;
never executed: goto accept;
0
1189 }-
1190-
1191 else if (e == QKeySequence::InsertParagraphSeparator
e == QKeySeque...graphSeparatorDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
1192 cursor.insertBlock();-
1193 e->accept();-
1194 goto
never executed: goto accept;
accept;
never executed: goto accept;
0
1195 } else if (e == QKeySequence::InsertLineSeparator
e == QKeySeque...tLineSeparatorDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
1196 cursor.insertText(QString(QChar::LineSeparator));-
1197 e->accept();-
1198 goto
never executed: goto accept;
accept;
never executed: goto accept;
0
1199 }-
1200-
1201 if (false) {
dead code: { }
-
1202 }
dead code: { }
-
1203-
1204 else if (e == QKeySequence::Undo
e == QKeySequence::UndoDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
1205 q->undo();-
1206 }
never executed: end of block
0
1207 else if (e == QKeySequence::Redo
e == QKeySequence::RedoDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
1208 q->redo();-
1209 }
never executed: end of block
0
1210-
1211 else if (e == QKeySequence::Cut
e == QKeySequence::CutDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
1212 q->cut();-
1213 }
never executed: end of block
0
1214 else if (e == QKeySequence::Paste
e == QKeySequence::PasteDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
1215 QClipboard::Mode mode = QClipboard::Clipboard;-
1216 if (QGuiApplication::clipboard()->supportsSelection()
QGuiApplicatio...rtsSelection()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
1217 if (e->modifiers() == (Qt::CTRL | Qt::SHIFT)
e->modifiers()...L | Qt::SHIFT)Description
TRUEnever evaluated
FALSEnever evaluated
&& e->key() == Qt::Key_Insert
e->key() == Qt::Key_InsertDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
1218 mode = QClipboard::Selection;
never executed: mode = QClipboard::Selection;
0
1219 }
never executed: end of block
0
1220 q->paste(mode);-
1221 }
never executed: end of block
0
1222-
1223 else if (e == QKeySequence::Delete
e == QKeySequence::DeleteDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
1224 QTextCursor localCursor = cursor;-
1225 localCursor.deleteChar();-
1226 }
never executed: end of block
else if (e == QKeySequence::Backspace
e == QKeySequence::BackspaceDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
1227 QTextCursor localCursor = cursor;-
1228 localCursor.deletePreviousChar();-
1229 }
never executed: end of block
else if (e == QKeySequence::DeleteEndOfWord
e == QKeySeque...eleteEndOfWordDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
1230 if (!cursor.hasSelection()
!cursor.hasSelection()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
1231 cursor.movePosition(QTextCursor::NextWord, QTextCursor::KeepAnchor);
never executed: cursor.movePosition(QTextCursor::NextWord, QTextCursor::KeepAnchor);
0
1232 cursor.removeSelectedText();-
1233 }
never executed: end of block
0
1234 else if (e == QKeySequence::DeleteStartOfWord
e == QKeySeque...eteStartOfWordDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
1235 if (!cursor.hasSelection()
!cursor.hasSelection()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
1236 cursor.movePosition(QTextCursor::PreviousWord, QTextCursor::KeepAnchor);
never executed: cursor.movePosition(QTextCursor::PreviousWord, QTextCursor::KeepAnchor);
0
1237 cursor.removeSelectedText();-
1238 }
never executed: end of block
0
1239 else if (e == QKeySequence::DeleteEndOfLine
e == QKeySeque...eleteEndOfLineDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
1240 QTextBlock block = cursor.block();-
1241 if (cursor.position() == block.position() + block.length() - 2
cursor.positio...k.length() - 2Description
TRUEnever evaluated
FALSEnever evaluated
)
0
1242 cursor.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor);
never executed: cursor.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor);
0
1243 else-
1244 cursor.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor);
never executed: cursor.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor);
0
1245 cursor.removeSelectedText();-
1246 }
never executed: end of block
0
1247-
1248 else {-
1249 goto
never executed: goto process;
process;
never executed: goto process;
0
1250 }-
1251 goto
never executed: goto accept;
accept;
never executed: goto accept;
0
1252-
1253process:-
1254 {-
1255-
1256 if (qe
e->modifiers()...ontrolModifierDescription
TRUEnever evaluated
FALSEnever evaluated
->isAcceptableInput(modifiers() == Qt::ControlModifier
e->modifiers()...ontrolModifierDescription
TRUEnever evaluated
FALSEnever evaluated
0
1257 || e->modifiers() == (Qt::ShiftModifier | Qt::ControlModifier)
e->modifiers()...ntrolModifier)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
1258 e->ignore();-
1259 return;
never executed: return;
0
1260 }-
1261 QString text = e->text();-
1262 if (!text.isEmpty()
!text.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
&& (text.at(0).isPrint()
text.at(0).isPrint()Description
TRUEnever evaluated
FALSEnever evaluated
|| text.at(0) == QLatin1Char('\t')
text.at(0) == ...tin1Char('\t')Description
TRUEnever evaluated
FALSEnever evaluated
))
{
0
1263 if (overwriteMode
overwriteModeDescription
TRUEnever evaluated
FALSEnever evaluated
0
1264-
1265-
1266 && !cursor.hasSelection()
!cursor.hasSelection()Description
TRUEnever evaluated
FALSEnever evaluated
0
1267 && !cursor.atBlockEnd()
!cursor.atBlockEnd()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
1268 cursor.deleteChar();
never executed: cursor.deleteChar();
0
1269-
1270 cursor.insertText(e->text()););-
1271 selectionChanged();-
1272 }
never executed: end of block
else {
0
1273 e->ignore();-
1274 return;
never executed: return;
0
1275 }-
1276 }-
1277-
1278 accept:
code before this statement never executed: accept:
0
1279-
1280 e->accept();-
1281 cursorOn = true;-
1282-
1283 q->ensureCursorVisible();-
1284-
1285 updateCurrentCharFormat();-
1286}
never executed: end of block
0
1287-
1288QVariant QWidgetTextControl::loadResource(int type, const QUrl &name)-
1289{-
1290-
1291-
1292-
1293-
1294 if (QTextEdit *textEdit = qobject_cast<QTextEdit *>(parent())) {-
1295 QUrl resolvedName = textEdit->d_func()->resolveUrl(name);-
1296 return textEdit->loadResource(type, resolvedName);-
1297 }-
1298-
1299 return QVariant();-
1300}-
1301-
1302void QWidgetTextControlPrivate::_q_updateBlock(const QTextBlock &block)-
1303{-
1304 QWidgetTextControl * const q = q_func();-
1305 QRectF br = q->blockBoundingRect(block);-
1306 br.setRight(qreal(2147483647));-
1307 q->updateRequest(br);-
1308}-
1309-
1310QRectF QWidgetTextControlPrivate::rectForPosition(int position) const-
1311{-
1312 const QWidgetTextControl * const q = q_func();-
1313 const QTextBlock block = doc->findBlock(position);-
1314 if (!block.isValid())-
1315 return QRectF();-
1316 const QAbstractTextDocumentLayout *docLayout = doc->documentLayout();-
1317 const QTextLayout *layout = block.layout();-
1318 const QPointF layoutPos = q->blockBoundingRect(block).topLeft();-
1319 int relativePos = position - block.position();-
1320 if (preeditCursor != 0) {-
1321 int preeditPos = layout->preeditAreaPosition();-
1322 if (relativePos == preeditPos)-
1323 relativePos += preeditCursor;-
1324 else if (relativePos > preeditPos)-
1325 relativePos += layout->preeditAreaText().length();-
1326 }-
1327 QTextLine line = layout->lineForTextPosition(relativePos);-
1328-
1329 int cursorWidth;-
1330 {-
1331 bool ok = false;-
1332-
1333 cursorWidth = docLayout->property("cursorWidth").toInt(&ok);-
1334-
1335 if (!ok)-
1336 cursorWidth = 1;-
1337 }-
1338-
1339 QRectF r;-
1340-
1341 if (line.isValid()) {-
1342 qreal x = line.cursorToX(relativePos);-
1343 qreal w = 0;-
1344 if (overwriteMode) {-
1345 if (relativePos < line.textLength() - line.textStart())-
1346 w = line.cursorToX(relativePos + 1) - x;-
1347 else-
1348 w = QFontMetrics(block.layout()->font()).width(QLatin1Char(' '));-
1349 }-
1350 r = QRectF(layoutPos.x() + x, layoutPos.y() + line.y(),-
1351 cursorWidth + w, line.height());-
1352 } else {-
1353 r = QRectF(layoutPos.x(), layoutPos.y(), cursorWidth, 10);-
1354 }-
1355-
1356 return r;-
1357}-
1358-
1359namespace {-
1360struct QTextFrameComparator {-
1361-
1362-
1363-
1364-
1365 bool operator()(QTextFrame *frame, int position) { return frame->firstPosition() < position; }-
1366 bool operator()(int position, QTextFrame *frame) { return position < frame->firstPosition(); }-
1367};-
1368}-
1369-
1370static QRectF boundingRectOfFloatsInSelection(const QTextCursor &cursor)-
1371{-
1372 QRectF r;-
1373 QTextFrame *frame = cursor.currentFrame();-
1374 const QList<QTextFrame *> children = frame->childFrames();-
1375-
1376 const QList<QTextFrame *>::ConstIterator firstFrame = std::lower_bound(children.constBegin(), children.constEnd(),-
1377 cursor.selectionStart(), QTextFrameComparator());-
1378 const QList<QTextFrame *>::ConstIterator lastFrame = std::upper_bound(children.constBegin(), children.constEnd(),-
1379 cursor.selectionEnd(), QTextFrameComparator());-
1380 for (QList<QTextFrame *>::ConstIterator it = firstFrame; it != lastFrame; ++it) {-
1381 if ((*it)->frameFormat().position() != QTextFrameFormat::InFlow)-
1382 r |= frame->document()->documentLayout()->frameBoundingRect(*it);-
1383 }-
1384 return r;-
1385}-
1386-
1387QRectF QWidgetTextControl::selectionRect(const QTextCursor &cursor) const-
1388{-
1389 const QWidgetTextControlPrivate * const d = d_func();-
1390-
1391 QRectF r = d->rectForPosition(cursor.selectionStart());-
1392-
1393 if (cursor.hasComplexSelection() && cursor.currentTable()) {-
1394 QTextTable *table = cursor.currentTable();-
1395-
1396 r = d->doc->documentLayout()->frameBoundingRect(table);-
1397 } else if (cursor.hasSelection()) {-
1398 const int position = cursor.selectionStart();-
1399 const int anchor = cursor.selectionEnd();-
1400 const QTextBlock posBlock = d->doc->findBlock(position);-
1401 const QTextBlock anchorBlock = d->doc->findBlock(anchor);-
1402 if (posBlock == anchorBlock && posBlock.isValid() && posBlock.layout()->lineCount()) {-
1403 const QTextLine posLine = posBlock.layout()->lineForTextPosition(position - posBlock.position());-
1404 const QTextLine anchorLine = anchorBlock.layout()->lineForTextPosition(anchor - anchorBlock.position());-
1405-
1406 const int firstLine = qMin(posLine.lineNumber(), anchorLine.lineNumber());-
1407 const int lastLine = qMax(posLine.lineNumber(), anchorLine.lineNumber());-
1408 const QTextLayout *layout = posBlock.layout();-
1409 r = QRectF();-
1410 for (int i = firstLine; i <= lastLine; ++i) {-
1411 r |= layout->lineAt(i).rect();-
1412 r |= layout->lineAt(i).naturalTextRect();-
1413 }-
1414 r.translate(blockBoundingRect(posBlock).topLeft());-
1415 } else {-
1416 QRectF anchorRect = d->rectForPosition(cursor.selectionEnd());-
1417 r |= anchorRect;-
1418 r |= boundingRectOfFloatsInSelection(cursor);-
1419 QRectF frameRect(d->doc->documentLayout()->frameBoundingRect(cursor.currentFrame()));-
1420 r.setLeft(frameRect.left());-
1421 r.setRight(frameRect.right());-
1422 }-
1423 if (r.isValid())-
1424 r.adjust(-1, -1, 1, 1);-
1425 }-
1426-
1427 return r;-
1428}-
1429-
1430QRectF QWidgetTextControl::selectionRect() const-
1431{-
1432 const QWidgetTextControlPrivate * const d = d_func();-
1433 return selectionRect(d->cursor);-
1434}-
1435-
1436void QWidgetTextControlPrivate::mousePressEvent(QEvent *e, Qt::MouseButton button, const QPointF &pos, Qt::KeyboardModifiers modifiers,-
1437 Qt::MouseButtons buttons, const QPoint &globalPos)-
1438{-
1439 QWidgetTextControl * const q = q_func();-
1440-
1441 mousePressPos = pos.toPoint();-
1442-
1443-
1444 mightStartDrag = false;-
1445-
1446-
1447 if (sendMouseEventToInputContext(-
1448 e, QEvent::MouseButtonPress, button, pos, modifiers, buttons, globalPos)) {-
1449 return;-
1450 }-
1451-
1452 if (interactionFlags & Qt::LinksAccessibleByMouse) {-
1453 anchorOnMousePress = q->anchorAt(pos);-
1454-
1455 if (cursorIsFocusIndicator) {-
1456 cursorIsFocusIndicator = false;-
1457 repaintSelection();-
1458 cursor.clearSelection();-
1459 }-
1460 }-
1461 if (!(button & Qt::LeftButton) ||-
1462 !((interactionFlags & Qt::TextSelectableByMouse) || (interactionFlags & Qt::TextEditable))) {-
1463 e->ignore();-
1464 return;-
1465 }-
1466-
1467 cursorIsFocusIndicator = false;-
1468 const QTextCursor oldSelection = cursor;-
1469 const int oldCursorPos = cursor.position();-
1470-
1471 mousePressed = (interactionFlags & Qt::TextSelectableByMouse);-
1472-
1473 commitPreedit();-
1474-
1475 if (trippleClickTimer.isActive()-
1476 && ((pos - trippleClickPoint).toPoint().manhattanLength() < QApplication::startDragDistance())) {-
1477-
1478 cursor.movePosition(QTextCursor::StartOfBlock);-
1479 cursor.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor);-
1480 cursor.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor);-
1481 selectedBlockOnTrippleClick = cursor;-
1482-
1483 anchorOnMousePress = QString();-
1484-
1485 trippleClickTimer.stop();-
1486 } else {-
1487 int cursorPos = q->hitTest(pos, Qt::FuzzyHit);-
1488 if (cursorPos == -1) {-
1489 e->ignore();-
1490 return;-
1491 }-
1492-
1493 if (modifiers == Qt::ShiftModifier && (interactionFlags & Qt::TextSelectableByMouse)) {-
1494 if (wordSelectionEnabled && !selectedWordOnDoubleClick.hasSelection()) {-
1495 selectedWordOnDoubleClick = cursor;-
1496 selectedWordOnDoubleClick.select(QTextCursor::WordUnderCursor);-
1497 }-
1498-
1499 if (selectedBlockOnTrippleClick.hasSelection())-
1500 extendBlockwiseSelection(cursorPos);-
1501 else if (selectedWordOnDoubleClick.hasSelection())-
1502 extendWordwiseSelection(cursorPos, pos.x());-
1503 else if (!wordSelectionEnabled)-
1504 setCursorPosition(cursorPos, QTextCursor::KeepAnchor);-
1505 } else {-
1506-
1507 if (dragEnabled-
1508 && cursor.hasSelection()-
1509 && !cursorIsFocusIndicator-
1510 && cursorPos >= cursor.selectionStart()-
1511 && cursorPos <= cursor.selectionEnd()-
1512 && q->hitTest(pos, Qt::ExactHit) != -1) {-
1513-
1514 mightStartDrag = true;-
1515-
1516 return;-
1517 }-
1518-
1519 setCursorPosition(cursorPos);-
1520 }-
1521 }-
1522-
1523 if (interactionFlags & Qt::TextEditable) {-
1524 q->ensureCursorVisible();-
1525 if (cursor.position() != oldCursorPos)-
1526 q->cursorPositionChanged();-
1527 _q_updateCurrentCharFormatAndSelection();-
1528 } else {-
1529 if (cursor.position() != oldCursorPos) {-
1530 q->cursorPositionChanged();-
1531 q->microFocusChanged();-
1532 }-
1533 selectionChanged();-
1534 }-
1535 repaintOldAndNewSelection(oldSelection);-
1536 hadSelectionOnMousePress = cursor.hasSelection();-
1537}-
1538-
1539void QWidgetTextControlPrivate::mouseMoveEvent(QEvent *e, Qt::MouseButton button, const QPointF &mousePos, Qt::KeyboardModifiers modifiers,-
1540 Qt::MouseButtons buttons, const QPoint &globalPos)-
1541{-
1542 QWidgetTextControl * const q = q_func();-
1543-
1544 if (interactionFlags & Qt::LinksAccessibleByMouse) {-
1545 QString anchor = q->anchorAt(mousePos);-
1546 if (anchor != highlightedAnchor) {-
1547 highlightedAnchor = anchor;-
1548 q->linkHovered(anchor);-
1549 }-
1550 }-
1551-
1552 if (buttons & Qt::LeftButton) {-
1553 const bool editable = interactionFlags & Qt::TextEditable;-
1554-
1555 if (!(mousePressed-
1556 || editable-
1557 || mightStartDrag-
1558 || selectedWordOnDoubleClick.hasSelection()-
1559 || selectedBlockOnTrippleClick.hasSelection()))-
1560 return;-
1561-
1562 const QTextCursor oldSelection = cursor;-
1563 const int oldCursorPos = cursor.position();-
1564-
1565 if (mightStartDrag) {-
1566 if ((mousePos.toPoint() - mousePressPos).manhattanLength() > QApplication::startDragDistance())-
1567 startDrag();-
1568 return;-
1569 }-
1570-
1571 const qreal mouseX = qreal(mousePos.x());-
1572-
1573 int newCursorPos = q->hitTest(mousePos, Qt::FuzzyHit);-
1574-
1575 if (isPreediting()) {-
1576-
1577 int selectionStartPos = q->hitTest(mousePressPos, Qt::FuzzyHit);-
1578-
1579 if (newCursorPos != selectionStartPos) {-
1580 commitPreedit();-
1581-
1582 newCursorPos = q->hitTest(mousePos, Qt::FuzzyHit);-
1583 selectionStartPos = q->hitTest(mousePressPos, Qt::FuzzyHit);-
1584 setCursorPosition(selectionStartPos);-
1585 }-
1586 }-
1587-
1588 if (newCursorPos == -1)-
1589 return;-
1590-
1591 if (mousePressed && wordSelectionEnabled && !selectedWordOnDoubleClick.hasSelection()) {-
1592 selectedWordOnDoubleClick = cursor;-
1593 selectedWordOnDoubleClick.select(QTextCursor::WordUnderCursor);-
1594 }-
1595-
1596 if (selectedBlockOnTrippleClick.hasSelection())-
1597 extendBlockwiseSelection(newCursorPos);-
1598 else if (selectedWordOnDoubleClick.hasSelection())-
1599 extendWordwiseSelection(newCursorPos, mouseX);-
1600 else if (mousePressed && !isPreediting())-
1601 setCursorPosition(newCursorPos, QTextCursor::KeepAnchor);-
1602-
1603 if (interactionFlags & Qt::TextEditable) {-
1604-
1605-
1606-
1607 if (cursor.position() != oldCursorPos)-
1608 q->cursorPositionChanged();-
1609 _q_updateCurrentCharFormatAndSelection();-
1610-
1611 if (contextWidget)-
1612 QGuiApplication::inputMethod()->update(Qt::ImQueryInput);-
1613-
1614 } else {-
1615-
1616 if (cursor.position() != oldCursorPos) {-
1617 q->cursorPositionChanged();-
1618 q->microFocusChanged();-
1619 }-
1620 }-
1621 selectionChanged(true);-
1622 repaintOldAndNewSelection(oldSelection);-
1623 }-
1624-
1625 sendMouseEventToInputContext(e, QEvent::MouseMove, button, mousePos, modifiers, buttons, globalPos);-
1626}-
1627-
1628void QWidgetTextControlPrivate::mouseReleaseEvent(QEvent *e, Qt::MouseButton button, const QPointF &pos, Qt::KeyboardModifiers modifiers,-
1629 Qt::MouseButtons buttons, const QPoint &globalPos)-
1630{-
1631 QWidgetTextControl * const q = q_func();-
1632-
1633 const QTextCursor oldSelection = cursor;-
1634 if (sendMouseEventToInputContext(-
1635 e, QEvent::MouseButtonRelease, button, pos, modifiers, buttons, globalPos)) {-
1636 repaintOldAndNewSelection(oldSelection);-
1637 return;-
1638 }-
1639-
1640 const int oldCursorPos = cursor.position();-
1641-
1642-
1643 if (mightStartDrag && (button & Qt::LeftButton)) {-
1644 mousePressed = false;-
1645 setCursorPosition(pos);-
1646 cursor.clearSelection();-
1647 selectionChanged();-
1648 }-
1649-
1650 if (mousePressed) {-
1651 mousePressed = false;-
1652-
1653 setClipboardSelection();-
1654 selectionChanged(true);-
1655 } else if (button == Qt::MidButton-
1656 && (interactionFlags & Qt::TextEditable)-
1657 && QApplication::clipboard()->supportsSelection()) {-
1658 setCursorPosition(pos);-
1659 const QMimeData *md = QApplication::clipboard()->mimeData(QClipboard::Selection);-
1660 if (md)-
1661 q->insertFromMimeData(md);-
1662-
1663 }-
1664-
1665 repaintOldAndNewSelection(oldSelection);-
1666-
1667 if (cursor.position() != oldCursorPos) {-
1668 q->cursorPositionChanged();-
1669 q->microFocusChanged();-
1670 }-
1671-
1672 if (interactionFlags & Qt::LinksAccessibleByMouse) {-
1673 if (!(button & Qt::LeftButton))-
1674 return;-
1675-
1676 const QString anchor = q->anchorAt(pos);-
1677-
1678 if (anchor.isEmpty())-
1679 return;-
1680-
1681 if (!cursor.hasSelection()-
1682 || (anchor == anchorOnMousePress && hadSelectionOnMousePress)) {-
1683-
1684 const int anchorPos = q->hitTest(pos, Qt::ExactHit);-
1685 if (anchorPos != -1) {-
1686 cursor.setPosition(anchorPos);-
1687-
1688 QString anchor = anchorOnMousePress;-
1689 anchorOnMousePress = QString();-
1690 activateLinkUnderCursor(anchor);-
1691 }-
1692 }-
1693 }-
1694}-
1695-
1696void QWidgetTextControlPrivate::mouseDoubleClickEvent(QEvent *e, Qt::MouseButton button, const QPointF &pos,-
1697 Qt::KeyboardModifiers modifiers, Qt::MouseButtons buttons,-
1698 const QPoint &globalPos)-
1699{-
1700 QWidgetTextControl * const q = q_func();-
1701-
1702 if (button == Qt::LeftButton-
1703 && (interactionFlags & Qt::TextSelectableByMouse)) {-
1704-
1705-
1706 mightStartDrag = false;-
1707-
1708 commitPreedit();-
1709-
1710 const QTextCursor oldSelection = cursor;-
1711 setCursorPosition(pos);-
1712 QTextLine line = currentTextLine(cursor);-
1713 bool doEmit = false;-
1714 if (line.isValid() && line.textLength()) {-
1715 cursor.select(QTextCursor::WordUnderCursor);-
1716 doEmit = true;-
1717 }-
1718 repaintOldAndNewSelection(oldSelection);-
1719-
1720 cursorIsFocusIndicator = false;-
1721 selectedWordOnDoubleClick = cursor;-
1722-
1723 trippleClickPoint = pos;-
1724 trippleClickTimer.start(QApplication::doubleClickInterval(), q);-
1725 if (doEmit) {-
1726 selectionChanged();-
1727-
1728 setClipboardSelection();-
1729-
1730 q->cursorPositionChanged();-
1731 }-
1732 } else if (!sendMouseEventToInputContext(e, QEvent::MouseButtonDblClick, button, pos,-
1733 modifiers, buttons, globalPos)) {-
1734 e->ignore();-
1735 }-
1736}-
1737-
1738bool QWidgetTextControlPrivate::sendMouseEventToInputContext(-
1739 QEvent *e, QEvent::Type eventType, Qt::MouseButton button, const QPointF &pos,-
1740 Qt::KeyboardModifiers modifiers, Qt::MouseButtons buttons, const QPoint &globalPos)-
1741{-
1742 (void)eventType;;-
1743 (void)button;;-
1744 (void)pos;;-
1745 (void)modifiers;;-
1746 (void)buttons;;-
1747 (void)globalPos;;-
1748-
1749 QWidgetTextControl * const q = q_func();-
1750-
1751 if (isPreediting()) {-
1752 QTextLayout *layout = cursor.block().layout();-
1753 int cursorPos = q->hitTest(pos, Qt::FuzzyHit) - cursor.position();-
1754-
1755 if (cursorPos < 0 || cursorPos > layout->preeditAreaText().length())-
1756 cursorPos = -1;-
1757-
1758 if (cursorPos >= 0) {-
1759 if (eventType == QEvent::MouseButtonRelease)-
1760 QGuiApplication::inputMethod()->invokeAction(QInputMethod::Click, cursorPos);-
1761-
1762 e->setAccepted(true);-
1763 return true;-
1764 }-
1765 }-
1766-
1767-
1768-
1769 return false;-
1770}-
1771-
1772void QWidgetTextControlPrivate::contextMenuEvent(const QPoint &screenPos, const QPointF &docPos, QWidget *contextWidget)-
1773{-
1774-
1775-
1776-
1777-
1778-
1779 QWidgetTextControl * const q = q_func();-
1780 if (!hasFocus)-
1781 return;-
1782 QMenu *menu = q->createStandardContextMenu(docPos, contextWidget);-
1783 if (!menu)-
1784 return;-
1785 menu->setAttribute(Qt::WA_DeleteOnClose);-
1786 menu->popup(screenPos);-
1787-
1788}-
1789-
1790bool QWidgetTextControlPrivate::dragEnterEvent(QEvent *e, const QMimeData *mimeData)-
1791{-
1792 QWidgetTextControl * const q = q_func();-
1793 if (!(interactionFlags & Qt::TextEditable) || !q->canInsertFromMimeData(mimeData)) {-
1794 e->ignore();-
1795 return false;-
1796 }-
1797-
1798 dndFeedbackCursor = QTextCursor();-
1799-
1800 return true;-
1801}-
1802-
1803void QWidgetTextControlPrivate::dragLeaveEvent()-
1804{-
1805 QWidgetTextControl * const q = q_func();-
1806-
1807 const QRectF crect = q->cursorRect(dndFeedbackCursor);-
1808 dndFeedbackCursor = QTextCursor();-
1809-
1810 if (crect.isValid())-
1811 q->updateRequest(crect);-
1812}-
1813-
1814bool QWidgetTextControlPrivate::dragMoveEvent(QEvent *e, const QMimeData *mimeData, const QPointF &pos)-
1815{-
1816 QWidgetTextControl * const q = q_func();-
1817 if (!(interactionFlags & Qt::TextEditable) || !q->canInsertFromMimeData(mimeData)) {-
1818 e->ignore();-
1819 return false;-
1820 }-
1821-
1822 const int cursorPos = q->hitTest(pos, Qt::FuzzyHit);-
1823 if (cursorPos != -1) {-
1824 QRectF crect = q->cursorRect(dndFeedbackCursor);-
1825 if (crect.isValid())-
1826 q->updateRequest(crect);-
1827-
1828 dndFeedbackCursor = cursor;-
1829 dndFeedbackCursor.setPosition(cursorPos);-
1830-
1831 crect = q->cursorRect(dndFeedbackCursor);-
1832 q->updateRequest(crect);-
1833 }-
1834-
1835 return true;-
1836}-
1837-
1838bool QWidgetTextControlPrivate::dropEvent(const QMimeData *mimeData, const QPointF &pos, Qt::DropAction dropAction, QObject *source)-
1839{-
1840 QWidgetTextControl * const q = q_func();-
1841 dndFeedbackCursor = QTextCursor();-
1842-
1843 if (!(interactionFlags & Qt::TextEditable) || !q->canInsertFromMimeData(mimeData))-
1844 return false;-
1845-
1846 repaintSelection();-
1847-
1848 QTextCursor insertionCursor = q->cursorForPosition(pos);-
1849 insertionCursor.beginEditBlock();-
1850-
1851 if (dropAction == Qt::MoveAction && source == contextWidget)-
1852 cursor.removeSelectedText();-
1853-
1854 cursor = insertionCursor;-
1855 q->insertFromMimeData(mimeData);-
1856 insertionCursor.endEditBlock();-
1857 q->ensureCursorVisible();-
1858 return true;-
1859}-
1860-
1861void QWidgetTextControlPrivate::inputMethodEvent(QInputMethodEvent *e)-
1862{-
1863 QWidgetTextControl * const q = q_func();-
1864 if (!(interactionFlags & Qt::TextEditable) || cursor.isNull()) {-
1865 e->ignore();-
1866 return;-
1867 }-
1868 bool isGettingInput = !e->commitString().isEmpty()-
1869 || e->preeditString() != cursor.block().layout()->preeditAreaText()-
1870 || e->replacementLength() > 0;-
1871-
1872 cursor.beginEditBlock();-
1873 if (isGettingInput) {-
1874 cursor.removeSelectedText();-
1875 }-
1876-
1877-
1878 if (!e->commitString().isEmpty() || e->replacementLength()) {-
1879 QTextCursor c = cursor;-
1880 c.setPosition(c.position() + e->replacementStart());-
1881 c.setPosition(c.position() + e->replacementLength(), QTextCursor::KeepAnchor);-
1882 c.insertText(e->commitString());-
1883 }-
1884-
1885 for (int i = 0; i < e->attributes().size(); ++i) {-
1886 const QInputMethodEvent::Attribute &a = e->attributes().at(i);-
1887 if (a.type == QInputMethodEvent::Selection) {-
1888 QTextCursor oldCursor = cursor;-
1889 int blockStart = a.start + cursor.block().position();-
1890 cursor.setPosition(blockStart, QTextCursor::MoveAnchor);-
1891 cursor.setPosition(blockStart + a.length, QTextCursor::KeepAnchor);-
1892 q->ensureCursorVisible();-
1893 repaintOldAndNewSelection(oldCursor);-
1894 }-
1895 }-
1896-
1897 QTextBlock block = cursor.block();-
1898 QTextLayout *layout = block.layout();-
1899 if (isGettingInput)-
1900 layout->setPreeditArea(cursor.position() - block.position(), e->preeditString());-
1901 QVector<QTextLayout::FormatRange> overrides;-
1902 overrides.reserve(e->attributes().size());-
1903 const int oldPreeditCursor = preeditCursor;-
1904 preeditCursor = e->preeditString().length();-
1905 hideCursor = false;-
1906 for (int i = 0; i < e->attributes().size(); ++i) {-
1907 const QInputMethodEvent::Attribute &a = e->attributes().at(i);-
1908 if (a.type == QInputMethodEvent::Cursor) {-
1909 preeditCursor = a.start;-
1910 hideCursor = !a.length;-
1911 } else if (a.type == QInputMethodEvent::TextFormat) {-
1912 QTextCharFormat f = qvariant_cast<QTextFormat>(a.value).toCharFormat();-
1913 if (f.isValid()) {-
1914 QTextLayout::FormatRange o;-
1915 o.start = a.start + cursor.position() - block.position();-
1916 o.length = a.length;-
1917 o.format = f;-
1918 overrides.append(o);-
1919 }-
1920 }-
1921 }-
1922 layout->setFormats(overrides);-
1923-
1924 cursor.endEditBlock();-
1925-
1926 if (cursor.d)-
1927 cursor.d->setX();-
1928 if (oldPreeditCursor != preeditCursor)-
1929 q->microFocusChanged();-
1930}-
1931-
1932QVariant QWidgetTextControl::inputMethodQuery(Qt::InputMethodQuery property, QVariant argument) const-
1933{-
1934 const QWidgetTextControlPrivate * const d = d_func();-
1935 QTextBlock block = d->cursor.block();-
1936 switch(property) {-
1937 case
never executed: case Qt::ImCursorRectangle:
Qt::ImCursorRectangle:
never executed: case Qt::ImCursorRectangle:
0
1938 return
never executed: return cursorRect();
cursorRect();
never executed: return cursorRect();
0
1939 case
never executed: case Qt::ImAnchorRectangle:
never executed: case Qt::ImAnchorRectangle:
Qt::ImAnchorRectangle:
never executed: case Qt::ImAnchorRectangle:
0
1940 return
never executed: return d->rectForPosition(d->cursor.anchor());
d->rectForPosition(d->cursor.anchor());
never executed: return d->rectForPosition(d->cursor.anchor());
0
1941 case
never executed: case Qt::ImFont:
Qt::ImFont:
never executed: case Qt::ImFont:
0
1942 return
never executed: return QVariant(d->cursor.charFormat().font());
QVariant(d->cursor.charFormat().font());
never executed: return QVariant(d->cursor.charFormat().font());
0
1943 case
never executed: case Qt::ImCursorPosition:
Qt::ImCursorPosition:
never executed: case Qt::ImCursorPosition:
{
0
1944 const QPointF pt = argument.toPointF();-
1945 if (!pt.isNull()
!pt.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
1946 return
never executed: return QVariant(cursorForPosition(pt).position() - block.position());
QVariant(cursorForPosition(pt).position() - block.position());
never executed: return QVariant(cursorForPosition(pt).position() - block.position());
0
1947 return
never executed: return QVariant(d->cursor.position() - block.position());
QVariant(d->cursor.position() - block.position());
never executed: return QVariant(d->cursor.position() - block.position());
}
0
1948 case
never executed: case Qt::ImSurroundingText:
Qt::ImSurroundingText:
never executed: case Qt::ImSurroundingText:
0
1949 return
never executed: return QVariant(block.text());
QVariant(block.text());
never executed: return QVariant(block.text());
0
1950 case
never executed: case Qt::ImCurrentSelection:
Qt::ImCurrentSelection:
never executed: case Qt::ImCurrentSelection:
0
1951 return
never executed: return QVariant(d->cursor.selectedText());
QVariant(d->cursor.selectedText());
never executed: return QVariant(d->cursor.selectedText());
0
1952 case
never executed: case Qt::ImMaximumTextLength:
Qt::ImMaximumTextLength:
never executed: case Qt::ImMaximumTextLength:
0
1953 return
never executed: return QVariant();
QVariant();
never executed: return QVariant();
0
1954 case
never executed: case Qt::ImAnchorPosition:
Qt::ImAnchorPosition:
never executed: case Qt::ImAnchorPosition:
0
1955 return
never executed: return QVariant(d->cursor.anchor() - block.position());
QVariant(d->cursor.anchor() - block.position());
never executed: return QVariant(d->cursor.anchor() - block.position());
0
1956 case
never executed: case Qt::ImAbsolutePosition:
Qt::ImAbsolutePosition:
never executed: case Qt::ImAbsolutePosition:
{
0
1957 const QPointF pt = argument.toPointF();-
1958 if (!pt.isNull()
!pt.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
1959 return
never executed: return QVariant(cursorForPosition(pt).position());
QVariant(cursorForPosition(pt).position());
never executed: return QVariant(cursorForPosition(pt).position());
0
1960 return
never executed: return QVariant(d->cursor.position());
QVariant(d->cursor.position());
never executed: return QVariant(d->cursor.position());
}
0
1961 case
never executed: case Qt::ImTextAfterCursor:
Qt::ImTextAfterCursor:
never executed: case Qt::ImTextAfterCursor:
0
1962 {-
1963 int maxLength = argument.isValid()
argument.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
? argument.toInt() : 1024;
0
1964 QTextCursor tmpCursor = d->cursor;-
1965 int localPos = d->cursor.position() - block.position();-
1966 QString result = block.text().mid(localPos);-
1967 while (result.length() < maxLength
result.length() < maxLengthDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
1968 int currentBlock = tmpCursor.blockNumber();-
1969 tmpCursor.movePosition(QTextCursor::NextBlock);-
1970 if (tmpCursor.blockNumber() == currentBlock
tmpCursor.bloc...= currentBlockDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
1971 break;
never executed: break;
0
1972 result += QLatin1Char('\n') + tmpCursor.block().text();-
1973 }
never executed: end of block
0
1974 return
never executed: return QVariant(result);
QVariant(result);
never executed: return QVariant(result);
0
1975 }-
1976 case
never executed: case Qt::ImTextBeforeCursor:
Qt::ImTextBeforeCursor:
never executed: case Qt::ImTextBeforeCursor:
0
1977 {-
1978 int maxLength = argument.isValid()
argument.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
? argument.toInt() : 1024;
0
1979 QTextCursor tmpCursor = d->cursor;-
1980 int localPos = d->cursor.position() - block.position();-
1981 int numBlocks = 0;-
1982 int resultLen = localPos;-
1983 while (resultLen < maxLength
resultLen < maxLengthDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
1984 int currentBlock = tmpCursor.blockNumber();-
1985 tmpCursor.movePosition(QTextCursor::PreviousBlock);-
1986 if (tmpCursor.blockNumber() == currentBlock
tmpCursor.bloc...= currentBlockDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
1987 break;
never executed: break;
0
1988 numBlocks++;-
1989 resultLen += tmpCursor.block().length();-
1990 }
never executed: end of block
0
1991 QString result;-
1992 while (numBlocks
numBlocksDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
1993 result += tmpCursor.block().text() + QLatin1Char('\n');-
1994 tmpCursor.movePosition(QTextCursor::NextBlock);-
1995 --numBlocks;-
1996 }
never executed: end of block
0
1997 result += block.text().midmidRef(0, localPos);-
1998 return
never executed: return QVariant(result);
QVariant(result);
never executed: return QVariant(result);
0
1999 }-
2000 default
never executed: default:
:
never executed: default:
0
2001 return
never executed: return QVariant();
QVariant();
never executed: return QVariant();
0
2002 }-
2003}-
2004-
2005void QWidgetTextControl::setFocus(bool focus, Qt::FocusReason reason)-
2006{-
2007 QFocusEvent ev(focus ? QEvent::FocusIn : QEvent::FocusOut,-
2008 reason);-
2009 processEvent(&ev);-
2010}-
2011-
2012void QWidgetTextControlPrivate::focusEvent(QFocusEvent *e)-
2013{-
2014 QWidgetTextControl * const q = q_func();-
2015 q->updateRequest(q->selectionRect());-
2016 if (e->gotFocus()
e->gotFocus()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
2017-
2018-
2019-
2020 cursorOn = (interactionFlags & (Qt::TextSelectableByKeyboard | Qt::TextEditable));-
2021 if (interactionFlags & Qt::TextEditable
interactionFla...::TextEditableDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
2022 setBlinkingCursorEnabledsetCursorVisible(true);-
2023 }
never executed: end of block
0
2024-
2025-
2026-
2027 }
never executed: end of block
else {
0
2028 setBlinkingCursorEnabledsetCursorVisible(false);-
2029-
2030 if (cursorIsFocusIndicator
cursorIsFocusIndicatorDescription
TRUEnever evaluated
FALSEnever evaluated
0
2031 && e->reason() != Qt::ActiveWindowFocusReason
e->reason() !=...dowFocusReasonDescription
TRUEnever evaluated
FALSEnever evaluated
0
2032 && e->reason() != Qt::PopupFocusReason
e->reason() !=...pupFocusReasonDescription
TRUEnever evaluated
FALSEnever evaluated
0
2033 && cursor.hasSelection()
cursor.hasSelection()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
2034 cursor.clearSelection();-
2035 }
never executed: end of block
0
2036 }
never executed: end of block
0
2037 hasFocus = e->gotFocus();-
2038}
never executed: end of block
0
2039-
2040QString QWidgetTextControlPrivate::anchorForCursor(const QTextCursor &anchorCursor) const-
2041{-
2042 if (anchorCursor.hasSelection()) {-
2043 QTextCursor cursor = anchorCursor;-
2044 if (cursor.selectionStart() != cursor.position())-
2045 cursor.setPosition(cursor.selectionStart());-
2046 cursor.movePosition(QTextCursor::NextCharacter);-
2047 QTextCharFormat fmt = cursor.charFormat();-
2048 if (fmt.isAnchor() && fmt.hasProperty(QTextFormat::AnchorHref))-
2049 return fmt.stringProperty(QTextFormat::AnchorHref);-
2050 }-
2051 return QString();-
2052}-
2053static inline void setActionIcon(QAction *action, const QString &name)-
2054{-
2055 const QIcon icon = QIcon::fromTheme(name);-
2056 if (!icon.isNull())-
2057 action->setIcon(icon);-
2058}-
2059-
2060QMenu *QWidgetTextControl::createStandardContextMenu(const QPointF &pos, QWidget *parent)-
2061{-
2062 QWidgetTextControlPrivate * const d = d_func();-
2063-
2064 const bool showTextSelectionActions = d->interactionFlags & (Qt::TextEditable | Qt::TextSelectableByKeyboard | Qt::TextSelectableByMouse);-
2065-
2066 d->linkToCopy = QString();-
2067 if (!pos.isNull())-
2068 d->linkToCopy = anchorAt(pos);-
2069-
2070 if (d->linkToCopy.isEmpty() && !showTextSelectionActions)-
2071 return 0;-
2072-
2073 QMenu *menu = new QMenu(parent);-
2074 QAction *a;-
2075-
2076 if (d->interactionFlags & Qt::TextEditable) {-
2077 a = menu->addAction(tr("&Undo") + (!(static_cast<QApplication *>(QCoreApplication::instance()))->d_func()->shortcutMap.hasShortcutForKeySequence(QKeySequence::Undo) ? QLatin1Char('\t') + QKeySequence(QKeySequence::Undo).toString(QKeySequence::NativeText) : QString()), this, qFlagLocation("1""undo()" "\0" __FILE__ ":" "2223""2257"));-
2078 a->setEnabled(d->doc->isUndoAvailable());-
2079 a->setObjectName(([]() -> QString { enum { Size = sizeof(u"" "edit-undo")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "edit-undo" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }()));-
2080 setActionIcon(a, ([]() -> QString { enum { Size = sizeof(u"" "edit-undo")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "edit-undo" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }()));-
2081 a = menu->addAction(tr("&Redo") + (!(static_cast<QApplication *>(QCoreApplication::instance()))->d_func()->shortcutMap.hasShortcutForKeySequence(QKeySequence::Redo) ? QLatin1Char('\t') + QKeySequence(QKeySequence::Redo).toString(QKeySequence::NativeText) : QString()), this, qFlagLocation("1""redo()" "\0" __FILE__ ":" "2227""2261"));-
2082 a->setEnabled(d->doc->isRedoAvailable());-
2083 a->setObjectName(([]() -> QString { enum { Size = sizeof(u"" "edit-redo")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "edit-redo" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }()));-
2084 setActionIcon(a, ([]() -> QString { enum { Size = sizeof(u"" "edit-redo")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "edit-redo" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }()));-
2085 menu->addSeparator();-
2086-
2087-
2088 a = menu->addAction(tr("Cu&t") + (!(static_cast<QApplication *>(QCoreApplication::instance()))->d_func()->shortcutMap.hasShortcutForKeySequence(QKeySequence::Cut) ? QLatin1Char('\t') + QKeySequence(QKeySequence::Cut).toString(QKeySequence::NativeText) : QString()), this, qFlagLocation("1""cut()" "\0" __FILE__ ":" "2234""2268"));-
2089 a->setEnabled(d->cursor.hasSelection());-
2090 a->setObjectName(([]() -> QString { enum { Size = sizeof(u"" "edit-cut")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "edit-cut" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }()));-
2091 setActionIcon(a, ([]() -> QString { enum { Size = sizeof(u"" "edit-cut")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "edit-cut" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }()));-
2092-
2093 }-
2094-
2095-
2096 if (showTextSelectionActions) {-
2097 a = menu->addAction(tr("&Copy") + (!(static_cast<QApplication *>(QCoreApplication::instance()))->d_func()->shortcutMap.hasShortcutForKeySequence(QKeySequence::Copy) ? QLatin1Char('\t') + QKeySequence(QKeySequence::Copy).toString(QKeySequence::NativeText) : QString()), this, qFlagLocation("1""copy()" "\0" __FILE__ ":" "2243""2277"));-
2098 a->setEnabled(d->cursor.hasSelection());-
2099 a->setObjectName(([]() -> QString { enum { Size = sizeof(u"" "edit-copy")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "edit-copy" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }()));-
2100 setActionIcon(a, ([]() -> QString { enum { Size = sizeof(u"" "edit-copy")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "edit-copy" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }()));-
2101 }-
2102-
2103 if ((d->interactionFlags & Qt::LinksAccessibleByKeyboard)-
2104 || (d->interactionFlags & Qt::LinksAccessibleByMouse)) {-
2105-
2106 a = menu->addAction(tr("Copy &Link Location"), this, qFlagLocation("1""_q_copyLink()" "\0" __FILE__ ":" "2252""2286"));-
2107 a->setEnabled(!d->linkToCopy.isEmpty());-
2108 a->setObjectName(([]() -> QString { enum { Size = sizeof(u"" "link-copy")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "link-copy" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }()));-
2109 }-
2110-
2111-
2112 if (d->interactionFlags & Qt::TextEditable) {-
2113-
2114 a = menu->addAction(tr("&Paste") + (!(static_cast<QApplication *>(QCoreApplication::instance()))->d_func()->shortcutMap.hasShortcutForKeySequence(QKeySequence::Paste) ? QLatin1Char('\t') + QKeySequence(QKeySequence::Paste).toString(QKeySequence::NativeText) : QString()), this, qFlagLocation("1""paste()" "\0" __FILE__ ":" "2260""2294"));-
2115 a->setEnabled(canPaste());-
2116 a->setObjectName(([]() -> QString { enum { Size = sizeof(u"" "edit-paste")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "edit-paste" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }()));-
2117 setActionIcon(a, ([]() -> QString { enum { Size = sizeof(u"" "edit-paste")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "edit-paste" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }()));-
2118-
2119 a = menu->addAction(tr("Delete"), this, qFlagLocation("1""_q_deleteSelected()" "\0" __FILE__ ":" "2265""2299"));-
2120 a->setEnabled(d->cursor.hasSelection());-
2121 a->setObjectName(([]() -> QString { enum { Size = sizeof(u"" "edit-delete")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "edit-delete" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }()));-
2122 setActionIcon(a, ([]() -> QString { enum { Size = sizeof(u"" "edit-delete")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "edit-delete" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }()));-
2123 }-
2124-
2125-
2126 if (showTextSelectionActions) {-
2127 menu->addSeparator();-
2128 a = menu->addAction(tr("Select All") + (!(static_cast<QApplication *>(QCoreApplication::instance()))->d_func()->shortcutMap.hasShortcutForKeySequence(QKeySequence::SelectAll) ? QLatin1Char('\t') + QKeySequence(QKeySequence::SelectAll).toString(QKeySequence::NativeText) : QString()), this, qFlagLocation("1""selectAll()" "\0" __FILE__ ":" "2274""2308"));-
2129 a->setEnabled(!d->doc->isEmpty());-
2130 a->setObjectName(([]() -> QString { enum { Size = sizeof(u"" "select-all")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "select-all" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }()));-
2131 }-
2132-
2133 if ((d->interactionFlags & Qt::TextEditable) && QGuiApplication::styleHints()->useRtlExtensions()) {-
2134 menu->addSeparator();-
2135 QUnicodeControlCharacterMenu *ctrlCharacterMenu = new QUnicodeControlCharacterMenu(this, menu);-
2136 menu->addMenu(ctrlCharacterMenu);-
2137 }-
2138-
2139 return menu;-
2140}-
2141-
2142-
2143QTextCursor QWidgetTextControl::cursorForPosition(const QPointF &pos) const-
2144{-
2145 const QWidgetTextControlPrivate * const d = d_func();-
2146 int cursorPos = hitTest(pos, Qt::FuzzyHit);-
2147 if (cursorPos == -1)-
2148 cursorPos = 0;-
2149 QTextCursor c(d->doc);-
2150 c.setPosition(cursorPos);-
2151 return c;-
2152}-
2153-
2154QRectF QWidgetTextControl::cursorRect(const QTextCursor &cursor) const-
2155{-
2156 const QWidgetTextControlPrivate * const d = d_func();-
2157 if (cursor.isNull())-
2158 return QRectF();-
2159-
2160 return d->rectForPosition(cursor.position());-
2161}-
2162-
2163QRectF QWidgetTextControl::cursorRect() const-
2164{-
2165 const QWidgetTextControlPrivate * const d = d_func();-
2166 return cursorRect(d->cursor);-
2167}-
2168-
2169QRectF QWidgetTextControlPrivate::cursorRectPlusUnicodeDirectionMarkers(const QTextCursor &cursor) const-
2170{-
2171 if (cursor.isNull())-
2172 return QRectF();-
2173-
2174 return rectForPosition(cursor.position()).adjusted(-4, 0, 4, 0);-
2175}-
2176-
2177QString QWidgetTextControl::anchorAt(const QPointF &pos) const-
2178{-
2179 const QWidgetTextControlPrivate * const d = d_func();-
2180 return d->doc->documentLayout()->anchorAt(pos);-
2181}-
2182-
2183QString QWidgetTextControl::anchorAtCursor() const-
2184{-
2185 const QWidgetTextControlPrivate * const d = d_func();-
2186-
2187 return d->anchorForCursor(d->cursor);-
2188}-
2189-
2190bool QWidgetTextControl::overwriteMode() const-
2191{-
2192 const QWidgetTextControlPrivate * const d = d_func();-
2193 return d->overwriteMode;-
2194}-
2195-
2196void QWidgetTextControl::setOverwriteMode(bool overwrite)-
2197{-
2198 QWidgetTextControlPrivate * const d = d_func();-
2199 d->overwriteMode = overwrite;-
2200}-
2201-
2202int QWidgetTextControl::cursorWidth() const-
2203{-
2204-
2205 const QWidgetTextControlPrivate * const d = d_func();-
2206 return d->doc->documentLayout()->property("cursorWidth").toInt();-
2207-
2208-
2209-
2210}-
2211-
2212void QWidgetTextControl::setCursorWidth(int width)-
2213{-
2214 QWidgetTextControlPrivate * const d = d_func();-
2215-
2216-
2217-
2218 if (width == -1)-
2219 width = QApplication::style()->pixelMetric(QStyle::PM_TextCursorWidth);-
2220 d->doc->documentLayout()->setProperty("cursorWidth", width);-
2221-
2222 d->repaintCursor();-
2223}-
2224-
2225bool QWidgetTextControl::acceptRichText() const-
2226{-
2227 const QWidgetTextControlPrivate * const d = d_func();-
2228 return d->acceptRichText;-
2229}-
2230-
2231void QWidgetTextControl::setAcceptRichText(bool accept)-
2232{-
2233 QWidgetTextControlPrivate * const d = d_func();-
2234 d->acceptRichText = accept;-
2235}-
2236-
2237-
2238-
2239void QWidgetTextControl::setExtraSelections(const QList<QTextEdit::ExtraSelection> &selections)-
2240{-
2241 QWidgetTextControlPrivate * const d = d_func();-
2242-
2243 QHash<int, int> hash;-
2244 for (int i = 0; i < d->extraSelections.count()
i < d->extraSelections.count()Description
TRUEnever evaluated
FALSEnever evaluated
; ++i) {
0
2245 const QAbstractTextDocumentLayout::Selection &esel = d->extraSelections.at(i);-
2246 hash.insertMulti(esel.cursor.anchor(), i);-
2247 }
never executed: end of block
0
2248-
2249 for (int i = 0; i < selections.count()
i < selections.count()Description
TRUEnever evaluated
FALSEnever evaluated
; ++i) {
0
2250 const QTextEdit::ExtraSelection &sel = selections.at(i);-
2251 QHash<int, int>::iteratorconst auto it = hash.findconstFind(sel.cursor.anchor());-
2252 if (it != hash.endcend()
it != hash.cend()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
2253 const QAbstractTextDocumentLayout::Selection &esel = d->extraSelections.at(it.value());-
2254 if (esel.cursor.position() == sel.cursor.position()
esel.cursor.po...sor.position()Description
TRUEnever evaluated
FALSEnever evaluated
0
2255 && esel.format == sel.format
esel.format == sel.formatDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
2256 hash.erase(it);-
2257 continue;
never executed: continue;
0
2258 }-
2259 }
never executed: end of block
0
2260 QRectF r = selectionRect(sel.cursor);-
2261 if (sel.format.boolProperty(QTextFormat::FullWidthSelection)
sel.format.boo...idthSelection)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
2262 r.setLeft(0);-
2263 r.setWidth(qreal(2147483647));-
2264 }
never executed: end of block
0
2265 updateRequest(r);-
2266 }
never executed: end of block
0
2267-
2268 for (QHash<int, int>::iterator it = hash.begin(); it != hash.end()
it != hash.end()Description
TRUEnever evaluated
FALSEnever evaluated
; ++it) {
0
2269 const QAbstractTextDocumentLayout::Selection &esel = d->extraSelections.at(it.value());-
2270 QRectF r = selectionRect(esel.cursor);-
2271 if (esel.format.boolProperty(QTextFormat::FullWidthSelection)
esel.format.bo...idthSelection)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
2272 r.setLeft(0);-
2273 r.setWidth(qreal(2147483647));-
2274 }
never executed: end of block
0
2275 updateRequest(r);-
2276 }
never executed: end of block
0
2277-
2278 d->extraSelections.resize(selections.count());-
2279 for (int i = 0; i < selections.count()
i < selections.count()Description
TRUEnever evaluated
FALSEnever evaluated
; ++i) {
0
2280 d->extraSelections[i].cursor = selections.at(i).cursor;-
2281 d->extraSelections[i].format = selections.at(i).format;-
2282 }
never executed: end of block
0
2283}
never executed: end of block
0
2284-
2285QList<QTextEdit::ExtraSelection> QWidgetTextControl::extraSelections() const-
2286{-
2287 const QWidgetTextControlPrivate * const d = d_func();-
2288 QList<QTextEdit::ExtraSelection> selections;-
2289 const int numExtraSelections = d->extraSelections.count();-
2290 selections.reserve(numExtraSelections);-
2291 for (int i = 0; i < numExtraSelections; ++i) {-
2292 QTextEdit::ExtraSelection sel;-
2293 const QAbstractTextDocumentLayout::Selection &sel2 = d->extraSelections.at(i);-
2294 sel.cursor = sel2.cursor;-
2295 sel.format = sel2.format;-
2296 selections.append(sel);-
2297 }-
2298 return selections;-
2299}-
2300-
2301-
2302-
2303void QWidgetTextControl::setTextWidth(qreal width)-
2304{-
2305 QWidgetTextControlPrivate * const d = d_func();-
2306 d->doc->setTextWidth(width);-
2307}-
2308-
2309qreal QWidgetTextControl::textWidth() const-
2310{-
2311 const QWidgetTextControlPrivate * const d = d_func();-
2312 return d->doc->textWidth();-
2313}-
2314-
2315QSizeF QWidgetTextControl::size() const-
2316{-
2317 const QWidgetTextControlPrivate * const d = d_func();-
2318 return d->doc->size();-
2319}-
2320-
2321void QWidgetTextControl::setOpenExternalLinks(bool open)-
2322{-
2323 QWidgetTextControlPrivate * const d = d_func();-
2324 d->openExternalLinks = open;-
2325}-
2326-
2327bool QWidgetTextControl::openExternalLinks() const-
2328{-
2329 const QWidgetTextControlPrivate * const d = d_func();-
2330 return d->openExternalLinks;-
2331}-
2332-
2333bool QWidgetTextControl::ignoreUnusedNavigationEvents() const-
2334{-
2335 const QWidgetTextControlPrivate * const d = d_func();-
2336 return d->ignoreUnusedNavigationEvents;-
2337}-
2338-
2339void QWidgetTextControl::setIgnoreUnusedNavigationEvents(bool ignore)-
2340{-
2341 QWidgetTextControlPrivate * const d = d_func();-
2342 d->ignoreUnusedNavigationEvents = ignore;-
2343}-
2344-
2345void QWidgetTextControl::moveCursor(QTextCursor::MoveOperation op, QTextCursor::MoveMode mode)-
2346{-
2347 QWidgetTextControlPrivate * const d = d_func();-
2348 const QTextCursor oldSelection = d->cursor;-
2349 const bool moved = d->cursor.movePosition(op, mode);-
2350 d->_q_updateCurrentCharFormatAndSelection();-
2351 ensureCursorVisible();-
2352 d->repaintOldAndNewSelection(oldSelection);-
2353 if (moved)-
2354 cursorPositionChanged();-
2355}-
2356-
2357bool QWidgetTextControl::canPaste() const-
2358{-
2359-
2360 const QWidgetTextControlPrivate * const d = d_func();-
2361 if (d->interactionFlags & Qt::TextEditable) {-
2362 const QMimeData *md = QApplication::clipboard()->mimeData();-
2363 return md && canInsertFromMimeData(md);-
2364 }-
2365-
2366 return false;-
2367}-
2368-
2369void QWidgetTextControl::setCursorIsFocusIndicator(bool b)-
2370{-
2371 QWidgetTextControlPrivate * const d = d_func();-
2372 d->cursorIsFocusIndicator = b;-
2373 d->repaintCursor();-
2374}-
2375-
2376bool QWidgetTextControl::cursorIsFocusIndicator() const-
2377{-
2378 const QWidgetTextControlPrivate * const d = d_func();-
2379 return d->cursorIsFocusIndicator;-
2380}-
2381-
2382-
2383void QWidgetTextControl::setDragEnabled(bool enabled)-
2384{-
2385 QWidgetTextControlPrivate * const d = d_func();-
2386 d->dragEnabled = enabled;-
2387}-
2388-
2389bool QWidgetTextControl::isDragEnabled() const-
2390{-
2391 const QWidgetTextControlPrivate * const d = d_func();-
2392 return d->dragEnabled;-
2393}-
2394-
2395void QWidgetTextControl::setWordSelectionEnabled(bool enabled)-
2396{-
2397 QWidgetTextControlPrivate * const d = d_func();-
2398 d->wordSelectionEnabled = enabled;-
2399}-
2400-
2401bool QWidgetTextControl::isWordSelectionEnabled() const-
2402{-
2403 const QWidgetTextControlPrivate * const d = d_func();-
2404 return d->wordSelectionEnabled;-
2405}-
2406-
2407bool QWidgetTextControl::isPreediting()-
2408{-
2409 return d_func()->isPreediting();-
2410}-
2411-
2412-
2413void QWidgetTextControl::print(QPagedPaintDevice *printer) const-
2414{-
2415 const QWidgetTextControlPrivate * const d = d_func();-
2416 if (!printer)-
2417 return;-
2418 QTextDocument *tempDoc = 0;-
2419 const QTextDocument *doc = d->doc;-
2420 if (QPagedPaintDevicePrivate::get(printer)->printSelectionOnly) {-
2421 if (!d->cursor.hasSelection())-
2422 return;-
2423 tempDoc = new QTextDocument(const_cast<QTextDocument *>(doc));-
2424 tempDoc->setMetaInformation(QTextDocument::DocumentTitle, doc->metaInformation(QTextDocument::DocumentTitle));-
2425 tempDoc->setPageSize(doc->pageSize());-
2426 tempDoc->setDefaultFont(doc->defaultFont());-
2427 tempDoc->setUseDesignMetrics(doc->useDesignMetrics());-
2428 QTextCursor(tempDoc).insertFragment(d->cursor.selection());-
2429 doc = tempDoc;-
2430-
2431-
2432 doc->documentLayout()->d_func()->handlers = d->doc->documentLayout()->d_func()->handlers;-
2433 }-
2434 doc->print(printer);-
2435 delete tempDoc;-
2436}-
2437-
2438-
2439QMimeData *QWidgetTextControl::createMimeDataFromSelection() const-
2440{-
2441 const QWidgetTextControlPrivate * const d = d_func();-
2442 const QTextDocumentFragment fragment(d->cursor);-
2443 return new QTextEditMimeData(fragment);-
2444}-
2445-
2446bool QWidgetTextControl::canInsertFromMimeData(const QMimeData *source) const-
2447{-
2448 const QWidgetTextControlPrivate * const d = d_func();-
2449 if (d->acceptRichText)-
2450 return (source->hasText() && !source->text().isEmpty())-
2451 || source->hasHtml()-
2452 || source->hasFormat(QLatin1String("application/x-qrichtext"))-
2453 || source->hasFormat(QLatin1String("application/x-qt-richtext"));-
2454 else-
2455 return source->hasText() && !source->text().isEmpty();-
2456}-
2457-
2458void QWidgetTextControl::insertFromMimeData(const QMimeData *source)-
2459{-
2460 QWidgetTextControlPrivate * const d = d_func();-
2461 if (!(d->interactionFlags & Qt::TextEditable)
!(d->interacti...:TextEditable)Description
TRUEnever evaluated
FALSEnever evaluated
|| !source
!sourceDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
2462 return;
never executed: return;
0
2463-
2464 bool hasData = false;-
2465 QTextDocumentFragment fragment;-
2466-
2467 if (source->hasFormat(QLatin1String("application/x-qrichtext"))
source->hasFor...x-qrichtext"))Description
TRUEnever evaluated
FALSEnever evaluated
&& d->acceptRichText
d->acceptRichTextDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
2468-
2469 const QString richtext = QString::fromUtf8(source->data(QLatin1String("application/x-qrichtext")));-
richtext.prepend(QLatin1String("<meta name=\"qrichtext\" content=\"1\" />"));)
2470 + QString::fromUtf8(source->data(QLatin1String("application/x-qrichtext")));-
2471 fragment = QTextDocumentFragment::fromHtml(richtext, d->doc);-
2472 hasData = true;-
2473 }
never executed: end of block
else if (source->hasHtml()
source->hasHtml()Description
TRUEnever evaluated
FALSEnever evaluated
&& d->acceptRichText
d->acceptRichTextDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
2474 fragment = QTextDocumentFragment::fromHtml(source->html(), d->doc);-
2475 hasData = true;-
2476 }
never executed: end of block
else {
0
2477 QString text = source->text();-
2478 if (!text.isNull()
!text.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
2479 fragment = QTextDocumentFragment::fromPlainText(text);-
2480 hasData = true;-
2481 }
never executed: end of block
0
2482 }
never executed: end of block
0
2483-
2484-
2485-
2486-
2487 if (hasData
hasDataDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
2488 d->cursor.insertFragment(fragment);
never executed: d->cursor.insertFragment(fragment);
0
2489 ensureCursorVisible();-
2490}
never executed: end of block
0
2491-
2492bool QWidgetTextControl::findNextPrevAnchor(const QTextCursor &startCursor, bool next, QTextCursor &newAnchor)-
2493{-
2494 QWidgetTextControlPrivate * const d = d_func();-
2495-
2496 int anchorStart = -1;-
2497 QString anchorHref;-
2498 int anchorEnd = -1;-
2499-
2500 if (next) {-
2501 const int startPos = startCursor.selectionEnd();-
2502-
2503 QTextBlock block = d->doc->findBlock(startPos);-
2504 QTextBlock::Iterator it = block.begin();-
2505-
2506 while (!it.atEnd() && it.fragment().position() < startPos)-
2507 ++it;-
2508-
2509 while (block.isValid()) {-
2510 anchorStart = -1;-
2511-
2512-
2513 for (; !it.atEnd(); ++it) {-
2514 const QTextFragment fragment = it.fragment();-
2515 const QTextCharFormat fmt = fragment.charFormat();-
2516-
2517 if (fmt.isAnchor() && fmt.hasProperty(QTextFormat::AnchorHref)) {-
2518 anchorStart = fragment.position();-
2519 anchorHref = fmt.anchorHref();-
2520 break;-
2521 }-
2522 }-
2523-
2524 if (anchorStart != -1) {-
2525 anchorEnd = -1;-
2526-
2527-
2528 for (; !it.atEnd(); ++it) {-
2529 const QTextFragment fragment = it.fragment();-
2530 const QTextCharFormat fmt = fragment.charFormat();-
2531-
2532 if (!fmt.isAnchor() || fmt.anchorHref() != anchorHref) {-
2533 anchorEnd = fragment.position();-
2534 break;-
2535 }-
2536 }-
2537-
2538 if (anchorEnd == -1)-
2539 anchorEnd = block.position() + block.length() - 1;-
2540-
2541-
2542 break;-
2543 }-
2544-
2545 block = block.next();-
2546 it = block.begin();-
2547 }-
2548 } else {-
2549 int startPos = startCursor.selectionStart();-
2550 if (startPos > 0)-
2551 --startPos;-
2552-
2553 QTextBlock block = d->doc->findBlock(startPos);-
2554 QTextBlock::Iterator blockStart = block.begin();-
2555 QTextBlock::Iterator it = block.end();-
2556-
2557 if (startPos == block.position()) {-
2558 it = block.begin();-
2559 } else {-
2560 do {-
2561 if (it == blockStart) {-
2562 it = QTextBlock::Iterator();-
2563 block = QTextBlock();-
2564 } else {-
2565 --it;-
2566 }-
2567 } while (!it.atEnd() && it.fragment().position() + it.fragment().length() - 1 > startPos);-
2568 }-
2569-
2570 while (block.isValid()) {-
2571 anchorStart = -1;-
2572-
2573 if (!it.atEnd()) {-
2574 do {-
2575 const QTextFragment fragment = it.fragment();-
2576 const QTextCharFormat fmt = fragment.charFormat();-
2577-
2578 if (fmt.isAnchor() && fmt.hasProperty(QTextFormat::AnchorHref)) {-
2579 anchorStart = fragment.position() + fragment.length();-
2580 anchorHref = fmt.anchorHref();-
2581 break;-
2582 }-
2583-
2584 if (it == blockStart)-
2585 it = QTextBlock::Iterator();-
2586 else-
2587 --it;-
2588 } while (!it.atEnd());-
2589 }-
2590-
2591 if (anchorStart != -1 && !it.atEnd()) {-
2592 anchorEnd = -1;-
2593-
2594 do {-
2595 const QTextFragment fragment = it.fragment();-
2596 const QTextCharFormat fmt = fragment.charFormat();-
2597-
2598 if (!fmt.isAnchor() || fmt.anchorHref() != anchorHref) {-
2599 anchorEnd = fragment.position() + fragment.length();-
2600 break;-
2601 }-
2602-
2603 if (it == blockStart)-
2604 it = QTextBlock::Iterator();-
2605 else-
2606 --it;-
2607 } while (!it.atEnd());-
2608-
2609 if (anchorEnd == -1)-
2610 anchorEnd = qMax(0, block.position());-
2611-
2612 break;-
2613 }-
2614-
2615 block = block.previous();-
2616 it = block.end();-
2617 if (it != block.begin())-
2618 --it;-
2619 blockStart = block.begin();-
2620 }-
2621-
2622 }-
2623-
2624 if (anchorStart != -1 && anchorEnd != -1) {-
2625 newAnchor = d->cursor;-
2626 newAnchor.setPosition(anchorStart);-
2627 newAnchor.setPosition(anchorEnd, QTextCursor::KeepAnchor);-
2628 return true;-
2629 }-
2630-
2631 return false;-
2632}-
2633-
2634void QWidgetTextControlPrivate::activateLinkUnderCursor(QString href)-
2635{-
2636 QTextCursor oldCursor = cursor;-
2637-
2638 if (href.isEmpty()) {-
2639 QTextCursor tmp = cursor;-
2640 if (tmp.selectionStart() != tmp.position())-
2641 tmp.setPosition(tmp.selectionStart());-
2642 tmp.movePosition(QTextCursor::NextCharacter);-
2643 href = tmp.charFormat().anchorHref();-
2644 }-
2645 if (href.isEmpty())-
2646 return;-
2647-
2648 if (!cursor.hasSelection()) {-
2649 QTextBlock block = cursor.block();-
2650 const int cursorPos = cursor.position();-
2651-
2652 QTextBlock::Iterator it = block.begin();-
2653 QTextBlock::Iterator linkFragment;-
2654-
2655 for (; !it.atEnd(); ++it) {-
2656 QTextFragment fragment = it.fragment();-
2657 const int fragmentPos = fragment.position();-
2658 if (fragmentPos <= cursorPos &&-
2659 fragmentPos + fragment.length() > cursorPos) {-
2660 linkFragment = it;-
2661 break;-
2662 }-
2663 }-
2664-
2665 if (!linkFragment.atEnd()) {-
2666 it = linkFragment;-
2667 cursor.setPosition(it.fragment().position());-
2668 if (it != block.begin()) {-
2669 do {-
2670 --it;-
2671 QTextFragment fragment = it.fragment();-
2672 if (fragment.charFormat().anchorHref() != href)-
2673 break;-
2674 cursor.setPosition(fragment.position());-
2675 } while (it != block.begin());-
2676 }-
2677-
2678 for (it = linkFragment; !it.atEnd(); ++it) {-
2679 QTextFragment fragment = it.fragment();-
2680 if (fragment.charFormat().anchorHref() != href)-
2681 break;-
2682 cursor.setPosition(fragment.position() + fragment.length(), QTextCursor::KeepAnchor);-
2683 }-
2684 }-
2685 }-
2686-
2687 if (hasFocus) {-
2688 cursorIsFocusIndicator = true;-
2689 } else {-
2690 cursorIsFocusIndicator = false;-
2691 cursor.clearSelection();-
2692 }-
2693 repaintOldAndNewSelection(oldCursor);-
2694-
2695-
2696 if (openExternalLinks)-
2697 QDesktopServices::openUrl(href);-
2698 else-
2699-
2700 q_func()->linkActivated(href);-
2701}-
2702-
2703-
2704void QWidgetTextControlPrivate::showToolTip(const QPoint &globalPos, const QPointF &pos, QWidget *contextWidget)-
2705{-
2706 const QString toolTip = q_func()->cursorForPosition(pos).charFormat().toolTip();-
2707 if (toolTip.isEmpty())-
2708 return;-
2709 QToolTip::showText(globalPos, toolTip, contextWidget);-
2710}-
2711-
2712-
2713bool QWidgetTextControlPrivate::isPreediting() const-
2714{-
2715 QTextLayout *layout = cursor.block().layout();-
2716 if (layout && !layout->preeditAreaText().isEmpty())-
2717 return true;-
2718-
2719 return false;-
2720}-
2721-
2722void QWidgetTextControlPrivate::commitPreedit()-
2723{-
2724 if (!isPreediting())-
2725 return;-
2726-
2727 QGuiApplication::inputMethod()->commit();-
2728-
2729 if (!isPreediting())-
2730 return;-
2731-
2732 cursor.beginEditBlock();-
2733 preeditCursor = 0;-
2734 QTextBlock block = cursor.block();-
2735 QTextLayout *layout = block.layout();-
2736 layout->setPreeditArea(-1, QString());-
2737 layout->clearFormats();-
2738 cursor.endEditBlock();-
2739}-
2740-
2741bool QWidgetTextControl::setFocusToNextOrPreviousAnchor(bool next)-
2742{-
2743 QWidgetTextControlPrivate * const d = d_func();-
2744-
2745 if (!(d->interactionFlags & Qt::LinksAccessibleByKeyboard))-
2746 return false;-
2747-
2748 QRectF crect = selectionRect();-
2749 updateRequest(crect);-
2750-
2751-
2752 if (!d->cursor.hasSelection()) {-
2753 d->cursor = QTextCursor(d->doc);-
2754 if (next)-
2755 d->cursor.movePosition(QTextCursor::Start);-
2756 else-
2757 d->cursor.movePosition(QTextCursor::End);-
2758 }-
2759-
2760 QTextCursor newAnchor;-
2761 if (findNextPrevAnchor(d->cursor, next, newAnchor)) {-
2762 d->cursor = newAnchor;-
2763 d->cursorIsFocusIndicator = true;-
2764 } else {-
2765 d->cursor.clearSelection();-
2766 }-
2767-
2768 if (d->cursor.hasSelection()) {-
2769 crect = selectionRect();-
2770 updateRequest(crect);-
2771 visibilityRequest(crect);-
2772 return true;-
2773 } else {-
2774 return false;-
2775 }-
2776}-
2777-
2778bool QWidgetTextControl::setFocusToAnchor(const QTextCursor &newCursor)-
2779{-
2780 QWidgetTextControlPrivate * const d = d_func();-
2781-
2782 if (!(d->interactionFlags & Qt::LinksAccessibleByKeyboard))-
2783 return false;-
2784-
2785-
2786 const QString anchorHref = d->anchorForCursor(newCursor);-
2787 if (anchorHref.isEmpty())-
2788 return false;-
2789-
2790-
2791 QRectF crect = selectionRect();-
2792 updateRequest(crect);-
2793-
2794 d->cursor.setPosition(newCursor.selectionStart());-
2795 d->cursor.setPosition(newCursor.selectionEnd(), QTextCursor::KeepAnchor);-
2796 d->cursorIsFocusIndicator = true;-
2797-
2798 crect = selectionRect();-
2799 updateRequest(crect);-
2800 visibilityRequest(crect);-
2801 return true;-
2802}-
2803-
2804void QWidgetTextControl::setTextInteractionFlags(Qt::TextInteractionFlags flags)-
2805{-
2806 QWidgetTextControlPrivate * const d = d_func();-
2807 if (flags == d->interactionFlags
flags == d->interactionFlagsDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
2808 return;
never executed: return;
0
2809 d->interactionFlags = flags;-
2810-
2811 if (d->hasFocus
d->hasFocusDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
2812 d->setBlinkingCursorEnabledsetCursorVisible(flags & Qt::TextEditable);
never executed: d->setCursorVisible(flags & Qt::TextEditable);
0
2813}
never executed: end of block
0
2814-
2815Qt::TextInteractionFlags QWidgetTextControl::textInteractionFlags() const-
2816{-
2817 const QWidgetTextControlPrivate * const d = d_func();-
2818 return d->interactionFlags;-
2819}-
2820-
2821void QWidgetTextControl::mergeCurrentCharFormat(const QTextCharFormat &modifier)-
2822{-
2823 QWidgetTextControlPrivate * const d = d_func();-
2824 d->cursor.mergeCharFormat(modifier);-
2825 d->updateCurrentCharFormat();-
2826}-
2827-
2828void QWidgetTextControl::setCurrentCharFormat(const QTextCharFormat &format)-
2829{-
2830 QWidgetTextControlPrivate * const d = d_func();-
2831 d->cursor.setCharFormat(format);-
2832 d->updateCurrentCharFormat();-
2833}-
2834-
2835QTextCharFormat QWidgetTextControl::currentCharFormat() const-
2836{-
2837 const QWidgetTextControlPrivate * const d = d_func();-
2838 return d->cursor.charFormat();-
2839}-
2840-
2841void QWidgetTextControl::insertPlainText(const QString &text)-
2842{-
2843 QWidgetTextControlPrivate * const d = d_func();-
2844 d->cursor.insertText(text);-
2845}-
2846-
2847-
2848void QWidgetTextControl::insertHtml(const QString &text)-
2849{-
2850 QWidgetTextControlPrivate * const d = d_func();-
2851 d->cursor.insertHtml(text);-
2852}-
2853-
2854-
2855QPointF QWidgetTextControl::anchorPosition(const QString &name) const-
2856{-
2857 const QWidgetTextControlPrivate * const d = d_func();-
2858 if (name.isEmpty())-
2859 return QPointF();-
2860-
2861 QRectF r;-
2862 for (QTextBlock block = d->doc->begin(); block.isValid(); block = block.next()) {-
2863 QTextCharFormat format = block.charFormat();-
2864 if (format.isAnchor() && format.anchorNames().contains(name)) {-
2865 r = d->rectForPosition(block.position());-
2866 break;-
2867 }-
2868-
2869 for (QTextBlock::Iterator it = block.begin(); !it.atEnd(); ++it) {-
2870 QTextFragment fragment = it.fragment();-
2871 format = fragment.charFormat();-
2872 if (format.isAnchor() && format.anchorNames().contains(name)) {-
2873 r = d->rectForPosition(fragment.position());-
2874 block = QTextBlock();-
2875 break;-
2876 }-
2877 }-
2878 }-
2879 if (!r.isValid())-
2880 return QPointF();-
2881 return QPointF(0, r.top());-
2882}-
2883-
2884void QWidgetTextControl::adjustSize()-
2885{-
2886 QWidgetTextControlPrivate * const d = d_func();-
2887 d->doc->adjustSize();-
2888}-
2889-
2890bool QWidgetTextControl::find(const QString &exp, QTextDocument::FindFlags options)-
2891{-
2892 QWidgetTextControlPrivate * const d = d_func();-
2893 QTextCursor search = d->doc->find(exp, d->cursor, options);-
2894 if (search.isNull())-
2895 return false;-
2896-
2897 setTextCursor(search);-
2898 return true;-
2899}-
2900-
2901-
2902bool QWidgetTextControl::find(const QRegExp &exp, QTextDocument::FindFlags options)-
2903{-
2904 QWidgetTextControlPrivate * const d = d_func();-
2905 QTextCursor search = d->doc->find(exp, d->cursor, options);-
2906 if (search.isNull())-
2907 return false;-
2908-
2909 setTextCursor(search);-
2910 return true;-
2911}-
2912-
2913-
2914QString QWidgetTextControl::toPlainText() const-
2915{-
2916 return document()->toPlainText();-
2917}-
2918-
2919-
2920QString QWidgetTextControl::toHtml() const-
2921{-
2922 return document()->toHtml();-
2923}-
2924-
2925-
2926void QWidgetTextControlPrivate::append(const QString &text, Qt::TextFormat format)-
2927{-
2928 QTextCursor tmp(doc);-
2929 tmp.beginEditBlock();-
2930 tmp.movePosition(QTextCursor::End);-
2931-
2932 if (!doc->isEmpty())-
2933 tmp.insertBlock(cursor.blockFormat(), cursor.charFormat());-
2934 else-
2935 tmp.setCharFormat(cursor.charFormat());-
2936-
2937-
2938 QTextCharFormat oldCharFormat = cursor.charFormat();-
2939-
2940-
2941 if (format == Qt::RichText || (format == Qt::AutoText && Qt::mightBeRichText(text))) {-
2942 tmp.insertHtml(text);-
2943 } else {-
2944 tmp.insertText(text);-
2945 }-
2946-
2947-
2948-
2949 if (!cursor.hasSelection())-
2950 cursor.setCharFormat(oldCharFormat);-
2951-
2952 tmp.endEditBlock();-
2953}-
2954-
2955void QWidgetTextControl::append(const QString &text)-
2956{-
2957 QWidgetTextControlPrivate * const d = d_func();-
2958 d->append(text, Qt::AutoText);-
2959}-
2960-
2961void QWidgetTextControl::appendHtml(const QString &html)-
2962{-
2963 QWidgetTextControlPrivate * const d = d_func();-
2964 d->append(html, Qt::RichText);-
2965}-
2966-
2967void QWidgetTextControl::appendPlainText(const QString &text)-
2968{-
2969 QWidgetTextControlPrivate * const d = d_func();-
2970 d->append(text, Qt::PlainText);-
2971}-
2972-
2973-
2974void QWidgetTextControl::ensureCursorVisible()-
2975{-
2976 QWidgetTextControlPrivate * const d = d_func();-
2977 QRectF crect = d->rectForPosition(d->cursor.position()).adjusted(-5, 0, 5, 0);-
2978 visibilityRequest(crect);-
2979 microFocusChanged();-
2980}-
2981-
2982QPalette QWidgetTextControl::palette() const-
2983{-
2984 const QWidgetTextControlPrivate * const d = d_func();-
2985 return d->palette;-
2986}-
2987-
2988void QWidgetTextControl::setPalette(const QPalette &pal)-
2989{-
2990 QWidgetTextControlPrivate * const d = d_func();-
2991 d->palette = pal;-
2992}-
2993-
2994QAbstractTextDocumentLayout::PaintContext QWidgetTextControl::getPaintContext(QWidget *widget) const-
2995{-
2996 const QWidgetTextControlPrivate * const d = d_func();-
2997-
2998 QAbstractTextDocumentLayout::PaintContext ctx;-
2999-
3000 ctx.selections = d->extraSelections;-
3001 ctx.palette = d->palette;-
3002 if (d->cursorOn && d->isEnabled) {-
3003 if (d->hideCursor)-
3004 ctx.cursorPosition = -1;-
3005 else if (d->preeditCursor != 0)-
3006 ctx.cursorPosition = - (d->preeditCursor + 2);-
3007 else-
3008 ctx.cursorPosition = d->cursor.position();-
3009 }-
3010-
3011 if (!d->dndFeedbackCursor.isNull())-
3012 ctx.cursorPosition = d->dndFeedbackCursor.position();-
3013-
3014-
3015-
3016 if (d->cursor.hasSelection()) {-
3017 QAbstractTextDocumentLayout::Selection selection;-
3018 selection.cursor = d->cursor;-
3019 if (d->cursorIsFocusIndicator) {-
3020 QStyleOption opt;-
3021 opt.palette = ctx.palette;-
3022 QStyleHintReturnVariant ret;-
3023 QStyle *style = QApplication::style();-
3024 if (widget)-
3025 style = widget->style();-
3026 style->styleHint(QStyle::SH_TextControl_FocusIndicatorTextCharFormat, &opt, widget, &ret);-
3027 selection.format = qvariant_cast<QTextFormat>(ret.variant).toCharFormat();-
3028 } else {-
3029 QPalette::ColorGroup cg = d->hasFocus ? QPalette::Active : QPalette::Inactive;-
3030 selection.format.setBackground(ctx.palette.brush(cg, QPalette::Highlight));-
3031 selection.format.setForeground(ctx.palette.brush(cg, QPalette::HighlightedText));-
3032 QStyleOption opt;-
3033 QStyle *style = QApplication::style();-
3034 if (widget) {-
3035 opt.initFrom(widget);-
3036 style = widget->style();-
3037 }-
3038 if (style->styleHint(QStyle::SH_RichText_FullWidthSelection, &opt, widget))-
3039 selection.format.setProperty(QTextFormat::FullWidthSelection, true);-
3040 }-
3041 ctx.selections.append(selection);-
3042 }-
3043-
3044 return ctx;-
3045}-
3046-
3047void QWidgetTextControl::drawContents(QPainter *p, const QRectF &rect, QWidget *widget)-
3048{-
3049 QWidgetTextControlPrivate * const d = d_func();-
3050 p->save();-
3051 QAbstractTextDocumentLayout::PaintContext ctx = getPaintContext(widget);-
3052 if (rect.isValid())-
3053 p->setClipRect(rect, Qt::IntersectClip);-
3054 ctx.clip = rect;-
3055-
3056 d->doc->documentLayout()->draw(p, ctx);-
3057 p->restore();-
3058}-
3059-
3060void QWidgetTextControlPrivate::_q_copyLink()-
3061{-
3062-
3063 QMimeData *md = new QMimeData;-
3064 md->setText(linkToCopy);-
3065 QApplication::clipboard()->setMimeData(md);-
3066-
3067}-
3068-
3069int QWidgetTextControl::hitTest(const QPointF &point, Qt::HitTestAccuracy accuracy) const-
3070{-
3071 const QWidgetTextControlPrivate * const d = d_func();-
3072 return d->doc->documentLayout()->hitTest(point, accuracy);-
3073}-
3074-
3075QRectF QWidgetTextControl::blockBoundingRect(const QTextBlock &block) const-
3076{-
3077 const QWidgetTextControlPrivate * const d = d_func();-
3078 return d->doc->documentLayout()->blockBoundingRect(block);-
3079}-
3080-
3081-
3082-
3083const struct QUnicodeControlCharacter {-
3084 const char *text;-
3085 ushort character;-
3086} qt_controlCharacters[14] = {-
3087 { "LRM Left-to-right mark", 0x200e },-
3088 { "RLM Right-to-left mark", 0x200f },-
3089 { "ZWJ Zero width joiner", 0x200d },-
3090 { "ZWNJ Zero width non-joiner", 0x200c },-
3091 { "ZWSP Zero width space", 0x200b },-
3092 { "LRE Start of left-to-right embedding", 0x202a },-
3093 { "RLE Start of right-to-left embedding", 0x202b },-
3094 { "LRO Start of left-to-right override", 0x202d },-
3095 { "RLO Start of right-to-left override", 0x202e },-
3096 { "PDF Pop directional formatting", 0x202c },-
3097 { "LRI Left-to-right isolate", 0x2066 },-
3098 { "RLI Right-to-left isolate", 0x2067 },-
3099 { "FSI First strong isolate", 0x2068 },-
3100 { "PDI Pop directional isolate", 0x2069 }-
3101};-
3102-
3103QUnicodeControlCharacterMenu::QUnicodeControlCharacterMenu(QObject *_editWidget, QWidget *parent)-
3104 : QMenu(parent), editWidget(_editWidget)-
3105{-
3106 setTitle(tr("Insert Unicode control character"));-
3107 for (int i = 0; i < 14; ++i) {-
3108 addAction(tr(qt_controlCharacters[i].text), this, qFlagLocation("1""menuActionTriggered()" "\0" __FILE__ ":" "3254""3288"));-
3109 }-
3110}-
3111-
3112void QUnicodeControlCharacterMenu::menuActionTriggered()-
3113{-
3114 QAction *a = qobject_cast<QAction *>(sender());-
3115 int idx = actions().indexOf(a);-
3116 if (idx < 0 || idx >= 14)-
3117 return;-
3118 QChar c(qt_controlCharacters[idx].character);-
3119 QString str(c);-
3120-
3121-
3122 if (QTextEdit *edit = qobject_cast<QTextEdit *>(editWidget)) {-
3123 edit->insertPlainText(str);-
3124 return;-
3125 }-
3126-
3127 if (QWidgetTextControl *control = qobject_cast<QWidgetTextControl *>(editWidget)) {-
3128 control->insertPlainText(str);-
3129 }-
3130-
3131 if (QLineEdit *edit = qobject_cast<QLineEdit *>(editWidget)) {-
3132 edit->insert(str);-
3133 return;-
3134 }-
3135-
3136}-
3137-
3138-
3139QStringList QTextEditMimeData::formats() const-
3140{-
3141 if (!fragment.isEmpty())-
3142 return QStringList() << QString::fromLatin1("text/plain") << QString::fromLatin1("text/html")-
3143-
3144 << QString::fromLatin1("application/vnd.oasis.opendocument.text")-
3145-
3146 ;-
3147 else-
3148 return QMimeData::formats();-
3149}-
3150-
3151QVariant QTextEditMimeData::retrieveData(const QString &mimeType, QVariant::Type type) const-
3152{-
3153 if (!fragment.isEmpty())-
3154 setup();-
3155 return QMimeData::retrieveData(mimeType, type);-
3156}-
3157-
3158void QTextEditMimeData::setup() const-
3159{-
3160 QTextEditMimeData *that = const_cast<QTextEditMimeData *>(this);-
3161-
3162 that->setData(QLatin1String("text/html"), fragment.toHtml("utf-8").toUtf8());-
3163-
3164-
3165 {-
3166 QBuffer buffer;-
3167 QTextDocumentWriter writer(&buffer, "ODF");-
3168 writer.write(fragment);-
3169 buffer.close();-
3170 that->setData(QLatin1String("application/vnd.oasis.opendocument.text"), buffer.data());-
3171 }-
3172-
3173 that->setText(fragment.toPlainText());-
3174 fragment = QTextDocumentFragment();-
3175}-
3176-
3177-
3178-
Switch to Source codePreprocessed file

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