summaryrefslogtreecommitdiffstats
path: root/src/declarative/graphicsitems/qdeclarativetext.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/declarative/graphicsitems/qdeclarativetext.cpp')
-rw-r--r--src/declarative/graphicsitems/qdeclarativetext.cpp55
1 files changed, 45 insertions, 10 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativetext.cpp b/src/declarative/graphicsitems/qdeclarativetext.cpp
index 03c9765..82c444e 100644
--- a/src/declarative/graphicsitems/qdeclarativetext.cpp
+++ b/src/declarative/graphicsitems/qdeclarativetext.cpp
@@ -219,6 +219,7 @@ void QDeclarativeTextPrivate::updateSize()
QFontMetrics fm(font);
if (text.isEmpty()) {
+ q->setImplicitWidth(0);
q->setImplicitHeight(fm.height());
emit q->paintedSizeChanged();
q->update();
@@ -284,37 +285,58 @@ QSize QDeclarativeTextPrivate::setupTextLayout()
{
// ### text layout handling should be profiled and optimized as needed
// what about QStackTextEngine engine(tmp, d->font.font()); QTextLayout textLayout(&engine);
-
Q_Q(QDeclarativeText);
layout.setCacheEnabled(true);
qreal height = 0;
+ qreal widthUsed = 0;
qreal lineWidth = 0;
//set manual width
- if (q->widthValid())
+ if ((wrapMode != QDeclarativeText::NoWrap || elideMode != QDeclarativeText::ElideNone) && q->widthValid())
lineWidth = q->width();
QTextOption textOption = layout.textOption();
textOption.setWrapMode(QTextOption::WrapMode(wrapMode));
- textOption.setAlignment(Qt::Alignment(hAlign));
layout.setTextOption(textOption);
layout.beginLayout();
- while (1) {
+ forever {
QTextLine line = layout.createLine();
if (!line.isValid())
break;
- if (q->widthValid()) {
+ if (lineWidth)
line.setLineWidth(lineWidth);
- line.setPosition(QPointF(0, height));
- height += line.height();
- }
}
layout.endLayout();
- return QSize(qCeil(layout.boundingRect().width()), layout.boundingRect().height());
+ 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;
+
+ qreal x = 0;
+ for (int i = 0; i < layout.lineCount(); ++i) {
+ QTextLine line = layout.lineAt(i);
+ line.setPosition(QPointF(0, height));
+ height += line.height();
+
+ if (!cacheAllTextAsImage) {
+ if (hAlign == QDeclarativeText::AlignLeft) {
+ x = 0;
+ } else if (hAlign == QDeclarativeText::AlignRight) {
+ x = layoutWidth - line.naturalTextWidth();
+ } else if (hAlign == QDeclarativeText::AlignHCenter) {
+ x = (layoutWidth - line.naturalTextWidth()) / 2;
+ }
+ line.setPosition(QPointF(x, line.y()));
+ }
+ }
+
+ return layout.boundingRect().toAlignedRect().size();
}
/*!
@@ -326,6 +348,19 @@ QPixmap QDeclarativeTextPrivate::textLayoutImage(bool drawStyle)
//do layout
QSize size = layedOutTextSize;
+ qreal 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() - line.naturalTextWidth();
+ } else if (hAlign == QDeclarativeText::AlignHCenter) {
+ x = (size.width() - line.naturalTextWidth()) / 2;
+ }
+ line.setPosition(QPointF(x, line.y()));
+ }
+
//paint text
QPixmap img(size);
if (!size.isEmpty()) {
@@ -1028,7 +1063,7 @@ void QDeclarativeText::setTextFormat(TextFormat format)
Set this property to elide parts of the text fit to the Text item's width.
The text will only elide if an explicit width has been set.
- This property cannot be used with wrapping enabled or with rich text.
+ This property cannot be used with multi-line text or with rich text.
Eliding can be:
\list