aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/items/qquicktext.cpp
diff options
context:
space:
mode:
authorAndrew den Exter <andrew.den-exter@nokia.com>2012-02-09 16:14:40 +1000
committerQt by Nokia <qt-info@nokia.com>2012-02-09 09:10:31 +0100
commit8550ed69156f0472450fd11aabcaa5d4dcc676db (patch)
tree91b1d6848e1ce5199db4040decb4a3cd79352788 /src/quick/items/qquicktext.cpp
parenta4b4932efb631a3c467c9bb4b3e4f99ca70a066d (diff)
Add linkColor property to Text.
Allows the color of links in text to be changed from the default blue. This currently only works with StyledText and the distance field rendererer. It could be made to work with RichText overwriting the specified foreground color in all instances or by not setting a default color in the html parser. The former would prevent the color being set with CSS or some future means for altering text formats. The latter would break rendering with QPainter. Task-number: QTBUG-23048 Change-Id: I98df215cabe8a089f648fd4a6206622b4318fb8f Reviewed-by: Martin Jones <martin.jones@nokia.com>
Diffstat (limited to 'src/quick/items/qquicktext.cpp')
-rw-r--r--src/quick/items/qquicktext.cpp37
1 files changed, 32 insertions, 5 deletions
diff --git a/src/quick/items/qquicktext.cpp b/src/quick/items/qquicktext.cpp
index 14016777c1..c671320fb9 100644
--- a/src/quick/items/qquicktext.cpp
+++ b/src/quick/items/qquicktext.cpp
@@ -71,7 +71,7 @@ QT_BEGIN_NAMESPACE
const QChar QQuickTextPrivate::elideChar = QChar(0x2026);
QQuickTextPrivate::QQuickTextPrivate()
-: color((QRgb)0), style(QQuickText::Normal), hAlign(QQuickText::AlignLeft),
+: 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),
@@ -1279,6 +1279,34 @@ void QQuickText::setColor(const QColor &color)
}
emit colorChanged(d->color);
}
+
+/*!
+ \qmlproperty color QtQuick2::Text::linkColor
+
+ The color of links in the text.
+
+ This property works with the StyledText \l textFormat, but not with RichText.
+ Link color in RichText can be specified by including CSS style tags in the
+ text.
+*/
+
+QColor QQuickText::linkColor() const
+{
+ Q_D(const QQuickText);
+ return d->linkColor;
+}
+
+void QQuickText::setLinkColor(const QColor &color)
+{
+ Q_D(QQuickText);
+ if (d->linkColor == color)
+ return;
+
+ d->linkColor = color;
+ update();
+ emit linkColorChanged();
+}
+
/*!
\qmlproperty enumeration QtQuick2::Text::style
@@ -1894,12 +1922,11 @@ QSGNode *QQuickText::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *data
if (d->richText) {
d->ensureDoc();
- node->addTextDocument(bounds.topLeft(), d->doc, d->color, d->style, d->styleColor);
-
+ node->addTextDocument(bounds.topLeft(), d->doc, d->color, d->style, d->styleColor, d->linkColor);
} else if (d->elideMode == QQuickText::ElideNone || bounds.width() > 0.) {
- node->addTextLayout(QPoint(0, bounds.y()), &d->layout, d->color, d->style, d->styleColor);
+ node->addTextLayout(QPoint(0, bounds.y()), &d->layout, d->color, d->style, d->styleColor, d->linkColor);
if (d->elideLayout)
- node->addTextLayout(QPoint(0, bounds.y()), d->elideLayout, d->color, d->style, d->styleColor);
+ node->addTextLayout(QPoint(0, bounds.y()), d->elideLayout, d->color, d->style, d->styleColor, d->linkColor);
}
foreach (QDeclarativeStyledTextImgTag *img, d->visibleImgTags) {