From 8550ed69156f0472450fd11aabcaa5d4dcc676db Mon Sep 17 00:00:00 2001 From: Andrew den Exter Date: Thu, 9 Feb 2012 16:14:40 +1000 Subject: 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 --- tests/auto/qtquick2/qquicktext/tst_qquicktext.cpp | 87 ++++++++++++++++++++++- 1 file changed, 86 insertions(+), 1 deletion(-) (limited to 'tests/auto') diff --git a/tests/auto/qtquick2/qquicktext/tst_qquicktext.cpp b/tests/auto/qtquick2/qquicktext/tst_qquicktext.cpp index 8e3a1f4864..5a0086393c 100644 --- a/tests/auto/qtquick2/qquicktext/tst_qquicktext.cpp +++ b/tests/auto/qtquick2/qquicktext/tst_qquicktext.cpp @@ -904,6 +904,7 @@ void tst_qquicktext::color() QCOMPARE(textObject->color(), QColor(colorStrings.at(i))); QCOMPARE(textObject->styleColor(), QColor()); + QCOMPARE(textObject->linkColor(), QColor("blue")); delete textObject; } @@ -918,6 +919,22 @@ void tst_qquicktext::color() QCOMPARE(textObject->styleColor(), QColor(colorStrings.at(i))); // default color to black? QCOMPARE(textObject->color(), QColor("black")); + QCOMPARE(textObject->linkColor(), QColor("blue")); + + delete textObject; + } + + for (int i = 0; i < colorStrings.size(); i++) + { + QString componentStr = "import QtQuick 2.0\nText { linkColor: \"" + colorStrings.at(i) + "\"; text: \"Hello World\" }"; + QDeclarativeComponent textComponent(&engine); + textComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile("")); + QQuickText *textObject = qobject_cast(textComponent.create()); + + QCOMPARE(textObject->styleColor(), QColor()); + // default color to black? + QCOMPARE(textObject->color(), QColor("black")); + QCOMPARE(textObject->linkColor(), QColor(colorStrings.at(i))); delete textObject; } @@ -926,13 +943,18 @@ void tst_qquicktext::color() { for (int j = 0; j < colorStrings.size(); j++) { - QString componentStr = "import QtQuick 2.0\nText { color: \"" + colorStrings.at(i) + "\"; styleColor: \"" + colorStrings.at(j) + "\"; text: \"Hello World\" }"; + QString componentStr = "import QtQuick 2.0\nText { " + "color: \"" + colorStrings.at(i) + "\"; " + "styleColor: \"" + colorStrings.at(j) + "\"; " + "linkColor: \"" + colorStrings.at(j) + "\"; " + "text: \"Hello World\" }"; QDeclarativeComponent textComponent(&engine); textComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile("")); QQuickText *textObject = qobject_cast(textComponent.create()); QCOMPARE(textObject->color(), QColor(colorStrings.at(i))); QCOMPARE(textObject->styleColor(), QColor(colorStrings.at(j))); + QCOMPARE(textObject->linkColor(), QColor(colorStrings.at(j))); delete textObject; } @@ -950,6 +972,69 @@ void tst_qquicktext::color() QCOMPARE(textObject->color(), testColor); delete textObject; + } { + QString colorStr = "#001234"; + QColor testColor(colorStr); + + QString componentStr = "import QtQuick 2.0\nText { color: \"" + colorStr + "\"; text: \"Hello World\" }"; + QDeclarativeComponent textComponent(&engine); + textComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile("")); + QScopedPointer object(textComponent.create()); + QQuickText *textObject = qobject_cast(object.data()); + + QSignalSpy spy(textObject, SIGNAL(colorChanged(QColor))); + + QCOMPARE(textObject->color(), testColor); + textObject->setColor(testColor); + QCOMPARE(textObject->color(), testColor); + QCOMPARE(spy.count(), 0); + + testColor = QColor("black"); + textObject->setColor(testColor); + QCOMPARE(textObject->color(), testColor); + QCOMPARE(spy.count(), 1); + } { + QString colorStr = "#001234"; + QColor testColor(colorStr); + + QString componentStr = "import QtQuick 2.0\nText { styleColor: \"" + colorStr + "\"; text: \"Hello World\" }"; + QDeclarativeComponent textComponent(&engine); + textComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile("")); + QScopedPointer object(textComponent.create()); + QQuickText *textObject = qobject_cast(object.data()); + + QSignalSpy spy(textObject, SIGNAL(styleColorChanged(QColor))); + + QCOMPARE(textObject->styleColor(), testColor); + textObject->setStyleColor(testColor); + QCOMPARE(textObject->styleColor(), testColor); + QCOMPARE(spy.count(), 0); + + testColor = QColor("black"); + textObject->setStyleColor(testColor); + QCOMPARE(textObject->styleColor(), testColor); + QCOMPARE(spy.count(), 1); + } { + QString colorStr = "#001234"; + QColor testColor(colorStr); + + QString componentStr = "import QtQuick 2.0\nText { linkColor: \"" + colorStr + "\"; text: \"Hello World\" }"; + QDeclarativeComponent textComponent(&engine); + textComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile("")); + QScopedPointer object(textComponent.create()); + QQuickText *textObject = qobject_cast(object.data()); + + QSignalSpy spy(textObject, SIGNAL(linkColorChanged())); + + QCOMPARE(textObject->linkColor(), testColor); + textObject->setLinkColor(testColor); + QCOMPARE(textObject->linkColor(), testColor); + QCOMPARE(spy.count(), 0); + + testColor = QColor("black"); + textObject->setLinkColor(testColor); + QCOMPARE(textObject->linkColor(), testColor); + QCOMPARE(spy.count(), 1); } } -- cgit v1.2.3