diff options
author | Andrew den Exter <andrew.den-exter@nokia.com> | 2011-02-24 03:17:13 (GMT) |
---|---|---|
committer | Andrew den Exter <andrew.den-exter@nokia.com> | 2011-02-24 03:47:46 (GMT) |
commit | 60f84b596476f88a39d0eb2c56dc9468805442aa (patch) | |
tree | 06b4e1e5ffd660a70f41cd03c3e753b7f2f311e7 /src/declarative | |
parent | a8a02cf8099f1269bc23495b60841031fbd36b0a (diff) | |
download | Qt-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')
-rw-r--r-- | src/declarative/graphicsitems/qdeclarativetextinput.cpp | 20 | ||||
-rw-r--r-- | src/declarative/graphicsitems/qdeclarativetextinput_p.h | 6 |
2 files changed, 23 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) diff --git a/src/declarative/graphicsitems/qdeclarativetextinput_p.h b/src/declarative/graphicsitems/qdeclarativetextinput_p.h index e1e66a9..c29be26 100644 --- a/src/declarative/graphicsitems/qdeclarativetextinput_p.h +++ b/src/declarative/graphicsitems/qdeclarativetextinput_p.h @@ -120,8 +120,14 @@ public: SelectWords }; + enum CursorPosition { + CursorBetweenCharacters, + CursorOnCharacter + }; + //Auxilliary functions needed to control the TextInput from QML Q_INVOKABLE int positionAt(int x) const; + Q_INVOKABLE Q_REVISION(1) int positionAt(int x, CursorPosition position); Q_INVOKABLE QRectF positionToRectangle(int pos) const; Q_INVOKABLE void moveCursorSelection(int pos); Q_INVOKABLE Q_REVISION(1) void moveCursorSelection(int pos, SelectionMode mode); |