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 | |
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')
-rw-r--r-- | tests/auto/qml/qqmlqt/data/alpha.qml | 16 | ||||
-rw-r--r-- | tests/auto/qml/qqmlqt/tst_qqmlqt.cpp | 32 |
2 files changed, 48 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlqt/data/alpha.qml b/tests/auto/qml/qqmlqt/data/alpha.qml new file mode 100644 index 0000000000..0587f60bc6 --- /dev/null +++ b/tests/auto/qml/qqmlqt/data/alpha.qml @@ -0,0 +1,16 @@ +import QtQuick 2.0 + +QtObject { + property variant test1: Qt.alpha(Qt.rgba(1, 0.8, 0.3), 0.5) + property variant test2: Qt.alpha() + property variant test3: Qt.alpha(Qt.rgba(1, 0.8, 0.3), 0.7) + property variant test4: Qt.alpha("red", 0.5); + property variant test5: Qt.alpha("perfectred", 0.5); // Non-existent color + property variant test6: Qt.alpha(1, 0.5); + property variant test7: Qt.alpha(Qt.rgba(1, 0.8, 0.3), 2.8, 10) + + property variant testColor1: Qt.rgba(1, 0.8, 0.3).alpha(0.5) + property variant testColor3: Qt.rgba(1, 0.8, 0.3).alpha(0.7) + property variant testColor4: Qt.color("red").alpha(0.5); + property variant testColor7: Qt.rgba(1, 0.8, 0.3).alpha(2.8, 10); +} 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")); |