Fix images not being rendered when embedded in a rich text.
authorYoann Lopes <yoann.lopes@nokia.com>
Wed, 1 Jun 2011 12:49:53 +0000 (14:49 +0200)
committerYoann Lopes <yoann.lopes@nokia.com>
Wed, 1 Jun 2011 13:56:36 +0000 (15:56 +0200)
In that case the whole text is cached in a QImage, but that cache was
not updated when the embedded image was finished to be loaded.

Depends on ac7dcaec90d7603cd4dd80cdb3dcbdc689f376c2.

Task-number: QTBUG-19428

src/declarative/items/qsgtext.cpp
src/declarative/items/qsgtext_p_p.h

index 8bff100..fe18169 100644 (file)
@@ -106,7 +106,8 @@ QSGTextPrivate::QSGTextPrivate()
   imageCacheDirty(true), updateOnComponentComplete(true),
   richText(false), singleline(false), cacheAllTextAsImage(true), internalWidthUpdate(false),
   requireImplicitWidth(false), truncated(false), hAlignImplicit(true), rightToLeftText(false),
-  layoutTextElided(false), naturalWidth(0), doc(0), layoutThread(0), nodeType(NodeIsNull)
+  layoutTextElided(false), richTextAsImage(false), naturalWidth(0), doc(0), layoutThread(0),
+  nodeType(NodeIsNull)
 {
     cacheAllTextAsImage = enableImageCache();
 }
@@ -574,7 +575,7 @@ void QSGTextPrivate::invalidateImageCache()
 {
     Q_Q(QSGText);
 
-    if(cacheAllTextAsImage || (!QSGDistanceFieldGlyphCache::distanceFieldEnabled() && style != QSGText::Normal)){//If actually using the image cache
+    if(richTextAsImage || cacheAllTextAsImage || (!QSGDistanceFieldGlyphCache::distanceFieldEnabled() && style != QSGText::Normal)){//If actually using the image cache
         if (imageCacheDirty)
             return;
 
@@ -749,6 +750,7 @@ void QSGText::setText(const QString &n)
             d->ensureDoc();
             d->doc->setText(n);
             d->rightToLeftText = d->doc->toPlainText().isRightToLeft();
+            d->richTextAsImage = QSGTextNode::isComplexRichText(d->doc);
         } else {
             d->rightToLeftText = d->text.isRightToLeft();
         }
@@ -988,6 +990,7 @@ void QSGText::setTextFormat(TextFormat format)
     if (!wasRich && d->richText && isComponentComplete()) {
         d->ensureDoc();
         d->doc->setText(d->text);
+        d->richTextAsImage = QSGTextNode::isComplexRichText(d->doc);
     }
 
     d->updateLayout();
@@ -1069,12 +1072,6 @@ QSGNode *QSGText::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *data)
         return 0;
     }
 
-    bool richTextAsImage = false;
-    if (d->richText) {
-        d->ensureDoc();
-        richTextAsImage = QSGTextNode::isComplexRichText(d->doc);
-    }
-
     QRectF bounds = boundingRect();
 
     // We need to make sure the layout is done in the current thread
@@ -1082,7 +1079,7 @@ QSGNode *QSGText::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *data)
         d->updateLayout();
 
     // XXX todo - some styled text can be done by the QSGTextNode
-    if (richTextAsImage || d->cacheAllTextAsImage || (!QSGDistanceFieldGlyphCache::distanceFieldEnabled() && d->style != Normal)) {
+    if (d->richTextAsImage || d->cacheAllTextAsImage || (!QSGDistanceFieldGlyphCache::distanceFieldEnabled() && d->style != Normal)) {
         bool wasDirty = d->imageCacheDirty;
 
         d->checkImageCache();
@@ -1213,6 +1210,7 @@ void QSGText::componentComplete()
             d->ensureDoc();
             d->doc->setText(d->text);
             d->rightToLeftText = d->doc->toPlainText().isRightToLeft();
+            d->richTextAsImage = QSGTextNode::isComplexRichText(d->doc);
         } else {
             d->rightToLeftText = d->text.isRightToLeft();
         }
index a3836a1..9c0d5b1 100644 (file)
@@ -120,12 +120,13 @@ public:
     bool hAlignImplicit:1;
     bool rightToLeftText:1;
     bool layoutTextElided:1;
+    bool richTextAsImage:1;
 
     QRect layedOutTextRect;
     QSize paintedSize;
     qreal naturalWidth;
     virtual qreal getImplicitWidth() const;
-    
+
     void ensureDoc();
     QPixmap textDocumentImage(bool drawStyle);
     QSGTextDocumentWithImageResources *doc;