aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/declarative/qsgtextedit
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/declarative/qsgtextedit')
-rw-r--r--tests/auto/declarative/qsgtextedit/data/horizontalAlignment_RightToLeft.qml1
-rw-r--r--tests/auto/declarative/qsgtextedit/data/mouseselection_false_words.qml3
-rw-r--r--tests/auto/declarative/qsgtextedit/data/mouseselection_true_words.qml3
-rw-r--r--tests/auto/declarative/qsgtextedit/tst_qsgtextedit.cpp100
4 files changed, 86 insertions, 21 deletions
diff --git a/tests/auto/declarative/qsgtextedit/data/horizontalAlignment_RightToLeft.qml b/tests/auto/declarative/qsgtextedit/data/horizontalAlignment_RightToLeft.qml
index 74592fed7f..4cd92367ec 100644
--- a/tests/auto/declarative/qsgtextedit/data/horizontalAlignment_RightToLeft.qml
+++ b/tests/auto/declarative/qsgtextedit/data/horizontalAlignment_RightToLeft.qml
@@ -18,6 +18,7 @@ Rectangle {
objectName: "text"
anchors.fill: parent
text: top.text
+ focus: true
}
}
}
diff --git a/tests/auto/declarative/qsgtextedit/data/mouseselection_false_words.qml b/tests/auto/declarative/qsgtextedit/data/mouseselection_false_words.qml
index ac32f4ced7..86aea46a85 100644
--- a/tests/auto/declarative/qsgtextedit/data/mouseselection_false_words.qml
+++ b/tests/auto/declarative/qsgtextedit/data/mouseselection_false_words.qml
@@ -2,6 +2,7 @@ import QtQuick 2.0
TextEdit {
focus: true
- text: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+ text: "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ"
selectByMouse: false
+ mouseSelectionMode: TextEdit.SelectWords
}
diff --git a/tests/auto/declarative/qsgtextedit/data/mouseselection_true_words.qml b/tests/auto/declarative/qsgtextedit/data/mouseselection_true_words.qml
index 7c7cb0b6fc..c356999220 100644
--- a/tests/auto/declarative/qsgtextedit/data/mouseselection_true_words.qml
+++ b/tests/auto/declarative/qsgtextedit/data/mouseselection_true_words.qml
@@ -2,6 +2,7 @@ import QtQuick 2.0
TextEdit {
focus: true
- text: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+ text: "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ"
selectByMouse: true
+ mouseSelectionMode: TextEdit.SelectWords
}
diff --git a/tests/auto/declarative/qsgtextedit/tst_qsgtextedit.cpp b/tests/auto/declarative/qsgtextedit/tst_qsgtextedit.cpp
index 79ff8ea3ec..7c0f097358 100644
--- a/tests/auto/declarative/qsgtextedit/tst_qsgtextedit.cpp
+++ b/tests/auto/declarative/qsgtextedit/tst_qsgtextedit.cpp
@@ -489,6 +489,8 @@ void tst_qsgtextedit::hAlign_RightToLeft()
QVERIFY(textEdit != 0);
canvas.show();
+ const QString rtlText = textEdit->text();
+
// implicit alignment should follow the reading direction of text
QCOMPARE(textEdit->hAlign(), QSGTextEdit::AlignRight);
QVERIFY(textEdit->positionToRectangle(0).x() > canvas.width()/2);
@@ -565,6 +567,16 @@ void tst_qsgtextedit::hAlign_RightToLeft()
QCOMPARE(textEdit->hAlign(), QSGTextEdit::AlignLeft);
QVERIFY(textEdit->positionToRectangle(0).x() < canvas.width()/2);
+ QApplication::setActiveWindow(&canvas);
+ QTest::qWaitForWindowShown(&canvas);
+ QTRY_COMPARE(QApplication::activeWindow(), static_cast<QWidget *>(&canvas));
+
+ textEdit->setText(QString());
+ { QInputMethodEvent ev(rtlText, QList<QInputMethodEvent::Attribute>()); QApplication::sendEvent(&canvas, &ev); }
+ QCOMPARE(textEdit->hAlign(), QSGTextEdit::AlignRight);
+ { QInputMethodEvent ev("Hello world!", QList<QInputMethodEvent::Attribute>()); QApplication::sendEvent(&canvas, &ev); }
+ QCOMPARE(textEdit->hAlign(), QSGTextEdit::AlignLeft);
+
#ifndef Q_OS_MAC // QTBUG-18040
// empty text with implicit alignment follows the system locale-based
// keyboard input direction from QApplication::keyboardInputDirection
@@ -1336,20 +1348,32 @@ void tst_qsgtextedit::moveCursorSelectionSequence()
void tst_qsgtextedit::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_qsgtextedit::mouseSelection()
{
QFETCH(QString, qmlfile);
- QFETCH(bool, expectSelection);
+ QFETCH(int, from);
+ QFETCH(int, to);
+ QFETCH(QString, selectedText);
QSGView canvas(QUrl::fromLocalFile(qmlfile));
@@ -1363,19 +1387,20 @@ void tst_qsgtextedit::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, Qt::LeftButton, 0, QPoint(x1,y));
- //QTest::mouseMove(canvas, QPoint(x2,y)); // doesn't work
- QMouseEvent mv(QEvent::MouseMove, QPoint(x2,y), Qt::LeftButton, Qt::LeftButton,Qt::NoModifier);
+ QPoint p1 = textEditObject->positionToRectangle(from).center().toPoint();
+ QPoint p2 = textEditObject->positionToRectangle(to).center().toPoint();
+ QTest::mousePress(&canvas, Qt::LeftButton, 0, p1);
+ //QTest::mouseMove(canvas->viewport(), canvas->mapFromScene(QPoint(x2,y))); // doesn't work
+ QMouseEvent mv(QEvent::MouseMove, p2, Qt::LeftButton, Qt::LeftButton,Qt::NoModifier);
QApplication::sendEvent(&canvas, &mv);
- QTest::mouseRelease(&canvas, Qt::LeftButton, 0, 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, 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, Qt::LeftButton, Qt::NoModifier, p1);
+ QTest::mouseClick(&canvas, Qt::LeftButton, Qt::ShiftModifier, p2);
+ QCOMPARE(textEditObject->selectedText(), selectedText);
}
void tst_qsgtextedit::dragMouseSelection()
@@ -1569,6 +1594,43 @@ void tst_qsgtextedit::cursorDelegate()
QCOMPARE(textEditObject->cursorRectangle().x(), qRound(delegateObject->x()));
QCOMPARE(textEditObject->cursorRectangle().y(), qRound(delegateObject->y()));
}
+ // Clear preedit text;
+ QInputMethodEvent event;
+ QApplication::sendEvent(&view, &event);
+
+
+ // Test delegate gets moved on mouse press.
+ textEditObject->setSelectByMouse(true);
+ textEditObject->setCursorPosition(0);
+ const QPoint point1 = textEditObject->positionToRectangle(5).center().toPoint();
+ QTest::mouseClick(&view, Qt::LeftButton, 0, point1);
+ QVERIFY(textEditObject->cursorPosition() != 0);
+ QCOMPARE(textEditObject->cursorRectangle().x(), qRound(delegateObject->x()));
+ QCOMPARE(textEditObject->cursorRectangle().y(), qRound(delegateObject->y()));
+
+ // Test delegate gets moved on mouse drag
+ textEditObject->setCursorPosition(0);
+ const QPoint point2 = textEditObject->positionToRectangle(10).center().toPoint();
+ QTest::mousePress(&view, Qt::LeftButton, 0, point1);
+ QMouseEvent mv(QEvent::MouseMove, point2, Qt::LeftButton, Qt::LeftButton,Qt::NoModifier);
+ QApplication::sendEvent(&view, &mv);
+ QTest::mouseRelease(&view, Qt::LeftButton, 0, point2);
+ QCOMPARE(textEditObject->cursorRectangle().x(), qRound(delegateObject->x()));
+ QCOMPARE(textEditObject->cursorRectangle().y(), qRound(delegateObject->y()));
+
+ textEditObject->setReadOnly(true);
+ textEditObject->setCursorPosition(0);
+ QTest::mouseClick(&view, Qt::LeftButton, 0, textEditObject->positionToRectangle(5).center().toPoint());
+ QVERIFY(textEditObject->cursorPosition() != 0);
+ QCOMPARE(textEditObject->cursorRectangle().x(), qRound(delegateObject->x()));
+ QCOMPARE(textEditObject->cursorRectangle().y(), qRound(delegateObject->y()));
+
+ textEditObject->setCursorPosition(0);
+ QTest::mouseClick(&view, Qt::LeftButton, 0, textEditObject->positionToRectangle(5).center().toPoint());
+ QVERIFY(textEditObject->cursorPosition() != 0);
+ QCOMPARE(textEditObject->cursorRectangle().x(), qRound(delegateObject->x()));
+ QCOMPARE(textEditObject->cursorRectangle().y(), qRound(delegateObject->y()));
+
textEditObject->setCursorPosition(0);
QCOMPARE(textEditObject->cursorRectangle().x(), qRound(delegateObject->x()));
QCOMPARE(textEditObject->cursorRectangle().y(), qRound(delegateObject->y()));