summaryrefslogtreecommitdiffstats
path: root/src/widgets/widgets/qtextedit.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/widgets/widgets/qtextedit.cpp')
-rw-r--r--src/widgets/widgets/qtextedit.cpp320
1 files changed, 142 insertions, 178 deletions
diff --git a/src/widgets/widgets/qtextedit.cpp b/src/widgets/widgets/qtextedit.cpp
index dd2ea3f18f..90884dd438 100644
--- a/src/widgets/widgets/qtextedit.cpp
+++ b/src/widgets/widgets/qtextedit.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2019 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtWidgets module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2019 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qtextedit_p.h"
#if QT_CONFIG(lineedit)
@@ -58,7 +22,7 @@
#endif
#include <qstyle.h>
#include <qtimer.h>
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
#include <qaccessible.h>
#endif
#include "private/qtextdocumentlayout_p.h"
@@ -79,7 +43,11 @@ QT_BEGIN_NAMESPACE
static inline bool shouldEnableInputMethod(QTextEdit *textedit)
{
+#if defined (Q_OS_ANDROID)
+ return !textedit->isReadOnly() || (textedit->textInteractionFlags() & Qt::TextSelectableByMouse);
+#else
return !textedit->isReadOnly();
+#endif
}
class QTextEditControl : public QWidgetTextControl
@@ -117,11 +85,10 @@ public:
};
QTextEditPrivate::QTextEditPrivate()
- : control(0),
+ : control(nullptr),
autoFormatting(QTextEdit::AutoNone), tabChangesFocus(false),
lineWrap(QTextEdit::WidgetWidth), lineWrapColumnOrWidth(0),
- wordWrap(QTextOption::WrapAtWordBoundaryOrAnywhere), clickCausedFocus(0),
- textFormat(Qt::AutoText)
+ wordWrap(QTextOption::WrapAtWordBoundaryOrAnywhere), clickCausedFocus(0)
{
ignoreAutomaticScrollbarAdjustment = false;
preferRichText = false;
@@ -129,6 +96,12 @@ QTextEditPrivate::QTextEditPrivate()
inDrag = false;
}
+QTextEditPrivate::~QTextEditPrivate()
+{
+ for (const QMetaObject::Connection &connection : connections)
+ QObject::disconnect(connection);
+}
+
void QTextEditPrivate::createAutoBulletList()
{
QTextCursor cursor = control->textCursor();
@@ -155,24 +128,34 @@ void QTextEditPrivate::init(const QString &html)
control = new QTextEditControl(q);
control->setPalette(q->palette());
- QObject::connect(control, SIGNAL(microFocusChanged()), q, SLOT(updateMicroFocus()));
- QObject::connect(control, SIGNAL(documentSizeChanged(QSizeF)), q, SLOT(_q_adjustScrollbars()));
- QObject::connect(control, SIGNAL(updateRequest(QRectF)), q, SLOT(_q_repaintContents(QRectF)));
- QObject::connect(control, SIGNAL(visibilityRequest(QRectF)), q, SLOT(_q_ensureVisible(QRectF)));
- QObject::connect(control, SIGNAL(currentCharFormatChanged(QTextCharFormat)),
- q, SLOT(_q_currentCharFormatChanged(QTextCharFormat)));
-
- QObject::connect(control, SIGNAL(textChanged()), q, SIGNAL(textChanged()));
- QObject::connect(control, SIGNAL(undoAvailable(bool)), q, SIGNAL(undoAvailable(bool)));
- QObject::connect(control, SIGNAL(redoAvailable(bool)), q, SIGNAL(redoAvailable(bool)));
- QObject::connect(control, SIGNAL(copyAvailable(bool)), q, SIGNAL(copyAvailable(bool)));
- QObject::connect(control, SIGNAL(selectionChanged()), q, SIGNAL(selectionChanged()));
- QObject::connect(control, SIGNAL(cursorPositionChanged()), q, SLOT(_q_cursorPositionChanged()));
-#if QT_CONFIG(cursor)
- QObject::connect(control, SIGNAL(blockMarkerHovered(QTextBlock)), q, SLOT(_q_hoveredBlockWithMarkerChanged(QTextBlock)));
-#endif
-
- QObject::connect(control, SIGNAL(textChanged()), q, SLOT(updateMicroFocus()));
+ connections = {
+ QObjectPrivate::connect(control, &QTextEditControl::documentSizeChanged,
+ this, &QTextEditPrivate::adjustScrollbars),
+ QObjectPrivate::connect(control, &QTextEditControl::updateRequest,
+ this, &QTextEditPrivate::repaintContents),
+ QObjectPrivate::connect(control, &QTextEditControl::visibilityRequest,
+ this, &QTextEditPrivate::ensureVisible),
+ QObjectPrivate::connect(control, &QTextEditControl::blockMarkerHovered,
+ this, &QTextEditPrivate::hoveredBlockWithMarkerChanged),
+ QObjectPrivate::connect(control, &QTextEditControl::cursorPositionChanged,
+ this, &QTextEditPrivate::cursorPositionChanged),
+ QObject::connect(control, &QTextEditControl::microFocusChanged,
+ q, [q]() { q->updateMicroFocus(); }),
+ QObject::connect(control, &QTextEditControl::currentCharFormatChanged,
+ q, &QTextEdit::currentCharFormatChanged),
+ QObject::connect(control, &QTextEditControl::textChanged,
+ q, &QTextEdit::textChanged),
+ QObject::connect(control, &QTextEditControl::undoAvailable,
+ q, &QTextEdit::undoAvailable),
+ QObject::connect(control, &QTextEditControl::redoAvailable,
+ q, &QTextEdit::redoAvailable),
+ QObject::connect(control, &QTextEditControl::copyAvailable,
+ q, &QTextEdit::copyAvailable),
+ QObject::connect(control, &QTextEditControl::selectionChanged,
+ q, &QTextEdit::selectionChanged),
+ QObject::connect(control, &QTextEditControl::textChanged,
+ q, [q]() { q->updateMicroFocus(); }),
+ };
QTextDocument *doc = control->document();
// set a null page size initially to avoid any relayouting until the textedit
@@ -202,7 +185,7 @@ void QTextEditPrivate::init(const QString &html)
#endif
}
-void QTextEditPrivate::_q_repaintContents(const QRectF &contentsRect)
+void QTextEditPrivate::repaintContents(const QRectF &contentsRect)
{
if (!contentsRect.isValid()) {
viewport->update();
@@ -220,19 +203,19 @@ void QTextEditPrivate::_q_repaintContents(const QRectF &contentsRect)
viewport->update(r);
}
-void QTextEditPrivate::_q_cursorPositionChanged()
+void QTextEditPrivate::cursorPositionChanged()
{
Q_Q(QTextEdit);
emit q->cursorPositionChanged();
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
QAccessibleTextCursorEvent event(q, q->textCursor().position());
QAccessible::updateAccessibility(&event);
#endif
}
-#if QT_CONFIG(cursor)
-void QTextEditPrivate::_q_hoveredBlockWithMarkerChanged(const QTextBlock &block)
+void QTextEditPrivate::hoveredBlockWithMarkerChanged(const QTextBlock &block)
{
+#if QT_CONFIG(cursor)
Q_Q(QTextEdit);
Qt::CursorShape cursor = cursorToRestoreAfterHover;
if (block.isValid() && !q->isReadOnly()) {
@@ -244,8 +227,8 @@ void QTextEditPrivate::_q_hoveredBlockWithMarkerChanged(const QTextBlock &block)
}
}
viewport->setCursor(cursor);
-}
#endif
+}
void QTextEditPrivate::pageUpDown(QTextCursor::MoveOperation op, QTextCursor::MoveMode moveMode)
{
@@ -270,7 +253,7 @@ void QTextEditPrivate::pageUpDown(QTextCursor::MoveOperation op, QTextCursor::Mo
vbar->triggerAction(QAbstractSlider::SliderPageStepAdd);
}
}
- control->setTextCursor(cursor);
+ control->setTextCursor(cursor, moveMode == QTextCursor::KeepAnchor);
}
#if QT_CONFIG(scrollbar)
@@ -294,7 +277,7 @@ static QSize documentSize(QWidgetTextControl *control)
return docSize;
}
-void QTextEditPrivate::_q_adjustScrollbars()
+void QTextEditPrivate::adjustScrollbars()
{
if (ignoreAutomaticScrollbarAdjustment)
return;
@@ -344,12 +327,12 @@ void QTextEditPrivate::_q_adjustScrollbars()
#endif
// rect is in content coordinates
-void QTextEditPrivate::_q_ensureVisible(const QRectF &_rect)
+void QTextEditPrivate::ensureVisible(const QRectF &_rect)
{
const QRect rect = _rect.toRect();
if ((vbar->isVisible() && vbar->maximum() < rect.bottom())
|| (hbar->isVisible() && hbar->maximum() < rect.right()))
- _q_adjustScrollbars();
+ adjustScrollbars();
const int visibleWidth = viewport->width();
const int visibleHeight = viewport->height();
const bool rtl = q_func()->isRightToLeft();
@@ -572,7 +555,7 @@ void QTextEditPrivate::_q_ensureVisible(const QRectF &_rect)
of the movement keystrokes, for example, \e{Shift+Right}
will select the character to the right, and \e{Shift+Ctrl+Right} will select the word to the right, etc.
- \sa QTextDocument, QTextCursor, {Application Example},
+ \sa QTextDocument, QTextCursor,
{Syntax Highlighter Example}, {Rich Text Processing}
*/
@@ -580,8 +563,9 @@ void QTextEditPrivate::_q_ensureVisible(const QRectF &_rect)
\property QTextEdit::plainText
\since 4.3
- This property gets and sets the text editor's contents as plain
- text. Previous contents are removed and undo/redo history is reset
+ \brief the text editor's contents as plain text.
+
+ Previous contents are removed and undo/redo history is reset
when the property is set. currentCharFormat() is also reset, unless
textCursor() is already at the beginning of the document.
@@ -598,7 +582,7 @@ void QTextEditPrivate::_q_ensureVisible(const QRectF &_rect)
/*!
\property QTextEdit::undoRedoEnabled
- \brief whether undo and redo are enabled
+ \brief whether undo and redo are enabled.
Users are only able to undo or redo actions if this property is
true, and if there is an action that can be undone (or redone).
@@ -685,7 +669,7 @@ qreal QTextEdit::fontPointSize() const
QString QTextEdit::fontFamily() const
{
Q_D(const QTextEdit);
- return d->control->textCursor().charFormat().fontFamily();
+ return d->control->textCursor().charFormat().fontFamilies().toStringList().value(0, QString());
}
/*!
@@ -744,7 +728,8 @@ QColor QTextEdit::textColor() const
QColor QTextEdit::textBackgroundColor() const
{
Q_D(const QTextEdit);
- return d->control->textCursor().charFormat().background().color();
+ const QBrush &brush = d->control->textCursor().charFormat().background();
+ return brush.style() == Qt::NoBrush ? Qt::transparent : brush.color();
}
/*!
@@ -877,7 +862,7 @@ QTextCursor QTextEdit::textCursor() const
void QTextEdit::setFontFamily(const QString &fontFamily)
{
QTextCharFormat fmt;
- fmt.setFontFamily(fontFamily);
+ fmt.setFontFamilies({fontFamily});
mergeCurrentCharFormat(fmt);
}
@@ -1095,30 +1080,38 @@ void QTextEdit::selectAll()
bool QTextEdit::event(QEvent *e)
{
Q_D(QTextEdit);
-#ifndef QT_NO_CONTEXTMENU
- if (e->type() == QEvent::ContextMenu
- && static_cast<QContextMenuEvent *>(e)->reason() == QContextMenuEvent::Keyboard) {
- Q_D(QTextEdit);
- ensureCursorVisible();
- const QPoint cursorPos = cursorRect().center();
- QContextMenuEvent ce(QContextMenuEvent::Keyboard, cursorPos, d->viewport->mapToGlobal(cursorPos));
- ce.setAccepted(e->isAccepted());
- const bool result = QAbstractScrollArea::event(&ce);
- e->setAccepted(ce.isAccepted());
- return result;
- } else if (e->type() == QEvent::ShortcutOverride
- || e->type() == QEvent::ToolTip) {
+ switch (e->type()) {
+ case QEvent::ShortcutOverride:
+ case QEvent::ToolTip:
d->sendControlEvent(e);
- }
-#else
- Q_UNUSED(d)
+ break;
+ case QEvent::WindowActivate:
+ case QEvent::WindowDeactivate:
+ d->control->setPalette(palette());
+ break;
+#ifndef QT_NO_CONTEXTMENU
+ case QEvent::ContextMenu:
+ if (static_cast<QContextMenuEvent *>(e)->reason() == QContextMenuEvent::Keyboard) {
+ ensureCursorVisible();
+ const QPoint cursorPos = cursorRect().center();
+ QContextMenuEvent ce(QContextMenuEvent::Keyboard, cursorPos, d->viewport->mapToGlobal(cursorPos));
+ ce.setAccepted(e->isAccepted());
+ const bool result = QAbstractScrollArea::event(&ce);
+ e->setAccepted(ce.isAccepted());
+ return result;
+ }
+ break;
#endif // QT_NO_CONTEXTMENU
#ifdef QT_KEYPAD_NAVIGATION
- if (e->type() == QEvent::EnterEditFocus || e->type() == QEvent::LeaveEditFocus) {
+ case QEvent::EnterEditFocus:
+ case QEvent::LeaveEditFocus:
if (QApplicationPrivate::keypadNavigationEnabled())
d->sendControlEvent(e);
- }
+ break;
#endif
+ default:
+ break;
+ }
return QAbstractScrollArea::event(e);
}
@@ -1272,6 +1265,7 @@ QString QTextEdit::toHtml() const
The default is \c MarkdownDialectGitHub.
\sa plainText, html, QTextDocument::toMarkdown(), QTextDocument::setMarkdown()
+ \since 5.14
*/
#endif
@@ -1401,8 +1395,8 @@ void QTextEdit::keyPressEvent(QKeyEvent *e)
const QString text = e->text();
if (cursor.atBlockStart()
&& (d->autoFormatting & AutoBulletList)
- && (text.length() == 1)
- && (text.at(0) == QLatin1Char('-') || text.at(0) == QLatin1Char('*'))
+ && (text.size() == 1)
+ && (text.at(0) == u'-' || text.at(0) == u'*')
&& (!cursor.currentList())) {
d->createAutoBulletList();
@@ -1450,8 +1444,10 @@ void QTextEdit::keyPressEvent(QKeyEvent *e)
*/
void QTextEdit::keyReleaseEvent(QKeyEvent *e)
{
-#ifdef QT_KEYPAD_NAVIGATION
Q_D(QTextEdit);
+ if (!isReadOnly())
+ d->handleSoftwareInputPanel();
+#ifdef QT_KEYPAD_NAVIGATION
if (QApplicationPrivate::keypadNavigationEnabled()) {
if (!e->isAutoRepeat() && e->key() == Qt::Key_Back
&& d->deleteAllTimer.isActive()) {
@@ -1502,10 +1498,10 @@ void QTextEdit::resizeEvent(QResizeEvent *e)
QVariant alignmentProperty = doc->documentLayout()->property("contentHasAlignment");
if (!doc->pageSize().isNull()
- && alignmentProperty.type() == QVariant::Bool
+ && alignmentProperty.userType() == QMetaType::Bool
&& !alignmentProperty.toBool()) {
- d->_q_adjustScrollbars();
+ d->adjustScrollbars();
return;
}
}
@@ -1514,7 +1510,7 @@ void QTextEdit::resizeEvent(QResizeEvent *e)
&& e->oldSize().width() != e->size().width())
d->relayoutDocument();
else
- d->_q_adjustScrollbars();
+ d->adjustScrollbars();
}
void QTextEditPrivate::relayoutDocument()
@@ -1536,7 +1532,7 @@ void QTextEditPrivate::relayoutDocument()
else
lastUsedSize = layout->documentSize().toSize();
- // ignore calls to _q_adjustScrollbars caused by an emission of the
+ // ignore calls to adjustScrollbars caused by an emission of the
// usedSizeChanged() signal in the layout, as we're calling it
// later on our own anyway (or deliberately not) .
const bool oldIgnoreScrollbarAdjustment = ignoreAutomaticScrollbarAdjustment;
@@ -1547,7 +1543,7 @@ void QTextEditPrivate::relayoutDocument()
width = lineWrapColumnOrWidth;
else if (lineWrap == QTextEdit::NoWrap) {
QVariant alignmentProperty = doc->documentLayout()->property("contentHasAlignment");
- if (alignmentProperty.type() == QVariant::Bool && !alignmentProperty.toBool()) {
+ if (alignmentProperty.userType() == QMetaType::Bool && !alignmentProperty.toBool()) {
width = 0;
}
@@ -1575,7 +1571,7 @@ void QTextEditPrivate::relayoutDocument()
// its size. So a layout with less width _can_ take up less vertical space, too.
// If the wider case causes a vertical scroll bar to appear and the narrower one
// (narrower because the vertical scroll bar takes up horizontal space)) to disappear
- // again then we have an endless loop, as _q_adjustScrollBars sets new ranges on the
+ // again then we have an endless loop, as adjustScrollbars sets new ranges on the
// scroll bars, the QAbstractScrollArea will find out about it and try to show/hide
// the scroll bars again. That's why we try to detect this case here and break out.
//
@@ -1588,7 +1584,7 @@ void QTextEditPrivate::relayoutDocument()
&& usedSize.height() <= viewport->height())
return;
- _q_adjustScrollbars();
+ adjustScrollbars();
}
void QTextEditPrivate::paint(QPainter *p, QPaintEvent *e)
@@ -1626,6 +1622,8 @@ void QTextEditPrivate::paint(QPainter *p, QPaintEvent *e)
This event handler can be reimplemented in a subclass to receive paint events passed in \a event.
It is usually unnecessary to reimplement this function in a subclass of QTextEdit.
+\note If you create a QPainter, it must operate on the \l{QAbstractScrollArea::}{viewport()}.
+
\warning The underlying text document must not be modified from within a reimplementation
of this function.
*/
@@ -1636,12 +1634,6 @@ void QTextEdit::paintEvent(QPaintEvent *e)
d->paint(&p, e);
}
-void QTextEditPrivate::_q_currentCharFormatChanged(const QTextCharFormat &fmt)
-{
- Q_Q(QTextEdit);
- emit q->currentCharFormatChanged(fmt);
-}
-
void QTextEditPrivate::updateDefaultTextOption()
{
QTextDocument *doc = control->document();
@@ -1676,7 +1668,7 @@ void QTextEdit::mouseMoveEvent(QMouseEvent *e)
{
Q_D(QTextEdit);
d->inDrag = false; // paranoia
- const QPoint pos = e->pos();
+ const QPoint pos = e->position().toPoint();
d->sendControlEvent(e);
if (!(e->buttons() & Qt::LeftButton))
return;
@@ -1699,7 +1691,7 @@ void QTextEdit::mouseReleaseEvent(QMouseEvent *e)
d->autoScrollTimer.stop();
ensureCursorVisible();
}
- if (!isReadOnly() && rect().contains(e->pos()))
+ if (!isReadOnly() && rect().contains(e->position().toPoint()))
d->handleSoftwareInputPanel(e->button(), d->clickCausedFocus);
d->clickCausedFocus = 0;
}
@@ -1770,7 +1762,7 @@ void QTextEdit::dragLeaveEvent(QDragLeaveEvent *e)
void QTextEdit::dragMoveEvent(QDragMoveEvent *e)
{
Q_D(QTextEdit);
- d->autoScrollDragPos = e->pos();
+ d->autoScrollDragPos = e->position().toPoint();
if (!d->autoScrollTimer.isActive())
d->autoScrollTimer.start(100, this);
d->sendControlEvent(e);
@@ -1800,6 +1792,10 @@ void QTextEdit::inputMethodEvent(QInputMethodEvent *e)
setEditFocus(true);
#endif
d->sendControlEvent(e);
+ const bool emptyEvent = e->preeditString().isEmpty() && e->commitString().isEmpty()
+ && e->attributes().isEmpty();
+ if (emptyEvent)
+ return;
ensureCursorVisible();
}
@@ -1827,25 +1823,29 @@ QVariant QTextEdit::inputMethodQuery(Qt::InputMethodQuery query, QVariant argume
{
Q_D(const QTextEdit);
switch (query) {
- case Qt::ImHints:
- case Qt::ImInputItemClipRectangle:
+ case Qt::ImEnabled:
+ return isEnabled() && !isReadOnly();
+ case Qt::ImHints:
+ case Qt::ImInputItemClipRectangle:
return QWidget::inputMethodQuery(query);
+ case Qt::ImReadOnly:
+ return isReadOnly();
default:
break;
}
const QPointF offset(-d->horizontalOffset(), -d->verticalOffset());
- switch (argument.type()) {
- case QVariant::RectF:
+ switch (argument.userType()) {
+ case QMetaType::QRectF:
argument = argument.toRectF().translated(-offset);
break;
- case QVariant::PointF:
+ case QMetaType::QPointF:
argument = argument.toPointF() - offset;
break;
- case QVariant::Rect:
+ case QMetaType::QRect:
argument = argument.toRect().translated(-offset.toPoint());
break;
- case QVariant::Point:
+ case QMetaType::QPoint:
argument = argument.toPoint() - offset;
break;
default:
@@ -1853,14 +1853,14 @@ QVariant QTextEdit::inputMethodQuery(Qt::InputMethodQuery query, QVariant argume
}
const QVariant v = d->control->inputMethodQuery(query, argument);
- switch (v.type()) {
- case QVariant::RectF:
+ switch (v.userType()) {
+ case QMetaType::QRectF:
return v.toRectF().translated(offset);
- case QVariant::PointF:
+ case QMetaType::QPointF:
return v.toPointF() + offset;
- case QVariant::Rect:
+ case QMetaType::QRect:
return v.toRect().translated(offset.toPoint());
- case QVariant::Point:
+ case QMetaType::QPoint:
return v.toPoint() + offset.toPoint();
default:
break;
@@ -1913,7 +1913,7 @@ void QTextEdit::changeEvent(QEvent *e)
if (e->type() == QEvent::ApplicationFontChange
|| e->type() == QEvent::FontChange) {
d->control->document()->setDefaultFont(font());
- } else if(e->type() == QEvent::ActivationChange) {
+ } else if (e->type() == QEvent::ActivationChange) {
if (!isActiveWindow())
d->autoScrollTimer.stop();
} else if (e->type() == QEvent::EnabledChange) {
@@ -2052,33 +2052,18 @@ void QTextEdit::setOverwriteMode(bool overwrite)
d->control->setOverwriteMode(overwrite);
}
-#if QT_DEPRECATED_SINCE(5, 10)
-/*!
- \property QTextEdit::tabStopWidth
- \brief the tab stop width in pixels
- \since 4.1
- \deprecated in Qt 5.10. Use tabStopDistance instead.
-
- By default, this property contains a value of 80 pixels.
-*/
-
-int QTextEdit::tabStopWidth() const
-{
- return qRound(tabStopDistance());
-}
-
-void QTextEdit::setTabStopWidth(int width)
-{
- setTabStopDistance(width);
-}
-#endif
-
/*!
\property QTextEdit::tabStopDistance
\brief the tab stop distance in pixels
\since 5.10
By default, this property contains a value of 80 pixels.
+
+ Do not set a value less than the \l {QFontMetrics::}{horizontalAdvance()}
+ of the QChar::VisualTabCharacter character, otherwise the tab-character
+ will be drawn incompletely.
+
+ \sa QTextOption::ShowTabsAndSpaces, QTextDocument::defaultTextOption
*/
qreal QTextEdit::tabStopDistance() const
@@ -2120,7 +2105,7 @@ void QTextEdit::setCursorWidth(int width)
\brief whether the text edit accepts rich text insertions by the user
\since 4.1
- When this propery is set to false text edit will accept only
+ When this property is set to false text edit will accept only
plain text input from the user. For example through clipboard or drag and drop.
This property's default is true.
@@ -2244,7 +2229,7 @@ void QTextEdit::insertFromMimeData(const QMimeData *source)
bool QTextEdit::isReadOnly() const
{
Q_D(const QTextEdit);
- return !(d->control->textInteractionFlags() & Qt::TextEditable);
+ return !d->control || !(d->control->textInteractionFlags() & Qt::TextEditable);
}
void QTextEdit::setReadOnly(bool ro)
@@ -2401,7 +2386,7 @@ void QTextEdit::scrollToAnchor(const QString &name)
QPointF p = d->control->anchorPosition(name);
const int newPosition = qRound(p.y());
if ( d->vbar->maximum() < newPosition )
- d->_q_adjustScrollbars();
+ d->adjustScrollbars();
d->vbar->setValue(newPosition);
}
@@ -2609,38 +2594,20 @@ bool QTextEdit::find(const QString &exp, QTextDocument::FindFlags options)
}
/*!
- \fn bool QTextEdit::find(const QRegExp &exp, QTextDocument::FindFlags options)
-
- \since 5.3
- \overload
-
- Finds the next occurrence, matching the regular expression, \a exp, using the given
- \a options. The QTextDocument::FindCaseSensitively option is ignored for this overload,
- use QRegExp::caseSensitivity instead.
-
- Returns \c true if a match was found and changes the cursor to select the match;
- otherwise returns \c false.
-*/
-#ifndef QT_NO_REGEXP
-bool QTextEdit::find(const QRegExp &exp, QTextDocument::FindFlags options)
-{
- Q_D(QTextEdit);
- return d->control->find(exp, options);
-}
-#endif
-
-/*!
\fn bool QTextEdit::find(const QRegularExpression &exp, QTextDocument::FindFlags options)
\since 5.13
\overload
Finds the next occurrence, matching the regular expression, \a exp, using the given
- \a options. The QTextDocument::FindCaseSensitively option is ignored for this overload,
- use QRegularExpression::CaseInsensitiveOption instead.
+ \a options.
Returns \c true if a match was found and changes the cursor to select the match;
otherwise returns \c false.
+
+ \warning For historical reasons, the case sensitivity option set on
+ \a exp is ignored. Instead, the \a options are used to determine
+ if the search is case sensitive or not.
*/
#if QT_CONFIG(regularexpression)
bool QTextEdit::find(const QRegularExpression &exp, QTextDocument::FindFlags options)
@@ -2704,10 +2671,7 @@ bool QTextEdit::find(const QRegularExpression &exp, QTextDocument::FindFlags opt
*/
void QTextEdit::setText(const QString &text)
{
- Q_D(QTextEdit);
- Qt::TextFormat format = d->textFormat;
- if (d->textFormat == Qt::AutoText)
- format = Qt::mightBeRichText(text) ? Qt::RichText : Qt::PlainText;
+ Qt::TextFormat format = Qt::mightBeRichText(text) ? Qt::RichText : Qt::PlainText;
#ifndef QT_NO_TEXTHTMLPARSER
if (format == Qt::RichText)
setHtml(text);