summaryrefslogtreecommitdiffstats
path: root/tests/auto/gui/painting
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/gui/painting')
-rw-r--r--tests/auto/gui/painting/qcolorspace/resources/HP_ZR30w.iccbin0 -> 1856 bytes
-rw-r--r--tests/auto/gui/painting/qcolorspace/tst_qcolorspace.cpp141
-rw-r--r--tests/auto/gui/painting/qpainter/tst_qpainter.cpp68
-rw-r--r--tests/auto/gui/painting/qpainterpath/tst_qpainterpath.cpp10
-rw-r--r--tests/auto/gui/painting/qpathclipper/paths.cpp2
5 files changed, 175 insertions, 46 deletions
diff --git a/tests/auto/gui/painting/qcolorspace/resources/HP_ZR30w.icc b/tests/auto/gui/painting/qcolorspace/resources/HP_ZR30w.icc
new file mode 100644
index 0000000000..b3f860714c
--- /dev/null
+++ b/tests/auto/gui/painting/qcolorspace/resources/HP_ZR30w.icc
Binary files differ
diff --git a/tests/auto/gui/painting/qcolorspace/tst_qcolorspace.cpp b/tests/auto/gui/painting/qcolorspace/tst_qcolorspace.cpp
index 7a88eb18b2..bc1a45013c 100644
--- a/tests/auto/gui/painting/qcolorspace/tst_qcolorspace.cpp
+++ b/tests/auto/gui/painting/qcolorspace/tst_qcolorspace.cpp
@@ -36,7 +36,7 @@
#include <private/qcolorspace_p.h>
Q_DECLARE_METATYPE(QColorSpace::ColorSpaceId)
-Q_DECLARE_METATYPE(QColorSpace::Gamut)
+Q_DECLARE_METATYPE(QColorSpace::Primaries)
Q_DECLARE_METATYPE(QColorSpace::TransferFunction)
class tst_QColorSpace : public QObject
@@ -53,6 +53,7 @@ private slots:
void toIccProfile_data();
void toIccProfile();
+ void fromIccProfile_data();
void fromIccProfile();
void imageConversion_data();
@@ -60,11 +61,14 @@ private slots:
void loadImage();
- void gamut();
+ void primaries();
void primariesXyz();
void primaries2_data();
void primaries2();
void invalidPrimaries();
+
+ void changeTransferFunction();
+ void changePrimaries();
};
tst_QColorSpace::tst_QColorSpace()
@@ -74,33 +78,33 @@ tst_QColorSpace::tst_QColorSpace()
void tst_QColorSpace::namedColorSpaces_data()
{
QTest::addColumn<QColorSpace::ColorSpaceId>("colorSpaceId");
- QTest::addColumn<QColorSpace::Gamut>("gamutId");
+ QTest::addColumn<QColorSpace::Primaries>("primariesId");
QTest::addColumn<QColorSpace::TransferFunction>("transferFunctionId");
QTest::newRow("sRGB") << QColorSpace::SRgb
- << QColorSpace::Gamut::SRgb
+ << QColorSpace::Primaries::SRgb
<< QColorSpace::TransferFunction::SRgb;
QTest::newRow("sRGB Linear") << QColorSpace::SRgbLinear
- << QColorSpace::Gamut::SRgb
+ << QColorSpace::Primaries::SRgb
<< QColorSpace::TransferFunction::Linear;
QTest::newRow("Adobe RGB") << QColorSpace::AdobeRgb
- << QColorSpace::Gamut::AdobeRgb
+ << QColorSpace::Primaries::AdobeRgb
<< QColorSpace::TransferFunction::Gamma;
QTest::newRow("Display-P3") << QColorSpace::DisplayP3
- << QColorSpace::Gamut::DciP3D65
+ << QColorSpace::Primaries::DciP3D65
<< QColorSpace::TransferFunction::SRgb;
QTest::newRow("ProPhoto RGB") << QColorSpace::ProPhotoRgb
- << QColorSpace::Gamut::ProPhotoRgb
+ << QColorSpace::Primaries::ProPhotoRgb
<< QColorSpace::TransferFunction::ProPhotoRgb;
QTest::newRow("BT.2020") << QColorSpace::Bt2020
- << QColorSpace::Gamut::Bt2020
+ << QColorSpace::Primaries::Bt2020
<< QColorSpace::TransferFunction::Bt2020;
}
void tst_QColorSpace::namedColorSpaces()
{
QFETCH(QColorSpace::ColorSpaceId, colorSpaceId);
- QFETCH(QColorSpace::Gamut, gamutId);
+ QFETCH(QColorSpace::Primaries, primariesId);
QFETCH(QColorSpace::TransferFunction, transferFunctionId);
QColorSpace colorSpace = colorSpaceId;
@@ -108,7 +112,7 @@ void tst_QColorSpace::namedColorSpaces()
QVERIFY(colorSpace.isValid());
QCOMPARE(colorSpace.colorSpaceId(), colorSpaceId);
- QCOMPARE(colorSpace.gamut(), gamutId);
+ QCOMPARE(colorSpace.primaries(), primariesId);
QCOMPARE(colorSpace.transferFunction(), transferFunctionId);
}
@@ -121,10 +125,10 @@ void tst_QColorSpace::toIccProfile_data()
void tst_QColorSpace::toIccProfile()
{
QFETCH(QColorSpace::ColorSpaceId, colorSpaceId);
- QFETCH(QColorSpace::Gamut, gamutId);
+ QFETCH(QColorSpace::Primaries, primariesId);
QFETCH(QColorSpace::TransferFunction, transferFunctionId);
- Q_UNUSED(gamutId);
+ Q_UNUSED(primariesId);
Q_UNUSED(transferFunctionId);
QColorSpace colorSpace = colorSpaceId;
@@ -142,21 +146,38 @@ void tst_QColorSpace::toIccProfile()
QCOMPARE(iccProfile2, iccProfile);
}
-void tst_QColorSpace::fromIccProfile()
+void tst_QColorSpace::fromIccProfile_data()
{
- // Read the official sRGB ICCv2 profile:
+ QTest::addColumn<QString>("testProfile");
+ QTest::addColumn<QColorSpace::ColorSpaceId>("colorSpaceId");
+ QTest::addColumn<QColorSpace::TransferFunction>("transferFunction");
+ QTest::addColumn<QString>("description");
+
QString prefix = QFINDTESTDATA("resources/");
- QFile file(prefix + "sRGB2014.icc");
+ // Read the official sRGB ICCv2 profile:
+ QTest::newRow("sRGB2014 (ICCv2)") << prefix + "sRGB2014.icc" << QColorSpace::SRgb
+ << QColorSpace::TransferFunction::SRgb << QString("sRGB2014");
+ // My monitor's profile:
+ QTest::newRow("HP ZR30w (ICCv4)") << prefix + "HP_ZR30w.icc" << QColorSpace::Unknown
+ << QColorSpace::TransferFunction::Gamma << QString("HP Z30i");
+}
+
+void tst_QColorSpace::fromIccProfile()
+{
+ QFETCH(QString, testProfile);
+ QFETCH(QColorSpace::ColorSpaceId, colorSpaceId);
+ QFETCH(QColorSpace::TransferFunction, transferFunction);
+ QFETCH(QString, description);
+
+ QFile file(testProfile);
file.open(QIODevice::ReadOnly);
QByteArray iccProfile = file.readAll();
- QColorSpace stdSRgb = QColorSpace::fromIccProfile(iccProfile);
- QVERIFY(stdSRgb.isValid());
-
- QCOMPARE(stdSRgb.gamut(), QColorSpace::Gamut::SRgb);
- QCOMPARE(stdSRgb.transferFunction(), QColorSpace::TransferFunction::SRgb);
- QCOMPARE(stdSRgb.colorSpaceId(), QColorSpace::SRgb);
+ QColorSpace fileColorSpace = QColorSpace::fromIccProfile(iccProfile);
+ QVERIFY(fileColorSpace.isValid());
- QCOMPARE(stdSRgb, QColorSpace(QColorSpace::SRgb));
+ QCOMPARE(fileColorSpace.colorSpaceId(), colorSpaceId);
+ QCOMPARE(fileColorSpace.transferFunction(), transferFunction);
+ QCOMPARE(QColorSpacePrivate::get(fileColorSpace)->description, description);
}
void tst_QColorSpace::imageConversion_data()
@@ -262,7 +283,7 @@ void tst_QColorSpace::loadImage()
QVERIFY(maxBlue2 > maxBlue);
}
-void tst_QColorSpace::gamut()
+void tst_QColorSpace::primaries()
{
QColor black = QColor::fromRgbF(0.0, 0.0, 0.0);
QColor white = QColor::fromRgbF(1.0, 1.0, 1.0);
@@ -304,30 +325,30 @@ void tst_QColorSpace::primariesXyz()
QColorSpace bt2020 = QColorSpace::Bt2020;
// Check if our calculated matrices, match the precalculated ones.
- QCOMPARE(sRgb.d_func()->toXyz, QColorMatrix::toXyzFromSRgb());
- QCOMPARE(adobeRgb.d_func()->toXyz, QColorMatrix::toXyzFromAdobeRgb());
- QCOMPARE(displayP3.d_func()->toXyz, QColorMatrix::toXyzFromDciP3D65());
- QCOMPARE(proPhotoRgb.d_func()->toXyz, QColorMatrix::toXyzFromProPhotoRgb());
- QCOMPARE(bt2020.d_func()->toXyz, QColorMatrix::toXyzFromBt2020());
+ QCOMPARE(QColorSpacePrivate::get(sRgb)->toXyz, QColorMatrix::toXyzFromSRgb());
+ QCOMPARE(QColorSpacePrivate::get(adobeRgb)->toXyz, QColorMatrix::toXyzFromAdobeRgb());
+ QCOMPARE(QColorSpacePrivate::get(displayP3)->toXyz, QColorMatrix::toXyzFromDciP3D65());
+ QCOMPARE(QColorSpacePrivate::get(proPhotoRgb)->toXyz, QColorMatrix::toXyzFromProPhotoRgb());
+ QCOMPARE(QColorSpacePrivate::get(bt2020)->toXyz, QColorMatrix::toXyzFromBt2020());
}
void tst_QColorSpace::primaries2_data()
{
- QTest::addColumn<QColorSpace::Gamut>("gamut");
+ QTest::addColumn<QColorSpace::Primaries>("primariesId");
- QTest::newRow("sRGB") << QColorSpace::Gamut::SRgb;
- QTest::newRow("DCI-P3 (D65)") << QColorSpace::Gamut::DciP3D65;
- QTest::newRow("Adobe RGB (1998)") << QColorSpace::Gamut::AdobeRgb;
- QTest::newRow("ProPhoto RGB") << QColorSpace::Gamut::ProPhotoRgb;
- QTest::newRow("BT.2020") << QColorSpace::Gamut::Bt2020;
+ QTest::newRow("sRGB") << QColorSpace::Primaries::SRgb;
+ QTest::newRow("DCI-P3 (D65)") << QColorSpace::Primaries::DciP3D65;
+ QTest::newRow("Adobe RGB (1998)") << QColorSpace::Primaries::AdobeRgb;
+ QTest::newRow("ProPhoto RGB") << QColorSpace::Primaries::ProPhotoRgb;
+ QTest::newRow("BT.2020") << QColorSpace::Primaries::Bt2020;
}
void tst_QColorSpace::primaries2()
{
- QFETCH(QColorSpace::Gamut, gamut);
- QColorSpacePrimaries primaries(gamut);
+ QFETCH(QColorSpace::Primaries, primariesId);
+ QColorSpacePrimaries primaries(primariesId);
- QColorSpace original(gamut, QColorSpace::TransferFunction::Linear);
+ QColorSpace original(primariesId, QColorSpace::TransferFunction::Linear);
QColorSpace custom1(primaries.whitePoint, primaries.redPoint,
primaries.greenPoint, primaries.bluePoint, QColorSpace::TransferFunction::Linear);
QCOMPARE(original, custom1);
@@ -357,5 +378,49 @@ void tst_QColorSpace::invalidPrimaries()
QCOMPARE(custom.colorSpaceId(), QColorSpace::Undefined);
}
+void tst_QColorSpace::changeTransferFunction()
+{
+ QColorSpace sRgb = QColorSpace::SRgb;
+
+ QColorSpace sRgbLinear = sRgb.withTransferFunction(QColorSpace::TransferFunction::Linear);
+ QCOMPARE(sRgbLinear.transferFunction(), QColorSpace::TransferFunction::Linear);
+ QCOMPARE(sRgbLinear.gamma(), 1.0f);
+ QCOMPARE(sRgbLinear.primaries(), QColorSpace::Primaries::SRgb);
+ QCOMPARE(sRgbLinear.colorSpaceId(), QColorSpace::SRgbLinear);
+ QCOMPARE(sRgbLinear, QColorSpace(QColorSpace::SRgbLinear));
+ QVERIFY(sRgbLinear != sRgb);
+ QCOMPARE(sRgbLinear.withTransferFunction(QColorSpace::TransferFunction::SRgb), sRgb);
+
+ QColorSpace aRgb = QColorSpace::AdobeRgb;
+ aRgb.setTransferFunction(QColorSpace::TransferFunction::SRgb);
+ QCOMPARE(aRgb.transferFunction(), QColorSpace::TransferFunction::SRgb);
+ QCOMPARE(aRgb.primaries(), QColorSpace::Primaries::AdobeRgb);
+ QCOMPARE(aRgb.colorSpaceId(), QColorSpace::Unknown);
+ QVERIFY(aRgb != QColorSpace(QColorSpace::AdobeRgb));
+ QVERIFY(aRgb != sRgb);
+ QCOMPARE(aRgb.withTransferFunction(QColorSpace::TransferFunction::Gamma, 2.2f),
+ QColorSpace(QColorSpace::AdobeRgb));
+ QVERIFY(aRgb != QColorSpace(QColorSpace::AdobeRgb));
+ aRgb.setTransferFunction(QColorSpace::TransferFunction::Gamma, 2.2f);
+ QVERIFY(aRgb == QColorSpace(QColorSpace::AdobeRgb));
+
+ QColorSpace undefined;
+ QCOMPARE(undefined.withTransferFunction(QColorSpace::TransferFunction::Linear), undefined);
+ undefined.setTransferFunction(QColorSpace::TransferFunction::SRgb);
+ QCOMPARE(undefined, QColorSpace());
+}
+
+void tst_QColorSpace::changePrimaries()
+{
+ QColorSpace cs = QColorSpace::SRgb;
+ cs.setPrimaries(QColorSpace::Primaries::DciP3D65);
+ QVERIFY(cs.isValid());
+ QCOMPARE(cs, QColorSpace(QColorSpace::DisplayP3));
+ cs.setTransferFunction(QColorSpace::TransferFunction::Linear);
+ cs.setPrimaries(QPointF(0.3127, 0.3290), QPointF(0.640, 0.330),
+ QPointF(0.3000, 0.6000), QPointF(0.150, 0.060));
+ QCOMPARE(cs, QColorSpace(QColorSpace::SRgbLinear));
+}
+
QTEST_MAIN(tst_QColorSpace)
#include "tst_qcolorspace.moc"
diff --git a/tests/auto/gui/painting/qpainter/tst_qpainter.cpp b/tests/auto/gui/painting/qpainter/tst_qpainter.cpp
index 2b53169a45..0efeb9b356 100644
--- a/tests/auto/gui/painting/qpainter/tst_qpainter.cpp
+++ b/tests/auto/gui/painting/qpainter/tst_qpainter.cpp
@@ -123,14 +123,18 @@ private slots:
void drawPath2();
void drawPath3();
+#if QT_DEPRECATED_SINCE(5, 13)
void drawRoundRect_data() { fillData(); }
void drawRoundRect();
+#endif
+ void drawRoundedRect_data() { fillData(); }
+ void drawRoundedRect();
void qimageFormats_data();
void qimageFormats();
void textOnTransparentImage();
-#ifndef QT_NO_WIDGETS
+#if !defined(QT_NO_WIDGETS) && QT_DEPRECATED_SINCE(5, 13)
void initFrom();
#endif
@@ -679,12 +683,14 @@ static QRect getPaintedSize(const QPixmap &pm, const QColor &background)
}
#ifndef QT_NO_WIDGETS
+
+#if QT_DEPRECATED_SINCE(5, 13)
void tst_QPainter::initFrom()
{
QWidget *widget = new QWidget();
QPalette pal = widget->palette();
- pal.setColor(QPalette::Foreground, QColor(255, 0, 0));
- pal.setBrush(QPalette::Background, QColor(0, 255, 0));
+ pal.setColor(QPalette::WindowText, QColor(255, 0, 0));
+ pal.setBrush(QPalette::Window, QColor(0, 255, 0));
widget->setPalette(pal);
widget->show();
@@ -698,11 +704,12 @@ void tst_QPainter::initFrom()
p.initFrom(widget);
QCOMPARE(p.font(), font);
- QCOMPARE(p.pen().color(), pal.color(QPalette::Foreground));
+ QCOMPARE(p.pen().color(), pal.color(QPalette::WindowText));
QCOMPARE(p.background(), pal.window());
delete widget;
}
+#endif
void tst_QPainter::drawBorderPixmap()
{
@@ -1546,6 +1553,7 @@ void tst_QPainter::drawClippedEllipse()
}
+#if QT_DEPRECATED_SINCE(5, 13)
void tst_QPainter::drawRoundRect()
{
QFETCH(QRect, rect);
@@ -1580,6 +1588,42 @@ void tst_QPainter::drawRoundRect()
QCOMPARE(painted.height(), rect.height() + increment);
}
}
+#endif
+
+void tst_QPainter::drawRoundedRect()
+{
+ QFETCH(QRect, rect);
+ QFETCH(bool, usePen);
+
+#ifdef Q_OS_DARWIN
+ if (QTest::currentDataTag() == QByteArray("rect(6, 12, 3, 14) with pen") ||
+ QTest::currentDataTag() == QByteArray("rect(6, 17, 3, 25) with pen") ||
+ QTest::currentDataTag() == QByteArray("rect(10, 6, 10, 3) with pen") ||
+ QTest::currentDataTag() == QByteArray("rect(10, 12, 10, 14) with pen") ||
+ QTest::currentDataTag() == QByteArray("rect(13, 45, 17, 80) with pen") ||
+ QTest::currentDataTag() == QByteArray("rect(13, 50, 17, 91) with pen") ||
+ QTest::currentDataTag() == QByteArray("rect(17, 6, 24, 3) with pen") ||
+ QTest::currentDataTag() == QByteArray("rect(24, 12, 38, 14) with pen"))
+ QSKIP("The Mac paint engine is off-by-one on certain rect sizes");
+#endif
+ QPixmap pixmap(rect.x() + rect.width() + 10,
+ rect.y() + rect.height() + 10);
+ {
+ pixmap.fill(Qt::white);
+ QPainter p(&pixmap);
+ p.setRenderHint(QPainter::Qt4CompatiblePainting);
+ p.setPen(usePen ? QPen(Qt::black) : QPen(Qt::NoPen));
+ p.setBrush(Qt::black);
+ p.drawRoundedRect(rect, 25, 25, Qt::RelativeSize);
+ p.end();
+
+ int increment = usePen ? 1 : 0;
+
+ const QRect painted = getPaintedSize(pixmap, Qt::white);
+ QCOMPARE(painted.width(), rect.width() + increment);
+ QCOMPARE(painted.height(), rect.height() + increment);
+ }
+}
void tst_QPainter::qimageFormats_data()
{
@@ -1662,9 +1706,13 @@ void tst_QPainter::combinedMatrix()
p.translate(0.5, 0.5);
+ QTransform ct = p.combinedTransform();
+#if QT_DEPRECATED_SINCE(5, 13)
QMatrix cm = p.combinedMatrix();
+ QCOMPARE(cm, ct.toAffine());
+#endif
- QPointF pt = QPointF(0, 0) * cm;
+ QPointF pt = QPointF(0, 0) * ct.toAffine();
QCOMPARE(pt.x(), 48.0);
QCOMPARE(pt.y(), 16.0);
@@ -1979,7 +2027,7 @@ void tst_QPainter::clippedFillPath_data()
<< pen2;
path = QPainterPath();
- path.addRoundRect(QRect(15, 15, 50, 50), 20);
+ path.addRoundedRect(QRect(15, 15, 50, 50), 20, Qt::RelativeSize);
QTest::newRow("round rect 0") << QSize(100, 100) << path
<< QRect(15, 15, 49, 49)
<< QBrush(Qt::NoBrush)
@@ -4088,14 +4136,18 @@ void tst_QPainter::inactivePainter()
p.setClipRegion(region);
p.setClipping(true);
+#if QT_DEPRECATED_SINCE(5, 13)
p.combinedMatrix();
+#endif
p.combinedTransform();
p.compositionMode();
p.setCompositionMode(QPainter::CompositionMode_Plus);
p.device();
+#if QT_DEPRECATED_SINCE(5, 13)
p.deviceMatrix();
+#endif
p.deviceTransform();
p.font();
@@ -4119,7 +4171,9 @@ void tst_QPainter::inactivePainter()
p.setRenderHint(QPainter::Antialiasing, true);
p.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform, false);
+#if QT_DEPRECATED_SINCE(5, 13)
p.resetMatrix();
+#endif
p.resetTransform();
p.rotate(1);
p.scale(2, 2);
@@ -4135,8 +4189,10 @@ void tst_QPainter::inactivePainter()
p.window();
p.setWindow(QRect(10, 10, 620, 460));
+#if QT_DEPRECATED_SINCE(5, 13)
p.worldMatrix();
p.setWorldMatrix(QMatrix().translate(43, 21), true);
+#endif
p.setWorldMatrixEnabled(true);
p.transform();
diff --git a/tests/auto/gui/painting/qpainterpath/tst_qpainterpath.cpp b/tests/auto/gui/painting/qpainterpath/tst_qpainterpath.cpp
index c90348e91a..67cf9a321a 100644
--- a/tests/auto/gui/painting/qpainterpath/tst_qpainterpath.cpp
+++ b/tests/auto/gui/painting/qpainterpath/tst_qpainterpath.cpp
@@ -161,10 +161,18 @@ void tst_QPainterPath::clear()
p1.clear();
QCOMPARE(p1, p2);
+ p1.lineTo(50, 50);
+ QPainterPath p3;
+ QCOMPARE(p1.elementCount(), 2);
+ p3.lineTo(50, 50);
+ QCOMPARE(p1, p3);
+
QCOMPARE(p1.fillRule(), Qt::OddEvenFill);
p1.setFillRule(Qt::WindingFill);
+ QVERIFY(p1 != p3);
p1.clear();
- QCOMPARE(p1.fillRule(), Qt::WindingFill);
+ QCOMPARE(p1.fillRule(), Qt::OddEvenFill);
+ QCOMPARE(p1, p2);
}
void tst_QPainterPath::reserveAndCapacity()
diff --git a/tests/auto/gui/painting/qpathclipper/paths.cpp b/tests/auto/gui/painting/qpathclipper/paths.cpp
index 077527e1a0..1328befd1b 100644
--- a/tests/auto/gui/painting/qpathclipper/paths.cpp
+++ b/tests/auto/gui/painting/qpathclipper/paths.cpp
@@ -578,7 +578,7 @@ QPainterPath Paths::node()
m_rect.setHeight(100);
QPainterPath shape;
- shape.addRoundRect(m_rect, 25);
+ shape.addRoundedRect(m_rect, 25, Qt::RelativeSize);
const int conWidth = 10;
const int xOffset = 7;