QQuickTextEdit: render inline images after change 48798
authorPierre Rossi <pierre.rossi@digia.com>
Thu, 21 Mar 2013 12:15:01 +0000 (13:15 +0100)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Thu, 4 Apr 2013 16:10:04 +0000 (18:10 +0200)
The refactoring in QQuickTextEdit from this change:
https://codereview.qt-project.org/#change,48798
accidentally broke rendering of inline images.
Revive the ProtectedLayoutAccessor trick to get the proper
format and properly extract the image from it.

Change-Id: I445914efcea1012daa79d594aa1e828b1039b988
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@digia.com>
src/quick/items/qquicktextedit.cpp

index 506b4ca..dde3587 100644 (file)
@@ -125,6 +125,17 @@ TextEdit {
 // into text nodes corresponding to a text block each so that the glyph node grouping doesn't become pointless.
 static const int nodeBreakingSize = 300;
 
+namespace {
+    class ProtectedLayoutAccessor: public QAbstractTextDocumentLayout
+    {
+    public:
+        inline QTextCharFormat formatAccessor(int pos)
+        {
+            return format(pos);
+        }
+    };
+}
+
 QQuickTextEdit::QQuickTextEdit(QQuickItem *parent)
 : QQuickImplicitSizeItem(*(new QQuickTextEditPrivate), parent)
 {
@@ -1772,9 +1783,11 @@ QSGNode *QQuickTextEdit::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *
                     node->setMatrix(transformMatrix);
                 }
                 const int pos = textFrame->firstPosition() - 1;
+                ProtectedLayoutAccessor *a = static_cast<ProtectedLayoutAccessor *>(d->document->documentLayout());
+                QTextCharFormat format = a->formatAccessor(pos);
                 QTextBlock block = textFrame->firstCursorPosition().block();
                 node->m_engine->setCurrentLine(block.layout()->lineForTextPosition(pos - block.position()));
-                node->m_engine->addTextObject(QPointF(0, 0), block.charFormat(), QQuickTextNodeEngine::Unselected, d->document,
+                node->m_engine->addTextObject(QPointF(0, 0), format, QQuickTextNodeEngine::Unselected, d->document,
                                               pos, textFrame->frameFormat().position());
             } else {