summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/declarative/fx/qfxtextinput.cpp26
-rw-r--r--src/declarative/fx/qfxtextinput.h2
-rw-r--r--tests/auto/declarative/qfxtextedit/tst_qfxtextedit.cpp8
-rw-r--r--tests/auto/declarative/qfxtextinput/tst_qfxtextinput.cpp26
4 files changed, 52 insertions, 10 deletions
diff --git a/src/declarative/fx/qfxtextinput.cpp b/src/declarative/fx/qfxtextinput.cpp
index f5bf911..e9ddd3f 100644
--- a/src/declarative/fx/qfxtextinput.cpp
+++ b/src/declarative/fx/qfxtextinput.cpp
@@ -289,6 +289,18 @@ void QFxTextInput::setCursorPosition(int cp)
}
/*!
+ \internal
+
+ Returns a Rect which encompasses the cursor, but which may be larger than is
+ required. Ignores custom cursor delegates.
+*/
+QRect QFxTextInput::cursorRect() const
+{
+ Q_D(const QFxTextInput);
+ return d->control->cursorRect();
+}
+
+/*!
\qmlproperty int TextInput::selectionStart
The cursor position before the first character in the current selection.
@@ -489,17 +501,19 @@ void QFxTextInput::setCursorDelegate(QmlComponent* c)
{
Q_D(QFxTextInput);
d->cursorComponent = c;
- d->startCreatingCursor();
+ if(!c){
+ //note that the components are owned by something else
+ disconnect(d->control, SIGNAL(cursorPositionChanged(int, int)),
+ this, SLOT(moveCursor()));
+ delete d->cursorItem;
+ }else{
+ d->startCreatingCursor();
+ }
}
void QFxTextInputPrivate::startCreatingCursor()
{
Q_Q(QFxTextInput);
- if(!cursorComponent){
- q->disconnect(control, SIGNAL(cursorPositionChanged(int, int)),
- q, SLOT(moveCursor()));
- return;
- }
q->connect(control, SIGNAL(cursorPositionChanged(int, int)),
q, SLOT(moveCursor()));
if(cursorComponent->isReady()){
diff --git a/src/declarative/fx/qfxtextinput.h b/src/declarative/fx/qfxtextinput.h
index d5d0450..2540d41 100644
--- a/src/declarative/fx/qfxtextinput.h
+++ b/src/declarative/fx/qfxtextinput.h
@@ -131,6 +131,8 @@ public:
int cursorPosition() const;
void setCursorPosition(int cp);
+ QRect cursorRect() const;
+
int selectionStart() const;
void setSelectionStart(int);
diff --git a/tests/auto/declarative/qfxtextedit/tst_qfxtextedit.cpp b/tests/auto/declarative/qfxtextedit/tst_qfxtextedit.cpp
index 7ab598f..f78e564 100644
--- a/tests/auto/declarative/qfxtextedit/tst_qfxtextedit.cpp
+++ b/tests/auto/declarative/qfxtextedit/tst_qfxtextedit.cpp
@@ -433,10 +433,10 @@ void tst_qfxtextedit::selection()
void tst_qfxtextedit::cursorDelegate()
{
- QmlView* view = new QmlView(0);
- view->show();
- view->setUrl(QUrl("data/cursorTest.qml"));
+ QmlView* view = createView(SRCDIR "/data/cursorTest.qml");
view->execute();
+ view->show();
+ view->setFocus();
QFxTextEdit *textEditObject = view->root()->findChild<QFxTextEdit*>("textEditObject");
QVERIFY(textEditObject != 0);
QVERIFY(textEditObject->findChild<QFxItem*>("cursorInstance"));
@@ -467,6 +467,7 @@ void tst_qfxtextedit::navigation()
QmlView *canvas = createView(SRCDIR "/data/navigation.qml");
canvas->execute();
canvas->show();
+ canvas->setFocus();
QVERIFY(canvas->root() != 0);
@@ -474,6 +475,7 @@ void tst_qfxtextedit::navigation()
QVERIFY(input != 0);
QTRY_VERIFY(input->hasFocus() == true);
+ QEXPECT_FAIL("", "Depends on QT-2236", Abort);
simulateKey(canvas, Qt::Key_Left);
QVERIFY(input->hasFocus() == false);
simulateKey(canvas, Qt::Key_Right);
diff --git a/tests/auto/declarative/qfxtextinput/tst_qfxtextinput.cpp b/tests/auto/declarative/qfxtextinput/tst_qfxtextinput.cpp
index bd0b9c3..069574c 100644
--- a/tests/auto/declarative/qfxtextinput/tst_qfxtextinput.cpp
+++ b/tests/auto/declarative/qfxtextinput/tst_qfxtextinput.cpp
@@ -310,6 +310,7 @@ void tst_qfxtextinput::navigation()
QmlView *canvas = createView(SRCDIR "/data/navigation.qml");
canvas->execute();
canvas->show();
+ canvas->setFocus();
QVERIFY(canvas->root() != 0);
@@ -329,7 +330,30 @@ void tst_qfxtextinput::navigation()
void tst_qfxtextinput::cursorDelegate()
{
- //TODO:Get the QFxTextEdit test passing first
+ QmlView* view = createView(SRCDIR "/data/cursorTest.qml");
+ view->execute();
+ view->show();
+ view->setFocus();
+ QFxTextInput *textInputObject = view->root()->findChild<QFxTextInput*>("textInputObject");
+ QVERIFY(textInputObject != 0);
+ QVERIFY(textInputObject->findChild<QFxItem*>("cursorInstance"));
+ //Test Delegate gets created
+ textInputObject->setFocus(true);
+ QFxItem* delegateObject = textInputObject->findChild<QFxItem*>("cursorInstance");
+ QVERIFY(delegateObject);
+ //Test Delegate gets moved
+ for(int i=0; i<= textInputObject->text().length(); i++){
+ textInputObject->setCursorPosition(i);
+ //+5 is because the TextInput cursorRect is just a 10xHeight area centered on cursor position
+ QCOMPARE(textInputObject->cursorRect().x() + 5, qRound(delegateObject->x()));
+ QCOMPARE(textInputObject->cursorRect().y(), qRound(delegateObject->y()));
+ }
+ textInputObject->setCursorPosition(0);
+ QCOMPARE(textInputObject->cursorRect().x()+5, qRound(delegateObject->x()));
+ QCOMPARE(textInputObject->cursorRect().y(), qRound(delegateObject->y()));
+ //Test Delegate gets deleted
+ textInputObject->setCursorDelegate(0);
+ QVERIFY(!textInputObject->findChild<QFxItem*>("cursorInstance"));
}
void tst_qfxtextinput::simulateKey(QmlView *view, int key)