Qt 4.8
qtextcontrol.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include "qtextcontrol_p.h"
43 #include "qtextcontrol_p_p.h"
44 
45 #ifndef QT_NO_TEXTCONTROL
46 
47 #include <qfont.h>
48 #include <qpainter.h>
49 #include <qevent.h>
50 #include <qdebug.h>
51 #include <qmime.h>
52 #include <qdrag.h>
53 #include <qconfig.h>
54 #include <qclipboard.h>
55 #include <qmenu.h>
56 #include <qstyle.h>
57 #include <qtimer.h>
58 #include "private/qtextdocumentlayout_p.h"
59 #include "private/qabstracttextdocumentlayout_p.h"
60 #include "private/qtextedit_p.h"
61 #include "qtextdocument.h"
62 #include "private/qtextdocument_p.h"
63 #include "qtextlist.h"
64 #include "private/qtextcontrol_p.h"
65 #include "qgraphicssceneevent.h"
66 #include "qprinter.h"
67 #include "qtextdocumentwriter.h"
68 #include "private/qtextcursor_p.h"
69 
70 #include <qtextformat.h>
71 #include <qdatetime.h>
72 #include <qbuffer.h>
73 #include <qapplication.h>
74 #include <limits.h>
75 #include <qtexttable.h>
76 #include <qvariant.h>
77 #include <qurl.h>
78 #include <qdesktopservices.h>
79 #include <qinputcontext.h>
80 #include <qtooltip.h>
81 #include <qstyleoption.h>
82 #include <QtGui/qlineedit.h>
83 #include <QtGui/qaccessible.h>
84 
85 #ifndef QT_NO_SHORTCUT
86 #include "private/qapplication_p.h"
87 #include "private/qshortcutmap_p.h"
88 #include <qkeysequence.h>
89 #define ACCEL_KEY(k) (!qApp->d_func()->shortcutMap.hasShortcutForKeySequence(k) ? QLatin1Char('\t') + QString(QKeySequence(k)) : QString())
90 #else
91 #define ACCEL_KEY(k) QString()
92 #endif
93 
95 
96 #ifndef QT_NO_CONTEXTMENU
97 #if defined(Q_WS_WIN) || defined(Q_WS_X11)
98 extern bool qt_use_rtl_extensions;
99 #endif
100 #endif
101 
102 // could go into QTextCursor...
103 static QTextLine currentTextLine(const QTextCursor &cursor)
104 {
105  const QTextBlock block = cursor.block();
106  if (!block.isValid())
107  return QTextLine();
108 
109  const QTextLayout *layout = block.layout();
110  if (!layout)
111  return QTextLine();
112 
113  const int relativePos = cursor.position() - block.position();
114  return layout->lineForTextPosition(relativePos);
115 }
116 
118  : doc(0), cursorOn(false), cursorIsFocusIndicator(false),
119  interactionFlags(Qt::TextEditorInteraction),
120  dragEnabled(true),
121 #ifndef QT_NO_DRAGANDDROP
122  mousePressed(false), mightStartDrag(false),
123 #endif
124  lastSelectionState(false), ignoreAutomaticScrollbarAdjustement(false),
125  overwriteMode(false),
126  acceptRichText(true),
127  preeditCursor(0), hideCursor(false),
128  hasFocus(false),
129 #ifdef QT_KEYPAD_NAVIGATION
130  hasEditFocus(false),
131 #endif
132  isEnabled(true),
133  hadSelectionOnMousePress(false),
134  ignoreUnusedNavigationEvents(false),
135  openExternalLinks(false),
136  wordSelectionEnabled(false)
137 {}
138 
140 {
141 #ifdef QT_NO_SHORTCUT
142  Q_UNUSED(e);
143 #endif
144 
145  Q_Q(QTextControl);
146  if (cursor.isNull())
147  return false;
148 
149  const QTextCursor oldSelection = cursor;
150  const int oldCursorPos = cursor.position();
151 
154 
155  if (false) {
156  }
157 #ifndef QT_NO_SHORTCUT
158  if (e == QKeySequence::MoveToNextChar) {
159  op = QTextCursor::Right;
160  }
161  else if (e == QKeySequence::MoveToPreviousChar) {
162  op = QTextCursor::Left;
163  }
164  else if (e == QKeySequence::SelectNextChar) {
165  op = QTextCursor::Right;
167  }
168  else if (e == QKeySequence::SelectPreviousChar) {
169  op = QTextCursor::Left;
171  }
172  else if (e == QKeySequence::SelectNextWord) {
175  }
176  else if (e == QKeySequence::SelectPreviousWord) {
179  }
180  else if (e == QKeySequence::SelectStartOfLine) {
183  }
184  else if (e == QKeySequence::SelectEndOfLine) {
187  }
188  else if (e == QKeySequence::SelectStartOfBlock) {
191  }
192  else if (e == QKeySequence::SelectEndOfBlock) {
195  }
196  else if (e == QKeySequence::SelectStartOfDocument) {
197  op = QTextCursor::Start;
199  }
200  else if (e == QKeySequence::SelectEndOfDocument) {
201  op = QTextCursor::End;
203  }
204  else if (e == QKeySequence::SelectPreviousLine) {
205  op = QTextCursor::Up;
207  }
208  else if (e == QKeySequence::SelectNextLine) {
209  op = QTextCursor::Down;
211  {
212  QTextBlock block = cursor.block();
214  if (!block.next().isValid()
215  && line.isValid()
216  && line.lineNumber() == block.layout()->lineCount() - 1)
217  op = QTextCursor::End;
218  }
219  }
220  else if (e == QKeySequence::MoveToNextWord) {
222  }
223  else if (e == QKeySequence::MoveToPreviousWord) {
225  }
226  else if (e == QKeySequence::MoveToEndOfBlock) {
228  }
229  else if (e == QKeySequence::MoveToStartOfBlock) {
231  }
232  else if (e == QKeySequence::MoveToNextLine) {
233  op = QTextCursor::Down;
234  }
235  else if (e == QKeySequence::MoveToPreviousLine) {
236  op = QTextCursor::Up;
237  }
238  else if (e == QKeySequence::MoveToPreviousLine) {
239  op = QTextCursor::Up;
240  }
241  else if (e == QKeySequence::MoveToStartOfLine) {
243  }
244  else if (e == QKeySequence::MoveToEndOfLine) {
246  }
247  else if (e == QKeySequence::MoveToStartOfDocument) {
248  op = QTextCursor::Start;
249  }
250  else if (e == QKeySequence::MoveToEndOfDocument) {
251  op = QTextCursor::End;
252  }
253 #endif // QT_NO_SHORTCUT
254  else {
255  return false;
256  }
257 
258 // Except for pageup and pagedown, Mac OS X has very different behavior, we don't do it all, but
259 // here's the breakdown:
260 // Shift still works as an anchor, but only one of the other keys can be down Ctrl (Command),
261 // Alt (Option), or Meta (Control).
262 // Command/Control + Left/Right -- Move to left or right of the line
263 // + Up/Down -- Move to top bottom of the file. (Control doesn't move the cursor)
264 // Option + Left/Right -- Move one word Left/right.
265 // + Up/Down -- Begin/End of Paragraph.
266 // Home/End Top/Bottom of file. (usually don't move the cursor, but will select)
267 
268  bool visualNavigation = cursor.visualNavigation();
270  const bool moved = cursor.movePosition(op, mode);
271  cursor.setVisualNavigation(visualNavigation);
272  q->ensureCursorVisible();
273 
274  bool ignoreNavigationEvents = ignoreUnusedNavigationEvents;
275  bool isNavigationEvent = e->key() == Qt::Key_Up || e->key() == Qt::Key_Down;
276 
277 #ifdef QT_KEYPAD_NAVIGATION
278  ignoreNavigationEvents = ignoreNavigationEvents || QApplication::keypadNavigationEnabled();
279  isNavigationEvent = isNavigationEvent ||
280  (QApplication::navigationMode() == Qt::NavigationModeKeypadDirectional
281  && (e->key() == Qt::Key_Left || e->key() == Qt::Key_Right));
282 #else
283  isNavigationEvent = isNavigationEvent || e->key() == Qt::Key_Left || e->key() == Qt::Key_Right;
284 #endif
285 
286  if (moved) {
287  if (cursor.position() != oldCursorPos)
288  emit q->cursorPositionChanged();
289  emit q->microFocusChanged();
290  } else if (ignoreNavigationEvents && isNavigationEvent && oldSelection.anchor() == cursor.anchor()) {
291  return false;
292  }
293 
294  selectionChanged(/*forceEmitSelectionChanged =*/(mode == QTextCursor::KeepAnchor));
295 
296  repaintOldAndNewSelection(oldSelection);
297 
298  return true;
299 }
300 
302 {
303  Q_Q(QTextControl);
304 
306  if (fmt == lastCharFormat)
307  return;
308  lastCharFormat = fmt;
309 
310  emit q->currentCharFormatChanged(fmt);
311  emit q->microFocusChanged();
312 }
313 
315 {
316  QTextBlockFormat blockFmt = cursor.blockFormat();
317 
318  QTextList *list = cursor.currentList();
319  if (!list) {
320  QTextBlockFormat modifier;
321  modifier.setIndent(blockFmt.indent() + 1);
322  cursor.mergeBlockFormat(modifier);
323  } else {
324  QTextListFormat format = list->format();
325  format.setIndent(format.indent() + 1);
326 
327  if (list->itemNumber(cursor.block()) == 1)
328  list->setFormat(format);
329  else
330  cursor.createList(format);
331  }
332 }
333 
335 {
336  QTextBlockFormat blockFmt = cursor.blockFormat();
337 
338  QTextList *list = cursor.currentList();
339 
340  if (!list) {
341  QTextBlockFormat modifier;
342  modifier.setIndent(blockFmt.indent() - 1);
343  cursor.mergeBlockFormat(modifier);
344  } else {
345  QTextListFormat listFmt = list->format();
346  listFmt.setIndent(listFmt.indent() - 1);
347  list->setFormat(listFmt);
348  }
349 }
350 
352 {
353  QTextTable *table = cursor.currentTable();
354  QTextTableCell cell = table->cellAt(cursor);
355 
356  int newColumn = cell.column() + cell.columnSpan();
357  int newRow = cell.row();
358 
359  if (newColumn >= table->columns()) {
360  newColumn = 0;
361  ++newRow;
362  if (newRow >= table->rows())
363  table->insertRows(table->rows(), 1);
364  }
365 
366  cell = table->cellAt(newRow, newColumn);
367  cursor = cell.firstCursorPosition();
368 }
369 
371 {
372  QTextTable *table = cursor.currentTable();
373  QTextTableCell cell = table->cellAt(cursor);
374 
375  int newColumn = cell.column() - 1;
376  int newRow = cell.row();
377 
378  if (newColumn < 0) {
379  newColumn = table->columns() - 1;
380  --newRow;
381  if (newRow < 0)
382  return;
383  }
384 
385  cell = table->cellAt(newRow, newColumn);
386  cursor = cell.firstCursorPosition();
387 }
388 
390 {
392 
393  QTextBlockFormat blockFmt = cursor.blockFormat();
394 
395  QTextListFormat listFmt;
397  listFmt.setIndent(blockFmt.indent() + 1);
398 
399  blockFmt.setIndent(0);
400  cursor.setBlockFormat(blockFmt);
401 
402  cursor.createList(listFmt);
403 
405 }
406 
408 {
409  setContent(format, text, document);
410 
412 }
413 
415 {
416  Q_Q(QTextControl);
417 
418  // for use when called from setPlainText. we may want to re-use the currently
419  // set char format then.
420  const QTextCharFormat charFormatForInsertion = cursor.charFormat();
421 
422  bool clearDocument = true;
423  if (!doc) {
424  if (document) {
425  doc = document;
426  clearDocument = false;
427  } else {
428  palette = QApplication::palette("QTextControl");
429  doc = new QTextDocument(q);
430  }
433 
434 // #### doc->documentLayout()->setPaintDevice(viewport);
435 
438  QObject::connect(doc, SIGNAL(documentLayoutChanged()), q, SLOT(_q_documentLayoutChanged()));
439 
440  // convenience signal forwards
441  QObject::connect(doc, SIGNAL(undoAvailable(bool)), q, SIGNAL(undoAvailable(bool)));
442  QObject::connect(doc, SIGNAL(redoAvailable(bool)), q, SIGNAL(redoAvailable(bool)));
443  QObject::connect(doc, SIGNAL(modificationChanged(bool)), q, SIGNAL(modificationChanged(bool)));
444  QObject::connect(doc, SIGNAL(blockCountChanged(int)), q, SIGNAL(blockCountChanged(int)));
445  }
446 
447  bool previousUndoRedoState = doc->isUndoRedoEnabled();
448  if (!document)
449  doc->setUndoRedoEnabled(false);
450 
451  //Saving the index save some time.
452  static int contentsChangedIndex = QTextDocument::staticMetaObject.indexOfSignal("contentsChanged()");
453  static int textChangedIndex = QTextControl::staticMetaObject.indexOfSignal("textChanged()");
454  // avoid multiple textChanged() signals being emitted
455  QMetaObject::disconnect(doc, contentsChangedIndex, q, textChangedIndex);
456 
457  if (!text.isEmpty()) {
458  // clear 'our' cursor for insertion to prevent
459  // the emission of the cursorPositionChanged() signal.
460  // instead we emit it only once at the end instead of
461  // at the end of the document after loading and when
462  // positioning the cursor again to the start of the
463  // document.
464  cursor = QTextCursor();
465  if (format == Qt::PlainText) {
466  QTextCursor formatCursor(doc);
467  // put the setPlainText and the setCharFormat into one edit block,
468  // so that the syntax highlight triggers only /once/ for the entire
469  // document, not twice.
470  formatCursor.beginEditBlock();
471  doc->setPlainText(text);
472  doc->setUndoRedoEnabled(false);
473  formatCursor.select(QTextCursor::Document);
474  formatCursor.setCharFormat(charFormatForInsertion);
475  formatCursor.endEditBlock();
476  } else {
477 #ifndef QT_NO_TEXTHTMLPARSER
478  doc->setHtml(text);
479 #else
480  doc->setPlainText(text);
481 #endif
482  doc->setUndoRedoEnabled(false);
483  }
485  } else if (clearDocument) {
486  doc->clear();
487  }
488  cursor.setCharFormat(charFormatForInsertion);
489 
490  QMetaObject::connect(doc, contentsChangedIndex, q, textChangedIndex);
491  emit q->textChanged();
492  if (!document)
493  doc->setUndoRedoEnabled(previousUndoRedoState);
495  if (!document)
496  doc->setModified(false);
497 
498  q->ensureCursorVisible();
499  emit q->cursorPositionChanged();
500 }
501 
503 {
504 #ifndef QT_NO_DRAGANDDROP
505  Q_Q(QTextControl);
506  mousePressed = false;
507  if (!contextWidget)
508  return;
509  QMimeData *data = q->createMimeDataFromSelection();
510 
511  QDrag *drag = new QDrag(contextWidget);
512  drag->setMimeData(data);
513 
514  Qt::DropActions actions = Qt::CopyAction;
515  Qt::DropAction action;
517  actions |= Qt::MoveAction;
518  action = drag->exec(actions, Qt::MoveAction);
519  } else {
520  action = drag->exec(actions, Qt::CopyAction);
521  }
522 
523  if (action == Qt::MoveAction && drag->target() != contextWidget)
525 #endif
526 }
527 
529 {
530  Q_Q(QTextControl);
531  const int cursorPos = q->hitTest(pos, Qt::FuzzyHit);
532  if (cursorPos == -1)
533  return;
534  cursor.setPosition(cursorPos);
535 }
536 
538 {
539  cursor.setPosition(pos, mode);
540 
541  if (mode != QTextCursor::KeepAnchor) {
544  }
545 }
546 
548 {
549  Q_Q(QTextControl);
551 }
552 
554 {
555  Q_Q(QTextControl);
556  if (cursor.hasSelection()
557  && oldSelection.hasSelection()
558  && cursor.currentFrame() == oldSelection.currentFrame()
560  && !oldSelection.hasComplexSelection()
561  && cursor.anchor() == oldSelection.anchor()
562  ) {
563  QTextCursor differenceSelection(doc);
564  differenceSelection.setPosition(oldSelection.position());
565  differenceSelection.setPosition(cursor.position(), QTextCursor::KeepAnchor);
566  emit q->updateRequest(q->selectionRect(differenceSelection));
567  } else {
568  if (!oldSelection.isNull())
569  emit q->updateRequest(q->selectionRect(oldSelection) | cursorRectPlusUnicodeDirectionMarkers(oldSelection));
570  emit q->updateRequest(q->selectionRect() | cursorRectPlusUnicodeDirectionMarkers(cursor));
571  }
572 }
573 
574 void QTextControlPrivate::selectionChanged(bool forceEmitSelectionChanged /*=false*/)
575 {
576  Q_Q(QTextControl);
577  if (forceEmitSelectionChanged) {
578  emit q->selectionChanged();
579 #ifndef QT_NO_ACCESSIBILITY
580  if (q->parent())
582 #endif
583  }
584 
585  bool current = cursor.hasSelection();
586  if (current == lastSelectionState)
587  return;
588 
589  lastSelectionState = current;
590  emit q->copyAvailable(current);
591  if (!forceEmitSelectionChanged) {
592  emit q->selectionChanged();
593 #ifndef QT_NO_ACCESSIBILITY
594  if (q->parent())
596 #endif
597  }
598  emit q->microFocusChanged();
599 }
600 
602 {
605 }
606 
607 #ifndef QT_NO_CLIPBOARD
609 {
611  if (!cursor.hasSelection() || !clipboard->supportsSelection())
612  return;
613  Q_Q(QTextControl);
614  QMimeData *data = q->createMimeDataFromSelection();
615  clipboard->setMimeData(data, QClipboard::Selection);
616 }
617 #endif
618 
620 {
621  Q_Q(QTextControl);
622  if (someCursor.isCopyOf(cursor)) {
623  emit q->cursorPositionChanged();
624  emit q->microFocusChanged();
625  }
626 }
627 
629 {
630  Q_Q(QTextControl);
632  QObject::connect(layout, SIGNAL(update(QRectF)), q, SIGNAL(updateRequest(QRectF)));
633  QObject::connect(layout, SIGNAL(updateBlock(QTextBlock)), q, SLOT(_q_updateBlock(QTextBlock)));
634  QObject::connect(layout, SIGNAL(documentSizeChanged(QSizeF)), q, SIGNAL(documentSizeChanged(QSizeF)));
635 
636 }
637 
639 {
640  Q_Q(QTextControl);
641 
642  if (enable && QApplication::cursorFlashTime() > 0)
644  else
646 
647  cursorOn = enable;
648 
649  repaintCursor();
650 }
651 
652 void QTextControlPrivate::extendWordwiseSelection(int suggestedNewPosition, qreal mouseXPosition)
653 {
654  Q_Q(QTextControl);
655 
656  // if inside the initial selected word keep that
657  if (suggestedNewPosition >= selectedWordOnDoubleClick.selectionStart()
658  && suggestedNewPosition <= selectedWordOnDoubleClick.selectionEnd()) {
659  q->setTextCursor(selectedWordOnDoubleClick);
660  return;
661  }
662 
664  curs.setPosition(suggestedNewPosition, QTextCursor::KeepAnchor);
665 
667  return;
668  const int wordStartPos = curs.position();
669 
670  const int blockPos = curs.block().position();
671  const QPointF blockCoordinates = q->blockBoundingRect(curs.block()).topLeft();
672 
673  QTextLine line = currentTextLine(curs);
674  if (!line.isValid())
675  return;
676 
677  const qreal wordStartX = line.cursorToX(curs.position() - blockPos) + blockCoordinates.x();
678 
680  return;
681  const int wordEndPos = curs.position();
682 
683  const QTextLine otherLine = currentTextLine(curs);
684  if (otherLine.textStart() != line.textStart()
685  || wordEndPos == wordStartPos)
686  return;
687 
688  const qreal wordEndX = line.cursorToX(curs.position() - blockPos) + blockCoordinates.x();
689 
690  if (!wordSelectionEnabled && (mouseXPosition < wordStartX || mouseXPosition > wordEndX))
691  return;
692 
693  if (wordSelectionEnabled) {
694  if (suggestedNewPosition < selectedWordOnDoubleClick.position()) {
697  } else {
700  }
701  } else {
702  // keep the already selected word even when moving to the left
703  // (#39164)
704  if (suggestedNewPosition < selectedWordOnDoubleClick.position())
706  else
708 
709  const qreal differenceToStart = mouseXPosition - wordStartX;
710  const qreal differenceToEnd = wordEndX - mouseXPosition;
711 
712  if (differenceToStart < differenceToEnd)
714  else
716  }
717 
719 #ifndef QT_NO_CLIPBOARD
721 #endif
722  selectionChanged(true);
723  }
724 }
725 
726 void QTextControlPrivate::extendBlockwiseSelection(int suggestedNewPosition)
727 {
728  Q_Q(QTextControl);
729 
730  // if inside the initial selected line keep that
731  if (suggestedNewPosition >= selectedBlockOnTrippleClick.selectionStart()
732  && suggestedNewPosition <= selectedBlockOnTrippleClick.selectionEnd()) {
733  q->setTextCursor(selectedBlockOnTrippleClick);
734  return;
735  }
736 
737  if (suggestedNewPosition < selectedBlockOnTrippleClick.position()) {
739  cursor.setPosition(suggestedNewPosition, QTextCursor::KeepAnchor);
741  } else {
743  cursor.setPosition(suggestedNewPosition, QTextCursor::KeepAnchor);
746  }
747 
749 #ifndef QT_NO_CLIPBOARD
751 #endif
752  selectionChanged(true);
753  }
754 }
755 
757 {
759  return;
761 }
762 
764 {
765  Q_D(QTextControl);
766  d->repaintSelection();
767  const int oldCursorPos = d->cursor.position();
768  d->doc->undo(&d->cursor);
769  if (d->cursor.position() != oldCursorPos)
770  emit cursorPositionChanged();
771  emit microFocusChanged();
772  ensureCursorVisible();
773 }
774 
776 {
777  Q_D(QTextControl);
778  d->repaintSelection();
779  const int oldCursorPos = d->cursor.position();
780  d->doc->redo(&d->cursor);
781  if (d->cursor.position() != oldCursorPos)
782  emit cursorPositionChanged();
783  emit microFocusChanged();
784  ensureCursorVisible();
785 }
786 
788  : QObject(*new QTextControlPrivate, parent)
789 {
790  Q_D(QTextControl);
791  d->init();
792 }
793 
795  : QObject(*new QTextControlPrivate, parent)
796 {
797  Q_D(QTextControl);
798  d->init(Qt::RichText, text);
799 }
800 
802  : QObject(*new QTextControlPrivate, parent)
803 {
804  Q_D(QTextControl);
805  d->init(Qt::RichText, QString(), doc);
806 }
807 
809 {
810 }
811 
813 {
814  Q_D(QTextControl);
815  if (d->doc == document)
816  return;
817 
818  d->doc->disconnect(this);
819  d->doc->documentLayout()->disconnect(this);
820  d->doc->documentLayout()->setPaintDevice(0);
821 
822  if (d->doc->parent() == this)
823  delete d->doc;
824 
825  d->doc = 0;
826  d->setContent(Qt::RichText, QString(), document);
827 }
828 
830 {
831  Q_D(const QTextControl);
832  return d->doc;
833 }
834 
836 {
837  Q_D(QTextControl);
838  d->cursorIsFocusIndicator = false;
839  const bool posChanged = cursor.position() != d->cursor.position();
840  const QTextCursor oldSelection = d->cursor;
841  d->cursor = cursor;
842  d->cursorOn = d->hasFocus && (d->interactionFlags & Qt::TextEditable);
843  d->_q_updateCurrentCharFormatAndSelection();
845  d->repaintOldAndNewSelection(oldSelection);
846  if (posChanged)
848 }
849 
851 {
852  Q_D(const QTextControl);
853  return d->cursor;
854 }
855 
856 #ifndef QT_NO_CLIPBOARD
857 
859 {
860  Q_D(QTextControl);
861  if (!(d->interactionFlags & Qt::TextEditable) || !d->cursor.hasSelection())
862  return;
863  copy();
864  d->cursor.removeSelectedText();
865 }
866 
868 {
869  Q_D(QTextControl);
870  if (!d->cursor.hasSelection())
871  return;
874 }
875 
877 {
878  const QMimeData *md = QApplication::clipboard()->mimeData(mode);
879  if (md)
880  insertFromMimeData(md);
881 }
882 #endif
883 
885 {
886  Q_D(QTextControl);
887  // clears and sets empty content
888  d->extraSelections.clear();
889  d->setContent();
890 }
891 
892 
894 {
895  Q_D(QTextControl);
896  const int selectionLength = qAbs(d->cursor.position() - d->cursor.anchor());
897  d->cursor.select(QTextCursor::Document);
898  d->selectionChanged(selectionLength != qAbs(d->cursor.position() - d->cursor.anchor()));
899  d->cursorIsFocusIndicator = false;
901 }
902 
903 void QTextControl::processEvent(QEvent *e, const QPointF &coordinateOffset, QWidget *contextWidget)
904 {
905  QMatrix m;
906  m.translate(coordinateOffset.x(), coordinateOffset.y());
907  processEvent(e, m, contextWidget);
908 }
909 
910 void QTextControl::processEvent(QEvent *e, const QMatrix &matrix, QWidget *contextWidget)
911 {
912  Q_D(QTextControl);
913  if (d->interactionFlags == Qt::NoTextInteraction) {
914  e->ignore();
915  return;
916  }
917 
918  d->contextWidget = contextWidget;
919 
920  if (!d->contextWidget) {
921  switch (e->type()) {
922 #ifndef QT_NO_GRAPHICSVIEW
936  QGraphicsSceneEvent *ev = static_cast<QGraphicsSceneEvent *>(e);
937  d->contextWidget = ev->widget();
938  break;
939  }
940 #endif // QT_NO_GRAPHICSVIEW
941  default: break;
942  };
943  }
944 
945  switch (e->type()) {
946  case QEvent::KeyPress:
947  d->keyPressEvent(static_cast<QKeyEvent *>(e));
948  break;
950  QMouseEvent *ev = static_cast<QMouseEvent *>(e);
951  d->mousePressEvent(ev, ev->button(), matrix.map(ev->pos()), ev->modifiers(),
952  ev->buttons(), ev->globalPos());
953  break; }
954  case QEvent::MouseMove: {
955  QMouseEvent *ev = static_cast<QMouseEvent *>(e);
956  d->mouseMoveEvent(ev, ev->button(), matrix.map(ev->pos()), ev->modifiers(),
957  ev->buttons(), ev->globalPos());
958  break; }
960  QMouseEvent *ev = static_cast<QMouseEvent *>(e);
961  d->mouseReleaseEvent(ev, ev->button(), matrix.map(ev->pos()), ev->modifiers(),
962  ev->buttons(), ev->globalPos());
963  break; }
965  QMouseEvent *ev = static_cast<QMouseEvent *>(e);
966  d->mouseDoubleClickEvent(ev, ev->button(), matrix.map(ev->pos()), ev->modifiers(),
967  ev->buttons(), ev->globalPos());
968  break; }
969  case QEvent::InputMethod:
970  d->inputMethodEvent(static_cast<QInputMethodEvent *>(e));
971  break;
972 #ifndef QT_NO_CONTEXTMENU
973  case QEvent::ContextMenu: {
974  QContextMenuEvent *ev = static_cast<QContextMenuEvent *>(e);
975  d->contextMenuEvent(ev->globalPos(), matrix.map(ev->pos()), contextWidget);
976  break; }
977 #endif // QT_NO_CONTEXTMENU
978  case QEvent::FocusIn:
979  case QEvent::FocusOut:
980  d->focusEvent(static_cast<QFocusEvent *>(e));
981  break;
982 
984  d->isEnabled = e->isAccepted();
985  break;
986 
987 #ifndef QT_NO_TOOLTIP
988  case QEvent::ToolTip: {
989  QHelpEvent *ev = static_cast<QHelpEvent *>(e);
990  d->showToolTip(ev->globalPos(), matrix.map(ev->pos()), contextWidget);
991  break;
992  }
993 #endif // QT_NO_TOOLTIP
994 
995 #ifndef QT_NO_DRAGANDDROP
996  case QEvent::DragEnter: {
997  QDragEnterEvent *ev = static_cast<QDragEnterEvent *>(e);
998  if (d->dragEnterEvent(e, ev->mimeData()))
999  ev->acceptProposedAction();
1000  break;
1001  }
1002  case QEvent::DragLeave:
1003  d->dragLeaveEvent();
1004  break;
1005  case QEvent::DragMove: {
1006  QDragMoveEvent *ev = static_cast<QDragMoveEvent *>(e);
1007  if (d->dragMoveEvent(e, ev->mimeData(), matrix.map(ev->pos())))
1008  ev->acceptProposedAction();
1009  break;
1010  }
1011  case QEvent::Drop: {
1012  QDropEvent *ev = static_cast<QDropEvent *>(e);
1013  if (d->dropEvent(ev->mimeData(), matrix.map(ev->pos()), ev->dropAction(), ev->source()))
1014  ev->acceptProposedAction();
1015  break;
1016  }
1017 #endif
1018 
1019 #ifndef QT_NO_GRAPHICSVIEW
1021  QGraphicsSceneMouseEvent *ev = static_cast<QGraphicsSceneMouseEvent *>(e);
1022  d->mousePressEvent(ev, ev->button(), matrix.map(ev->pos()), ev->modifiers(), ev->buttons(),
1023  ev->screenPos());
1024  break; }
1026  QGraphicsSceneMouseEvent *ev = static_cast<QGraphicsSceneMouseEvent *>(e);
1027  d->mouseMoveEvent(ev, ev->button(), matrix.map(ev->pos()), ev->modifiers(), ev->buttons(),
1028  ev->screenPos());
1029  break; }
1031  QGraphicsSceneMouseEvent *ev = static_cast<QGraphicsSceneMouseEvent *>(e);
1032  d->mouseReleaseEvent(ev, ev->button(), matrix.map(ev->pos()), ev->modifiers(), ev->buttons(),
1033  ev->screenPos());
1034  break; }
1036  QGraphicsSceneMouseEvent *ev = static_cast<QGraphicsSceneMouseEvent *>(e);
1037  d->mouseDoubleClickEvent(ev, ev->button(), matrix.map(ev->pos()), ev->modifiers(), ev->buttons(),
1038  ev->screenPos());
1039  break; }
1042  d->contextMenuEvent(ev->screenPos(), matrix.map(ev->pos()), contextWidget);
1043  break; }
1044 
1046  QGraphicsSceneHoverEvent *ev = static_cast<QGraphicsSceneHoverEvent *>(e);
1047  d->mouseMoveEvent(ev, Qt::NoButton, matrix.map(ev->pos()), ev->modifiers(),Qt::NoButton,
1048  ev->screenPos());
1049  break; }
1050 
1053  if (d->dragEnterEvent(e, ev->mimeData()))
1054  ev->acceptProposedAction();
1055  break; }
1057  d->dragLeaveEvent();
1058  break;
1061  if (d->dragMoveEvent(e, ev->mimeData(), matrix.map(ev->pos())))
1062  ev->acceptProposedAction();
1063  break; }
1066  if (d->dropEvent(ev->mimeData(), matrix.map(ev->pos()), ev->dropAction(), ev->source()))
1067  ev->accept();
1068  break; }
1069 #endif // QT_NO_GRAPHICSVIEW
1070 #ifdef QT_KEYPAD_NAVIGATION
1071  case QEvent::EnterEditFocus:
1072  case QEvent::LeaveEditFocus:
1073  if (QApplication::keypadNavigationEnabled())
1074  d->editFocusEvent(e);
1075  break;
1076 #endif
1078  if (d->interactionFlags & Qt::TextEditable) {
1079  QKeyEvent* ke = static_cast<QKeyEvent *>(e);
1080  if (ke->modifiers() == Qt::NoModifier
1081  || ke->modifiers() == Qt::ShiftModifier
1082  || ke->modifiers() == Qt::KeypadModifier) {
1083  if (ke->key() < Qt::Key_Escape) {
1084  ke->accept();
1085  } else {
1086  switch (ke->key()) {
1087  case Qt::Key_Return:
1088  case Qt::Key_Enter:
1089  case Qt::Key_Delete:
1090  case Qt::Key_Home:
1091  case Qt::Key_End:
1092  case Qt::Key_Backspace:
1093  case Qt::Key_Left:
1094  case Qt::Key_Right:
1095  case Qt::Key_Up:
1096  case Qt::Key_Down:
1097  case Qt::Key_Tab:
1098  ke->accept();
1099  default:
1100  break;
1101  }
1102  }
1103 #ifndef QT_NO_SHORTCUT
1104  } else if (ke == QKeySequence::Copy
1105  || ke == QKeySequence::Paste
1106  || ke == QKeySequence::Cut
1107  || ke == QKeySequence::Redo
1108  || ke == QKeySequence::Undo
1121  || ke == QKeySequence::SelectAll
1122  ) {
1123  ke->accept();
1124 #endif
1125  }
1126  }
1127  break;
1128  default:
1129  break;
1130  }
1131 }
1132 
1134 {
1135  return QObject::event(e);
1136 }
1137 
1139 {
1140  Q_D(QTextControl);
1141  if (e->timerId() == d->cursorBlinkTimer.timerId()) {
1142  d->cursorOn = !d->cursorOn;
1143 
1144  if (d->cursor.hasSelection())
1146  != 0);
1147 
1148  d->repaintCursor();
1149  } else if (e->timerId() == d->trippleClickTimer.timerId()) {
1150  d->trippleClickTimer.stop();
1151  }
1152 }
1153 
1155 {
1156  Q_D(QTextControl);
1157  d->setContent(Qt::PlainText, text);
1158 }
1159 
1161 {
1162  Q_D(QTextControl);
1163  d->setContent(Qt::RichText, text);
1164 }
1165 
1167 {
1168  Q_Q(QTextControl);
1169 #ifndef QT_NO_SHORTCUT
1170  if (e == QKeySequence::SelectAll) {
1171  e->accept();
1172  q->selectAll();
1173  return;
1174  }
1175 #ifndef QT_NO_CLIPBOARD
1176  else if (e == QKeySequence::Copy) {
1177  e->accept();
1178  q->copy();
1179  return;
1180  }
1181 #endif
1182 #endif // QT_NO_SHORTCUT
1183 
1184  if (interactionFlags & Qt::TextSelectableByKeyboard
1185  && cursorMoveKeyEvent(e))
1186  goto accept;
1187 
1188  if (interactionFlags & Qt::LinksAccessibleByKeyboard) {
1189  if ((e->key() == Qt::Key_Return
1190  || e->key() == Qt::Key_Enter
1191 #ifdef QT_KEYPAD_NAVIGATION
1192  || e->key() == Qt::Key_Select
1193 #endif
1194  )
1195  && cursor.hasSelection()) {
1196 
1197  e->accept();
1198  activateLinkUnderCursor();
1199  return;
1200  }
1201  }
1202 
1203  if (!(interactionFlags & Qt::TextEditable)) {
1204  e->ignore();
1205  return;
1206  }
1207 
1208  if (e->key() == Qt::Key_Direction_L || e->key() == Qt::Key_Direction_R) {
1209  QTextBlockFormat fmt;
1211  cursor.mergeBlockFormat(fmt);
1212  goto accept;
1213  }
1214 
1215  // schedule a repaint of the region of the cursor, as when we move it we
1216  // want to make sure the old cursor disappears (not noticeable when moving
1217  // only a few pixels but noticeable when jumping between cells in tables for
1218  // example)
1219  repaintSelection();
1220 
1221  if (e->key() == Qt::Key_Backspace && !(e->modifiers() & ~Qt::ShiftModifier)) {
1222  QTextBlockFormat blockFmt = cursor.blockFormat();
1223  QTextList *list = cursor.currentList();
1224  if (list && cursor.atBlockStart() && !cursor.hasSelection()) {
1225  list->remove(cursor.block());
1226  } else if (cursor.atBlockStart() && blockFmt.indent() > 0) {
1227  blockFmt.setIndent(blockFmt.indent() - 1);
1228  cursor.setBlockFormat(blockFmt);
1229  } else {
1230  QTextCursor localCursor = cursor;
1231  localCursor.deletePreviousChar();
1232  }
1233  goto accept;
1234  }
1235 #ifndef QT_NO_SHORTCUT
1237  cursor.insertBlock();
1238  e->accept();
1239  goto accept;
1240  } else if (e == QKeySequence::InsertLineSeparator) {
1241  cursor.insertText(QString(QChar::LineSeparator));
1242  e->accept();
1243  goto accept;
1244  }
1245 #endif
1246  if (false) {
1247  }
1248 #ifndef QT_NO_SHORTCUT
1249  else if (e == QKeySequence::Undo) {
1250  q->undo();
1251  }
1252  else if (e == QKeySequence::Redo) {
1253  q->redo();
1254  }
1255 #ifndef QT_NO_CLIPBOARD
1256  else if (e == QKeySequence::Cut) {
1257  q->cut();
1258  }
1259  else if (e == QKeySequence::Paste) {
1261 #ifdef Q_WS_X11
1262  if (e->modifiers() == (Qt::CTRL | Qt::SHIFT) && e->key() == Qt::Key_Insert)
1263  mode = QClipboard::Selection;
1264 #endif
1265  q->paste(mode);
1266  }
1267 #endif
1268  else if (e == QKeySequence::Delete) {
1269  QTextCursor localCursor = cursor;
1270  localCursor.deleteChar();
1271  }
1272  else if (e == QKeySequence::DeleteEndOfWord) {
1273  if (!cursor.hasSelection())
1274  cursor.movePosition(QTextCursor::NextWord, QTextCursor::KeepAnchor);
1275  cursor.removeSelectedText();
1276  }
1277  else if (e == QKeySequence::DeleteStartOfWord) {
1278  if (!cursor.hasSelection())
1279  cursor.movePosition(QTextCursor::PreviousWord, QTextCursor::KeepAnchor);
1280  cursor.removeSelectedText();
1281  }
1282  else if (e == QKeySequence::DeleteEndOfLine) {
1283  QTextBlock block = cursor.block();
1284  if (cursor.position() == block.position() + block.length() - 2)
1285  cursor.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor);
1286  else
1287  cursor.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor);
1288  cursor.removeSelectedText();
1289  }
1290 #endif // QT_NO_SHORTCUT
1291  else {
1292  goto process;
1293  }
1294  goto accept;
1295 
1296 process:
1297  {
1298  QString text = e->text();
1299  if (!text.isEmpty() && (text.at(0).isPrint() || text.at(0) == QLatin1Char('\t'))) {
1300  if (overwriteMode
1301  // no need to call deleteChar() if we have a selection, insertText
1302  // does it already
1303  && !cursor.hasSelection()
1304  && !cursor.atBlockEnd())
1305  cursor.deleteChar();
1306 
1307  cursor.insertText(text);
1308  selectionChanged();
1309  } else {
1310  e->ignore();
1311  return;
1312  }
1313  }
1314 
1315  accept:
1316 
1317  e->accept();
1318  cursorOn = true;
1319 
1320  q->ensureCursorVisible();
1321 
1322  updateCurrentCharFormat();
1323 }
1324 
1326 {
1327 #ifdef QT_NO_TEXTEDIT
1328  Q_UNUSED(type);
1329  Q_UNUSED(name);
1330 #else
1331  if (QTextEdit *textEdit = qobject_cast<QTextEdit *>(parent())) {
1332  QUrl resolvedName = textEdit->d_func()->resolveUrl(name);
1333  return textEdit->loadResource(type, resolvedName);
1334  }
1335 #endif
1336  return QVariant();
1337 }
1338 
1340 {
1341  Q_Q(QTextControl);
1342  QRectF br = q->blockBoundingRect(block);
1343  br.setRight(qreal(INT_MAX)); // the block might have shrunk
1344  emit q->updateRequest(br);
1345 }
1346 
1348 {
1349  Q_Q(const QTextControl);
1350  const QTextBlock block = doc->findBlock(position);
1351  if (!block.isValid())
1352  return QRectF();
1353  const QAbstractTextDocumentLayout *docLayout = doc->documentLayout();
1354  const QTextLayout *layout = block.layout();
1355  const QPointF layoutPos = q->blockBoundingRect(block).topLeft();
1356  int relativePos = position - block.position();
1357  if (preeditCursor != 0) {
1358  int preeditPos = layout->preeditAreaPosition();
1359  if (relativePos == preeditPos)
1360  relativePos += preeditCursor;
1361  else if (relativePos > preeditPos)
1362  relativePos += layout->preeditAreaText().length();
1363  }
1364  QTextLine line = layout->lineForTextPosition(relativePos);
1365 
1366  int cursorWidth;
1367  {
1368  bool ok = false;
1369 #ifndef QT_NO_PROPERTIES
1370  cursorWidth = docLayout->property("cursorWidth").toInt(&ok);
1371 #endif
1372  if (!ok)
1373  cursorWidth = 1;
1374  }
1375 
1376  QRectF r;
1377 
1378  if (line.isValid()) {
1379  qreal x = line.cursorToX(relativePos);
1380  qreal w = 0;
1381  if (overwriteMode) {
1382  if (relativePos < line.textLength() - line.textStart())
1383  w = line.cursorToX(relativePos + 1) - x;
1384  else
1385  w = QFontMetrics(block.layout()->font()).width(QLatin1Char(' ')); // in sync with QTextLine::draw()
1386  }
1387  r = QRectF(layoutPos.x() + x, layoutPos.y() + line.y(),
1388  cursorWidth + w, line.height());
1389  } else {
1390  r = QRectF(layoutPos.x(), layoutPos.y(), cursorWidth, 10); // #### correct height
1391  }
1392 
1393  return r;
1394 }
1395 
1396 static inline bool firstFramePosLessThanCursorPos(QTextFrame *frame, int position)
1397 {
1398  return frame->firstPosition() < position;
1399 }
1400 
1401 static inline bool cursorPosLessThanLastFramePos(int position, QTextFrame *frame)
1402 {
1403  return position < frame->lastPosition();
1404 }
1405 
1407 {
1408  QRectF r;
1409  QTextFrame *frame = cursor.currentFrame();
1410  const QList<QTextFrame *> children = frame->childFrames();
1411 
1412  const QList<QTextFrame *>::ConstIterator firstFrame = qLowerBound(children.constBegin(), children.constEnd(),
1414  const QList<QTextFrame *>::ConstIterator lastFrame = qUpperBound(children.constBegin(), children.constEnd(),
1416  for (QList<QTextFrame *>::ConstIterator it = firstFrame; it != lastFrame; ++it) {
1417  if ((*it)->frameFormat().position() != QTextFrameFormat::InFlow)
1418  r |= frame->document()->documentLayout()->frameBoundingRect(*it);
1419  }
1420  return r;
1421 }
1422 
1424 {
1425  Q_D(const QTextControl);
1426 
1427  QRectF r = d->rectForPosition(cursor.selectionStart());
1428 
1429  if (cursor.hasComplexSelection() && cursor.currentTable()) {
1430  QTextTable *table = cursor.currentTable();
1431 
1432  r = d->doc->documentLayout()->frameBoundingRect(table);
1433  /*
1434  int firstRow, numRows, firstColumn, numColumns;
1435  cursor.selectedTableCells(&firstRow, &numRows, &firstColumn, &numColumns);
1436 
1437  const QTextTableCell firstCell = table->cellAt(firstRow, firstColumn);
1438  const QTextTableCell lastCell = table->cellAt(firstRow + numRows - 1, firstColumn + numColumns - 1);
1439 
1440  const QAbstractTextDocumentLayout * const layout = doc->documentLayout();
1441 
1442  QRectF tableSelRect = layout->blockBoundingRect(firstCell.firstCursorPosition().block());
1443 
1444  for (int col = firstColumn; col < firstColumn + numColumns; ++col) {
1445  const QTextTableCell cell = table->cellAt(firstRow, col);
1446  const qreal y = layout->blockBoundingRect(cell.firstCursorPosition().block()).top();
1447 
1448  tableSelRect.setTop(qMin(tableSelRect.top(), y));
1449  }
1450 
1451  for (int row = firstRow; row < firstRow + numRows; ++row) {
1452  const QTextTableCell cell = table->cellAt(row, firstColumn);
1453  const qreal x = layout->blockBoundingRect(cell.firstCursorPosition().block()).left();
1454 
1455  tableSelRect.setLeft(qMin(tableSelRect.left(), x));
1456  }
1457 
1458  for (int col = firstColumn; col < firstColumn + numColumns; ++col) {
1459  const QTextTableCell cell = table->cellAt(firstRow + numRows - 1, col);
1460  const qreal y = layout->blockBoundingRect(cell.lastCursorPosition().block()).bottom();
1461 
1462  tableSelRect.setBottom(qMax(tableSelRect.bottom(), y));
1463  }
1464 
1465  for (int row = firstRow; row < firstRow + numRows; ++row) {
1466  const QTextTableCell cell = table->cellAt(row, firstColumn + numColumns - 1);
1467  const qreal x = layout->blockBoundingRect(cell.lastCursorPosition().block()).right();
1468 
1469  tableSelRect.setRight(qMax(tableSelRect.right(), x));
1470  }
1471 
1472  r = tableSelRect.toRect();
1473  */
1474  } else if (cursor.hasSelection()) {
1475  const int position = cursor.selectionStart();
1476  const int anchor = cursor.selectionEnd();
1477  const QTextBlock posBlock = d->doc->findBlock(position);
1478  const QTextBlock anchorBlock = d->doc->findBlock(anchor);
1479  if (posBlock == anchorBlock && posBlock.isValid() && posBlock.layout()->lineCount()) {
1480  const QTextLine posLine = posBlock.layout()->lineForTextPosition(position - posBlock.position());
1481  const QTextLine anchorLine = anchorBlock.layout()->lineForTextPosition(anchor - anchorBlock.position());
1482 
1483  const int firstLine = qMin(posLine.lineNumber(), anchorLine.lineNumber());
1484  const int lastLine = qMax(posLine.lineNumber(), anchorLine.lineNumber());
1485  const QTextLayout *layout = posBlock.layout();
1486  r = QRectF();
1487  for (int i = firstLine; i <= lastLine; ++i) {
1488  r |= layout->lineAt(i).rect();
1489  r |= layout->lineAt(i).naturalTextRect(); // might be bigger in the case of wrap not enabled
1490  }
1491  r.translate(blockBoundingRect(posBlock).topLeft());
1492  } else {
1493  QRectF anchorRect = d->rectForPosition(cursor.selectionEnd());
1494  r |= anchorRect;
1495  r |= boundingRectOfFloatsInSelection(cursor);
1496  QRectF frameRect(d->doc->documentLayout()->frameBoundingRect(cursor.currentFrame()));
1497  r.setLeft(frameRect.left());
1498  r.setRight(frameRect.right());
1499  }
1500  if (r.isValid())
1501  r.adjust(-1, -1, 1, 1);
1502  }
1503 
1504  return r;
1505 }
1506 
1508 {
1509  Q_D(const QTextControl);
1510  return selectionRect(d->cursor);
1511 }
1512 
1513 void QTextControlPrivate::mousePressEvent(QEvent *e, Qt::MouseButton button, const QPointF &pos, Qt::KeyboardModifiers modifiers,
1514  Qt::MouseButtons buttons, const QPoint &globalPos)
1515 {
1516  Q_Q(QTextControl);
1517 
1518  if (sendMouseEventToInputContext(
1519  e, QEvent::MouseButtonPress, button, pos, modifiers, buttons, globalPos)) {
1520  return;
1521  }
1522 
1523  if (interactionFlags & Qt::LinksAccessibleByMouse) {
1524  anchorOnMousePress = q->anchorAt(pos);
1525 
1526  if (cursorIsFocusIndicator) {
1527  cursorIsFocusIndicator = false;
1528  repaintSelection();
1529  cursor.clearSelection();
1530  }
1531  }
1532  if (!(button & Qt::LeftButton) ||
1533  !((interactionFlags & Qt::TextSelectableByMouse) || (interactionFlags & Qt::TextEditable))) {
1534  e->ignore();
1535  return;
1536  }
1537 
1538  cursorIsFocusIndicator = false;
1539  const QTextCursor oldSelection = cursor;
1540  const int oldCursorPos = cursor.position();
1541 
1542  mousePressed = (interactionFlags & Qt::TextSelectableByMouse);
1543 #ifndef QT_NO_DRAGANDDROP
1544  mightStartDrag = false;
1545 #endif
1546 
1547  if (trippleClickTimer.isActive()
1548  && ((pos - trippleClickPoint).toPoint().manhattanLength() < QApplication::startDragDistance())) {
1549 
1550  cursor.movePosition(QTextCursor::StartOfBlock);
1551  cursor.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor);
1553  selectedBlockOnTrippleClick = cursor;
1554 
1555  anchorOnMousePress = QString();
1556 
1557  trippleClickTimer.stop();
1558  } else {
1559  int cursorPos = q->hitTest(pos, Qt::FuzzyHit);
1560  if (cursorPos == -1) {
1561  e->ignore();
1562  return;
1563  }
1564 
1565  if (modifiers == Qt::ShiftModifier && (interactionFlags & Qt::TextSelectableByMouse)) {
1566  if (wordSelectionEnabled && !selectedWordOnDoubleClick.hasSelection()) {
1567  selectedWordOnDoubleClick = cursor;
1568  selectedWordOnDoubleClick.select(QTextCursor::WordUnderCursor);
1569  }
1570 
1571  if (selectedBlockOnTrippleClick.hasSelection())
1572  extendBlockwiseSelection(cursorPos);
1573  else if (selectedWordOnDoubleClick.hasSelection())
1574  extendWordwiseSelection(cursorPos, pos.x());
1575  else if (!wordSelectionEnabled)
1576  setCursorPosition(cursorPos, QTextCursor::KeepAnchor);
1577  } else {
1578 
1579  if (dragEnabled
1580  && cursor.hasSelection()
1582  && cursorPos >= cursor.selectionStart()
1583  && cursorPos <= cursor.selectionEnd()
1584  && q->hitTest(pos, Qt::ExactHit) != -1) {
1585 #ifndef QT_NO_DRAGANDDROP
1586  mightStartDrag = true;
1587  dragStartPos = pos.toPoint();
1588 #endif
1589  return;
1590  }
1591 
1592  setCursorPosition(cursorPos);
1593  }
1594  }
1595 
1596  if (interactionFlags & Qt::TextEditable) {
1597  q->ensureCursorVisible();
1598  if (cursor.position() != oldCursorPos)
1599  emit q->cursorPositionChanged();
1600  _q_updateCurrentCharFormatAndSelection();
1601  } else {
1602  if (cursor.position() != oldCursorPos) {
1603  emit q->cursorPositionChanged();
1604  emit q->microFocusChanged();
1605  }
1606  selectionChanged();
1607  }
1608  repaintOldAndNewSelection(oldSelection);
1609  hadSelectionOnMousePress = cursor.hasSelection();
1610 }
1611 
1612 void QTextControlPrivate::mouseMoveEvent(QEvent *e, Qt::MouseButton button, const QPointF &mousePos, Qt::KeyboardModifiers modifiers,
1613  Qt::MouseButtons buttons, const QPoint &globalPos)
1614 {
1615  Q_Q(QTextControl);
1616 
1617  if (sendMouseEventToInputContext(
1618  e, QEvent::MouseMove, button, mousePos, modifiers, buttons, globalPos)) {
1619  return;
1620  }
1621 
1622  if (interactionFlags & Qt::LinksAccessibleByMouse) {
1623  QString anchor = q->anchorAt(mousePos);
1624  if (anchor != highlightedAnchor) {
1625  highlightedAnchor = anchor;
1626  emit q->linkHovered(anchor);
1627  }
1628  }
1629 
1630  if (!(buttons & Qt::LeftButton))
1631  return;
1632 
1633  const bool editable = interactionFlags & Qt::TextEditable;
1634 
1635  if (!(mousePressed
1636  || editable
1637  || mightStartDrag
1638  || selectedWordOnDoubleClick.hasSelection()
1639  || selectedBlockOnTrippleClick.hasSelection()))
1640  return;
1641 
1642  const QTextCursor oldSelection = cursor;
1643  const int oldCursorPos = cursor.position();
1644 
1645  if (mightStartDrag) {
1646  if ((mousePos.toPoint() - dragStartPos).manhattanLength() > QApplication::startDragDistance())
1647  startDrag();
1648  return;
1649  }
1650 
1651  const qreal mouseX = qreal(mousePos.x());
1652 
1653  int newCursorPos = q->hitTest(mousePos, Qt::FuzzyHit);
1654  if (newCursorPos == -1)
1655  return;
1656 
1657  if (mousePressed && wordSelectionEnabled && !selectedWordOnDoubleClick.hasSelection()) {
1658  selectedWordOnDoubleClick = cursor;
1659  selectedWordOnDoubleClick.select(QTextCursor::WordUnderCursor);
1660  }
1661 
1662  if (selectedBlockOnTrippleClick.hasSelection())
1663  extendBlockwiseSelection(newCursorPos);
1664  else if (selectedWordOnDoubleClick.hasSelection())
1665  extendWordwiseSelection(newCursorPos, mouseX);
1666  else if (mousePressed)
1667  setCursorPosition(newCursorPos, QTextCursor::KeepAnchor);
1668 
1669  if (interactionFlags & Qt::TextEditable) {
1670  // don't call ensureVisible for the visible cursor to avoid jumping
1671  // scrollbars. the autoscrolling ensures smooth scrolling if necessary.
1672  //q->ensureCursorVisible();
1673  if (cursor.position() != oldCursorPos)
1674  emit q->cursorPositionChanged();
1675  _q_updateCurrentCharFormatAndSelection();
1676 #ifndef QT_NO_IM
1677  if (contextWidget) {
1678  if (QInputContext *ic = inputContext()) {
1679  ic->update();
1680  }
1681  }
1682 #endif //QT_NO_IM
1683  } else {
1684  //emit q->visibilityRequest(QRectF(mousePos, QSizeF(1, 1)));
1685  if (cursor.position() != oldCursorPos) {
1686  emit q->cursorPositionChanged();
1687  emit q->microFocusChanged();
1688  }
1689  }
1690  selectionChanged(true);
1691  repaintOldAndNewSelection(oldSelection);
1692 }
1693 
1694 void QTextControlPrivate::mouseReleaseEvent(QEvent *e, Qt::MouseButton button, const QPointF &pos, Qt::KeyboardModifiers modifiers,
1695  Qt::MouseButtons buttons, const QPoint &globalPos)
1696 {
1697  Q_Q(QTextControl);
1698 
1699  if (sendMouseEventToInputContext(
1700  e, QEvent::MouseButtonRelease, button, pos, modifiers, buttons, globalPos)) {
1701  return;
1702  }
1703 
1704  const QTextCursor oldSelection = cursor;
1705  const int oldCursorPos = cursor.position();
1706 
1707 #ifndef QT_NO_DRAGANDDROP
1708  if (mightStartDrag && (button & Qt::LeftButton)) {
1709  mousePressed = false;
1710  setCursorPosition(pos);
1711  cursor.clearSelection();
1712  selectionChanged();
1713  }
1714 #endif
1715  if (mousePressed) {
1716  mousePressed = false;
1717 #ifndef QT_NO_CLIPBOARD
1718  setClipboardSelection();
1719  selectionChanged(true);
1720  } else if (button == Qt::MidButton
1721  && (interactionFlags & Qt::TextEditable)
1722  && QApplication::clipboard()->supportsSelection()) {
1723  setCursorPosition(pos);
1725  if (md)
1726  q->insertFromMimeData(md);
1727 #endif
1728  }
1729 
1730  repaintOldAndNewSelection(oldSelection);
1731 
1732  if (cursor.position() != oldCursorPos) {
1733  emit q->cursorPositionChanged();
1734  emit q->microFocusChanged();
1735  }
1736 
1737  if (interactionFlags & Qt::LinksAccessibleByMouse) {
1738  if (!(button & Qt::LeftButton))
1739  return;
1740 
1741  const QString anchor = q->anchorAt(pos);
1742 
1743  if (anchor.isEmpty())
1744  return;
1745 
1746  if (!cursor.hasSelection()
1747  || (anchor == anchorOnMousePress && hadSelectionOnMousePress)) {
1748 
1749  const int anchorPos = q->hitTest(pos, Qt::ExactHit);
1750  if (anchorPos != -1) {
1751  cursor.setPosition(anchorPos);
1752 
1753  QString anchor = anchorOnMousePress;
1754  anchorOnMousePress = QString();
1755  activateLinkUnderCursor(anchor);
1756  }
1757  }
1758  }
1759 }
1760 
1761 void QTextControlPrivate::mouseDoubleClickEvent(QEvent *e, Qt::MouseButton button, const QPointF &pos, Qt::KeyboardModifiers modifiers,
1762  Qt::MouseButtons buttons, const QPoint &globalPos)
1763 {
1764  Q_Q(QTextControl);
1765 
1766  if (sendMouseEventToInputContext(
1767  e, QEvent::MouseButtonDblClick, button, pos, modifiers, buttons, globalPos)) {
1768  return;
1769  }
1770 
1771  if (button != Qt::LeftButton
1772  || !(interactionFlags & Qt::TextSelectableByMouse)) {
1773  e->ignore();
1774  return;
1775  }
1776 
1777 #ifndef QT_NO_DRAGANDDROP
1778  mightStartDrag = false;
1779 #endif
1780  const QTextCursor oldSelection = cursor;
1781  setCursorPosition(pos);
1782  QTextLine line = currentTextLine(cursor);
1783  bool doEmit = false;
1784  if (line.isValid() && line.textLength()) {
1785  cursor.select(QTextCursor::WordUnderCursor);
1786  doEmit = true;
1787  }
1788  repaintOldAndNewSelection(oldSelection);
1789 
1790  cursorIsFocusIndicator = false;
1791  selectedWordOnDoubleClick = cursor;
1792 
1793  trippleClickPoint = pos;
1794  trippleClickTimer.start(QApplication::doubleClickInterval(), q);
1795  if (doEmit) {
1796  selectionChanged();
1797 #ifndef QT_NO_CLIPBOARD
1798  setClipboardSelection();
1799 #endif
1800  emit q->cursorPositionChanged();
1801  }
1802 }
1803 
1805  QEvent *e, QEvent::Type eventType, Qt::MouseButton button, const QPointF &pos,
1806  Qt::KeyboardModifiers modifiers, Qt::MouseButtons buttons, const QPoint &globalPos)
1807 {
1808 #if !defined(QT_NO_IM)
1809  Q_Q(QTextControl);
1810 
1811  QTextLayout *layout = cursor.block().layout();
1812  if (contextWidget && layout && !layout->preeditAreaText().isEmpty()) {
1813  QInputContext *ctx = inputContext();
1814  int cursorPos = q->hitTest(pos, Qt::FuzzyHit) - cursor.position();
1815 
1816  if (cursorPos < 0 || cursorPos > layout->preeditAreaText().length()) {
1817  cursorPos = -1;
1818  // don't send move events outside the preedit area
1819  if (eventType == QEvent::MouseMove)
1820  return true;
1821  }
1822  if (ctx) {
1823  QMouseEvent ev(eventType, contextWidget->mapFromGlobal(globalPos), globalPos,
1824  button, buttons, modifiers);
1825  ctx->mouseHandler(cursorPos, &ev);
1826  e->setAccepted(ev.isAccepted());
1827  }
1828  if (!layout->preeditAreaText().isEmpty())
1829  return true;
1830  }
1831 #else
1832  Q_UNUSED(e);
1833  Q_UNUSED(eventType);
1834  Q_UNUSED(button);
1835  Q_UNUSED(pos);
1836  Q_UNUSED(modifiers);
1837  Q_UNUSED(buttons);
1838  Q_UNUSED(globalPos);
1839 #endif
1840  return false;
1841 }
1842 
1843 void QTextControlPrivate::contextMenuEvent(const QPoint &screenPos, const QPointF &docPos, QWidget *contextWidget)
1844 {
1845 #ifdef QT_NO_CONTEXTMENU
1846  Q_UNUSED(screenPos);
1847  Q_UNUSED(docPos);
1848  Q_UNUSED(contextWidget);
1849 #else
1850  Q_Q(QTextControl);
1851  if (!hasFocus)
1852  return;
1853  QMenu *menu = q->createStandardContextMenu(docPos, contextWidget);
1854  if (!menu)
1855  return;
1857  menu->popup(screenPos);
1858 #endif
1859 }
1860 
1862 {
1863  Q_Q(QTextControl);
1864  if (!(interactionFlags & Qt::TextEditable) || !q->canInsertFromMimeData(mimeData)) {
1865  e->ignore();
1866  return false;
1867  }
1868 
1869  dndFeedbackCursor = QTextCursor();
1870 
1871  return true; // accept proposed action
1872 }
1873 
1875 {
1876  Q_Q(QTextControl);
1877 
1878  const QRectF crect = q->cursorRect(dndFeedbackCursor);
1879  dndFeedbackCursor = QTextCursor();
1880 
1881  if (crect.isValid())
1882  emit q->updateRequest(crect);
1883 }
1884 
1885 bool QTextControlPrivate::dragMoveEvent(QEvent *e, const QMimeData *mimeData, const QPointF &pos)
1886 {
1887  Q_Q(QTextControl);
1888  if (!(interactionFlags & Qt::TextEditable) || !q->canInsertFromMimeData(mimeData)) {
1889  e->ignore();
1890  return false;
1891  }
1892 
1893  const int cursorPos = q->hitTest(pos, Qt::FuzzyHit);
1894  if (cursorPos != -1) {
1895  QRectF crect = q->cursorRect(dndFeedbackCursor);
1896  if (crect.isValid())
1897  emit q->updateRequest(crect);
1898 
1899  dndFeedbackCursor = cursor;
1900  dndFeedbackCursor.setPosition(cursorPos);
1901 
1902  crect = q->cursorRect(dndFeedbackCursor);
1903  emit q->updateRequest(crect);
1904  }
1905 
1906  return true; // accept proposed action
1907 }
1908 
1909 bool QTextControlPrivate::dropEvent(const QMimeData *mimeData, const QPointF &pos, Qt::DropAction dropAction, QWidget *source)
1910 {
1911  Q_Q(QTextControl);
1912  dndFeedbackCursor = QTextCursor();
1913 
1914  if (!(interactionFlags & Qt::TextEditable) || !q->canInsertFromMimeData(mimeData))
1915  return false;
1916 
1917  repaintSelection();
1918 
1919  QTextCursor insertionCursor = q->cursorForPosition(pos);
1920  insertionCursor.beginEditBlock();
1921 
1922  if (dropAction == Qt::MoveAction && source == contextWidget)
1923  cursor.removeSelectedText();
1924 
1925  cursor = insertionCursor;
1926  q->insertFromMimeData(mimeData);
1927  insertionCursor.endEditBlock();
1928  q->ensureCursorVisible();
1929  return true; // accept proposed action
1930 }
1931 
1933 {
1934  Q_Q(QTextControl);
1935  if (!(interactionFlags & Qt::TextEditable) || cursor.isNull()) {
1936  e->ignore();
1937  return;
1938  }
1939  bool isGettingInput = !e->commitString().isEmpty()
1940  || e->preeditString() != cursor.block().layout()->preeditAreaText()
1941  || e->replacementLength() > 0;
1942 
1943  cursor.beginEditBlock();
1944  if (isGettingInput) {
1945  cursor.removeSelectedText();
1946  }
1947 
1948  // insert commit string
1949  if (!e->commitString().isEmpty() || e->replacementLength()) {
1950  QTextCursor c = cursor;
1951  c.setPosition(c.position() + e->replacementStart());
1953  c.insertText(e->commitString());
1954  }
1955 
1956  for (int i = 0; i < e->attributes().size(); ++i) {
1957  const QInputMethodEvent::Attribute &a = e->attributes().at(i);
1959  QTextCursor oldCursor = cursor;
1960  int blockStart = a.start + cursor.block().position();
1961  cursor.setPosition(blockStart, QTextCursor::MoveAnchor);
1962  cursor.setPosition(blockStart + a.length, QTextCursor::KeepAnchor);
1963  q->ensureCursorVisible();
1964  repaintOldAndNewSelection(oldCursor);
1965  }
1966  }
1967 
1968  QTextBlock block = cursor.block();
1969  QTextLayout *layout = block.layout();
1970  if (isGettingInput)
1971  layout->setPreeditArea(cursor.position() - block.position(), e->preeditString());
1973  const int oldPreeditCursor = preeditCursor;
1974  preeditCursor = e->preeditString().length();
1975  hideCursor = false;
1976  for (int i = 0; i < e->attributes().size(); ++i) {
1977  const QInputMethodEvent::Attribute &a = e->attributes().at(i);
1978  if (a.type == QInputMethodEvent::Cursor) {
1979  preeditCursor = a.start;
1980  hideCursor = !a.length;
1981  } else if (a.type == QInputMethodEvent::TextFormat) {
1982  QTextCharFormat f = qvariant_cast<QTextFormat>(a.value).toCharFormat();
1983  if (f.isValid()) {
1984  if (f.background().color().alphaF() == 1 && f.background().style() == Qt::SolidPattern) {
1985  f.setForeground(f.background().color());
1988  f.setFontUnderline(true);
1989  }
1991  o.start = a.start + cursor.position() - block.position();
1992  o.length = a.length;
1993  o.format = f;
1994  overrides.append(o);
1995  }
1996  }
1997  }
1998  layout->setAdditionalFormats(overrides);
1999  cursor.endEditBlock();
2000  if (cursor.d)
2001  cursor.d->setX();
2002  if (oldPreeditCursor != preeditCursor)
2003  emit q->microFocusChanged();
2004 }
2005 
2007 {
2008  Q_D(const QTextControl);
2009  QTextBlock block = d->cursor.block();
2010  switch(property) {
2011  case Qt::ImMicroFocus:
2012  return cursorRect();
2013  case Qt::ImFont:
2014  return QVariant(d->cursor.charFormat().font());
2015  case Qt::ImCursorPosition:
2016  return QVariant(d->cursor.position() - block.position());
2017  case Qt::ImSurroundingText:
2018  return QVariant(block.text());
2020  return QVariant(d->cursor.selectedText());
2022  return QVariant(); // No limit.
2023  case Qt::ImAnchorPosition:
2024  return QVariant(qBound(0, d->cursor.anchor() - block.position(), block.length()));
2025  default:
2026  return QVariant();
2027  }
2028 }
2029 
2030 void QTextControl::setFocus(bool focus, Qt::FocusReason reason)
2031 {
2033  reason);
2034  processEvent(&ev);
2035 }
2036 
2038 {
2039  Q_Q(QTextControl);
2040  emit q->updateRequest(q->selectionRect());
2041  if (e->gotFocus()) {
2042 #ifdef QT_KEYPAD_NAVIGATION
2043  if (!QApplication::keypadNavigationEnabled() || (hasEditFocus && (e->reason() == Qt::PopupFocusReason
2044 #ifdef Q_OS_SYMBIAN
2046 #endif
2047  ))) {
2048 #endif
2049  setBlinkingCursorEnabled(interactionFlags & (Qt::TextEditable | Qt::TextSelectableByKeyboard));
2050 #ifdef QT_KEYPAD_NAVIGATION
2051  }
2052 #endif
2053  } else {
2054  setBlinkingCursorEnabled(false);
2055 
2058  && e->reason() != Qt::PopupFocusReason
2059  && cursor.hasSelection()) {
2060  cursor.clearSelection();
2061  }
2062  }
2063  hasFocus = e->gotFocus();
2064 }
2065 
2067 {
2068  if (anchorCursor.hasSelection()) {
2069  QTextCursor cursor = anchorCursor;
2070  if (cursor.selectionStart() != cursor.position())
2071  cursor.setPosition(cursor.selectionStart());
2073  QTextCharFormat fmt = cursor.charFormat();
2074  if (fmt.isAnchor() && fmt.hasProperty(QTextFormat::AnchorHref))
2076  }
2077  return QString();
2078 }
2079 
2080 #ifdef QT_KEYPAD_NAVIGATION
2081 void QTextControlPrivate::editFocusEvent(QEvent *e)
2082 {
2083  Q_Q(QTextControl);
2084 
2085  if (QApplication::keypadNavigationEnabled()) {
2086  if (e->type() == QEvent::EnterEditFocus && interactionFlags & Qt::TextEditable) {
2087  const QTextCursor oldSelection = cursor;
2088  const int oldCursorPos = cursor.position();
2089  const bool moved = cursor.movePosition(QTextCursor::End, QTextCursor::MoveAnchor);
2090  q->ensureCursorVisible();
2091  if (moved) {
2092  if (cursor.position() != oldCursorPos)
2093  emit q->cursorPositionChanged();
2094  emit q->microFocusChanged();
2095  }
2096  selectionChanged();
2097  repaintOldAndNewSelection(oldSelection);
2098 
2099  setBlinkingCursorEnabled(true);
2100  } else
2101  setBlinkingCursorEnabled(false);
2102  }
2103 
2104  hasEditFocus = e->type() == QEvent::EnterEditFocus ? true : false;
2105 }
2106 #endif
2107 
2108 #ifndef QT_NO_CONTEXTMENU
2110 {
2111  Q_D(QTextControl);
2112 
2113  const bool showTextSelectionActions = d->interactionFlags & (Qt::TextEditable | Qt::TextSelectableByKeyboard | Qt::TextSelectableByMouse);
2114 
2115  d->linkToCopy = QString();
2116  if (!pos.isNull())
2117  d->linkToCopy = anchorAt(pos);
2118 
2119  if (d->linkToCopy.isEmpty() && !showTextSelectionActions)
2120  return 0;
2121 
2122  QMenu *menu = new QMenu(parent);
2123  QAction *a;
2124 
2125  if (d->interactionFlags & Qt::TextEditable) {
2126  a = menu->addAction(tr("&Undo") + ACCEL_KEY(QKeySequence::Undo), this, SLOT(undo()));
2127  a->setEnabled(d->doc->isUndoAvailable());
2128  a = menu->addAction(tr("&Redo") + ACCEL_KEY(QKeySequence::Redo), this, SLOT(redo()));
2129  a->setEnabled(d->doc->isRedoAvailable());
2130  menu->addSeparator();
2131 
2132  a = menu->addAction(tr("Cu&t") + ACCEL_KEY(QKeySequence::Cut), this, SLOT(cut()));
2133  a->setEnabled(d->cursor.hasSelection());
2134  }
2135 
2136  if (showTextSelectionActions) {
2137  a = menu->addAction(tr("&Copy") + ACCEL_KEY(QKeySequence::Copy), this, SLOT(copy()));
2138  a->setEnabled(d->cursor.hasSelection());
2139  }
2140 
2141  if ((d->interactionFlags & Qt::LinksAccessibleByKeyboard)
2142  || (d->interactionFlags & Qt::LinksAccessibleByMouse)) {
2143 
2144  a = menu->addAction(tr("Copy &Link Location"), this, SLOT(_q_copyLink()));
2145  a->setEnabled(!d->linkToCopy.isEmpty());
2146  }
2147 
2148  if (d->interactionFlags & Qt::TextEditable) {
2149 #if !defined(QT_NO_CLIPBOARD)
2150  a = menu->addAction(tr("&Paste") + ACCEL_KEY(QKeySequence::Paste), this, SLOT(paste()));
2151  a->setEnabled(canPaste());
2152 #endif
2153  a = menu->addAction(tr("Delete"), this, SLOT(_q_deleteSelected()));
2154  a->setEnabled(d->cursor.hasSelection());
2155  }
2156 
2157 
2158  if (showTextSelectionActions) {
2159  menu->addSeparator();
2160  a = menu->addAction(tr("Select All") + ACCEL_KEY(QKeySequence::SelectAll), this, SLOT(selectAll()));
2161  a->setEnabled(!d->doc->isEmpty());
2162  }
2163 
2164 #if !defined(QT_NO_IM)
2165  if (d->contextWidget) {
2166  QInputContext *qic = d->inputContext();
2167  if (qic) {
2168  QList<QAction *> imActions = qic->actions();
2169  for (int i = 0; i < imActions.size(); ++i)
2170  menu->addAction(imActions.at(i));
2171  }
2172  }
2173 #endif
2174 
2175 #if defined(Q_WS_WIN) || defined(Q_WS_X11)
2176  if ((d->interactionFlags & Qt::TextEditable) && qt_use_rtl_extensions) {
2177 #else
2178  if (d->interactionFlags & Qt::TextEditable) {
2179 #endif
2180  menu->addSeparator();
2181  QUnicodeControlCharacterMenu *ctrlCharacterMenu = new QUnicodeControlCharacterMenu(this, menu);
2182  menu->addMenu(ctrlCharacterMenu);
2183  }
2184 
2185  return menu;
2186 }
2187 #endif // QT_NO_CONTEXTMENU
2188 
2190 {
2191  Q_D(const QTextControl);
2192  int cursorPos = hitTest(pos, Qt::FuzzyHit);
2193  if (cursorPos == -1)
2194  cursorPos = 0;
2195  QTextCursor c(d->doc);
2196  c.setPosition(cursorPos);
2197  return c;
2198 }
2199 
2201 {
2202  Q_D(const QTextControl);
2203  if (cursor.isNull())
2204  return QRectF();
2205 
2206  return d->rectForPosition(cursor.position());
2207 }
2208 
2210 {
2211  Q_D(const QTextControl);
2212  return cursorRect(d->cursor);
2213 }
2214 
2216 {
2217  if (cursor.isNull())
2218  return QRectF();
2219 
2220  return rectForPosition(cursor.position()).adjusted(-4, 0, 4, 0);
2221 }
2222 
2224 {
2225  Q_D(const QTextControl);
2226  return d->doc->documentLayout()->anchorAt(pos);
2227 }
2228 
2230 {
2231  Q_D(const QTextControl);
2232 
2233  return d->anchorForCursor(d->cursor);
2234 }
2235 
2236 bool QTextControl::overwriteMode() const
2237 {
2238  Q_D(const QTextControl);
2239  return d->overwriteMode;
2240 }
2241 
2243 {
2244  Q_D(QTextControl);
2245  d->overwriteMode = overwrite;
2246 }
2247 
2248 int QTextControl::cursorWidth() const
2249 {
2250 #ifndef QT_NO_PROPERTIES
2251  Q_D(const QTextControl);
2252  int width = d->doc->documentLayout()->property("cursorWidth").toInt();
2253  if (width == -1)
2255  return width;
2256 #else
2257  return 1;
2258 #endif
2259 }
2260 
2262 {
2263  Q_D(QTextControl);
2264 #ifdef QT_NO_PROPERTIES
2265  Q_UNUSED(width);
2266 #else
2267  d->doc->documentLayout()->setProperty("cursorWidth", width);
2268 #endif
2269  d->repaintCursor();
2270 }
2271 
2272 bool QTextControl::acceptRichText() const
2273 {
2274  Q_D(const QTextControl);
2275  return d->acceptRichText;
2276 }
2277 
2279 {
2280  Q_D(QTextControl);
2281  d->acceptRichText = accept;
2282 }
2283 
2284 #ifndef QT_NO_TEXTEDIT
2285 
2287 {
2288  Q_D(QTextControl);
2289 
2291  for (int i = 0; i < d->extraSelections.count(); ++i) {
2292  const QAbstractTextDocumentLayout::Selection &esel = d->extraSelections.at(i);
2293  hash.insertMulti(esel.cursor.anchor(), i);
2294  }
2295 
2296  for (int i = 0; i < selections.count(); ++i) {
2297  const QTextEdit::ExtraSelection &sel = selections.at(i);
2299  if (it != hash.end()) {
2300  const QAbstractTextDocumentLayout::Selection &esel = d->extraSelections.at(it.value());
2301  if (esel.cursor.position() == sel.cursor.position()
2302  && esel.format == sel.format) {
2303  hash.erase(it);
2304  continue;
2305  }
2306  }
2307  QRectF r = selectionRect(sel.cursor);
2309  r.setLeft(0);
2310  r.setWidth(qreal(INT_MAX));
2311  }
2312  emit updateRequest(r);
2313  }
2314 
2315  for (QHash<int, int>::iterator it = hash.begin(); it != hash.end(); ++it) {
2316  const QAbstractTextDocumentLayout::Selection &esel = d->extraSelections.at(it.value());
2317  QRectF r = selectionRect(esel.cursor);
2319  r.setLeft(0);
2320  r.setWidth(qreal(INT_MAX));
2321  }
2322  emit updateRequest(r);
2323  }
2324 
2325  d->extraSelections.resize(selections.count());
2326  for (int i = 0; i < selections.count(); ++i) {
2327  d->extraSelections[i].cursor = selections.at(i).cursor;
2328  d->extraSelections[i].format = selections.at(i).format;
2329  }
2330 }
2331 
2333 {
2334  Q_D(const QTextControl);
2336  for (int i = 0; i < d->extraSelections.count(); ++i) {
2338  sel.cursor = d->extraSelections.at(i).cursor;
2339  sel.format = d->extraSelections.at(i).format;
2340  selections.append(sel);
2341  }
2342  return selections;
2343 }
2344 
2345 #endif // QT_NO_TEXTEDIT
2346 
2348 {
2349  Q_D(QTextControl);
2350  d->doc->setTextWidth(width);
2351 }
2352 
2354 {
2355  Q_D(const QTextControl);
2356  return d->doc->textWidth();
2357 }
2358 
2360 {
2361  Q_D(const QTextControl);
2362  return d->doc->size();
2363 }
2364 
2366 {
2367  Q_D(QTextControl);
2368  d->openExternalLinks = open;
2369 }
2370 
2372 {
2373  Q_D(const QTextControl);
2374  return d->openExternalLinks;
2375 }
2376 
2378 {
2379  Q_D(const QTextControl);
2380  return d->ignoreUnusedNavigationEvents;
2381 }
2382 
2384 {
2385  Q_D(QTextControl);
2386  d->ignoreUnusedNavigationEvents = ignore;
2387 }
2388 
2390 {
2391  Q_D(QTextControl);
2392  const QTextCursor oldSelection = d->cursor;
2393  const bool moved = d->cursor.movePosition(op, mode);
2394  d->_q_updateCurrentCharFormatAndSelection();
2396  d->repaintOldAndNewSelection(oldSelection);
2397  if (moved)
2399 }
2400 
2402 {
2403 #ifndef QT_NO_CLIPBOARD
2404  Q_D(const QTextControl);
2405  if (d->interactionFlags & Qt::TextEditable) {
2406  const QMimeData *md = QApplication::clipboard()->mimeData();
2407  return md && canInsertFromMimeData(md);
2408  }
2409 #endif
2410  return false;
2411 }
2412 
2414 {
2415  Q_D(QTextControl);
2416  d->cursorIsFocusIndicator = b;
2417  d->repaintCursor();
2418 }
2419 
2421 {
2422  Q_D(const QTextControl);
2423  return d->cursorIsFocusIndicator;
2424 }
2425 
2426 
2428 {
2429  Q_D(QTextControl);
2430  d->dragEnabled = enabled;
2431 }
2432 
2434 {
2435  Q_D(const QTextControl);
2436  return d->dragEnabled;
2437 }
2438 
2440 {
2441  Q_D(QTextControl);
2442  d->wordSelectionEnabled = enabled;
2443 }
2444 
2446 {
2447  Q_D(const QTextControl);
2448  return d->wordSelectionEnabled;
2449 }
2450 
2451 #ifndef QT_NO_PRINTER
2452 void QTextControl::print(QPrinter *printer) const
2453 {
2454 #ifndef QT_NO_PRINTER
2455  Q_D(const QTextControl);
2456  if (!printer || !printer->isValid())
2457  return;
2458  QTextDocument *tempDoc = 0;
2459  const QTextDocument *doc = d->doc;
2460  if (printer->printRange() == QPrinter::Selection) {
2461  if (!d->cursor.hasSelection())
2462  return;
2463  tempDoc = new QTextDocument(const_cast<QTextDocument *>(doc));
2465  tempDoc->setPageSize(doc->pageSize());
2466  tempDoc->setDefaultFont(doc->defaultFont());
2467  tempDoc->setUseDesignMetrics(doc->useDesignMetrics());
2468  QTextCursor(tempDoc).insertFragment(d->cursor.selection());
2469  doc = tempDoc;
2470 
2471  // copy the custom object handlers
2472  doc->documentLayout()->d_func()->handlers = d->doc->documentLayout()->d_func()->handlers;
2473  }
2474  doc->print(printer);
2475  delete tempDoc;
2476 #endif
2477 }
2478 #endif // QT_NO_PRINTER
2479 
2481 {
2482  Q_D(const QTextControl);
2483  const QTextDocumentFragment fragment(d->cursor);
2484  return new QTextEditMimeData(fragment);
2485 }
2486 
2488 {
2489  Q_D(const QTextControl);
2490  if (d->acceptRichText)
2491  return (source->hasText() && !source->text().isEmpty())
2492  || source->hasHtml()
2493  || source->hasFormat(QLatin1String("application/x-qrichtext"))
2494  || source->hasFormat(QLatin1String("application/x-qt-richtext"));
2495  else
2496  return source->hasText() && !source->text().isEmpty();
2497 }
2498 
2500 {
2501  Q_D(QTextControl);
2502  if (!(d->interactionFlags & Qt::TextEditable) || !source)
2503  return;
2504 
2505  bool hasData = false;
2506  QTextDocumentFragment fragment;
2507 #ifndef QT_NO_TEXTHTMLPARSER
2508  if (source->hasFormat(QLatin1String("application/x-qrichtext")) && d->acceptRichText) {
2509  // x-qrichtext is always UTF-8 (taken from Qt3 since we don't use it anymore).
2510  QString richtext = QString::fromUtf8(source->data(QLatin1String("application/x-qrichtext")));
2511  richtext.prepend(QLatin1String("<meta name=\"qrichtext\" content=\"1\" />"));
2512  fragment = QTextDocumentFragment::fromHtml(richtext, d->doc);
2513  hasData = true;
2514  } else if (source->hasHtml() && d->acceptRichText) {
2515  fragment = QTextDocumentFragment::fromHtml(source->html(), d->doc);
2516  hasData = true;
2517  } else {
2518  QString text = source->text();
2519  if (!text.isNull()) {
2520  fragment = QTextDocumentFragment::fromPlainText(text);
2521  hasData = true;
2522  }
2523  }
2524 #else
2525  fragment = QTextDocumentFragment::fromPlainText(source->text());
2526 #endif // QT_NO_TEXTHTMLPARSER
2527 
2528  if (hasData)
2529  d->cursor.insertFragment(fragment);
2531 }
2532 
2533 bool QTextControl::findNextPrevAnchor(const QTextCursor &startCursor, bool next, QTextCursor &newAnchor)
2534 {
2535  Q_D(QTextControl);
2536 
2537  int anchorStart = -1;
2538  QString anchorHref;
2539  int anchorEnd = -1;
2540 
2541  if (next) {
2542  const int startPos = startCursor.selectionEnd();
2543 
2544  QTextBlock block = d->doc->findBlock(startPos);
2545  QTextBlock::Iterator it = block.begin();
2546 
2547  while (!it.atEnd() && it.fragment().position() < startPos)
2548  ++it;
2549 
2550  while (block.isValid()) {
2551  anchorStart = -1;
2552 
2553  // find next anchor
2554  for (; !it.atEnd(); ++it) {
2555  const QTextFragment fragment = it.fragment();
2556  const QTextCharFormat fmt = fragment.charFormat();
2557 
2558  if (fmt.isAnchor() && fmt.hasProperty(QTextFormat::AnchorHref)) {
2559  anchorStart = fragment.position();
2560  anchorHref = fmt.anchorHref();
2561  break;
2562  }
2563  }
2564 
2565  if (anchorStart != -1) {
2566  anchorEnd = -1;
2567 
2568  // find next non-anchor fragment
2569  for (; !it.atEnd(); ++it) {
2570  const QTextFragment fragment = it.fragment();
2571  const QTextCharFormat fmt = fragment.charFormat();
2572 
2573  if (!fmt.isAnchor() || fmt.anchorHref() != anchorHref) {
2574  anchorEnd = fragment.position();
2575  break;
2576  }
2577  }
2578 
2579  if (anchorEnd == -1)
2580  anchorEnd = block.position() + block.length() - 1;
2581 
2582  // make found selection
2583  break;
2584  }
2585 
2586  block = block.next();
2587  it = block.begin();
2588  }
2589  } else {
2590  int startPos = startCursor.selectionStart();
2591  if (startPos > 0)
2592  --startPos;
2593 
2594  QTextBlock block = d->doc->findBlock(startPos);
2595  QTextBlock::Iterator blockStart = block.begin();
2596  QTextBlock::Iterator it = block.end();
2597 
2598  if (startPos == block.position()) {
2599  it = block.begin();
2600  } else {
2601  do {
2602  if (it == blockStart) {
2603  it = QTextBlock::Iterator();
2604  block = QTextBlock();
2605  } else {
2606  --it;
2607  }
2608  } while (!it.atEnd() && it.fragment().position() + it.fragment().length() - 1 > startPos);
2609  }
2610 
2611  while (block.isValid()) {
2612  anchorStart = -1;
2613 
2614  if (!it.atEnd()) {
2615  do {
2616  const QTextFragment fragment = it.fragment();
2617  const QTextCharFormat fmt = fragment.charFormat();
2618 
2619  if (fmt.isAnchor() && fmt.hasProperty(QTextFormat::AnchorHref)) {
2620  anchorStart = fragment.position() + fragment.length();
2621  anchorHref = fmt.anchorHref();
2622  break;
2623  }
2624 
2625  if (it == blockStart)
2626  it = QTextBlock::Iterator();
2627  else
2628  --it;
2629  } while (!it.atEnd());
2630  }
2631 
2632  if (anchorStart != -1 && !it.atEnd()) {
2633  anchorEnd = -1;
2634 
2635  do {
2636  const QTextFragment fragment = it.fragment();
2637  const QTextCharFormat fmt = fragment.charFormat();
2638 
2639  if (!fmt.isAnchor() || fmt.anchorHref() != anchorHref) {
2640  anchorEnd = fragment.position() + fragment.length();
2641  break;
2642  }
2643 
2644  if (it == blockStart)
2645  it = QTextBlock::Iterator();
2646  else
2647  --it;
2648  } while (!it.atEnd());
2649 
2650  if (anchorEnd == -1)
2651  anchorEnd = qMax(0, block.position());
2652 
2653  break;
2654  }
2655 
2656  block = block.previous();
2657  it = block.end();
2658  if (it != block.begin())
2659  --it;
2660  blockStart = block.begin();
2661  }
2662 
2663  }
2664 
2665  if (anchorStart != -1 && anchorEnd != -1) {
2666  newAnchor = d->cursor;
2667  newAnchor.setPosition(anchorStart);
2668  newAnchor.setPosition(anchorEnd, QTextCursor::KeepAnchor);
2669  return true;
2670  }
2671 
2672  return false;
2673 }
2674 
2676 {
2677  QTextCursor oldCursor = cursor;
2678 
2679  if (href.isEmpty()) {
2680  QTextCursor tmp = cursor;
2681  if (tmp.selectionStart() != tmp.position())
2682  tmp.setPosition(tmp.selectionStart());
2684  href = tmp.charFormat().anchorHref();
2685  }
2686  if (href.isEmpty())
2687  return;
2688 
2689  if (!cursor.hasSelection()) {
2690  QTextBlock block = cursor.block();
2691  const int cursorPos = cursor.position();
2692 
2693  QTextBlock::Iterator it = block.begin();
2694  QTextBlock::Iterator linkFragment;
2695 
2696  for (; !it.atEnd(); ++it) {
2697  QTextFragment fragment = it.fragment();
2698  const int fragmentPos = fragment.position();
2699  if (fragmentPos <= cursorPos &&
2700  fragmentPos + fragment.length() > cursorPos) {
2701  linkFragment = it;
2702  break;
2703  }
2704  }
2705 
2706  if (!linkFragment.atEnd()) {
2707  it = linkFragment;
2708  cursor.setPosition(it.fragment().position());
2709  if (it != block.begin()) {
2710  do {
2711  --it;
2712  QTextFragment fragment = it.fragment();
2713  if (fragment.charFormat().anchorHref() != href)
2714  break;
2715  cursor.setPosition(fragment.position());
2716  } while (it != block.begin());
2717  }
2718 
2719  for (it = linkFragment; !it.atEnd(); ++it) {
2720  QTextFragment fragment = it.fragment();
2721  if (fragment.charFormat().anchorHref() != href)
2722  break;
2723  cursor.setPosition(fragment.position() + fragment.length(), QTextCursor::KeepAnchor);
2724  }
2725  }
2726  }
2727 
2728  if (hasFocus) {
2729  cursorIsFocusIndicator = true;
2730  } else {
2731  cursorIsFocusIndicator = false;
2732  cursor.clearSelection();
2733  }
2734  repaintOldAndNewSelection(oldCursor);
2735 
2736 #ifndef QT_NO_DESKTOPSERVICES
2737  if (openExternalLinks)
2739  else
2740 #endif
2741  emit q_func()->linkActivated(href);
2742 }
2743 
2744 #ifndef QT_NO_TOOLTIP
2745 void QTextControlPrivate::showToolTip(const QPoint &globalPos, const QPointF &pos, QWidget *contextWidget)
2746 {
2747  const QString toolTip = q_func()->cursorForPosition(pos).charFormat().toolTip();
2748  if (toolTip.isEmpty())
2749  return;
2750  QToolTip::showText(globalPos, toolTip, contextWidget);
2751 }
2752 #endif // QT_NO_TOOLTIP
2753 
2755 {
2756  Q_D(QTextControl);
2757 
2758  if (!(d->interactionFlags & Qt::LinksAccessibleByKeyboard))
2759  return false;
2760 
2761  QRectF crect = selectionRect();
2762  emit updateRequest(crect);
2763 
2764  // If we don't have a current anchor, we start from the start/end
2765  if (!d->cursor.hasSelection()) {
2766  d->cursor = QTextCursor(d->doc);
2767  if (next)
2768  d->cursor.movePosition(QTextCursor::Start);
2769  else
2770  d->cursor.movePosition(QTextCursor::End);
2771  }
2772 
2773  QTextCursor newAnchor;
2774  if (findNextPrevAnchor(d->cursor, next, newAnchor)) {
2775  d->cursor = newAnchor;
2776  d->cursorIsFocusIndicator = true;
2777  } else {
2778  d->cursor.clearSelection();
2779  }
2780 
2781  if (d->cursor.hasSelection()) {
2782  crect = selectionRect();
2783  emit updateRequest(crect);
2784  emit visibilityRequest(crect);
2785  return true;
2786  } else {
2787  return false;
2788  }
2789 }
2790 
2792 {
2793  Q_D(QTextControl);
2794 
2795  if (!(d->interactionFlags & Qt::LinksAccessibleByKeyboard))
2796  return false;
2797 
2798  // Verify that this is an anchor.
2799  const QString anchorHref = d->anchorForCursor(newCursor);
2800  if (anchorHref.isEmpty())
2801  return false;
2802 
2803  // and process it
2804  QRectF crect = selectionRect();
2805  emit updateRequest(crect);
2806 
2807  d->cursor.setPosition(newCursor.selectionStart());
2808  d->cursor.setPosition(newCursor.selectionEnd(), QTextCursor::KeepAnchor);
2809  d->cursorIsFocusIndicator = true;
2810 
2811  crect = selectionRect();
2812  emit updateRequest(crect);
2813  emit visibilityRequest(crect);
2814  return true;
2815 }
2816 
2817 void QTextControl::setTextInteractionFlags(Qt::TextInteractionFlags flags)
2818 {
2819  Q_D(QTextControl);
2820  if (flags == d->interactionFlags)
2821  return;
2822  d->interactionFlags = flags;
2823 
2824  if (d->hasFocus)
2825  d->setBlinkingCursorEnabled(flags & (Qt::TextEditable | Qt::TextSelectableByKeyboard));
2826 }
2827 
2828 Qt::TextInteractionFlags QTextControl::textInteractionFlags() const
2829 {
2830  Q_D(const QTextControl);
2831  return d->interactionFlags;
2832 }
2833 
2835 {
2836  Q_D(QTextControl);
2837  d->cursor.mergeCharFormat(modifier);
2838  d->updateCurrentCharFormat();
2839 }
2840 
2842 {
2843  Q_D(QTextControl);
2844  d->cursor.setCharFormat(format);
2845  d->updateCurrentCharFormat();
2846 }
2847 
2849 {
2850  Q_D(const QTextControl);
2851  return d->cursor.charFormat();
2852 }
2853 
2855 {
2856  Q_D(QTextControl);
2857  d->cursor.insertText(text);
2858 }
2859 
2860 #ifndef QT_NO_TEXTHTMLPARSER
2862 {
2863  Q_D(QTextControl);
2864  d->cursor.insertHtml(text);
2865 }
2866 #endif // QT_NO_TEXTHTMLPARSER
2867 
2869 {
2870  Q_D(const QTextControl);
2871  if (name.isEmpty())
2872  return QPointF();
2873 
2874  QRectF r;
2875  for (QTextBlock block = d->doc->begin(); block.isValid(); block = block.next()) {
2876  QTextCharFormat format = block.charFormat();
2877  if (format.isAnchor() && format.anchorNames().contains(name)) {
2878  r = d->rectForPosition(block.position());
2879  break;
2880  }
2881 
2882  for (QTextBlock::Iterator it = block.begin(); !it.atEnd(); ++it) {
2883  QTextFragment fragment = it.fragment();
2884  format = fragment.charFormat();
2885  if (format.isAnchor() && format.anchorNames().contains(name)) {
2886  r = d->rectForPosition(fragment.position());
2887  block = QTextBlock();
2888  break;
2889  }
2890  }
2891  }
2892  if (!r.isValid())
2893  return QPointF();
2894  return QPointF(0, r.top());
2895 }
2896 
2898 {
2899  Q_D(QTextControl);
2900  d->doc->adjustSize();
2901 }
2902 
2903 bool QTextControl::find(const QString &exp, QTextDocument::FindFlags options)
2904 {
2905  Q_D(QTextControl);
2906  QTextCursor search = d->doc->find(exp, d->cursor, options);
2907  if (search.isNull())
2908  return false;
2909 
2910  setTextCursor(search);
2911  return true;
2912 }
2913 
2914 
2915 
2917 {
2918  QTextCursor tmp(doc);
2919  tmp.beginEditBlock();
2921 
2922  if (!doc->isEmpty())
2923  tmp.insertBlock(cursor.blockFormat(), cursor.charFormat());
2924  else
2925  tmp.setCharFormat(cursor.charFormat());
2926 
2927  // preserve the char format
2928  QTextCharFormat oldCharFormat = cursor.charFormat();
2929 
2930 #ifndef QT_NO_TEXTHTMLPARSER
2931  if (format == Qt::RichText || (format == Qt::AutoText && Qt::mightBeRichText(text))) {
2932  tmp.insertHtml(text);
2933  } else {
2934  tmp.insertText(text);
2935  }
2936 #else
2937  tmp.insertText(text);
2938 #endif // QT_NO_TEXTHTMLPARSER
2939  if (!cursor.hasSelection())
2940  cursor.setCharFormat(oldCharFormat);
2941 
2942  tmp.endEditBlock();
2943 }
2944 
2946 {
2947  Q_D(QTextControl);
2948  d->append(text, Qt::AutoText);
2949 }
2950 
2952 {
2953  Q_D(QTextControl);
2954  d->append(html, Qt::RichText);
2955 }
2956 
2958 {
2959  Q_D(QTextControl);
2960  d->append(text, Qt::PlainText);
2961 }
2962 
2963 
2965 {
2966  Q_D(QTextControl);
2967  QRectF crect = d->rectForPosition(d->cursor.position()).adjusted(-5, 0, 5, 0);
2968  emit visibilityRequest(crect);
2970 }
2971 
2973 {
2974  Q_D(const QTextControl);
2975  return d->palette;
2976 }
2977 
2979 {
2980  Q_D(QTextControl);
2981  d->palette = pal;
2982 }
2983 
2985 {
2986  Q_D(const QTextControl);
2987 
2989 
2990  ctx.selections = d->extraSelections;
2991  ctx.palette = d->palette;
2992  if (d->cursorOn && d->isEnabled) {
2993  if (d->hideCursor)
2994  ctx.cursorPosition = -1;
2995  else if (d->preeditCursor != 0)
2996  ctx.cursorPosition = - (d->preeditCursor + 2);
2997  else
2998  ctx.cursorPosition = d->cursor.position();
2999  }
3000 
3001  if (!d->dndFeedbackCursor.isNull())
3002  ctx.cursorPosition = d->dndFeedbackCursor.position();
3003 #ifdef QT_KEYPAD_NAVIGATION
3004  if (!QApplication::keypadNavigationEnabled() || d->hasEditFocus)
3005 #endif
3006  if (d->cursor.hasSelection()) {
3008  selection.cursor = d->cursor;
3009  if (d->cursorIsFocusIndicator) {
3010  QStyleOption opt;
3011  opt.palette = ctx.palette;
3013  QStyle *style = QApplication::style();
3014  if (widget)
3015  style = widget->style();
3017  selection.format = qvariant_cast<QTextFormat>(ret.variant).toCharFormat();
3018  } else {
3022  QStyleOption opt;
3023  QStyle *style = QApplication::style();
3024  if (widget) {
3025  opt.initFrom(widget);
3026  style = widget->style();
3027  }
3028  if (style->styleHint(QStyle::SH_RichText_FullWidthSelection, &opt, widget))
3030  }
3031  ctx.selections.append(selection);
3032  }
3033 
3034  return ctx;
3035 }
3036 
3038 {
3039  Q_D(QTextControl);
3040  p->save();
3042  if (rect.isValid())
3043  p->setClipRect(rect, Qt::IntersectClip);
3044  ctx.clip = rect;
3045 
3046  d->doc->documentLayout()->draw(p, ctx);
3047  p->restore();
3048 }
3049 
3051 {
3052 #ifndef QT_NO_CLIPBOARD
3053  QMimeData *md = new QMimeData;
3054  md->setText(linkToCopy);
3056 #endif
3057 }
3058 
3059 #ifndef QT_NO_IM
3061 {
3062  QInputContext *ctx = contextWidget->inputContext();
3063  if (!ctx && contextWidget->parentWidget())
3064  ctx = contextWidget->parentWidget()->inputContext();
3065  return ctx;
3066 }
3067 #endif
3068 
3069 int QTextControl::hitTest(const QPointF &point, Qt::HitTestAccuracy accuracy) const
3070 {
3071  Q_D(const QTextControl);
3072  return d->doc->documentLayout()->hitTest(point, accuracy);
3073 }
3074 
3076 {
3077  Q_D(const QTextControl);
3078  return d->doc->documentLayout()->blockBoundingRect(block);
3079 }
3080 
3081 #ifndef QT_NO_CONTEXTMENU
3082 #define NUM_CONTROL_CHARACTERS 10
3084  const char *text;
3087  { QT_TRANSLATE_NOOP("QUnicodeControlCharacterMenu", "LRM Left-to-right mark"), 0x200e },
3088  { QT_TRANSLATE_NOOP("QUnicodeControlCharacterMenu", "RLM Right-to-left mark"), 0x200f },
3089  { QT_TRANSLATE_NOOP("QUnicodeControlCharacterMenu", "ZWJ Zero width joiner"), 0x200d },
3090  { QT_TRANSLATE_NOOP("QUnicodeControlCharacterMenu", "ZWNJ Zero width non-joiner"), 0x200c },
3091  { QT_TRANSLATE_NOOP("QUnicodeControlCharacterMenu", "ZWSP Zero width space"), 0x200b },
3092  { QT_TRANSLATE_NOOP("QUnicodeControlCharacterMenu", "LRE Start of left-to-right embedding"), 0x202a },
3093  { QT_TRANSLATE_NOOP("QUnicodeControlCharacterMenu", "RLE Start of right-to-left embedding"), 0x202b },
3094  { QT_TRANSLATE_NOOP("QUnicodeControlCharacterMenu", "LRO Start of left-to-right override"), 0x202d },
3095  { QT_TRANSLATE_NOOP("QUnicodeControlCharacterMenu", "RLO Start of right-to-left override"), 0x202e },
3096  { QT_TRANSLATE_NOOP("QUnicodeControlCharacterMenu", "PDF Pop directional formatting"), 0x202c },
3097 };
3098 
3100  : QMenu(parent), editWidget(_editWidget)
3101 {
3102  setTitle(tr("Insert Unicode control character"));
3103  for (int i = 0; i < NUM_CONTROL_CHARACTERS; ++i) {
3105  }
3106 }
3107 
3109 {
3110  QAction *a = qobject_cast<QAction *>(sender());
3111  int idx = actions().indexOf(a);
3112  if (idx < 0 || idx >= NUM_CONTROL_CHARACTERS)
3113  return;
3114  QChar c(qt_controlCharacters[idx].character);
3115  QString str(c);
3116 
3117 #ifndef QT_NO_TEXTEDIT
3118  if (QTextEdit *edit = qobject_cast<QTextEdit *>(editWidget)) {
3119  edit->insertPlainText(str);
3120  return;
3121  }
3122 #endif
3123  if (QTextControl *control = qobject_cast<QTextControl *>(editWidget)) {
3124  control->insertPlainText(str);
3125  }
3126 #ifndef QT_NO_LINEEDIT
3127  if (QLineEdit *edit = qobject_cast<QLineEdit *>(editWidget)) {
3128  edit->insert(str);
3129  return;
3130  }
3131 #endif
3132 }
3133 #endif // QT_NO_CONTEXTMENU
3134 
3136 {
3137  if (!fragment.isEmpty())
3138  return QStringList() << QString::fromLatin1("text/plain") << QString::fromLatin1("text/html")
3139 #ifndef QT_NO_TEXTODFWRITER
3140  << QString::fromLatin1("application/vnd.oasis.opendocument.text")
3141 #endif
3142  ;
3143  else
3144  return QMimeData::formats();
3145 }
3146 
3148 {
3149  if (!fragment.isEmpty())
3150  setup();
3151  return QMimeData::retrieveData(mimeType, type);
3152 }
3153 
3155 {
3156  QTextEditMimeData *that = const_cast<QTextEditMimeData *>(this);
3157 #ifndef QT_NO_TEXTHTMLPARSER
3158  that->setData(QLatin1String("text/html"), fragment.toHtml("utf-8").toUtf8());
3159 #endif
3160 #ifndef QT_NO_TEXTODFWRITER
3161  {
3162  QBuffer buffer;
3163  QTextDocumentWriter writer(&buffer, "ODF");
3164  writer.write(fragment);
3165  buffer.close();
3166  that->setData(QLatin1String("application/vnd.oasis.opendocument.text"), buffer.data());
3167  }
3168 #endif
3169  that->setText(fragment.toPlainText());
3170  fragment = QTextDocumentFragment();
3171 }
3172 
3174 
3175 #include "moc_qtextcontrol_p.cpp"
3176 
3177 #endif // QT_NO_TEXTCONTROL
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
Mode
This enum type is used to control which part of the system clipboard is used by QClipboard::mimeData(...
Definition: qclipboard.h:71
Qt::DropAction dropAction() const
Returns the action that was performed in this drag and drop.
bool dropEvent(const QMimeData *mimeData, const QPointF &pos, Qt::DropAction dropAction, QWidget *source)
const QMimeData * mimeData() const
This function returns the MIME data of the event.
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
int columns() const
Returns the number of columns in the table.
double d
Definition: qnumeric_p.h:62
QSizeF pageSize
the page size that should be used for laying out the document
void setAdditionalFormats(const QList< FormatRange > &overrides)
Sets the additional formats supported by the text layout to formatList.
const QString & preeditString() const
Returns the preedit text, i.
Definition: qevent.h:455
static uint hash(const uchar *p, int n)
Definition: qhash.cpp:68
void acceptProposedAction()
Sets the drop action to be the proposed action.
Definition: qevent.h:492
QStringList anchorNames() const
Returns the anchor names associated with this text format, or an empty string list if none has been s...
void setCursorWidth(int width)
The QStyleHintReturnVariant class provides style hints that return a QVariant.
Definition: qstyleoption.h:933
void mouseDoubleClickEvent(QEvent *e, Qt::MouseButton button, const QPointF &pos, Qt::KeyboardModifiers modifiers, Qt::MouseButtons buttons, const QPoint &globalPos)
void appendHtml(const QString &html)
int anchor() const
Returns the anchor position; this is the same as position() unless there is a selection in which case...
static void updateAccessibility(QObject *, int who, Event reason)
Notifies accessibility clients about a change in object&#39;s accessibility information.
static QWaylandClipboard * clipboard
The QTextLayout::FormatRange structure is used to apply extra formatting information for a specified ...
Definition: qtextlayout.h:128
Q_OUTOFLINE_TEMPLATE RandomAccessIterator qUpperBound(RandomAccessIterator begin, RandomAccessIterator end, const T &value)
Definition: qalgorithms.h:262
qreal right() const
Returns the x-coordinate of the rectangle&#39;s right edge.
Definition: qrect.h:527
qreal alphaF() const
Returns the alpha color component of this color.
Definition: qcolor.cpp:1106
void endEditBlock()
Indicates the end of a block of editing operations on the document that should appear as a single ope...
The QKeyEvent class describes a key event.
Definition: qevent.h:224
void setData(const QString &mimetype, const QByteArray &data)
Sets the data associated with the MIME type given by mimeType to the specified data.
Definition: qmimedata.cpp:547
bool findNextPrevAnchor(const QTextCursor &from, bool next, QTextCursor &newAnchor)
QString text() const
Returns the block&#39;s contents as plain text.
void setPlainText(const QString &text)
QPoint screenPos() const
Returns the mouse cursor position in screen coordinates.
void mousePressEvent(QEvent *e, Qt::MouseButton button, const QPointF &pos, Qt::KeyboardModifiers modifiers, Qt::MouseButtons buttons, const QPoint &globalPos)
int type
Definition: qmetatype.cpp:239
The QTextCharFormat class provides formatting information for characters in a QTextDocument.
Definition: qtextformat.h:372
double qreal
Definition: qglobal.h:1193
virtual QRectF blockBoundingRect(const QTextBlock &block) const
virtual void ensureCursorVisible()
The QTextListFormat class provides formatting information for lists in a QTextDocument.
Definition: qtextformat.h:642
unsigned char c[8]
Definition: qnumeric_p.h:62
static bool connect(const QObject *sender, int signal_index, const QObject *receiver, int method_index, int type=0, int *types=0)
Definition: qobject.cpp:3194
QTextCharFormat charFormat() const
Returns the format of the character immediately before the cursor position().
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
QTextDocument * doc
The QFontMetrics class provides font metrics information.
Definition: qfontmetrics.h:65
int replacementStart() const
Returns the position at which characters are to be replaced relative from the start of the preedit st...
Definition: qevent.h:458
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
qreal y() const
Returns the line&#39;s y position.
const QColor & color() const
Returns the brush color.
Definition: qbrush.h:183
bool isDragEnabled() const
virtual QStringList formats() const
Returns a list of formats supported by the object.
Definition: qmimedata.cpp:579
The QDrag class provides support for MIME-based drag and drop data transfer.
Definition: qdrag.h:61
void setMimeData(QMimeData *data)
Sets the data to be sent to the given MIME data.
Definition: qdrag.cpp:142
QPointer< QWidget > widget
The QInputMethodEvent::Attribute class stores an input method attribute.
Definition: qevent.h:441
const QByteArray & data() const
Returns the data contained in the buffer.
Definition: qbuffer.cpp:301
bool isValid() const
Returns true if the rectangle is valid, otherwise returns false.
Definition: qrect.h:661
const QChar at(int i) const
Returns the character at the given index position in the string.
Definition: qstring.h:698
bool ignoreUnusedNavigationEvents() const
QString anchorAtCursor() const
void setTextCursor(const QTextCursor &cursor)
QTextCharFormat format
the format of the selection
void setLeft(qreal pos)
Sets the left edge of the rectangle to the given x coordinate.
Definition: qrect.h:670
The QMatrix class specifies 2D transformations of a coordinate system.
Definition: qmatrix.h:61
QSizeF size() const
#define it(className, varName)
QTextCharFormat lastCharFormat
iterator end() const
Returns a text block iterator pointing to the end of the text block.
void setProperty(int propertyId, const QVariant &value)
Sets the property specified by the propertyId to the given value.
void popup(const QPoint &pos, QAction *at=0)
Displays the menu so that the action atAction will be at the specified global position p...
Definition: qmenu.cpp:1847
The QContextMenuEvent class contains parameters that describe a context menu event.
Definition: qevent.h:396
void setTextInteractionFlags(Qt::TextInteractionFlags flags)
void extendWordwiseSelection(int suggestedNewPosition, qreal mouseXPosition)
The QTextFrame class represents a frame in a QTextDocument.
Definition: qtextobject.h:122
void setDocument(QTextDocument *document)
const QPoint & pos() const
Returns the position of the mouse pointer relative to the widget that received the event...
Definition: qevent.h:412
#define NUM_CONTROL_CHARACTERS
void keyPressEvent(QKeyEvent *e)
void insertRows(int pos, int num)
Inserts a number of rows before the row with the specified index.
Definition: qtexttable.cpp:732
QTextCursor selectedWordOnDoubleClick
virtual int pixelMetric(PixelMetric metric, const QStyleOption *option=0, const QWidget *widget=0) const =0
Returns the value of the given pixel metric.
void setCurrentCharFormat(const QTextCharFormat &format)
static bool cursorPosLessThanLastFramePos(int position, QTextFrame *frame)
void visibilityRequest(const QRectF &rect)
QTextCursor cursor
A cursor that contains a selection in a QTextDocument.
Definition: qtextedit.h:224
int selectionEnd() const
Returns the end of the selection or position() if the cursor doesn&#39;t have a selection.
bool hasHtml() const
Returns true if the object can return HTML (MIME type text/html); otherwise returns false...
Definition: qmimedata.cpp:425
void append(const QString &text)
QPoint screenPos() const
Returns the position of the mouse cursor in screen coordinates at the moment the hover event was sent...
bool atEnd() const
Returns true if the current item is the last item in the text block.
Definition: qtextobject.h:264
void setClipRect(const QRectF &, Qt::ClipOperation op=Qt::ReplaceClip)
Enables clipping, and sets the clip region to the given rectangle using the given clip operation...
Definition: qpainter.cpp:2801
void setModified(bool m=true)
void setPalette(const QPalette &pal)
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
virtual bool canInsertFromMimeData(const QMimeData *source) const
HitTestAccuracy
Definition: qtextdocument.h:78
void close()
Reimplemented Function
Definition: qbuffer.cpp:359
void setAccepted(bool accepted)
Definition: qcoreevent.h:306
QTextControl(QObject *parent=0)
QString & prepend(QChar c)
Definition: qstring.h:261
virtual QVariant loadResource(int type, const QUrl &name)
#define SLOT(a)
Definition: qobjectdefs.h:226
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
The QGraphicsSceneMouseEvent class provides mouse events in the graphics view framework.
qreal left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:525
The QTextLine class represents a line of text inside a QTextLayout.
Definition: qtextlayout.h:197
void setIndent(int indent)
Sets the list format&#39;s indentation.
Definition: qtextformat.h:685
static Qt::MouseButtons buttons
static qreal position(QGraphicsObject *item, QDeclarativeAnchorLine::AnchorLine anchorLine)
void restore()
Restores the current painter state (pops a saved state off the stack).
Definition: qpainter.cpp:1620
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
QTextList * createList(const QTextListFormat &format)
Creates and returns a new list with the given format, and makes the current paragraph the cursor is i...
int textLength() const
Returns the length of the text in the line.
Qt::DropAction dropAction() const
Returns the action to be performed on the data by the target.
Definition: qevent.h:494
virtual ~QTextControl()
Q_GUI_EXPORT bool mightBeRichText(const QString &)
Returns true if the string text is likely to be rich text; otherwise returns false.
virtual int styleHint(StyleHint stylehint, const QStyleOption *opt=0, const QWidget *widget=0, QStyleHintReturn *returnData=0) const =0
Returns an integer representing the specified style hint for the given widget described by the provid...
QRectF cursorRectPlusUnicodeDirectionMarkers(const QTextCursor &cursor) const
QList< QTextEdit::ExtraSelection > extraSelections() const
Qt::MouseButton button() const
Returns the mouse button (if any) that caused the event.
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the list.
Definition: qlist.h:269
static bool ignore(const char *test, const char *const *table)
Definition: qaxserver.cpp:660
QTextBlockFormat blockFormat() const
Returns the block format of the block the cursor is in.
static const QMetaObject staticMetaObject
This variable stores the meta-object for the class.
Definition: qobject.h:128
The QList::const_iterator class provides an STL-style const iterator for QList and QQueue...
Definition: qlist.h:228
QTextDocument * document() const
Returns the document this object belongs to.
iterator begin() const
Returns a text block iterator pointing to the beginning of the text block.
int cursorWidth() const
bool write(const QTextDocument *document)
Writes the given document to the assigned device or file and returns true if successful; otherwise re...
void _q_emitCursorPosChanged(const QTextCursor &someCursor)
#define QT_TRANSLATE_NOOP(scope, x)
Marks the string literal sourceText for dynamic translation in the given context; i...
Definition: qglobal.h:2487
static QString tr(const char *sourceText, const char *comment=0, int n=-1)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
void setPageSize(const QSizeF &size)
QWidget * widget() const
Returns the widget where the event originated, or 0 if the event originates from another application...
QTextCursor cursor
the selection&#39;s cursor
QBasicTimer cursorBlinkTimer
long ASN1_INTEGER_get ASN1_INTEGER * a
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
static QPalette palette()
Returns the application palette.
static QStyle * style()
Returns the application&#39;s style object.
QString anchorHref() const
Returns the text format&#39;s hypertext link, or an empty string if none has been set.
Definition: qtextformat.h:506
QByteArray data(const QString &mimetype) const
Returns the data stored in the object in the format described by the MIME type specified by mimeType...
Definition: qmimedata.cpp:524
void setCharFormat(const QTextCharFormat &format)
Sets the cursor&#39;s current character format to the given format.
static QRectF boundingRectOfFloatsInSelection(const QTextCursor &cursor)
void print(QPrinter *printer) const
Prints the document to the given printer.
void paste(QClipboard::Mode mode=QClipboard::Clipboard)
static int cursorFlashTime()
int start
Specifies the beginning of the format range within the text layout&#39;s text.
Definition: qtextlayout.h:129
The QBuffer class provides a QIODevice interface for a QByteArray.
Definition: qbuffer.h:57
void setBackground(const QBrush &brush)
Sets the brush use to paint the document&#39;s background to the brush specified.
Definition: qtextformat.h:343
void setFormat(const QTextListFormat &format)
Sets the list&#39;s format to format.
Definition: qtextlist.h:87
Qt::DropAction exec(Qt::DropActions supportedActions=Qt::MoveAction)
Starts the drag and drop operation and returns a value indicating the requested drop action when it i...
Definition: qdrag.cpp:243
QRectF rectForPosition(int position) const
void setMimeData(QMimeData *data, Mode mode=Clipboard)
Sets the clipboard data to src.
The QUrl class provides a convenient interface for working with URLs.
Definition: qurl.h:61
The QString class provides a Unicode character string.
Definition: qstring.h:83
T * qobject_cast(QObject *object)
Definition: qobject.h:375
void mouseMoveEvent(QEvent *e, Qt::MouseButton button, const QPointF &pos, Qt::KeyboardModifiers modifiers, Qt::MouseButtons buttons, const QPoint &globalPos)
bool isValid() const
Returns true if this character format is valid; otherwise returns false.
Definition: qtextformat.h:397
The QDragMoveEvent class provides an event which is sent while a drag and drop action is in progress...
Definition: qevent.h:530
QFont defaultFont
the default font used to display the document&#39;s text
QPointer< QWidget > contextWidget
bool dragMoveEvent(QEvent *e, const QMimeData *mimeData, const QPointF &pos)
QPalette palette
the default color that is used for the text, when no color is specified.
Q_DECL_CONSTEXPR T qAbs(const T &t)
Definition: qglobal.h:1201
int indent() const
Returns the paragraph&#39;s indent.
Definition: qtextformat.h:590
QAction * addAction(const QString &text)
This convenience function creates a new action with text.
Definition: qmenu.cpp:1453
void append(const QString &text, Qt::TextFormat format=Qt::AutoText)
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
virtual bool event(QEvent *)
This virtual function receives events to an object and should return true if the event e was recogniz...
Definition: qobject.cpp:1200
bool isPrint() const
Returns true if the character is a printable character; otherwise returns false.
Definition: qchar.cpp:598
int firstPosition() const
Returns the first document position inside the frame.
void mergeBlockFormat(const QTextBlockFormat &modifier)
Modifies the block format of the current block (or all blocks that are contained in the selection) wi...
#define Q_D(Class)
Definition: qglobal.h:2482
QMatrix & translate(qreal dx, qreal dy)
Moves the coordinate system dx along the x axis and dy along the y axis, and returns a reference to t...
Definition: qmatrix.cpp:922
int cursorPosition
the position within the document, where the cursor line should be drawn.
QFont font() const
Returns the current font that is used for the layout, or a default font if none is set...
bool isValid() const
Returns true if this text line is valid; otherwise returns false.
Definition: qtextlayout.h:201
virtual QVariant inputMethodQuery(Qt::InputMethodQuery property) const
The QSizeF class defines the size of a two-dimensional object using floating point precision...
Definition: qsize.h:202
virtual void processEvent(QEvent *e, const QMatrix &matrix, QWidget *contextWidget=0)
QRectF selectionRect() const
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
Qt::TextInteractionFlags interactionFlags
virtual int hitTest(const QPointF &point, Qt::HitTestAccuracy accuracy) const
void insertText(const QString &text)
Inserts text at the current position, using the current character format.
virtual QList< QAction * > actions()
This is a preliminary interface for Qt 4.
virtual void insertFromMimeData(const QMimeData *source)
const T value(const Key &key) const
Returns the value associated with the key.
Definition: qhash.h:606
QTextCursor textCursor() const
void setRight(qreal pos)
Sets the right edge of the rectangle to the given x coordinate.
Definition: qrect.h:672
void save()
Saves the current painter state (pushes the state onto a stack).
Definition: qpainter.cpp:1590
void setEnabled(bool)
Definition: qaction.cpp:1192
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
void setMetaInformation(MetaInformation info, const QString &)
Sets the document&#39;s meta information of the type specified by info to the given string.
const QPoint & pos() const
Returns the position of the mouse cursor, relative to the widget that received the event...
Definition: qevent.h:95
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
QStyle * style() const
Definition: qwidget.cpp:2742
QUnicodeControlCharacterMenu(QObject *editWidget, QWidget *parent)
QObject * sender() const
Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; othe...
Definition: qobject.cpp:2327
QTextBlock next() const
Returns the text block in the document after this block, or an empty text block if this is the last o...
#define ACCEL_KEY(k)
#define Q_Q(Class)
Definition: qglobal.h:2483
QTextLine lineForTextPosition(int pos) const
Returns the line that contains the cursor position specified by pos.
ColorGroup
Definition: qpalette.h:92
int toInt(bool *ok=0) const
Returns the variant as an int if the variant has type() Int , Bool , ByteArray , Char ...
Definition: qvariant.cpp:2625
int position() const
Returns the index of the block&#39;s first character within the document.
QTextCharFormat currentCharFormat() const
QMenu * createStandardContextMenu(const QPointF &pos, QWidget *parent)
QTextFrame * currentFrame() const
Returns a pointer to the current frame.
void init(Qt::TextFormat format=Qt::RichText, const QString &text=QString(), QTextDocument *document=0)
QTextBlock previous() const
Returns the text block in the document before this block, or an empty text block if this is the first...
The QAbstractTextDocumentLayout::Selection class is a convenience class defining the parameters of a ...
void selectionChanged()
Qt::KeyboardModifiers modifiers() const
Returns the keyboard modifier flags that existed immediately after the event occurred.
Definition: qevent.cpp:999
int key() const
Returns the code of the key that was pressed or released.
Definition: qevent.h:231
void inputMethodEvent(QInputMethodEvent *)
void setPlainText(const QString &text)
Replaces the entire contents of the document with the given plain text.
#define SIGNAL(a)
Definition: qobjectdefs.h:227
void setCursorPosition(const QPointF &pos)
bool hasProperty(int propertyId) const
Returns true if the text format has a property with the given propertyId; otherwise returns false...
QTextTableCell cellAt(int row, int col) const
Returns the table cell at the given row and column in the table.
Definition: qtexttable.cpp:630
void activateLinkUnderCursor(QString href=QString())
bool setFocusToNextOrPreviousAnchor(bool next)
QWidget * source() const
This function returns the QGraphicsView that created the QGraphicsSceneDragDropEvent.
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
QTextCharFormat charFormat() const
Returns the text fragment&#39;s character format.
qreal cursorToX(int *cursorPos, Edge edge=Leading) const
Converts the cursor position cursorPos to the corresponding x position inside the line...
const QString & commitString() const
Returns the text that should get added to (or replace parts of) the text of the editor widget...
Definition: qevent.h:457
const QMimeData * mimeData(Mode mode=Clipboard) const
Returns a reference to a QMimeData representation of the current clipboard data.
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
bool cursorMoveKeyEvent(QKeyEvent *e)
MoveMode
If the anchor() is kept where it is and the position() is moved, the text in between will be selected...
Definition: qtextcursor.h:85
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
QString anchorAt(const QPointF &pos) const
bool isWordSelectionEnabled() const
bool isAccepted() const
Definition: qcoreevent.h:307
qreal textWidth() const
int column() const
Returns the number of the column in the table that contains this cell.
Definition: qtexttable.cpp:201
Qt::KeyboardModifiers modifiers() const
Returns the keyboard modifiers at the moment the hover event was sent.
int lastPosition() const
Returns the last document position inside the frame.
bool dragEnterEvent(QEvent *e, const QMimeData *mimeData)
static QTextDocumentFragment fromHtml(const QString &html)
Returns a QTextDocumentFragment based on the arbitrary piece of HTML in the given text...
void setTitle(const QString &title)
Definition: qmenu.cpp:732
bool hasSelection() const
Returns true if the cursor contains a selection; otherwise returns false.
bool sendMouseEventToInputContext(QEvent *e, QEvent::Type eventType, Qt::MouseButton button, const QPointF &pos, Qt::KeyboardModifiers modifiers, Qt::MouseButtons buttons, const QPoint &globalPos)
QTextTable * currentTable() const
Returns a pointer to the current table if the cursor position() is inside a block that is part of a t...
QString text() const
Returns a plain text (MIME type text/plain) representation of the data.
Definition: qmimedata.cpp:364
bool isAnchor() const
Returns true if the text is formatted as an anchor; otherwise returns false.
Definition: qtextformat.h:501
static QClipboard * clipboard()
Returns a pointer to the application global clipboard.
The QStyleOption class stores the parameters used by QStyle functions.
Definition: qstyleoption.h:67
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
QString anchorForCursor(const QTextCursor &anchor) const
The QTextFormat class provides formatting information for a QTextDocument.
Definition: qtextformat.h:129
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
void setBlockFormat(const QTextBlockFormat &format)
Sets the block format of the current block (or all blocks that are contained in the selection) to for...
The QTextCursor class offers an API to access and modify QTextDocuments.
Definition: qtextcursor.h:70
QPalette palette() const
void print(QPrinter *printer) const
Qt::TextInteractionFlags textInteractionFlags() const
void contextMenuEvent(const QPoint &screenPos, const QPointF &docPos, QWidget *contextWidget)
void initFrom(const QWidget *w)
Definition: qstyleoption.h:99
const char * name
The QPrinter class is a paint device that paints on a printer.
Definition: qprinter.h:66
void updateRequest(const QRectF &rect=QRectF())
static bool firstFramePosLessThanCursorPos(QTextFrame *frame, int position)
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
#define emit
Definition: qobjectdefs.h:76
int lineNumber() const
Returns the position of the line in the text engine.
Definition: qtextlayout.h:243
bool isUndoRedoEnabled() const
bool visualNavigation() const
Returns true if the cursor does visual navigation; otherwise returns false.
const char * layout
QString html() const
Returns a string if the data stored in the object is HTML (MIME type text/html); otherwise returns an...
Definition: qmimedata.cpp:400
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
void setHtml(const QString &text)
QPointF pos() const
Returns the position of the mouse cursor in item coordinates at the moment the context menu was reque...
static QTextDocumentFragment fromPlainText(const QString &plainText)
Returns a document fragment that contains the given plainText.
static QString fromUtf8(const char *, int size=-1)
Returns a QString initialized with the first size bytes of the UTF-8 string str.
Definition: qstring.cpp:4302
static QTextLine currentTextLine(const QTextCursor &cursor)
bool isValid() const
Returns true if the printer currently selected is a valid printer in the system, or a pure PDF/PostSc...
Definition: qprinter.cpp:895
QAction * addSeparator()
This convenience function creates a new separator action, i.e.
Definition: qmenu.cpp:1583
int timerId() const
Returns the unique timer identifier, which is the same identifier as returned from QObject::startTime...
Definition: qcoreevent.h:346
QPoint screenPos() const
Returns the position of the mouse cursor in screen coordinates at the moment the the context menu was...
virtual void timerEvent(QTimerEvent *e)
This event handler can be reimplemented in a subclass to receive timer events for the object...
The QTextBlock class provides a container for text fragments in a QTextDocument.
Definition: qtextobject.h:199
static const char * data(const QByteArray &arr)
virtual QMimeData * createMimeDataFromSelection() const
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
Type
This enum type defines the types of variable that a QVariant can contain.
Definition: qvariant.h:95
void moveCursor(QTextCursor::MoveOperation op, QTextCursor::MoveMode mode=QTextCursor::MoveAnchor)
PrintRange printRange() const
Returns the page range of the QPrinter.
Definition: qprinter.cpp:2265
static bool disconnect(const QObject *sender, int signal_index, const QObject *receiver, int method_index)
Definition: qobject.cpp:3276
QBool contains(const QString &str, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the list contains the string str; otherwise returns false.
Definition: qstringlist.h:172
int row() const
Returns the number of the row in the table that contains this cell.
Definition: qtexttable.cpp:184
void setHtml(const QString &html)
Replaces the entire contents of the document with the given HTML-formatted text in the html string...
int indexOfSignal(const char *signal) const
Finds signal and returns its index; otherwise returns -1.
const QList< Attribute > & attributes() const
Returns the list of attributes passed to the QInputMethodEvent constructor.
Definition: qevent.h:454
void select(SelectionType selection)
Selects text in the document according to the given selection.
void insertFragment(const QTextDocumentFragment &fragment)
Inserts the text fragment at the current position().
The QClipboard class provides access to the window system clipboard.
Definition: qclipboard.h:62
DropAction
Definition: qnamespace.h:1597
The QGraphicsSceneEvent class provides a base class for all graphics view related events...
void setUseDesignMetrics(bool b)
static int startDragDistance()
QRectF clip
a hint to the layout specifying the area around paragraphs, frames or text require painting...
void setIgnoreUnusedNavigationEvents(bool ignore)
int position() const
Returns the absolute position of the cursor within the document.
int length() const
Returns the length of the block in characters.
virtual void mouseHandler(int x, QMouseEvent *event)
This function can be reimplemented in a subclass to handle mouse press, release, double-click, and move events within the preedit text.
QBrush background() const
Returns the brush used to paint the document&#39;s background.
Definition: qtextformat.h:345
Qt::BrushStyle style() const
Returns the brush style.
Definition: qbrush.h:182
void setContent(Qt::TextFormat format=Qt::RichText, const QString &text=QString(), QTextDocument *document=0)
The QTextTable class represents a table in a QTextDocument.
Definition: qtexttable.h:103
int itemNumber(const QTextBlock &) const
Returns the index of the list item that corresponds to the given block.
Definition: qtextlist.cpp:185
QRectF cursorRect() const
The QMimeData class provides a container for data that records information about its MIME type...
Definition: qmimedata.h:57
int length() const
Returns the number of characters in the text fragment.
void _q_updateBlock(const QTextBlock &)
void translate(qreal dx, qreal dy)
Moves the rectangle dx along the x-axis and dy along the y-axis, relative to the current position...
Definition: qrect.h:716
virtual QRectF frameBoundingRect(QTextFrame *frame) const =0
Returns the bounding rectangle of frame.
The QTextFragment class holds a piece of text in a QTextDocument with a single QTextCharFormat.
Definition: qtextobject.h:297
Qt::MouseButton button() const
Returns the button that caused the event.
Definition: qevent.h:101
void acceptProposedAction()
Sets the proposed action as accepted, i.e, the drop action is set to the proposed action...
void setDragEnabled(bool enabled)
void removeSelectedText()
If there is a selection, its content is deleted; otherwise does nothing.
The QTextBlock::iterator class provides an iterator for reading the contents of a QTextBlock...
Definition: qtextobject.h:251
QTextList * currentList() const
Returns the current list if the cursor position() is inside a block that is part of a list; otherwise...
bool isCopyOf(const QTextCursor &other) const
Returns true if this cursor and other are copies of each other, i.e.
QTextBlock block() const
Returns the block that contains the cursor.
int preeditAreaPosition() const
Returns the position of the area in the text layout that will be processed before editing occurs...
void setAcceptRichText(bool accept)
const QBrush & brush(ColorGroup cg, ColorRole cr) const
Returns the brush in the specified color group, used for the given color role.
Definition: qpalette.cpp:874
QTextDocument * document() const
#define QT_NO_DRAGANDDROP
Definition: qconfig-large.h:96
bool supportsSelection() const
Returns true if the clipboard supports mouse selection; otherwise returns false.
Definition: qclipboard.cpp:567
void stop()
Stops the timer.
QInputContext * inputContext()
QAbstractTextDocumentLayout::PaintContext getPaintContext(QWidget *widget) const
TextFormat
Definition: qnamespace.h:1310
The QMouseEvent class contains parameters that describe a mouse event.
Definition: qevent.h:85
QList< QTextFrame * > childFrames() const
Returns a (possibly empty) list of the frame&#39;s child frames.
InputMethodQuery
Definition: qnamespace.h:1541
QPalette palette
the palette that should be used when painting the control
Definition: qstyleoption.h:92
The QInputMethodEvent class provides parameters for input method events.
Definition: qevent.h:431
bool isNull() const
Returns true if this string is null; otherwise returns false.
Definition: qstring.h:505
void insertBlock()
Inserts a new empty block at the cursor position() with the current blockFormat() and charFormat()...
virtual bool hasFormat(const QString &mimetype) const
Returns true if the object can return data for the MIME type specified by mimeType; otherwise returns...
Definition: qmimedata.cpp:563
Q_OUTOFLINE_TEMPLATE RandomAccessIterator qLowerBound(RandomAccessIterator begin, RandomAccessIterator end, const T &value)
Definition: qalgorithms.h:227
void setDefaultFont(const QFont &font)
Sets the default font to use in the document layout.
void setCursorIsFocusIndicator(bool b)
int position() const
Returns the position of this text fragment in the document.
void setOverwriteMode(bool overwrite)
QString preeditAreaText() const
Returns the text that is inserted in the layout before editing occurs.
virtual QStringList formats() const
Returns a list of formats supported by the object.
The QTextLayout class is used to lay out and render text.
Definition: qtextlayout.h:105
void remove(const QTextBlock &)
Removes the given block from the list.
Definition: qtextlist.cpp:319
void beginEditBlock()
Indicates the start of a block of editing operations on the document that should appear as a single o...
bool overwriteMode() const
The QDropEvent class provides an event which is sent when a drag and drop action is completed...
Definition: qevent.h:476
Qt::MouseButtons buttons() const
Returns the button state when the event was generated.
Definition: qevent.h:102
iterator Iterator
Qt-style synonym for QTextBlock::iterator.
Definition: qtextobject.h:275
bool acceptRichText() const
int indexOf(const T &t, int from=0) const
Returns the index position of the first occurrence of value in the list, searching forward from index...
Definition: qlist.h:847
The QMenu class provides a menu widget for use in menu bars, context menus, and other popup menus...
Definition: qmenu.h:72
void map(int x, int y, int *tx, int *ty) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qmatrix.cpp:384
virtual QVariant retrieveData(const QString &mimeType, QVariant::Type type) const
Returns a variant with the given type containing data for the MIME type specified by mimeType...
The QGraphicsSceneDragDropEvent class provides events for drag and drop in the graphics view framewor...
FocusReason
Definition: qnamespace.h:1521
bool qt_use_rtl_extensions
Type
This enum type defines the valid event types in Qt.
Definition: qcoreevent.h:62
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the hash...
Definition: qhash.h:467
The QTimerEvent class contains parameters that describe a timer event.
Definition: qcoreevent.h:341
QString text() const
Returns the Unicode text that this key generated.
Definition: qevent.h:236
unsigned short ushort
Definition: qglobal.h:995
QPoint toPoint() const
Rounds the coordinates of this point to the nearest integer, and returns a QPoint object with the rou...
Definition: qpoint.h:376
void focusEvent(QFocusEvent *e)
virtual QVariant retrieveData(const QString &mimetype, QVariant::Type preferredType) const
Returns a variant with the given type containing data for the MIME type specified by mimeType...
Definition: qmimedata.cpp:603
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
void adjust(qreal x1, qreal y1, qreal x2, qreal y2)
Adds dx1, dy1, dx2 and dy2 respectively to the existing coordinates of the rectangle.
Definition: qrect.h:778
void setFontUnderline(bool underline)
If underline is true, sets the text format&#39;s font to be underlined; otherwise it is displayed non-und...
Definition: qtextformat.h:432
QWidget * source() const
If the source of the drag operation is a widget in this application, this function returns that sourc...
Definition: qevent.cpp:2739
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
#define ctx
Definition: qgl.cpp:6094
bool hasText() const
Returns true if the object can return plain text (MIME type text/plain); otherwise returns false...
Definition: qmimedata.cpp:389
The QDragEnterEvent class provides an event which is sent to a widget when a drag and drop action ent...
Definition: qevent.h:555
int rows() const
Returns the number of rows in the table.
QString metaInformation(MetaInformation info) const
Returns meta information about the document of the type specified by info.
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
QAbstractTextDocumentLayout * documentLayout() const
Returns the document layout for this document.
Q_DECL_CONSTEXPR const T & qBound(const T &min, const T &val, const T &max)
Definition: qglobal.h:1219
void deletePreviousChar()
If there is no selected text, deletes the character before the current cursor position; otherwise del...
The QTextTableCell class represents the properties of a cell in a QTextTable.
Definition: qtexttable.h:59
bool hasComplexSelection() const
Returns true if the cursor contains a selection that is not simply a range from selectionStart() to s...
The QAbstractTextDocumentLayout::PaintContext class is a convenience class defining the parameters us...
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
The QTextBlockFormat class provides formatting information for blocks of text in a QTextDocument...
Definition: qtextformat.h:545
The QStyle class is an abstract base class that encapsulates the look and feel of a GUI...
Definition: qstyle.h:68
bool isNull() const
Returns true if the cursor is null; otherwise returns false.
QList< QAction * > actions() const
Returns the (possibly empty) list of this widget&#39;s actions.
Definition: qwidget.cpp:3407
bool find(const QString &exp, QTextDocument::FindFlags options=0)
bool boolProperty(int propertyId) const
Returns the value of the property specified by propertyId.
void setUndoRedoEnabled(bool enable)
virtual bool event(QEvent *e)
This virtual function receives events to an object and should return true if the event e was recogniz...
const QPoint & globalPos() const
Returns the mouse cursor position when the event was generated in global coordinates.
Definition: qevent.h:598
QPointF pos() const
Returns the position of the mouse cursor in item coordinates at the moment the hover event was sent...
Definition: qnamespace.h:54
QAction * addMenu(QMenu *menu)
This convenience function adds menu as a submenu to this menu.
Definition: qmenu.cpp:1541
iterator begin()
Returns an STL-style iterator pointing to the first item in the hash.
Definition: qhash.h:464
The QTextEdit::ExtraSelection structure provides a way of specifying a character format for a given s...
Definition: qtextedit.h:222
void setIndent(int indent)
Sets the paragraph&#39;s indentation.
Definition: qtextformat.h:622
bool isNull() const
Returns true if both the x and y coordinates are set to +0.
Definition: qpoint.h:277
Qt::FocusReason reason()
Definition: qevent.cpp:1197
void _q_updateCurrentCharFormatAndSelection()
const QObjectList & children() const
Returns a list of child objects.
Definition: qobject.h:197
QTextCursor firstCursorPosition() const
Returns the first valid cursor position in this cell.
Definition: qtexttable.cpp:249
T qvariant_cast(const QVariant &)
Definition: qvariant.h:571
void microFocusChanged()
void setup() const
bool movePosition(MoveOperation op, MoveMode=MoveAnchor, int n=1)
Moves the cursor by performing the given operation n times, using the specified mode, and returns true if all operations were completed successfully; otherwise returns false.
void setBlinkingCursorEnabled(bool enable)
The QLineEdit widget is a one-line text editor.
Definition: qlineedit.h:66
void setAttribute(Qt::WidgetAttribute, bool on=true)
Sets the attribute attribute on this widget if on is true; otherwise clears the attribute.
Definition: qwidget.cpp:11087
bool setFocusToAnchor(const QTextCursor &newCursor)
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287
void setVisualNavigation(bool b)
Sets visual navigation to b.
QVariant property(const char *name) const
Returns the value of the object&#39;s name property.
Definition: qobject.cpp:3807
QObject * parent
Definition: qobject.h:92
QTextCursor cursorForPosition(const QPointF &pos) const
void setPosition(int pos, MoveMode mode=MoveAnchor)
Moves the cursor to the absolute position in the document specified by pos using a MoveMode specified...
QString stringProperty(int propertyId) const
Returns the value of the property given by propertyId; if the property isn&#39;t of QVariant::String type...
The QTextDocument class holds formatted text that can be viewed and edited using a QTextEdit...
void drawContents(QPainter *painter, const QRectF &rect=QRectF(), QWidget *widget=0)
void setText(const QString &text)
Sets text as the plain text (MIME type text/plain) used to represent the data.
Definition: qmimedata.cpp:377
void extendBlockwiseSelection(int suggestedNewPosition)
QPointF pos() const
Returns the mouse cursor position in item coordinates.
bool isValid() const
Returns true if this text block is valid; otherwise returns false.
Definition: qtextobject.h:208
qreal top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:526
int length
Specifies the numer of characters the format range spans.
Definition: qtextlayout.h:130
QTextCharFormat format
Specifies the format to apply.
Definition: qtextlayout.h:131
Qt::KeyboardModifiers modifiers() const
Returns the keyboard modifiers in use at the time the event was sent.
The QTextList class provides a decorated list of items in a QTextDocument.
Definition: qtextlist.h:57
void setForeground(const QBrush &brush)
Sets the foreground brush to the specified brush.
Definition: qtextformat.h:350
void ignore()
Clears the accept flag parameter of the event object, the equivalent of calling setAccepted(false).
Definition: qcoreevent.h:310
void accept()
Sets the accept flag of the event object, the equivalent of calling setAccepted(true).
Definition: qcoreevent.h:309
const QMimeData * mimeData() const
Returns the data that was dropped on the widget and its associated MIME type information.
Definition: qevent.h:498
The QTextDocumentWriter class provides a format-independent interface for writing a QTextDocument to ...
void appendPlainText(const QString &text)
void setWidth(qreal w)
Sets the width of the rectangle to the given width.
Definition: qrect.h:784
int replacementLength() const
Returns the number of characters to be replaced in the preedit string.
Definition: qevent.h:459
void setFocus(bool focus, Qt::FocusReason=Qt::OtherFocusReason)
const QPoint & globalPos() const
Returns the global position of the mouse pointer at the time of the event.
Definition: qevent.h:413
void setTextWidth(qreal width)
bool gotFocus() const
Returns true if type() is QEvent::FocusIn; otherwise returns false.
Definition: qevent.h:281
iterator find(const Key &key)
Returns an iterator pointing to the item with the key in the hash.
Definition: qhash.h:865
iterator insertMulti(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition: qhash.h:772
int columnSpan() const
Returns the number of columns this cell spans.
Definition: qtexttable.cpp:228
void insertHtml(const QString &text)
The QInputContext class abstracts the input method dependent data and composing state.
Definition: qinputcontext.h:83
void cursorPositionChanged()
QVector< Selection > selections
the collection of selections that will be rendered when passing this paint context to QAbstractTextDo...
QTextCharFormat format
A format that is used to specify a foreground or background brush/color for the selection.
Definition: qtextedit.h:225
void insertHtml(const QString &html)
Inserts the text html at the current position().
void deleteChar()
If there is no selected text, deletes the character at the current cursor position; otherwise deletes...
QTextFragment fragment() const
Returns the text fragment the iterator currently points to.
bool cursorIsFocusIndicator() const
Qt::KeyboardModifiers modifiers() const
Returns the keyboard modifier flags that existed immediately before the event occurred.
Definition: qevent.h:79
void mouseReleaseEvent(QEvent *e, Qt::MouseButton button, const QPointF &pos, Qt::KeyboardModifiers modifiers, Qt::MouseButtons buttons, const QPoint &globalPos)
void selectionChanged(bool forceEmitSelectionChanged=false)
Q_TESTLIB_EXPORT QTestData & newRow(const char *dataTag)
Appends a new row to the current test data.
Definition: qtestcase.cpp:2183
void setStyle(Style style)
Sets the list format&#39;s style.
Definition: qtextformat.h:682
virtual void clear()
Clears the document.
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56
void setLayoutDirection(Qt::LayoutDirection direction)
Sets the document&#39;s layout direction to the specified direction.
Definition: qtextformat.h:338
void setUnderlineStyle(UnderlineStyle style)
Sets the style of underlining the text to style.
Type type() const
Returns the event type.
Definition: qcoreevent.h:303
void setPreeditArea(int position, const QString &text)
Sets the position and text of the area in the layout that is processed before editing occurs...
const QPoint & globalPos() const
Returns the global position of the mouse cursor at the time of the event.
Definition: qevent.h:96
static int doubleClickInterval()
QTextCursor selectedBlockOnTrippleClick
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
void setWordSelectionEnabled(bool enabled)
int indent() const
Returns the list format&#39;s indentation.
Definition: qtextformat.h:666
iterator erase(iterator it)
Removes the (key, value) pair associated with the iterator pos from the hash, and returns an iterator...
Definition: qhash.h:827
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
#define INT_MAX
qreal height() const
Returns the line&#39;s height.
QPointF anchorPosition(const QString &name) const
The QTextDocumentFragment class represents a piece of formatted text from a QTextDocument.
#define enabled
The QFocusEvent class contains event parameters for widget focus events.
Definition: qevent.h:275
int selectionStart() const
Returns the start of the selection or position() if the cursor doesn&#39;t have a selection.
The QAction class provides an abstract user interface action that can be inserted into widgets...
Definition: qaction.h:64
void start(int msec, QObject *obj)
Starts (or restarts) the timer with a msec milliseconds timeout.
QVariant variant
the variant for style hints that return a QVariant
Definition: qstyleoption.h:940
const struct QUnicodeControlCharacter qt_controlCharacters[NUM_CONTROL_CHARACTERS]
void showToolTip(const QPoint &globalPos, const QPointF &pos, QWidget *contextWidget)
The QTextEdit class provides a widget that is used to edit and display both plain and rich text...
Definition: qtextedit.h:70
int textStart() const
Returns the start of the line from the beginning of the string passed to the QTextLayout.
const QPoint & pos() const
Returns the position where the drop was made.
Definition: qevent.h:486
int open(const char *, int,...)
Qt::MouseButtons buttons() const
Returns the combination of mouse buttons that were pressed at the time the event was sent...
#define text
Definition: qobjectdefs.h:80
void repaintOldAndNewSelection(const QTextCursor &oldSelection)
int lineCount() const
Returns the number of lines in this text layout.
static void setup()
Definition: qtextcodec.cpp:718
void insertPlainText(const QString &text)
bool useDesignMetrics
whether the document uses design metrics of fonts to improve the accuracy of text layout ...
QPointF pos() const
Returns the mouse position of the event relative to the view that sent the event. ...
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
The QGraphicsSceneHoverEvent class provides hover events in the graphics view framework.
QWidget * target() const
Returns the target of the drag and drop operation.
Definition: qdrag.cpp:219
bool openExternalLinks() const
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the list...
Definition: qlist.h:272
static bool openUrl(const QUrl &url)
Opens the given url in the appropriate Web browser for the user&#39;s desktop environment, and returns true if successful; otherwise returns false.
QTextListFormat format() const
Returns the list&#39;s format.
Definition: qtextlist.h:80
void mergeCurrentCharFormat(const QTextCharFormat &modifier)
static void showText(const QPoint &pos, const QString &text, QWidget *w=0)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qtooltip.cpp:497
The QHelpEvent class provides an event that is used to request helpful information about a particular...
Definition: qevent.h:586
MouseButton
Definition: qnamespace.h:150
The QAbstractTextDocumentLayout class is an abstract base class used to implement custom layouts for ...
bool canPaste() const
void setExtraSelections(const QList< QTextEdit::ExtraSelection > &selections)
The QGraphicsSceneContextMenuEvent class provides context menu events in the graphics view framework...
void setOpenExternalLinks(bool open)
The QPalette class contains color groups for each widget state.
Definition: qpalette.h:61
QTextLayout * layout() const
Returns the QTextLayout that is used to lay out and display the block&#39;s contents. ...
const QPoint & pos() const
Returns the mouse cursor position when the event was generated, relative to the widget to which the e...
Definition: qevent.h:597