aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/items/qquicktextedit.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/quick/items/qquicktextedit.cpp')
-rw-r--r--src/quick/items/qquicktextedit.cpp63
1 files changed, 47 insertions, 16 deletions
diff --git a/src/quick/items/qquicktextedit.cpp b/src/quick/items/qquicktextedit.cpp
index f739474908..0df71fc559 100644
--- a/src/quick/items/qquicktextedit.cpp
+++ b/src/quick/items/qquicktextedit.cpp
@@ -1592,15 +1592,20 @@ bool QQuickTextEdit::selectByMouse() const
void QQuickTextEdit::setSelectByMouse(bool on)
{
Q_D(QQuickTextEdit);
- if (d->selectByMouse != on) {
- d->selectByMouse = on;
- setKeepMouseGrab(on);
- if (on)
- d->control->setTextInteractionFlags(d->control->textInteractionFlags() | Qt::TextSelectableByMouse);
- else
- d->control->setTextInteractionFlags(d->control->textInteractionFlags() & ~Qt::TextSelectableByMouse);
- emit selectByMouseChanged(on);
- }
+ if (d->selectByMouse == on)
+ return;
+
+ d->selectByMouse = on;
+ setKeepMouseGrab(on);
+ if (on)
+ d->control->setTextInteractionFlags(d->control->textInteractionFlags() | Qt::TextSelectableByMouse);
+ else
+ d->control->setTextInteractionFlags(d->control->textInteractionFlags() & ~Qt::TextSelectableByMouse);
+
+#if QT_CONFIG(cursor)
+ d->updateMouseCursorShape();
+#endif
+ emit selectByMouseChanged(on);
}
/*!
@@ -1663,6 +1668,9 @@ void QQuickTextEdit::setReadOnly(bool r)
#if QT_CONFIG(im)
updateInputMethod(Qt::ImEnabled);
#endif
+#if QT_CONFIG(cursor)
+ d->updateMouseCursorShape();
+#endif
q_canPasteChanged();
emit readOnlyChanged(r);
if (!d->selectByKeyboardSet)
@@ -2247,9 +2255,13 @@ QSGNode *QQuickTextEdit::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *
}
}
+ bool createdNodeInView = false;
if (inView) {
if (!engine.hasContents()) {
+ if (node && !node->parent())
+ d->addCurrentTextNodeToRoot(&engine, rootNode, node, nodeIterator, nodeStart);
node = d->createTextNode();
+ createdNodeInView = true;
updateNodeTransform(node, nodeOffset);
nodeStart = block.position();
}
@@ -2259,13 +2271,13 @@ QSGNode *QQuickTextEdit::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *
if ((it.atEnd()) || block.next().position() >= firstCleanNode.startPos())
break; // last node that needed replacing or last block of the frame
-
QList<int>::const_iterator lowerBound = std::lower_bound(frameBoundaries.constBegin(), frameBoundaries.constEnd(), block.next().position());
if (node && (currentNodeSize > nodeBreakingSize || lowerBound == frameBoundaries.constEnd() || *lowerBound > nodeStart)) {
currentNodeSize = 0;
if (!node->parent())
d->addCurrentTextNodeToRoot(&engine, rootNode, node, nodeIterator, nodeStart);
- node = d->createTextNode();
+ if (!createdNodeInView)
+ node = d->createTextNode();
resetEngine(&engine, d->color, d->selectedTextColor, d->selectionColor);
nodeStart = block.next().position();
}
@@ -2450,7 +2462,7 @@ void QQuickTextEditPrivate::init()
updateDefaultTextOption();
q->updateSize();
#if QT_CONFIG(cursor)
- q->setCursor(Qt::IBeamCursor);
+ updateMouseCursorShape();
#endif
}
@@ -2734,9 +2746,8 @@ void QQuickTextEdit::q_linkHovered(const QString &link)
emit linkHovered(link);
#if QT_CONFIG(cursor)
if (link.isEmpty()) {
- setCursor(d->cursorToRestoreAfterHover);
+ d->updateMouseCursorShape();
} else if (cursor().shape() != Qt::PointingHandCursor) {
- d->cursorToRestoreAfterHover = cursor().shape();
setCursor(Qt::PointingHandCursor);
}
#endif
@@ -2747,9 +2758,8 @@ void QQuickTextEdit::q_markerHovered(bool hovered)
Q_D(QQuickTextEdit);
#if QT_CONFIG(cursor)
if (!hovered) {
- setCursor(d->cursorToRestoreAfterHover);
+ d->updateMouseCursorShape();
} else if (cursor().shape() != Qt::PointingHandCursor) {
- d->cursorToRestoreAfterHover = cursor().shape();
setCursor(Qt::PointingHandCursor);
}
#endif
@@ -3020,6 +3030,14 @@ bool QQuickTextEditPrivate::isLinkHoveredConnected()
IS_SIGNAL_CONNECTED(q, QQuickTextEdit, linkHovered, (const QString &));
}
+#if QT_CONFIG(cursor)
+void QQuickTextEditPrivate::updateMouseCursorShape()
+{
+ Q_Q(QQuickTextEdit);
+ q->setCursor(q->isReadOnly() && !q->selectByMouse() ? Qt::ArrowCursor : Qt::IBeamCursor);
+}
+#endif
+
/*!
\qmlsignal QtQuick::TextEdit::linkHovered(string link)
\since 5.2
@@ -3070,6 +3088,7 @@ void QQuickTextEdit::hoverEnterEvent(QHoverEvent *event)
Q_D(QQuickTextEdit);
if (d->isLinkHoveredConnected())
d->control->processEvent(event, QPointF(-d->xoff, -d->yoff));
+ event->ignore();
}
void QQuickTextEdit::hoverMoveEvent(QHoverEvent *event)
@@ -3077,6 +3096,7 @@ void QQuickTextEdit::hoverMoveEvent(QHoverEvent *event)
Q_D(QQuickTextEdit);
if (d->isLinkHoveredConnected())
d->control->processEvent(event, QPointF(-d->xoff, -d->yoff));
+ event->ignore();
}
void QQuickTextEdit::hoverLeaveEvent(QHoverEvent *event)
@@ -3084,6 +3104,7 @@ void QQuickTextEdit::hoverLeaveEvent(QHoverEvent *event)
Q_D(QQuickTextEdit);
if (d->isLinkHoveredConnected())
d->control->processEvent(event, QPointF(-d->xoff, -d->yoff));
+ event->ignore();
}
/*!
@@ -3303,6 +3324,16 @@ void QQuickTextEdit::clear()
d->control->clear();
}
+#ifndef QT_NO_DEBUG_STREAM
+QDebug operator<<(QDebug debug, const QQuickTextEditPrivate::Node &n)
+{
+ QDebugStateSaver saver(debug);
+ debug.space();
+ debug << "Node(startPos:" << n.m_startPos << "dirty:" << n.m_dirty << n.m_node << ')';
+ return debug;
+}
+#endif
+
QT_END_NAMESPACE
#include "moc_qquicktextedit_p.cpp"