summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiikka Heikkinen <miikka.heikkinen@digia.com>2009-08-12 09:40:02 (GMT)
committerMiikka Heikkinen <miikka.heikkinen@digia.com>2009-08-12 09:40:02 (GMT)
commit7d6c47d81eec6696a1684ebc459bdaf05538dd2e (patch)
tree2373f5260c84a27a6d44c809c7a1c414f051c019
parentefa40eb09f8f1aca87439456666a2747e435e548 (diff)
parent129f580affa8bc0b63bc1cd8a051fdf8e9f2ab56 (diff)
downloadQt-7d6c47d81eec6696a1684ebc459bdaf05538dd2e.zip
Qt-7d6c47d81eec6696a1684ebc459bdaf05538dd2e.tar.gz
Qt-7d6c47d81eec6696a1684ebc459bdaf05538dd2e.tar.bz2
Merge branch 'master' of git@scm.dev.troll.no:qt/qt-s60-public
-rw-r--r--src/gui/widgets/qlinecontrol.cpp39
-rw-r--r--src/gui/widgets/qlineedit.cpp2
-rw-r--r--src/gui/widgets/qlineedit_p.h4
3 files changed, 37 insertions, 8 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);
}
/*!
diff --git a/src/gui/widgets/qlineedit.cpp b/src/gui/widgets/qlineedit.cpp
index 5b04616..cd9666d 100644
--- a/src/gui/widgets/qlineedit.cpp
+++ b/src/gui/widgets/qlineedit.cpp
@@ -1657,7 +1657,7 @@ QVariant QLineEdit::inputMethodQuery(Qt::InputMethodQuery property) const
case Qt::ImFont:
return font();
case Qt::ImCursorPosition:
- return QVariant(d->control->hasSelectedText() ? d->control->selectionEnd() : d->control->cursor());
+ return QVariant(d->control->cursor());
case Qt::ImSurroundingText:
return QVariant(text());
case Qt::ImCurrentSelection:
diff --git a/src/gui/widgets/qlineedit_p.h b/src/gui/widgets/qlineedit_p.h
index b21820c..2c0d08f 100644
--- a/src/gui/widgets/qlineedit_p.h
+++ b/src/gui/widgets/qlineedit_p.h
@@ -76,7 +76,7 @@ public:
QLineEditPrivate()
: control(0), frame(1), contextMenuEnabled(1), cursorVisible(0),
- dragEnabled(0), hscroll(0), vscroll(0), clickCausedFocus(0),
+ dragEnabled(0), clickCausedFocus(0), hscroll(0), vscroll(0),
alignment(Qt::AlignLeading | Qt::AlignVCenter),
leftTextMargin(0), topTextMargin(0), rightTextMargin(0), bottomTextMargin(0)
{
@@ -101,7 +101,7 @@ public:
inline bool shouldEnableInputMethod() const
{
- return !control->isReadOnly() && (control->echoMode() == QLineEdit::Normal || control->echoMode() == QLineEdit::PasswordEchoOnEdit);
+ return !control->isReadOnly();
}
QPoint tripleClick;