diff options
author | Andrew den Exter <andrew.den-exter@nokia.com> | 2012-02-09 16:14:40 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-02-09 09:10:31 +0100 |
commit | 8550ed69156f0472450fd11aabcaa5d4dcc676db (patch) | |
tree | 91b1d6848e1ce5199db4040decb4a3cd79352788 /tests | |
parent | a4b4932efb631a3c467c9bb4b3e4f99ca70a066d (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 'tests')
-rw-r--r-- | tests/auto/qtquick2/qquicktext/tst_qquicktext.cpp | 87 |
1 files changed, 86 insertions, 1 deletions
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<QQuickText*>(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<QQuickText*>(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<QObject> object(textComponent.create()); + QQuickText *textObject = qobject_cast<QQuickText*>(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<QObject> object(textComponent.create()); + QQuickText *textObject = qobject_cast<QQuickText*>(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<QObject> object(textComponent.create()); + QQuickText *textObject = qobject_cast<QQuickText*>(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); } } |