diff options
author | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com> | 2011-10-05 12:13:31 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-10-05 14:31:40 +0200 |
commit | 2dbb77584a26b8de5f84124498059d9f811a23dd (patch) | |
tree | f5bf7edfbb9289f69e22703b698c7d6947146bd6 | |
parent | cd8c7b1c3c4f743bda9b66ef7840606a20e7b9cf (diff) |
Fix floating images in QSGTextNode
When images are floating and we encounter the object replacement
character, we should ignore them, as they're done by special
handling of the QTextFrame. We also need to make sure they are
not attempted inlined by passing the layout position of the frame
to addTextObject(), and we need to set a valid QTextLine for the
object to make sure it's added to the graph.
Change-Id: Ia43ef3fd4bb9c7b48e0862071118ee0f176212bd
Reviewed-on: http://codereview.qt-project.org/6036
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Jiang Jiang <jiang.jiang@nokia.com>
-rw-r--r-- | src/declarative/items/qsgtextnode.cpp | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/src/declarative/items/qsgtextnode.cpp b/src/declarative/items/qsgtextnode.cpp index 39fa0332e7..1dd3564425 100644 --- a/src/declarative/items/qsgtextnode.cpp +++ b/src/declarative/items/qsgtextnode.cpp @@ -325,10 +325,12 @@ namespace { const QBrush &borderBrush); void addFrameDecorations(QTextDocument *document, QTextFrame *frame); void addImage(const QRectF &rect, const QImage &image, qreal ascent, - BinaryTreeNode::SelectionState selectionState); + BinaryTreeNode::SelectionState selectionState, + QTextFrameFormat::Position layoutPosition); void addTextObject(const QPointF &position, const QTextCharFormat &format, BinaryTreeNode::SelectionState selectionState, - QTextDocument *textDocument, int pos); + QTextDocument *textDocument, int pos, + QTextFrameFormat::Position layoutPosition = QTextFrameFormat::InFlow); void addSelectedGlyphs(const QGlyphRun &glyphRun); void addUnselectedGlyphs(const QGlyphRun &glyphRun); void addGlyphsInRange(int rangeStart, int rangeEnd, @@ -619,10 +621,11 @@ namespace { } void SelectionEngine::addImage(const QRectF &rect, const QImage &image, qreal ascent, - BinaryTreeNode::SelectionState selectionState) + BinaryTreeNode::SelectionState selectionState, + QTextFrameFormat::Position layoutPosition) { QRectF searchRect = rect; - if (searchRect.topLeft().isNull()) { + if (layoutPosition == QTextFrameFormat::InFlow) { if (m_currentLineTree.isEmpty()) { searchRect.moveTopLeft(m_position); } else { @@ -642,7 +645,8 @@ namespace { void SelectionEngine::addTextObject(const QPointF &position, const QTextCharFormat &format, BinaryTreeNode::SelectionState selectionState, - QTextDocument *textDocument, int pos) + QTextDocument *textDocument, int pos, + QTextFrameFormat::Position layoutPosition) { QTextObjectInterface *handler = textDocument->documentLayout()->handlerForObject(format.objectType()); if (handler != 0) { @@ -678,7 +682,7 @@ namespace { ascent = size.height() - 1; } - addImage(QRectF(position, size), image, ascent, selectionState); + addImage(QRectF(position, size), image, ascent, selectionState, layoutPosition); } } @@ -941,8 +945,7 @@ namespace { if (node->selectionState == BinaryTreeNode::Selected) { QColor color = m_selectionColor; color.setAlpha(128); - parentNode->appendChildNode(new QSGSimpleRectNode(node->boundingRect, - color)); + parentNode->appendChildNode(new QSGSimpleRectNode(node->boundingRect, color)); } } } @@ -1071,8 +1074,10 @@ void QSGTextNode::addTextDocument(const QPointF &, QTextDocument *textDocument, QTextCharFormat format = a->formatAccessor(pos); QRectF rect = a->frameBoundingRect(textFrame); + QTextBlock block = textFrame->firstCursorPosition().block(); + engine.setCurrentLine(block.layout()->lineForTextPosition(pos - block.position())); engine.addTextObject(rect.topLeft(), format, BinaryTreeNode::Unselected, textDocument, - pos); + pos, textFrame->frameFormat().position()); } else { QTextFrame::iterator it = textFrame->begin(); @@ -1158,7 +1163,8 @@ void QSGTextNode::addTextDocument(const QPointF &, QTextDocument *textDocument, engine.setPosition(blockPosition); if (text.contains(QChar::ObjectReplacementCharacter)) { QTextFrame *frame = qobject_cast<QTextFrame *>(textDocument->objectForFormat(charFormat)); - if (frame) { + if (frame && frame->frameFormat().position() == QTextFrameFormat::InFlow + && frame->firstPosition() <= frame->lastPosition()) { BinaryTreeNode::SelectionState selectionState = (selectionStart < textPos + text.length() && selectionEnd >= textPos) |