aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qqmlqt/tst_qqmlqt.cpp
diff options
context:
space:
mode:
authorMaximilian Goldstein <max.goldstein@qt.io>2020-03-27 13:58:13 +0100
committerMaximilian Goldstein <max.goldstein@qt.io>2020-04-02 09:26:40 +0100
commit19850f129881a04c36c51859454bf71ed688f28a (patch)
tree710468d765071c2cffd983a9165b36feae5346e6 /tests/auto/qml/qqmlqt/tst_qqmlqt.cpp
parentb3d28f72862433f54033d1b744715a5699c1ee59 (diff)
Implement modifying colors using methods
Instead of having to use Qt.tint, Qt.lighter or Qt.lighter you can now directly use these on colors (e.g. color.tint("red")). Also adds Qt.color to explicitly convert color strings into actual color objects. [ChangeLog][QML][General] Added Qt.color to turn color strings into color objects [ChangeLog][Quick][General] Make Qt.tint, Qt.lighter and Qt.darker methods that can directly operate on color objects Task-number: QTBUG-77635 Change-Id: Ie10ced7ba7f1dc10afdebbcbc8664d74cd6efccf Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'tests/auto/qml/qqmlqt/tst_qqmlqt.cpp')
-rw-r--r--tests/auto/qml/qqmlqt/tst_qqmlqt.cpp40
1 files changed, 40 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlqt/tst_qqmlqt.cpp b/tests/auto/qml/qqmlqt/tst_qqmlqt.cpp
index 60ee2a4d1c..6c93b46167 100644
--- a/tests/auto/qml/qqmlqt/tst_qqmlqt.cpp
+++ b/tests/auto/qml/qqmlqt/tst_qqmlqt.cpp
@@ -80,6 +80,7 @@ private slots:
void lighter();
void darker();
void tint();
+ void color();
void openUrlExternally();
void openUrlExternally_pragmaLibrary();
void md5();
@@ -505,9 +506,14 @@ void tst_qqmlqt::lighter()
QVERIFY(object != nullptr);
QCOMPARE(qvariant_cast<QColor>(object->property("test1")), QColor::fromRgbF(1, 0.8, 0.3).lighter());
+ QCOMPARE(qvariant_cast<QColor>(object->property("testColor1")),
+ QColor::fromRgbF(1, 0.8, 0.3).lighter());
QCOMPARE(qvariant_cast<QColor>(object->property("test2")), QColor());
QCOMPARE(qvariant_cast<QColor>(object->property("test3")), QColor::fromRgbF(1, 0.8, 0.3).lighter(180));
+ QCOMPARE(qvariant_cast<QColor>(object->property("testColor3")),
+ QColor::fromRgbF(1, 0.8, 0.3).lighter(180));
QCOMPARE(qvariant_cast<QColor>(object->property("test4")), QColor("red").lighter());
+ QCOMPARE(qvariant_cast<QColor>(object->property("testColor4")), QColor("red").lighter());
QCOMPARE(qvariant_cast<QColor>(object->property("test5")), QColor());
QCOMPARE(qvariant_cast<QColor>(object->property("test6")), QColor());
}
@@ -525,9 +531,14 @@ void tst_qqmlqt::darker()
QVERIFY(object != nullptr);
QCOMPARE(qvariant_cast<QColor>(object->property("test1")), QColor::fromRgbF(1, 0.8, 0.3).darker());
+ QCOMPARE(qvariant_cast<QColor>(object->property("testColor1")),
+ QColor::fromRgbF(1, 0.8, 0.3).darker());
QCOMPARE(qvariant_cast<QColor>(object->property("test2")), QColor());
QCOMPARE(qvariant_cast<QColor>(object->property("test3")), QColor::fromRgbF(1, 0.8, 0.3).darker(280));
+ QCOMPARE(qvariant_cast<QColor>(object->property("testColor3")),
+ QColor::fromRgbF(1, 0.8, 0.3).darker(280));
QCOMPARE(qvariant_cast<QColor>(object->property("test4")), QColor("red").darker());
+ QCOMPARE(qvariant_cast<QColor>(object->property("testColor4")), QColor("red").darker());
QCOMPARE(qvariant_cast<QColor>(object->property("test5")), QColor());
QCOMPARE(qvariant_cast<QColor>(object->property("test6")), QColor());
}
@@ -538,19 +549,48 @@ void tst_qqmlqt::tint()
QString warning1 = component.url().toString() + ":7: Error: Qt.tint(): Invalid arguments";
QString warning2 = component.url().toString() + ":8: Error: Qt.tint(): Invalid arguments";
+ QString warning3 = component.url().toString() + ":13: Error: Insufficient arguments";
QTest::ignoreMessage(QtWarningMsg, qPrintable(warning1));
QTest::ignoreMessage(QtWarningMsg, qPrintable(warning2));
+ QTest::ignoreMessage(QtWarningMsg, qPrintable(warning3));
QScopedPointer<QObject> object(component.create());
QVERIFY(object != nullptr);
QCOMPARE(qvariant_cast<QColor>(object->property("test1")), QColor::fromRgbF(0, 0, 1));
+ QCOMPARE(qvariant_cast<QColor>(object->property("testColor1")), QColor::fromRgbF(0, 0, 1));
QCOMPARE(qvariant_cast<QColor>(object->property("test2")), QColor::fromRgbF(1, 0, 0));
+ QCOMPARE(qvariant_cast<QColor>(object->property("testColor2")), QColor::fromRgbF(1, 0, 0));
QColor test3 = qvariant_cast<QColor>(object->property("test3"));
+ QColor testColor3 = qvariant_cast<QColor>(object->property("testColor3"));
QCOMPARE(test3.rgba(), 0xFF7F0080);
+ QCOMPARE(testColor3.rgba(), 0xFF7F0080);
+ QCOMPARE(qvariant_cast<QColor>(object->property("test4")), QColor());
+ QCOMPARE(qvariant_cast<QColor>(object->property("test5")), QColor());
+ QCOMPARE(qvariant_cast<QColor>(object->property("testColor5")), QColor());
+}
+
+void tst_qqmlqt::color()
+{
+ QQmlComponent component(&engine, testFileUrl("color.qml"));
+
+ QStringList warnings = { ":7: Error: Qt.color(): Argument must be a string",
+ ":8: Error: Qt.color(): Qt.color takes exactly one argument",
+ ":9: Error: Qt.color(): Qt.color takes exactly one argument" };
+
+ for (const QString &warning : warnings)
+ QTest::ignoreMessage(QtWarningMsg, qPrintable(component.url().toString() + warning));
+
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY(object != nullptr);
+
+ QCOMPARE(qvariant_cast<QColor>(object->property("test1")), QColor("red"));
+ QCOMPARE(qvariant_cast<QColor>(object->property("test2")), QColor("#ff00ff00"));
+ QCOMPARE(qvariant_cast<QColor>(object->property("test3")), QColor());
QCOMPARE(qvariant_cast<QColor>(object->property("test4")), QColor());
QCOMPARE(qvariant_cast<QColor>(object->property("test5")), QColor());
+ QCOMPARE(qvariant_cast<QColor>(object->property("test6")), QColor());
}
class MyUrlHandler : public QObject