55 #include "private/qtextdocumentlayout_p.h" 56 #include "private/qabstracttextdocumentlayout_p.h" 58 #include "private/qtextdocument_p.h" 60 #include "private/qtextcontrol_p.h" 71 #ifndef QT_NO_TEXTEDIT 203 const_cast<QPlainTextDocumentLayout*>(
this)->layoutBlock(block);
210 br.
adjust(0, 0, margin, 0);
212 br.
adjust(0, 0, 0, margin);
227 const_cast<QPlainTextDocumentLayout*>(
this)->layoutBlock(block);
241 d->cursorWidth = width;
247 return d->cursorWidth;
270 d->width =
d->maximumWidth = newWidth;
287 block = block.
next();
304 if (changeStartBlock == changeEndBlock && newBlockCount ==
d->blockCount) {
307 if (block.
isValid() && blockLineCount) {
321 if (block == changeEndBlock)
323 block = block.
next();
327 if (newBlockCount !=
d->blockCount) {
330 int blockDiff = newBlockCount -
d->blockCount;
331 int oldChangeEnd = changeEnd - blockDiff;
333 if (
d->maximumWidthBlockNumber > oldChangeEnd)
334 d->maximumWidthBlockNumber += blockDiff;
336 d->blockCount = newBlockCount;
337 if (
d->blockCount == 1)
340 if (!
d->blockDocumentSizeChanged)
343 if (blockDiff == 1 && changeEnd == newBlockCount -1 ) {
344 if (!
d->blockUpdate) {
348 if (b == changeEndBlock)
367 qreal blockMaximumWidth = 0;
380 qreal availableWidth =
d->width;
381 if (availableWidth <= 0) {
384 availableWidth -= 2*margin + extraMargin;
397 int previousLineCount = doc->
lineCount();
401 bool emitDocumentSizeChanged = previousLineCount != lineCount;
402 if (blockMaximumWidth >
d->maximumWidth) {
404 d->maximumWidth = blockMaximumWidth;
406 emitDocumentSizeChanged =
true;
407 }
else if (block.
blockNumber() ==
d->maximumWidthBlockNumber && blockMaximumWidth <
d->maximumWidth) {
414 if (blockMaximumWidth >
d->maximumWidth) {
415 d->maximumWidth = blockMaximumWidth;
421 d->maximumWidthBlockNumber = maximumBlock.
blockNumber();
422 emitDocumentSizeChanged =
true;
425 if (emitDocumentSizeChanged && !
d->blockDocumentSizeChanged)
435 for (
int i = 0; i < layout->
lineCount(); ++i) {
452 pageUpDownLastCursorYIsValid =
false;
453 #ifndef QT_NO_ACCESSIBILITY 499 if (layout && topLine <= layout->lineCount()) {
505 if (topBlock == 0 && topLine == 0)
512 return verticalOffset(control->topBlock, topLine) + topLineFracture;
536 currentBlock = currentBlock.
next();
537 ++currentBlockNumber;
542 currentBlock = currentBlock.
previous();
543 --currentBlockNumber;
553 for (
int i = 0; i < layout->
lineCount(); ++i) {
556 if (lr.
top() > pos.
y()) {
558 }
else if (lr.
bottom() <= pos.
y()) {
567 return currentBlock.
position() + off;
585 int maxVerticalOffset = r.
height();
586 while (currentBlockNumber < blockNumber && offset.
y() - maxVerticalOffset <= 2*
textEdit->
viewport()->
height()) {
588 currentBlock = currentBlock.
next();
589 ++currentBlockNumber;
591 currentBlock = doc->findBlockByLineNumber(currentBlock.
firstLineNumber());
596 while (currentBlockNumber > blockNumber && offset.
y() + maxVerticalOffset >= -
textEdit->
viewport()->
height()) {
597 currentBlock = currentBlock.
previous();
598 --currentBlockNumber;
600 currentBlock = currentBlock.
previous();
601 --currentBlockNumber;
610 if (currentBlockNumber != blockNumber) {
614 if (currentBlockNumber > blockNumber)
628 setTopBlock(blockNumber, lineNumber, dx);
634 blockNumber =
qMax(0, blockNumber);
635 lineNumber =
qMax(0, lineNumber);
640 int maxTopLine = vbar->maximum();
642 if (newTopLine > maxTopLine) {
648 bool vbarSignalsBlocked = vbar->blockSignals(
true);
649 vbar->setValue(newTopLine);
650 vbar->blockSignals(vbarSignalsBlocked);
652 if (!dx && blockNumber == control->topBlock && lineNumber == topLine)
655 if (viewport->updatesEnabled() && viewport->isVisible()) {
658 qreal realdy = -q->blockBoundingGeometry(block).y()
659 + verticalOffset() - verticalOffset(blockNumber, lineNumber);
661 topLineFracture = realdy - dy;
663 control->topBlock = blockNumber;
664 topLine = lineNumber;
666 bool vbarSignalsBlocked = vbar->blockSignals(
true);
668 vbar->blockSignals(vbarSignalsBlocked);
671 viewport->scroll(q->isRightToLeft() ? -dx : dx, dy);
676 emit q->updateRequest(viewport->rect(), dy);
678 control->topBlock = blockNumber;
679 topLine = lineNumber;
689 QRectF visible =
QRectF(viewport->rect()).translated(-q->contentOffset());
691 if (!block.isValid())
693 QRectF br = control->blockBoundingRect(block);
697 QTextLine line = block.layout()->lineForTextPosition(position - block.position());
701 if (lr.bottom() >= visible.
bottom() || (center && lr.top() < visible.
top()) || forceCenter){
710 while (h < height && block.previous().isValid()) {
711 previousVisibleBlock = block;
714 }
while (!block.isVisible() && block.previous().isValid());
715 h += q->blockBoundingRect(block).height();
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)
728 if (l >= lineCount) {
729 block = previousVisibleBlock;
732 setTopBlock(block.blockNumber(),
l);
733 }
else if (lr.top() < visible.
top()) {
734 setTopBlock(block.blockNumber(), line.
lineNumber());
744 emit q->updateRequest(viewport->rect(), 0);
749 tabChangesFocus(false),
751 wordWrap(
QTextOption::WrapAtWordBoundaryOrAnywhere),
752 clickCausedFocus(0),topLine(0),topLineFracture(0),
753 pageUpDownLastCursorYIsValid(false)
807 q->setAcceptDrops(
true);
838 emit q->updateRequest(r, 0);
858 QTextBlock firstVisibleBlock = q->firstVisibleBlock();
860 QRectF br = q->blockBoundingRect(block);
870 block = block.
next();
871 br = q->blockBoundingRect(block);
878 while (line < lineCount - 1) {
903 while (h >= visible.
top()) {
911 QRectF br = q->blockBoundingRect(block);
919 while (line < lineCount) {
924 if (line == lineCount) {
925 if (block.
next().
isValid() && block.
next() != q->firstVisibleBlock()) {
926 block = block.
next();
952 #ifndef QT_NO_SCROLLBAR 966 int vSliderLength = 0;
971 int visibleFromBottom = 0;
981 int layoutLineCount = layout->
lineCount();
984 while (lineNumber < layoutLineCount) {
987 if (lr.
top() >= y - visible)
991 if (lineNumber < layoutLineCount)
992 visibleFromBottom += (layoutLineCount - lineNumber);
996 visibleFromBottom += layoutLineCount;
1000 vSliderLength = visibleFromBottom;
1004 vSliderLength =
viewport->
height() / q->fontMetrics().lineSpacing();
1012 int visualTopLine = vmax;
1013 QTextBlock firstVisibleBlock = q->firstVisibleBlock();
1014 if (firstVisibleBlock.
isValid())
1279 if (
d->documentLayoutPtr) {
1280 if (
d->documentLayoutPtr->priv()->mainViewPrivate ==
d)
1281 d->documentLayoutPtr->priv()->mainViewPrivate = 0;
1308 if (!documentLayout) {
1309 qWarning(
"QPlainTextEdit::setDocument: Document set does not support QPlainTextDocumentLayout");
1313 d->control->setDocument(document);
1316 d->documentLayoutPtr = documentLayout;
1317 d->updateDefaultTextOption();
1318 d->relayoutDocument();
1319 d->_q_adjustScrollbars();
1330 return d->control->document();
1339 d->control->setTextCursor(cursor);
1350 return d->control->textCursor();
1362 int cursorPos =
d->control->hitTest(pos +
QPointF(
d->horizontalOffset(),
1363 d->verticalOffset()),
1408 #ifndef QT_NO_CLIPBOARD 1453 d->control->paste();
1468 d->control->topBlock =
d->topLine =
d->topLineFracture = 0;
1469 d->control->clear();
1481 d->control->selectAll();
1490 #ifndef QT_NO_CONTEXTMENU 1501 #endif // QT_NO_CONTEXTMENU 1504 d->sendControlEvent(e);
1506 #ifdef QT_KEYPAD_NAVIGATION 1507 else if (e->
type() == QEvent::EnterEditFocus || e->
type() == QEvent::LeaveEditFocus) {
1508 if (QApplication::keypadNavigationEnabled())
1509 d->sendControlEvent(e);
1512 #ifndef QT_NO_GESTURES 1520 d->originalOffsetY = vBar->
value();
1527 int lineHeight = fm.
height();
1529 int newY =
d->originalOffsetY - offset.
y()/lineHeight;
1536 #endif // QT_NO_GESTURES 1546 if (e->
timerId() ==
d->autoScrollTimer.timerId()) {
1550 pos =
d->autoScrollDragPos;
1555 pos =
d->viewport->mapFromGlobal(globalPos);
1561 int delta =
qMax(deltaX, deltaY);
1565 int timeout = 4900 / (delta * delta);
1566 d->autoScrollTimer.start(timeout,
this);
1569 d->vbar->triggerAction(pos.
y() < visible.
center().
y() ?
1573 d->hbar->triggerAction(pos.
x() < visible.
center().
x() ?
1578 #ifdef QT_KEYPAD_NAVIGATION 1579 else if (e->
timerId() ==
d->deleteAllTimer.timerId()) {
1580 d->deleteAllTimer.stop();
1600 d->control->setPlainText(text);
1620 #ifdef QT_KEYPAD_NAVIGATION 1623 if (QApplication::keypadNavigationEnabled()) {
1625 setEditFocus(!hasEditFocus());
1627 if (!hasEditFocus())
1633 setEditFocus(
false);
1641 if (!QApplication::keypadNavigationEnabled()
1642 || (QApplication::keypadNavigationEnabled() && !hasEditFocus())) {
1648 if (QApplication::keypadNavigationEnabled()) {
1650 if (e->
text()[0].isPrint()) {
1663 #ifndef QT_NO_SHORTCUT 1665 Qt::TextInteractionFlags tif =
d->control->textInteractionFlags();
1700 d->sendControlEvent(e);
1716 #endif // QT_NO_SHORTCUT 1718 d->sendControlEvent(e);
1719 #ifdef QT_KEYPAD_NAVIGATION 1724 if (QApplication::keypadNavigationEnabled()) {
1733 if (QApplication::keypadNavigationEnabled()
1742 if (QApplication::keypadNavigationEnabled()) {
1744 setEditFocus(
false);
1746 }
else if (!
d->deleteAllTimer.isActive()) {
1748 d->deleteAllTimer.start(750,
this);
1766 #ifdef QT_KEYPAD_NAVIGATION 1768 if (QApplication::keypadNavigationEnabled()) {
1770 &&
d->deleteAllTimer.isActive()) {
1771 d->deleteAllTimer.stop();
1812 d->relayoutDocument();
1813 d->_q_adjustScrollbars();
1821 documentLayoutPtr = documentLayout;
1827 || width > documentLayout->
textWidth()) {
1837 if (!gradientRect.isNull()) {
1839 m.
scale(gradientRect.width(), gradientRect.height());
1857 Q_ASSERT(qobject_cast<QPlainTextDocumentLayout*>(
document()->documentLayout()));
1888 block = block.
next();
1906 int bllen = block.
length();
1907 for (
int i = 0; i < context.
selections.size(); ++i) {
1911 if (selStart < bllen && selEnd > 0
1912 && selEnd > selStart) {
1915 o.
length = selEnd - selStart;
1939 if (drawCursorAsBlock) {
1941 drawCursorAsBlock =
false;
1953 layout->
draw(&painter, offset, selections, er);
1954 if ((drawCursor && !drawCursorAsBlock)
1967 if (offset.
y() > viewportRect.
height())
1969 block = block.
next();
2001 #ifdef QT_KEYPAD_NAVIGATION 2002 if (QApplication::keypadNavigationEnabled() && !hasEditFocus())
2005 d->sendControlEvent(e);
2015 d->sendControlEvent(e);
2020 d->autoScrollTimer.stop();
2021 else if (!
d->autoScrollTimer.isActive())
2022 d->autoScrollTimer.start(100,
this);
2030 d->sendControlEvent(e);
2031 if (
d->autoScrollTimer.isActive()) {
2032 d->autoScrollTimer.stop();
2033 d->ensureCursorVisible();
2037 d->handleSoftwareInputPanel(e->
button(),
d->clickCausedFocus);
2038 d->clickCausedFocus = 0;
2046 d->sendControlEvent(e);
2059 #ifndef QT_NO_CONTEXTMENU 2078 d->sendControlEvent(e);
2080 #endif // QT_NO_CONTEXTMENU 2082 #ifndef QT_NO_DRAGANDDROP 2089 d->sendControlEvent(e);
2098 d->autoScrollTimer.stop();
2099 d->sendControlEvent(e);
2107 d->autoScrollDragPos = e->
pos();
2108 if (!
d->autoScrollTimer.isActive())
2109 d->autoScrollTimer.start(100,
this);
2110 d->sendControlEvent(e);
2119 d->autoScrollTimer.stop();
2120 d->sendControlEvent(e);
2123 #endif // QT_NO_DRAGANDDROP 2130 #ifdef QT_KEYPAD_NAVIGATION 2132 && QApplication::keypadNavigationEnabled()
2133 && !hasEditFocus()) {
2138 d->sendControlEvent(e);
2147 d->setTopLine(
d->vbar->value(), dx);
2155 QVariant v =
d->control->inputMethodQuery(property);
2156 const QPoint offset(-
d->horizontalOffset(), -0);
2174 d->clickCausedFocus = 1;
2177 d->sendControlEvent(e);
2186 d->sendControlEvent(e);
2194 if (
d->showCursorOnInitialShow) {
2195 d->showCursorOnInitialShow =
false;
2208 d->control->document()->setDefaultFont(
font());
2211 d->autoScrollTimer.stop();
2214 d->sendControlEvent(e);
2218 d->sendControlEvent(e);
2224 #ifndef QT_NO_WHEELEVENT 2232 #ifndef QT_NO_CONTEXTMENU 2242 return d->control->createStandardContextMenu(
QPointF(),
this);
2244 #endif // QT_NO_CONTEXTMENU 2252 return d->control->cursorForPosition(
d->mapToContents(pos));
2265 QRect r =
d->control->cursorRect(cursor).toRect();
2266 r.
translate(-
d->horizontalOffset(),-(int)
d->verticalOffset());
2277 QRect r =
d->control->cursorRect().toRect();
2278 r.
translate(-
d->horizontalOffset(),-(int)
d->verticalOffset());
2303 return d->control->overwriteMode();
2309 d->control->setOverwriteMode(overwrite);
2325 return qRound(
d->control->document()->defaultTextOption().tabStop());
2331 QTextOption opt =
d->control->document()->defaultTextOption();
2332 if (opt.
tabStop() == width || width < 0)
2335 d->control->document()->setDefaultTextOption(opt);
2349 return d->control->cursorWidth();
2355 d->control->setCursorWidth(width);
2371 d->control->setExtraSelections(selections);
2382 return d->control->extraSelections();
2398 return d->control->QTextControl::createMimeDataFromSelection();
2410 return d->control->QTextControl::canInsertFromMimeData(source);
2423 d->control->QTextControl::insertFromMimeData(source);
2455 d->control->setTextInteractionFlags(flags);
2476 d->control->setTextInteractionFlags(flags);
2482 return d->control->textInteractionFlags();
2496 d->control->mergeCurrentCharFormat(modifier);
2508 d->control->setCurrentCharFormat(format);
2517 return d->control->currentCharFormat();
2533 d->control->insertPlainText(text);
2549 d->control->moveCursor(operation, mode);
2558 return d->control->canPaste();
2561 #ifndef QT_NO_PRINTER 2572 d->control->print(printer);
2574 #endif // QT _NO_PRINTER 2591 return d->tabChangesFocus;
2597 d->tabChangesFocus = b;
2632 if (
d->lineWrap == wrap)
2635 d->updateDefaultTextOption();
2636 d->relayoutDocument();
2637 d->_q_adjustScrollbars();
2662 if (mode ==
d->wordWrap)
2665 d->updateDefaultTextOption();
2688 return d->backgroundVisible;
2694 if (visible ==
d->backgroundVisible)
2697 d->updateViewport();
2723 return d->centerOnScroll;
2729 if (enabled ==
d->centerOnScroll)
2744 return d->control->find(exp, options);
2843 if (maximumBlockCount)
2846 const bool atBottom = q->isVisible()
2847 && (control->blockBoundingRect(document->
lastBlock()).bottom() - verticalOffset()
2850 if (!q->isVisible())
2851 showCursorOnInitialShow =
true;
2857 control->appendHtml(text);
2859 control->appendPlainText(text);
2861 control->append(text);
2863 if (maximumBlockCount > 0) {
2865 bool blockUpdate =
false;
2866 if (control->topBlock) {
2867 control->topBlock--;
2883 _q_adjustScrollbars();
2888 || control->blockBoundingRect(document->
lastBlock()).bottom() - verticalOffset()
2891 vbar->setValue(vbar->maximum());
2924 QRect cr = q->cursorRect();
2926 ensureVisible(control->textCursor().position(),
center);
2929 const bool rtl = q->isRightToLeft();
2931 int x = cr.
center().
x() + horizontalOffset() - visible.
width()/2;
2932 hbar->setValue(rtl ? hbar->maximum() -
x :
x);
2945 d->ensureCursorVisible(
d->centerOnScroll);
2967 return d->control->firstVisibleBlock();
2986 return QPointF(-
d->horizontalOffset(), -
d->verticalOffset());
2999 return d->control->blockBoundingRect(block);
3034 return d->control->getPaintContext(
d->viewport);
3091 #include "moc_qplaintextedit.cpp" 3092 #include "moc_qplaintextedit_p.cpp" 3094 #endif // QT_NO_TEXTEDIT The QVariant class acts like a union for the most common Qt data types.
T qobject_cast(QObject *object)
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.
QRect toAlignedRect() const
Returns a QRect based on the values of this rectangle that is the smallest possible integer rectangle...
QPointF bottomRight() const
Returns the position of the rectangle's bottom-right corner.
QTextCharFormat charFormat(int index) const
void setTabStopWidth(int width)
QFont font() const
Returns the font for this character format.
qreal blockWidth(const QTextBlock &block)
bool pageUpDownLastCursorYIsValid
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's accessibility information.
The QTextLayout::FormatRange structure is used to apply extra formatting information for a specified ...
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...
The QPanGesture class describes a panning gesture made by the user.
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.
void setPlainText(const QString &text)
void setTextInteractionFlags(Qt::TextInteractionFlags flags)
The QTextCharFormat class provides formatting information for characters in a QTextDocument.
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)
The QFontMetrics class provides font metrics information.
#define QT_END_NAMESPACE
This macro expands to.
void _q_cursorPositionChanged()
QPointF toPointF() const
Returns the variant as a QPointF if the variant has type() Point or PointF ; otherwise returns a null...
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)
bool isValid() const
Returns true if the rectangle is valid, otherwise returns false.
void centerCursor()
Scrolls the document in order to center the cursor vertically.
bool blockDocumentSizeChanged
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
The QPlainTextDocumentLayout class implements a plain text layout for QTextDocument.
const QGradient * gradient() const
Returns the gradient describing this brush.
#define it(className, varName)
int hitTest(const QPointF &, Qt::HitTestAccuracy) const
Reimplemented Function
bool isEmpty() const
Returns true if the document is empty; otherwise returns false.
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.
The QTextFrame class represents a frame in a QTextDocument.
void setTransform(const QTransform &)
Sets matrix as an explicit transformation matrix on the current brush.
void _q_adjustScrollbars()
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.
qreal width() const
Returns the width.
int selectionEnd() const
Returns the end of the selection or position() if the cursor doesn'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...
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...
void setAccepted(bool accepted)
The QPointF class defines a point in the plane using floating point precision.
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.
QPlainTextDocumentLayoutPrivate()
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).
WrapMode
This enum describes how text is wrapped in a document.
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's top-left corner.
void _q_repaintContents(const QRectF &contentsRect)
Flags flags() const
Returns the flags associated with the option.
int left() const
Returns the x-coordinate of the rectangle's left edge.
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...
QTextDocument * document() const
Returns the text document that this layout is operating on.
int width() const
Returns the width of the rectangle.
QRectF boundingRect() const
The smallest rectangle that contains all the lines in the layout.
virtual void scrollContentsBy(int dx, int dy)
em>Reimplemented Function
QTextCursor cursor
the selection's cursor
static QSize documentSize(QTextControl *control)
Qt::TextInteractionFlags textInteractionFlags() const
bool atBlockStart() const
Returns true if the cursor is at the start of a block; otherwise returns false.
void setLineWidth(qreal width)
Lays out the line with the given width.
QString anchorHref() const
Returns the text format's hypertext link, or an empty string if none has been set.
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's text.
void setBackground(const QBrush &brush)
Sets the brush use to paint the document's background to the brush specified.
int height() const
Returns the height of the rectangle.
QRectF blockBoundingRect(const QTextBlock &block) const
The QUrl class provides a convenient interface for working with URLs.
QRectF intersected(const QRectF &other) const
Returns the intersection of this rectangle and the given rectangle.
int bottom() const
Returns the y-coordinate of the rectangle's bottom edge.
The QString class provides a Unicode character string.
T * qobject_cast(QObject *object)
QRectF toRectF() const
Returns the variant as a QRectF if the variant has type() Rect or RectF ; otherwise returns an invali...
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...
void setLineWrapMode(LineWrapMode mode)
void setWordWrapMode(QTextOption::WrapMode policy)
void clearLayout()
Clears the QTextLayout that is used to lay out and display the block's contents.
int indent() const
Returns the paragraph's indent.
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.
QPointF delta
the offset from the previous input position to the current input
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'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's origin to point (x, y).
bool isValid() const
Returns true if this text line is valid; otherwise returns false.
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...
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.
virtual void insertFromMimeData(const QMimeData *source)
qreal tabStop() const
Returns the distance in device units between tab stops.
QTextCursor textCursor() const
virtual void dropEvent(QDropEvent *e)
Reimplemented Function
void save()
Saves the current painter state (pushes the state onto a stack).
FragmentMap::ConstIterator FragmentIterator
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
void setRange(int min, int max)
Sets the slider'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...
virtual void wheelEvent(QWheelEvent *e)
Reimplemented Function
qreal x() const
Returns the x-coordinate of this point.
QTextBlock next() const
Returns the text block in the document after this block, or an empty text block if this is the last o...
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
int position() const
Returns the index of the block's first character within the document.
static QCursor * moveCursor
virtual void mouseMoveEvent(QMouseEvent *e)
Reimplemented Function
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.
QSizeF documentSize() const
Reimplemented Function
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.
int key() const
Returns the code of the key that was pressed or released.
void ensureViewportLayouted()
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.
virtual QMimeData * createMimeDataFromSelection() const
This function returns a new MIME data object to represent the contents of the text edit's current sel...
bool isVisible() const
Returns true if the block is visible; otherwise returns false.
#define QT_BEGIN_NAMESPACE
This macro expands to.
qreal & rx()
Returns a reference to the x coordinate of this point.
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...
The QGestureEvent class provides the description of triggered gestures.
The QRectF class defines a rectangle in the plane using floating point precision. ...
void insertFromMimeData(const QMimeData *source)
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's bottom-right corner.
void setCursorWidth(int width)
void insertPlainText(const QString &text)
Convenience slot that inserts text at the current cursor position.
~QPlainTextDocumentLayout()
Destructs a plain text document layout.
void changeEvent(QEvent *)
This event handler can be reimplemented to handle state changes.
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.
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...
void setTabChangesFocus(bool b)
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
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.
The QTextCursor class offers an API to access and modify QTextDocuments.
virtual QSizeF documentSize() const =0
Returns the total size of the document's layout.
QTextFormatCollection * formatCollection()
qreal height() const
Returns the height of the rectangle.
QMenu * createStandardContextMenu()
This function creates the standard context menu which is shown when the user clicks on the line edit ...
The QPrinter class is a paint device that paints on a printer.
int lineNumber() const
Returns the position of the line in the text engine.
Qt::GestureState state() const
void adjust(int x1, int y1, int x2, int y2)
Adds dx1, dy1, dx2 and dy2 respectively to the existing coordinates of the rectangle.
void setRight(int pos)
Sets the right edge of the rectangle to the given x coordinate.
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.
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.
QRectF blockBoundingRect(const QTextBlock &block) const
Returns the bounding rectangle of the text block in the block's own coordinates.
void updateDefaultTextOption()
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...
QPlainTextEdit(QWidget *parent=0)
Constructs an empty QPlainTextEdit with parent parent.
The QTextBlock class provides a container for text fragments in a QTextDocument.
virtual QMimeData * createMimeDataFromSelection() const
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.
void ensureVisible(int position, bool center, bool forceCenter=false)
qreal width() const
Returns the width of the rectangle.
virtual void contextMenuEvent(QContextMenuEvent *e)
Shows the standard context menu created with createStandardContextMenu().
bool backgroundVisible() const
The QDragLeaveEvent class provides an event that is sent to a widget when a drag and drop action leav...
QPlainTextEditControl(QPlainTextEdit *parent)
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's background.
Qt::BrushStyle style() const
Returns the brush style.
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 ...
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.
void setTopBlock(int newTopBlock, int newTopLine, int dx=0)
The QMimeData class provides a container for data that records information about its MIME type...
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...
Qt::MouseButton button() const
Returns the button that caused the event.
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.
void removeSelectedText()
If there is a selection, its content is deleted; otherwise does nothing.
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'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...
QTextBlock block() const
Returns the block that contains the cursor.
int preeditAreaPosition() const
Returns the position of the area in the text layout that will be processed before editing occurs...
void setAcceptRichText(bool accept)
QTextOption::WrapMode wordWrapMode() const
the mode QPlainTextEdit will use when wrapping text by words
QTextDocument * document() const
void setLeadingIncluded(bool included)
Includes positive leading into the line's height if included is true; otherwise does not include lead...
The QMouseEvent class contains parameters that describe a mouse event.
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.
The QBrush class defines the fill pattern of shapes drawn by QPainter.
QPoint center() const
Returns the center point of the rectangle.
bool centerOnScroll() const
void setDefaultFont(const QFont &font)
Sets the default font to use in the document layout.
QPointF contentOffset() const
Returns the content'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's top edge.
The QTextLayout class is used to lay out and render text.
QPlainTextEditPrivate * mainViewPrivate
void remove(const QTextBlock &)
Removes the given block from the list.
void paste()
Pastes the text from the clipboard into the text edit at the current cursor position.
#define Q_DECLARE_PUBLIC(Class)
bool overwriteMode() const
The QDropEvent class provides an event which is sent when a drag and drop action is completed...
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.
int right() const
Returns the x-coordinate of the rectangle's right edge.
LineWrapMode lineWrapMode() 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.
void selectAll()
Selects all text.
void clear()
Deletes all the text in the text edit.
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. ...
QString text() const
Returns the Unicode text that this key generated.
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...
const QSize & size() const
Returns the new size of the widget.
QPoint toPoint() const
Rounds the coordinates of this point to the nearest integer, and returns a QPoint object with the rou...
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.
Type type() const
Returns the storage type of the value stored in the variant.
uint showCursorOnInitialShow
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.
QObject * parent() const
Returns a pointer to the parent object.
QTextBlock firstVisibleBlock() const
The QDragEnterEvent class provides an event which is sent to a widget when a drag and drop action ent...
QPlainTextEditControl * control
The QPoint class defines a point in the plane using integer precision.
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())
void deletePreviousChar()
If there is no selected text, deletes the character before the current cursor position; otherwise del...
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...
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's last (valid) text block.
The QRect class defines a rectangle in the plane using integer precision.
WrapMode wrapMode() const
Returns the text wrap mode defined by the option.
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...
void setIndent(int indent)
Sets the paragraph's indentation.
bool isNull() const
Returns true if both the x and y coordinates are set to +0.
void setCenterOnScroll(bool enabled)
void setDocument(QTextDocument *document)
Makes document the new document of the text editor.
The QTextOption class provides a description of general rich text properties.
virtual void resizeEvent(QResizeEvent *e)
Reimplemented Function
qreal & ry()
Returns a reference to the y coordinate of this point.
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.
static bool shouldEnableInputMethod(QPlainTextEdit *plaintextedit)
qreal y() const
Returns the y-coordinate of this point.
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's name property.
bool canInsertFromMimeData(const QMimeData *source) const
int horizontalOffset() 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.
qreal top() const
Returns the y-coordinate of the rectangle's top edge.
qreal pageUpDownLastCursorY
int length
Specifies the numer of characters the format range spans.
void setPaintDevice(QPaintDevice *device)
Sets the paint device used for rendering the document's layout to the given device.
QTextCharFormat format
Specifies the format to apply.
QGesture * gesture(Qt::GestureType type) const
Returns a gesture object by type.
int pageCount() const
Reimplemented Function
The QTextList class provides a decorated list of items in a QTextDocument.
void setWrapMode(WrapMode wrap)
Sets the option's text wrap mode to the given mode.
void setForeground(const QBrush &brush)
Sets the foreground brush to the specified brush.
void ignore()
Clears the accept flag parameter of the event object, the equivalent of calling setAccepted(false).
void accept()
Sets the accept flag of the event object, the equivalent of calling setAccepted(true).
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.
virtual void timerEvent(QTimerEvent *e)
int x() const
Returns the x coordinate of this point.
void setTextWidth(qreal newWidth)
void endLayout()
Ends the layout process.
qreal bottom() const
Returns the y-coordinate of the rectangle's bottom edge.
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...
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.
int height() const
Returns the height of the font.
The QPaintEvent class contains event parameters for paint events.
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...
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.
Type type() const
Returns the event type.
int hitTest(const QPointF &point, Qt::HitTestAccuracy=Qt::FuzzyHit) const
QPointF center() const
Returns the center point of the rectangle.
static bool isRightToLeft()
Returns true if the application's layout direction is Qt::RightToLeft; otherwise returns false...
int maximumWidthBlockNumber
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...
virtual void changeEvent(QEvent *e)
Reimplemented Function
QTextBlockFormat blockFormat() const
Returns the QTextBlockFormat that describes block-specific properties.
qreal height() const
Returns the line's height.
bool tabChangesFocus() const
The QFocusEvent class contains event parameters for widget focus events.
QPoint toPoint() const
Returns the variant as a QPoint if the variant has type() Point or PointF ; otherwise returns a null ...
Q_DECL_CONSTEXPR int qRound(qreal d)
virtual void showEvent(QShowEvent *)
Reimplemented Function
int selectionStart() const
Returns the start of the selection or position() if the cursor doesn't have a selection.
void setTabStop(qreal tabStop)
Sets the default distance in device units between tab stops to the value specified by tabStop...
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.
void fillRect(const QRectF &, const QBrush &)
Fills the given rectangle with the brush specified.
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.
int lineCount() const
Returns the number of lines in this text layout.
The QList class is a template class that provides lists.
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 ...
QTextLayout * layout() const
Returns the QTextLayout that is used to lay out and display the block's contents. ...
QTextBlock firstBlock() const
Returns the document's first text block.