#include #include #include "jkqtcommon/jkqtpcsstools.h" #include "jkqtcommon/jkqtpcachingtools.h" #ifndef QCOMPARE_EQ #define QCOMPARE_EQ(A,B) if (!static_cast((A)==(B))) {qDebug()<= QT_VERSION_CHECK(5, 12, 0)) QVERIFY_THROWS_NO_EXCEPTION(n=JKQTPCSSParser::readGradient("warmflame")); g = QGradient(QGradient::WarmFlame); g.setCoordinateMode(QGradient::ObjectBoundingMode); QCOMPARE_EQ(n, g); #endif QVERIFY_THROWS_NO_EXCEPTION(n=JKQTPCSSParser::readGradient("linear-gradient(to left, red, blue)")); lg = QLinearGradient(1,0.5,0,0.5); lg.setCoordinateMode(QGradient::ObjectBoundingMode); lg.setStops({QGradientStop(0, QColor("red")), QGradientStop(1, QColor("blue"))}); QCOMPARE_EQ(n, lg); QVERIFY_THROWS_NO_EXCEPTION(n=JKQTPCSSParser::readGradient("linear-gradient(to right, red, green 20%, blue)")); lg = QLinearGradient(0,0.5,1,0.5); lg.setCoordinateMode(QGradient::ObjectBoundingMode); lg.setStops({QGradientStop(0, QColor("red")), QGradientStop(0.2, QColor("green")), QGradientStop(1, QColor("blue"))}); QCOMPARE_EQ(n, lg); QVERIFY_THROWS_NO_EXCEPTION(n=JKQTPCSSParser::readGradient("linear-gradient(to top, red, blue)")); lg = QLinearGradient(0.5,1,0.5,0); lg.setCoordinateMode(QGradient::ObjectBoundingMode); lg.setStops({QGradientStop(0, QColor("red")), QGradientStop(1, QColor("blue"))}); QCOMPARE_EQ(n, lg); QVERIFY_THROWS_NO_EXCEPTION(n=JKQTPCSSParser::readGradient("linear-gradient(to bottom, red, blue)")); lg = QLinearGradient(0.5,0,0.5,1); lg.setCoordinateMode(QGradient::ObjectBoundingMode); lg.setStops({QGradientStop(0, QColor("red")), QGradientStop(1, QColor("blue"))}); QCOMPARE_EQ(n, lg); QVERIFY_THROWS_NO_EXCEPTION(n=JKQTPCSSParser::readGradient("linear-gradient(to bottom, rgb(255,0,0), rgb(0,0,255))")); lg = QLinearGradient(0.5,0,0.5,1); lg.setCoordinateMode(QGradient::ObjectBoundingMode); lg.setStops({QGradientStop(0, QColor("red")), QGradientStop(1, QColor("blue"))}); QCOMPARE_EQ(n, lg); QVERIFY_THROWS_NO_EXCEPTION(n=JKQTPCSSParser::readGradient("linear-gradient(to bottom, rgb(100%,0,0/90%), rgb(0,0,100%/10%))")); lg = QLinearGradient(0.5,0,0.5,1); lg.setCoordinateMode(QGradient::ObjectBoundingMode); lg.setStops({QGradientStop(0, QColor::fromRgbF(1,0,0,0.9)), QGradientStop(1, QColor::fromRgbF(0,0,1,0.1))}); QCOMPARE_EQ(n, lg); } inline void test_JKQTPCSSParser_jkqtp_String2QBrushStyleExt() { Qt::BrushStyle bs; QGradient n, g; QLinearGradient lg; #if (QT_VERSION >= QT_VERSION_CHECK(5, 12, 0)) QVERIFY_THROWS_NO_EXCEPTION(bs=jkqtp_String2QBrushStyleExt("warmflame", &n, nullptr)); g = QGradient(QGradient::WarmFlame); g.setCoordinateMode(QGradient::ObjectBoundingMode); QCOMPARE_EQ(n, g); QCOMPARE_EQ(bs, Qt::LinearGradientPattern); #endif QVERIFY_THROWS_NO_EXCEPTION(bs=jkqtp_String2QBrushStyleExt("d1", &n, nullptr)); QCOMPARE_EQ(bs, Qt::Dense1Pattern); QVERIFY_THROWS_NO_EXCEPTION(bs=jkqtp_String2QBrushStyleExt("linear-gradient(to left, red, blue)", &n, nullptr)); lg = QLinearGradient(1,0.5,0,0.5); lg.setCoordinateMode(QGradient::ObjectBoundingMode); lg.setStops({QGradientStop(0, QColor("red")), QGradientStop(1, QColor("blue"))}); QCOMPARE_EQ(n, lg); QCOMPARE_EQ(bs, Qt::LinearGradientPattern); } inline void test_JKQTPCSSParser_jkqtp_String2QColor() { QColor n; QVERIFY_THROWS_NO_EXCEPTION(n=jkqtp_String2QColor("black")); QCOMPARE_EQ(n, QColor(Qt::black)); QVERIFY_THROWS_NO_EXCEPTION(n=jkqtp_String2QColor("red")); QCOMPARE_EQ(n, QColor(Qt::red)); QVERIFY_THROWS_NO_EXCEPTION(n=jkqtp_String2QColor("salmon")); QCOMPARE_EQ(n, QColor("salmon")); QVERIFY_THROWS_NO_EXCEPTION(n=jkqtp_String2QColor("transparent")); QCOMPARE_EQ(n.alpha(), 0); QVERIFY_THROWS_NO_EXCEPTION(n=jkqtp_String2QColor("window")); QCOMPARE_EQ(n, QGuiApplication::palette().color(QPalette::Window)); QVERIFY_THROWS_NO_EXCEPTION(n=jkqtp_String2QColor("#F0F")); QCOMPARE_EQ(n, QColor::fromRgb(255,0,255)); QVERIFY_THROWS_NO_EXCEPTION(n=jkqtp_String2QColor("#FF00FF")); QCOMPARE_EQ(n, QColor::fromRgb(255,0,255)); QVERIFY_THROWS_NO_EXCEPTION(n=jkqtp_String2QColor("#F0F1")); QCOMPARE_EQ(n, QColor::fromRgb(0xFF,0,0xFF,0x11)); QVERIFY_THROWS_NO_EXCEPTION(n=jkqtp_String2QColor("#FF00FF11")); QCOMPARE_EQ(n, QColor::fromRgb(255,0,255,17)); QVERIFY_THROWS_NO_EXCEPTION(n=jkqtp_String2QColor("rgb(50,100,200)")); QCOMPARE_EQ(n, QColor::fromRgb(50,100,200)); QVERIFY_THROWS_NO_EXCEPTION(n=jkqtp_String2QColor("grey50")); QCOMPARE_EQ(n, QColor::fromRgbF(0.5,0.5,0.5)); QVERIFY_THROWS_NO_EXCEPTION(n=jkqtp_String2QColor("grey52")); QCOMPARE_EQ(n, QColor::fromRgbF(0.52,0.52,0.52)); QVERIFY_THROWS_NO_EXCEPTION(n=jkqtp_String2QColor("grey52,20%")); QCOMPARE_EQ(n, QColor::fromRgbF(0.52,0.52,0.52,0.8)); QVERIFY_THROWS_NO_EXCEPTION(n=jkqtp_String2QColor("grey52,a20%")); QCOMPARE_EQ(n, QColor::fromRgbF(0.52,0.52,0.52,0.2)); QVERIFY_THROWS_NO_EXCEPTION(n=jkqtp_String2QColor("grey52,a240")); QCOMPARE_EQ(n, QColor::fromRgbF(0.52,0.52,0.52,240.0/255.0)); } }; QTEST_APPLESS_MAIN(JKQTPCSSParserTest) #include "JKQTPCSSParser_test.moc"