11#if QT_CONFIG(draganddrop)
21#include "private/qapplication_p.h"
22#include "private/qtextdocumentlayout_p.h"
23#include "private/qabstracttextdocumentlayout_p.h"
25#include "private/qtextdocument_p.h"
40#if defined(Q_OS_ANDROID)
176 br.
adjust(0, 0, margin, 0);
178 br.
adjust(0, 0, 0, margin);
210 return d->cursorWidth;
230void QPlainTextDocumentLayout::setTextWidth(
qreal newWidth)
233 d->width =
d->maximumWidth = newWidth;
237qreal QPlainTextDocumentLayout::textWidth()
const
250 block = block.
next();
263 int charsChanged = charsRemoved + charsAdded;
267 bool blockVisibilityChanged =
false;
269 if (changeStartBlock == changeEndBlock && newBlockCount ==
d->blockCount) {
288 blockVisibilityChanged =
true;
291 if (block == changeEndBlock)
293 block = block.
next();
297 if (newBlockCount !=
d->blockCount || blockVisibilityChanged) {
299 int blockDiff = newBlockCount -
d->blockCount;
300 int oldChangeEnd = changeEnd - blockDiff;
302 if (
d->maximumWidthBlockNumber > oldChangeEnd)
303 d->maximumWidthBlockNumber += blockDiff;
305 d->blockCount = newBlockCount;
306 if (
d->blockCount == 1)
309 if (!
d->blockDocumentSizeChanged)
312 if (blockDiff == 1 && changeEnd == newBlockCount -1 ) {
313 if (!
d->blockUpdate) {
317 if (
b == changeEndBlock)
331void QPlainTextDocumentLayout::layoutBlock(
const QTextBlock &block)
336 qreal blockMaximumWidth = 0;
346 extraMargin += fm.horizontalAdvance(
QChar(0x21B5));
349 qreal availableWidth =
d->width;
350 if (availableWidth <= 0) {
351 availableWidth =
qreal(INT_MAX);
353 availableWidth -= 2*margin + extraMargin;
358 line.setLeadingIncluded(
true);
359 line.setLineWidth(availableWidth);
362 if (
line.leading() < 0)
364 blockMaximumWidth =
qMax(blockMaximumWidth,
line.naturalTextWidth() + 2*margin);
368 int previousLineCount = doc->
lineCount();
372 bool emitDocumentSizeChanged = previousLineCount != lineCount;
373 if (blockMaximumWidth >
d->maximumWidth) {
375 d->maximumWidth = blockMaximumWidth;
377 emitDocumentSizeChanged =
true;
378 }
else if (block.
blockNumber() ==
d->maximumWidthBlockNumber && blockMaximumWidth <
d->maximumWidth) {
383 while (
b.isValid()) {
384 qreal blockMaximumWidth = blockWidth(
b);
385 if (blockMaximumWidth >
d->maximumWidth) {
386 d->maximumWidth = blockMaximumWidth;
392 d->maximumWidthBlockNumber = maximumBlock.
blockNumber();
393 emitDocumentSizeChanged =
true;
396 if (emitDocumentSizeChanged && !
d->blockDocumentSizeChanged)
405 qreal blockWidth = 0;
406 for (
int i = 0;
i <
layout->lineCount(); ++
i) {
408 blockWidth =
qMax(
line.naturalTextWidth() + 8, blockWidth);
425#if QT_CONFIG(accessibility)
426 QAccessibleTextCursorEvent ev(
q,
q->textCursor().position());
427 QAccessible::updateAccessibility(&ev);
429 emit q->cursorPositionChanged();
479 if (
layout && topLine <= layout->lineCount()) {
485 if (topBlock == 0 &&
topLine == 0)
516 currentBlock = currentBlock.
next();
517 ++currentBlockNumber;
522 currentBlock = currentBlock.
previous();
523 --currentBlockNumber;
533 for (
int i = 0;
i <
layout->lineCount(); ++
i) {
547 return currentBlock.
position() + off;
565 int maxVerticalOffset =
r.
height();
566 while (currentBlockNumber < blockNumber &&
offset.y() - maxVerticalOffset <= 2* textEdit->
viewport()->
height()) {
568 currentBlock = currentBlock.
next();
569 ++currentBlockNumber;
576 while (currentBlockNumber > blockNumber &&
offset.y() + maxVerticalOffset >= -
textEdit->viewport()->height()) {
577 currentBlock = currentBlock.
previous();
578 --currentBlockNumber;
580 currentBlock = currentBlock.
previous();
581 --currentBlockNumber;
590 if (currentBlockNumber != blockNumber) {
594 if (currentBlockNumber > blockNumber)
618 blockNumber =
qMax(0, blockNumber);
619 lineNumber =
qMax(0, lineNumber);
624 int maxTopLine = vbar->maximum();
626 if (newTopLine > maxTopLine) {
632 vbar->setValue(newTopLine);
640 qreal realdy = -
q->blockBoundingGeometry(block).y()
651 viewport->scroll(
q->isRightToLeft() ? -dx : dx, dy);
681 if (lr.
bottom() >= visible.
bottom() || (center && lr.
top() < visible.
top()) || forceCenter){
687 qreal h = center ?
line.naturalTextRect().center().y() :
line.naturalTextRect().bottom();
691 previousVisibleBlock = block;
695 h +=
q->blockBoundingRect(block).height();
701 while (l < lineCount) {
708 if (l >= lineCount) {
709 block = previousVisibleBlock;
713 }
else if (lr.
top() < visible.
top()) {
728 : tabChangesFocus(
false), showCursorOnInitialShow(
false), backgroundVisible(
false),
729 centerOnScroll(
false), inDrag(
false), clickCausedFocus(
false), placeholderVisible(true),
730 pageUpDownLastCursorYIsValid(
false)
749 [
q](){
q->updateMicroFocus(); });
780 hbar->setSingleStep(20);
781 vbar->setSingleStep(1);
784 q->setAcceptDrops(
true);
806 &&
q->document()->isEmpty()
807 && (!
q->firstVisibleBlock().isValid() ||
808 q->firstVisibleBlock().layout()->preeditAreaText().isEmpty());
831 emit q->updateRequest(
r, 0);
851 QTextBlock firstVisibleBlock =
q->firstVisibleBlock();
853 QRectF br =
q->blockBoundingRect(block);
863 block = block.
next();
864 br =
q->blockBoundingRect(block);
871 while (
line < lineCount - 1) {
886 moved =
cursor.movePosition(op, moveMode);
896 while (
h >= visible.
top()) {
904 QRectF br =
q->blockBoundingRect(block);
912 while (
line < lineCount) {
917 if (
line == lineCount) {
919 block = block.
next();
929 cursor.setVisualNavigation(
true);
934 moved =
cursor.movePosition(op, moveMode);
945#if QT_CONFIG(scrollbar)
959 int vSliderLength = 0;
962 const qreal visible =
viewport->rect().height() - margin - 1;
964 int visibleFromBottom = 0;
974 int layoutLineCount =
layout->lineCount();
977 while (lineNumber < layoutLineCount) {
980 if (lr.
top() >=
y - visible)
984 if (lineNumber < layoutLineCount)
985 visibleFromBottom += (layoutLineCount - lineNumber);
989 visibleFromBottom += layoutLineCount;
993 vSliderLength = visibleFromBottom;
997 int lineSpacing =
q->fontMetrics().lineSpacing();
998 vSliderLength = lineSpacing != 0 ?
viewport->height() / lineSpacing : 0;
1002 vbar->setRange(0,
qMax(0, vmax));
1003 vbar->setPageStep(vSliderLength);
1004 int visualTopLine =
vmax;
1005 QTextBlock firstVisibleBlock =
q->firstVisibleBlock();
1006 if (firstVisibleBlock.
isValid())
1009 vbar->setValue(visualTopLine);
1011 hbar->setRange(0, (
int)documentSize.
width() -
viewport->width());
1012 hbar->setPageStep(
viewport->width());
1238 : QAbstractScrollArea(dd,
parent)
1262 if (
d->documentLayoutPtr) {
1263 if (
d->documentLayoutPtr->priv()->mainViewPrivate ==
d)
1264 d->documentLayoutPtr->priv()->mainViewPrivate =
nullptr;
1292 qWarning(
"QPlainTextEdit::setDocument: Document set does not support QPlainTextDocumentLayout");
1299 d->documentLayoutPtr = documentLayout;
1300 d->updateDefaultTextOption();
1301 d->relayoutDocument();
1302 d->_q_adjustScrollbars();
1313 return d->control->document();
1334 d->_q_updatePlaceholderVisibility();
1341 return d->placeholderText;
1361 d->control->setTextCursor(
cursor);
1372 return d->control->textCursor();
1384 int cursorPos =
d->control->hitTest(
pos +
QPointF(
d->horizontalOffset(),
1385 d->verticalOffset()),
1393 return fmt.anchorHref();
1427#ifndef QT_NO_CLIPBOARD
1472 d->control->paste();
1492 d->control->topBlock =
d->topLine =
d->topLineFracture = 0;
1493 d->control->clear();
1505 d->control->selectAll();
1514 switch (
e->type()) {
1515#ifndef QT_NO_CONTEXTMENU
1522 const bool result = QAbstractScrollArea::event(&ce);
1530 d->sendControlEvent(
e);
1532#ifdef QT_KEYPAD_NAVIGATION
1533 case QEvent::EnterEditFocus:
1534 case QEvent::LeaveEditFocus:
1535 if (QApplicationPrivate::keypadNavigationEnabled())
1536 d->sendControlEvent(
e);
1539#ifndef QT_NO_GESTURES
1546 d->originalOffsetY = vBar->
value();
1553 int lineHeight = fm.
height();
1554 int newX = hBar->
value() - panGesture->
delta().
x();
1555 int newY =
d->originalOffsetY -
offset.y()/lineHeight;
1565 return QAbstractScrollArea::event(
e);
1574 if (
e->timerId() ==
d->autoScrollTimer.timerId()) {
1575 QRect visible =
d->viewport->rect();
1578 pos =
d->autoScrollDragPos;
1583 pos =
d->viewport->mapFromGlobal(globalPos);
1590 int delta =
qMax(deltaX, deltaY);
1594 int timeout = 4900 / (delta * delta);
1595 d->autoScrollTimer.start(
timeout,
this);
1598 d->vbar->triggerAction(
pos.y() < visible.
center().
y() ?
1602 d->hbar->triggerAction(
pos.x() < visible.
center().
x() ?
1607#ifdef QT_KEYPAD_NAVIGATION
1608 else if (
e->timerId() ==
d->deleteAllTimer.timerId()) {
1609 d->deleteAllTimer.stop();
1634 d->control->setPlainText(
text);
1651#ifdef QT_KEYPAD_NAVIGATION
1654 if (QApplicationPrivate::keypadNavigationEnabled()) {
1656 setEditFocus(!hasEditFocus());
1658 if (!hasEditFocus())
1664 setEditFocus(
false);
1672 if (!QApplicationPrivate::keypadNavigationEnabled()
1673 || (QApplicationPrivate::keypadNavigationEnabled() && !hasEditFocus())) {
1679 if (QApplicationPrivate::keypadNavigationEnabled()) {
1681 if (
e->text()[0].isPrint()) {
1694#ifndef QT_NO_SHORTCUT
1696 Qt::TextInteractionFlags tif =
d->control->textInteractionFlags();
1731 d->sendControlEvent(
e);
1741 if (!
e->isAccepted()) {
1742 QAbstractScrollArea::keyPressEvent(
e);
1749 d->sendControlEvent(
e);
1750#ifdef QT_KEYPAD_NAVIGATION
1751 if (!
e->isAccepted()) {
1755 if (QApplicationPrivate::keypadNavigationEnabled()) {
1764 if (QApplicationPrivate::keypadNavigationEnabled()
1772 if (!
e->isAutoRepeat()) {
1773 if (QApplicationPrivate::keypadNavigationEnabled()) {
1775 setEditFocus(
false);
1777 }
else if (!
d->deleteAllTimer.isActive()) {
1779 d->deleteAllTimer.start(750,
this);
1799 d->handleSoftwareInputPanel();
1801#ifdef QT_KEYPAD_NAVIGATION
1802 if (QApplicationPrivate::keypadNavigationEnabled()) {
1804 &&
d->deleteAllTimer.isActive()) {
1805 d->deleteAllTimer.stop();
1812 }
else if (
cursor.atBlockStart() && blockFmt.
indent() > 0) {
1814 cursor.setBlockFormat(blockFmt);
1816 cursor.deletePreviousChar();
1845 if (
e->oldSize().width() !=
e->size().width())
1846 d->relayoutDocument();
1847 d->_q_adjustScrollbars();
1861 ||
width > documentLayout->textWidth()) {
1863 documentLayout->setTextWidth(
width);
1871 if (!gradientRect.isNull()) {
1873 m.scale(gradientRect.width(), gradientRect.height());
1878 p->setBrushOrigin(
rect.topLeft());
1892 Q_ASSERT(qobject_cast<QPlainTextDocumentLayout*>(
document()->documentLayout()));
1913 if (
d->placeholderVisible) {
1914 const QColor col =
d->control->palette().placeholderText().color();
1917 const int margin = int(
document()->documentMargin());
1932 block = block.
next();
1936 if (
r.bottom() >= er.
top() &&
r.top() <= er.
bottom()) {
1949 int bllen = block.
length();
1950 for (
int i = 0;
i <
context.selections.size(); ++
i) {
1952 const int selStart =
range.cursor.selectionStart() - blpos;
1953 const int selEnd =
range.cursor.selectionEnd() - blpos;
1954 if (selStart < bllen && selEnd > 0
1955 && selEnd > selStart) {
1958 o.length = selEnd - selStart;
1969 if (
o.start +
o.length == bllen - 1)
1977 &&
context.cursorPosition >= blpos
1978 &&
context.cursorPosition < blpos + bllen);
1982 if (drawCursorAsBlock) {
1983 if (
context.cursorPosition == blpos + bllen - 1) {
1984 drawCursorAsBlock =
false;
1987 o.start =
context.cursorPosition - blpos;
1997 if ((drawCursor && !drawCursorAsBlock)
1998 || (editable &&
context.cursorPosition < -1
2000 int cpos =
context.cursorPosition;
2002 cpos =
layout->preeditAreaPosition() - (cpos + 2);
2012 block = block.
next();
2016 && (
centerOnScroll() || verticalScrollBar()->maximum() == verticalScrollBar()->minimum())) {
2034 if (
opt.wrapMode() != oldWrapMode)
2044#ifdef QT_KEYPAD_NAVIGATION
2045 if (QApplicationPrivate::keypadNavigationEnabled() && !hasEditFocus())
2048 d->sendControlEvent(
e);
2058 d->sendControlEvent(
e);
2062 const QRect visible =
d->viewport->rect();
2064 d->autoScrollTimer.stop();
2065 else if (!
d->autoScrollTimer.isActive())
2066 d->autoScrollTimer.start(100,
this);
2075 d->sendControlEvent(
e);
2077 d->autoScrollTimer.stop();
2078 d->ensureCursorVisible();
2082 d->handleSoftwareInputPanel(
e->button(),
d->clickCausedFocus);
2083 d->clickCausedFocus = 0;
2091 d->sendControlEvent(
e);
2101 return QAbstractScrollArea::focusNextPrevChild(
next);
2104#ifndef QT_NO_CONTEXTMENU
2123 d->sendControlEvent(
e);
2127#if QT_CONFIG(draganddrop)
2130void QPlainTextEdit::dragEnterEvent(QDragEnterEvent *
e)
2134 d->sendControlEvent(
e);
2139void QPlainTextEdit::dragLeaveEvent(QDragLeaveEvent *
e)
2143 d->autoScrollTimer.stop();
2144 d->sendControlEvent(
e);
2149void QPlainTextEdit::dragMoveEvent(QDragMoveEvent *
e)
2152 d->autoScrollDragPos =
e->position().toPoint();
2153 if (!
d->autoScrollTimer.isActive())
2154 d->autoScrollTimer.start(100,
this);
2155 d->sendControlEvent(
e);
2160void QPlainTextEdit::dropEvent(QDropEvent *
e)
2164 d->autoScrollTimer.stop();
2165 d->sendControlEvent(
e);
2175#ifdef QT_KEYPAD_NAVIGATION
2177 && QApplicationPrivate::keypadNavigationEnabled()
2178 && !hasEditFocus()) {
2183 d->sendControlEvent(
e);
2184 const bool emptyEvent =
e->preeditString().isEmpty() &&
e->commitString().isEmpty()
2185 &&
e->attributes().isEmpty();
2196 d->setTopLine(
d->vbar->value(), dx);
2225 case QMetaType::QRectF:
2228 case QMetaType::QPointF:
2231 case QMetaType::QRect:
2234 case QMetaType::QPoint:
2242 switch (
v.userType()) {
2243 case QMetaType::QRectF:
2244 return v.toRectF().translated(
offset);
2245 case QMetaType::QPointF:
2247 case QMetaType::QRect:
2248 return v.toRect().translated(
offset.toPoint());
2249 case QMetaType::QPoint:
2250 return v.toPoint() +
offset.toPoint();
2263 d->clickCausedFocus = 1;
2265 QAbstractScrollArea::focusInEvent(
e);
2266 d->sendControlEvent(
e);
2274 QAbstractScrollArea::focusOutEvent(
e);
2275 d->sendControlEvent(
e);
2283 if (
d->showCursorOnInitialShow) {
2284 d->showCursorOnInitialShow =
false;
2287 d->_q_adjustScrollbars();
2295 QAbstractScrollArea::changeEvent(
e);
2297 switch (
e->type()) {
2300 d->control->document()->setDefaultFont(
font());
2304 if (!isActiveWindow())
2305 d->autoScrollTimer.stop();
2308 e->setAccepted(isEnabled());
2310 d->sendControlEvent(
e);
2316 d->sendControlEvent(
e);
2325#if QT_CONFIG(wheelevent)
2326void QPlainTextEdit::wheelEvent(QWheelEvent *
e)
2331 float delta =
e->angleDelta().y() / 120.f;
2336 QAbstractScrollArea::wheelEvent(
e);
2373 const float newSize =
f.pointSizeF() +
range;
2376 f.setPointSizeF(newSize);
2380#ifndef QT_NO_CONTEXTMENU
2393 return d->control->createStandardContextMenu(
QPointF(),
this);
2409 return d->control->createStandardContextMenu(
position,
this);
2419 return d->control->cursorForPosition(
d->mapToContents(
pos));
2433 r.translate(-
d->horizontalOffset(),-(
int)
d->verticalOffset());
2444 QRect r =
d->control->cursorRect().toRect();
2445 r.translate(-
d->horizontalOffset(),-(
int)
d->verticalOffset());
2467 return d->control->overwriteMode();
2473 d->control->setOverwriteMode(overwrite);
2493 return d->control->document()->defaultTextOption().tabStopDistance();
2503 d->control->document()->setDefaultTextOption(
opt);
2515 return d->control->cursorWidth();
2521 d->control->setCursorWidth(
width);
2537 d->control->setExtraSelections(selections);
2548 return d->control->extraSelections();
2564 return d->control->QWidgetTextControl::createMimeDataFromSelection();
2576 return d->control->QWidgetTextControl::canInsertFromMimeData(
source);
2589 d->control->QWidgetTextControl::insertFromMimeData(
source);
2617 d->control->setTextInteractionFlags(
flags);
2638 d->control->setTextInteractionFlags(
flags);
2644 return d->control->textInteractionFlags();
2658 d->control->mergeCurrentCharFormat(modifier);
2670 d->control->setCurrentCharFormat(
format);
2679 return d->control->currentCharFormat();
2695 d->control->insertPlainText(
text);
2711 d->control->moveCursor(operation,
mode);
2720 return d->control->canPaste();
2730#ifndef QT_NO_PRINTER
2734 d->control->print(printer);
2750 return d->tabChangesFocus;
2756 d->tabChangesFocus =
b;
2785 if (
d->lineWrap ==
wrap)
2788 d->updateDefaultTextOption();
2789 d->relayoutDocument();
2790 d->_q_adjustScrollbars();
2812 if (
mode ==
d->wordWrap)
2815 d->updateDefaultTextOption();
2835 return d->backgroundVisible;
2841 if (visible ==
d->backgroundVisible)
2843 d->backgroundVisible = visible;
2844 d->updateViewport();
2867 return d->centerOnScroll;
2876 d->_q_adjustScrollbars();
2889 return d->control->find(exp, options);
2905#if QT_CONFIG(regularexpression)
2909 return d->control->find(exp, options);
2990 int maximumBlockCount = document->maximumBlockCount();
2991 if (maximumBlockCount)
2992 document->setMaximumBlockCount(0);
2994 const bool atBottom =
q->isVisible()
2998 if (!
q->isVisible())
3016 if (maximumBlockCount > 0) {
3017 if (document->blockCount() > maximumBlockCount) {
3018 bool blockUpdate =
false;
3025 bool updatesBlocked = documentLayout->priv()->
blockUpdate;
3026 documentLayout->priv()->
blockUpdate = blockUpdate;
3029 cursor.removeSelectedText();
3030 documentLayout->priv()->
blockUpdate = updatesBlocked;
3032 document->setMaximumBlockCount(maximumBlockCount);
3044 vbar->setValue(vbar->maximum());
3077 QRect cr =
q->cursorRect();
3082 const bool rtl =
q->isRightToLeft();
3085 hbar->setValue(rtl ? hbar->maximum() -
x :
x);
3098 d->ensureCursorVisible(
d->centerOnScroll);
3120 return d->control->firstVisibleBlock();
3139 return QPointF(-
d->horizontalOffset(), -
d->verticalOffset());
3152 return d->control->blockBoundingRect(block);
3184 return d->control->getPaintContext(
d->viewport);
3229#include "moc_qplaintextedit.cpp"
3230#include "moc_qplaintextedit_p.cpp"
int value
the slider's current value
SliderAction
\value SliderNoAction \value SliderSingleStepAdd \value SliderSingleStepSub \value SliderPageStepAdd ...
void actionTriggered(int action)
This signal is emitted when the slider action action is triggered.
void documentSizeChanged(const QSizeF &newSize)
This signal is emitted when the size of the document layout changes to newSize.
QTextDocument * document() const
Returns the text document that this layout is operating on.
void updateBlock(const QTextBlock &block)
void setPaintDevice(QPaintDevice *device)
Sets the paint device used for rendering the document's layout to the given device.
void update(const QRectF &=QRectF(0., 0., 1000000000., 1000000000.))
This signal is emitted when the rectangle rect has been updated.
virtual QSizeF documentSize() const =0
Returns the total size of the document's layout.
The QColor class provides colors based on RGB, HSV or CMYK values.
static bool sendEvent(QObject *receiver, QEvent *event)
Sends event event directly to receiver receiver, using the notify() function.
static QPoint pos()
Returns the position of the cursor (hot spot) of the primary screen in global screen coordinates.
virtual void setAccepted(bool accepted)
The QFocusEvent class contains event parameters for widget focus events.
\reentrant \inmodule QtGui
int height() const
Returns the height of the font.
The QGestureEvent class provides the description of triggered gestures.
Qt::GestureState state
the current state of the gesture
static QInputMethod * inputMethod()
returns the input method.
static Qt::KeyboardModifiers keyboardModifiers()
Returns the current state of the modifier keys on the keyboard.
static bool isRightToLeft()
Returns true if the application's layout direction is Qt::RightToLeft; otherwise returns false.
The QKeyEvent class describes a key event.
bool isEmpty() const override
\reimp
void remove(qsizetype i, qsizetype n=1)
void append(parameter_type t)
static QMetaObject::Connection connect(const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::FunctionPointer< Func2 >::Object *receiverPrivate, Func2 slot, Qt::ConnectionType type=Qt::AutoConnection)
QObject * parent() const
Returns a pointer to the parent object.
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
The QPaintEvent class contains event parameters for paint events.
The QPainter class performs low-level painting on widgets and other paint devices.
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 setPen(const QColor &color)
This is an overloaded member function, provided for convenience. It differs from the above function o...
void setBrushOrigin(int x, int y)
This is an overloaded member function, provided for convenience. It differs from the above function o...
void drawText(const QPointF &p, const QString &s)
Draws the given text with the currently defined text direction, beginning at the given position.
void fillRect(const QRectF &, const QBrush &)
Fills the given rectangle with the brush specified.
The QPanGesture class describes a panning gesture made by the user.\inmodule QtWidgets.
QPointF delta
the offset from the previous input position to the current input
QPointF offset
the total offset from the first input position to the current input position
QPlainTextDocumentLayoutPrivate()
bool blockDocumentSizeChanged
QPlainTextEditPrivate * mainViewPrivate
int maximumWidthBlockNumber
void layoutBlock(const QTextBlock &block)
qreal blockWidth(const QTextBlock &block)
The QPlainTextDocumentLayout class implements a plain text layout for QTextDocument.
void ensureBlockLayout(const QTextBlock &block) const
Ensures that block has a valid layout.
~QPlainTextDocumentLayout()
Destructs a plain text document layout.
QRectF frameBoundingRect(QTextFrame *) const override
\reimp
void documentChanged(int from, int, int charsAdded) override
\reimp
void requestUpdate()
Requests a complete update on all views.
int hitTest(const QPointF &, Qt::HitTestAccuracy) const override
\reimp
QRectF blockBoundingRect(const QTextBlock &block) const override
\reimp
void draw(QPainter *, const PaintContext &) override
\reimp
QSizeF documentSize() const override
\reimp
int pageCount() const override
\reimp
void setCursorWidth(int width)
QPlainTextDocumentLayout(QTextDocument *document)
Constructs a plain text document layout for the text document.
int cursorWidth
This property specifies the width of the cursor in pixels.
QPlainTextEdit * textEdit
QRectF cursorRect(const QTextCursor &cursor) const
void insertFromMimeData(const QMimeData *source) override
bool canInsertFromMimeData(const QMimeData *source) const override
QTextBlock firstVisibleBlock() const
QRectF blockBoundingRect(const QTextBlock &block) const override
int hitTest(const QPointF &point, Qt::HitTestAccuracy=Qt::FuzzyHit) const override
QString anchorAt(const QPointF &pos) const override
QPlainTextEditControl(QPlainTextEdit *parent)
QMimeData * createMimeDataFromSelection() const override
qreal verticalOffset() const
int horizontalOffset() const
void _q_repaintContents(const QRectF &contentsRect)
void _q_adjustScrollbars()
void _q_verticalScrollbarActionTriggered(int action)
uint pageUpDownLastCursorYIsValid
void pageUpDown(QTextCursor::MoveOperation op, QTextCursor::MoveMode moveMode, bool moveCursor=true)
QPlainTextEditControl * control
void updateDefaultTextOption()
void append(const QString &text, Qt::TextFormat format=Qt::AutoText)
void ensureVisible(int position, bool center, bool forceCenter=false)
QTextOption::WrapMode wordWrap
void init(const QString &txt=QString())
QPlainTextEdit::LineWrapMode lineWrap
void setTopLine(int visualTopLine, int dx=0)
QPointer< QPlainTextDocumentLayout > documentLayoutPtr
uint showCursorOnInitialShow
qreal pageUpDownLastCursorY
void ensureCursorVisible(bool center=false)
void ensureViewportLayouted()
void _q_cursorPositionChanged()
void setTopBlock(int newTopBlock, int newTopLine, int dx=0)
void _q_updatePlaceholderVisibility()
The QPlainTextEdit class provides a widget that is used to edit and display plain text.
void cut()
Copies the selected text to the clipboard and deletes it from the text edit.
virtual void mouseMoveEvent(QMouseEvent *e) override
\reimp
virtual ~QPlainTextEdit()
Destructor.
virtual bool focusNextPrevChild(bool next) override
\reimp
QTextBlock firstVisibleBlock() const
Returns the first visible block.
int cursorWidth
This property specifies the width of the cursor in pixels.
QRectF blockBoundingGeometry(const QTextBlock &block) const
Returns the bounding rectangle of the text block in content coordinates.
void zoomOut(int range=1)
Zooms out on the text by making the base font size range points smaller and recalculating all font si...
virtual QVariant loadResource(int type, const QUrl &name)
Loads the resource specified by the given type and name.
void setTabStopDistance(qreal distance)
void copy()
Copies any selected text to the clipboard.
virtual void paintEvent(QPaintEvent *e) override
\reimp
void setCursorWidth(int width)
virtual bool canInsertFromMimeData(const QMimeData *source) const
This function returns true if the contents of the MIME data object, specified by source,...
QTextOption::WrapMode wordWrapMode() const
the mode QPlainTextEdit will use when wrapping text by words
void setLineWrapMode(LineWrapMode mode)
void setExtraSelections(const QList< QTextEdit::ExtraSelection > &selections)
This function allows temporarily marking certain regions in the document with a given color,...
QMenu * createStandardContextMenu()
This function creates the standard context menu which is shown when the user clicks on the text edit ...
void setPlainText(const QString &text)
Changes the text of the text edit to the string text.
QTextCharFormat currentCharFormat() const
Returns the char format that is used when inserting new text.
virtual void mouseDoubleClickEvent(QMouseEvent *e) override
\reimp
void setTabChangesFocus(bool b)
QTextCursor cursorForPosition(const QPoint &pos) const
returns a QTextCursor at position pos (in viewport coordinates).
void setBackgroundVisible(bool visible)
virtual void keyReleaseEvent(QKeyEvent *e) override
\reimp
void centerCursor()
Scrolls the document in order to center the cursor vertically.
virtual void resizeEvent(QResizeEvent *e) override
\reimp
void copyAvailable(bool b)
This signal is emitted when text is selected or de-selected in the text edit.
void paste()
Pastes the text from the clipboard into the text edit at the current cursor position.
virtual void keyPressEvent(QKeyEvent *e) override
\reimp
void selectionChanged()
This signal is emitted whenever the selection changes.
void undoAvailable(bool b)
This signal is emitted whenever undo operations become available (available is true) or unavailable (...
void ensureCursorVisible()
Ensures that the cursor is visible by scrolling the text edit if necessary.
void insertPlainText(const QString &text)
Convenience slot that inserts text at the current cursor position.
void blockCountChanged(int newBlockCount)
This signal is emitted whenever the block count changes.
void clear()
Deletes all the text in the text edit.
void zoomIn(int range=1)
\reimp
void redo()
Redoes the last operation.
virtual void timerEvent(QTimerEvent *e) override
void redoAvailable(bool b)
This signal is emitted whenever redo operations become available (available is true) or unavailable (...
bool backgroundVisible
whether the palette background is visible outside the document area
virtual void doSetTextCursor(const QTextCursor &cursor)
QAbstractTextDocumentLayout::PaintContext getPaintContext() const
Returns the paint context for the viewport(), useful only when reimplementing paintEvent().
void setCenterOnScroll(bool enabled)
LineWrapMode
\value NoWrap \value WidgetWidth
void setOverwriteMode(bool overwrite)
virtual void showEvent(QShowEvent *) override
\reimp
QTextDocument * document() const
Returns a pointer to the underlying document.
QPointF contentOffset() const
Returns the content's origin in viewport coordinates.
virtual void changeEvent(QEvent *e) override
\reimp
QTextCursor textCursor() const
Returns a copy of the QTextCursor that represents the currently visible cursor.
virtual void inputMethodEvent(QInputMethodEvent *) override
\reimp
void print(QPagedPaintDevice *printer) const
Convenience function to print the text edit's document to the given printer.
virtual void mousePressEvent(QMouseEvent *e) override
\reimp
void setCurrentCharFormat(const QTextCharFormat &format)
Sets the char format that is be used when inserting new text to format by calling QTextCursor::setCha...
QList< QTextEdit::ExtraSelection > extraSelections() const
Returns previously set extra selections.
void textChanged()
This signal is emitted whenever the document's content changes; for example, when text is inserted or...
virtual void focusOutEvent(QFocusEvent *e) override
\reimp
virtual QMimeData * createMimeDataFromSelection() const
This function returns a new MIME data object to represent the contents of the text edit's current sel...
void selectAll()
Selects all text.
virtual bool event(QEvent *e) override
QVariant inputMethodQuery(Qt::InputMethodQuery property) const override
\reimp
bool canPaste() const
Returns whether text can be pasted from the clipboard into the textedit.
QRectF blockBoundingRect(const QTextBlock &block) const
Returns the bounding rectangle of the text block in the block's own coordinates.
bool find(const QString &exp, QTextDocument::FindFlags options=QTextDocument::FindFlags())
Finds the next occurrence of the string, exp, using the given options.
void setPlaceholderText(const QString &placeholderText)
virtual void contextMenuEvent(QContextMenuEvent *e) override
Shows the standard context menu created with createStandardContextMenu().
Qt::TextInteractionFlags textInteractionFlags
Specifies how the label should interact with user input if it displays text.
QString placeholderText
the editor placeholder text
LineWrapMode lineWrapMode
the line wrap mode
void appendPlainText(const QString &text)
Appends a new paragraph with text to the end of the text edit.
void undo()
Undoes the last operation.
QRect cursorRect() const
returns a rectangle (in viewport coordinates) that includes the cursor of the text edit.
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 setDocument(QTextDocument *document)
Makes document the new document of the text editor.
int blockCount
the number of text blocks in the document.
void modificationChanged(bool)
This signal is emitted whenever the content of the document changes in a way that affects the modific...
void setTextInteractionFlags(Qt::TextInteractionFlags flags)
void zoomInF(float range)
virtual void scrollContentsBy(int dx, int dy) override
\reimp
void setTextCursor(const QTextCursor &cursor)
Sets the visible cursor.
void mergeCurrentCharFormat(const QTextCharFormat &modifier)
Merges the properties specified in modifier into the current character format by calling QTextCursor:...
void setReadOnly(bool ro)
virtual void insertFromMimeData(const QMimeData *source)
This function inserts the contents of the MIME data object, specified by source, into the text edit a...
void appendHtml(const QString &html)
Appends a new paragraph with html to the end of the text edit.
virtual void focusInEvent(QFocusEvent *e) override
\reimp
qreal tabStopDistance
the tab stop distance in pixels
QPlainTextEdit(QWidget *parent=nullptr)
Constructs an empty QPlainTextEdit with parent parent.
virtual void mouseReleaseEvent(QMouseEvent *e) override
\reimp
bool centerOnScroll
whether the cursor should be centered on screen
void moveCursor(QTextCursor::MoveOperation operation, QTextCursor::MoveMode mode=QTextCursor::MoveAnchor)
Moves the cursor by performing the given operation.
void setWordWrapMode(QTextOption::WrapMode policy)
bool tabChangesFocus
whether \uicontrol Tab changes focus or is accepted as input
bool overwriteMode
whether text entered by the user will overwrite existing text
\inmodule QtCore\reentrant
constexpr qreal x() const noexcept
Returns the x coordinate of this point.
constexpr qreal y() const noexcept
Returns the y coordinate of this point.
constexpr qreal & rx() noexcept
Returns a reference to the x coordinate of this point.
\inmodule QtCore\reentrant
constexpr int x() const noexcept
Returns the x coordinate of this point.
constexpr int y() const noexcept
Returns the y coordinate of this point.
\inmodule QtCore\reentrant
constexpr qreal bottom() const noexcept
Returns the y-coordinate of the rectangle's bottom edge.
QRect toAlignedRect() const noexcept
constexpr qreal height() const noexcept
Returns the height of the rectangle.
constexpr qreal width() const noexcept
Returns the width of the rectangle.
constexpr QRectF translated(qreal dx, qreal dy) const noexcept
Returns a copy of the rectangle that is translated dx along the x axis and dy along the y axis,...
constexpr QRectF adjusted(qreal x1, qreal y1, qreal x2, qreal y2) const noexcept
Returns a new rectangle with dx1, dy1, dx2 and dy2 added respectively to the existing coordinates of ...
constexpr void setWidth(qreal w) noexcept
Sets the width of the rectangle to the given finite width.
constexpr QPointF topLeft() const noexcept
Returns the position of the rectangle's top-left corner.
constexpr QPointF bottomRight() const noexcept
Returns the position of the rectangle's bottom-right corner.
constexpr void adjust(qreal x1, qreal y1, qreal x2, qreal y2) noexcept
Adds dx1, dy1, dx2 and dy2 respectively to the existing coordinates of the rectangle.
constexpr void translate(qreal dx, qreal dy) noexcept
Moves the rectangle dx along the x-axis and dy along the y-axis, relative to the current position.
constexpr qreal top() const noexcept
Returns the y-coordinate of the rectangle's top edge.
constexpr bool isValid() const noexcept
Returns true if the rectangle is valid, otherwise returns false.
QRectF intersected(const QRectF &other) const noexcept
\inmodule QtCore\reentrant
constexpr void adjust(int x1, int y1, int x2, int y2) noexcept
Adds dx1, dy1, dx2 and dy2 respectively to the existing coordinates of the rectangle.
constexpr int height() const noexcept
Returns the height of the rectangle.
constexpr int bottom() const noexcept
Returns the y-coordinate of the rectangle's bottom edge.
constexpr void setRight(int pos) noexcept
Sets the right edge of the rectangle to the given x coordinate.
constexpr QRect adjusted(int x1, int y1, int x2, int y2) const noexcept
Returns a new rectangle with dx1, dy1, dx2 and dy2 added respectively to the existing coordinates of ...
constexpr int top() const noexcept
Returns the y-coordinate of the rectangle's top edge.
bool contains(const QRect &r, bool proper=false) const noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
constexpr int left() const noexcept
Returns the x-coordinate of the rectangle's left edge.
constexpr void translate(int dx, int dy) noexcept
Moves the rectangle dx along the x axis and dy along the y axis, relative to the current position.
constexpr QPoint bottomRight() const noexcept
Returns the position of the rectangle's bottom-right corner.
constexpr int width() const noexcept
Returns the width of the rectangle.
constexpr QPoint center() const noexcept
Returns the center point of the rectangle.
constexpr int right() const noexcept
Returns the x-coordinate of the rectangle's right edge.
\inmodule QtCore \reentrant
The QResizeEvent class contains event parameters for resize events.
The QShowEvent class provides an event that is sent when a widget is shown.
constexpr qreal width() const noexcept
Returns the width.
\macro QT_RESTRICTED_CAST_FROM_ASCII
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
void setIndent(int indent)
Sets the paragraph's indentation.
int indent() const
Returns the paragraph's indent.
int length() const
Returns the length of the block in characters.
void setLineCount(int count)
QTextBlockFormat blockFormat() const
Returns the QTextBlockFormat that describes block-specific properties.
const QTextDocument * document() const
Returns the text document this text block belongs to, or \nullptr if the text block does not belong t...
bool isValid() const
Returns true if this text block is valid; otherwise returns false.
bool contains(int position) const
Returns true if the given position is located within the text block; otherwise returns false.
QTextBlock next() const
Returns the text block in the document after this block, or an empty text block if this is the last o...
int firstLineNumber() const
QTextLayout * layout() const
Returns the QTextLayout that is used to lay out and display the block's contents.
int position() const
Returns the index of the block's first character within the document.
QTextCharFormat charFormat() const
Returns the QTextCharFormat that describes the block's character format.
QTextBlock previous() const
Returns the text block in the document before this block, or an empty text block if this is the first...
QString anchorHref() const
Returns the text format's hypertext link, or an empty string if none has been set.
QFont font() const
Returns the font for this character format.
\reentrant \inmodule QtGui
MoveMode
\value MoveAnchor Moves the anchor to the same position as the cursor itself.
MoveOperation
\value NoMove Keep the cursor where it is
int position() const
Returns the absolute position of the cursor within the document.
QTextFormatCollection * formatCollection()
static const QTextDocumentPrivate * get(const QTextDocument *document)
FragmentMap::ConstIterator FragmentIterator
FragmentIterator find(int pos) const
\reentrant \inmodule QtGui
QTextBlock findBlockByLineNumber(int blockNumber) const
void setDefaultTextOption(const QTextOption &option)
QTextBlock findBlockByNumber(int blockNumber) const
int blockCount
the number of text blocks in the document.
QAbstractTextDocumentLayout * documentLayout() const
Returns the document layout for this document.
QTextOption defaultTextOption() const
the default text option will be set on all \l{QTextLayout}s in the document.
void setDefaultFont(const QFont &font)
Sets the default font to use in the document layout.
QTextBlock findBlock(int pos) const
Returns the text block that contains the {pos}-th character.
QTextBlock firstBlock() const
void setDocumentLayout(QAbstractTextDocumentLayout *layout)
Sets the document to use the given layout.
QTextBlock lastBlock() const
void setTextWidth(qreal width)
QTextCharFormat charFormat(int index) const
QBrush background() const
Returns the brush used to paint the document's background.
QTextLine lineForTextPosition(int pos) const
Returns the line that contains the cursor position specified by pos.
QTextLine createLine()
Returns a new text line to be laid out if there is text to be inserted into the layout; otherwise ret...
void beginLayout()
Begins the layout process.
int lineCount() const
Returns the number of lines in this text layout.
QTextLine lineAt(int i) const
Returns the {i}-th line of text in this text layout.
void setTextOption(const QTextOption &option)
Sets the text option structure that controls the layout process to the given option.
void endLayout()
Ends the layout process.
QRectF boundingRect() const
The smallest rectangle that contains all the lines in the layout.
int textStart() const
Returns the start of the line from the beginning of the string passed to the QTextLayout.
QRectF naturalTextRect() const
Returns the rectangle covered by the line.
qreal naturalTextWidth() const
Returns the width of the line that is occupied by text.
@ CursorBetweenCharacters
int textLength() const
Returns the length of the text in the line.
@ AddSpaceForLineAndParagraphSeparators
WrapMode
This enum describes how text is wrapped in a document.
void setPlainText(const QString &text)
QTextCursor textCursor() const
void redoAvailable(bool b)
void appendPlainText(const QString &text)
void cursorPositionChanged()
virtual QMimeData * createMimeDataFromSelection() const
void setTextCursor(const QTextCursor &cursor, bool selectionClipboard=false)
void undoAvailable(bool b)
void setAcceptRichText(bool accept)
void modificationChanged(bool m)
void updateRequest(const QRectF &rect=QRectF())
void setDocument(QTextDocument *document)
void append(const QString &text)
void documentSizeChanged(const QSizeF &)
virtual void insertFromMimeData(const QMimeData *source)
virtual bool canInsertFromMimeData(const QMimeData *source) const
void setPalette(const QPalette &pal)
QTextDocument * document() const
void appendHtml(const QString &html)
void blockCountChanged(int newBlockCount)
void copyAvailable(bool b)
QSet< QString >::iterator it
QVector3D vmax(const QVector3D &a, const QVector3D &b)
Combined button and popup list for selecting options.
@ ImInputItemClipRectangle
@ NavigationModeKeypadDirectional
@ LinksAccessibleByKeyboard
@ TextSelectableByKeyboard
@ MouseEventNotSynthesized
constexpr const T & qMin(const T &a, const T &b)
constexpr const T & qMax(const T &a, const T &b)
static bool contains(const QJsonArray &haystack, unsigned needle)
GLboolean GLboolean GLboolean b
GLsizei const GLfloat * v
[13]
GLint GLint GLint GLint GLint x
[0]
GLint GLsizei GLsizei height
GLboolean GLboolean GLboolean GLboolean a
[7]
GLbitfield GLuint64 timeout
[4]
GLenum GLenum GLsizei const GLuint GLboolean enabled
GLsizei GLsizei GLfloat distance
GLenum GLuint GLintptr offset
GLint GLsizei GLsizei GLenum format
GLfloat GLfloat GLfloat GLfloat maxX
GLfloat GLfloat GLfloat GLfloat h
GLsizei GLsizei GLchar * source
GLdouble GLdouble GLdouble GLdouble q
static QT_BEGIN_NAMESPACE bool shouldEnableInputMethod(QPlainTextEdit *control)
static void fillBackground(QPainter *p, const QRectF &rect, QBrush brush, const QRectF &gradientRect=QRectF())
static qreal position(const QQuickItem *item, QQuickAnchors::Anchor anchorLine)
static QT_BEGIN_NAMESPACE QAsn1Element wrap(quint8 type, const QAsn1Element &child)
static void fillBackground(QPainter *p, const QRectF &rect, QBrush brush, const QPointF &origin, const QRectF &gradientRect=QRectF())
QVideoFrameFormat::PixelFormat fmt
QGraphicsWidget * textEdit
view viewport() -> scroll(dx, dy, deviceRect)
app setAttribute(Qt::AA_DontShowIconsInMenus)
\reentrant \inmodule QtGui
\variable QAbstractTextDocumentLayout::PaintContext::cursorPosition
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent