summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorAndrew den Exter <andrew.den-exter@nokia.com>2011-01-28 05:58:37 (GMT)
committerAndrew den Exter <andrew.den-exter@nokia.com>2011-02-01 00:00:30 (GMT)
commitba63becc13221ca6538fb40c790275465dd47703 (patch)
tree46d27e12faee710564866b2779343f7ac5791209 /tests/auto
parent2b337d8cbe8e6646ec78b3acaad50ce108d33dc0 (diff)
downloadQt-ba63becc13221ca6538fb40c790275465dd47703.zip
Qt-ba63becc13221ca6538fb40c790275465dd47703.tar.gz
Qt-ba63becc13221ca6538fb40c790275465dd47703.tar.bz2
Add a mouseSelectionMode property to TextEdit and TextInput.
Adds an option to do per word selection when selectByMouse is true. Also changes the selection behavior so that the first word selected remains selected when the direction of the selection changes which is more consistent with other implementations including the existing per word selection in QTextEdit. Task-number: QTBUG-16283 Reviewed-by: Martin Jones
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/declarative/qdeclarativetextedit/data/mouseselectionmode_characters.qml8
-rw-r--r--tests/auto/declarative/qdeclarativetextedit/data/mouseselectionmode_default.qml7
-rw-r--r--tests/auto/declarative/qdeclarativetextedit/data/mouseselectionmode_words.qml8
-rw-r--r--tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp349
-rw-r--r--tests/auto/declarative/qdeclarativetextinput/data/mouseselectionmode_characters.qml8
-rw-r--r--tests/auto/declarative/qdeclarativetextinput/data/mouseselectionmode_default.qml7
-rw-r--r--tests/auto/declarative/qdeclarativetextinput/data/mouseselectionmode_words.qml8
-rw-r--r--tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp352
8 files changed, 630 insertions, 117 deletions
diff --git a/tests/auto/declarative/qdeclarativetextedit/data/mouseselectionmode_characters.qml b/tests/auto/declarative/qdeclarativetextedit/data/mouseselectionmode_characters.qml
new file mode 100644
index 0000000..5784e19
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativetextedit/data/mouseselectionmode_characters.qml
@@ -0,0 +1,8 @@
+import QtQuick 1.1
+
+TextEdit {
+ focus: true
+ text: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+ selectByMouse: true
+ mouseSelectionMode: TextEdit.SelectCharacters
+}
diff --git a/tests/auto/declarative/qdeclarativetextedit/data/mouseselectionmode_default.qml b/tests/auto/declarative/qdeclarativetextedit/data/mouseselectionmode_default.qml
new file mode 100644
index 0000000..1e5f4aa
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativetextedit/data/mouseselectionmode_default.qml
@@ -0,0 +1,7 @@
+import QtQuick 1.1
+
+TextEdit {
+ focus: true
+ text: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+ selectByMouse: true
+}
diff --git a/tests/auto/declarative/qdeclarativetextedit/data/mouseselectionmode_words.qml b/tests/auto/declarative/qdeclarativetextedit/data/mouseselectionmode_words.qml
new file mode 100644
index 0000000..4b25f2f
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativetextedit/data/mouseselectionmode_words.qml
@@ -0,0 +1,8 @@
+import QtQuick 1.1
+
+TextEdit {
+ focus: true
+ text: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+ selectByMouse: true
+ mouseSelectionMode: TextEdit.SelectWords
+}
diff --git a/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp b/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp
index 1364337..b82aca8 100644
--- a/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp
+++ b/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp
@@ -112,8 +112,12 @@ private slots:
void selection();
void moveCursorSelection_data();
void moveCursorSelection();
+ void moveCursorSelectionSequence_data();
+ void moveCursorSelectionSequence();
void mouseSelection_data();
void mouseSelection();
+ void mouseSelectionMode_data();
+ void mouseSelectionMode();
void dragMouseSelection();
void inputMethodHints();
@@ -786,91 +790,113 @@ void tst_qdeclarativetextedit::moveCursorSelection_data()
QTest::newRow("jum()ped|characters")
<< standard[0] << 23 << 23 << QDeclarativeTextEdit::SelectCharacters << 23 << 23 << true;
- QTest::newRow("(t)he|words")
+ QTest::newRow("<(t)he>|words")
<< standard[0] << 0 << 1 << QDeclarativeTextEdit::SelectWords << 0 << 3 << true;
- QTest::newRow("do(g)|words")
+ QTest::newRow("<do(g)>|words")
<< standard[0] << 43 << 44 << QDeclarativeTextEdit::SelectWords << 41 << 44 << true;
- QTest::newRow("jum(p)ed|words")
+ QTest::newRow("<jum(p)ed>|words")
<< standard[0] << 23 << 24 << QDeclarativeTextEdit::SelectWords << 20 << 26 << true;
- QTest::newRow("jumped( )over|words")
- << standard[0] << 26 << 27 << QDeclarativeTextEdit::SelectWords << 27 << 27 << false;
- QTest::newRow("jumped( )over|words,reversed")
- << standard[0] << 27 << 26 << QDeclarativeTextEdit::SelectWords << 26 << 26 << false;
- QTest::newRow("(the )|words")
- << standard[0] << 0 << 4 << QDeclarativeTextEdit::SelectWords << 0 << 3 << true;
- QTest::newRow("( dog)|words")
- << standard[0] << 40 << 44 << QDeclarativeTextEdit::SelectWords << 41 << 44 << true;
- QTest::newRow("( jumped )|words")
- << standard[0] << 19 << 27 << QDeclarativeTextEdit::SelectWords << 20 << 26 << true;
- QTest::newRow("th(e qu)ick|words")
+ QTest::newRow("<jumped( )>over|words")
+ << standard[0] << 26 << 27 << QDeclarativeTextEdit::SelectWords << 20 << 27 << false;
+ QTest::newRow("jumped<( )over>|words,reversed")
+ << standard[0] << 27 << 26 << QDeclarativeTextEdit::SelectWords << 26 << 31 << false;
+ QTest::newRow("<(the )>quick|words")
+ << standard[0] << 0 << 4 << QDeclarativeTextEdit::SelectWords << 0 << 4 << false;
+ QTest::newRow("<(the )quick>|words,reversed")
+ << standard[0] << 4 << 0 << QDeclarativeTextEdit::SelectWords << 0 << 9 << false;
+ QTest::newRow("<lazy( dog)>|words")
+ << standard[0] << 40 << 44 << QDeclarativeTextEdit::SelectWords << 36 << 44 << false;
+ QTest::newRow("lazy<( dog)>|words,reversed")
+ << standard[0] << 44 << 40 << QDeclarativeTextEdit::SelectWords << 40 << 44 << false;
+ QTest::newRow("<fox( jumped )>over|words")
+ << standard[0] << 19 << 27 << QDeclarativeTextEdit::SelectWords << 16 << 27 << false;
+ QTest::newRow("fox<( jumped )over>|words,reversed")
+ << standard[0] << 27 << 19 << QDeclarativeTextEdit::SelectWords << 19 << 31 << false;
+ QTest::newRow("<th(e qu)ick>|words")
<< standard[0] << 2 << 6 << QDeclarativeTextEdit::SelectWords << 0 << 9 << true;
- QTest::newRow("la(zy d)og|words")
+ QTest::newRow("<la(zy d)og|words>")
<< standard[0] << 38 << 42 << QDeclarativeTextEdit::SelectWords << 36 << 44 << true;
- QTest::newRow("jum(ped ov)er|words")
+ QTest::newRow("<jum(ped ov)er>|words")
<< standard[0] << 23 << 29 << QDeclarativeTextEdit::SelectWords << 20 << 31 << true;
- QTest::newRow("()the|words")
+ QTest::newRow("<()>the|words")
<< standard[0] << 0 << 0 << QDeclarativeTextEdit::SelectWords << 0 << 0 << true;
- QTest::newRow("dog()|words")
+ QTest::newRow("dog<()>|words")
<< standard[0] << 44 << 44 << QDeclarativeTextEdit::SelectWords << 44 << 44 << true;
- QTest::newRow("jum()ped|words")
+ QTest::newRow("jum<()>ped|words")
<< standard[0] << 23 << 23 << QDeclarativeTextEdit::SelectWords << 23 << 23 << true;
- QTest::newRow("Hello(,) |words")
+ QTest::newRow("Hello<(,)> |words")
<< standard[2] << 5 << 6 << QDeclarativeTextEdit::SelectWords << 5 << 6 << true;
- QTest::newRow("Hello(, )|words")
- << standard[2] << 5 << 7 << QDeclarativeTextEdit::SelectWords << 5 << 6 << true;
- QTest::newRow("Hel(lo, )|words")
- << standard[2] << 3 << 7 << QDeclarativeTextEdit::SelectWords << 0 << 6 << true;
- QTest::newRow("Hel(lo),|words")
+ QTest::newRow("Hello<(, )>world|words")
+ << standard[2] << 5 << 7 << QDeclarativeTextEdit::SelectWords << 5 << 7 << false;
+ QTest::newRow("Hello<(, )world>|words,reversed")
+ << standard[2] << 7 << 5 << QDeclarativeTextEdit::SelectWords << 5 << 12 << false;
+ QTest::newRow("<Hel(lo, )>world|words")
+ << standard[2] << 3 << 7 << QDeclarativeTextEdit::SelectWords << 0 << 7 << false;
+ QTest::newRow("<Hel(lo, )world>|words,reversed")
+ << standard[2] << 7 << 3 << QDeclarativeTextEdit::SelectWords << 0 << 12 << false;
+ QTest::newRow("<Hel(lo)>,|words")
<< standard[2] << 3 << 5 << QDeclarativeTextEdit::SelectWords << 0 << 5 << true;
- QTest::newRow("Hello(),|words")
+ QTest::newRow("Hello<()>,|words")
<< standard[2] << 5 << 5 << QDeclarativeTextEdit::SelectWords << 5 << 5 << true;
- QTest::newRow("Hello,()|words")
+ QTest::newRow("Hello,<()>|words")
<< standard[2] << 6 << 6 << QDeclarativeTextEdit::SelectWords << 6 << 6 << true;
- QTest::newRow("Hello,( )|words")
- << standard[2] << 6 << 7 << QDeclarativeTextEdit::SelectWords << 7 << 7 << false;
- QTest::newRow("Hello,( )|words")
- << standard[2] << 7 << 6 << QDeclarativeTextEdit::SelectWords << 6 << 6 << false;
- QTest::newRow("Hello,( world)|words")
- << standard[2] << 6 << 12 << QDeclarativeTextEdit::SelectWords << 7 << 12 << true;
- QTest::newRow("Hello,( world!)|words")
- << standard[2] << 6 << 13 << QDeclarativeTextEdit::SelectWords << 7 << 13 << true;
- QTest::newRow("Hello(, world!)|words")
+ QTest::newRow("Hello<,( )>world|words")
+ << standard[2] << 6 << 7 << QDeclarativeTextEdit::SelectWords << 5 << 7 << false;
+ QTest::newRow("Hello,<( )world>|words,reversed")
+ << standard[2] << 7 << 6 << QDeclarativeTextEdit::SelectWords << 6 << 12 << false;
+ QTest::newRow("Hello<,( world)>|words")
+ << standard[2] << 6 << 12 << QDeclarativeTextEdit::SelectWords << 5 << 12 << false;
+ QTest::newRow("Hello,<( world)>|words,reversed")
+ << standard[2] << 12 << 6 << QDeclarativeTextEdit::SelectWords << 6 << 12 << false;
+ QTest::newRow("Hello<,( world!)>|words")
+ << standard[2] << 6 << 13 << QDeclarativeTextEdit::SelectWords << 5 << 13 << false;
+ QTest::newRow("Hello,<( world!)>|words,reversed")
+ << standard[2] << 13 << 6 << QDeclarativeTextEdit::SelectWords << 6 << 13 << false;
+ QTest::newRow("Hello<(, world!)>|words")
<< standard[2] << 5 << 13 << QDeclarativeTextEdit::SelectWords << 5 << 13 << true;
- QTest::newRow("world(!)|words")
+ QTest::newRow("world<(!)>|words")
<< standard[2] << 12 << 13 << QDeclarativeTextEdit::SelectWords << 12 << 13 << true;
- QTest::newRow("world!())|words")
+ QTest::newRow("world!<()>)|words")
<< standard[2] << 13 << 13 << QDeclarativeTextEdit::SelectWords << 13 << 13 << true;
- QTest::newRow("world()!)|words")
+ QTest::newRow("world<()>!)|words")
<< standard[2] << 12 << 12 << QDeclarativeTextEdit::SelectWords << 12 << 12 << true;
- QTest::newRow("(,)olleH |words")
+ QTest::newRow("<(,)>olleH |words")
<< standard[3] << 7 << 8 << QDeclarativeTextEdit::SelectWords << 7 << 8 << true;
- QTest::newRow("( ,)olleH|words")
- << standard[3] << 6 << 8 << QDeclarativeTextEdit::SelectWords << 7 << 8 << true;
- QTest::newRow("( ,ol)leH|words")
- << standard[3] << 6 << 10 << QDeclarativeTextEdit::SelectWords << 7 << 13 << true;
- QTest::newRow(",(ol)leH,|words")
+ QTest::newRow("<dlrow( ,)>olleH|words")
+ << standard[3] << 6 << 8 << QDeclarativeTextEdit::SelectWords << 1 << 8 << false;
+ QTest::newRow("dlrow<( ,)>olleH|words,reversed")
+ << standard[3] << 8 << 6 << QDeclarativeTextEdit::SelectWords << 6 << 8 << false;
+ QTest::newRow("<dlrow( ,ol)leH>|words")
+ << standard[3] << 6 << 10 << QDeclarativeTextEdit::SelectWords << 1 << 13 << false;
+ QTest::newRow("dlrow<( ,ol)leH>|words,reversed")
+ << standard[3] << 10 << 6 << QDeclarativeTextEdit::SelectWords << 6 << 13 << false;
+ QTest::newRow(",<(ol)leH>,|words")
<< standard[3] << 8 << 10 << QDeclarativeTextEdit::SelectWords << 8 << 13 << true;
- QTest::newRow(",()olleH|words")
+ QTest::newRow(",<()>olleH|words")
<< standard[3] << 8 << 8 << QDeclarativeTextEdit::SelectWords << 8 << 8 << true;
- QTest::newRow("(),olleH|words")
+ QTest::newRow("<()>,olleH|words")
<< standard[3] << 7 << 7 << QDeclarativeTextEdit::SelectWords << 7 << 7 << true;
- QTest::newRow("( ),olleH|words")
- << standard[3] << 6 << 7 << QDeclarativeTextEdit::SelectWords << 7 << 7 << false;
- QTest::newRow("( ),olleH|words,reversed")
- << standard[3] << 7 << 6 << QDeclarativeTextEdit::SelectWords << 6 << 6 << false;
- QTest::newRow("(dlrow ),olleH|words")
- << standard[3] << 1 << 7 << QDeclarativeTextEdit::SelectWords << 1 << 6 << true;
- QTest::newRow("(!dlrow ),olleH|words")
- << standard[3] << 0 << 7 << QDeclarativeTextEdit::SelectWords << 0 << 6 << true;
+ QTest::newRow("<dlrow( )>,olleH|words")
+ << standard[3] << 6 << 7 << QDeclarativeTextEdit::SelectWords << 1 << 7 << false;
+ QTest::newRow("dlrow<( ),>olleH|words,reversed")
+ << standard[3] << 7 << 6 << QDeclarativeTextEdit::SelectWords << 6 << 8 << false;
+ QTest::newRow("<(dlrow )>,olleH|words")
+ << standard[3] << 1 << 7 << QDeclarativeTextEdit::SelectWords << 1 << 7 << false;
+ QTest::newRow("<(dlrow ),>olleH|words,reversed")
+ << standard[3] << 7 << 1 << QDeclarativeTextEdit::SelectWords << 1 << 8 << false;
+ QTest::newRow("<(!dlrow )>,olleH|words")
+ << standard[3] << 0 << 7 << QDeclarativeTextEdit::SelectWords << 0 << 7 << false;
+ QTest::newRow("<(!dlrow ),>olleH|words,reversed")
+ << standard[3] << 7 << 0 << QDeclarativeTextEdit::SelectWords << 0 << 8 << false;
QTest::newRow("(!dlrow ,)olleH|words")
<< standard[3] << 0 << 8 << QDeclarativeTextEdit::SelectWords << 0 << 8 << true;
- QTest::newRow("(!)dlrow|words")
+ QTest::newRow("<(!)>dlrow|words")
<< standard[3] << 0 << 1 << QDeclarativeTextEdit::SelectWords << 0 << 1 << true;
- QTest::newRow("()!dlrow|words")
+ QTest::newRow("<()>!dlrow|words")
<< standard[3] << 0 << 0 << QDeclarativeTextEdit::SelectWords << 0 << 0 << true;
- QTest::newRow("!()dlrow|words")
+ QTest::newRow("!<()>dlrow|words")
<< standard[3] << 1 << 1 << QDeclarativeTextEdit::SelectWords << 1 << 1 << true;
}
@@ -893,6 +919,7 @@ void tst_qdeclarativetextedit::moveCursorSelection()
texteditObject->setCursorPosition(cursorPosition);
texteditObject->moveCursorSelection(movePosition, mode);
+ QCOMPARE(texteditObject->selectedText(), testStr.mid(selectionStart, selectionEnd - selectionStart));
QCOMPARE(texteditObject->selectionStart(), selectionStart);
QCOMPARE(texteditObject->selectionEnd(), selectionEnd);
@@ -900,11 +927,168 @@ void tst_qdeclarativetextedit::moveCursorSelection()
texteditObject->setCursorPosition(movePosition);
texteditObject->moveCursorSelection(cursorPosition, mode);
+ QCOMPARE(texteditObject->selectedText(), testStr.mid(selectionStart, selectionEnd - selectionStart));
QCOMPARE(texteditObject->selectionStart(), selectionStart);
QCOMPARE(texteditObject->selectionEnd(), selectionEnd);
}
}
+void tst_qdeclarativetextedit::moveCursorSelectionSequence_data()
+{
+ QTest::addColumn<QString>("testStr");
+ QTest::addColumn<int>("cursorPosition");
+ QTest::addColumn<int>("movePosition1");
+ QTest::addColumn<int>("movePosition2");
+ QTest::addColumn<int>("selection1Start");
+ QTest::addColumn<int>("selection1End");
+ QTest::addColumn<int>("selection2Start");
+ QTest::addColumn<int>("selection2End");
+
+ QTest::newRow("the {<quick( bro)wn> f^ox} jumped|ltr")
+ << standard[0]
+ << 9 << 13 << 17
+ << 4 << 15
+ << 4 << 19;
+ QTest::newRow("the quick<( {bro)wn> f^ox} jumped|rtl")
+ << standard[0]
+ << 13 << 9 << 17
+ << 9 << 15
+ << 10 << 19;
+ QTest::newRow("the {<quick( bro)wn> ^}fox jumped|ltr")
+ << standard[0]
+ << 9 << 13 << 16
+ << 4 << 15
+ << 4 << 16;
+ QTest::newRow("the quick<( {bro)wn> ^}fox jumped|rtl")
+ << standard[0]
+ << 13 << 9 << 16
+ << 9 << 15
+ << 10 << 16;
+ QTest::newRow("the {<quick( bro)wn^>} fox jumped|ltr")
+ << standard[0]
+ << 9 << 13 << 15
+ << 4 << 15
+ << 4 << 15;
+ QTest::newRow("the quick<( {bro)wn^>} f^ox jumped|rtl")
+ << standard[0]
+ << 13 << 9 << 15
+ << 9 << 15
+ << 10 << 15;
+ QTest::newRow("the {<quick() ^}bro)wn> fox|ltr")
+ << standard[0]
+ << 9 << 13 << 10
+ << 4 << 15
+ << 4 << 10;
+ QTest::newRow("the quick<(^ {^bro)wn>} fox|rtl")
+ << standard[0]
+ << 13 << 9 << 10
+ << 9 << 15
+ << 10 << 15;
+ QTest::newRow("the {<quick^}( bro)wn> fox|ltr")
+ << standard[0]
+ << 9 << 13 << 9
+ << 4 << 15
+ << 4 << 9;
+ QTest::newRow("the quick{<(^ bro)wn>} fox|rtl")
+ << standard[0]
+ << 13 << 9 << 9
+ << 9 << 15
+ << 9 << 15;
+ QTest::newRow("the {<qui^ck}( bro)wn> fox|ltr")
+ << standard[0]
+ << 9 << 13 << 7
+ << 4 << 15
+ << 4 << 9;
+ QTest::newRow("the {<qui^ck}( bro)wn> fox|rtl")
+ << standard[0]
+ << 13 << 9 << 7
+ << 9 << 15
+ << 4 << 15;
+ QTest::newRow("the {<^quick}( bro)wn> fox|ltr")
+ << standard[0]
+ << 9 << 13 << 4
+ << 4 << 15
+ << 4 << 9;
+ QTest::newRow("the {<^quick}( bro)wn> fox|rtl")
+ << standard[0]
+ << 13 << 9 << 4
+ << 9 << 15
+ << 4 << 15;
+ QTest::newRow("the{^ <quick}( bro)wn> fox|ltr")
+ << standard[0]
+ << 9 << 13 << 3
+ << 4 << 15
+ << 3 << 9;
+ QTest::newRow("the{^ <quick}( bro)wn> fox|rtl")
+ << standard[0]
+ << 13 << 9 << 3
+ << 9 << 15
+ << 3 << 15;
+ QTest::newRow("{t^he <quick}( bro)wn> fox|ltr")
+ << standard[0]
+ << 9 << 13 << 1
+ << 4 << 15
+ << 0 << 9;
+ QTest::newRow("{t^he <quick}( bro)wn> fox|rtl")
+ << standard[0]
+ << 13 << 9 << 1
+ << 9 << 15
+ << 0 << 15;
+
+ QTest::newRow("{<He(ll)o>, w^orld}!|ltr")
+ << standard[2]
+ << 2 << 4 << 8
+ << 0 << 5
+ << 0 << 12;
+ QTest::newRow("{<He(ll)o>, w^orld}!|rtl")
+ << standard[2]
+ << 4 << 2 << 8
+ << 0 << 5
+ << 0 << 12;
+
+ QTest::newRow("!{dlro^w ,<o(ll)eH>}|ltr")
+ << standard[3]
+ << 9 << 11 << 5
+ << 8 << 13
+ << 1 << 13;
+ QTest::newRow("!{dlro^w ,<o(ll)eH>}|rtl")
+ << standard[3]
+ << 11 << 9 << 5
+ << 8 << 13
+ << 1 << 13;
+}
+
+void tst_qdeclarativetextedit::moveCursorSelectionSequence()
+{
+ QFETCH(QString, testStr);
+ QFETCH(int, cursorPosition);
+ QFETCH(int, movePosition1);
+ QFETCH(int, movePosition2);
+ QFETCH(int, selection1Start);
+ QFETCH(int, selection1End);
+ QFETCH(int, selection2Start);
+ QFETCH(int, selection2End);
+
+ QString componentStr = "import QtQuick 1.1\nTextEdit { text: \""+ testStr +"\"; }";
+ QDeclarativeComponent texteditComponent(&engine);
+ texteditComponent.setData(componentStr.toLatin1(), QUrl());
+ QDeclarativeTextEdit *texteditObject = qobject_cast<QDeclarativeTextEdit*>(texteditComponent.create());
+ QVERIFY(texteditObject != 0);
+
+ texteditObject->setCursorPosition(cursorPosition);
+
+ texteditObject->moveCursorSelection(movePosition1, QDeclarativeTextEdit::SelectWords);
+ QCOMPARE(texteditObject->selectedText(), testStr.mid(selection1Start, selection1End - selection1Start));
+ QCOMPARE(texteditObject->selectionStart(), selection1Start);
+ QCOMPARE(texteditObject->selectionEnd(), selection1End);
+
+ texteditObject->moveCursorSelection(movePosition2, QDeclarativeTextEdit::SelectWords);
+ QCOMPARE(texteditObject->selectedText(), testStr.mid(selection2Start, selection2End - selection2Start));
+ QCOMPARE(texteditObject->selectionStart(), selection2Start);
+ QCOMPARE(texteditObject->selectionEnd(), selection2End);
+}
+
+
void tst_qdeclarativetextedit::mouseSelection_data()
{
QTest::addColumn<QString>("qmlfile");
@@ -995,6 +1179,55 @@ void tst_qdeclarativetextedit::dragMouseSelection()
QVERIFY(str1 != str2); // Verify the second press and drag is a new selection and doesn't not the first moved.
}
+void tst_qdeclarativetextedit::mouseSelectionMode_data()
+{
+ QTest::addColumn<QString>("qmlfile");
+ QTest::addColumn<bool>("selectWords");
+
+ // import installed
+ QTest::newRow("SelectWords") << SRCDIR "/data/mouseselectionmode_words.qml" << true;
+ QTest::newRow("SelectCharacters") << SRCDIR "/data/mouseselectionmode_characters.qml" << false;
+ QTest::newRow("default") << SRCDIR "/data/mouseselectionmode_default.qml" << false;
+}
+
+void tst_qdeclarativetextedit::mouseSelectionMode()
+{
+ QFETCH(QString, qmlfile);
+ QFETCH(bool, selectWords);
+
+ QString text = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
+
+ QDeclarativeView *canvas = createView(qmlfile);
+
+ 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-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)));
+ //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);
+ QApplication::sendEvent(canvas->viewport(), &mv);
+ QTest::mouseRelease(canvas->viewport(), Qt::LeftButton, 0, canvas->mapFromScene(QPoint(x2,y)));
+ QString str = textEditObject->selectedText();
+ if (selectWords) {
+ QCOMPARE(str, text);
+ } else {
+ QVERIFY(str.length() > 3);
+ QVERIFY(str != text);
+ }
+
+ delete canvas;
+}
+
void tst_qdeclarativetextedit::inputMethodHints()
{
QDeclarativeView *canvas = createView(SRCDIR "/data/inputmethodhints.qml");
diff --git a/tests/auto/declarative/qdeclarativetextinput/data/mouseselectionmode_characters.qml b/tests/auto/declarative/qdeclarativetextinput/data/mouseselectionmode_characters.qml
new file mode 100644
index 0000000..0ffc6ff
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativetextinput/data/mouseselectionmode_characters.qml
@@ -0,0 +1,8 @@
+import QtQuick 1.1
+
+TextInput {
+ focus: true
+ text: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+ selectByMouse: true
+ mouseSelectionMode: TextInput.SelectCharacters
+}
diff --git a/tests/auto/declarative/qdeclarativetextinput/data/mouseselectionmode_default.qml b/tests/auto/declarative/qdeclarativetextinput/data/mouseselectionmode_default.qml
new file mode 100644
index 0000000..87c174b
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativetextinput/data/mouseselectionmode_default.qml
@@ -0,0 +1,7 @@
+import QtQuick 1.1
+
+TextInput {
+ focus: true
+ text: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+ selectByMouse: true
+}
diff --git a/tests/auto/declarative/qdeclarativetextinput/data/mouseselectionmode_words.qml b/tests/auto/declarative/qdeclarativetextinput/data/mouseselectionmode_words.qml
new file mode 100644
index 0000000..df69a7d
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativetextinput/data/mouseselectionmode_words.qml
@@ -0,0 +1,8 @@
+import QtQuick 1.1
+
+TextInput {
+ focus: true
+ text: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+ selectByMouse: true
+ mouseSelectionMode: TextInput.SelectWords
+}
diff --git a/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp b/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp
index 7cdec27..675367c 100644
--- a/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp
+++ b/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp
@@ -91,7 +91,11 @@ private slots:
void selection();
void moveCursorSelection_data();
void moveCursorSelection();
+ void moveCursorSelectionSequence_data();
+ void moveCursorSelectionSequence();
void dragMouseSelection();
+ void mouseSelectionMode_data();
+ void mouseSelectionMode();
void horizontalAlignment_data();
void horizontalAlignment();
@@ -462,91 +466,115 @@ void tst_qdeclarativetextinput::moveCursorSelection_data()
QTest::newRow("jum()ped|characters")
<< standard[0] << 23 << 23 << QDeclarativeTextInput::SelectCharacters << 23 << 23 << true;
- QTest::newRow("(t)he|words")
+ QTest::newRow("<(t)he>|words")
<< standard[0] << 0 << 1 << QDeclarativeTextInput::SelectWords << 0 << 3 << true;
- QTest::newRow("do(g)|words")
+ QTest::newRow("<do(g)>|words")
<< standard[0] << 43 << 44 << QDeclarativeTextInput::SelectWords << 41 << 44 << true;
- QTest::newRow("jum(p)ed|words")
+ QTest::newRow("<jum(p)ed>|words")
<< standard[0] << 23 << 24 << QDeclarativeTextInput::SelectWords << 20 << 26 << true;
- QTest::newRow("jumped( )over|words")
- << standard[0] << 26 << 27 << QDeclarativeTextInput::SelectWords << 27 << 27 << false;
- QTest::newRow("jumped( )over|words,reversed")
- << standard[0] << 27 << 26 << QDeclarativeTextInput::SelectWords << 26 << 26 << false;
- QTest::newRow("(the )|words")
- << standard[0] << 0 << 4 << QDeclarativeTextInput::SelectWords << 0 << 3 << true;
- QTest::newRow("( dog)|words")
- << standard[0] << 40 << 44 << QDeclarativeTextInput::SelectWords << 41 << 44 << true;
- QTest::newRow("( jumped )|words")
- << standard[0] << 19 << 27 << QDeclarativeTextInput::SelectWords << 20 << 26 << true;
- QTest::newRow("th(e qu)ick|words")
+ QTest::newRow("<jumped( )>over|words,ltr")
+ << standard[0] << 26 << 27 << QDeclarativeTextInput::SelectWords << 20 << 27 << false;
+ QTest::newRow("jumped<( )over>|words,rtl")
+ << standard[0] << 27 << 26 << QDeclarativeTextInput::SelectWords << 26 << 31 << false;
+ QTest::newRow("<(the )>quick|words,ltr")
+ << standard[0] << 0 << 4 << QDeclarativeTextInput::SelectWords << 0 << 4 << false;
+ QTest::newRow("<(the )quick>|words,rtl")
+ << standard[0] << 4 << 0 << QDeclarativeTextInput::SelectWords << 0 << 9 << false;
+ QTest::newRow("<lazy( dog)>|words,ltr")
+ << standard[0] << 40 << 44 << QDeclarativeTextInput::SelectWords << 36 << 44 << false;
+ QTest::newRow("lazy<( dog)>|words,rtl")
+ << standard[0] << 44 << 40 << QDeclarativeTextInput::SelectWords << 40 << 44 << false;
+ QTest::newRow("<fox( jumped )>over|words,ltr")
+ << standard[0] << 19 << 27 << QDeclarativeTextInput::SelectWords << 16 << 27 << false;
+ QTest::newRow("fox<( jumped )over>|words,rtl")
+ << standard[0] << 27 << 19 << QDeclarativeTextInput::SelectWords << 19 << 31 << false;
+ QTest::newRow("<th(e qu)ick>|words")
<< standard[0] << 2 << 6 << QDeclarativeTextInput::SelectWords << 0 << 9 << true;
- QTest::newRow("la(zy d)og|words")
+ QTest::newRow("<la(zy d)og|words>")
<< standard[0] << 38 << 42 << QDeclarativeTextInput::SelectWords << 36 << 44 << true;
- QTest::newRow("jum(ped ov)er|words")
+ QTest::newRow("<jum(ped ov)er>|words")
<< standard[0] << 23 << 29 << QDeclarativeTextInput::SelectWords << 20 << 31 << true;
- QTest::newRow("()the|words")
+ QTest::newRow("<()>the|words")
<< standard[0] << 0 << 0 << QDeclarativeTextInput::SelectWords << 0 << 0 << true;
- QTest::newRow("dog()|words")
+ QTest::newRow("dog<()>|words")
<< standard[0] << 44 << 44 << QDeclarativeTextInput::SelectWords << 44 << 44 << true;
- QTest::newRow("jum()ped|words")
+ QTest::newRow("jum<()>ped|words")
<< standard[0] << 23 << 23 << QDeclarativeTextInput::SelectWords << 23 << 23 << true;
- QTest::newRow("Hello(,) |words")
+ QTest::newRow("Hello<(,)> |words")
<< standard[2] << 5 << 6 << QDeclarativeTextInput::SelectWords << 5 << 6 << true;
- QTest::newRow("Hello(, )|words")
- << standard[2] << 5 << 7 << QDeclarativeTextInput::SelectWords << 5 << 6 << true;
- QTest::newRow("Hel(lo, )|words")
- << standard[2] << 3 << 7 << QDeclarativeTextInput::SelectWords << 0 << 6 << true;
- QTest::newRow("Hel(lo),|words")
+ QTest::newRow("Hello<(, )>world|words,ltr")
+ << standard[2] << 5 << 7 << QDeclarativeTextInput::SelectWords << 5 << 7 << false;
+ QTest::newRow("Hello<(, )world>|words,rtl")
+ << standard[2] << 7 << 5 << QDeclarativeTextInput::SelectWords << 5 << 12 << false;
+ QTest::newRow("<Hel(lo, )>world|words,ltr")
+ << standard[2] << 3 << 7 << QDeclarativeTextInput::SelectWords << 0 << 7 << false;
+ QTest::newRow("<Hel(lo, )world>|words,rtl")
+ << standard[2] << 7 << 3 << QDeclarativeTextInput::SelectWords << 0 << 12 << false;
+ QTest::newRow("<Hel(lo)>,|words")
<< standard[2] << 3 << 5 << QDeclarativeTextInput::SelectWords << 0 << 5 << true;
- QTest::newRow("Hello(),|words")
+ QTest::newRow("Hello<()>,|words")
<< standard[2] << 5 << 5 << QDeclarativeTextInput::SelectWords << 5 << 5 << true;
- QTest::newRow("Hello,()|words")
+ QTest::newRow("Hello,<()>|words")
<< standard[2] << 6 << 6 << QDeclarativeTextInput::SelectWords << 6 << 6 << true;
- QTest::newRow("Hello,( )|words")
- << standard[2] << 6 << 7 << QDeclarativeTextInput::SelectWords << 7 << 7 << false;
- QTest::newRow("Hello,( )|words,reversed")
- << standard[2] << 7 << 6 << QDeclarativeTextInput::SelectWords << 6 << 6 << false;
- QTest::newRow("Hello,( world)|words")
- << standard[2] << 6 << 12 << QDeclarativeTextInput::SelectWords << 7 << 12 << true;
- QTest::newRow("Hello,( world!)|words")
- << standard[2] << 6 << 13 << QDeclarativeTextInput::SelectWords << 7 << 13 << true;
- QTest::newRow("Hello(, world!)|words")
+ QTest::newRow("Hello<,( )>world|words,ltr")
+ << standard[2] << 6 << 7 << QDeclarativeTextInput::SelectWords << 5 << 7 << false;
+ QTest::newRow("Hello,<( )world>|words,rtl")
+ << standard[2] << 7 << 6 << QDeclarativeTextInput::SelectWords << 6 << 12 << false;
+ QTest::newRow("Hello<,( world)>|words,ltr")
+ << standard[2] << 6 << 12 << QDeclarativeTextInput::SelectWords << 5 << 12 << false;
+ QTest::newRow("Hello,<( world)>|words,rtl")
+ << standard[2] << 12 << 6 << QDeclarativeTextInput::SelectWords << 6 << 12 << false;
+ QTest::newRow("Hello<,( world!)>|words,ltr")
+ << standard[2] << 6 << 13 << QDeclarativeTextInput::SelectWords << 5 << 13 << false;
+ QTest::newRow("Hello,<( world!)>|words,rtl")
+ << standard[2] << 13 << 6 << QDeclarativeTextInput::SelectWords << 6 << 13 << false;
+ QTest::newRow("Hello<(, world!)>|words")
<< standard[2] << 5 << 13 << QDeclarativeTextInput::SelectWords << 5 << 13 << true;
- QTest::newRow("world(!)|words")
- << standard[2] << 12 << 13 << QDeclarativeTextInput::SelectWords << 12 << 13 << true;
- QTest::newRow("world!())|words")
+ // Fails due to an issue with QTextBoundaryFinder and punctuation at the end of strings.
+ // QTBUG-11365
+ // QTest::newRow("world<(!)>|words")
+ // << standard[2] << 12 << 13 << QDeclarativeTextInput::SelectWords << 12 << 13 << true;
+ QTest::newRow("world!<()>)|words")
<< standard[2] << 13 << 13 << QDeclarativeTextInput::SelectWords << 13 << 13 << true;
- QTest::newRow("world()!)|words")
+ QTest::newRow("world<()>!)|words")
<< standard[2] << 12 << 12 << QDeclarativeTextInput::SelectWords << 12 << 12 << true;
- QTest::newRow("(,)olleH |words")
+ QTest::newRow("<(,)>olleH |words")
<< standard[3] << 7 << 8 << QDeclarativeTextInput::SelectWords << 7 << 8 << true;
- QTest::newRow("( ,)olleH|words")
- << standard[3] << 6 << 8 << QDeclarativeTextInput::SelectWords << 7 << 8 << true;
- QTest::newRow("( ,ol)leH|words")
- << standard[3] << 6 << 10 << QDeclarativeTextInput::SelectWords << 7 << 13 << true;
- QTest::newRow(",(ol)leH,|words")
+ QTest::newRow("<dlrow( ,)>olleH|words,ltr")
+ << standard[3] << 6 << 8 << QDeclarativeTextInput::SelectWords << 1 << 8 << false;
+ QTest::newRow("dlrow<( ,)>olleH|words,rtl")
+ << standard[3] << 8 << 6 << QDeclarativeTextInput::SelectWords << 6 << 8 << false;
+ QTest::newRow("<dlrow( ,ol)leH>|words,ltr")
+ << standard[3] << 6 << 10 << QDeclarativeTextInput::SelectWords << 1 << 13 << false;
+ QTest::newRow("dlrow<( ,ol)leH>|words,rtl")
+ << standard[3] << 10 << 6 << QDeclarativeTextInput::SelectWords << 6 << 13 << false;
+ QTest::newRow(",<(ol)leH>,|words")
<< standard[3] << 8 << 10 << QDeclarativeTextInput::SelectWords << 8 << 13 << true;
- QTest::newRow(",()olleH|words")
+ QTest::newRow(",<()>olleH|words")
<< standard[3] << 8 << 8 << QDeclarativeTextInput::SelectWords << 8 << 8 << true;
- QTest::newRow("(),olleH|words")
+ QTest::newRow("<()>,olleH|words")
<< standard[3] << 7 << 7 << QDeclarativeTextInput::SelectWords << 7 << 7 << true;
- QTest::newRow("( ),olleH|words")
- << standard[3] << 6 << 7 << QDeclarativeTextInput::SelectWords << 7 << 7 << false;
- QTest::newRow("( ),olleH|words,reversed")
- << standard[3] << 7 << 6 << QDeclarativeTextInput::SelectWords << 6 << 6 << false;
- QTest::newRow("(dlrow ),olleH|words")
- << standard[3] << 1 << 7 << QDeclarativeTextInput::SelectWords << 1 << 6 << true;
- QTest::newRow("(!dlrow ),olleH|words")
- << standard[3] << 0 << 7 << QDeclarativeTextInput::SelectWords << 0 << 6 << true;
+ QTest::newRow("<dlrow( )>,olleH|words,ltr")
+ << standard[3] << 6 << 7 << QDeclarativeTextInput::SelectWords << 1 << 7 << false;
+ QTest::newRow("dlrow<( ),>olleH|words,rtl")
+ << standard[3] << 7 << 6 << QDeclarativeTextInput::SelectWords << 6 << 8 << false;
+ QTest::newRow("<(dlrow )>,olleH|words,ltr")
+ << standard[3] << 1 << 7 << QDeclarativeTextInput::SelectWords << 1 << 7 << false;
+ QTest::newRow("<(dlrow ),>olleH|words,rtl")
+ << standard[3] << 7 << 1 << QDeclarativeTextInput::SelectWords << 1 << 8 << false;
+ QTest::newRow("<(!dlrow )>,olleH|words,ltr")
+ << standard[3] << 0 << 7 << QDeclarativeTextInput::SelectWords << 0 << 7 << false;
+ QTest::newRow("<(!dlrow ),>olleH|words,rtl")
+ << standard[3] << 7 << 0 << QDeclarativeTextInput::SelectWords << 0 << 8 << false;
QTest::newRow("(!dlrow ,)olleH|words")
<< standard[3] << 0 << 8 << QDeclarativeTextInput::SelectWords << 0 << 8 << true;
- QTest::newRow("(!)dlrow|words")
+ QTest::newRow("<(!)>dlrow|words")
<< standard[3] << 0 << 1 << QDeclarativeTextInput::SelectWords << 0 << 1 << true;
- QTest::newRow("()!dlrow|words")
+ QTest::newRow("<()>!dlrow|words")
<< standard[3] << 0 << 0 << QDeclarativeTextInput::SelectWords << 0 << 0 << true;
- QTest::newRow("!()dlrow|words")
+ QTest::newRow("!<()>dlrow|words")
<< standard[3] << 1 << 1 << QDeclarativeTextInput::SelectWords << 1 << 1 << true;
}
@@ -569,6 +597,7 @@ void tst_qdeclarativetextinput::moveCursorSelection()
textinputObject->setCursorPosition(cursorPosition);
textinputObject->moveCursorSelection(movePosition, mode);
+ QCOMPARE(textinputObject->selectedText(), testStr.mid(selectionStart, selectionEnd - selectionStart));
QCOMPARE(textinputObject->selectionStart(), selectionStart);
QCOMPARE(textinputObject->selectionEnd(), selectionEnd);
@@ -576,11 +605,167 @@ void tst_qdeclarativetextinput::moveCursorSelection()
textinputObject->setCursorPosition(movePosition);
textinputObject->moveCursorSelection(cursorPosition, mode);
+ QCOMPARE(textinputObject->selectedText(), testStr.mid(selectionStart, selectionEnd - selectionStart));
QCOMPARE(textinputObject->selectionStart(), selectionStart);
QCOMPARE(textinputObject->selectionEnd(), selectionEnd);
}
}
+void tst_qdeclarativetextinput::moveCursorSelectionSequence_data()
+{
+ QTest::addColumn<QString>("testStr");
+ QTest::addColumn<int>("cursorPosition");
+ QTest::addColumn<int>("movePosition1");
+ QTest::addColumn<int>("movePosition2");
+ QTest::addColumn<int>("selection1Start");
+ QTest::addColumn<int>("selection1End");
+ QTest::addColumn<int>("selection2Start");
+ QTest::addColumn<int>("selection2End");
+
+ QTest::newRow("the {<quick( bro)wn> f^ox} jumped|ltr")
+ << standard[0]
+ << 9 << 13 << 17
+ << 4 << 15
+ << 4 << 19;
+ QTest::newRow("the quick<( {bro)wn> f^ox} jumped|rtl")
+ << standard[0]
+ << 13 << 9 << 17
+ << 9 << 15
+ << 10 << 19;
+ QTest::newRow("the {<quick( bro)wn> ^}fox jumped|ltr")
+ << standard[0]
+ << 9 << 13 << 16
+ << 4 << 15
+ << 4 << 16;
+ QTest::newRow("the quick<( {bro)wn> ^}fox jumped|rtl")
+ << standard[0]
+ << 13 << 9 << 16
+ << 9 << 15
+ << 10 << 16;
+ QTest::newRow("the {<quick( bro)wn^>} fox jumped|ltr")
+ << standard[0]
+ << 9 << 13 << 15
+ << 4 << 15
+ << 4 << 15;
+ QTest::newRow("the quick<( {bro)wn^>} f^ox jumped|rtl")
+ << standard[0]
+ << 13 << 9 << 15
+ << 9 << 15
+ << 10 << 15;
+ QTest::newRow("the {<quick() ^}bro)wn> fox|ltr")
+ << standard[0]
+ << 9 << 13 << 10
+ << 4 << 15
+ << 4 << 10;
+ QTest::newRow("the quick<( {^bro)wn>} fox|rtl")
+ << standard[0]
+ << 13 << 9 << 10
+ << 9 << 15
+ << 10 << 15;
+ QTest::newRow("the {<quick^}( bro)wn> fox|ltr")
+ << standard[0]
+ << 9 << 13 << 9
+ << 4 << 15
+ << 4 << 9;
+ QTest::newRow("the quick{<(^ bro)wn>} fox|rtl")
+ << standard[0]
+ << 13 << 9 << 9
+ << 9 << 15
+ << 9 << 15;
+ QTest::newRow("the {<qui^ck}( bro)wn> fox|ltr")
+ << standard[0]
+ << 9 << 13 << 7
+ << 4 << 15
+ << 4 << 9;
+ QTest::newRow("the {<qui^ck}( bro)wn> fox|rtl")
+ << standard[0]
+ << 13 << 9 << 7
+ << 9 << 15
+ << 4 << 15;
+ QTest::newRow("the {<^quick}( bro)wn> fox|ltr")
+ << standard[0]
+ << 9 << 13 << 4
+ << 4 << 15
+ << 4 << 9;
+ QTest::newRow("the {<^quick}( bro)wn> fox|rtl")
+ << standard[0]
+ << 13 << 9 << 4
+ << 9 << 15
+ << 4 << 15;
+ QTest::newRow("the{^ <quick}( bro)wn> fox|ltr")
+ << standard[0]
+ << 9 << 13 << 3
+ << 4 << 15
+ << 3 << 9;
+ QTest::newRow("the{^ <quick}( bro)wn> fox|rtl")
+ << standard[0]
+ << 13 << 9 << 3
+ << 9 << 15
+ << 3 << 15;
+ QTest::newRow("{t^he <quick}( bro)wn> fox|ltr")
+ << standard[0]
+ << 9 << 13 << 1
+ << 4 << 15
+ << 0 << 9;
+ QTest::newRow("{t^he <quick}( bro)wn> fox|rtl")
+ << standard[0]
+ << 13 << 9 << 1
+ << 9 << 15
+ << 0 << 15;
+
+ QTest::newRow("{<He(ll)o>, w^orld}!|ltr")
+ << standard[2]
+ << 2 << 4 << 8
+ << 0 << 5
+ << 0 << 12;
+ QTest::newRow("{<He(ll)o>, w^orld}!|rtl")
+ << standard[2]
+ << 4 << 2 << 8
+ << 0 << 5
+ << 0 << 12;
+
+ QTest::newRow("!{dlro^w ,<o(ll)eH>}|ltr")
+ << standard[3]
+ << 9 << 11 << 5
+ << 8 << 13
+ << 1 << 13;
+ QTest::newRow("!{dlro^w ,<o(ll)eH>}|rtl")
+ << standard[3]
+ << 11 << 9 << 5
+ << 8 << 13
+ << 1 << 13;
+}
+
+void tst_qdeclarativetextinput::moveCursorSelectionSequence()
+{
+ QFETCH(QString, testStr);
+ QFETCH(int, cursorPosition);
+ QFETCH(int, movePosition1);
+ QFETCH(int, movePosition2);
+ QFETCH(int, selection1Start);
+ QFETCH(int, selection1End);
+ QFETCH(int, selection2Start);
+ QFETCH(int, selection2End);
+
+ QString componentStr = "import QtQuick 1.1\nTextInput { text: \""+ testStr +"\"; }";
+ QDeclarativeComponent textinputComponent(&engine);
+ textinputComponent.setData(componentStr.toLatin1(), QUrl());
+ QDeclarativeTextInput *textinputObject = qobject_cast<QDeclarativeTextInput*>(textinputComponent.create());
+ QVERIFY(textinputObject != 0);
+
+ textinputObject->setCursorPosition(cursorPosition);
+
+ textinputObject->moveCursorSelection(movePosition1, QDeclarativeTextInput::SelectWords);
+ QCOMPARE(textinputObject->selectedText(), testStr.mid(selection1Start, selection1End - selection1Start));
+ QCOMPARE(textinputObject->selectionStart(), selection1Start);
+ QCOMPARE(textinputObject->selectionEnd(), selection1End);
+
+ textinputObject->moveCursorSelection(movePosition2, QDeclarativeTextInput::SelectWords);
+ QCOMPARE(textinputObject->selectedText(), testStr.mid(selection2Start, selection2End - selection2Start));
+ QCOMPARE(textinputObject->selectionStart(), selection2Start);
+ QCOMPARE(textinputObject->selectionEnd(), selection2End);
+}
+
void tst_qdeclarativetextinput::dragMouseSelection()
{
QString qmlfile = SRCDIR "/data/mouseselection_true.qml";
@@ -626,6 +811,55 @@ void tst_qdeclarativetextinput::dragMouseSelection()
delete canvas;
}
+void tst_qdeclarativetextinput::mouseSelectionMode_data()
+{
+ QTest::addColumn<QString>("qmlfile");
+ QTest::addColumn<bool>("selectWords");
+
+ // import installed
+ QTest::newRow("SelectWords") << SRCDIR "/data/mouseselectionmode_words.qml" << true;
+ QTest::newRow("SelectCharacters") << SRCDIR "/data/mouseselectionmode_characters.qml" << false;
+ QTest::newRow("default") << SRCDIR "/data/mouseselectionmode_default.qml" << false;
+}
+
+void tst_qdeclarativetextinput::mouseSelectionMode()
+{
+ QFETCH(QString, qmlfile);
+ QFETCH(bool, selectWords);
+
+ QString text = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
+
+ QDeclarativeView *canvas = createView(qmlfile);
+
+ canvas->show();
+ QApplication::setActiveWindow(canvas);
+ QTest::qWaitForWindowShown(canvas);
+ QTRY_COMPARE(QApplication::activeWindow(), static_cast<QWidget *>(canvas));
+
+ QVERIFY(canvas->rootObject() != 0);
+ QDeclarativeTextInput *textInputObject = qobject_cast<QDeclarativeTextInput *>(canvas->rootObject());
+ QVERIFY(textInputObject != 0);
+
+ // press-and-drag-and-release from x1 to x2
+ int x1 = 10;
+ int x2 = 70;
+ int y = textInputObject->height()/2;
+ QTest::mousePress(canvas->viewport(), Qt::LeftButton, 0, canvas->mapFromScene(QPoint(x1,y)));
+ //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);
+ QApplication::sendEvent(canvas->viewport(), &mv);
+ QTest::mouseRelease(canvas->viewport(), Qt::LeftButton, 0, canvas->mapFromScene(QPoint(x2,y)));
+ QString str = textInputObject->selectedText();
+ if (selectWords) {
+ QCOMPARE(str, text);
+ } else {
+ QVERIFY(str.length() > 3);
+ QVERIFY(str != text);
+ }
+
+ delete canvas;
+}
+
void tst_qdeclarativetextinput::horizontalAlignment_data()
{
QTest::addColumn<int>("hAlign");