summaryrefslogtreecommitdiffstats
path: root/src/declarative/graphicsitems/qdeclarativetextinput.cpp
diff options
context:
space:
mode:
authorAndrew den Exter <andrew.den-exter@nokia.com>2011-02-28 06:54:08 (GMT)
committerAndrew den Exter <andrew.den-exter@nokia.com>2011-03-01 06:56:46 (GMT)
commit119a8ddcd7c8de0607309b37f9ef83439b607f17 (patch)
tree83eff83c432946235437466fa15a6233a50aaa50 /src/declarative/graphicsitems/qdeclarativetextinput.cpp
parent70be048712ba3516b79dbf2b1b0b4677fdc7ee0f (diff)
downloadQt-119a8ddcd7c8de0607309b37f9ef83439b607f17.zip
Qt-119a8ddcd7c8de0607309b37f9ef83439b607f17.tar.gz
Qt-119a8ddcd7c8de0607309b37f9ef83439b607f17.tar.bz2
Don't return positions within preedit text from positionAt().
Preedit text isn't visible outside the inner workings of the Text elements so any position returned that is greater than the current cursor position is invalid. Change-Id: I433fc635dcd6d087bde13fc47a1a92e4222a3b2c Task-number: QTBUG-17834 Reviewed-by: Martin Jones
Diffstat (limited to 'src/declarative/graphicsitems/qdeclarativetextinput.cpp')
-rw-r--r--src/declarative/graphicsitems/qdeclarativetextinput.cpp19
1 files changed, 14 insertions, 5 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativetextinput.cpp b/src/declarative/graphicsitems/qdeclarativetextinput.cpp
index 88b55df..c873172 100644
--- a/src/declarative/graphicsitems/qdeclarativetextinput.cpp
+++ b/src/declarative/graphicsitems/qdeclarativetextinput.cpp
@@ -921,6 +921,8 @@ void QDeclarativeTextInput::moveCursor()
QRectF QDeclarativeTextInput::positionToRectangle(int pos) const
{
Q_D(const QDeclarativeTextInput);
+ if (pos > d->control->cursorPosition())
+ pos += d->control->preeditAreaText().length();
return QRectF(d->control->cursorToX(pos)-d->hscroll,
0.0,
d->control->cursorWidth(),
@@ -929,8 +931,7 @@ QRectF QDeclarativeTextInput::positionToRectangle(int pos) const
int QDeclarativeTextInput::positionAt(int x) const
{
- Q_D(const QDeclarativeTextInput);
- return d->control->xToPos(x + d->hscroll);
+ return positionAt(x, CursorBetweenCharacters);
}
/*!
@@ -952,10 +953,18 @@ int QDeclarativeTextInput::positionAt(int x) const
\o TextInput.CursorOnCharacter - Returns the position before the character that is nearest x.
\endlist
*/
-int QDeclarativeTextInput::positionAt(int x, CursorPosition position)
+int QDeclarativeTextInput::positionAt(int x, CursorPosition position) const
{
Q_D(const QDeclarativeTextInput);
- return d->control->xToPos(x + d->hscroll, QTextLine::CursorPosition(position));
+ int pos = d->control->xToPos(x + d->hscroll, QTextLine::CursorPosition(position));
+ const int cursor = d->control->cursor();
+ if (pos > cursor) {
+ const int preeditLength = d->control->preeditAreaText().length();
+ pos = pos > cursor + preeditLength
+ ? pos - preeditLength
+ : cursor;
+ }
+ return pos;
}
void QDeclarativeTextInputPrivate::focusChanged(bool hasFocus)
@@ -1065,7 +1074,7 @@ void QDeclarativeTextInput::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
Q_D(QDeclarativeTextInput);
if (d->sendMouseEventToInputContext(event, QEvent::MouseMove))
- event->setAccepted(true);
+ return;
if (d->selectByMouse) {
if (qAbs(int(event->pos().x() - d->pressPos.x())) > QApplication::startDragDistance())
setKeepMouseGrab(true);