summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorQt Continuous Integration System <qt-info@nokia.com>2011-08-24 02:20:05 (GMT)
committerQt Continuous Integration System <qt-info@nokia.com>2011-08-24 02:20:05 (GMT)
commit52d3a7418818e5b6f497a4a7c6efd4b590356c35 (patch)
tree4bfca5cd744fcd764388d14fc7496bf8f6c2958e
parent5bf62d2f11d36b2bfc1b970f2cfff97c87caa770 (diff)
parent33eb83565466d3dc31ea90dcf18dc3c7b16fd5b6 (diff)
downloadQt-52d3a7418818e5b6f497a4a7c6efd4b590356c35.zip
Qt-52d3a7418818e5b6f497a4a7c6efd4b590356c35.tar.gz
Qt-52d3a7418818e5b6f497a4a7c6efd4b590356c35.tar.bz2
Merge branch '4.7' of scm.dev.nokia.troll.no:qt/qt-qml into 4.7-integration
* '4.7' of scm.dev.nokia.troll.no:qt/qt-qml: Make it easier to select words at the start of a line.
-rw-r--r--src/gui/text/qtextcontrol.cpp34
-rw-r--r--tests/auto/declarative/qdeclarativetextedit/data/mouseselection_false_words.qml5
-rw-r--r--tests/auto/declarative/qdeclarativetextedit/data/mouseselection_true_words.qml5
-rw-r--r--tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp49
4 files changed, 56 insertions, 37 deletions
diff --git a/src/gui/text/qtextcontrol.cpp b/src/gui/text/qtextcontrol.cpp
index 9081ab7..f3d42f8 100644
--- a/src/gui/text/qtextcontrol.cpp
+++ b/src/gui/text/qtextcontrol.cpp
@@ -679,20 +679,30 @@ void QTextControlPrivate::extendWordwiseSelection(int suggestedNewPosition, qrea
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
diff --git a/tests/auto/declarative/qdeclarativetextedit/data/mouseselection_false_words.qml b/tests/auto/declarative/qdeclarativetextedit/data/mouseselection_false_words.qml
index 22a9871..f8d2e4e 100644
--- a/tests/auto/declarative/qdeclarativetextedit/data/mouseselection_false_words.qml
+++ b/tests/auto/declarative/qdeclarativetextedit/data/mouseselection_false_words.qml
@@ -1,7 +1,8 @@
-import QtQuick 1.0
+import QtQuick 1.1
TextEdit {
focus: true
- text: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+ text: "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ"
selectByMouse: false
+ mouseSelectionMode: TextEdit.SelectWords
}
diff --git a/tests/auto/declarative/qdeclarativetextedit/data/mouseselection_true_words.qml b/tests/auto/declarative/qdeclarativetextedit/data/mouseselection_true_words.qml
index d61da46..f58fd45 100644
--- a/tests/auto/declarative/qdeclarativetextedit/data/mouseselection_true_words.qml
+++ b/tests/auto/declarative/qdeclarativetextedit/data/mouseselection_true_words.qml
@@ -1,7 +1,8 @@
-import QtQuick 1.0
+import QtQuick 1.1
TextEdit {
focus: true
- text: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+ text: "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ"
selectByMouse: true
+ mouseSelectionMode: TextEdit.SelectWords
}
diff --git a/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp b/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp
index 5c7f36f..fde0588 100644
--- a/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp
+++ b/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp
@@ -1327,20 +1327,32 @@ void tst_qdeclarativetextedit::moveCursorSelectionSequence()
void tst_qdeclarativetextedit::mouseSelection_data()
{
QTest::addColumn<QString>("qmlfile");
- QTest::addColumn<bool>("expectSelection");
+ QTest::addColumn<int>("from");
+ QTest::addColumn<int>("to");
+ QTest::addColumn<QString>("selectedText");
// import installed
- QTest::newRow("on") << SRCDIR "/data/mouseselection_true.qml" << true;
- QTest::newRow("off") << SRCDIR "/data/mouseselection_false.qml" << false;
- QTest::newRow("default") << SRCDIR "/data/mouseselection_default.qml" << false;
- QTest::newRow("on word selection") << SRCDIR "/data/mouseselection_true_words.qml" << true;
- QTest::newRow("off word selection") << SRCDIR "/data/mouseselection_false_words.qml" << false;
+ QTest::newRow("on") << SRCDIR "/data/mouseselection_true.qml" << 4 << 9 << "45678";
+ QTest::newRow("off") << SRCDIR "/data/mouseselection_false.qml" << 4 << 9 << QString();
+ QTest::newRow("default") << SRCDIR "/data/mouseselection_default.qml" << 4 << 9 << QString();
+ QTest::newRow("off word selection") << SRCDIR "/data/mouseselection_false_words.qml" << 4 << 9 << QString();
+ QTest::newRow("on word selection (4,9)") << SRCDIR "/data/mouseselection_true_words.qml" << 4 << 9 << "0123456789";
+ QTest::newRow("on word selection (2,13)") << SRCDIR "/data/mouseselection_true_words.qml" << 2 << 13 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ";
+ QTest::newRow("on word selection (2,30)") << SRCDIR "/data/mouseselection_true_words.qml" << 2 << 30 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ";
+ QTest::newRow("on word selection (9,13)") << SRCDIR "/data/mouseselection_true_words.qml" << 9 << 13 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ";
+ QTest::newRow("on word selection (9,30)") << SRCDIR "/data/mouseselection_true_words.qml" << 9 << 30 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ";
+ QTest::newRow("on word selection (13,2)") << SRCDIR "/data/mouseselection_true_words.qml" << 13 << 2 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ";
+ QTest::newRow("on word selection (20,2)") << SRCDIR "/data/mouseselection_true_words.qml" << 20 << 2 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ";
+ QTest::newRow("on word selection (12,9)") << SRCDIR "/data/mouseselection_true_words.qml" << 12 << 9 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ";
+ QTest::newRow("on word selection (30,9)") << SRCDIR "/data/mouseselection_true_words.qml" << 30 << 9 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ";
}
void tst_qdeclarativetextedit::mouseSelection()
{
QFETCH(QString, qmlfile);
- QFETCH(bool, expectSelection);
+ QFETCH(int, from);
+ QFETCH(int, to);
+ QFETCH(QString, selectedText);
QDeclarativeView *canvas = createView(qmlfile);
@@ -1354,25 +1366,20 @@ void tst_qdeclarativetextedit::mouseSelection()
QVERIFY(textEditObject != 0);
// press-and-drag-and-release from x1 to x2
- int x1 = 10;
- int x2 = 70;
- int y = textEditObject->height()/2;
- QTest::mousePress(canvas->viewport(), Qt::LeftButton, 0, canvas->mapFromScene(QPoint(x1,y)));
+ QPoint p1 = canvas->mapFromScene(textEditObject->positionToRectangle(from).center());
+ QPoint p2 = canvas->mapFromScene(textEditObject->positionToRectangle(to).center());
+ QTest::mousePress(canvas->viewport(), Qt::LeftButton, 0, p1);
//QTest::mouseMove(canvas->viewport(), canvas->mapFromScene(QPoint(x2,y))); // doesn't work
- QMouseEvent mv(QEvent::MouseMove, canvas->mapFromScene(QPoint(x2,y)), Qt::LeftButton, Qt::LeftButton,Qt::NoModifier);
+ QMouseEvent mv(QEvent::MouseMove, canvas->mapFromScene(p2), Qt::LeftButton, Qt::LeftButton,Qt::NoModifier);
QApplication::sendEvent(canvas->viewport(), &mv);
- QTest::mouseRelease(canvas->viewport(), Qt::LeftButton, 0, canvas->mapFromScene(QPoint(x2,y)));
- QString str = textEditObject->selectedText();
- if (expectSelection)
- QVERIFY(str.length() > 3); // don't reallly care *what* was selected (and it's too sensitive to platform)
- else
- QVERIFY(str.isEmpty());
+ QTest::mouseRelease(canvas->viewport(), Qt::LeftButton, 0, p2);
+ QCOMPARE(textEditObject->selectedText(), selectedText);
// Clicking and shift to clicking between the same points should select the same text.
textEditObject->setCursorPosition(0);
- QTest::mouseClick(canvas->viewport(), Qt::LeftButton, Qt::NoModifier, canvas->mapFromScene(QPoint(x1,y)));
- QTest::mouseClick(canvas->viewport(), Qt::LeftButton, Qt::ShiftModifier, canvas->mapFromScene(QPoint(x2,y)));
- QCOMPARE(textEditObject->selectedText(), str);
+ QTest::mouseClick(canvas->viewport(), Qt::LeftButton, Qt::NoModifier, p1);
+ QTest::mouseClick(canvas->viewport(), Qt::LeftButton, Qt::ShiftModifier, p2);
+ QCOMPARE(textEditObject->selectedText(), selectedText);
delete canvas;
}