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) {
275 if (newBr.height() == oldBr.height()) {
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;
391 if (maximumBlock.isValid()) {
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();
451 return ed->createMimeDataFromSelection();
457 return ed->canInsertFromMimeData(
source);
464 ed->insertFromMimeData(
source);
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) {
536 if (lr.top() >
pos.y()) {
538 }
else if (lr.bottom() <=
pos.y()) {
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) {
703 if (
h - voffset - lineRect.top() <=
height)
708 if (l >= lineCount) {
709 block = previousVisibleBlock;
713 }
else if (lr.top() < visible.
top()) {
728 : tabChangesFocus(
false)
729 , showCursorOnInitialShow(
false)
730 , backgroundVisible(
false)
731 , centerOnScroll(
false)
733 , clickCausedFocus(
false)
734 , pageUpDownLastCursorYIsValid(
false)
735 , placeholderTextShown(
false)
754 [
q](){
q->updateMicroFocus(); });
785 hbar->setSingleStep(20);
786 vbar->setSingleStep(1);
789 q->setAcceptDrops(
true);
823 QRect r = contentsRect.
adjusted(-1, -1, 1, 1).intersected(visibleRect).toAlignedRect();
827 r.translate(-xOffset, -yOffset);
829 emit q->updateRequest(
r, 0);
849 QTextBlock firstVisibleBlock =
q->firstVisibleBlock();
851 QRectF br =
q->blockBoundingRect(block);
861 block = block.
next();
862 br =
q->blockBoundingRect(block);
869 while (
line < lineCount - 1) {
884 moved =
cursor.movePosition(op, moveMode);
894 while (
h >= visible.
top()) {
902 QRectF br =
q->blockBoundingRect(block);
910 while (
line < lineCount) {
915 if (
line == lineCount) {
917 block = block.
next();
927 cursor.setVisualNavigation(
true);
932 moved =
cursor.movePosition(op, moveMode);
943#if QT_CONFIG(scrollbar)
957 int vSliderLength = 0;
960 const qreal visible =
viewport->rect().height() - margin - 1;
962 int visibleFromBottom = 0;
972 int layoutLineCount =
layout->lineCount();
975 while (lineNumber < layoutLineCount) {
978 if (lr.top() >=
y - visible)
982 if (lineNumber < layoutLineCount)
983 visibleFromBottom += (layoutLineCount - lineNumber);
987 visibleFromBottom += layoutLineCount;
991 vSliderLength = visibleFromBottom;
995 int lineSpacing =
q->fontMetrics().lineSpacing();
996 vSliderLength = lineSpacing != 0 ?
viewport->height() / lineSpacing : 0;
1000 vbar->setRange(0,
qMax(0, vmax));
1001 vbar->setPageStep(vSliderLength);
1002 int visualTopLine =
vmax;
1003 QTextBlock firstVisibleBlock =
q->firstVisibleBlock();
1004 if (firstVisibleBlock.
isValid())
1007 vbar->setValue(visualTopLine);
1009 hbar->setRange(0, (
int)documentSize.
width() -
viewport->width());
1010 hbar->setPageStep(
viewport->width());
1236 : QAbstractScrollArea(dd, parent)
1260 if (
d->documentLayoutPtr) {
1261 if (
d->documentLayoutPtr->priv()->mainViewPrivate ==
d)
1262 d->documentLayoutPtr->priv()->mainViewPrivate =
nullptr;
1290 qWarning(
"QPlainTextEdit::setDocument: Document set does not support QPlainTextDocumentLayout");
1298 d->updateDefaultTextOption();
1299 d->relayoutDocument();
1300 d->adjustScrollbars();
1311 return d->control->document();
1332 d->updatePlaceholderVisibility();
1339 return d->placeholderText;
1359 d->control->setTextCursor(
cursor);
1370 return d->control->textCursor();
1382 int cursorPos =
d->control->hitTest(
pos +
QPointF(
d->horizontalOffset(),
1383 d->verticalOffset()),
1425#ifndef QT_NO_CLIPBOARD
1470 d->control->paste();
1490 d->control->topBlock =
d->topLine =
d->topLineFracture = 0;
1491 d->control->clear();
1503 d->control->selectAll();
1512 switch (e->
type()) {
1513#ifndef QT_NO_CONTEXTMENU
1520 const bool result = QAbstractScrollArea::event(&ce);
1528 d->sendControlEvent(e);
1530#ifdef QT_KEYPAD_NAVIGATION
1531 case QEvent::EnterEditFocus:
1532 case QEvent::LeaveEditFocus:
1533 if (QApplicationPrivate::keypadNavigationEnabled())
1534 d->sendControlEvent(e);
1537#ifndef QT_NO_GESTURES
1544 d->originalOffsetY = vBar->value();
1551 int lineHeight = fm.height();
1552 int newX = hBar->value() - panGesture->delta().x();
1553 int newY =
d->originalOffsetY -
offset.y()/lineHeight;
1554 hBar->setValue(newX);
1555 vBar->setValue(newY);
1567 return QAbstractScrollArea::event(e);
1576 if (e->
timerId() ==
d->autoScrollTimer.timerId()) {
1577 QRect visible =
d->viewport->rect();
1580 pos =
d->autoScrollDragPos;
1585 pos =
d->viewport->mapFromGlobal(globalPos);
1592 int delta =
qMax(deltaX, deltaY);
1596 int timeout = 4900 / (delta * delta);
1597 d->autoScrollTimer.start(
timeout,
this);
1600 d->vbar->triggerAction(
pos.y() < visible.
center().y() ?
1604 d->hbar->triggerAction(
pos.x() < visible.
center().x() ?
1609#ifdef QT_KEYPAD_NAVIGATION
1610 else if (e->
timerId() ==
d->deleteAllTimer.timerId()) {
1611 d->deleteAllTimer.stop();
1636 d->control->setPlainText(
text);
1653#ifdef QT_KEYPAD_NAVIGATION
1656 if (QApplicationPrivate::keypadNavigationEnabled()) {
1658 setEditFocus(!hasEditFocus());
1660 if (!hasEditFocus())
1665 if (!
cursor.hasSelection() || charFmt.anchorHref().isEmpty()) {
1666 setEditFocus(
false);
1674 if (!QApplicationPrivate::keypadNavigationEnabled()
1675 || (QApplicationPrivate::keypadNavigationEnabled() && !hasEditFocus())) {
1681 if (QApplicationPrivate::keypadNavigationEnabled()) {
1683 if (e->
text()[0].isPrint()) {
1696#ifndef QT_NO_SHORTCUT
1698 Qt::TextInteractionFlags tif =
d->control->textInteractionFlags();
1733 d->sendControlEvent(e);
1744 QAbstractScrollArea::keyPressEvent(e);
1751 d->sendControlEvent(e);
1752#ifdef QT_KEYPAD_NAVIGATION
1757 if (QApplicationPrivate::keypadNavigationEnabled()) {
1766 if (QApplicationPrivate::keypadNavigationEnabled()
1775 if (QApplicationPrivate::keypadNavigationEnabled()) {
1777 setEditFocus(
false);
1779 }
else if (!
d->deleteAllTimer.isActive()) {
1781 d->deleteAllTimer.start(750,
this);
1801 d->handleSoftwareInputPanel();
1803#ifdef QT_KEYPAD_NAVIGATION
1804 if (QApplicationPrivate::keypadNavigationEnabled()) {
1806 &&
d->deleteAllTimer.isActive()) {
1807 d->deleteAllTimer.stop();
1814 }
else if (
cursor.atBlockStart() && blockFmt.indent() > 0) {
1815 blockFmt.setIndent(blockFmt.indent() - 1);
1816 cursor.setBlockFormat(blockFmt);
1818 cursor.deletePreviousChar();
1848 d->relayoutDocument();
1849 d->adjustScrollbars();
1863 ||
width > documentLayout->textWidth()) {
1865 documentLayout->setTextWidth(
width);
1873 if (!gradientRect.isNull()) {
1875 m.scale(gradientRect.width(), gradientRect.height());
1880 p->setBrushOrigin(
rect.topLeft());
1894 Q_ASSERT(qobject_cast<QPlainTextDocumentLayout*>(
document()->documentLayout()));
1912 er.setRight(
qMin(er.right(),
maxX));
1915 if (
d->placeHolderTextToBeShown()) {
1916 const QColor col =
d->control->palette().placeholderText().color();
1919 const int margin = int(
document()->documentMargin());
1934 block = block.
next();
1938 if (
r.bottom() >= er.top() &&
r.top() <= er.bottom()) {
1949 QList<QTextLayout::FormatRange> selections;
1951 int bllen = block.
length();
1952 for (
int i = 0;
i <
context.selections.size(); ++
i) {
1954 const int selStart =
range.cursor.selectionStart() - blpos;
1955 const int selEnd =
range.cursor.selectionEnd() - blpos;
1956 if (selStart < bllen && selEnd > 0
1957 && selEnd > selStart) {
1960 o.length = selEnd - selStart;
1962 selections.append(
o);
1971 if (
o.start +
o.length == bllen - 1)
1974 selections.append(
o);
1979 &&
context.cursorPosition >= blpos
1980 &&
context.cursorPosition < blpos + bllen);
1984 if (drawCursorAsBlock) {
1985 if (
context.cursorPosition == blpos + bllen - 1) {
1986 drawCursorAsBlock =
false;
1989 o.start =
context.cursorPosition - blpos;
1993 selections.append(
o);
1999 if ((drawCursor && !drawCursorAsBlock)
2000 || (editable &&
context.cursorPosition < -1
2002 int cpos =
context.cursorPosition;
2004 cpos =
layout->preeditAreaPosition() - (cpos + 2);
2014 block = block.
next();
2018 && (
centerOnScroll() || verticalScrollBar()->maximum() == verticalScrollBar()->minimum())) {
2036 if (
opt.wrapMode() != oldWrapMode)
2046#ifdef QT_KEYPAD_NAVIGATION
2047 if (QApplicationPrivate::keypadNavigationEnabled() && !hasEditFocus())
2050 d->sendControlEvent(e);
2060 d->sendControlEvent(e);
2064 const QRect visible =
d->viewport->rect();
2066 d->autoScrollTimer.stop();
2067 else if (!
d->autoScrollTimer.isActive())
2068 d->autoScrollTimer.start(100,
this);
2077 d->sendControlEvent(e);
2079 d->autoScrollTimer.stop();
2080 d->ensureCursorVisible();
2084 d->handleSoftwareInputPanel(e->
button(),
d->clickCausedFocus);
2085 d->clickCausedFocus = 0;
2093 d->sendControlEvent(e);
2103 return QAbstractScrollArea::focusNextPrevChild(
next);
2106#ifndef QT_NO_CONTEXTMENU
2125 d->sendControlEvent(e);
2129#if QT_CONFIG(draganddrop)
2132void QPlainTextEdit::dragEnterEvent(QDragEnterEvent *e)
2136 d->sendControlEvent(e);
2141void QPlainTextEdit::dragLeaveEvent(QDragLeaveEvent *e)
2145 d->autoScrollTimer.stop();
2146 d->sendControlEvent(e);
2151void QPlainTextEdit::dragMoveEvent(QDragMoveEvent *e)
2154 d->autoScrollDragPos = e->position().toPoint();
2155 if (!
d->autoScrollTimer.isActive())
2156 d->autoScrollTimer.start(100,
this);
2157 d->sendControlEvent(e);
2162void QPlainTextEdit::dropEvent(QDropEvent *e)
2166 d->autoScrollTimer.stop();
2167 d->sendControlEvent(e);
2177#ifdef QT_KEYPAD_NAVIGATION
2179 && QApplicationPrivate::keypadNavigationEnabled()
2180 && !hasEditFocus()) {
2185 d->sendControlEvent(e);
2198 d->setTopLine(
d->vbar->value(), dx);
2227 case QMetaType::QRectF:
2230 case QMetaType::QPointF:
2233 case QMetaType::QRect:
2236 case QMetaType::QPoint:
2244 switch (
v.userType()) {
2245 case QMetaType::QRectF:
2247 case QMetaType::QPointF:
2249 case QMetaType::QRect:
2250 return v.toRect().translated(
offset.toPoint());
2251 case QMetaType::QPoint:
2252 return v.toPoint() +
offset.toPoint();
2265 d->clickCausedFocus = 1;
2267 QAbstractScrollArea::focusInEvent(e);
2268 d->sendControlEvent(e);
2276 QAbstractScrollArea::focusOutEvent(e);
2277 d->sendControlEvent(e);
2285 if (
d->showCursorOnInitialShow) {
2286 d->showCursorOnInitialShow =
false;
2289 d->adjustScrollbars();
2297 QAbstractScrollArea::changeEvent(e);
2299 switch (e->
type()) {
2302 d->control->document()->setDefaultFont(
font());
2305 if (!isActiveWindow())
2306 d->autoScrollTimer.stop();
2311 d->sendControlEvent(e);
2317 d->sendControlEvent(e);
2326#if QT_CONFIG(wheelevent)
2327void QPlainTextEdit::wheelEvent(QWheelEvent *e)
2332 float delta = e->angleDelta().y() / 120.f;
2337 QAbstractScrollArea::wheelEvent(e);
2374 const float newSize =
f.pointSizeF() +
range;
2377 f.setPointSizeF(newSize);
2381#ifndef QT_NO_CONTEXTMENU
2394 return d->control->createStandardContextMenu(
QPointF(),
this);
2410 return d->control->createStandardContextMenu(
position,
this);
2420 return d->control->cursorForPosition(
d->mapToContents(
pos));
2434 r.
translate(-
d->horizontalOffset(),-(
int)
d->verticalOffset());
2445 QRect r =
d->control->cursorRect().toRect();
2446 r.
translate(-
d->horizontalOffset(),-(
int)
d->verticalOffset());
2468 return d->control->overwriteMode();
2474 d->control->setOverwriteMode(overwrite);
2494 return d->control->document()->defaultTextOption().tabStopDistance();
2504 d->control->document()->setDefaultTextOption(
opt);
2516 return d->control->cursorWidth();
2522 d->control->setCursorWidth(
width);
2538 d->control->setExtraSelections(selections);
2549 return d->control->extraSelections();
2565 return d->control->QWidgetTextControl::createMimeDataFromSelection();
2577 return d->control->QWidgetTextControl::canInsertFromMimeData(
source);
2590 d->control->QWidgetTextControl::insertFromMimeData(
source);
2618 d->control->setTextInteractionFlags(
flags);
2639 d->control->setTextInteractionFlags(
flags);
2645 return d->control->textInteractionFlags();
2659 d->control->mergeCurrentCharFormat(modifier);
2671 d->control->setCurrentCharFormat(
format);
2680 return d->control->currentCharFormat();
2696 d->control->insertPlainText(
text);
2712 d->control->moveCursor(operation,
mode);
2721 return d->control->canPaste();
2731#ifndef QT_NO_PRINTER
2735 d->control->print(printer);
2751 return d->tabChangesFocus;
2757 d->tabChangesFocus =
b;
2786 if (
d->lineWrap ==
wrap)
2789 d->updateDefaultTextOption();
2790 d->relayoutDocument();
2791 d->adjustScrollbars();
2813 if (
mode ==
d->wordWrap)
2816 d->updateDefaultTextOption();
2836 return d->backgroundVisible;
2842 if (visible ==
d->backgroundVisible)
2844 d->backgroundVisible = visible;
2845 d->updateViewport();
2868 return d->centerOnScroll;
2877 d->adjustScrollbars();
2890 return d->control->find(exp, options);
2909#if QT_CONFIG(regularexpression)
2913 return d->control->find(exp, options);
2994 int maximumBlockCount = document->maximumBlockCount();
2995 if (maximumBlockCount)
2996 document->setMaximumBlockCount(0);
2998 const bool atBottom =
q->isVisible()
3002 if (!
q->isVisible())
3020 if (maximumBlockCount > 0) {
3021 if (document->blockCount() > maximumBlockCount) {
3022 bool blockUpdate =
false;
3029 bool updatesBlocked = documentLayout->priv()->
blockUpdate;
3030 documentLayout->priv()->
blockUpdate = blockUpdate;
3033 cursor.removeSelectedText();
3034 documentLayout->priv()->
blockUpdate = updatesBlocked;
3036 document->setMaximumBlockCount(maximumBlockCount);
3048 vbar->setValue(vbar->maximum());
3081 QRect cr =
q->cursorRect();
3086 const bool rtl =
q->isRightToLeft();
3089 hbar->setValue(rtl ? hbar->maximum() -
x :
x);
3102 d->ensureCursorVisible(
d->centerOnScroll);
3124 return d->control->firstVisibleBlock();
3143 return QPointF(-
d->horizontalOffset(), -
d->verticalOffset());
3156 return d->control->blockBoundingRect(block);
3188 return d->control->getPaintContext(
d->viewport);
3233#include "moc_qplaintextedit.cpp"
3234#include "moc_qplaintextedit_p.cpp"
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)
Type type() const
Returns the event type.
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).
The QFocusEvent class contains event parameters for widget focus events.
Qt::FocusReason reason() const
Returns the reason for this focus event.
\reentrant \inmodule QtGui
The QGestureEvent class provides the description of triggered gestures.
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.
Qt::KeyboardModifiers modifiers() const
Returns the keyboard modifier flags that existed immediately after the event occurred.
QString text() const
Returns the Unicode text that this key generated.
bool isAutoRepeat() const
Returns true if this event comes from an auto-repeating key; returns false if it comes from an initia...
int key() const
Returns the code of the key that was pressed or released.
bool isEmpty() const override
\reimp
void remove(qsizetype i, qsizetype n=1)
Qt::MouseEventSource source() const
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.
const QRect & rect() const
Returns the rectangle that needs to be updated.
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.
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
uint pageUpDownLastCursorYIsValid
void pageUpDown(QTextCursor::MoveOperation op, QTextCursor::MoveMode moveMode, bool moveCursor=true)
QPlainTextEditControl * control
void repaintContents(const QRectF &contentsRect)
void updateDefaultTextOption()
void append(const QString &text, Qt::TextFormat format=Qt::AutoText)
void ensureVisible(int position, bool center, bool forceCenter=false)
bool placeHolderTextToBeShown() const
QTextOption::WrapMode wordWrap
void init(const QString &txt=QString())
uint placeholderTextShown
void updatePlaceholderVisibility()
QPlainTextEdit::LineWrapMode lineWrap
void setTopLine(int visualTopLine, int dx=0)
void verticalScrollbarActionTriggered(int action)
QPointer< QPlainTextDocumentLayout > documentLayoutPtr
uint showCursorOnInitialShow
qreal pageUpDownLastCursorY
void cursorPositionChanged()
void ensureCursorVisible(bool center=false)
void ensureViewportLayouted()
void setTopBlock(int newTopBlock, int newTopLine, int dx=0)
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 y() const noexcept
Returns the y coordinate of this point.
constexpr qreal & rx() noexcept
Returns a reference to the x coordinate of this point.
constexpr QPoint toPoint() const
Rounds the coordinates of this point to the nearest integer, and returns a QPoint object with the rou...
\inmodule QtCore\reentrant
\inmodule QtCore\reentrant
constexpr qreal bottom() const noexcept
Returns the y-coordinate of the rectangle's bottom edge.
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.
\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 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 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.
const QSize & oldSize() const
Returns the old size of the widget.
const QSize & size() const
Returns the new size of the widget.
The QShowEvent class provides an event that is sent when a widget is shown.
QPointF position() const
Returns the position of the point in this event, relative to the widget or item that received the eve...
Qt::MouseButton button() const
Returns the button that caused the event.
Qt::MouseButtons buttons() const
Returns the button state when the event was generated.
constexpr qreal width() const noexcept
Returns the width.
constexpr int width() const noexcept
Returns the width.
\macro QT_RESTRICTED_CAST_FROM_ASCII
bool isEmpty() const noexcept
Returns true if the string has no characters; otherwise returns false.
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.
int timerId() const
Returns the unique timer identifier, which is the same identifier as returned from QObject::startTime...
QRectF toRectF() const
Returns the variant as a QRectF if the variant has userType() \l QMetaType::QRect or \l QMetaType::QR...
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