summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/quick/items/qquicktext.cpp88
-rw-r--r--src/quick/items/qquicktext_p.h4
-rw-r--r--src/quick/items/qquicktext_p_p.h82
-rw-r--r--tests/auto/qtquick2/qquicktext/tst_qquicktext.cpp9
4 files changed, 95 insertions, 88 deletions
diff --git a/src/quick/items/qquicktext.cpp b/src/quick/items/qquicktext.cpp
index ce030938a9..6f8aa383cd 100644
--- a/src/quick/items/qquicktext.cpp
+++ b/src/quick/items/qquicktext.cpp
@@ -71,21 +71,21 @@ QT_BEGIN_NAMESPACE
const QChar QQuickTextPrivate::elideChar = QChar(0x2026);
QQuickTextPrivate::QQuickTextPrivate()
-: color((QRgb)0), linkColor((QRgb)255), style(QQuickText::Normal), hAlign(QQuickText::AlignLeft),
- vAlign(QQuickText::AlignTop), elideMode(QQuickText::ElideNone),
- format(QQuickText::AutoText), wrapMode(QQuickText::NoWrap), lineHeight(1),
- lineHeightMode(QQuickText::ProportionalHeight), lineCount(1), maximumLineCount(INT_MAX),
- maximumLineCountValid(false), fontSizeMode(QQuickText::FixedSize), multilengthEos(-1),
- minimumPixelSize(12), minimumPointSize(12), updateOnComponentComplete(true),
- richText(false), styledText(false), singleline(false), internalWidthUpdate(false),
- requireImplicitWidth(false), truncated(false), hAlignImplicit(true), rightToLeftText(false),
- layoutTextElided(false), textHasChanged(true),
- needToUpdateLayout(false), naturalWidth(0), doc(0), elideLayout(0), textLine(0),
- updateType(UpdatePaintNode), nbActiveDownloads(0)
-
+ : lineHeight(1)
+ , elideLayout(0), textLine(0), doc(0)
#if defined(Q_OS_MAC)
-, layoutThread(0), paintingThread(0)
+ , layoutThread(0), paintingThread(0)
#endif
+ , color(0xFF000000), linkColor(0xFF0000FF), styleColor(0xFF000000)
+ , lineCount(1), maximumLineCount(INT_MAX), multilengthEos(-1), minimumPixelSize(12), minimumPointSize(12), nbActiveDownloads(0)
+ , hAlign(QQuickText::AlignLeft), vAlign(QQuickText::AlignTop), elideMode(QQuickText::ElideNone)
+ , format(QQuickText::AutoText), wrapMode(QQuickText::NoWrap)
+ , lineHeightMode(QQuickText::ProportionalHeight), style(QQuickText::Normal)
+ , fontSizeMode(QQuickText::FixedSize), updateType(UpdatePaintNode)
+ , maximumLineCountValid(false), updateOnComponentComplete(true), richText(false)
+ , styledText(false), singleline(false), internalWidthUpdate(false), requireImplicitWidth(false)
+ , truncated(false), hAlignImplicit(true), rightToLeftText(false)
+ , layoutTextElided(false), textHasChanged(true), needToUpdateLayout(false)
{
}
@@ -378,23 +378,25 @@ void QQuickTextPrivate::updateSize()
if (text.isEmpty()) {
qreal fontHeight = fm.height();
q->setImplicitSize(0, fontHeight);
- contentSize = QSize(0, fontHeight);
+ layedOutTextRect = QRect(0, 0, 0, fontHeight);
emit q->contentSizeChanged();
updateType = UpdatePaintNode;
q->update();
return;
}
+ qreal naturalWidth = 0;
+
int dy = q->height();
QSize size(0, 0);
-
+ QSize previousSize = layedOutTextRect.size();
#if defined(Q_OS_MAC)
layoutThread = QThread::currentThread();
#endif
//setup instance of QTextLayout for all cases other than richtext
if (!richText) {
- QRect textRect = setupTextLayout();
+ QRect textRect = setupTextLayout(&naturalWidth);
layedOutTextRect = textRect;
size = textRect.size();
dy -= size.height();
@@ -450,10 +452,8 @@ void QQuickTextPrivate::updateSize()
if (iWidth == -1)
q->setImplicitHeight(size.height());
- if (contentSize != size) {
- contentSize = size;
+ if (layedOutTextRect.size() != previousSize)
emit q->contentSizeChanged();
- }
updateType = UpdatePaintNode;
q->update();
}
@@ -618,7 +618,7 @@ QString QQuickTextPrivate::elidedText(int lineWidth, const QTextLine &line, QTex
already absolutely positioned horizontally).
*/
-QRect QQuickTextPrivate::setupTextLayout()
+QRect QQuickTextPrivate::setupTextLayout(qreal *const naturalWidth)
{
Q_Q(QQuickText);
layout.setCacheEnabled(true);
@@ -652,7 +652,7 @@ QRect QQuickTextPrivate::setupTextLayout()
break;
}
layout.endLayout();
- naturalWidth = layout.maximumWidth();
+ *naturalWidth = layout.maximumWidth();
layout.clearLayout();
}
@@ -695,7 +695,7 @@ QRect QQuickTextPrivate::setupTextLayout()
QString elideText;
bool once = true;
- naturalWidth = 0;
+ *naturalWidth = 0;
int eos = multilengthEos;
@@ -815,7 +815,7 @@ QRect QQuickTextPrivate::setupTextLayout()
// Save the implicitWidth of the text on the first layout only.
if (once) {
- naturalWidth = layout.maximumWidth();
+ *naturalWidth = layout.maximumWidth();
once = false;
if (requireImplicitWidth
@@ -831,7 +831,7 @@ QRect QQuickTextPrivate::setupTextLayout()
if (!line.isValid())
break;
}
- naturalWidth = qMax(naturalWidth, widthLayout.maximumWidth());
+ *naturalWidth = qMax(*naturalWidth, widthLayout.maximumWidth());
}
}
@@ -1322,21 +1322,22 @@ void QQuickText::setText(const QString &n)
QColor QQuickText::color() const
{
Q_D(const QQuickText);
- return d->color;
+ return QColor::fromRgba(d->color);
}
void QQuickText::setColor(const QColor &color)
{
Q_D(QQuickText);
- if (d->color == color)
+ QRgb rgb = color.rgba();
+ if (d->color == rgb)
return;
- d->color = color;
+ d->color = rgb;
if (isComponentComplete()) {
d->updateType = QQuickTextPrivate::UpdatePaintNode;
update();
}
- emit colorChanged(d->color);
+ emit colorChanged();
}
/*!
@@ -1352,16 +1353,17 @@ void QQuickText::setColor(const QColor &color)
QColor QQuickText::linkColor() const
{
Q_D(const QQuickText);
- return d->linkColor;
+ return QColor::fromRgba(d->linkColor);
}
void QQuickText::setLinkColor(const QColor &color)
{
Q_D(QQuickText);
- if (d->linkColor == color)
+ QRgb rgb = color.rgba();
+ if (d->linkColor == rgb)
return;
- d->linkColor = color;
+ d->linkColor = rgb;
update();
emit linkColorChanged();
}
@@ -1428,21 +1430,22 @@ void QQuickText::setStyle(QQuickText::TextStyle style)
QColor QQuickText::styleColor() const
{
Q_D(const QQuickText);
- return d->styleColor;
+ return QColor::fromRgba(d->styleColor);
}
void QQuickText::setStyleColor(const QColor &color)
{
Q_D(QQuickText);
- if (d->styleColor == color)
+ QRgb rgb = color.rgba();
+ if (d->styleColor == rgb)
return;
- d->styleColor = color;
+ d->styleColor = rgb;
if (isComponentComplete()) {
d->updateType = QQuickTextPrivate::UpdatePaintNode;
update();
}
- emit styleColorChanged(d->styleColor);
+ emit styleColorChanged();
}
/*!
@@ -1662,7 +1665,6 @@ void QQuickText::resetMaximumLineCount()
{
Q_D(QQuickText);
setMaximumLineCount(INT_MAX);
- d->elidePos = QPointF();
if (d->truncated != false) {
d->truncated = false;
emit truncatedChanged();
@@ -1993,13 +1995,17 @@ QSGNode *QQuickText::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *data
node->deleteContent();
node->setMatrix(QMatrix4x4());
+ const QColor color = QColor::fromRgba(d->color);
+ const QColor styleColor = QColor::fromRgba(d->styleColor);
+ const QColor linkColor = QColor::fromRgba(d->linkColor);
+
if (d->richText) {
d->ensureDoc();
- node->addTextDocument(bounds.topLeft(), d->doc, d->color, d->style, d->styleColor, d->linkColor);
+ node->addTextDocument(bounds.topLeft(), d->doc, color, d->style, styleColor, linkColor);
} else if (d->elideMode == QQuickText::ElideNone || bounds.width() > 0.) {
- node->addTextLayout(QPoint(0, bounds.y()), &d->layout, d->color, d->style, d->styleColor, d->linkColor);
+ node->addTextLayout(QPoint(0, bounds.y()), &d->layout, color, d->style, styleColor, linkColor);
if (d->elideLayout)
- node->addTextLayout(QPoint(0, bounds.y()), d->elideLayout, d->color, d->style, d->styleColor, d->linkColor);
+ node->addTextLayout(QPoint(0, bounds.y()), d->elideLayout, color, d->style, styleColor, linkColor);
}
foreach (QDeclarativeStyledTextImgTag *img, d->visibleImgTags) {
@@ -2028,7 +2034,7 @@ void QQuickText::updatePolish()
qreal QQuickText::contentWidth() const
{
Q_D(const QQuickText);
- return d->contentSize.width();
+ return d->layedOutTextRect.width();
}
/*!
@@ -2040,7 +2046,7 @@ qreal QQuickText::contentWidth() const
qreal QQuickText::contentHeight() const
{
Q_D(const QQuickText);
- return d->contentSize.height();
+ return d->layedOutTextRect.height();
}
/*!
diff --git a/src/quick/items/qquicktext_p.h b/src/quick/items/qquicktext_p.h
index 2276773d27..37287b5445 100644
--- a/src/quick/items/qquicktext_p.h
+++ b/src/quick/items/qquicktext_p.h
@@ -203,10 +203,10 @@ Q_SIGNALS:
void textChanged(const QString &text);
void linkActivated(const QString &link);
void fontChanged(const QFont &font);
- void colorChanged(const QColor &color);
+ void colorChanged();
void linkColorChanged();
void styleChanged(TextStyle style);
- void styleColorChanged(const QColor &color);
+ void styleColorChanged();
void horizontalAlignmentChanged(HAlignment alignment);
void verticalAlignmentChanged(VAlignment alignment);
void wrapModeChanged();
diff --git a/src/quick/items/qquicktext_p_p.h b/src/quick/items/qquicktext_p_p.h
index 8a9452a2d2..555f41ff94 100644
--- a/src/quick/items/qquicktext_p_p.h
+++ b/src/quick/items/qquicktext_p_p.h
@@ -84,33 +84,57 @@ public:
void setLineGeometry(QTextLine &line, qreal lineWidth, qreal &height);
QString elidedText(int lineWidth, const QTextLine &line, QTextLine *nextLine = 0) const;
+ QRect layedOutTextRect;
+
+ qreal lineHeight;
+
QString text;
+ QString activeLink;
QUrl baseUrl;
QFont font;
QFont sourceFont;
- QColor color;
- QColor linkColor;
- QQuickText::TextStyle style;
- QColor styleColor;
- QString activeLink;
+ QList<QDeclarativeStyledTextImgTag*> imgTags;
+ QList<QDeclarativeStyledTextImgTag*> visibleImgTags;
+
+ QTextLayout layout;
+ QTextLayout *elideLayout;
+ QQuickTextLine *textLine;
+ QQuickTextDocumentWithImageResources *doc;
+
+#if defined(Q_OS_MAC)
+ QList<QRectF> linesRects;
+ QThread *layoutThread;
+ QThread *paintingThread;
+#endif
+
+ QRgb color;
+ QRgb linkColor;
+ QRgb styleColor;
+
+ int lineCount;
+ int maximumLineCount;
+ int multilengthEos;
+ int minimumPixelSize;
+ int minimumPointSize;
+ int nbActiveDownloads;
+
+ enum UpdateType {
+ UpdateNone,
+ UpdatePreprocess,
+ UpdatePaintNode
+ };
+
QQuickText::HAlignment hAlign;
QQuickText::VAlignment vAlign;
QQuickText::TextElideMode elideMode;
QQuickText::TextFormat format;
QQuickText::WrapMode wrapMode;
- qreal lineHeight;
QQuickText::LineHeightMode lineHeightMode;
- int lineCount;
- int maximumLineCount;
- int maximumLineCountValid;
+ QQuickText::TextStyle style;
QQuickText::FontSizeMode fontSizeMode;
- int multilengthEos;
- int minimumPixelSize;
- int minimumPointSize;
- QPointF elidePos;
-
- static const QChar elideChar;
+ UpdateType updateType;
+ bool maximumLineCountValid:1;
bool updateOnComponentComplete:1;
bool updateLayoutOnPolish:1;
bool richText:1;
@@ -125,42 +149,20 @@ public:
bool textHasChanged:1;
bool needToUpdateLayout:1;
- QRect layedOutTextRect;
- QSize contentSize;
- qreal naturalWidth;
+ static const QChar elideChar;
+
virtual qreal getImplicitWidth() const;
void ensureDoc();
- QQuickTextDocumentWithImageResources *doc;
- QRect setupTextLayout();
+ QRect setupTextLayout(qreal *const naturalWidth);
void setupCustomLineGeometry(QTextLine &line, qreal &height, int lineOffset = 0);
bool isLinkActivatedConnected();
QString anchorAt(const QPointF &pos);
- QTextLayout layout;
- QTextLayout *elideLayout;
- QQuickTextLine *textLine;
static inline QQuickTextPrivate *get(QQuickText *t) {
return t->d_func();
}
-
- enum UpdateType {
- UpdateNone,
- UpdatePreprocess,
- UpdatePaintNode
- };
- UpdateType updateType;
-
- QList<QDeclarativeStyledTextImgTag*> imgTags;
- QList<QDeclarativeStyledTextImgTag*> visibleImgTags;
- int nbActiveDownloads;
-
-#if defined(Q_OS_MAC)
- QList<QRectF> linesRects;
- QThread *layoutThread;
- QThread *paintingThread;
-#endif
};
class QDeclarativePixmap;
diff --git a/tests/auto/qtquick2/qquicktext/tst_qquicktext.cpp b/tests/auto/qtquick2/qquicktext/tst_qquicktext.cpp
index cbe3d30cbb..d1c0f765d0 100644
--- a/tests/auto/qtquick2/qquicktext/tst_qquicktext.cpp
+++ b/tests/auto/qtquick2/qquicktext/tst_qquicktext.cpp
@@ -905,7 +905,7 @@ void tst_qquicktext::color()
QQuickText *textObject = qobject_cast<QQuickText*>(textComponent.create());
QCOMPARE(textObject->color(), QColor(colorStrings.at(i)));
- QCOMPARE(textObject->styleColor(), QColor());
+ QCOMPARE(textObject->styleColor(), QColor("black"));
QCOMPARE(textObject->linkColor(), QColor("blue"));
delete textObject;
@@ -933,8 +933,7 @@ void tst_qquicktext::color()
textComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
QQuickText *textObject = qobject_cast<QQuickText*>(textComponent.create());
- QCOMPARE(textObject->styleColor(), QColor());
- // default color to black?
+ QCOMPARE(textObject->styleColor(), QColor("black"));
QCOMPARE(textObject->color(), QColor("black"));
QCOMPARE(textObject->linkColor(), QColor(colorStrings.at(i)));
@@ -984,7 +983,7 @@ void tst_qquicktext::color()
QScopedPointer<QObject> object(textComponent.create());
QQuickText *textObject = qobject_cast<QQuickText*>(object.data());
- QSignalSpy spy(textObject, SIGNAL(colorChanged(QColor)));
+ QSignalSpy spy(textObject, SIGNAL(colorChanged()));
QCOMPARE(textObject->color(), testColor);
textObject->setColor(testColor);
@@ -1005,7 +1004,7 @@ void tst_qquicktext::color()
QScopedPointer<QObject> object(textComponent.create());
QQuickText *textObject = qobject_cast<QQuickText*>(object.data());
- QSignalSpy spy(textObject, SIGNAL(styleColorChanged(QColor)));
+ QSignalSpy spy(textObject, SIGNAL(styleColorChanged()));
QCOMPARE(textObject->styleColor(), testColor);
textObject->setStyleColor(testColor);