diff options
author | Andrew den Exter <andrew.den-exter@nokia.com> | 2011-05-13 03:49:20 (GMT) |
---|---|---|
committer | Andrew den Exter <andrew.den-exter@nokia.com> | 2011-05-13 04:11:07 (GMT) |
commit | f69e465e15930ef02dceba7175eed6f3f1df070e (patch) | |
tree | d21c81e738b7215bb0097b93396e8e40aa44f07a /tests/auto/declarative | |
parent | 88492fcea5d5c8dd6a8e1c2458a6a2b8747e84c7 (diff) | |
download | Qt-f69e465e15930ef02dceba7175eed6f3f1df070e.zip Qt-f69e465e15930ef02dceba7175eed6f3f1df070e.tar.gz Qt-f69e465e15930ef02dceba7175eed6f3f1df070e.tar.bz2 |
Make TextEdit word selection more natural.
QTextControl will only extend the selection to a word if the cursor is
directly over it which prevents the selection being extended if the
mouse is dragged up or down a to a shorter line of text making it
difficult to select multiple lines of text. Just disable that
limitation when the TextEdit word selection is enabled.
Change-Id: I3b9d1575c0141db8441197d740de94a90eacc077
Task-number: QTBUG-19230
Reviewed-by: Martin Jones
Diffstat (limited to 'tests/auto/declarative')
-rw-r--r-- | tests/auto/declarative/qdeclarativetextedit/data/mouseselection_multiline.qml | 8 | ||||
-rw-r--r-- | tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp | 36 |
2 files changed, 44 insertions, 0 deletions
diff --git a/tests/auto/declarative/qdeclarativetextedit/data/mouseselection_multiline.qml b/tests/auto/declarative/qdeclarativetextedit/data/mouseselection_multiline.qml new file mode 100644 index 0000000..af23f6d --- /dev/null +++ b/tests/auto/declarative/qdeclarativetextedit/data/mouseselection_multiline.qml @@ -0,0 +1,8 @@ +import QtQuick 1.1 + +TextEdit { + focus: true + text: "0123456789ABCDEFGHIJKLMNOPQRS\nTUVWXYZ" + selectByMouse: true + mouseSelectionMode: TextInput.SelectWords +} diff --git a/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp b/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp index 7bbef21..f8af433 100644 --- a/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp +++ b/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp @@ -119,6 +119,7 @@ private slots: void moveCursorSelectionSequence(); void mouseSelection_data(); void mouseSelection(); + void multilineMouseSelection(); void deferEnableSelectByMouse_data(); void deferEnableSelectByMouse(); void deferDisableSelectByMouse_data(); @@ -1364,6 +1365,41 @@ void tst_qdeclarativetextedit::mouseSelection() delete canvas; } +void tst_qdeclarativetextedit::multilineMouseSelection() +{ + QDeclarativeView *canvas = createView(SRCDIR "/data/mouseselection_multiline.qml"); + + canvas->show(); + QApplication::setActiveWindow(canvas); + QTest::qWaitForWindowShown(canvas); + QTRY_COMPARE(QApplication::activeWindow(), static_cast<QWidget *>(canvas)); + + QVERIFY(canvas->rootObject() != 0); + QDeclarativeTextEdit *textEditObject = qobject_cast<QDeclarativeTextEdit *>(canvas->rootObject()); + QVERIFY(textEditObject != 0); + + // press-and-drag from x1,y1 to x2,y1 + int x1 = 10; + int x2 = textEditObject->width() - 10; + int y1 = textEditObject->height() / 4; + int y2 = textEditObject->height() * 3 / 4; + QTest::mousePress(canvas->viewport(), Qt::LeftButton, 0, canvas->mapFromScene(QPoint(x1,y1))); + QMouseEvent mv1(QEvent::MouseMove, canvas->mapFromScene(QPoint(x2,y1)), Qt::LeftButton, Qt::LeftButton,Qt::NoModifier); + QApplication::sendEvent(canvas->viewport(), &mv1); + QString str1 = textEditObject->selectedText(); + QVERIFY(str1.length() > 3); // don't reallly care *what* was selected (and it's too sensitive to platform) + + // drag-and-release from x2,y1 to x2,y2 + QMouseEvent mv2(QEvent::MouseMove, canvas->mapFromScene(QPoint(x2,y2)), Qt::LeftButton, Qt::LeftButton,Qt::NoModifier); + QApplication::sendEvent(canvas->viewport(), &mv2); + QTest::mouseRelease(canvas->viewport(), Qt::LeftButton, 0, canvas->mapFromScene(QPoint(x2,y2))); + QString str2 = textEditObject->selectedText(); + QVERIFY(str1 != str2); + QVERIFY(str2.length() > 3); + + delete canvas; +} + void tst_qdeclarativetextedit::deferEnableSelectByMouse_data() { QTest::addColumn<QString>("qmlfile"); |