diff options
author | Yann Bodson <yann.bodson@nokia.com> | 2010-10-28 08:18:41 (GMT) |
---|---|---|
committer | Yann Bodson <yann.bodson@nokia.com> | 2010-10-28 08:20:04 (GMT) |
commit | 82159dbbfe7e36bc8f67ad1637a2285fb002eb11 (patch) | |
tree | e08155ba9e963af30bcdbb4fad8ccd7690018be9 /src/declarative/graphicsitems/qdeclarativetext.cpp | |
parent | 823ee43984a05e106e4b0b750a820b7da0892094 (diff) | |
download | Qt-82159dbbfe7e36bc8f67ad1637a2285fb002eb11.zip Qt-82159dbbfe7e36bc8f67ad1637a2285fb002eb11.tar.gz Qt-82159dbbfe7e36bc8f67ad1637a2285fb002eb11.tar.bz2 |
Remove unnecessary layouting code from QDeclarativeText
Task-number: QTBUG-14795
Reviewed-by: Michael Brasser
Diffstat (limited to 'src/declarative/graphicsitems/qdeclarativetext.cpp')
-rw-r--r-- | src/declarative/graphicsitems/qdeclarativetext.cpp | 51 |
1 files changed, 8 insertions, 43 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativetext.cpp b/src/declarative/graphicsitems/qdeclarativetext.cpp index 0717b78..c8e3615 100644 --- a/src/declarative/graphicsitems/qdeclarativetext.cpp +++ b/src/declarative/graphicsitems/qdeclarativetext.cpp @@ -287,8 +287,7 @@ QSize QDeclarativeTextPrivate::setupTextLayout() Q_Q(QDeclarativeText); layout.setCacheEnabled(true); - int height = 0; - qreal widthUsed = 0; + qreal height = 0; qreal lineWidth = 0; //set manual width @@ -297,6 +296,7 @@ QSize QDeclarativeTextPrivate::setupTextLayout() QTextOption textOption = layout.textOption(); textOption.setWrapMode(QTextOption::WrapMode(wrapMode)); + textOption.setAlignment((Qt::Alignment)hAlign); layout.setTextOption(textOption); layout.beginLayout(); @@ -305,37 +305,15 @@ QSize QDeclarativeTextPrivate::setupTextLayout() if (!line.isValid()) break; - if ((wrapMode != QDeclarativeText::NoWrap || elideMode != QDeclarativeText::ElideNone) && q->widthValid()) + if ((wrapMode != QDeclarativeText::NoWrap || elideMode != QDeclarativeText::ElideNone) && q->widthValid()) { line.setLineWidth(lineWidth); - } - layout.endLayout(); - - for (int i = 0; i < layout.lineCount(); ++i) { - QTextLine line = layout.lineAt(i); - widthUsed = qMax(widthUsed, line.naturalTextWidth()); - } - - qreal layoutWidth = q->widthValid()?q->width():widthUsed; - - int x = 0; - for (int i = 0; i < layout.lineCount(); ++i) { - QTextLine line = layout.lineAt(i); - line.setPosition(QPointF(0, height)); - height += int(line.height()); - - if (!cacheAllTextAsImage) { - if (hAlign == QDeclarativeText::AlignLeft) { - x = 0; - } else if (hAlign == QDeclarativeText::AlignRight) { - x = layoutWidth - (int)line.naturalTextWidth(); - } else if (hAlign == QDeclarativeText::AlignHCenter) { - x = (layoutWidth - (int)line.naturalTextWidth()) / 2; - } - line.setPosition(QPoint(x, (int)line.y())); + line.setPosition(QPointF(0, height)); + height += line.height(); } } + layout.endLayout(); - return QSize(qCeil(widthUsed), height); + return QSize(qCeil(layout.boundingRect().width()), layout.boundingRect().height()); } /*! @@ -347,19 +325,6 @@ QPixmap QDeclarativeTextPrivate::textLayoutImage(bool drawStyle) //do layout QSize size = layedOutTextSize; - int x = 0; - for (int i = 0; i < layout.lineCount(); ++i) { - QTextLine line = layout.lineAt(i); - if (hAlign == QDeclarativeText::AlignLeft) { - x = 0; - } else if (hAlign == QDeclarativeText::AlignRight) { - x = size.width() - (int)line.naturalTextWidth(); - } else if (hAlign == QDeclarativeText::AlignHCenter) { - x = (size.width() - (int)line.naturalTextWidth()) / 2; - } - line.setPosition(QPoint(x, (int)line.y())); - } - //paint text QPixmap img(size); if (!size.isEmpty()) { @@ -1147,7 +1112,7 @@ void QDeclarativeText::geometryChanged(const QRectF &newGeometry, const QRectF & if ((!d->internalWidthUpdate && newGeometry.width() != oldGeometry.width()) && (d->wrapMode != QDeclarativeText::NoWrap || d->elideMode != QDeclarativeText::ElideNone - || d->hAlign != Qt::AlignLeft)) { + || d->hAlign != QDeclarativeText::AlignLeft)) { if (d->singleline && d->elideMode != QDeclarativeText::ElideNone && widthValid()) { // We need to re-elide d->updateLayout(); |