aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/items/qquicktextnode.cpp
diff options
context:
space:
mode:
authorJiang Jiang <jiang.jiang@nokia.com>2012-01-13 11:06:10 +0100
committerQt by Nokia <qt-info@nokia.com>2012-01-16 12:36:46 +0100
commita9d2ef2d2a6a2db16ca3d703f671c3aa396cd99a (patch)
treea31251ff796f507dd3a1d8649f0e7097822d1b6f /src/quick/items/qquicktextnode.cpp
parentdf6338a7b4ff43b1bb0538c44c632d122a7c3766 (diff)
Fix preedit text visibility for TextEdit
For an empty TextEdit with preedit text, we need to add the text separately since the blockIterator will not go through that case. Also fixed preedit text appended at the end of any commited text. Move the code for adding text into SelectionEngine so that we can reuse it for adding preedit text. Task-number: QTBUG-22647 Change-Id: Id4fe04099b16949ff5de0747881c6dc96ef0673f Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>
Diffstat (limited to 'src/quick/items/qquicktextnode.cpp')
-rw-r--r--src/quick/items/qquicktextnode.cpp85
1 files changed, 55 insertions, 30 deletions
diff --git a/src/quick/items/qquicktextnode.cpp b/src/quick/items/qquicktextnode.cpp
index fcb1c855ec..b5c71d0b7a 100644
--- a/src/quick/items/qquicktextnode.cpp
+++ b/src/quick/items/qquicktextnode.cpp
@@ -329,6 +329,12 @@ namespace {
void addImage(const QRectF &rect, const QImage &image, qreal ascent,
BinaryTreeNode::SelectionState selectionState,
QTextFrameFormat::Position layoutPosition);
+ int addText(const QTextBlock &block,
+ const QTextCharFormat &charFormat,
+ const QColor &textColor,
+ const QVarLengthArray<QTextLayout::FormatRange> &colorChanges,
+ int textPos, int fragmentEnd,
+ int selectionStart, int selectionEnd);
void addTextObject(const QPointF &position, const QTextCharFormat &format,
BinaryTreeNode::SelectionState selectionState,
QTextDocument *textDocument, int pos,
@@ -407,6 +413,45 @@ namespace {
QList<QPair<QRectF, QImage> > m_images;
};
+ int SelectionEngine::addText(const QTextBlock &block,
+ const QTextCharFormat &charFormat,
+ const QColor &textColor,
+ const QVarLengthArray<QTextLayout::FormatRange> &colorChanges,
+ int textPos, int fragmentEnd,
+ int selectionStart, int selectionEnd)
+ {
+ if (charFormat.foreground().style() != Qt::NoBrush)
+ setTextColor(charFormat.foreground().color());
+ else
+ setTextColor(textColor);
+
+ while (textPos < fragmentEnd) {
+ int blockRelativePosition = textPos - block.position();
+ QTextLine line = block.layout()->lineForTextPosition(blockRelativePosition);
+ if (!currentLine().isValid()
+ || line.lineNumber() != currentLine().lineNumber()) {
+ setCurrentLine(line);
+ }
+
+ Q_ASSERT(line.textLength() > 0);
+ int lineEnd = line.textStart() + block.position() + line.textLength();
+
+ int len = qMin(lineEnd - textPos, fragmentEnd - textPos);
+ Q_ASSERT(len > 0);
+
+ int currentStepEnd = textPos + len;
+
+ addGlyphsForRanges(colorChanges,
+ textPos - block.position(),
+ currentStepEnd - block.position(),
+ selectionStart - block.position(),
+ selectionEnd - block.position());
+
+ textPos = currentStepEnd;
+ }
+ return textPos;
+ }
+
void SelectionEngine::addTextDecorations(const QVarLengthArray<TextDecoration> &textDecorations,
qreal offset, qreal thickness)
{
@@ -1155,6 +1200,13 @@ void QQuickTextNode::addTextDocument(const QPointF &, QTextDocument *textDocumen
int textPos = block.position();
QTextBlock::iterator blockIterator = block.begin();
+ if (blockIterator.atEnd() && preeditLength) {
+ engine.setPosition(blockPosition);
+ textPos = engine.addText(block, block.charFormat(), textColor, colorChanges,
+ textPos, textPos + preeditLength,
+ selectionStart, selectionEnd);
+ }
+
while (!blockIterator.atEnd()) {
QTextFragment fragment = blockIterator.fragment();
QString text = fragment.text();
@@ -1183,42 +1235,15 @@ void QQuickTextNode::addTextDocument(const QPointF &, QTextDocument *textDocumen
}
textPos += text.length();
} else {
- if (charFormat.foreground().style() != Qt::NoBrush)
- engine.setTextColor(charFormat.foreground().color());
- else
- engine.setTextColor(textColor);
-
int fragmentEnd = textPos + fragment.length();
if (preeditPosition >= 0
&& preeditPosition >= textPos
- && preeditPosition < fragmentEnd) {
+ && preeditPosition <= fragmentEnd) {
fragmentEnd += preeditLength;
}
- while (textPos < fragmentEnd) {
- int blockRelativePosition = textPos - block.position();
- QTextLine line = block.layout()->lineForTextPosition(blockRelativePosition);
- if (!engine.currentLine().isValid()
- || line.lineNumber() != engine.currentLine().lineNumber()) {
- engine.setCurrentLine(line);
- }
-
- Q_ASSERT(line.textLength() > 0);
- int lineEnd = line.textStart() + block.position() + line.textLength();
-
- int len = qMin(lineEnd - textPos, fragmentEnd - textPos);
- Q_ASSERT(len > 0);
-
- int currentStepEnd = textPos + len;
-
- engine.addGlyphsForRanges(colorChanges,
- textPos - block.position(),
- currentStepEnd - block.position(),
- selectionStart - block.position(),
- selectionEnd - block.position());
-
- textPos = currentStepEnd;
- }
+ engine.addText(block, charFormat, textColor, colorChanges, textPos, fragmentEnd,
+ selectionStart, selectionEnd);
}
++blockIterator;