summaryrefslogtreecommitdiffstats
path: root/src/declarative
diff options
context:
space:
mode:
authorMartin Jones <martin.jones@nokia.com>2010-01-15 08:53:20 (GMT)
committerMartin Jones <martin.jones@nokia.com>2010-01-15 08:53:20 (GMT)
commit44f9af5ebac6bed2dd46021140cd41d3a4547993 (patch)
treeae48c813db31e0abb94160faf48a73d9e5b94c03 /src/declarative
parentbc1c329c5fd7679023eb69f6d0924e6536fc7b12 (diff)
downloadQt-44f9af5ebac6bed2dd46021140cd41d3a4547993.zip
Qt-44f9af5ebac6bed2dd46021140cd41d3a4547993.tar.gz
Qt-44f9af5ebac6bed2dd46021140cd41d3a4547993.tar.bz2
Allow disabling of text cache for non-richtext.
Diffstat (limited to 'src/declarative')
-rw-r--r--src/declarative/graphicsitems/qmlgraphicstext.cpp155
-rw-r--r--src/declarative/graphicsitems/qmlgraphicstext_p_p.h7
2 files changed, 107 insertions, 55 deletions
diff --git a/src/declarative/graphicsitems/qmlgraphicstext.cpp b/src/declarative/graphicsitems/qmlgraphicstext.cpp
index 854ef45..58dab74 100644
--- a/src/declarative/graphicsitems/qmlgraphicstext.cpp
+++ b/src/declarative/graphicsitems/qmlgraphicstext.cpp
@@ -362,12 +362,23 @@ void QmlGraphicsText::setWrap(bool w)
The way the text property should be displayed.
- Supported text formats are \c AutoText, \c PlainText and \c RichText.
+ Supported text formats are \c AutoText, \c PlainText, \c RichText and \c StyledText
The default is AutoText. If the text format is AutoText the text element
will automatically determine whether the text should be treated as
rich text. This determination is made using Qt::mightBeRichText().
+ StyledText is an optimized format able supporting some basic text
+ styling markup, in the style of html 3.2:
+
+ \code
+ <font size="4" color="#ff0000">font size and color</font>
+ <b>bold</b>
+ <i>italic</i>
+ <br>
+ &gt; &lt; &amp;
+ \endcode
+
\table
\row
\o
@@ -622,12 +633,25 @@ QSize QmlGraphicsTextPrivate::setupTextLayout(QTextLayout *layout)
}
layout->endLayout();
+ int x = 0;
for (int i = 0; i < layout->lineCount(); ++i) {
QTextLine line = layout->lineAt(i);
widthUsed = qMax(widthUsed, line.naturalTextWidth());
line.setPosition(QPointF(0, height));
height += int(line.height());
+
+ if (!cache) {
+ if (hAlign == QmlGraphicsText::AlignLeft) {
+ x = 0;
+ } else if (hAlign == QmlGraphicsText::AlignRight) {
+ x = q->width() - (int)line.naturalTextWidth();
+ } else if (hAlign == QmlGraphicsText::AlignHCenter) {
+ x = (q->width() - (int)line.naturalTextWidth()) / 2;
+ }
+ line.setPosition(QPoint(x, (int)line.y()));
+ }
}
+
return QSize(qCeil(widthUsed), height);
}
@@ -654,17 +678,21 @@ QPixmap QmlGraphicsTextPrivate::wrappedTextImage(bool drawStyle)
if (!size.isEmpty()) {
img.fill(Qt::transparent);
QPainter p(&img);
- if (drawStyle) {
- p.setPen(styleColor);
- }
- else
- p.setPen(color);
- p.setFont(font);
- layout.draw(&p, QPointF(0, 0));
+ drawWrappedText(&p, QPointF(0,0), drawStyle);
}
return img;
}
+void QmlGraphicsTextPrivate::drawWrappedText(QPainter *p, const QPointF &pos, bool drawStyle)
+{
+ if (drawStyle)
+ p->setPen(styleColor);
+ else
+ p->setPen(color);
+ p->setFont(font);
+ layout.draw(p, pos);
+}
+
QPixmap QmlGraphicsTextPrivate::richTextImage(bool drawStyle)
{
QSize size = doc->size().toSize();
@@ -730,59 +758,78 @@ void QmlGraphicsTextPrivate::checkImgCache()
void QmlGraphicsText::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *)
{
Q_D(QmlGraphicsText);
- d->checkImgCache();
- if (d->imgCache.isNull())
- return;
- bool oldAA = p->testRenderHint(QPainter::Antialiasing);
- bool oldSmooth = p->testRenderHint(QPainter::SmoothPixmapTransform);
- if (d->smooth)
- p->setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform, d->smooth);
+ if (d->cache || d->richText || d->style != Normal) {
+ d->checkImgCache();
+ if (d->imgCache.isNull())
+ return;
- int w = width();
- int h = height();
+ bool oldAA = p->testRenderHint(QPainter::Antialiasing);
+ bool oldSmooth = p->testRenderHint(QPainter::SmoothPixmapTransform);
+ if (d->smooth)
+ p->setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform, d->smooth);
- int x = 0;
- int y = 0;
-
- switch (d->hAlign) {
- case AlignLeft:
- x = 0;
- break;
- case AlignRight:
- x = w - d->imgCache.width();
- break;
- case AlignHCenter:
- x = (w - d->imgCache.width()) / 2;
- break;
- }
+ int w = width();
+ int h = height();
- switch (d->vAlign) {
- case AlignTop:
- y = 0;
- break;
- case AlignBottom:
- y = h - d->imgCache.height();
- break;
- case AlignVCenter:
- y = (h - d->imgCache.height()) / 2;
- break;
- }
+ int x = 0;
+ int y = 0;
+
+ switch (d->hAlign) {
+ case AlignLeft:
+ x = 0;
+ break;
+ case AlignRight:
+ x = w - d->imgCache.width();
+ break;
+ case AlignHCenter:
+ x = (w - d->imgCache.width()) / 2;
+ break;
+ }
- bool needClip = !clip() && (d->imgCache.width() > width() ||
- d->imgCache.height() > height());
+ switch (d->vAlign) {
+ case AlignTop:
+ y = 0;
+ break;
+ case AlignBottom:
+ y = h - d->imgCache.height();
+ break;
+ case AlignVCenter:
+ y = (h - d->imgCache.height()) / 2;
+ break;
+ }
- if (needClip) {
- p->save();
- p->setClipRect(boundingRect(), Qt::IntersectClip);
- }
- p->drawPixmap(x, y, d->imgCache);
- if (needClip)
- p->restore();
+ bool needClip = !clip() && (d->imgCache.width() > width() ||
+ d->imgCache.height() > height());
- if (d->smooth) {
- p->setRenderHint(QPainter::Antialiasing, oldAA);
- p->setRenderHint(QPainter::SmoothPixmapTransform, oldSmooth);
+ if (needClip) {
+ p->save();
+ p->setClipRect(boundingRect(), Qt::IntersectClip);
+ }
+ p->drawPixmap(x, y, d->imgCache);
+ if (needClip)
+ p->restore();
+
+ if (d->smooth) {
+ p->setRenderHint(QPainter::Antialiasing, oldAA);
+ p->setRenderHint(QPainter::SmoothPixmapTransform, oldSmooth);
+ }
+ } else {
+ int h = height();
+ int y = 0;
+
+ switch (d->vAlign) {
+ case AlignTop:
+ y = 0;
+ break;
+ case AlignBottom:
+ y = h - d->cachedLayoutSize.height();
+ break;
+ case AlignVCenter:
+ y = (h - d->cachedLayoutSize.height()) / 2;
+ break;
+ }
+ d->drawWrappedText(p, QPointF(0,y), false);
}
}
diff --git a/src/declarative/graphicsitems/qmlgraphicstext_p_p.h b/src/declarative/graphicsitems/qmlgraphicstext_p_p.h
index 73c3dd7..1e29e58 100644
--- a/src/declarative/graphicsitems/qmlgraphicstext_p_p.h
+++ b/src/declarative/graphicsitems/qmlgraphicstext_p_p.h
@@ -72,9 +72,12 @@ public:
QmlGraphicsTextPrivate()
: color((QRgb)0), style(QmlGraphicsText::Normal), imgDirty(true),
hAlign(QmlGraphicsText::AlignLeft), vAlign(QmlGraphicsText::AlignTop), elideMode(QmlGraphicsText::ElideNone),
- dirty(true), wrap(false), richText(false), singleline(false), doc(0),
+ dirty(true), wrap(false), richText(false), singleline(false), cache(true), doc(0),
format(QmlGraphicsText::AutoText)
{
+#ifdef QML_NO_TEXT_CACHE
+ cache = false;
+#endif
}
~QmlGraphicsTextPrivate();
@@ -93,6 +96,7 @@ public:
void drawOutline(int yOffset);
QPixmap wrappedTextImage(bool drawStyle);
+ void drawWrappedText(QPainter *p, const QPointF &pos, bool drawStyle);
QPixmap richTextImage(bool drawStyle);
QSize setupTextLayout(QTextLayout *layout);
@@ -112,6 +116,7 @@ public:
bool wrap:1;
bool richText:1;
bool singleline:1;
+ bool cache:1;
QTextDocument *doc;
QTextLayout layout;
QSize cachedLayoutSize;