summaryrefslogtreecommitdiffstats
path: root/src/gui
diff options
context:
space:
mode:
authoraxis <qt-info@nokia.com>2009-08-12 08:09:50 (GMT)
committeraxis <qt-info@nokia.com>2009-08-12 08:59:37 (GMT)
commit4d1c7a4f2f8f451d13d9a5bffc4c44c3221c3ca1 (patch)
treeb1bef24711cb496b2a05d7a393c73a5760ab1a52 /src/gui
parent9e03643608527e9ea567b186c7b9209a52908d27 (diff)
downloadQt-4d1c7a4f2f8f451d13d9a5bffc4c44c3221c3ca1.zip
Qt-4d1c7a4f2f8f451d13d9a5bffc4c44c3221c3ca1.tar.gz
Qt-4d1c7a4f2f8f451d13d9a5bffc4c44c3221c3ca1.tar.bz2
Redid 7b95b70bc307 for QLineControl.
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/widgets/qlinecontrol.cpp39
1 files changed, 34 insertions, 5 deletions
diff --git a/src/gui/widgets/qlinecontrol.cpp b/src/gui/widgets/qlinecontrol.cpp
index f4a2348..80215e1 100644
--- a/src/gui/widgets/qlinecontrol.cpp
+++ b/src/gui/widgets/qlinecontrol.cpp
@@ -400,8 +400,17 @@ void QLineControl::moveCursor(int pos, bool mark)
*/
void QLineControl::processInputMethodEvent(QInputMethodEvent *event)
{
- int priorState = m_undoState;
- removeSelectedText();
+ int priorState = 0;
+ bool isGettingInput = !event->commitString().isEmpty() || !event->preeditString().isEmpty()
+ || event->replacementLength() > 0;
+ bool cursorPositionChanged = false;
+
+ if (isGettingInput) {
+ // If any text is being input, remove selected text.
+ priorState = m_undoState;
+ removeSelectedText();
+ }
+
int c = m_cursor; // cursor position after insertion of commit string
if (event->replacementStart() <= 0)
@@ -415,11 +424,30 @@ void QLineControl::processInputMethodEvent(QInputMethodEvent *event)
m_selend = m_selstart + event->replacementLength();
removeSelectedText();
}
- if (!event->commitString().isEmpty())
+ if (!event->commitString().isEmpty()) {
insert(event->commitString());
+ cursorPositionChanged = true;
+ }
m_cursor = qMin(c, m_text.length());
+ for (int i = 0; i < event->attributes().size(); ++i) {
+ const QInputMethodEvent::Attribute &a = event->attributes().at(i);
+ if (a.type == QInputMethodEvent::Selection) {
+ m_cursor = qBound(0, a.start + a.length, m_text.length());
+ if (a.length) {
+ m_selstart = qMax(0, qMin(a.start, m_text.length()));
+ m_selend = m_cursor;
+ if (m_selend < m_selstart) {
+ qSwap(m_selstart, m_selend);
+ }
+ } else {
+ m_selstart = m_selend = 0;
+ }
+ cursorPositionChanged = true;
+ }
+ }
+
setPreeditArea(m_cursor, event->preeditString());
m_preeditCursor = event->preeditString().length();
m_hideCursor = false;
@@ -442,9 +470,10 @@ void QLineControl::processInputMethodEvent(QInputMethodEvent *event)
}
m_textLayout.setAdditionalFormats(formats);
updateDisplayText();
- if (!event->commitString().isEmpty())
+ if (cursorPositionChanged)
emitCursorPositionChanged();
- finishChange(priorState);
+ if (isGettingInput)
+ finishChange(priorState);
}
/*!