format(QQuickText::AutoText), wrapMode(QQuickText::NoWrap), lineHeight(1),
lineHeightMode(QQuickText::ProportionalHeight), lineCount(1), maximumLineCount(INT_MAX),
maximumLineCountValid(false),
- texture(0),
+ imageCache(0), texture(0),
imageCacheDirty(false), updateOnComponentComplete(true),
- richText(false), styledText(false), singleline(false), cacheAllTextAsImage(true), internalWidthUpdate(false),
+ richText(false), styledText(false), singleline(false), cacheAllTextAsImage(true),
+ disableDistanceField(false), internalWidthUpdate(false),
requireImplicitWidth(false), truncated(false), hAlignImplicit(true), rightToLeftText(false),
layoutTextElided(false), richTextAsImage(false), textureImageCacheDirty(false), textHasChanged(true),
naturalWidth(0), doc(0), elipsisLayout(0), textLine(0), nodeType(NodeIsNull)
{
cacheAllTextAsImage = enableImageCache();
+ disableDistanceField = qmlDisableDistanceField();
}
void QQuickTextPrivate::init()
{
delete elipsisLayout;
delete textLine; textLine = 0;
+ delete imageCache;
}
qreal QQuickTextPrivate::getImplicitWidth() const
delete elipsisLayout;
elipsisLayout = 0;
}
- layout.clearLayout();
layout.setFont(font);
- if (!styledText) {
+ if (text.isEmpty()) {
+ if (!layout.text().isEmpty())
+ layout.setText(text);
+ } else if (!styledText) {
QString tmp = text;
tmp.replace(QLatin1Char('\n'), QChar::LineSeparator);
singleline = !tmp.contains(QChar::LineSeparator);
QFontMetrics fm(font);
if (text.isEmpty()) {
- q->setImplicitSize(0, fm.height());
- paintedSize = QSize(0, fm.height());
+ qreal fontHeight = fm.height();
+ q->setImplicitSize(0, fontHeight);
+ paintedSize = QSize(0, fontHeight);
emit q->paintedSizeChanged();
q->update();
return;
QTextOption option;
option.setAlignment((Qt::Alignment)int(horizontalAlignment | vAlign));
option.setWrapMode(QTextOption::WrapMode(wrapMode));
- if (!cacheAllTextAsImage && !richTextAsImage && !qmlDisableDistanceField())
+ if (!cacheAllTextAsImage && !richTextAsImage && !disableDistanceField)
option.setUseDesignMetrics(true);
doc->setDefaultTextOption(option);
if (requireImplicitWidth && q->widthValid()) {
#if defined(Q_OS_MAC)
if (QThread::currentThread() != paintingThread) {
-#endif
if (!line.lineNumber())
linesRects.clear();
+#endif
if (!textLine)
textLine = new QQuickTextLine;
emit q->lineLaidOut(textLine);
- linesRects << QRectF(textLine->x(), textLine->y(), textLine->width(), textLine->height());
height += textLine->height();
#if defined(Q_OS_MAC)
+ linesRects << QRectF(textLine->x(), textLine->y(), textLine->width(), textLine->height());
+
} else {
if (line.lineNumber() < linesRects.count()) {
QRectF r = linesRects.at(line.lineNumber());
QTextOption textOption = layout.textOption();
textOption.setAlignment(Qt::Alignment(q->effectiveHAlign()));
textOption.setWrapMode(QTextOption::WrapMode(wrapMode));
- if (!cacheAllTextAsImage && !richTextAsImage && !qmlDisableDistanceField())
+ if (!cacheAllTextAsImage && !richTextAsImage && !disableDistanceField)
textOption.setUseDesignMetrics(true);
layout.setTextOption(textOption);
return img;
}
+
+void QQuickTextPrivate::markDirty()
+{
+ Q_Q(QQuickText);
+ if (!invalidateImageCache() && q->isComponentComplete())
+ q->update();
+}
+
/*!
Mark the image cache as dirty.
*/
-void QQuickTextPrivate::invalidateImageCache()
+bool QQuickTextPrivate::invalidateImageCache()
{
Q_Q(QQuickText);
- if (richTextAsImage || cacheAllTextAsImage || (qmlDisableDistanceField() && style != QQuickText::Normal)) { // If actually using the image cache
+ if (richTextAsImage || cacheAllTextAsImage || (disableDistanceField && style != QQuickText::Normal)) { // If actually using the image cache
if (imageCacheDirty)
- return;
+ return true;
imageCacheDirty = true;
if (q->isComponentComplete())
QCoreApplication::postEvent(q, new QEvent(QEvent::User));
- } else if (q->isComponentComplete())
- q->update();
+ return true;
+ }
+
+ return false;
}
/*!
if (text.isEmpty()) {
- imageCache = QPixmap();
+ delete imageCache;
+ imageCache = 0;
} else {
styledImage = textLayoutImage(true); //### should use styleColor
}
+ delete imageCache;
switch (style) {
case QQuickText::Outline:
- imageCache = drawOutline(textImage, styledImage);
+ imageCache = new QPixmap(drawOutline(textImage, styledImage));
break;
case QQuickText::Sunken:
- imageCache = drawOutline(textImage, styledImage, -1);
+ imageCache = new QPixmap(drawOutline(textImage, styledImage, -1));
break;
case QQuickText::Raised:
- imageCache = drawOutline(textImage, styledImage, 1);
+ imageCache = new QPixmap(drawOutline(textImage, styledImage, 1));
break;
default:
- imageCache = textImage;
+ imageCache = new QPixmap(textImage);
break;
}
return;
d->color = color;
- d->invalidateImageCache();
+ d->markDirty();
emit colorChanged(d->color);
}
/*!
if (isComponentComplete() && (d->style == Normal || style == Normal))
update();
d->style = style;
- d->invalidateImageCache();
+ d->markDirty();
emit styleChanged(d->style);
}
return;
d->styleColor = color;
- d->invalidateImageCache();
+ d->markDirty();
emit styleColorChanged(d->styleColor);
}
void QQuickText::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
{
Q_D(QQuickText);
+ if (d->text.isEmpty()) {
+ QQuickItem::geometryChanged(newGeometry, oldGeometry);
+ return;
+ }
+
bool widthChanged = newGeometry.width() != oldGeometry.width();
bool heightChanged = newGeometry.height() != oldGeometry.height();
bool leftAligned = effectiveHAlign() == QQuickText::AlignLeft;
#endif
// XXX todo - some styled text can be done by the QQuickTextNode
- if (d->richTextAsImage || d->cacheAllTextAsImage || (qmlDisableDistanceField() && d->style != Normal)) {
+ if (d->richTextAsImage || d->cacheAllTextAsImage || (d->disableDistanceField && d->style != Normal)) {
bool wasDirty = d->textureImageCacheDirty;
d->textureImageCacheDirty = false;
- if (d->imageCache.isNull()) {
+ if (!d->imageCache || d->imageCache->isNull()) {
delete oldNode;
return 0;
}
}
if (wasDirty) {
- qobject_cast<QSGPlainTexture *>(d->texture)->setImage(d->imageCache.toImage());
+ qobject_cast<QSGPlainTexture *>(d->texture)->setImage(d->imageCache->toImage());
node->setTexture(0);
node->setTexture(d->texture);
}
- node->setTargetRect(QRectF(bounds.x(), bounds.y(), d->imageCache.width(), d->imageCache.height()));
+ node->setTargetRect(QRectF(bounds.x(), bounds.y(), d->imageCache->width(), d->imageCache->height()));
node->setSourceRect(QRectF(0, 0, 1, 1));
node->setHorizontalWrapMode(QSGTexture::ClampToEdge);
node->setVerticalWrapMode(QSGTexture::ClampToEdge);