summaryrefslogtreecommitdiffstats
path: root/src/gui
diff options
context:
space:
mode:
authorPekka Vuorela <pekka.ta.vuorela@nokia.com>2011-12-08 14:52:19 +0200
committerQt by Nokia <qt-info@nokia.com>2012-03-27 23:03:12 +0200
commit27441054197d0ecff6b83e7e6511e0d6955f4593 (patch)
treef93c41093e07789a20cc1063f71ee6859b0bee08 /src/gui
parent5e4ed93b1c0dac4916e5544fb613d5f1451aa155 (diff)
Protect QAbstractTextDocumentLayout::anchorAt() from preedit
Previously the method didn't take into account that hitTest() returns visual index, i.e. containing the preedit, and thus was easily hitting assertion. Need to compensate for that before checking for actual link. Change-Id: I119e7f91088b4db9d347a3da338f6df915ce9719 Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/text/qabstracttextdocumentlayout.cpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/gui/text/qabstracttextdocumentlayout.cpp b/src/gui/text/qabstracttextdocumentlayout.cpp
index 589c0f701f..e14cfe0f82 100644
--- a/src/gui/text/qabstracttextdocumentlayout.cpp
+++ b/src/gui/text/qabstracttextdocumentlayout.cpp
@@ -577,6 +577,21 @@ QString QAbstractTextDocumentLayout::anchorAt(const QPointF& pos) const
if (cursorPos == -1)
return QString();
+ // compensate for preedit in the hit text block
+ QTextBlock block = document()->firstBlock();
+ while (block.isValid()) {
+ QRectF blockBr = blockBoundingRect(block);
+ if (blockBr.contains(pos)) {
+ QTextLayout *layout = block.layout();
+ int relativeCursorPos = cursorPos - block.position();
+ const int preeditLength = layout ? layout->preeditAreaText().length() : 0;
+ if (preeditLength > 0 && relativeCursorPos > layout->preeditAreaPosition())
+ cursorPos -= qMin(cursorPos - layout->preeditAreaPosition(), preeditLength);
+ break;
+ }
+ block = block.next();
+ }
+
QTextDocumentPrivate *pieceTable = qobject_cast<const QTextDocument *>(parent())->docHandle();
QTextDocumentPrivate::FragmentIterator it = pieceTable->find(cursorPos);
QTextCharFormat fmt = pieceTable->formatCollection()->charFormat(it->format);