diff options
author | Liang Qi <liang.qi@qt.io> | 2017-03-28 09:23:03 +0200 |
---|---|---|
committer | Liang Qi <liang.qi@qt.io> | 2017-03-28 09:28:31 +0200 |
commit | b48a13fd6843e12b5725aa3ff0d010007e7c43b4 (patch) | |
tree | 316cfe36fc67906efcd92ff806c7c0da56ed4f8e /src/widgets/widgets/qwidgettextcontrol.cpp | |
parent | 3398d9d40cb0dae2dc2a1a4f7dc3b4b9cceae903 (diff) | |
parent | 15fe60cfdada84ea519f08e905d59cc3fb6d20cd (diff) |
Merge remote-tracking branch 'origin/5.9' into dev
Conflicts:
examples/examples.pro
tests/auto/corelib/tools/qchar/tst_qchar.cpp
tests/auto/other/qaccessibility/accessiblewidgets.h
Change-Id: I426696c40ab57d14dc295b8103152cede79f244c
Diffstat (limited to 'src/widgets/widgets/qwidgettextcontrol.cpp')
-rw-r--r-- | src/widgets/widgets/qwidgettextcontrol.cpp | 47 |
1 files changed, 45 insertions, 2 deletions
diff --git a/src/widgets/widgets/qwidgettextcontrol.cpp b/src/widgets/widgets/qwidgettextcontrol.cpp index 9aec94d47f..9e848ca834 100644 --- a/src/widgets/widgets/qwidgettextcontrol.cpp +++ b/src/widgets/widgets/qwidgettextcontrol.cpp @@ -2055,16 +2055,59 @@ void QWidgetTextControlPrivate::inputMethodEvent(QInputMethodEvent *e) preeditCursor = a.start; hideCursor = !a.length; } else if (a.type == QInputMethodEvent::TextFormat) { - QTextCharFormat f = qvariant_cast<QTextFormat>(a.value).toCharFormat(); + QTextCharFormat f = cursor.charFormat(); + f.merge(qvariant_cast<QTextFormat>(a.value).toCharFormat()); if (f.isValid()) { QTextLayout::FormatRange o; o.start = a.start + cursor.position() - block.position(); o.length = a.length; o.format = f; - overrides.append(o); + + // Make sure list is sorted by start index + QVector<QTextLayout::FormatRange>::iterator it = overrides.end(); + while (it != overrides.begin()) { + QVector<QTextLayout::FormatRange>::iterator previous = it - 1; + if (o.start >= previous->start) { + overrides.insert(it, o); + break; + } + it = previous; + } + + if (it == overrides.begin()) + overrides.prepend(o); } } } + + if (cursor.charFormat().isValid()) { + int start = cursor.position() - block.position(); + int end = start + e->preeditString().length(); + + QVector<QTextLayout::FormatRange>::iterator it = overrides.begin(); + while (it != overrides.end()) { + QTextLayout::FormatRange range = *it; + int rangeStart = range.start; + if (rangeStart > start) { + QTextLayout::FormatRange o; + o.start = start; + o.length = rangeStart - start; + o.format = cursor.charFormat(); + it = overrides.insert(it, o) + 1; + } + + ++it; + start = range.start + range.length; + } + + if (start < end) { + QTextLayout::FormatRange o; + o.start = start; + o.length = end - start; + o.format = cursor.charFormat(); + overrides.append(o); + } + } layout->setFormats(overrides); cursor.endEditBlock(); |