Skip to content

Commit

Permalink
Make QSGTextNode back-end for QML's TextInput and TextEdit
Browse files Browse the repository at this point in the history
Use the general QSGTextNode class as back-end for all text
elements in QML to make all text elements look the same and
use the same text rasterization back-end. This requires a
few rewrites in the text node to support e.g. selections.

Crashes seen with threaded renderer in TextEdit and TextInput on
Mac are also fixed by this.

Reviewed-by: Jiang Jiang
Task-number: QTBUG-18019, QTBUG-20017
Change-Id: I4207faf180c83422e5f8b726741321af395bd724
Reviewed-on: http://codereview.qt.nokia.com/2865
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>
  • Loading branch information
Eskil Abrahamsen Blomfeldt authored and Qt by Nokia committed Aug 19, 2011
1 parent 7059861 commit 1cc58fd
Show file tree
Hide file tree
Showing 16 changed files with 1,216 additions and 260 deletions.
17 changes: 14 additions & 3 deletions src/declarative/items/qsgtext.cpp
Expand Up @@ -107,7 +107,12 @@ QSGTextPrivate::QSGTextPrivate()
richText(false), singleline(false), cacheAllTextAsImage(true), internalWidthUpdate(false),
requireImplicitWidth(false), truncated(false), hAlignImplicit(true), rightToLeftText(false),
layoutTextElided(false), richTextAsImage(false), textureImageCacheDirty(false), naturalWidth(0),
doc(0), layoutThread(0), nodeType(NodeIsNull)
doc(0), nodeType(NodeIsNull)

#if defined(Q_OS_MAC)
, layoutThread(0)
#endif

{
cacheAllTextAsImage = enableImageCache();
}
Expand Down Expand Up @@ -291,7 +296,9 @@ void QSGTextPrivate::updateSize()
int dy = q->height();
QSize size(0, 0);

#if defined(Q_OS_MAC)
layoutThread = QThread::currentThread();
#endif

//setup instance of QTextLayout for all cases other than richtext
if (!richText) {
Expand All @@ -313,6 +320,8 @@ void QSGTextPrivate::updateSize()
QTextOption option;
option.setAlignment((Qt::Alignment)int(horizontalAlignment | vAlign));
option.setWrapMode(QTextOption::WrapMode(wrapMode));
if (!cacheAllTextAsImage && !richTextAsImage && !qmlDisableDistanceField())
option.setUseDesignMetrics(true);
doc->setDefaultTextOption(option);
if (requireImplicitWidth && q->widthValid()) {
doc->setTextWidth(-1);
Expand Down Expand Up @@ -376,6 +385,8 @@ QRect QSGTextPrivate::setupTextLayout()
QTextOption textOption = layout.textOption();
textOption.setAlignment(Qt::Alignment(q->effectiveHAlign()));
textOption.setWrapMode(QTextOption::WrapMode(wrapMode));
if (!cacheAllTextAsImage && !richTextAsImage && !qmlDisableDistanceField())
textOption.setUseDesignMetrics(true);
layout.setTextOption(textOption);

bool elideText = false;
Expand Down Expand Up @@ -907,8 +918,6 @@ void QSGText::setFont(const QFont &font)
d->sourceFont = font;
QFont oldFont = d->font;
d->font = font;
if (!qmlDisableDistanceField())
d->font.setHintingPreference(QFont::PreferNoHinting);

if (d->font.pointSizeF() != -1) {
// 0.5pt resolution
Expand Down Expand Up @@ -1480,8 +1489,10 @@ QSGNode *QSGText::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *data)
QRectF bounds = boundingRect();

// We need to make sure the layout is done in the current thread
#if defined(Q_OS_MAC)
if (d->layoutThread != QThread::currentThread())
d->updateLayout();
#endif

// XXX todo - some styled text can be done by the QSGTextNode
if (d->richTextAsImage || d->cacheAllTextAsImage || (qmlDisableDistanceField() && d->style != Normal)) {
Expand Down
7 changes: 5 additions & 2 deletions src/declarative/items/qsgtext_p_p.h
Expand Up @@ -134,7 +134,6 @@ class Q_AUTOTEST_EXPORT QSGTextPrivate : public QSGImplicitSizeItemPrivate
QPixmap textLayoutImage(bool drawStyle);
void drawTextLayout(QPainter *p, const QPointF &pos, bool drawStyle);
QTextLayout layout;
QThread *layoutThread;

static QPixmap drawOutline(const QPixmap &source, const QPixmap &styleSource);
static QPixmap drawOutline(const QPixmap &source, const QPixmap &styleSource, int yOffset);
Expand All @@ -146,9 +145,13 @@ class Q_AUTOTEST_EXPORT QSGTextPrivate : public QSGImplicitSizeItemPrivate
enum NodeType {
NodeIsNull,
NodeIsTexture,
NodeIsText,
NodeIsText
};
NodeType nodeType;

#if defined(Q_OS_MAC)
QThread *layoutThread;
#endif
};

QT_END_NAMESPACE
Expand Down

0 comments on commit 1cc58fd

Please sign in to comment.