Fix TextEdit/TextArea mouse cursor shape handling logic
Previously IBeamCursor was wrongly shown in case when TextEdit was readonly and not selectable by mouse. Now ArrowCursor will be shown in such case. Additionally removed own mouse cursor shape handling logic in TextArea, so it will be unified now with derived logic from TextEdit. This is a change from 23f78b6b76fb9350a472485e34857e1a4842e5d3: we no longer attempt to restore a cursor that was set via setCursor(). [ChangeLog][QtQuick][TextEdit] TextEdit and TextArea now set their own mouse cursors more consistently, but without regard for any external call to setCursor(). Fixes: QTBUG-104089 Pick-to: 6.3 6.4 Change-Id: Iba4e0cb55d555b0f360d7856346ff9e8393b9e1e Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
This commit is contained in:
parent
abc8550593
commit
175dfd25c2
|
@ -1568,15 +1568,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);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -1638,6 +1643,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);
|
||||
|
@ -2431,7 +2439,7 @@ void QQuickTextEditPrivate::init()
|
|||
updateDefaultTextOption();
|
||||
q->updateSize();
|
||||
#if QT_CONFIG(cursor)
|
||||
q->setCursor(Qt::IBeamCursor);
|
||||
updateMouseCursorShape();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -2715,9 +2723,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
|
||||
|
@ -2728,9 +2735,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
|
||||
|
@ -3001,6 +3007,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
|
||||
|
|
|
@ -111,6 +111,10 @@ public:
|
|||
Qt::LayoutDirection textDirection(const QString &text) const;
|
||||
bool isLinkHoveredConnected();
|
||||
|
||||
#if QT_CONFIG(cursor)
|
||||
void updateMouseCursorShape();
|
||||
#endif
|
||||
|
||||
void setNativeCursorEnabled(bool) {}
|
||||
void handleFocusEvent(QFocusEvent *event);
|
||||
void addCurrentTextNodeToRoot(QQuickTextNodeEngine *, QSGTransformNode *, QQuickTextNode*, TextNodeIterator&, int startPos);
|
||||
|
@ -176,7 +180,6 @@ public:
|
|||
Qt::InputMethodHints inputMethodHints;
|
||||
#endif
|
||||
UpdateType updateType;
|
||||
Qt::CursorShape cursorToRestoreAfterHover = Qt::IBeamCursor;
|
||||
|
||||
bool dirty : 1;
|
||||
bool richText : 1;
|
||||
|
|
|
@ -425,9 +425,6 @@ void QQuickTextAreaPrivate::readOnlyChanged(bool isReadOnly)
|
|||
if (QQuickAccessibleAttached *accessibleAttached = QQuickControlPrivate::accessibleAttached(q_func()))
|
||||
accessibleAttached->set_readOnly(isReadOnly);
|
||||
#endif
|
||||
#if QT_CONFIG(cursor)
|
||||
q_func()->setCursor(isReadOnly && !selectByMouse ? Qt::ArrowCursor : Qt::IBeamCursor);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if QT_CONFIG(accessibility)
|
||||
|
@ -509,9 +506,7 @@ QQuickTextArea::QQuickTextArea(QQuickItem *parent)
|
|||
setAcceptedMouseButtons(Qt::AllButtons);
|
||||
d->setImplicitResizeEnabled(false);
|
||||
d->pressHandler.control = this;
|
||||
#if QT_CONFIG(cursor)
|
||||
setCursor(Qt::IBeamCursor);
|
||||
#endif
|
||||
|
||||
QObjectPrivate::connect(this, &QQuickTextEdit::readOnlyChanged,
|
||||
d, &QQuickTextAreaPrivate::readOnlyChanged);
|
||||
}
|
||||
|
|
|
@ -2586,8 +2586,6 @@ void tst_qquicktextedit::linkHover()
|
|||
QCOMPARE(window.cursor().shape(), Qt::IBeamCursor);
|
||||
QCOMPARE(hover.last()[0].toString(), QString());
|
||||
|
||||
texteditObject->setCursor(Qt::OpenHandCursor);
|
||||
|
||||
QCursor::setPos(linkPos);
|
||||
QTRY_COMPARE(hover.count(), 3);
|
||||
QCOMPARE(window.cursor().shape(), Qt::PointingHandCursor);
|
||||
|
@ -2595,7 +2593,7 @@ void tst_qquicktextedit::linkHover()
|
|||
|
||||
QCursor::setPos(textPos);
|
||||
QTRY_COMPARE(hover.count(), 4);
|
||||
QCOMPARE(window.cursor().shape(), Qt::OpenHandCursor);
|
||||
QCOMPARE(window.cursor().shape(), Qt::IBeamCursor);
|
||||
QCOMPARE(hover.last()[0].toString(), QString());
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -33,6 +33,7 @@ private slots:
|
|||
void editable();
|
||||
void pageIndicator();
|
||||
void scrollBar();
|
||||
void textArea();
|
||||
};
|
||||
|
||||
tst_cursor::tst_cursor()
|
||||
|
@ -200,6 +201,19 @@ void tst_cursor::scrollBar()
|
|||
QCOMPARE(window->cursor().shape(), textArea->cursor().shape());
|
||||
}
|
||||
|
||||
// QTBUG-104089
|
||||
void tst_cursor::textArea()
|
||||
{
|
||||
QQuickTextArea textArea;
|
||||
QCOMPARE(textArea.cursor().shape(), Qt::IBeamCursor);
|
||||
|
||||
textArea.setReadOnly(true);
|
||||
QCOMPARE(textArea.cursor().shape(), Qt::ArrowCursor);
|
||||
|
||||
textArea.setSelectByMouse(true);
|
||||
QCOMPARE(textArea.cursor().shape(), Qt::IBeamCursor);
|
||||
}
|
||||
|
||||
QTEST_MAIN(tst_cursor)
|
||||
|
||||
#include "tst_cursor.moc"
|
||||
|
|
Loading…
Reference in New Issue