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)
{
}
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();
if (iWidth == -1)
q->setImplicitHeight(size.height());
- if (contentSize != size) {
- contentSize = size;
+ if (layedOutTextRect.size() != previousSize)
emit q->contentSizeChanged();
- }
updateType = UpdatePaintNode;
q->update();
}
already absolutely positioned horizontally).
*/
-QRect QQuickTextPrivate::setupTextLayout()
+QRect QQuickTextPrivate::setupTextLayout(qreal *const naturalWidth)
{
Q_Q(QQuickText);
layout.setCacheEnabled(true);
break;
}
layout.endLayout();
- naturalWidth = layout.maximumWidth();
+ *naturalWidth = layout.maximumWidth();
layout.clearLayout();
}
QString elideText;
bool once = true;
- naturalWidth = 0;
+ *naturalWidth = 0;
int eos = multilengthEos;
// Save the implicitWidth of the text on the first layout only.
if (once) {
- naturalWidth = layout.maximumWidth();
+ *naturalWidth = layout.maximumWidth();
once = false;
if (requireImplicitWidth
if (!line.isValid())
break;
}
- naturalWidth = qMax(naturalWidth, widthLayout.maximumWidth());
+ *naturalWidth = qMax(*naturalWidth, widthLayout.maximumWidth());
}
}
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();
}
/*!
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();
}
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();
}
/*!
{
Q_D(QQuickText);
setMaximumLineCount(INT_MAX);
- d->elidePos = QPointF();
if (d->truncated != false) {
d->truncated = false;
emit truncatedChanged();
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) {
qreal QQuickText::contentWidth() const
{
Q_D(const QQuickText);
- return d->contentSize.width();
+ return d->layedOutTextRect.width();
}
/*!
qreal QQuickText::contentHeight() const
{
Q_D(const QQuickText);
- return d->contentSize.height();
+ return d->layedOutTextRect.height();
}
/*!
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;
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;
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;
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)));
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);
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);