Qt 4.8
qplaintextedit.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 "qplaintextedit_p.h"
43 
44 
45 #include <qfont.h>
46 #include <qpainter.h>
47 #include <qevent.h>
48 #include <qdebug.h>
49 #include <qmime.h>
50 #include <qdrag.h>
51 #include <qclipboard.h>
52 #include <qmenu.h>
53 #include <qstyle.h>
54 #include <qtimer.h>
55 #include "private/qtextdocumentlayout_p.h"
56 #include "private/qabstracttextdocumentlayout_p.h"
57 #include "qtextdocument.h"
58 #include "private/qtextdocument_p.h"
59 #include "qtextlist.h"
60 #include "private/qtextcontrol_p.h"
61 #include "qaccessible.h"
62 
63 #include <qtextformat.h>
64 #include <qdatetime.h>
65 #include <qapplication.h>
66 #include <limits.h>
67 #include <qtexttable.h>
68 #include <qvariant.h>
69 #include <qinputcontext.h>
70 
71 #ifndef QT_NO_TEXTEDIT
72 
74 
75 static inline bool shouldEnableInputMethod(QPlainTextEdit *plaintextedit)
76 {
77  return !plaintextedit->isReadOnly();
78 }
79 
81 {
83 public:
85  mainViewPrivate = 0;
86  width = 0;
87  maximumWidth = 0;
89  blockCount = 1;
91  cursorWidth = 1;
92  textLayoutFlags = 0;
93  }
94 
104 
105  void layoutBlock(const QTextBlock &block);
106  qreal blockWidth(const QTextBlock &block);
107 
108  void relayout();
109 };
110 
111 
112 
144 }
149 
150 
155 {
156 }
157 
162 {
163 // this function is used from
164 // QAbstractTextDocumentLayout::anchorAt(), but is not
165 // implementable in a plain text document layout, because the
166 // layout depends on the top block and top line which depends on
167 // the view
168  return -1;
169 }
170 
175 { return 1; }
176 
181 {
183  return QSizeF(d->maximumWidth, document()->lineCount());
184 }
185 
190 {
192  return QRectF(0, 0, qMax(d->width, d->maximumWidth), qreal(INT_MAX));
193 }
194 
199 {
200  if (!block.isValid()) { return QRectF(); }
201  QTextLayout *tl = block.layout();
202  if (!tl->lineCount())
203  const_cast<QPlainTextDocumentLayout*>(this)->layoutBlock(block);
204  QRectF br;
205  if (block.isVisible()) {
206  br = QRectF(QPointF(0, 0), tl->boundingRect().bottomRight());
207  if (tl->lineCount() == 1)
208  br.setWidth(qMax(br.width(), tl->lineAt(0).naturalTextWidth()));
209  qreal margin = document()->documentMargin();
210  br.adjust(0, 0, margin, 0);
211  if (!block.next().isValid())
212  br.adjust(0, 0, 0, margin);
213  }
214  return br;
215 
216 }
217 
222 {
223  if (!block.isValid())
224  return;
225  QTextLayout *tl = block.layout();
226  if (!tl->lineCount())
227  const_cast<QPlainTextDocumentLayout*>(this)->layoutBlock(block);
228 }
229 
230 
239 {
241  d->cursorWidth = width;
242 }
243 
245 {
247  return d->cursorWidth;
248 }
249 
251 {
253  return const_cast<QPlainTextDocumentLayoutPrivate*>(d);
254 }
255 
256 
262 {
263  emit update(QRectF(0., -document()->documentMargin(), 1000000000., 1000000000.));
264 }
265 
266 
268 {
270  d->width = d->maximumWidth = newWidth;
271  d->relayout();
272 }
273 
275 {
277  return d->width;
278 }
279 
281 {
283  QTextBlock block = q->document()->firstBlock();
284  while (block.isValid()) {
285  block.layout()->clearLayout();
286  block.setLineCount(block.isVisible() ? 1 : 0);
287  block = block.next();
288  }
289  emit q->update();
290 }
291 
292 
295 void QPlainTextDocumentLayout::documentChanged(int from, int /*charsRemoved*/, int charsAdded)
296 {
298  QTextDocument *doc = document();
299  int newBlockCount = doc->blockCount();
300 
301  QTextBlock changeStartBlock = doc->findBlock(from);
302  QTextBlock changeEndBlock = doc->findBlock(qMax(0, from + charsAdded - 1));
303 
304  if (changeStartBlock == changeEndBlock && newBlockCount == d->blockCount) {
305  QTextBlock block = changeStartBlock;
306  int blockLineCount = block.layout()->lineCount();
307  if (block.isValid() && blockLineCount) {
308  QRectF oldBr = blockBoundingRect(block);
309  layoutBlock(block);
310  QRectF newBr = blockBoundingRect(block);
311  if (newBr.height() == oldBr.height()) {
312  if (!d->blockUpdate)
313  emit updateBlock(block);
314  return;
315  }
316  }
317  } else {
318  QTextBlock block = changeStartBlock;
319  do {
320  block.clearLayout();
321  if (block == changeEndBlock)
322  break;
323  block = block.next();
324  } while(block.isValid());
325  }
326 
327  if (newBlockCount != d->blockCount) {
328 
329  int changeEnd = changeEndBlock.blockNumber();
330  int blockDiff = newBlockCount - d->blockCount;
331  int oldChangeEnd = changeEnd - blockDiff;
332 
333  if (d->maximumWidthBlockNumber > oldChangeEnd)
334  d->maximumWidthBlockNumber += blockDiff;
335 
336  d->blockCount = newBlockCount;
337  if (d->blockCount == 1)
338  d->maximumWidth = blockWidth(doc->firstBlock());
339 
340  if (!d->blockDocumentSizeChanged)
342 
343  if (blockDiff == 1 && changeEnd == newBlockCount -1 ) {
344  if (!d->blockUpdate) {
345  QTextBlock b = changeStartBlock;
346  for(;;) {
347  emit updateBlock(b);
348  if (b == changeEndBlock)
349  break;
350  b = b.next();
351  }
352  }
353  return;
354  }
355  }
356 
357  if (!d->blockUpdate)
358  emit update(QRectF(0., -doc->documentMargin(), 1000000000., 1000000000.)); // optimization potential
359 }
360 
361 
363 {
365  QTextDocument *doc = document();
366  qreal margin = doc->documentMargin();
367  qreal blockMaximumWidth = 0;
368 
369  qreal height = 0;
370  QTextLayout *tl = block.layout();
371  QTextOption option = doc->defaultTextOption();
372  tl->setTextOption(option);
373 
374  int extraMargin = 0;
376  QFontMetrics fm(block.charFormat().font());
377  extraMargin += fm.width(QChar(0x21B5));
378  }
379  tl->beginLayout();
380  qreal availableWidth = d->width;
381  if (availableWidth <= 0) {
382  availableWidth = qreal(INT_MAX); // similar to text edit with pageSize.width == 0
383  }
384  availableWidth -= 2*margin + extraMargin;
385  while (1) {
386  QTextLine line = tl->createLine();
387  if (!line.isValid())
388  break;
389  line.setLeadingIncluded(true);
390  line.setLineWidth(availableWidth);
391  line.setPosition(QPointF(margin, height));
392  height += line.height();
393  blockMaximumWidth = qMax(blockMaximumWidth, line.naturalTextWidth() + 2*margin);
394  }
395  tl->endLayout();
396 
397  int previousLineCount = doc->lineCount();
398  const_cast<QTextBlock&>(block).setLineCount(block.isVisible() ? tl->lineCount() : 0);
399  int lineCount = doc->lineCount();
400 
401  bool emitDocumentSizeChanged = previousLineCount != lineCount;
402  if (blockMaximumWidth > d->maximumWidth) {
403  // new longest line
404  d->maximumWidth = blockMaximumWidth;
405  d->maximumWidthBlockNumber = block.blockNumber();
406  emitDocumentSizeChanged = true;
407  } else if (block.blockNumber() == d->maximumWidthBlockNumber && blockMaximumWidth < d->maximumWidth) {
408  // longest line shrinking
409  QTextBlock b = doc->firstBlock();
410  d->maximumWidth = 0;
411  QTextBlock maximumBlock;
412  while (b.isValid()) {
413  qreal blockMaximumWidth = blockWidth(b);
414  if (blockMaximumWidth > d->maximumWidth) {
415  d->maximumWidth = blockMaximumWidth;
416  maximumBlock = b;
417  }
418  b = b.next();
419  }
420  if (maximumBlock.isValid()) {
421  d->maximumWidthBlockNumber = maximumBlock.blockNumber();
422  emitDocumentSizeChanged = true;
423  }
424  }
425  if (emitDocumentSizeChanged && !d->blockDocumentSizeChanged)
427 }
428 
430 {
431  QTextLayout *layout = block.layout();
432  if (!layout->lineCount())
433  return 0; // only for layouted blocks
434  qreal blockWidth = 0;
435  for (int i = 0; i < layout->lineCount(); ++i) {
436  QTextLine line = layout->lineAt(i);
437  blockWidth = qMax(line.naturalTextWidth() + 8, blockWidth);
438  }
439  return blockWidth;
440 }
441 
442 
444  : QTextControl(parent), textEdit(parent),
445  topBlock(0)
446 {
447  setAcceptRichText(false);
448 }
449 
451 {
452  pageUpDownLastCursorYIsValid = false;
453 #ifndef QT_NO_ACCESSIBILITY
456 #endif
457 }
458 
460  if (action == QAbstractSlider::SliderPageStepAdd) {
461  pageUpDown(QTextCursor::Down, QTextCursor::MoveAnchor, false);
462  } else if (action == QAbstractSlider::SliderPageStepSub) {
463  pageUpDown(QTextCursor::Up, QTextCursor::MoveAnchor, false);
464  }
465 }
466 
469  if (!ed)
471  return ed->createMimeDataFromSelection();
472  }
475  if (!ed)
477  return ed->canInsertFromMimeData(source);
478 }
481  if (!ed)
483  else
484  ed->insertFromMimeData(source);
485 }
486 
488 {
489  qreal offset = 0;
490  QTextDocument *doc = control->document();
491 
492  if (topLine) {
493  QTextBlock currentBlock = doc->findBlockByNumber(topBlock);
495  Q_ASSERT(documentLayout);
496  QRectF r = documentLayout->blockBoundingRect(currentBlock);
497  Q_UNUSED(r);
498  QTextLayout *layout = currentBlock.layout();
499  if (layout && topLine <= layout->lineCount()) {
500  QTextLine line = layout->lineAt(topLine - 1);
501  const QRectF lr = line.naturalTextRect();
502  offset = lr.bottom();
503  }
504  }
505  if (topBlock == 0 && topLine == 0)
506  offset -= doc->documentMargin(); // top margin
507  return offset;
508 }
509 
510 
512  return verticalOffset(control->topBlock, topLine) + topLineFracture;
513 }
514 
515 
517 {
519 }
520 
521 
522 
524  int currentBlockNumber = topBlock;
525  QTextBlock currentBlock = document()->findBlockByNumber(currentBlockNumber);
526  if (!currentBlock.isValid())
527  return -1;
528 
530  Q_ASSERT(documentLayout);
531 
532  QPointF offset;
533  QRectF r = documentLayout->blockBoundingRect(currentBlock);
534  while (currentBlock.next().isValid() && r.bottom() + offset.y() <= point.y()) {
535  offset.ry() += r.height();
536  currentBlock = currentBlock.next();
537  ++currentBlockNumber;
538  r = documentLayout->blockBoundingRect(currentBlock);
539  }
540  while (currentBlock.previous().isValid() && r.top() + offset.y() > point.y()) {
541  offset.ry() -= r.height();
542  currentBlock = currentBlock.previous();
543  --currentBlockNumber;
544  r = documentLayout->blockBoundingRect(currentBlock);
545  }
546 
547 
548  if (!currentBlock.isValid())
549  return -1;
550  QTextLayout *layout = currentBlock.layout();
551  int off = 0;
552  QPointF pos = point - offset;
553  for (int i = 0; i < layout->lineCount(); ++i) {
554  QTextLine line = layout->lineAt(i);
555  const QRectF lr = line.naturalTextRect();
556  if (lr.top() > pos.y()) {
557  off = qMin(off, line.textStart());
558  } else if (lr.bottom() <= pos.y()) {
559  off = qMax(off, line.textStart() + line.textLength());
560  } else {
561  off = line.xToCursor(pos.x(), overwriteMode() ?
563  break;
564  }
565  }
566 
567  return currentBlock.position() + off;
568 }
569 
571  int currentBlockNumber = topBlock;
572  int blockNumber = block.blockNumber();
573  QTextBlock currentBlock = document()->findBlockByNumber(currentBlockNumber);
574  if (!currentBlock.isValid())
575  return QRectF();
576  Q_ASSERT(currentBlock.blockNumber() == currentBlockNumber);
577  QTextDocument *doc = document();
578  QPlainTextDocumentLayout *documentLayout = qobject_cast<QPlainTextDocumentLayout*>(doc->documentLayout());
579  Q_ASSERT(documentLayout);
580 
581  QPointF offset;
582  if (!block.isValid())
583  return QRectF();
584  QRectF r = documentLayout->blockBoundingRect(currentBlock);
585  int maxVerticalOffset = r.height();
586  while (currentBlockNumber < blockNumber && offset.y() - maxVerticalOffset <= 2* textEdit->viewport()->height()) {
587  offset.ry() += r.height();
588  currentBlock = currentBlock.next();
589  ++currentBlockNumber;
590  if (!currentBlock.isVisible()) {
591  currentBlock = doc->findBlockByLineNumber(currentBlock.firstLineNumber());
592  currentBlockNumber = currentBlock.blockNumber();
593  }
594  r = documentLayout->blockBoundingRect(currentBlock);
595  }
596  while (currentBlockNumber > blockNumber && offset.y() + maxVerticalOffset >= -textEdit->viewport()->height()) {
597  currentBlock = currentBlock.previous();
598  --currentBlockNumber;
599  while (!currentBlock.isVisible()) {
600  currentBlock = currentBlock.previous();
601  --currentBlockNumber;
602  }
603  if (!currentBlock.isValid())
604  break;
605 
606  r = documentLayout->blockBoundingRect(currentBlock);
607  offset.ry() -= r.height();
608  }
609 
610  if (currentBlockNumber != blockNumber) {
611  // fallback for blocks out of reach. Give it some geometry at
612  // least, and ensure the layout is up to date.
613  r = documentLayout->blockBoundingRect(block);
614  if (currentBlockNumber > blockNumber)
615  offset.ry() -= r.height();
616  }
617  r.translate(offset);
618  return r;
619 }
620 
621 
622 void QPlainTextEditPrivate::setTopLine(int visualTopLine, int dx)
623 {
624  QTextDocument *doc = control->document();
625  QTextBlock block = doc->findBlockByLineNumber(visualTopLine);
626  int blockNumber = block.blockNumber();
627  int lineNumber = visualTopLine - block.firstLineNumber();
628  setTopBlock(blockNumber, lineNumber, dx);
629 }
630 
631 void QPlainTextEditPrivate::setTopBlock(int blockNumber, int lineNumber, int dx)
632 {
634  blockNumber = qMax(0, blockNumber);
635  lineNumber = qMax(0, lineNumber);
636  QTextDocument *doc = control->document();
637  QTextBlock block = doc->findBlockByNumber(blockNumber);
638 
639  int newTopLine = block.firstLineNumber() + lineNumber;
640  int maxTopLine = vbar->maximum();
641 
642  if (newTopLine > maxTopLine) {
643  block = doc->findBlockByLineNumber(maxTopLine);
644  blockNumber = block.blockNumber();
645  lineNumber = maxTopLine - block.firstLineNumber();
646  }
647 
648  bool vbarSignalsBlocked = vbar->blockSignals(true);
649  vbar->setValue(newTopLine);
650  vbar->blockSignals(vbarSignalsBlocked);
651 
652  if (!dx && blockNumber == control->topBlock && lineNumber == topLine)
653  return;
654 
655  if (viewport->updatesEnabled() && viewport->isVisible()) {
656  int dy = 0;
657  if (doc->findBlockByNumber(control->topBlock).isValid()) {
658  qreal realdy = -q->blockBoundingGeometry(block).y()
659  + verticalOffset() - verticalOffset(blockNumber, lineNumber);
660  dy = (int)realdy;
661  topLineFracture = realdy - dy;
662  }
663  control->topBlock = blockNumber;
664  topLine = lineNumber;
665 
666  bool vbarSignalsBlocked = vbar->blockSignals(true);
667  vbar->setValue(block.firstLineNumber() + lineNumber);
668  vbar->blockSignals(vbarSignalsBlocked);
669 
670  if (dx || dy) {
671  viewport->scroll(q->isRightToLeft() ? -dx : dx, dy);
672  } else {
673  viewport->update();
674  topLineFracture = 0;
675  }
676  emit q->updateRequest(viewport->rect(), dy);
677  } else {
678  control->topBlock = blockNumber;
679  topLine = lineNumber;
680  topLineFracture = 0;
681  }
682 
683 }
684 
685 
686 
687 void QPlainTextEditPrivate::ensureVisible(int position, bool center, bool forceCenter) {
689  QRectF visible = QRectF(viewport->rect()).translated(-q->contentOffset());
690  QTextBlock block = control->document()->findBlock(position);
691  if (!block.isValid())
692  return;
693  QRectF br = control->blockBoundingRect(block);
694  if (!br.isValid())
695  return;
696  QRectF lr = br;
697  QTextLine line = block.layout()->lineForTextPosition(position - block.position());
698  Q_ASSERT(line.isValid());
699  lr = line.naturalTextRect().translated(br.topLeft());
700 
701  if (lr.bottom() >= visible.bottom() || (center && lr.top() < visible.top()) || forceCenter){
702 
703  qreal height = visible.height();
704  if (center)
705  height /= 2;
706 
707  qreal h = center ? line.naturalTextRect().center().y() : line.naturalTextRect().bottom();
708 
709  QTextBlock previousVisibleBlock = block;
710  while (h < height && block.previous().isValid()) {
711  previousVisibleBlock = block;
712  do {
713  block = block.previous();
714  } while (!block.isVisible() && block.previous().isValid());
715  h += q->blockBoundingRect(block).height();
716  }
717 
718  int l = 0;
719  int lineCount = block.layout()->lineCount();
720  qreal voffset = verticalOffset(block.blockNumber(), 0);
721  while (l < lineCount) {
722  QRectF lineRect = block.layout()->lineAt(l).naturalTextRect();
723  if (h - voffset - lineRect.top() <= height)
724  break;
725  ++l;
726  }
727 
728  if (l >= lineCount) {
729  block = previousVisibleBlock;
730  l = 0;
731  }
732  setTopBlock(block.blockNumber(), l);
733  } else if (lr.top() < visible.top()) {
734  setTopBlock(block.blockNumber(), line.lineNumber());
735  }
736 
737 }
738 
739 
741 {
743  viewport->update();
744  emit q->updateRequest(viewport->rect(), 0);
745 }
746 
748  : control(0),
749  tabChangesFocus(false),
750  lineWrap(QPlainTextEdit::WidgetWidth),
751  wordWrap(QTextOption::WrapAtWordBoundaryOrAnywhere),
752  clickCausedFocus(0),topLine(0),topLineFracture(0),
753  pageUpDownLastCursorYIsValid(false)
754 {
756  backgroundVisible = false;
757  centerOnScroll = false;
758  inDrag = false;
759 }
760 
761 
763 {
766 
767  QTextDocument *doc = new QTextDocument(control);
769  doc->setDocumentLayout(layout);
770  control->setDocument(doc);
771 
772  control->setPalette(q->palette());
773 
774  QObject::connect(vbar, SIGNAL(actionTriggered(int)), q, SLOT(_q_verticalScrollbarActionTriggered(int)));
775 
776  QObject::connect(control, SIGNAL(microFocusChanged()), q, SLOT(updateMicroFocus()));
777  QObject::connect(control, SIGNAL(documentSizeChanged(QSizeF)), q, SLOT(_q_adjustScrollbars()));
778  QObject::connect(control, SIGNAL(blockCountChanged(int)), q, SIGNAL(blockCountChanged(int)));
780  QObject::connect(control, SIGNAL(modificationChanged(bool)), q, SIGNAL(modificationChanged(bool)));
781 
782  QObject::connect(control, SIGNAL(textChanged()), q, SIGNAL(textChanged()));
783  QObject::connect(control, SIGNAL(undoAvailable(bool)), q, SIGNAL(undoAvailable(bool)));
784  QObject::connect(control, SIGNAL(redoAvailable(bool)), q, SIGNAL(redoAvailable(bool)));
785  QObject::connect(control, SIGNAL(copyAvailable(bool)), q, SIGNAL(copyAvailable(bool)));
786  QObject::connect(control, SIGNAL(selectionChanged()), q, SIGNAL(selectionChanged()));
787  QObject::connect(control, SIGNAL(cursorPositionChanged()), q, SLOT(_q_cursorPositionChanged()));
788  QObject::connect(control, SIGNAL(cursorPositionChanged()), q, SIGNAL(cursorPositionChanged()));
789 
790  QObject::connect(control, SIGNAL(textChanged()), q, SLOT(updateMicroFocus()));
791 
792  // set a null page size initially to avoid any relayouting until the textedit
793  // is shown. relayoutDocument() will take care of setting the page size to the
794  // viewport dimensions later.
795  doc->setTextWidth(-1);
797  doc->setDefaultFont(q->font());
798 
799 
800  if (!txt.isEmpty())
801  control->setPlainText(txt);
802 
803  hbar->setSingleStep(20);
804  vbar->setSingleStep(1);
805 
807  q->setAcceptDrops(true);
808  q->setFocusPolicy(Qt::WheelFocus);
809  q->setAttribute(Qt::WA_KeyCompression);
810  q->setAttribute(Qt::WA_InputMethodEnabled);
811 
812 #ifndef QT_NO_CURSOR
814 #endif
815  originalOffsetY = 0;
816 #ifdef Q_WS_WIN
818 #endif
819 }
820 
822 {
824  if (!contentsRect.isValid()) {
825  updateViewport();
826  return;
827  }
828  const int xOffset = horizontalOffset();
829  const int yOffset = (int)verticalOffset();
830  const QRect visibleRect(xOffset, yOffset, viewport->width(), viewport->height());
831 
832  QRect r = contentsRect.adjusted(-1, -1, 1, 1).intersected(visibleRect).toAlignedRect();
833  if (r.isEmpty())
834  return;
835 
836  r.translate(-xOffset, -yOffset);
837  viewport->update(r);
838  emit q->updateRequest(r, 0);
839 }
840 
842 {
843 
845 
846  QTextCursor cursor = control->textCursor();
847  if (moveCursor) {
851  }
852 
854 
855 
856  if (op == QTextCursor::Down) {
857  QRectF visible = QRectF(viewport->rect()).translated(-q->contentOffset());
858  QTextBlock firstVisibleBlock = q->firstVisibleBlock();
859  QTextBlock block = firstVisibleBlock;
860  QRectF br = q->blockBoundingRect(block);
861  qreal h = 0;
862  int atEnd = false;
863  while (h + br.height() <= visible.bottom()) {
864  if (!block.next().isValid()) {
865  atEnd = true;
866  lastY = visible.bottom(); // set cursor to last line
867  break;
868  }
869  h += br.height();
870  block = block.next();
871  br = q->blockBoundingRect(block);
872  }
873 
874  if (!atEnd) {
875  int line = 0;
876  qreal diff = visible.bottom() - h;
877  int lineCount = block.layout()->lineCount();
878  while (line < lineCount - 1) {
879  if (block.layout()->lineAt(line).naturalTextRect().bottom() > diff) {
880  // the first line that did not completely fit the screen
881  break;
882  }
883  ++line;
884  }
885  setTopBlock(block.blockNumber(), line);
886  }
887 
888  if (moveCursor) {
889  // move using movePosition to keep the cursor's x
890  lastY += verticalOffset();
891  bool moved = false;
892  do {
893  moved = cursor.movePosition(op, moveMode);
894  } while (moved && control->cursorRect(cursor).top() < lastY);
895  }
896 
897  } else if (op == QTextCursor::Up) {
898 
899  QRectF visible = QRectF(viewport->rect()).translated(-q->contentOffset());
900  visible.translate(0, -visible.height()); // previous page
901  QTextBlock block = q->firstVisibleBlock();
902  qreal h = 0;
903  while (h >= visible.top()) {
904  if (!block.previous().isValid()) {
905  if (control->topBlock == 0 && topLine == 0) {
906  lastY = 0; // set cursor to first line
907  }
908  break;
909  }
910  block = block.previous();
911  QRectF br = q->blockBoundingRect(block);
912  h -= br.height();
913  }
914 
915  int line = 0;
916  if (block.isValid()) {
917  qreal diff = visible.top() - h;
918  int lineCount = block.layout()->lineCount();
919  while (line < lineCount) {
920  if (block.layout()->lineAt(line).naturalTextRect().top() >= diff)
921  break;
922  ++line;
923  }
924  if (line == lineCount) {
925  if (block.next().isValid() && block.next() != q->firstVisibleBlock()) {
926  block = block.next();
927  line = 0;
928  } else {
929  --line;
930  }
931  }
932  }
933  setTopBlock(block.blockNumber(), line);
934 
935  if (moveCursor) {
936  cursor.setVisualNavigation(true);
937  // move using movePosition to keep the cursor's x
938  lastY += verticalOffset();
939  bool moved = false;
940  do {
941  moved = cursor.movePosition(op, moveMode);
942  } while (moved && control->cursorRect(cursor).top() > lastY);
943  }
944  }
945 
946  if (moveCursor) {
947  control->setTextCursor(cursor);
949  }
950 }
951 
952 #ifndef QT_NO_SCROLLBAR
953 
955 {
957  QTextDocument *doc = control->document();
959  Q_ASSERT(documentLayout);
960  bool documentSizeChangedBlocked = documentLayout->priv()->blockDocumentSizeChanged;
961  documentLayout->priv()->blockDocumentSizeChanged = true;
962  qreal margin = doc->documentMargin();
963 
964  int vmax = 0;
965 
966  int vSliderLength = 0;
967  if (!centerOnScroll && q->isVisible()) {
968  QTextBlock block = doc->lastBlock();
969  const qreal visible = viewport->rect().height() - margin - 1;
970  qreal y = 0;
971  int visibleFromBottom = 0;
972 
973  while (block.isValid()) {
974  if (!block.isVisible()) {
975  block = block.previous();
976  continue;
977  }
978  y += documentLayout->blockBoundingRect(block).height();
979 
980  QTextLayout *layout = block.layout();
981  int layoutLineCount = layout->lineCount();
982  if (y > visible) {
983  int lineNumber = 0;
984  while (lineNumber < layoutLineCount) {
985  QTextLine line = layout->lineAt(lineNumber);
986  const QRectF lr = line.naturalTextRect();
987  if (lr.top() >= y - visible)
988  break;
989  ++lineNumber;
990  }
991  if (lineNumber < layoutLineCount)
992  visibleFromBottom += (layoutLineCount - lineNumber);
993  break;
994 
995  }
996  visibleFromBottom += layoutLineCount;
997  block = block.previous();
998  }
999  vmax = qMax(0, doc->lineCount() - visibleFromBottom);
1000  vSliderLength = visibleFromBottom;
1001 
1002  } else {
1003  vmax = qMax(0, doc->lineCount() - 1);
1004  vSliderLength = viewport->height() / q->fontMetrics().lineSpacing();
1005  }
1006 
1007 
1008 
1009  QSizeF documentSize = documentLayout->documentSize();
1010  vbar->setRange(0, qMax(0, vmax));
1011  vbar->setPageStep(vSliderLength);
1012  int visualTopLine = vmax;
1013  QTextBlock firstVisibleBlock = q->firstVisibleBlock();
1014  if (firstVisibleBlock.isValid())
1015  visualTopLine = firstVisibleBlock.firstLineNumber() + topLine;
1016  bool vbarSignalsBlocked = vbar->blockSignals(true);
1017  vbar->setValue(visualTopLine);
1018  vbar->blockSignals(vbarSignalsBlocked);
1019 
1020  hbar->setRange(0, (int)documentSize.width() - viewport->width());
1022  documentLayout->priv()->blockDocumentSizeChanged = documentSizeChangedBlocked;
1023  setTopLine(vbar->value());
1024 }
1025 
1026 #endif
1027 
1028 
1030 {
1031 }
1032 
1246 {
1248  d->init();
1249 }
1250 
1255  : QAbstractScrollArea(dd, parent)
1256 {
1258  d->init();
1259 }
1260 
1267 {
1269  d->init(text);
1270 }
1271 
1272 
1277 {
1279  if (d->documentLayoutPtr) {
1280  if (d->documentLayoutPtr->priv()->mainViewPrivate == d)
1281  d->documentLayoutPtr->priv()->mainViewPrivate = 0;
1282  }
1283 }
1284 
1298 {
1300  QPlainTextDocumentLayout *documentLayout = 0;
1301 
1302  if (!document) {
1303  document = new QTextDocument(d->control);
1304  documentLayout = new QPlainTextDocumentLayout(document);
1305  document->setDocumentLayout(documentLayout);
1306  } else {
1307  documentLayout = qobject_cast<QPlainTextDocumentLayout*>(document->documentLayout());
1308  if (!documentLayout) {
1309  qWarning("QPlainTextEdit::setDocument: Document set does not support QPlainTextDocumentLayout");
1310  return;
1311  }
1312  }
1313  d->control->setDocument(document);
1314  if (!documentLayout->priv()->mainViewPrivate)
1315  documentLayout->priv()->mainViewPrivate = d;
1316  d->documentLayoutPtr = documentLayout;
1317  d->updateDefaultTextOption();
1318  d->relayoutDocument();
1319  d->_q_adjustScrollbars();
1320 }
1321 
1328 {
1329  Q_D(const QPlainTextEdit);
1330  return d->control->document();
1331 }
1332 
1337 {
1339  d->control->setTextCursor(cursor);
1340 }
1341 
1348 {
1349  Q_D(const QPlainTextEdit);
1350  return d->control->textCursor();
1351 }
1352 
1360 {
1361  Q_D(const QPlainTextEdit);
1362  int cursorPos = d->control->hitTest(pos + QPointF(d->horizontalOffset(),
1363  d->verticalOffset()),
1364  Qt::ExactHit);
1365  if (cursorPos < 0)
1366  return QString();
1367 
1368  QTextDocumentPrivate *pieceTable = document()->docHandle();
1369  QTextDocumentPrivate::FragmentIterator it = pieceTable->find(cursorPos);
1370  QTextCharFormat fmt = pieceTable->formatCollection()->charFormat(it->format);
1371  return fmt.anchorHref();
1372 }
1373 
1383 {
1385  d->control->undo();
1386 }
1387 
1389 {
1391  d->control->redo();
1392 }
1393 
1408 #ifndef QT_NO_CLIPBOARD
1409 
1419 {
1421  d->control->cut();
1422 }
1423 
1431 {
1433  d->control->copy();
1434 }
1435 
1451 {
1453  d->control->paste();
1454 }
1455 #endif
1456 
1465 {
1467  // clears and sets empty content
1468  d->control->topBlock = d->topLine = d->topLineFracture = 0;
1469  d->control->clear();
1470 }
1471 
1472 
1479 {
1481  d->control->selectAll();
1482 }
1483 
1487 {
1489 
1490 #ifndef QT_NO_CONTEXTMENU
1491  if (e->type() == QEvent::ContextMenu
1492  && static_cast<QContextMenuEvent *>(e)->reason() == QContextMenuEvent::Keyboard) {
1494  const QPoint cursorPos = cursorRect().center();
1495  QContextMenuEvent ce(QContextMenuEvent::Keyboard, cursorPos, d->viewport->mapToGlobal(cursorPos));
1496  ce.setAccepted(e->isAccepted());
1497  const bool result = QAbstractScrollArea::event(&ce);
1498  e->setAccepted(ce.isAccepted());
1499  return result;
1500  }
1501 #endif // QT_NO_CONTEXTMENU
1502  if (e->type() == QEvent::ShortcutOverride
1503  || e->type() == QEvent::ToolTip) {
1504  d->sendControlEvent(e);
1505  }
1506 #ifdef QT_KEYPAD_NAVIGATION
1507  else if (e->type() == QEvent::EnterEditFocus || e->type() == QEvent::LeaveEditFocus) {
1508  if (QApplication::keypadNavigationEnabled())
1509  d->sendControlEvent(e);
1510  }
1511 #endif
1512 #ifndef QT_NO_GESTURES
1513  else if (e->type() == QEvent::Gesture) {
1514  QGestureEvent *ge = static_cast<QGestureEvent *>(e);
1515  QPanGesture *g = static_cast<QPanGesture *>(ge->gesture(Qt::PanGesture));
1516  if (g) {
1517  QScrollBar *hBar = horizontalScrollBar();
1518  QScrollBar *vBar = verticalScrollBar();
1519  if (g->state() == Qt::GestureStarted)
1520  d->originalOffsetY = vBar->value();
1521  QPointF offset = g->offset();
1522  if (!offset.isNull()) {
1524  offset.rx() *= -1;
1525  // QPlainTextEdit scrolls by lines only in vertical direction
1526  QFontMetrics fm(document()->defaultFont());
1527  int lineHeight = fm.height();
1528  int newX = hBar->value() - g->delta().x();
1529  int newY = d->originalOffsetY - offset.y()/lineHeight;
1530  hBar->setValue(newX);
1531  vBar->setValue(newY);
1532  }
1533  }
1534  return true;
1535  }
1536 #endif // QT_NO_GESTURES
1537  return QAbstractScrollArea::event(e);
1538 }
1539 
1544 {
1546  if (e->timerId() == d->autoScrollTimer.timerId()) {
1547  QRect visible = d->viewport->rect();
1548  QPoint pos;
1549  if (d->inDrag) {
1550  pos = d->autoScrollDragPos;
1551  visible.adjust(qMin(visible.width()/3,20), qMin(visible.height()/3,20),
1552  -qMin(visible.width()/3,20), -qMin(visible.height()/3,20));
1553  } else {
1554  const QPoint globalPos = QCursor::pos();
1555  pos = d->viewport->mapFromGlobal(globalPos);
1557  mouseMoveEvent(&ev);
1558  }
1559  int deltaY = qMax(pos.y() - visible.top(), visible.bottom() - pos.y()) - visible.height();
1560  int deltaX = qMax(pos.x() - visible.left(), visible.right() - pos.x()) - visible.width();
1561  int delta = qMax(deltaX, deltaY);
1562  if (delta >= 0) {
1563  if (delta < 7)
1564  delta = 7;
1565  int timeout = 4900 / (delta * delta);
1566  d->autoScrollTimer.start(timeout, this);
1567 
1568  if (deltaY > 0)
1569  d->vbar->triggerAction(pos.y() < visible.center().y() ?
1572  if (deltaX > 0)
1573  d->hbar->triggerAction(pos.x() < visible.center().x() ?
1576  }
1577  }
1578 #ifdef QT_KEYPAD_NAVIGATION
1579  else if (e->timerId() == d->deleteAllTimer.timerId()) {
1580  d->deleteAllTimer.stop();
1581  clear();
1582  }
1583 #endif
1584 }
1585 
1598 {
1600  d->control->setPlainText(text);
1601 }
1602 
1617 {
1619 
1620 #ifdef QT_KEYPAD_NAVIGATION
1621  switch (e->key()) {
1622  case Qt::Key_Select:
1623  if (QApplication::keypadNavigationEnabled()) {
1624  if (!(d->control->textInteractionFlags() & Qt::LinksAccessibleByKeyboard))
1625  setEditFocus(!hasEditFocus());
1626  else {
1627  if (!hasEditFocus())
1628  setEditFocus(true);
1629  else {
1630  QTextCursor cursor = d->control->textCursor();
1631  QTextCharFormat charFmt = cursor.charFormat();
1632  if (!cursor.hasSelection() || charFmt.anchorHref().isEmpty()) {
1633  setEditFocus(false);
1634  }
1635  }
1636  }
1637  }
1638  break;
1639  case Qt::Key_Back:
1640  case Qt::Key_No:
1641  if (!QApplication::keypadNavigationEnabled()
1642  || (QApplication::keypadNavigationEnabled() && !hasEditFocus())) {
1643  e->ignore();
1644  return;
1645  }
1646  break;
1647  default:
1648  if (QApplication::keypadNavigationEnabled()) {
1649  if (!hasEditFocus() && !(e->modifiers() & Qt::ControlModifier)) {
1650  if (e->text()[0].isPrint()) {
1651  setEditFocus(true);
1652  clear();
1653  } else {
1654  e->ignore();
1655  return;
1656  }
1657  }
1658  }
1659  break;
1660  }
1661 #endif
1662 
1663 #ifndef QT_NO_SHORTCUT
1664 
1665  Qt::TextInteractionFlags tif = d->control->textInteractionFlags();
1666 
1667  if (tif & Qt::TextSelectableByKeyboard){
1669  e->accept();
1671  return;
1672  } else if (e ==QKeySequence::SelectNextPage) {
1673  e->accept();
1675  return;
1676  }
1677  }
1678  if (tif & (Qt::TextSelectableByKeyboard | Qt::TextEditable)) {
1680  e->accept();
1682  return;
1683  } else if (e == QKeySequence::MoveToNextPage) {
1684  e->accept();
1686  return;
1687  }
1688  }
1689 
1690  if (!(tif & Qt::TextEditable)) {
1691  switch (e->key()) {
1692  case Qt::Key_Space:
1693  e->accept();
1694  if (e->modifiers() & Qt::ShiftModifier)
1695  d->vbar->triggerAction(QAbstractSlider::SliderPageStepSub);
1696  else
1697  d->vbar->triggerAction(QAbstractSlider::SliderPageStepAdd);
1698  break;
1699  default:
1700  d->sendControlEvent(e);
1701  if (!e->isAccepted() && e->modifiers() == Qt::NoModifier) {
1702  if (e->key() == Qt::Key_Home) {
1703  d->vbar->triggerAction(QAbstractSlider::SliderToMinimum);
1704  e->accept();
1705  } else if (e->key() == Qt::Key_End) {
1706  d->vbar->triggerAction(QAbstractSlider::SliderToMaximum);
1707  e->accept();
1708  }
1709  }
1710  if (!e->isAccepted()) {
1712  }
1713  }
1714  return;
1715  }
1716 #endif // QT_NO_SHORTCUT
1717 
1718  d->sendControlEvent(e);
1719 #ifdef QT_KEYPAD_NAVIGATION
1720  if (!e->isAccepted()) {
1721  switch (e->key()) {
1722  case Qt::Key_Up:
1723  case Qt::Key_Down:
1724  if (QApplication::keypadNavigationEnabled()) {
1725  // Cursor position didn't change, so we want to leave
1726  // these keys to change focus.
1727  e->ignore();
1728  return;
1729  }
1730  break;
1731  case Qt::Key_Left:
1732  case Qt::Key_Right:
1733  if (QApplication::keypadNavigationEnabled()
1734  && QApplication::navigationMode() == Qt::NavigationModeKeypadDirectional) {
1735  // Same as for Key_Up and Key_Down.
1736  e->ignore();
1737  return;
1738  }
1739  break;
1740  case Qt::Key_Back:
1741  if (!e->isAutoRepeat()) {
1742  if (QApplication::keypadNavigationEnabled()) {
1743  if (document()->isEmpty()) {
1744  setEditFocus(false);
1745  e->accept();
1746  } else if (!d->deleteAllTimer.isActive()) {
1747  e->accept();
1748  d->deleteAllTimer.start(750, this);
1749  }
1750  } else {
1751  e->ignore();
1752  return;
1753  }
1754  }
1755  break;
1756  default: break;
1757  }
1758  }
1759 #endif
1760 }
1761 
1765 {
1766 #ifdef QT_KEYPAD_NAVIGATION
1768  if (QApplication::keypadNavigationEnabled()) {
1769  if (!e->isAutoRepeat() && e->key() == Qt::Key_Back
1770  && d->deleteAllTimer.isActive()) {
1771  d->deleteAllTimer.stop();
1772  QTextCursor cursor = d->control->textCursor();
1773  QTextBlockFormat blockFmt = cursor.blockFormat();
1774 
1775  QTextList *list = cursor.currentList();
1776  if (list && cursor.atBlockStart()) {
1777  list->remove(cursor.block());
1778  } else if (cursor.atBlockStart() && blockFmt.indent() > 0) {
1779  blockFmt.setIndent(blockFmt.indent() - 1);
1780  cursor.setBlockFormat(blockFmt);
1781  } else {
1782  cursor.deletePreviousChar();
1783  }
1784  setTextCursor(cursor);
1785  }
1786  }
1787 #else
1788  Q_UNUSED(e);
1789 #endif
1790 }
1791 
1800 {
1801  Q_UNUSED(type);
1802  Q_UNUSED(name);
1803  return QVariant();
1804 }
1805 
1809 {
1811  if (e->oldSize().width() != e->size().width())
1812  d->relayoutDocument();
1813  d->_q_adjustScrollbars();
1814 }
1815 
1817 {
1818  QTextDocument *doc = control->document();
1820  Q_ASSERT(documentLayout);
1821  documentLayoutPtr = documentLayout;
1822 
1823  int width = viewport->width();
1824 
1825  if (documentLayout->priv()->mainViewPrivate == 0
1826  || documentLayout->priv()->mainViewPrivate == this
1827  || width > documentLayout->textWidth()) {
1828  documentLayout->priv()->mainViewPrivate = this;
1829  documentLayout->setTextWidth(width);
1830  }
1831 }
1832 
1833 static void fillBackground(QPainter *p, const QRectF &rect, QBrush brush, QRectF gradientRect = QRectF())
1834 {
1835  p->save();
1836  if (brush.style() >= Qt::LinearGradientPattern && brush.style() <= Qt::ConicalGradientPattern) {
1837  if (!gradientRect.isNull()) {
1838  QTransform m = QTransform::fromTranslate(gradientRect.left(), gradientRect.top());
1839  m.scale(gradientRect.width(), gradientRect.height());
1840  brush.setTransform(m);
1841  const_cast<QGradient *>(brush.gradient())->setCoordinateMode(QGradient::LogicalMode);
1842  }
1843  } else {
1844  p->setBrushOrigin(rect.topLeft());
1845  }
1846  p->fillRect(rect, brush);
1847  p->restore();
1848 }
1849 
1850 
1851 
1855 {
1856  QPainter painter(viewport());
1857  Q_ASSERT(qobject_cast<QPlainTextDocumentLayout*>(document()->documentLayout()));
1858 
1859  QPointF offset(contentOffset());
1860 
1861  QRect er = e->rect();
1862  QRect viewportRect = viewport()->rect();
1863 
1864  bool editable = !isReadOnly();
1865 
1866  QTextBlock block = firstVisibleBlock();
1868 
1869  // Set a brush origin so that the WaveUnderline knows where the wave started
1870  painter.setBrushOrigin(offset);
1871 
1872  // keep right margin clean from full-width selection
1873  int maxX = offset.x() + qMax((qreal)viewportRect.width(), maximumWidth)
1874  - document()->documentMargin();
1875  er.setRight(qMin(er.right(), maxX));
1876  painter.setClipRect(er);
1877 
1878 
1880 
1881  while (block.isValid()) {
1882 
1883  QRectF r = blockBoundingRect(block).translated(offset);
1884  QTextLayout *layout = block.layout();
1885 
1886  if (!block.isVisible()) {
1887  offset.ry() += r.height();
1888  block = block.next();
1889  continue;
1890  }
1891 
1892  if (r.bottom() >= er.top() && r.top() <= er.bottom()) {
1893 
1894  QTextBlockFormat blockFormat = block.blockFormat();
1895 
1896  QBrush bg = blockFormat.background();
1897  if (bg != Qt::NoBrush) {
1898  QRectF contentsRect = r;
1899  contentsRect.setWidth(qMax(r.width(), maximumWidth));
1900  fillBackground(&painter, contentsRect, bg);
1901  }
1902 
1903 
1905  int blpos = block.position();
1906  int bllen = block.length();
1907  for (int i = 0; i < context.selections.size(); ++i) {
1908  const QAbstractTextDocumentLayout::Selection &range = context.selections.at(i);
1909  const int selStart = range.cursor.selectionStart() - blpos;
1910  const int selEnd = range.cursor.selectionEnd() - blpos;
1911  if (selStart < bllen && selEnd > 0
1912  && selEnd > selStart) {
1914  o.start = selStart;
1915  o.length = selEnd - selStart;
1916  o.format = range.format;
1917  selections.append(o);
1919  && block.contains(range.cursor.position())) {
1920  // for full width selections we don't require an actual selection, just
1921  // a position to specify the line. that's more convenience in usage.
1923  QTextLine l = layout->lineForTextPosition(range.cursor.position() - blpos);
1924  o.start = l.textStart();
1925  o.length = l.textLength();
1926  if (o.start + o.length == bllen - 1)
1927  ++o.length; // include newline
1928  o.format = range.format;
1929  selections.append(o);
1930  }
1931  }
1932 
1933  bool drawCursor = ((editable || (textInteractionFlags() & Qt::TextSelectableByKeyboard))
1934  && context.cursorPosition >= blpos
1935  && context.cursorPosition < blpos + bllen);
1936 
1937  bool drawCursorAsBlock = drawCursor && overwriteMode() ;
1938 
1939  if (drawCursorAsBlock) {
1940  if (context.cursorPosition == blpos + bllen - 1) {
1941  drawCursorAsBlock = false;
1942  } else {
1944  o.start = context.cursorPosition - blpos;
1945  o.length = 1;
1948  selections.append(o);
1949  }
1950  }
1951 
1952 
1953  layout->draw(&painter, offset, selections, er);
1954  if ((drawCursor && !drawCursorAsBlock)
1955  || (editable && context.cursorPosition < -1
1956  && !layout->preeditAreaText().isEmpty())) {
1957  int cpos = context.cursorPosition;
1958  if (cpos < -1)
1959  cpos = layout->preeditAreaPosition() - (cpos + 2);
1960  else
1961  cpos -= blpos;
1962  layout->drawCursor(&painter, offset, cpos, cursorWidth());
1963  }
1964  }
1965 
1966  offset.ry() += r.height();
1967  if (offset.y() > viewportRect.height())
1968  break;
1969  block = block.next();
1970  }
1971 
1972  if (backgroundVisible() && !block.isValid() && offset.y() <= er.bottom()
1974  painter.fillRect(QRect(QPoint((int)er.left(), (int)offset.y()), er.bottomRight()), palette().background());
1975  }
1976 }
1977 
1978 
1980 {
1981  QTextDocument *doc = control->document();
1982 
1983  QTextOption opt = doc->defaultTextOption();
1984  QTextOption::WrapMode oldWrapMode = opt.wrapMode();
1985 
1986  if (lineWrap == QPlainTextEdit::NoWrap)
1988  else
1989  opt.setWrapMode(wordWrap);
1990 
1991  if (opt.wrapMode() != oldWrapMode)
1992  doc->setDefaultTextOption(opt);
1993 }
1994 
1995 
1999 {
2001 #ifdef QT_KEYPAD_NAVIGATION
2002  if (QApplication::keypadNavigationEnabled() && !hasEditFocus())
2003  setEditFocus(true);
2004 #endif
2005  d->sendControlEvent(e);
2006 }
2007 
2011 {
2013  d->inDrag = false; // paranoia
2014  const QPoint pos = e->pos();
2015  d->sendControlEvent(e);
2016  if (!(e->buttons() & Qt::LeftButton))
2017  return;
2018  QRect visible = d->viewport->rect();
2019  if (visible.contains(pos))
2020  d->autoScrollTimer.stop();
2021  else if (!d->autoScrollTimer.isActive())
2022  d->autoScrollTimer.start(100, this);
2023 }
2024 
2028 {
2030  d->sendControlEvent(e);
2031  if (d->autoScrollTimer.isActive()) {
2032  d->autoScrollTimer.stop();
2033  d->ensureCursorVisible();
2034  }
2035 
2036  if (!isReadOnly() && rect().contains(e->pos()))
2037  d->handleSoftwareInputPanel(e->button(), d->clickCausedFocus);
2038  d->clickCausedFocus = 0;
2039 }
2040 
2044 {
2046  d->sendControlEvent(e);
2047 }
2048 
2052 {
2053  Q_D(const QPlainTextEdit);
2054  if (!d->tabChangesFocus && d->control->textInteractionFlags() & Qt::TextEditable)
2055  return false;
2057 }
2058 
2059 #ifndef QT_NO_CONTEXTMENU
2060 
2076 {
2078  d->sendControlEvent(e);
2079 }
2080 #endif // QT_NO_CONTEXTMENU
2081 
2082 #ifndef QT_NO_DRAGANDDROP
2083 
2086 {
2088  d->inDrag = true;
2089  d->sendControlEvent(e);
2090 }
2091 
2095 {
2097  d->inDrag = false;
2098  d->autoScrollTimer.stop();
2099  d->sendControlEvent(e);
2100 }
2101 
2105 {
2107  d->autoScrollDragPos = e->pos();
2108  if (!d->autoScrollTimer.isActive())
2109  d->autoScrollTimer.start(100, this);
2110  d->sendControlEvent(e);
2111 }
2112 
2116 {
2118  d->inDrag = false;
2119  d->autoScrollTimer.stop();
2120  d->sendControlEvent(e);
2121 }
2122 
2123 #endif // QT_NO_DRAGANDDROP
2124 
2128 {
2130 #ifdef QT_KEYPAD_NAVIGATION
2131  if (d->control->textInteractionFlags() & Qt::TextEditable
2132  && QApplication::keypadNavigationEnabled()
2133  && !hasEditFocus()) {
2134  setEditFocus(true);
2135  selectAll(); // so text is replaced rather than appended to
2136  }
2137 #endif
2138  d->sendControlEvent(e);
2140 }
2141 
2144 void QPlainTextEdit::scrollContentsBy(int dx, int /*dy*/)
2145 {
2147  d->setTopLine(d->vbar->value(), dx);
2148 }
2149 
2153 {
2154  Q_D(const QPlainTextEdit);
2155  QVariant v = d->control->inputMethodQuery(property);
2156  const QPoint offset(-d->horizontalOffset(), -0);
2157  if (v.type() == QVariant::RectF)
2158  v = v.toRectF().toRect().translated(offset);
2159  else if (v.type() == QVariant::PointF)
2160  v = v.toPointF().toPoint() + offset;
2161  else if (v.type() == QVariant::Rect)
2162  v = v.toRect().translated(offset);
2163  else if (v.type() == QVariant::Point)
2164  v = v.toPoint() + offset;
2165  return v;
2166 }
2167 
2171 {
2173  if (e->reason() == Qt::MouseFocusReason) {
2174  d->clickCausedFocus = 1;
2175  }
2177  d->sendControlEvent(e);
2178 }
2179 
2183 {
2186  d->sendControlEvent(e);
2187 }
2188 
2192 {
2194  if (d->showCursorOnInitialShow) {
2195  d->showCursorOnInitialShow = false;
2197  }
2198 }
2199 
2203 {
2207  || e->type() == QEvent::FontChange) {
2208  d->control->document()->setDefaultFont(font());
2209  } else if(e->type() == QEvent::ActivationChange) {
2210  if (!isActiveWindow())
2211  d->autoScrollTimer.stop();
2212  } else if (e->type() == QEvent::EnabledChange) {
2213  e->setAccepted(isEnabled());
2214  d->sendControlEvent(e);
2215  } else if (e->type() == QEvent::PaletteChange) {
2216  d->control->setPalette(palette());
2217  } else if (e->type() == QEvent::LayoutDirectionChange) {
2218  d->sendControlEvent(e);
2219  }
2220 }
2221 
2224 #ifndef QT_NO_WHEELEVENT
2226 {
2228  updateMicroFocus();
2229 }
2230 #endif
2231 
2232 #ifndef QT_NO_CONTEXTMENU
2233 
2240 {
2242  return d->control->createStandardContextMenu(QPointF(), this);
2243 }
2244 #endif // QT_NO_CONTEXTMENU
2245 
2250 {
2251  Q_D(const QPlainTextEdit);
2252  return d->control->cursorForPosition(d->mapToContents(pos));
2253 }
2254 
2260 {
2261  Q_D(const QPlainTextEdit);
2262  if (cursor.isNull())
2263  return QRect();
2264 
2265  QRect r = d->control->cursorRect(cursor).toRect();
2266  r.translate(-d->horizontalOffset(),-(int)d->verticalOffset());
2267  return r;
2268 }
2269 
2275 {
2276  Q_D(const QPlainTextEdit);
2277  QRect r = d->control->cursorRect().toRect();
2278  r.translate(-d->horizontalOffset(),-(int)d->verticalOffset());
2279  return r;
2280 }
2281 
2282 
2300 bool QPlainTextEdit::overwriteMode() const
2301 {
2302  Q_D(const QPlainTextEdit);
2303  return d->control->overwriteMode();
2304 }
2305 
2307 {
2309  d->control->setOverwriteMode(overwrite);
2310 }
2311 
2322 int QPlainTextEdit::tabStopWidth() const
2323 {
2324  Q_D(const QPlainTextEdit);
2325  return qRound(d->control->document()->defaultTextOption().tabStop());
2326 }
2327 
2329 {
2331  QTextOption opt = d->control->document()->defaultTextOption();
2332  if (opt.tabStop() == width || width < 0)
2333  return;
2334  opt.setTabStop(width);
2335  d->control->document()->setDefaultTextOption(opt);
2336 }
2337 
2346 int QPlainTextEdit::cursorWidth() const
2347 {
2348  Q_D(const QPlainTextEdit);
2349  return d->control->cursorWidth();
2350 }
2351 
2353 {
2355  d->control->setCursorWidth(width);
2356 }
2357 
2358 
2359 
2369 {
2371  d->control->setExtraSelections(selections);
2372 }
2373 
2380 {
2381  Q_D(const QPlainTextEdit);
2382  return d->control->extraSelections();
2383 }
2384 
2396 {
2397  Q_D(const QPlainTextEdit);
2398  return d->control->QTextControl::createMimeDataFromSelection();
2399 }
2400 
2408 {
2409  Q_D(const QPlainTextEdit);
2410  return d->control->QTextControl::canInsertFromMimeData(source);
2411 }
2412 
2421 {
2423  d->control->QTextControl::insertFromMimeData(source);
2424 }
2425 
2440 {
2441  Q_D(const QPlainTextEdit);
2442  return !(d->control->textInteractionFlags() & Qt::TextEditable);
2443 }
2444 
2446 {
2448  Qt::TextInteractionFlags flags = Qt::NoTextInteraction;
2449  if (ro) {
2450  flags = Qt::TextSelectableByMouse;
2451  } else {
2452  flags = Qt::TextEditorInteraction;
2453  }
2455  d->control->setTextInteractionFlags(flags);
2456 }
2457 
2473 void QPlainTextEdit::setTextInteractionFlags(Qt::TextInteractionFlags flags)
2474 {
2476  d->control->setTextInteractionFlags(flags);
2477 }
2478 
2479 Qt::TextInteractionFlags QPlainTextEdit::textInteractionFlags() const
2480 {
2481  Q_D(const QPlainTextEdit);
2482  return d->control->textInteractionFlags();
2483 }
2484 
2494 {
2496  d->control->mergeCurrentCharFormat(modifier);
2497 }
2498 
2506 {
2508  d->control->setCurrentCharFormat(format);
2509 }
2510 
2515 {
2516  Q_D(const QPlainTextEdit);
2517  return d->control->currentCharFormat();
2518 }
2519 
2520 
2521 
2531 {
2533  d->control->insertPlainText(text);
2534 }
2535 
2536 
2547 {
2549  d->control->moveCursor(operation, mode);
2550 }
2551 
2556 {
2557  Q_D(const QPlainTextEdit);
2558  return d->control->canPaste();
2559 }
2560 
2561 #ifndef QT_NO_PRINTER
2562 
2569 void QPlainTextEdit::print(QPrinter *printer) const
2570 {
2571  Q_D(const QPlainTextEdit);
2572  d->control->print(printer);
2573 }
2574 #endif // QT _NO_PRINTER
2575 
2589 {
2590  Q_D(const QPlainTextEdit);
2591  return d->tabChangesFocus;
2592 }
2593 
2595 {
2597  d->tabChangesFocus = b;
2598 }
2599 
2624 {
2625  Q_D(const QPlainTextEdit);
2626  return d->lineWrap;
2627 }
2628 
2630 {
2632  if (d->lineWrap == wrap)
2633  return;
2634  d->lineWrap = wrap;
2635  d->updateDefaultTextOption();
2636  d->relayoutDocument();
2637  d->_q_adjustScrollbars();
2639 }
2640 
2654 {
2655  Q_D(const QPlainTextEdit);
2656  return d->wordWrap;
2657 }
2658 
2660 {
2662  if (mode == d->wordWrap)
2663  return;
2664  d->wordWrap = mode;
2665  d->updateDefaultTextOption();
2666 }
2667 
2686 {
2687  Q_D(const QPlainTextEdit);
2688  return d->backgroundVisible;
2689 }
2690 
2692 {
2694  if (visible == d->backgroundVisible)
2695  return;
2696  d->backgroundVisible = visible;
2697  d->updateViewport();
2698 }
2699 
2720 bool QPlainTextEdit::centerOnScroll() const
2721 {
2722  Q_D(const QPlainTextEdit);
2723  return d->centerOnScroll;
2724 }
2725 
2727 {
2729  if (enabled == d->centerOnScroll)
2730  return;
2731  d->centerOnScroll = enabled;
2732 }
2733 
2734 
2735 
2741 bool QPlainTextEdit::find(const QString &exp, QTextDocument::FindFlags options)
2742 {
2744  return d->control->find(exp, options);
2745 }
2746 
2835 {
2837 
2838  QTextDocument *document = control->document();
2840  Q_ASSERT(documentLayout);
2841 
2842  int maximumBlockCount = document->maximumBlockCount();
2843  if (maximumBlockCount)
2844  document->setMaximumBlockCount(0);
2845 
2846  const bool atBottom = q->isVisible()
2847  && (control->blockBoundingRect(document->lastBlock()).bottom() - verticalOffset()
2848  <= viewport->rect().bottom());
2849 
2850  if (!q->isVisible())
2851  showCursorOnInitialShow = true;
2852 
2853  bool documentSizeChangedBlocked = documentLayout->priv()->blockDocumentSizeChanged;
2854  documentLayout->priv()->blockDocumentSizeChanged = true;
2855 
2856  if (format == Qt::RichText)
2857  control->appendHtml(text);
2858  else if (format == Qt::PlainText)
2859  control->appendPlainText(text);
2860  else
2861  control->append(text);
2862 
2863  if (maximumBlockCount > 0) {
2864  if (document->blockCount() > maximumBlockCount) {
2865  bool blockUpdate = false;
2866  if (control->topBlock) {
2867  control->topBlock--;
2868  blockUpdate = true;
2869  emit q->updateRequest(viewport->rect(), 0);
2870  }
2871 
2872  bool updatesBlocked = documentLayout->priv()->blockUpdate;
2873  documentLayout->priv()->blockUpdate = blockUpdate;
2874  QTextCursor cursor(document);
2876  cursor.removeSelectedText();
2877  documentLayout->priv()->blockUpdate = updatesBlocked;
2878  }
2879  document->setMaximumBlockCount(maximumBlockCount);
2880  }
2881 
2882  documentLayout->priv()->blockDocumentSizeChanged = documentSizeChangedBlocked;
2883  _q_adjustScrollbars();
2884 
2885 
2886  if (atBottom) {
2887  const bool needScroll = !centerOnScroll
2888  || control->blockBoundingRect(document->lastBlock()).bottom() - verticalOffset()
2889  > viewport->rect().bottom();
2890  if (needScroll)
2891  vbar->setValue(vbar->maximum());
2892  }
2893 }
2894 
2895 
2903 {
2905  d->append(text, Qt::PlainText);
2906 }
2907 
2915 {
2917  d->append(html, Qt::RichText);
2918 }
2919 
2921 {
2923  QRect visible = viewport->rect();
2924  QRect cr = q->cursorRect();
2925  if (cr.top() < visible.top() || cr.bottom() > visible.bottom()) {
2926  ensureVisible(control->textCursor().position(), center);
2927  }
2928 
2929  const bool rtl = q->isRightToLeft();
2930  if (cr.left() < visible.left() || cr.right() > visible.right()) {
2931  int x = cr.center().x() + horizontalOffset() - visible.width()/2;
2932  hbar->setValue(rtl ? hbar->maximum() - x : x);
2933  }
2934 }
2935 
2943 {
2945  d->ensureCursorVisible(d->centerOnScroll);
2946 }
2947 
2948 
2954 {
2956  d->ensureVisible(textCursor().position(), true, true);
2957 }
2958 
2965 {
2966  Q_D(const QPlainTextEdit);
2967  return d->control->firstVisibleBlock();
2968 }
2969 
2984 {
2985  Q_D(const QPlainTextEdit);
2986  return QPointF(-d->horizontalOffset(), -d->verticalOffset());
2987 }
2988 
2989 
2997 {
2998  Q_D(const QPlainTextEdit);
2999  return d->control->blockBoundingRect(block);
3000 }
3001 
3008 {
3010  Q_ASSERT(documentLayout);
3011  return documentLayout->blockBoundingRect(block);
3012 }
3013 
3023 int QPlainTextEdit::blockCount() const
3024 {
3025  return document()->blockCount();
3026 }
3027 
3032 {
3033  Q_D(const QPlainTextEdit);
3034  return d->control->getPaintContext(d->viewport);
3035 }
3036 
3090 
3091 #include "moc_qplaintextedit.cpp"
3092 #include "moc_qplaintextedit_p.cpp"
3093 
3094 #endif // QT_NO_TEXTEDIT
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
QPoint pos() const
T qobject_cast(QObject *object)
Definition: qobject.h:375
QPlainTextDocumentLayout(QTextDocument *document)
Constructs a plain text document layout for the text document.
virtual void dragMoveEvent(QDragMoveEvent *e)
Reimplemented Function
void requestUpdate()
Requests a complete update on all views.
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
QRect toAlignedRect() const
Returns a QRect based on the values of this rectangle that is the smallest possible integer rectangle...
Definition: qrect.cpp:2817
QPointF bottomRight() const
Returns the position of the rectangle&#39;s bottom-right corner.
Definition: qrect.h:540
QTextCharFormat charFormat(int index) const
Definition: qtextformat_p.h:85
void setTabStopWidth(int width)
QFont font() const
Returns the font for this character format.
bool enabled
whether the widget is enabled
Definition: qwidget.h:157
qreal blockWidth(const QTextBlock &block)
void setOverwriteMode(bool overwrite)
void setExtraSelections(const QList< QTextEdit::ExtraSelection > &selections)
This function allows temporarily marking certain regions in the document with a given color...
QRectF blockBoundingGeometry(const QTextBlock &block) const
Returns the bounding rectangle of the text block in content coordinates.
void ensureCursorVisible()
Ensures that the cursor is visible by scrolling the text edit if necessary.
static void updateAccessibility(QObject *, int who, Event reason)
Notifies accessibility clients about a change in object&#39;s accessibility information.
The QTextLayout::FormatRange structure is used to apply extra formatting information for a specified ...
Definition: qtextlayout.h:128
int width(const QString &, int len=-1) const
Returns the width in pixels of the first len characters of text.
bool blockSignals(bool b)
If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke...
Definition: qobject.cpp:1406
The QPanGesture class describes a panning gesture made by the user.
Definition: qgesture.h:107
bool find(const QString &exp, QTextDocument::FindFlags options=0)
Finds the next occurrence of the string, exp, using the given options.
The QKeyEvent class describes a key event.
Definition: qevent.h:224
void setPlainText(const QString &text)
void setTextInteractionFlags(Qt::TextInteractionFlags flags)
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
void _q_verticalScrollbarActionTriggered(int action)
void setCursorWidth(int width)
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
The QFontMetrics class provides font metrics information.
Definition: qfontmetrics.h:65
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
QPointF toPointF() const
Returns the variant as a QPointF if the variant has type() Point or PointF ; otherwise returns a null...
Definition: qvariant.cpp:2509
int lineCount() const
Returns the number of lines of this document (if the layout supports this).
void setPosition(const QPointF &pos)
Moves the line to position pos.
void layoutBlock(const QTextBlock &block)
QCursor cursor() const
bool isValid() const
Returns true if the rectangle is valid, otherwise returns false.
Definition: qrect.h:661
void centerCursor()
Scrolls the document in order to center the cursor vertically.
void documentChanged(int from, int, int charsAdded)
Reimplemented Function
void setLineCount(int count)
void setTextCursor(const QTextCursor &cursor)
QTextCharFormat format
the format of the selection
int width
the width of the widget excluding any window frame
Definition: qwidget.h:166
The QPlainTextDocumentLayout class implements a plain text layout for QTextDocument.
const QGradient * gradient() const
Returns the gradient describing this brush.
Definition: qbrush.cpp:871
#define it(className, varName)
int hitTest(const QPointF &, Qt::HitTestAccuracy) const
Reimplemented Function
QRect contentsRect() const
Returns the area inside the widget&#39;s margins.
Definition: qwidget.cpp:7544
bool isEmpty() const
Returns true if the document is empty; otherwise returns false.
int minimum() const
int blockCount
Returns the number of text blocks in the document.
void ensureCursorVisible(bool center=false)
The QWheelEvent class contains parameters that describe a wheel event.
Definition: qevent.h:139
The QContextMenuEvent class contains parameters that describe a context menu event.
Definition: qevent.h:396
The QTextFrame class represents a frame in a QTextDocument.
Definition: qtextobject.h:122
void setTransform(const QTransform &)
Sets matrix as an explicit transformation matrix on the current brush.
Definition: qbrush.cpp:968
QLayout * layout
Definition: qwidget_p.h:704
void setDocument(QTextDocument *document)
int maximumBlockCount
Specifies the limit for blocks in the document.
void undo()
Undoes the last operation.
const QBrush & background() const
Use window() instead.
Definition: qpalette.h:134
qreal width() const
Returns the width.
Definition: qsize.h:284
int selectionEnd() const
Returns the end of the selection or position() if the cursor doesn&#39;t have a selection.
QTextDocument * document() const
Returns a pointer to the underlying document.
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 setPalette(const QPalette &pal)
bool overwriteMode() const
virtual bool canInsertFromMimeData(const QMimeData *source) const
QString anchorAt(const QPoint &pos) const
Returns the reference of the anchor at position pos, or an empty string if no anchor exists at that p...
HitTestAccuracy
Definition: qtextdocument.h:78
void setAccepted(bool accepted)
Definition: qcoreevent.h:306
#define SLOT(a)
Definition: qobjectdefs.h:226
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
virtual void keyReleaseEvent(QKeyEvent *e)
Reimplemented Function
void setCurrentCharFormat(const QTextCharFormat &format)
Sets the char format that is be used when inserting new text to format by calling QTextCursor::setCha...
The QTextLine class represents a line of text inside a QTextLayout.
Definition: qtextlayout.h:197
void setPlainText(const QString &text)
Changes the text of the text edit to the string text.
void layoutBlock(const QTextBlock &block)
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
WrapMode
This enum describes how text is wrapped in a document.
Definition: qtextoption.h:102
int textLength() const
Returns the length of the text in the line.
int maximumBlockCount() const
void drawCursor(QPainter *p, const QPointF &pos, int cursorPosition) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
QPointF topLeft() const
Returns the position of the rectangle&#39;s top-left corner.
Definition: qrect.h:539
void _q_repaintContents(const QRectF &contentsRect)
Flags flags() const
Returns the flags associated with the option.
Definition: qtextoption.h:121
int left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:240
int blockCount() const
QTextBlockFormat blockFormat() const
Returns the block format of the block the cursor is in.
QRect translated(int dx, int dy) const
Returns a copy of the rectangle that is translated dx along the x axis and dy along the y axis...
Definition: qrect.h:328
QTextDocument * document() const
Returns the text document that this layout is operating on.
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
QRectF boundingRect() const
The smallest rectangle that contains all the lines in the layout.
QScrollBar * verticalScrollBar() const
Returns the vertical scroll bar.
virtual void scrollContentsBy(int dx, int dy)
em>Reimplemented Function
QTextCursor cursor
the selection&#39;s cursor
static QSize documentSize(QTextControl *control)
Definition: qtextedit.cpp:238
Qt::TextInteractionFlags textInteractionFlags() const
bool atBlockStart() const
Returns true if the cursor is at the start of a block; otherwise returns false.
The QAbstractScrollArea widget provides a scrolling area with on-demand scroll bars.
void setLineWidth(qreal width)
Lays out the line with the given width.
QString anchorHref() const
Returns the text format&#39;s hypertext link, or an empty string if none has been set.
Definition: qtextformat.h:506
QTextCursor textCursor() const
Returns a copy of the QTextCursor that represents the currently visible cursor.
virtual void mouseReleaseEvent(QMouseEvent *e)
Reimplemented Function
void setBackgroundVisible(bool visible)
int start
Specifies the beginning of the format range within the text layout&#39;s text.
Definition: qtextlayout.h:129
void setBackground(const QBrush &brush)
Sets the brush use to paint the document&#39;s background to the brush specified.
Definition: qtextformat.h:343
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
QRectF blockBoundingRect(const QTextBlock &block) const
bool isActiveWindow() const
The QUrl class provides a convenient interface for working with URLs.
Definition: qurl.h:61
QRectF intersected(const QRectF &other) const
Returns the intersection of this rectangle and the given rectangle.
Definition: qrect.h:818
int bottom() const
Returns the y-coordinate of the rectangle&#39;s bottom edge.
Definition: qrect.h:249
The QString class provides a Unicode character string.
Definition: qstring.h:83
T * qobject_cast(QObject *object)
Definition: qobject.h:375
QRectF toRectF() const
Returns the variant as a QRectF if the variant has type() Rect or RectF ; otherwise returns an invali...
Definition: qvariant.cpp:2463
virtual void keyPressEvent(QKeyEvent *e)
Reimplemented Function
The QDragMoveEvent class provides an event which is sent while a drag and drop action is in progress...
Definition: qevent.h:530
void setLineWrapMode(LineWrapMode mode)
void setWordWrapMode(QTextOption::WrapMode policy)
void clearLayout()
Clears the QTextLayout that is used to lay out and display the block&#39;s contents.
int indent() const
Returns the paragraph&#39;s indent.
Definition: qtextformat.h:590
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
void documentSizeChanged(const QSizeF &newSize)
This signal is emitted when the size of the document layout changes to newSize.
The QVector class is a template class that provides a dynamic array.
Definition: qdatastream.h:64
QPointF delta
the offset from the previous input position to the current input
Definition: qgesture.h:114
#define Q_D(Class)
Definition: qglobal.h:2482
QAbstractTextDocumentLayout::PaintContext getPaintContext() const
Returns the paint context for the viewport(), useful only when reimplementing paintEvent().
void print(QPrinter *printer) const
Convenience function to print the text edit&#39;s document to the given printer.
int cursorPosition
the position within the document, where the cursor line should be drawn.
void setBrushOrigin(int x, int y)
Sets the brush&#39;s origin to point (x, y).
Definition: qpainter.h:825
bool isValid() const
Returns true if this text line is valid; otherwise returns false.
Definition: qtextlayout.h:201
static const uint base
Definition: qurl.cpp:268
QRect cursorRect() const
returns a rectangle (in viewport coordinates) that includes the cursor of the text edit...
The QSizeF class defines the size of a two-dimensional object using floating point precision...
Definition: qsize.h:202
virtual void paintEvent(QPaintEvent *e)
Reimplemented Function
void update(const QRectF &=QRectF(0., 0., 1000000000., 1000000000.))
This signal is emitted when the rectangle rect has been updated.
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
virtual void insertFromMimeData(const QMimeData *source)
qreal tabStop() const
Returns the distance in device units between tab stops.
Definition: qtextoption.h:124
QTextCursor textCursor() const
virtual void dropEvent(QDropEvent *e)
Reimplemented Function
void save()
Saves the current painter state (pushes the state onto a stack).
Definition: qpainter.cpp:1590
virtual void focusOutEvent(QFocusEvent *)
This event handler can be reimplemented in a subclass to receive keyboard focus events (focus lost) f...
Definition: qwidget.cpp:9457
FragmentMap::ConstIterator FragmentIterator
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
void setRange(int min, int max)
Sets the slider&#39;s minimum to min and its maximum to max.
virtual ~QPlainTextEdit()
Destructor.
void setDefaultTextOption(const QTextOption &option)
Sets the default text option.
const QPoint & pos() const
Returns the position of the mouse cursor, relative to the widget that received the event...
Definition: qevent.h:95
virtual void wheelEvent(QWheelEvent *e)
Reimplemented Function
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
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 Q_Q(Class)
Definition: qglobal.h:2483
QPlainTextEdit * textEdit
QTextLine lineForTextPosition(int pos) const
Returns the line that contains the cursor position specified by pos.
QPointF offset
the total offset from the first input position to the current input position
Definition: qgesture.h:113
int position() const
Returns the index of the block&#39;s first character within the document.
static QCursor * moveCursor
Definition: qdnd_x11.cpp:254
virtual void mouseMoveEvent(QMouseEvent *e)
Reimplemented Function
void update()
Updates the widget unless updates are disabled or the widget is hidden.
Definition: qwidget.cpp:10883
QTextCursor cursorForPosition(const QPoint &pos) const
returns a QTextCursor at position pos (in viewport coordinates).
QTextBlock previous() const
Returns the text block in the document before this block, or an empty text block if this is the first...
void appendPlainText(const QString &text)
Appends a new paragraph with text to the end of the text edit.
void wheelEvent(QWheelEvent *)
This event handler can be reimplemented in a subclass to receive wheel events for the viewport() widg...
QSizeF documentSize() const
Reimplemented Function
QWidget * viewport() const
Returns the viewport widget.
The QAbstractTextDocumentLayout::Selection class is a convenience class defining the parameters of a ...
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
#define SIGNAL(a)
Definition: qobjectdefs.h:227
bool hasProperty(int propertyId) const
Returns true if the text format has a property with the given propertyId; otherwise returns false...
void redo()
Redoes the last operation.
int width() const
Returns the width.
Definition: qsize.h:126
The QScrollBar widget provides a vertical or horizontal scroll bar.
Definition: qscrollbar.h:59
void setBackgroundRole(QPalette::ColorRole)
Sets the background role of the widget to role.
Definition: qwidget.cpp:4708
virtual QMimeData * createMimeDataFromSelection() const
This function returns a new MIME data object to represent the contents of the text edit&#39;s current sel...
int value() const
bool isVisible() const
Returns true if the block is visible; otherwise returns false.
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
qreal & rx()
Returns a reference to the x coordinate of this point.
Definition: qpoint.h:302
FragmentIterator find(int pos) const
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 QGestureEvent class provides the description of triggered gestures.
Definition: qevent.h:841
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
void insertFromMimeData(const QMimeData *source)
bool isAccepted() const
Definition: qcoreevent.h:307
void updateBlock(const QTextBlock &block)
This signal is emitted when the specified block has been updated.
QPoint bottomRight() const
Returns the position of the rectangle&#39;s bottom-right corner.
Definition: qrect.h:291
void setCursorWidth(int width)
void insertPlainText(const QString &text)
Convenience slot that inserts text at the current cursor position.
bool visible
whether the widget is visible
Definition: qwidget.h:191
~QPlainTextDocumentLayout()
Destructs a plain text document layout.
void changeEvent(QEvent *)
This event handler can be reimplemented to handle state changes.
Definition: qframe.cpp:574
bool hasSelection() const
Returns true if the cursor contains a selection; otherwise returns false.
virtual bool canInsertFromMimeData(const QMimeData *source) const
This function returns true if the contents of the MIME data object, specified by source, can be decoded and inserted into the document.
int height
the height of the widget excluding any window frame
Definition: qwidget.h:167
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
void setTabChangesFocus(bool b)
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...
QTextDocumentPrivate * docHandle() const
So that not all classes have to be friends of each other.
bool isReadOnly() const
The QTextCursor class offers an API to access and modify QTextDocuments.
Definition: qtextcursor.h:70
int width() const
virtual QSizeF documentSize() const =0
Returns the total size of the document&#39;s layout.
QTextFormatCollection * formatCollection()
qreal height() const
Returns the height of the rectangle.
Definition: qrect.h:710
QMenu * createStandardContextMenu()
This function creates the standard context menu which is shown when the user clicks on the line edit ...
const char * name
The QPrinter class is a paint device that paints on a printer.
Definition: qprinter.h:66
int lineNumber() const
Returns the position of the line in the text engine.
Definition: qtextlayout.h:243
#define emit
Definition: qobjectdefs.h:76
Qt::GestureState state() const
const char * layout
void adjust(int x1, int y1, int x2, int y2)
Adds dx1, dy1, dx2 and dy2 respectively to the existing coordinates of the rectangle.
Definition: qrect.h:434
void setRight(int pos)
Sets the right edge of the rectangle to the given x coordinate.
Definition: qrect.h:264
const QPalette & palette() const
void appendHtml(const QString &html)
Appends a new paragraph with html to the end of the text edit.
void append(const T &t)
Inserts value at the end of the vector.
Definition: qvector.h:573
bool contains(int position) const
Returns true if the given position is located within the text block; otherwise returns false...
void draw(QPainter *, const PaintContext &)
Reimplemented Function
The QResizeEvent class contains event parameters for resize events.
Definition: qevent.h:349
QRectF blockBoundingRect(const QTextBlock &block) const
Returns the bounding rectangle of the text block in the block&#39;s own coordinates.
Q_CORE_EXPORT void qWarning(const char *,...)
int timerId() const
Returns the unique timer identifier, which is the same identifier as returned from QObject::startTime...
Definition: qcoreevent.h:346
QPlainTextEdit(QWidget *parent=0)
Constructs an empty QPlainTextEdit with parent parent.
The QTextBlock class provides a container for text fragments in a QTextDocument.
Definition: qtextobject.h:199
virtual QMimeData * createMimeDataFromSelection() const
static Bigint * diff(Bigint *a, Bigint *b)
void setMaximumBlockCount(int maximum)
The QPlainTextEdit class provides a widget that is used to edit and display plain text...
const QSize & oldSize() const
Returns the old size of the widget.
Definition: qevent.h:356
void ensureVisible(int position, bool center, bool forceCenter=false)
qreal width() const
Returns the width of the rectangle.
Definition: qrect.h:707
virtual void contextMenuEvent(QContextMenuEvent *e)
Shows the standard context menu created with createStandardContextMenu().
void setCursor(const QCursor &)
Definition: qwidget.cpp:5290
bool backgroundVisible() const
The QDragLeaveEvent class provides an event that is sent to a widget when a drag and drop action leav...
Definition: qevent.h:577
QPlainTextEditControl(QPlainTextEdit *parent)
void updateMicroFocus()
Updates the widget&#39;s micro focus.
Definition: qwidget.cpp:11820
void draw(QPainter *p, const QPointF &pos, const QVector< FormatRange > &selections=QVector< FormatRange >(), const QRectF &clip=QRectF()) const
Draws the whole layout on the painter p at the position specified by pos.
virtual void dragLeaveEvent(QDragLeaveEvent *e)
Reimplemented Function
int position() const
Returns the absolute position of the cursor within the document.
int length() const
Returns the length of the block in characters.
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
QRectF adjusted(qreal x1, qreal y1, qreal x2, qreal y2) const
Returns a new rectangle with dx1, dy1, dx2 and dy2 added respectively to the existing coordinates of ...
Definition: qrect.h:781
QRectF cursorRect(const QTextCursor &cursor) const
virtual void focusInEvent(QFocusEvent *e)
Reimplemented Function
The QShowEvent class provides an event that is sent when a widget is shown.
Definition: qevent.h:380
void setTopBlock(int newTopBlock, int newTopLine, int dx=0)
The QMimeData class provides a container for data that records information about its MIME type...
Definition: qmimedata.h:57
virtual void mousePressEvent(QMouseEvent *e)
Reimplemented Function
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
Qt::MouseButton button() const
Returns the button that caused the event.
Definition: qevent.h:101
QTextLine lineAt(int i) const
Returns the {i}-th line of text in this text layout.
QRect toRect() const
Returns a QRect based on the values of this rectangle.
Definition: qrect.h:845
void removeSelectedText()
If there is a selection, its content is deleted; otherwise does nothing.
QRect rect() const
void mergeCurrentCharFormat(const QTextCharFormat &modifier)
Merges the properties specified in modifier into the current character format by calling QTextCursor:...
QTextList * currentList() const
Returns the current list if the cursor position() is inside a block that is part of a list; otherwise...
QTextBlock findBlockByNumber(int blockNumber) const
Returns the text block with the specified blockNumber.
QTextCharFormat charFormat() const
Returns the QTextCharFormat that describes the block&#39;s character format.
bool contains(const QPoint &p, bool proper=false) const
Returns true if the given point is inside or on the edge of the rectangle, otherwise returns false...
Definition: qrect.cpp:1101
QTextBlock block() const
Returns the block that contains the cursor.
bool isEnabled() const
Definition: qwidget.h:948
int preeditAreaPosition() const
Returns the position of the area in the text layout that will be processed before editing occurs...
void setAcceptRichText(bool accept)
QTextOption::WrapMode wordWrapMode() const
the mode QPlainTextEdit will use when wrapping text by words
QTextDocument * document() const
TextFormat
Definition: qnamespace.h:1310
void setLeadingIncluded(bool included)
Includes positive leading into the line&#39;s height if included is true; otherwise does not include lead...
The QMouseEvent class contains parameters that describe a mouse event.
Definition: qevent.h:85
int firstLineNumber() const
Returns the first line number of this block, or -1 if the block is invalid.
Q_CORE_EXPORT QTextStream & center(QTextStream &s)
void cut()
Copies the selected text to the clipboard and deletes it from the text edit.
QTextBlock findBlockByLineNumber(int blockNumber) const
Returns the text block that contains the specified lineNumber.
void copy()
Copies any selected text to the clipboard.
InputMethodQuery
Definition: qnamespace.h:1541
The QBrush class defines the fill pattern of shapes drawn by QPainter.
Definition: qbrush.h:76
The QInputMethodEvent class provides parameters for input method events.
Definition: qevent.h:431
QPoint center() const
Returns the center point of the rectangle.
Definition: qrect.h:300
bool centerOnScroll() const
void setDefaultFont(const QFont &font)
Sets the default font to use in the document layout.
QPointF contentOffset() const
Returns the content&#39;s origin in viewport coordinates.
QString preeditAreaText() const
Returns the text that is inserted in the layout before editing occurs.
qreal verticalOffset() const
virtual bool event(QEvent *e)
int top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:243
The QTextLayout class is used to lay out and render text.
Definition: qtextlayout.h:105
QPlainTextEditPrivate * mainViewPrivate
void remove(const QTextBlock &)
Removes the given block from the list.
Definition: qtextlist.cpp:319
void paste()
Pastes the text from the clipboard into the text edit at the current cursor position.
#define Q_DECLARE_PUBLIC(Class)
Definition: qglobal.h:2477
bool overwriteMode() const
The QDropEvent class provides an event which is sent when a drag and drop action is completed...
Definition: qevent.h:476
virtual void focusOutEvent(QFocusEvent *e)
Reimplemented Function
QRectF frameBoundingRect(QTextFrame *) const
Reimplemented Function
Qt::MouseButtons buttons() const
Returns the button state when the event was generated.
Definition: qevent.h:102
int right() const
Returns the x-coordinate of the rectangle&#39;s right edge.
Definition: qrect.h:246
The QMenu class provides a menu widget for use in menu bars, context menus, and other popup menus...
Definition: qmenu.h:72
LineWrapMode lineWrapMode() const
int x() const
void pageUpDown(QTextCursor::MoveOperation op, QTextCursor::MoveMode moveMode, bool moveCursor=true)
void setTextWidth(qreal width)
The QTimerEvent class contains parameters that describe a timer event.
Definition: qcoreevent.h:341
void selectAll()
Selects all text.
void clear()
Deletes all the text in the text edit.
QRect rect
the internal geometry of the widget excluding any window frame
Definition: qwidget.h:168
QTextBlock findBlock(int pos) const
Returns the text block that contains the {pos}-th character.
The QGradient class is used in combination with QBrush to specify gradient fills. ...
Definition: qbrush.h:201
QString text() const
Returns the Unicode text that this key generated.
Definition: qevent.h:236
void moveCursor(QTextCursor::MoveOperation operation, QTextCursor::MoveMode mode=QTextCursor::MoveAnchor)
Moves the cursor by performing the given operation.
QRect toRect() const
Returns the variant as a QRect if the variant has type() Rect ; otherwise returns an invalid QRect...
Definition: qvariant.cpp:2416
const QSize & size() const
Returns the new size of the widget.
Definition: qevent.h:355
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
QMimeData * createMimeDataFromSelection() const
QTextLine createLine()
Returns a new text line to be laid out if there is text to be inserted into the layout; otherwise ret...
qreal naturalTextWidth() const
Returns the width of the line that is occupied by text.
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
Type type() const
Returns the storage type of the value stored in the variant.
Definition: qvariant.cpp:1901
void setTopLine(int visualTopLine, int dx=0)
void setTextOption(const QTextOption &option)
Sets the text option structure that controls the layout process to the given option.
int cursorWidth() const
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
QTextBlock firstVisibleBlock() const
The QDragEnterEvent class provides an event which is sent to a widget when a drag and drop action ent...
Definition: qevent.h:555
QPlainTextEditControl * control
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.
QTextCharFormat currentCharFormat() const
Returns the char format that is used when inserting new text.
static void fillBackground(QPainter *p, const QRectF &rect, QBrush brush, QRectF gradientRect=QRectF())
virtual bool focusNextPrevChild(bool next)
Finds a new widget to give the keyboard focus to, as appropriate for Tab and Shift+Tab, and returns true if it can find a new widget, or false if it can&#39;t.
Definition: qwidget.cpp:6836
void deletePreviousChar()
If there is no selected text, deletes the character before the current cursor position; otherwise del...
QScrollBar * horizontalScrollBar() const
Returns the horizontal scroll bar.
The QAbstractTextDocumentLayout::PaintContext class is a convenience class defining the parameters us...
The QTextBlockFormat class provides formatting information for blocks of text in a QTextDocument...
Definition: qtextformat.h:545
bool isNull() const
Returns true if the cursor is null; otherwise returns false.
virtual QVariant loadResource(int type, const QUrl &name)
Loads the resource specified by the given type and name.
QVariant inputMethodQuery(Qt::InputMethodQuery property) const
This method is only relevant for input widgets.
virtual void dragEnterEvent(QDragEnterEvent *e)
Reimplemented Function
QTextBlock lastBlock() const
Returns the document&#39;s last (valid) text block.
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
WrapMode wrapMode() const
Returns the text wrap mode defined by the option.
Definition: qtextoption.h:110
QFactoryLoader * l
QList< QTextEdit::ExtraSelection > extraSelections() const
Returns previously set extra selections.
bool isAutoRepeat() const
Returns true if this event comes from an auto-repeating key; returns false if it comes from an initia...
Definition: qevent.h:237
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
void setCenterOnScroll(bool enabled)
Qt::FocusReason reason()
Definition: qevent.cpp:1197
void setDocument(QTextDocument *document)
Makes document the new document of the text editor.
The QTextOption class provides a description of general rich text properties.
Definition: qtextoption.h:59
virtual void resizeEvent(QResizeEvent *e)
Reimplemented Function
qreal & ry()
Returns a reference to the y coordinate of this point.
Definition: qpoint.h:307
QPlainTextDocumentLayoutPrivate * priv() 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.
int y() const
Returns the y coordinate of this point.
Definition: qpoint.h:131
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
static bool shouldEnableInputMethod(QPlainTextEdit *plaintextedit)
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287
void setTextCursor(const QTextCursor &cursor)
Sets the visible cursor.
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
bool canInsertFromMimeData(const QMimeData *source) const
void clearLayout()
Clears the line information in the layout.
qreal documentMargin
The margin around the document.
The QTextDocument class holds formatted text that can be viewed and edited using a QTextEdit...
virtual void mouseDoubleClickEvent(QMouseEvent *e)
Reimplemented Function
QRectF blockBoundingRect(const QTextBlock &block) const
Reimplemented Function
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
bool event(QEvent *)
Reimplemented Function
int length
Specifies the numer of characters the format range spans.
Definition: qtextlayout.h:130
void setPaintDevice(QPaintDevice *device)
Sets the paint device used for rendering the document&#39;s layout to the given device.
QTextCharFormat format
Specifies the format to apply.
Definition: qtextlayout.h:131
QGesture * gesture(Qt::GestureType type) const
Returns a gesture object by type.
Definition: qevent.cpp:4881
int pageCount() const
Reimplemented Function
The QTextList class provides a decorated list of items in a QTextDocument.
Definition: qtextlist.h:57
void setWrapMode(WrapMode wrap)
Sets the option&#39;s text wrap mode to the given mode.
Definition: qtextoption.h:109
void setForeground(const QBrush &brush)
Sets the foreground brush to the specified brush.
Definition: qtextformat.h:350
QLayout * layout() const
Returns the layout manager that is installed on this widget, or 0 if no layout manager is installed...
Definition: qwidget.cpp:10073
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 QFont & font() const
bool canPaste() const
Returns whether text can be pasted from the clipboard into the textedit.
void setWidth(qreal w)
Sets the width of the rectangle to the given width.
Definition: qrect.h:784
static QTransform fromTranslate(qreal dx, qreal dy)
Creates a matrix which corresponds to a translation of dx along the x axis and dy along the y axis...
Definition: qtransform.cpp:462
void keyPressEvent(QKeyEvent *)
This function is called with key event e when key presses occur.
QTransform & scale(qreal sx, qreal sy)
Scales the coordinate system by sx horizontally and sy vertically, and returns a reference to the mat...
Definition: qtransform.cpp:485
virtual void timerEvent(QTimerEvent *e)
void setSingleFingerPanEnabled(bool on=true)
int x() const
Returns the x coordinate of this point.
Definition: qpoint.h:128
void setTextWidth(qreal newWidth)
int tabStopWidth() const
void endLayout()
Ends the layout process.
qreal bottom() const
Returns the y-coordinate of the rectangle&#39;s bottom edge.
Definition: qrect.h:528
virtual bool focusNextPrevChild(bool next)
Reimplemented Function
QVector< Selection > selections
the collection of selections that will be rendered when passing this paint context to QAbstractTextDo...
void setReadOnly(bool ro)
QRectF translated(qreal dx, qreal dy) const
Returns a copy of the rectangle that is translated dx along the x axis and dy along the y axis...
Definition: qrect.h:740
virtual void insertFromMimeData(const QMimeData *source)
This function inserts the contents of the MIME data object, specified by source, into the text edit a...
const QRect & rect() const
Returns the rectangle that needs to be updated.
Definition: qevent.h:305
int height() const
Returns the height of the font.
The QPaintEvent class contains event parameters for paint events.
Definition: qevent.h:298
int maximum() const
void translate(int dx, int dy)
Moves the rectangle dx along the x axis and dy along the y axis, relative to the current position...
Definition: qrect.h:312
QTextOption defaultTextOption() const
the default text option will be set on all QTextLayout in the document.
int xToCursor(qreal x, CursorPosition=CursorBetweenCharacters) const
Converts the x-coordinate x, to the nearest matching cursor position, depending on the cursor positio...
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56
Type type() const
Returns the event type.
Definition: qcoreevent.h:303
int hitTest(const QPointF &point, Qt::HitTestAccuracy=Qt::FuzzyHit) const
QPointF center() const
Returns the center point of the rectangle.
Definition: qrect.h:686
static bool isRightToLeft()
Returns true if the application&#39;s layout direction is Qt::RightToLeft; otherwise returns false...
Definition: qapplication.h:233
const QTextDocument * document() const
Returns the text document this text block belongs to, or 0 if the text block does not belong to any d...
#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
virtual void changeEvent(QEvent *e)
Reimplemented Function
virtual void focusInEvent(QFocusEvent *)
This event handler can be reimplemented in a subclass to receive keyboard focus events (focus receive...
Definition: qwidget.cpp:9431
#define INT_MAX
QTextBlockFormat blockFormat() const
Returns the QTextBlockFormat that describes block-specific properties.
qreal height() const
Returns the line&#39;s height.
bool tabChangesFocus() const
The QFocusEvent class contains event parameters for widget focus events.
Definition: qevent.h:275
QPoint toPoint() const
Returns the variant as a QPoint if the variant has type() Point or PointF ; otherwise returns a null ...
Definition: qvariant.cpp:2400
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203
virtual void showEvent(QShowEvent *)
Reimplemented Function
int selectionStart() const
Returns the start of the selection or position() if the cursor doesn&#39;t have a selection.
void setTabStop(qreal tabStop)
Sets the default distance in device units between tab stops to the value specified by tabStop...
Definition: qtextoption.h:154
void beginLayout()
Begins the layout process.
int blockNumber() const
Returns the number of this block, or -1 if the block is invalid.
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
void fillRect(const QRectF &, const QBrush &)
Fills the given rectangle with the brush specified.
Definition: qpainter.cpp:7420
#define text
Definition: qobjectdefs.h:80
void append(const QString &text, Qt::TextFormat format=Qt::AutoText)
static QPoint pos()
Returns the position of the cursor (hot spot) in global screen coordinates.
Definition: qcursor_mac.mm:310
int lineCount() const
Returns the number of lines in this text layout.
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
void setDocumentLayout(QAbstractTextDocumentLayout *layout)
Sets the document to use the given layout.
void ensureBlockLayout(const QTextBlock &block) const
Ensures that block has a valid layout.
QRectF naturalTextRect() const
Returns the rectangle covered by the line.
qreal blockWidth(const QTextBlock &block)
virtual void inputMethodEvent(QInputMethodEvent *)
Reimplemented Function
QTextBlock firstVisibleBlock() const
Returns the first visible block.
The QAbstractTextDocumentLayout class is an abstract base class used to implement custom layouts for ...
int maximumWidth() const
QTextLayout * layout() const
Returns the QTextLayout that is used to lay out and display the block&#39;s contents. ...
QTextBlock firstBlock() const
Returns the document&#39;s first text block.