summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAndrew den Exter <andrew.den-exter@nokia.com>2011-02-07 07:16:57 (GMT)
committerAndrew den Exter <andrew.den-exter@nokia.com>2011-02-08 00:14:21 (GMT)
commitcad4964276151879e3e6cf5f7ab610dba512d988 (patch)
tree095fd509a55b1a0af13e83b78d8dbd76ce2bf583 /src
parent6bd233953ac87603ddee8c5f087fbe523dd3793e (diff)
downloadQt-cad4964276151879e3e6cf5f7ab610dba512d988.zip
Qt-cad4964276151879e3e6cf5f7ab610dba512d988.tar.gz
Qt-cad4964276151879e3e6cf5f7ab610dba512d988.tar.bz2
Scroll TextInput to ensure preedit text is visible.
Update the scroll position on text input events and ensure the end of the pre-edit text is visible, unless that hides the cursor in which case display as much as possible while still displaying the cursor and a preceding pre-edit character. Change-Id: Iec6f82b00333f7c9ea21fe536c8f11be0f8de710 Task-number: QTBUG-16999 Reviewed-by: Martin Jones
Diffstat (limited to 'src')
-rw-r--r--src/declarative/graphicsitems/qdeclarativetextinput.cpp12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativetextinput.cpp b/src/declarative/graphicsitems/qdeclarativetextinput.cpp
index 57e60ac..2258ce6 100644
--- a/src/declarative/graphicsitems/qdeclarativetextinput.cpp
+++ b/src/declarative/graphicsitems/qdeclarativetextinput.cpp
@@ -980,6 +980,7 @@ void QDeclarativeTextInput::inputMethodEvent(QInputMethodEvent *ev)
} else {
d->control->processInputMethodEvent(ev);
updateSize();
+ d->updateHorizontalScroll();
}
if (!ev->isAccepted())
QDeclarativePaintedItem::inputMethodEvent(ev);
@@ -1098,7 +1099,8 @@ int QDeclarativeTextInputPrivate::calculateTextWidth()
void QDeclarativeTextInputPrivate::updateHorizontalScroll()
{
Q_Q(QDeclarativeTextInput);
- int cix = qRound(control->cursorToX());
+ const int preeditLength = control->preeditAreaText().length();
+ int cix = qRound(control->cursorToX(control->cursor() + preeditLength));
QRect br(q->boundingRect().toRect());
int widthUsed = calculateTextWidth();
Qt::Alignment va = QStyle::visualAlignment(control->layoutDirection(), QFlag(Qt::Alignment(hAlign)));
@@ -1128,6 +1130,14 @@ void QDeclarativeTextInputPrivate::updateHorizontalScroll()
// right
hscroll = widthUsed - br.width() + 1;
}
+ if (preeditLength > 0) {
+ // check to ensure long pre-edit text doesn't push the cursor
+ // off to the left
+ cix = qRound(control->cursorToX(
+ control->cursor() + qMax(0, control->preeditCursor() - 1)));
+ if (cix < hscroll)
+ hscroll = cix;
+ }
} else {
switch (va & ~(Qt::AlignAbsolute|Qt::AlignVertical_Mask)) {
case Qt::AlignRight: