summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWarwick Allison <warwick.allison@nokia.com>2010-05-31 05:45:01 (GMT)
committerWarwick Allison <warwick.allison@nokia.com>2010-05-31 05:49:01 (GMT)
commitb8b1e9784583e3b5960b1966328299f8a1bec440 (patch)
tree26b147cdf82bde0b3d97610a8449fcc1599d2246
parentc00e6b499e89e4b872e9148c5f8a37f9050d9c84 (diff)
downloadQt-b8b1e9784583e3b5960b1966328299f8a1bec440.zip
Qt-b8b1e9784583e3b5960b1966328299f8a1bec440.tar.gz
Qt-b8b1e9784583e3b5960b1966328299f8a1bec440.tar.bz2
Simplify selection setting. Make TextInput more like TextEdit.
By making selectionStart/End read-only, and adding adding select(). Task-number: QTBUG-11056
-rw-r--r--examples/declarative/modelviews/webview/content/FieldText.qml2
-rw-r--r--examples/declarative/text/edit/edit.qml16
-rw-r--r--src/declarative/graphicsitems/qdeclarativetextedit.cpp68
-rw-r--r--src/declarative/graphicsitems/qdeclarativetextedit_p.h8
-rw-r--r--src/declarative/graphicsitems/qdeclarativetextinput.cpp54
-rw-r--r--src/declarative/graphicsitems/qdeclarativetextinput_p.h16
-rw-r--r--tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp39
-rw-r--r--tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp55
-rw-r--r--tests/auto/declarative/qmlvisual/qdeclarativetextedit/MultilineEdit.qml3
-rw-r--r--tests/auto/declarative/qmlvisual/qdeclarativetextinput/LineEdit.qml3
10 files changed, 125 insertions, 139 deletions
diff --git a/examples/declarative/modelviews/webview/content/FieldText.qml b/examples/declarative/modelviews/webview/content/FieldText.qml
index c9adde5..17fa4cd 100644
--- a/examples/declarative/modelviews/webview/content/FieldText.qml
+++ b/examples/declarative/modelviews/webview/content/FieldText.qml
@@ -161,8 +161,6 @@ Item {
color: "black"
readOnly: false
focus: true
- selectionStart: 0
- selectionEnd: -1
}
PropertyChanges {
target: editRegion
diff --git a/examples/declarative/text/edit/edit.qml b/examples/declarative/text/edit/edit.qml
index 2774739..0be42e9 100644
--- a/examples/declarative/text/edit/edit.qml
+++ b/examples/declarative/text/edit/edit.qml
@@ -157,14 +157,16 @@ Rectangle {
if (editor.state == "selection" && drag != "") {
if (drag == "start") {
var pos = edit.positionAt(mouse.x+x+startHandle.width/2,mouse.y+y);
- if (edit.selectionEnd < pos)
- edit.selectionEnd = pos;
- edit.selectionStart = pos;
+ var e = edit.selectionEnd;
+ if (e < pos)
+ e = pos;
+ edit.select(pos,e);
} else if (drag == "end") {
var pos = edit.positionAt(mouse.x+x-endHandle.width/2,mouse.y+y);
- if (edit.selectionStart > pos)
- edit.selectionStart = pos;
- edit.selectionEnd = pos;
+ var s = edit.selectionStart;
+ if (s > pos)
+ s = pos;
+ edit.select(s,pos);
}
}
}
@@ -226,7 +228,7 @@ Rectangle {
height: 16
Text { anchors.centerIn: parent; text: "Deselect" }
MouseArea { anchors.fill: parent;
- onClicked: { edit.cursorPosition = edit.selectionEnd; edit.selectionStart = edit.selectionEnd; editor.state = "" } }
+ onClicked: { edit.cursorPosition = edit.selectionEnd; edit.select(edit.cursorPosition,edit.cursorPosition); editor.state = "" } }
}
}
}
diff --git a/src/declarative/graphicsitems/qdeclarativetextedit.cpp b/src/declarative/graphicsitems/qdeclarativetextedit.cpp
index f8876f2..935b431 100644
--- a/src/declarative/graphicsitems/qdeclarativetextedit.cpp
+++ b/src/declarative/graphicsitems/qdeclarativetextedit.cpp
@@ -717,12 +717,9 @@ void QDeclarativeTextEdit::loadCursorDelegate()
\qmlproperty int TextEdit::selectionStart
The cursor position before the first character in the current selection.
- Setting this and selectionEnd allows you to specify a selection in the
- text edit.
- Note that if selectionStart == selectionEnd then there is no current
- selection. If you attempt to set selectionStart to a value outside of
- the current text, selectionStart will not be changed.
+ This property is read-only. To change the selection, use select(start,end),
+ selectAll(), or selectWord().
\sa selectionEnd, cursorPosition, selectedText
*/
@@ -732,25 +729,13 @@ int QDeclarativeTextEdit::selectionStart() const
return d->control->textCursor().selectionStart();
}
-void QDeclarativeTextEdit::setSelectionStart(int s)
-{
- Q_D(QDeclarativeTextEdit);
- if(d->lastSelectionStart == s || s < 0 || s > text().length())
- return;
- d->lastSelectionStart = s;
- d->updateSelection();// Will emit the relevant signals
-}
-
/*!
\qmlproperty int TextEdit::selectionEnd
The cursor position after the last character in the current selection.
- Setting this and selectionStart allows you to specify a selection in the
- text edit.
- Note that if selectionStart == selectionEnd then there is no current
- selection. If you attempt to set selectionEnd to a value outside of
- the current text, selectionEnd will not be changed.
+ This property is read-only. To change the selection, use select(start,end),
+ selectAll(), or selectWord().
\sa selectionStart, cursorPosition, selectedText
*/
@@ -760,15 +745,6 @@ int QDeclarativeTextEdit::selectionEnd() const
return d->control->textCursor().selectionEnd();
}
-void QDeclarativeTextEdit::setSelectionEnd(int s)
-{
- Q_D(QDeclarativeTextEdit);
- if(d->lastSelectionEnd == s || s < 0 || s > text().length())
- return;
- d->lastSelectionEnd = s;
- d->updateSelection();// Will emit the relevant signals
-}
-
/*!
\qmlproperty string TextEdit::selectedText
@@ -1018,6 +994,8 @@ void QDeclarativeTextEditPrivate::focusChanged(bool hasFocus)
}
/*!
+ \qmlmethod void TextEdit::selectAll()
+
Causes all text to be selected.
*/
void QDeclarativeTextEdit::selectAll()
@@ -1027,6 +1005,8 @@ void QDeclarativeTextEdit::selectAll()
}
/*!
+ \qmlmethod void TextEdit::selectWord()
+
Causes the word closest to the current cursor position to be selected.
*/
void QDeclarativeTextEdit::selectWord()
@@ -1038,6 +1018,35 @@ void QDeclarativeTextEdit::selectWord()
}
/*!
+ \qmlmethod void TextEdit::select(start,end)
+
+ Causes the text from \a start to \a end to be selected.
+
+ If either start or end is out of range, the selection is not changed.
+
+ After calling this, selectionStart will become the lesser
+ and selectionEnd will become the greater (regardless of the order passed
+ to this method).
+
+ \sa selectionStart, selectionEnd
+*/
+void QDeclarativeTextEdit::select(int start, int end)
+{
+ Q_D(QDeclarativeTextEdit);
+ if (start < 0 || end < 0 || start > d->text.length() || end > d->text.length())
+ return;
+ QTextCursor cursor = d->control->textCursor();
+ cursor.beginEditBlock();
+ cursor.setPosition(start, QTextCursor::MoveAnchor);
+ cursor.setPosition(end, QTextCursor::KeepAnchor);
+ cursor.endEditBlock();
+ d->control->setTextCursor(cursor);
+
+ // QTBUG-11100
+ updateSelectionMarkers();
+}
+
+/*!
\qmlmethod TextEdit::cut()
Moves the currently selected text to the system clipboard.
@@ -1254,7 +1263,6 @@ void QDeclarativeTextEditPrivate::updateSelection()
QTextCursor cursor = control->textCursor();
bool startChange = (lastSelectionStart != cursor.selectionStart());
bool endChange = (lastSelectionEnd != cursor.selectionEnd());
- //### Is it worth calculating a more minimal set of movements?
cursor.beginEditBlock();
cursor.setPosition(lastSelectionStart, QTextCursor::MoveAnchor);
cursor.setPosition(lastSelectionEnd, QTextCursor::KeepAnchor);
@@ -1264,8 +1272,6 @@ void QDeclarativeTextEditPrivate::updateSelection()
q->selectionStartChanged();
if(endChange)
q->selectionEndChanged();
- startChange = (lastSelectionStart != control->textCursor().selectionStart());
- endChange = (lastSelectionEnd != control->textCursor().selectionEnd());
}
void QDeclarativeTextEdit::updateSelectionMarkers()
diff --git a/src/declarative/graphicsitems/qdeclarativetextedit_p.h b/src/declarative/graphicsitems/qdeclarativetextedit_p.h
index a83b3db..3abfc35 100644
--- a/src/declarative/graphicsitems/qdeclarativetextedit_p.h
+++ b/src/declarative/graphicsitems/qdeclarativetextedit_p.h
@@ -82,8 +82,8 @@ class Q_DECLARATIVE_EXPORT QDeclarativeTextEdit : public QDeclarativePaintedItem
Q_PROPERTY(int cursorPosition READ cursorPosition WRITE setCursorPosition NOTIFY cursorPositionChanged)
Q_PROPERTY(QRect cursorRectangle READ cursorRectangle NOTIFY cursorRectangleChanged)
Q_PROPERTY(QDeclarativeComponent* cursorDelegate READ cursorDelegate WRITE setCursorDelegate NOTIFY cursorDelegateChanged)
- Q_PROPERTY(int selectionStart READ selectionStart WRITE setSelectionStart NOTIFY selectionStartChanged)
- Q_PROPERTY(int selectionEnd READ selectionEnd WRITE setSelectionEnd NOTIFY selectionEndChanged)
+ Q_PROPERTY(int selectionStart READ selectionStart NOTIFY selectionStartChanged)
+ Q_PROPERTY(int selectionEnd READ selectionEnd NOTIFY selectionEndChanged)
Q_PROPERTY(QString selectedText READ selectedText NOTIFY selectionChanged)
Q_PROPERTY(bool focusOnPress READ focusOnPress WRITE setFocusOnPress NOTIFY focusOnPressChanged)
Q_PROPERTY(bool showInputPanelOnFocus READ showInputPanelOnFocus WRITE setShowInputPanelOnFocus NOTIFY showInputPanelOnFocusChanged)
@@ -160,10 +160,7 @@ public:
void setCursorDelegate(QDeclarativeComponent*);
int selectionStart() const;
- void setSelectionStart(int);
-
int selectionEnd() const;
- void setSelectionEnd(int);
QString selectedText() const;
@@ -230,6 +227,7 @@ Q_SIGNALS:
public Q_SLOTS:
void selectAll();
void selectWord();
+ void select(int start, int end);
void cut();
void copy();
void paste();
diff --git a/src/declarative/graphicsitems/qdeclarativetextinput.cpp b/src/declarative/graphicsitems/qdeclarativetextinput.cpp
index 9a6a070..25a2b49 100644
--- a/src/declarative/graphicsitems/qdeclarativetextinput.cpp
+++ b/src/declarative/graphicsitems/qdeclarativetextinput.cpp
@@ -46,6 +46,7 @@
#include <qdeclarativeinfo.h>
#include <QValidator>
+#include <QTextCursor>
#include <QApplication>
#include <QFontMetrics>
#include <QPainter>
@@ -429,10 +430,12 @@ void QDeclarativeTextInput::setCursorPosition(int cp)
Returns a Rect which encompasses the cursor, but which may be larger than is
required. Ignores custom cursor delegates.
*/
-QRect QDeclarativeTextInput::cursorRect() const
+QRect QDeclarativeTextInput::cursorRectangle() const
{
Q_D(const QDeclarativeTextInput);
- return d->control->cursorRect();
+ QRect r = d->control->cursorRect();
+ r.setHeight(r.height()-1); // Make consistent with TextEdit (QLineControl inexplicably adds 1)
+ return r;
}
/*!
@@ -454,15 +457,6 @@ int QDeclarativeTextInput::selectionStart() const
return d->lastSelectionStart;
}
-void QDeclarativeTextInput::setSelectionStart(int s)
-{
- Q_D(QDeclarativeTextInput);
- if(d->lastSelectionStart == s || s < 0 || s > text().length())
- return;
- d->lastSelectionStart = s;
- d->control->setSelection(s, d->lastSelectionEnd - s);
-}
-
/*!
\qmlproperty int TextInput::selectionEnd
@@ -482,13 +476,12 @@ int QDeclarativeTextInput::selectionEnd() const
return d->lastSelectionEnd;
}
-void QDeclarativeTextInput::setSelectionEnd(int s)
+void QDeclarativeTextInput::select(int start, int end)
{
Q_D(QDeclarativeTextInput);
- if(d->lastSelectionEnd == s || s < 0 || s > text().length())
+ if (start < 0 || end < 0 || start > d->control->text().length() || end > d->control->text().length())
return;
- d->lastSelectionEnd = s;
- d->control->setSelection(d->lastSelectionStart, s - d->lastSelectionStart);
+ d->control->setSelection(start, end-start);
}
/*!
@@ -833,6 +826,19 @@ void QDeclarativeTextInput::moveCursor()
}
/*!
+ \qmlmethod rect TextInput::positionToRectangle(int x)
+*/
+QRectF QDeclarativeTextInput::positionToRectangle(int x) const
+{
+ Q_D(const QDeclarativeTextInput);
+ QFontMetrics fm = QFontMetrics(d->font);
+ return QRectF(d->control->cursorToX(x)-d->hscroll,
+ 0.0,
+ d->control->cursorWidth(),
+ cursorRectangle().height());
+}
+
+/*!
\qmlmethod int TextInput::positionAt(int x)
This function returns the character position at
@@ -843,7 +849,7 @@ void QDeclarativeTextInput::moveCursor()
This means that for all x values before the first character this function returns 0,
and for all x values after the last character this function returns text.length.
*/
-int QDeclarativeTextInput::positionAt(int x)
+int QDeclarativeTextInput::positionAt(int x) const
{
Q_D(const QDeclarativeTextInput);
return d->control->xToPos(x - d->hscroll);
@@ -1019,7 +1025,6 @@ void QDeclarativeTextInput::drawContents(QPainter *p, const QRect &r)
d->hscroll -= minLB;
offset = QPoint(d->hscroll, 0);
}
-
d->control->draw(p, offset, r, flags);
p->restore();
@@ -1057,12 +1062,27 @@ QVariant QDeclarativeTextInput::inputMethodQuery(Qt::InputMethodQuery property)
}
}
+/*!
+ \qmlmethod void TextInput::selectAll()
+
+ Causes all text to be selected.
+*/
void QDeclarativeTextInput::selectAll()
{
Q_D(QDeclarativeTextInput);
d->control->setSelection(0, d->control->text().length());
}
+/*!
+ \qmlmethod void TextInput::selectWord()
+
+ Causes the word closest to the current cursor position to be selected.
+*/
+void QDeclarativeTextInput::selectWord()
+{
+ Q_D(QDeclarativeTextInput);
+ d->control->selectWordAtPos(d->control->cursor());
+}
/*!
\qmlproperty bool TextInput::smooth
diff --git a/src/declarative/graphicsitems/qdeclarativetextinput_p.h b/src/declarative/graphicsitems/qdeclarativetextinput_p.h
index 6bb94c2..0b7ddd5 100644
--- a/src/declarative/graphicsitems/qdeclarativetextinput_p.h
+++ b/src/declarative/graphicsitems/qdeclarativetextinput_p.h
@@ -72,10 +72,10 @@ class Q_DECLARATIVE_EXPORT QDeclarativeTextInput : public QDeclarativePaintedIte
Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly NOTIFY readOnlyChanged)
Q_PROPERTY(bool cursorVisible READ isCursorVisible WRITE setCursorVisible NOTIFY cursorVisibleChanged)
Q_PROPERTY(int cursorPosition READ cursorPosition WRITE setCursorPosition NOTIFY cursorPositionChanged)
- Q_PROPERTY(QRect cursorRect READ cursorRect NOTIFY cursorPositionChanged)
+ Q_PROPERTY(QRect cursorRectangle READ cursorRectangle NOTIFY cursorPositionChanged)
Q_PROPERTY(QDeclarativeComponent *cursorDelegate READ cursorDelegate WRITE setCursorDelegate NOTIFY cursorDelegateChanged)
- Q_PROPERTY(int selectionStart READ selectionStart WRITE setSelectionStart NOTIFY selectionStartChanged)
- Q_PROPERTY(int selectionEnd READ selectionEnd WRITE setSelectionEnd NOTIFY selectionEndChanged)
+ Q_PROPERTY(int selectionStart READ selectionStart NOTIFY selectionStartChanged)
+ Q_PROPERTY(int selectionEnd READ selectionEnd NOTIFY selectionEndChanged)
Q_PROPERTY(QString selectedText READ selectedText NOTIFY selectedTextChanged)
Q_PROPERTY(int maximumLength READ maxLength WRITE setMaxLength NOTIFY maximumLengthChanged)
@@ -110,7 +110,8 @@ public:
};
//Auxilliary functions needed to control the TextInput from QML
- Q_INVOKABLE int positionAt(int x);
+ Q_INVOKABLE int positionAt(int x) const;
+ Q_INVOKABLE QRectF positionToRectangle(int x) const;
Q_INVOKABLE void moveCursorSelection(int pos);
Q_INVOKABLE void openSoftwareInputPanel();
@@ -143,13 +144,10 @@ public:
int cursorPosition() const;
void setCursorPosition(int cp);
- QRect cursorRect() const;
+ QRect cursorRectangle() const;
int selectionStart() const;
- void setSelectionStart(int);
-
int selectionEnd() const;
- void setSelectionEnd(int);
QString selectedText() const;
@@ -231,6 +229,8 @@ protected:
public Q_SLOTS:
void selectAll();
+ void selectWord();
+ void select(int start, int end);
private Q_SLOTS:
void updateSize(bool needsRedraw = true);
diff --git a/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp b/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp
index d3e3c3a..47c5b63 100644
--- a/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp
+++ b/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp
@@ -551,11 +551,11 @@ void tst_qdeclarativetextedit::selection()
//Test selection
for(int i=0; i<= testStr.size(); i++) {
- textEditObject->setSelectionEnd(i);
+ textEditObject->select(0,i);
QCOMPARE(testStr.mid(0,i), textEditObject->selectedText());
}
for(int i=0; i<= testStr.size(); i++) {
- textEditObject->setSelectionStart(i);
+ textEditObject->select(i,testStr.size());
QCOMPARE(testStr.mid(i,testStr.size()-i), textEditObject->selectedText());
}
@@ -565,43 +565,26 @@ void tst_qdeclarativetextedit::selection()
QVERIFY(textEditObject->selectionEnd() == 0);
QVERIFY(textEditObject->selectedText().isNull());
- for(int i=0; i< testStr.size(); i++) {
- textEditObject->setSelectionStart(i);
- QCOMPARE(textEditObject->selectionEnd(), i);
- QCOMPARE(testStr.mid(i,0), textEditObject->selectedText());
- textEditObject->setSelectionEnd(i+1);
- QCOMPARE(textEditObject->selectionStart(), i);
- QCOMPARE(testStr.mid(i,1), textEditObject->selectedText());
- }
-
- for(int i= testStr.size() - 1; i>0; i--) {
- textEditObject->setSelectionEnd(i);
- QCOMPARE(testStr.mid(i,0), textEditObject->selectedText());
- textEditObject->setSelectionStart(i-1);
- QCOMPARE(testStr.mid(i-1,1), textEditObject->selectedText());
- }
-
//Test Error Ignoring behaviour
textEditObject->setCursorPosition(0);
QVERIFY(textEditObject->selectedText().isNull());
- textEditObject->setSelectionStart(-10);
+ textEditObject->select(-10,0);
QVERIFY(textEditObject->selectedText().isNull());
- textEditObject->setSelectionStart(100);
+ textEditObject->select(100,101);
QVERIFY(textEditObject->selectedText().isNull());
- textEditObject->setSelectionEnd(-10);
+ textEditObject->select(0,-10);
QVERIFY(textEditObject->selectedText().isNull());
- textEditObject->setSelectionEnd(100);
+ textEditObject->select(0,100);
QVERIFY(textEditObject->selectedText().isNull());
- textEditObject->setSelectionStart(0);
- textEditObject->setSelectionEnd(10);
+ textEditObject->select(0,10);
QVERIFY(textEditObject->selectedText().size() == 10);
- textEditObject->setSelectionStart(-10);
+ textEditObject->select(-10,0);
QVERIFY(textEditObject->selectedText().size() == 10);
- textEditObject->setSelectionStart(100);
+ textEditObject->select(100,101);
QVERIFY(textEditObject->selectedText().size() == 10);
- textEditObject->setSelectionEnd(-10);
+ textEditObject->select(0,-10);
QVERIFY(textEditObject->selectedText().size() == 10);
- textEditObject->setSelectionEnd(100);
+ textEditObject->select(0,100);
QVERIFY(textEditObject->selectedText().size() == 10);
}
diff --git a/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp b/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp
index c01cfa5..54bb9c1 100644
--- a/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp
+++ b/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp
@@ -322,11 +322,11 @@ void tst_qdeclarativetextinput::selection()
//Test selection
for(int i=0; i<= testStr.size(); i++) {
- textinputObject->setSelectionEnd(i);
+ textinputObject->select(0,i);
QCOMPARE(testStr.mid(0,i), textinputObject->selectedText());
}
for(int i=0; i<= testStr.size(); i++) {
- textinputObject->setSelectionStart(i);
+ textinputObject->select(i,testStr.size());
QCOMPARE(testStr.mid(i,testStr.size()-i), textinputObject->selectedText());
}
@@ -336,43 +336,26 @@ void tst_qdeclarativetextinput::selection()
QVERIFY(textinputObject->selectionEnd() == 0);
QVERIFY(textinputObject->selectedText().isNull());
- for(int i=0; i< testStr.size(); i++) {
- textinputObject->setSelectionStart(i);
- QCOMPARE(textinputObject->selectionEnd(), i);
- QCOMPARE(testStr.mid(i,0), textinputObject->selectedText());
- textinputObject->setSelectionEnd(i+1);
- QCOMPARE(textinputObject->selectionStart(), i);
- QCOMPARE(testStr.mid(i,1), textinputObject->selectedText());
- }
-
- for(int i= testStr.size() - 1; i>0; i--) {
- textinputObject->setSelectionEnd(i);
- QCOMPARE(testStr.mid(i,0), textinputObject->selectedText());
- textinputObject->setSelectionStart(i-1);
- QCOMPARE(testStr.mid(i-1,1), textinputObject->selectedText());
- }
-
//Test Error Ignoring behaviour
textinputObject->setCursorPosition(0);
QVERIFY(textinputObject->selectedText().isNull());
- textinputObject->setSelectionStart(-10);
+ textinputObject->select(-10,0);
QVERIFY(textinputObject->selectedText().isNull());
- textinputObject->setSelectionStart(100);
+ textinputObject->select(100,110);
QVERIFY(textinputObject->selectedText().isNull());
- textinputObject->setSelectionEnd(-10);
+ textinputObject->select(0,-10);
QVERIFY(textinputObject->selectedText().isNull());
- textinputObject->setSelectionEnd(100);
+ textinputObject->select(0,100);
QVERIFY(textinputObject->selectedText().isNull());
- textinputObject->setSelectionStart(0);
- textinputObject->setSelectionEnd(10);
+ textinputObject->select(0,10);
QVERIFY(textinputObject->selectedText().size() == 10);
- textinputObject->setSelectionStart(-10);
+ textinputObject->select(-10,10);
QVERIFY(textinputObject->selectedText().size() == 10);
- textinputObject->setSelectionStart(100);
+ textinputObject->select(100,101);
QVERIFY(textinputObject->selectedText().size() == 10);
- textinputObject->setSelectionEnd(-10);
+ textinputObject->select(0,-10);
QVERIFY(textinputObject->selectedText().size() == 10);
- textinputObject->setSelectionEnd(100);
+ textinputObject->select(0,100);
QVERIFY(textinputObject->selectedText().size() == 10);
delete textinputObject;
@@ -565,8 +548,7 @@ void tst_qdeclarativetextinput::navigation()
QVERIFY(input->hasFocus() == true);
//QT-2944: If text is selected, ensure we deselect upon cursor motion
input->setCursorPosition(input->text().length());
- input->setSelectionStart(0);
- input->setSelectionEnd(input->text().length());
+ input->select(0,input->text().length());
QVERIFY(input->selectionStart() != input->selectionEnd());
simulateKey(canvas, Qt::Key_Right);
QVERIFY(input->selectionStart() == input->selectionEnd());
@@ -603,13 +585,13 @@ void tst_qdeclarativetextinput::cursorDelegate()
//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()));
+ //+5 is because the TextInput cursorRectangle is just a 10xHeight area centered on cursor position
+ QCOMPARE(textInputObject->cursorRectangle().x() + 5, qRound(delegateObject->x()));
+ QCOMPARE(textInputObject->cursorRectangle().y(), qRound(delegateObject->y()));
}
textInputObject->setCursorPosition(0);
- QCOMPARE(textInputObject->cursorRect().x()+5, qRound(delegateObject->x()));
- QCOMPARE(textInputObject->cursorRect().y(), qRound(delegateObject->y()));
+ QCOMPARE(textInputObject->cursorRectangle().x()+5, qRound(delegateObject->x()));
+ QCOMPARE(textInputObject->cursorRectangle().y(), qRound(delegateObject->y()));
//Test Delegate gets deleted
textInputObject->setCursorDelegate(0);
QVERIFY(!textInputObject->findChild<QDeclarativeItem*>("cursorInstance"));
@@ -881,8 +863,7 @@ void tst_qdeclarativetextinput::focusOutClearSelection()
view.show();
QApplication::setActiveWindow(&view);
QTest::qWaitForWindowShown(&view);
- input.setSelectionStart(2);
- input.setSelectionEnd(5);
+ input.select(2,5);
//The selection should work
QTRY_COMPARE(input.selectedText(), QLatin1String("llo"));
input2.setFocus(true);
diff --git a/tests/auto/declarative/qmlvisual/qdeclarativetextedit/MultilineEdit.qml b/tests/auto/declarative/qmlvisual/qdeclarativetextedit/MultilineEdit.qml
index 0273282..53538cb 100644
--- a/tests/auto/declarative/qmlvisual/qdeclarativetextedit/MultilineEdit.qml
+++ b/tests/auto/declarative/qmlvisual/qdeclarativetextedit/MultilineEdit.qml
@@ -65,8 +65,7 @@ Item {
onReleased: {
}
onDoubleClicked: {
- textEdit.selectionStart=0;
- textEdit.selectionEnd=textEdit.text.length;
+ textEdit.selectAll()
}
z: textEdit.z + 1
}
diff --git a/tests/auto/declarative/qmlvisual/qdeclarativetextinput/LineEdit.qml b/tests/auto/declarative/qmlvisual/qdeclarativetextinput/LineEdit.qml
index cc0ad3c..69f57c6 100644
--- a/tests/auto/declarative/qmlvisual/qdeclarativetextinput/LineEdit.qml
+++ b/tests/auto/declarative/qmlvisual/qdeclarativetextinput/LineEdit.qml
@@ -58,8 +58,7 @@ Item {
onReleased: {
}
onDoubleClicked: {
- textInp.selectionStart=0;
- textInp.selectionEnd=textInp.text.length;
+ textInp.selectAll()
}
z: textInp.z + 1
}