diff options
author | Shawn Rutledge <shawn.rutledge@qt.io> | 2022-08-24 15:03:26 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2022-08-30 21:05:26 +0000 |
commit | 2b42c90c3773d3479a9b7d8452087828189573e9 (patch) | |
tree | fb9caf6116d6e304fffad76e9b2fa26d5c670923 /src | |
parent | 942331e49bbbd0ef0a439a019296cae227149981 (diff) |
Fix TextInput and TextField mouse/touch selection fallback behavior
We tried to make default behavior depend on the import version; but in
Controls that does not work well, because the QQuickTextField instance
is created in a style-specific QML file that does not use the same
import version that the user is using. So we work around it by adding
support for a Controls-specific env var to revert to pre-6.4 behavior.
Adding the autotest proves that the fallback was broken a different
way too: we didn't check selectByTouchDrag in all the necessary places.
Amends 650342de792e0ab37ce8bac8ccde21ab9b96b2c9
[ChangeLog][Controls][TextField] The selectByMouse property is now
enabled by default, but no longer enables selecting by dragging your
finger across text on a touchscreen. Platforms that are optimized for
touchscreens normally use special text-selection handles, which interact
with Qt via QInputMethod. You can opt out of the behavior change by
setting the environment variable
QT_QUICK_CONTROLS_TEXT_SELECTION_BEHAVIOR=old.
Task-number: QTBUG-10684
Task-number: QTBUG-38934
Task-number: QTBUG-101205
Change-Id: If1c1d6bd9c538f52022ae06d5252d178a1ae5a38
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
(cherry picked from commit 42848bda5cb7ed92781cbbd536005af617e91020)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/quick/items/qquicktextinput.cpp | 18 | ||||
-rw-r--r-- | src/quicktemplates2/qquicktextfield.cpp | 16 |
2 files changed, 26 insertions, 8 deletions
diff --git a/src/quick/items/qquicktextinput.cpp b/src/quick/items/qquicktextinput.cpp index 9d452093d3..34f6902666 100644 --- a/src/quick/items/qquicktextinput.cpp +++ b/src/quick/items/qquicktextinput.cpp @@ -1593,10 +1593,13 @@ void QQuickTextInput::mousePressEvent(QMouseEvent *event) void QQuickTextInput::mouseMoveEvent(QMouseEvent *event) { - if (!QQuickDeliveryAgentPrivate::isEventFromMouseOrTouchpad(event)) - return; - Q_D(QQuickTextInput); + if (!QQuickDeliveryAgentPrivate::isEventFromMouseOrTouchpad(event) +#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0) + && ! d->selectByTouchDrag +#endif + ) + return; if (d->selectPressed) { if (qAbs(int(event->position().x() - d->pressPos.x())) > QGuiApplication::styleHints()->startDragDistance()) @@ -1629,7 +1632,12 @@ void QQuickTextInput::mouseReleaseEvent(QMouseEvent *event) d->selectPressed = false; setKeepMouseGrab(false); } - const bool isMouse = QQuickDeliveryAgentPrivate::isEventFromMouseOrTouchpad(event); + const bool isMouse = QQuickDeliveryAgentPrivate::isEventFromMouseOrTouchpad(event) +#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0) + || d->selectByTouchDrag +#endif + ; + #if QT_CONFIG(clipboard) if (isMouse && QGuiApplication::clipboard()->supportsSelection()) { if (event->button() == Qt::LeftButton) { @@ -4872,7 +4880,7 @@ void QQuickTextInput::setOldSelectionDefault() Q_D(QQuickTextInput); d->selectByMouse = false; d->selectByTouchDrag = true; - qCDebug(lcQuickTextInput, "pre-6.4 behavior chosen by import version: selectByMouse defaults false; if enabled, touchscreen acts like a mouse"); + qCDebug(lcQuickTextInput, "pre-6.4 behavior chosen: selectByMouse defaults false; if enabled, touchscreen acts like a mouse"); } // TODO in 6.7.0: remove the note about versions prior to 6.4 in selectByMouse() documentation diff --git a/src/quicktemplates2/qquicktextfield.cpp b/src/quicktemplates2/qquicktextfield.cpp index 99f9b757c1..c74b1c01fb 100644 --- a/src/quicktemplates2/qquicktextfield.cpp +++ b/src/quicktemplates2/qquicktextfield.cpp @@ -17,6 +17,8 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + /*! \qmltype TextField \inherits TextInput @@ -377,6 +379,11 @@ QQuickTextField::QQuickTextField(QQuickItem *parent) #endif QObjectPrivate::connect(this, &QQuickTextInput::readOnlyChanged, d, &QQuickTextFieldPrivate::readOnlyChanged); QObjectPrivate::connect(this, &QQuickTextInput::echoModeChanged, d, &QQuickTextFieldPrivate::echoModeChanged); +#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0) +qDebug() << "QT_QUICK_CONTROLS_TEXT_SELECTION_BEHAVIOR" << qgetenv("QT_QUICK_CONTROLS_TEXT_SELECTION_BEHAVIOR"); + if (qEnvironmentVariable("QT_QUICK_CONTROLS_TEXT_SELECTION_BEHAVIOR") == u"old"_s) + QQuickTextInput::setOldSelectionDefault(); +#endif } QQuickTextField::~QQuickTextField() @@ -880,9 +887,12 @@ void QQuickTextField::mouseMoveEvent(QMouseEvent *event) QQuickTextInput::mousePressEvent(d->pressHandler.delayedMousePressEvent); d->pressHandler.clearDelayedMouseEvent(); } - const auto devType = event->device()->type(); - if (event->buttons() != Qt::RightButton && - (devType == QInputDevice::DeviceType::Mouse || devType == QInputDevice::DeviceType::TouchPad)) + const bool isMouse = QQuickDeliveryAgentPrivate::isEventFromMouseOrTouchpad(event) + #if QT_VERSION < QT_VERSION_CHECK(7, 0, 0) + || d->selectByTouchDrag + #endif + ; + if (event->buttons() != Qt::RightButton && isMouse) QQuickTextInput::mouseMoveEvent(event); } } |