diff options
author | Maximilian Goldstein <max.goldstein@qt.io> | 2020-04-08 14:35:21 +0200 |
---|---|---|
committer | Maximilian Goldstein <max.goldstein@qt.io> | 2020-04-14 14:46:19 +0200 |
commit | 53aa259d57e92f48585f95b47a25ee6e16fc2aaa (patch) | |
tree | b3e27b6ee5ca5b8fdfb4d1e084e50ebd151fc0bc /tests/auto/qml/qqmlqt/tst_qqmlqt.cpp | |
parent | 27748dec471a9c9825f5a35d1936bb5d00400b5b (diff) |
Implement Qt.alpha()
Introduces an easy way to get a version of a color with transparency
(e.g. Qt.alpha("red", 0.5)).
[ChangeLog][QML][General] Added Qt.alpha for easily modifying a color's alpha value
Task-number: QTBUG-77635
Change-Id: Ic724e5fa503ca2ae5157a99eed1b5c913a39239f
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'tests/auto/qml/qqmlqt/tst_qqmlqt.cpp')
-rw-r--r-- | tests/auto/qml/qqmlqt/tst_qqmlqt.cpp | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlqt/tst_qqmlqt.cpp b/tests/auto/qml/qqmlqt/tst_qqmlqt.cpp index 6c93b46167..da33a46c68 100644 --- a/tests/auto/qml/qqmlqt/tst_qqmlqt.cpp +++ b/tests/auto/qml/qqmlqt/tst_qqmlqt.cpp @@ -79,6 +79,7 @@ private slots: void font(); void lighter(); void darker(); + void alpha(); void tint(); void color(); void openUrlExternally(); @@ -543,6 +544,37 @@ void tst_qqmlqt::darker() QCOMPARE(qvariant_cast<QColor>(object->property("test6")), QColor()); } +void tst_qqmlqt::alpha() +{ + QQmlComponent component(&engine, testFileUrl("alpha.qml")); + + QString warning1 = component.url().toString() + ":5: Error: Qt.alpha(): Wrong number of arguments provided"; + QString warning2 = component.url().toString() + ":10: Error: Qt.alpha(): Wrong number of arguments provided"; + QTest::ignoreMessage(QtWarningMsg, qPrintable(warning1)); + QTest::ignoreMessage(QtWarningMsg, qPrintable(warning2)); + + QScopedPointer<QObject> object(component.create()); + QVERIFY(object != nullptr); + + QCOMPARE(qvariant_cast<QColor>(object->property("test1")), + QColor::fromRgbF(1.0, 0.8, 0.3, 0.5)); + QCOMPARE(qvariant_cast<QColor>(object->property("testColor1")), + QColor::fromRgbF(1, 0.8, 0.3, 0.5)); + QCOMPARE(qvariant_cast<QColor>(object->property("test2")), QColor()); + QCOMPARE(qvariant_cast<QColor>(object->property("test3")), + QColor::fromRgbF(1.0, 0.8, 0.3, 0.7)); + QCOMPARE(qvariant_cast<QColor>(object->property("testColor3")), + QColor::fromRgbF(1, 0.8, 0.3, 0.7)); + + QColor alphaRed = QColor("red"); + alphaRed.setAlphaF(0.5); + + QCOMPARE(qvariant_cast<QColor>(object->property("test4")), alphaRed); + QCOMPARE(qvariant_cast<QColor>(object->property("testColor4")), alphaRed); + QCOMPARE(qvariant_cast<QColor>(object->property("test5")), QColor()); + QCOMPARE(qvariant_cast<QColor>(object->property("test6")), QColor()); +} + void tst_qqmlqt::tint() { QQmlComponent component(&engine, testFileUrl("tint.qml")); |