summaryrefslogtreecommitdiffstats
path: root/src/widgets
diff options
context:
space:
mode:
authorAndrew den Exter <andrew.den-exter@nokia.com>2011-08-24 11:26:29 +1000
committerQt by Nokia <qt-info@nokia.com>2011-12-12 13:19:13 +0100
commit734033e71d76e02f63a46c7d8f68b7cf404667fe (patch)
tree0d67abf65f6d88a86067f0560cd239fd7c3d537e /src/widgets
parent55b432b24cbdaa98e1d7aec46fdc2aa67f2bbf7f (diff)
Make it easier to select words at the start of a line.
QTextControl's word selection will only include a word if the cursor position is past the mid point of the word. This can make it difficult to select words near the edges of the screen on touch devices. For the TextEdit word selection mode select a word ignore the relative position within a word. Task-number: QT-5206 Task-number: QTBUG-20719 Change-Id: I77e71e01d8021d66ada785cf894ba876faccefdf Reviewed-by: Joona Petrell <joona.t.petrell@nokia.com>
Diffstat (limited to 'src/widgets')
-rw-r--r--src/widgets/widgets/qwidgettextcontrol.cpp34
1 files changed, 22 insertions, 12 deletions
diff --git a/src/widgets/widgets/qwidgettextcontrol.cpp b/src/widgets/widgets/qwidgettextcontrol.cpp
index a55e001fc4..c63dcf0318 100644
--- a/src/widgets/widgets/qwidgettextcontrol.cpp
+++ b/src/widgets/widgets/qwidgettextcontrol.cpp
@@ -691,20 +691,30 @@ void QWidgetTextControlPrivate::extendWordwiseSelection(int suggestedNewPosition
if (!wordSelectionEnabled && (mouseXPosition < wordStartX || mouseXPosition > wordEndX))
return;
- // keep the already selected word even when moving to the left
- // (#39164)
- if (suggestedNewPosition < selectedWordOnDoubleClick.position())
- cursor.setPosition(selectedWordOnDoubleClick.selectionEnd());
- else
- cursor.setPosition(selectedWordOnDoubleClick.selectionStart());
+ if (wordSelectionEnabled) {
+ if (suggestedNewPosition < selectedWordOnDoubleClick.position()) {
+ cursor.setPosition(selectedWordOnDoubleClick.selectionEnd());
+ setCursorPosition(wordStartPos, QTextCursor::KeepAnchor);
+ } else {
+ cursor.setPosition(selectedWordOnDoubleClick.selectionStart());
+ setCursorPosition(wordEndPos, QTextCursor::KeepAnchor);
+ }
+ } else {
+ // keep the already selected word even when moving to the left
+ // (#39164)
+ if (suggestedNewPosition < selectedWordOnDoubleClick.position())
+ cursor.setPosition(selectedWordOnDoubleClick.selectionEnd());
+ else
+ cursor.setPosition(selectedWordOnDoubleClick.selectionStart());
- const qreal differenceToStart = mouseXPosition - wordStartX;
- const qreal differenceToEnd = wordEndX - mouseXPosition;
+ const qreal differenceToStart = mouseXPosition - wordStartX;
+ const qreal differenceToEnd = wordEndX - mouseXPosition;
- if (differenceToStart < differenceToEnd)
- setCursorPosition(wordStartPos, QTextCursor::KeepAnchor);
- else
- setCursorPosition(wordEndPos, QTextCursor::KeepAnchor);
+ if (differenceToStart < differenceToEnd)
+ setCursorPosition(wordStartPos, QTextCursor::KeepAnchor);
+ else
+ setCursorPosition(wordEndPos, QTextCursor::KeepAnchor);
+ }
if (interactionFlags & Qt::TextSelectableByMouse) {
#ifndef QT_NO_CLIPBOARD