diff options
author | Andrew den Exter <andrew.den-exter@nokia.com> | 2011-09-08 02:28:49 (GMT) |
---|---|---|
committer | Andrew den Exter <andrew.den-exter@nokia.com> | 2011-09-08 03:00:51 (GMT) |
commit | 852abfca6f4c349dce9b895956922f96d82df579 (patch) | |
tree | 99c31dfab2441a4af87a5948580c0699564ed8bb /tests/auto/qtextedit | |
parent | a1b2be3c8a64aee832c648c6dcdff003f22318a3 (diff) | |
download | Qt-852abfca6f4c349dce9b895956922f96d82df579.zip Qt-852abfca6f4c349dce9b895956922f96d82df579.tar.gz Qt-852abfca6f4c349dce9b895956922f96d82df579.tar.bz2 |
Fix double click and drag not extending word selection.
mousePressed isn't set on the second press of a double click and so
can't be used to determine if all selections should be skipped. Instead
skip only the single click and drag selections if mousePressed is false.
Change-Id: I5e7ba033f38b0f9b98fdca5c61a8548f92991601
Task-number: QTBUG-20925
Reviewed-by: Martin Jones
Diffstat (limited to 'tests/auto/qtextedit')
-rw-r--r-- | tests/auto/qtextedit/tst_qtextedit.cpp | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/tests/auto/qtextedit/tst_qtextedit.cpp b/tests/auto/qtextedit/tst_qtextedit.cpp index 42ea3b1..73d09f4 100644 --- a/tests/auto/qtextedit/tst_qtextedit.cpp +++ b/tests/auto/qtextedit/tst_qtextedit.cpp @@ -138,6 +138,8 @@ private slots: void textSemantics(); #endif void cursorPositionChanged(); + void mouseSelection(); + void mouseSelectionDClick(); void setTextCursor(); #ifndef QT_NO_CLIPBOARD void undoAvailableAfterPaste(); @@ -785,6 +787,45 @@ void tst_QTextEdit::cursorPositionChanged() QCOMPARE(ed->textCursor().position(), 0); } +void tst_QTextEdit::mouseSelection() +{ + ed->show(); + ed->setPlainText(("Hello World")); + QTextCursor cursor = ed->textCursor(); + cursor.setPosition(1); + QPoint p1 = ed->cursorRect(cursor).center(); + cursor.setPosition(10); + QPoint p2 = ed->cursorRect(cursor).center(); + QTest::mousePress(ed->viewport(), Qt::LeftButton, 0, p1); + { QMouseEvent ev(QEvent::MouseMove, p2, Qt::LeftButton, Qt::LeftButton, 0); + QCoreApplication::sendEvent(ed->viewport(), &ev); } + QTest::mouseRelease(ed->viewport(), Qt::LeftButton, 0, p2); + QVERIFY(ed->textCursor().hasSelection()); + QCOMPARE(ed->textCursor().selectedText(), QString("ello Worl")); + +} + +void tst_QTextEdit::mouseSelectionDClick() +{ + ed->show(); + ed->setPlainText(("Hello World")); + QTextCursor cursor = ed->textCursor(); + cursor.setPosition(1); + QPoint p1 = ed->cursorRect(cursor).center(); + cursor.setPosition(10); + QPoint p2 = ed->cursorRect(cursor).center(); + QTest::mousePress(ed->viewport(), Qt::LeftButton, 0, p1); + QTest::mouseRelease(ed->viewport(), Qt::LeftButton, 0, p1); + QTest::mouseDClick(ed->viewport(), Qt::LeftButton, 0, p1); + QVERIFY(ed->textCursor().hasSelection()); + QCOMPARE(ed->textCursor().selectedText(), QString("Hello")); + { QMouseEvent ev(QEvent::MouseMove, p2, Qt::LeftButton, Qt::LeftButton, 0); + QCoreApplication::sendEvent(ed->viewport(), &ev); } + QTest::mouseRelease(ed->viewport(), Qt::LeftButton, 0, p2); + QVERIFY(ed->textCursor().hasSelection()); + QCOMPARE(ed->textCursor().selectedText(), QString("Hello World")); +} + void tst_QTextEdit::setTextCursor() { QSignalSpy spy(ed, SIGNAL(cursorPositionChanged())); |