diff options
author | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com> | 2012-07-04 14:56:38 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-07-10 14:22:34 +0200 |
commit | b0b4869440fc6e5af42797cbcaa64ec30238be73 (patch) | |
tree | 208f5f90c9ee6c3a71cc9e751a9374addede67d0 /src/quick/items/qquicktext.cpp | |
parent | c66d00a7f53d6a6a847bc7171529273f4d089923 (diff) |
Add option to use native rasterizer for SceneGraph text
For old-style (desktop components) apps using QML 2 on regular density
displays, distance field text will look out of place. We introduce
an option to use the native rasterizer instead if you would rather
have native look and feel than scalable text items.
Change-Id: Idb38e3c89f2deab9ae1963357c6c5fb235ddeab8
Reviewed-by: Jiang Jiang <jiang.jiang@nokia.com>
Diffstat (limited to 'src/quick/items/qquicktext.cpp')
-rw-r--r-- | src/quick/items/qquicktext.cpp | 45 |
1 files changed, 42 insertions, 3 deletions
diff --git a/src/quick/items/qquicktext.cpp b/src/quick/items/qquicktext.cpp index c48ea0fb07..3d29adea9e 100644 --- a/src/quick/items/qquicktext.cpp +++ b/src/quick/items/qquicktext.cpp @@ -84,6 +84,7 @@ QQuickTextPrivate::QQuickTextPrivate() , elideMode(QQuickText::ElideNone), hAlign(QQuickText::AlignLeft), vAlign(QQuickText::AlignTop) , format(QQuickText::AutoText), wrapMode(QQuickText::NoWrap) , style(QQuickText::Normal) + , renderType(QQuickText::QtRendering) , updateType(UpdatePaintNode) , maximumLineCountValid(false), updateOnComponentComplete(true), richText(false) , styledText(false), widthExceeded(false), heightExceeded(false), internalWidthUpdate(false) @@ -300,6 +301,41 @@ qreal QQuickTextPrivate::getImplicitHeight() const return implicitHeight; } +/*! + \qmlproperty enumeration QtQuick2::Text::renderType + + Override the default rendering type for this component. + + Supported render types are: + \list + \li Text.QtRendering - the default + \li Text.NativeRendering + \endlist + + Select Text.NativeRendering if you prefer text to look native on the target platform and do + not require advanced features such as transformation of the text. Using such features in + combination with the NativeRendering render type will lend poor and sometimes pixelated + results. +*/ +QQuickText::RenderType QQuickText::renderType() const +{ + Q_D(const QQuickText); + return d->renderType; +} + +void QQuickText::setRenderType(QQuickText::RenderType renderType) +{ + Q_D(QQuickText); + if (d->renderType == renderType) + return; + + d->renderType = renderType; + emit renderTypeChanged(); + + if (isComponentComplete()) + d->updateLayout(); +} + void QQuickText::q_imagesLoaded() { Q_D(QQuickText); @@ -482,7 +518,7 @@ void QQuickTextPrivate::updateSize() QTextOption option; option.setAlignment((Qt::Alignment)int(horizontalAlignment | vAlign)); option.setWrapMode(QTextOption::WrapMode(wrapMode)); - option.setUseDesignMetrics(true); + option.setUseDesignMetrics(renderType != QQuickText::NativeRendering); extra->doc->setDefaultTextOption(option); qreal naturalWidth = 0; if (requireImplicitSize && q->widthValid()) { @@ -734,14 +770,16 @@ QRectF QQuickTextPrivate::setupTextLayout(qreal *const baseline) return QRectF(0, 0, 0, height); } + bool shouldUseDesignMetrics = renderType != QQuickText::NativeRendering; + layout.setCacheEnabled(true); QTextOption textOption = layout.textOption(); if (textOption.alignment() != q->effectiveHAlign() || textOption.wrapMode() != QTextOption::WrapMode(wrapMode) - || !textOption.useDesignMetrics()) { + || textOption.useDesignMetrics() != shouldUseDesignMetrics) { textOption.setAlignment(Qt::Alignment(q->effectiveHAlign())); textOption.setWrapMode(QTextOption::WrapMode(wrapMode)); - textOption.setUseDesignMetrics(true); + textOption.setUseDesignMetrics(shouldUseDesignMetrics); layout.setTextOption(textOption); } if (layout.font() != font) @@ -2219,6 +2257,7 @@ QSGNode *QQuickText::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *data node = static_cast<QQuickTextNode *>(oldNode); } + node->setUseNativeRenderer(d->renderType == NativeRendering); node->deleteContent(); node->setMatrix(QMatrix4x4()); |