summaryrefslogtreecommitdiffstats
path: root/src/declarative/graphicsitems/qdeclarativetextinput.cpp
diff options
context:
space:
mode:
authorAndrew den Exter <andrew.den-exter@nokia.com>2011-02-24 03:17:13 (GMT)
committerAndrew den Exter <andrew.den-exter@nokia.com>2011-02-24 03:47:46 (GMT)
commit60f84b596476f88a39d0eb2c56dc9468805442aa (patch)
tree06b4e1e5ffd660a70f41cd03c3e753b7f2f311e7 /src/declarative/graphicsitems/qdeclarativetextinput.cpp
parenta8a02cf8099f1269bc23495b60841031fbd36b0a (diff)
downloadQt-60f84b596476f88a39d0eb2c56dc9468805442aa.zip
Qt-60f84b596476f88a39d0eb2c56dc9468805442aa.tar.gz
Qt-60f84b596476f88a39d0eb2c56dc9468805442aa.tar.bz2
Add a 'CursorPosition' parameter to TextInput.positionAt().
Specifies whether positionAt should resolve to the nearest position between characters or the position of the nearest character. Change-Id: I9eb2db2f8dd2accb2d9844ff204fba0337e71876 Task-number: QTBUG-16070 Reviewed-by: Martin Jones
Diffstat (limited to 'src/declarative/graphicsitems/qdeclarativetextinput.cpp')
-rw-r--r--src/declarative/graphicsitems/qdeclarativetextinput.cpp20
1 files changed, 17 insertions, 3 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativetextinput.cpp b/src/declarative/graphicsitems/qdeclarativetextinput.cpp
index 78f34db..f3c6b93 100644
--- a/src/declarative/graphicsitems/qdeclarativetextinput.cpp
+++ b/src/declarative/graphicsitems/qdeclarativetextinput.cpp
@@ -927,8 +927,15 @@ QRectF QDeclarativeTextInput::positionToRectangle(int pos) const
cursorRectangle().height());
}
+int QDeclarativeTextInput::positionAt(int x) const
+{
+ Q_D(const QDeclarativeTextInput);
+ return d->control->xToPos(x + d->hscroll);
+}
+
/*!
- \qmlmethod int TextInput::positionAt(int x)
+ \qmlmethod int TextInput::positionAt(int x, CursorPosition position = CursorBetweenCharacters)
+ \since Quick 1.1
This function returns the character position at
x pixels from the left of the textInput. Position 0 is before the
@@ -937,11 +944,18 @@ QRectF QDeclarativeTextInput::positionToRectangle(int pos) const
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.
+
+ The cursor position type specifies how the cursor position should be resolved.
+
+ \list
+ \o TextInput.CursorBetweenCharacters - Returns the position between characters that is nearest x.
+ \o TextInput.CursorOnCharacter - Returns the position before the character that is nearest x.
+ \endlist
*/
-int QDeclarativeTextInput::positionAt(int x) const
+int QDeclarativeTextInput::positionAt(int x, CursorPosition position)
{
Q_D(const QDeclarativeTextInput);
- return d->control->xToPos(x + d->hscroll);
+ return d->control->xToPos(x + d->hscroll, QTextLine::CursorPosition(position));
}
void QDeclarativeTextInputPrivate::focusChanged(bool hasFocus)