Skip to content

Commit

Permalink
Fix floating images in QSGTextNode
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Eskil Abrahamsen Blomfeldt authored and Qt by Nokia committed Oct 5, 2011
1 parent cd8c7b1 commit 2dbb775
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions src/declarative/items/qsgtextnode.cpp
Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand All @@ -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) {
Expand Down Expand Up @@ -678,7 +682,7 @@ namespace {
ascent = size.height() - 1;
}

addImage(QRectF(position, size), image, ascent, selectionState);
addImage(QRectF(position, size), image, ascent, selectionState, layoutPosition);
}
}

Expand Down Expand Up @@ -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));
}
}
}
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 2dbb775

Please sign in to comment.