summaryrefslogtreecommitdiffstats
path: root/tests/auto/qgraphicseffectsource
diff options
context:
space:
mode:
authorGunnar Sletta <gunnar@trolltech.com>2009-10-26 09:39:38 (GMT)
committerGunnar Sletta <gunnar@trolltech.com>2009-10-27 07:50:27 (GMT)
commitc39fac87d62ef15867dc5571d03530d7e7240aa7 (patch)
treee947eb70c239619cf20db288300f3b0dd4423d92 /tests/auto/qgraphicseffectsource
parentf6480ca465af9617956752e60d9be3a19b710e0f (diff)
downloadQt-c39fac87d62ef15867dc5571d03530d7e7240aa7.zip
Qt-c39fac87d62ef15867dc5571d03530d7e7240aa7.tar.gz
Qt-c39fac87d62ef15867dc5571d03530d7e7240aa7.tar.bz2
Options on how to get a pixmap from an effect source
Usable for future optimizations. Reviewed-by: Samuel
Diffstat (limited to 'tests/auto/qgraphicseffectsource')
-rw-r--r--tests/auto/qgraphicseffectsource/tst_qgraphicseffectsource.cpp99
1 files changed, 99 insertions, 0 deletions
diff --git a/tests/auto/qgraphicseffectsource/tst_qgraphicseffectsource.cpp b/tests/auto/qgraphicseffectsource/tst_qgraphicseffectsource.cpp
index 855950b..0635989 100644
--- a/tests/auto/qgraphicseffectsource/tst_qgraphicseffectsource.cpp
+++ b/tests/auto/qgraphicseffectsource/tst_qgraphicseffectsource.cpp
@@ -166,6 +166,9 @@ private slots:
void deviceRect();
void pixmap();
+ void pixmapPadding_data();
+ void pixmapPadding();
+
private:
QGraphicsView *view;
QGraphicsScene *scene;
@@ -318,6 +321,102 @@ void tst_QGraphicsEffectSource::pixmap()
QCOMPARE(pixmap1, pixmap2);
}
+class PaddingEffect : public QGraphicsEffect
+{
+public:
+ PaddingEffect(QObject *parent) : QGraphicsEffect(parent)
+ {
+ }
+
+ QRectF boundingRectFor(const QRectF &src) const {
+ return src.adjusted(-10, -10, 10, 10);
+ }
+
+ void draw(QPainter *p, QGraphicsEffectSource *source) {
+ pix = source->pixmap(coordinateMode, &offset, padMode);
+ }
+
+ QPixmap pix;
+ QPoint offset;
+ QGraphicsEffectSource::PixmapPadMode padMode;
+ Qt::CoordinateSystem coordinateMode;
+};
+
+void tst_QGraphicsEffectSource::pixmapPadding_data()
+{
+ QTest::addColumn<int>("coordinateMode");
+ QTest::addColumn<int>("padMode");
+ QTest::addColumn<QSize>("size");
+ QTest::addColumn<QPoint>("offset");
+ QTest::addColumn<uint>("ulPixel");
+
+ QTest::newRow("log,nopad") << int(Qt::LogicalCoordinates)
+ << int(QGraphicsEffectSource::NoPadMode)
+ << QSize(10, 10) << QPoint(0, 0)
+ << 0xffff0000u;
+
+ QTest::newRow("log,transparent") << int(Qt::LogicalCoordinates)
+ << int(QGraphicsEffectSource::ExpandToTransparentBorderPadMode)
+ << QSize(12, 12) << QPoint(-1, -1)
+ << 0x00000000u;
+
+ QTest::newRow("log,effectrect") << int(Qt::LogicalCoordinates)
+ << int(QGraphicsEffectSource::ExpandToEffectRectPadMode)
+ << QSize(30, 30) << QPoint(-10, -10)
+ << 0x00000000u;
+
+ QTest::newRow("dev,nopad") << int(Qt::DeviceCoordinates)
+ << int(QGraphicsEffectSource::NoPadMode)
+ << QSize(20, 20) << QPoint(40, 40)
+ << 0xffff0000u;
+
+ QTest::newRow("dev,transparent") << int(Qt::DeviceCoordinates)
+ << int(QGraphicsEffectSource::ExpandToTransparentBorderPadMode)
+ << QSize(22, 22) << QPoint(39, 39)
+ << 0x00000000u;
+
+ QTest::newRow("dev,effectrect") << int(Qt::DeviceCoordinates)
+ << int(QGraphicsEffectSource::ExpandToEffectRectPadMode)
+ << QSize(40, 40) << QPoint(30, 30)
+ << 0x00000000u;
+
+}
+
+void tst_QGraphicsEffectSource::pixmapPadding()
+{
+ QPixmap dummyTarget(100, 100);
+ QPainter dummyPainter(&dummyTarget);
+ dummyPainter.translate(40, 40);
+ dummyPainter.scale(2, 2);
+
+ QPixmap pm(10, 10);
+ pm.fill(Qt::red);
+
+ QGraphicsScene *scene = new QGraphicsScene();
+ PaddingEffect *effect = new PaddingEffect(scene);
+ QGraphicsPixmapItem *pmItem = new QGraphicsPixmapItem(pm);
+ scene->addItem(pmItem);
+ pmItem->setGraphicsEffect(effect);
+
+ QFETCH(int, coordinateMode);
+ QFETCH(int, padMode);
+ QFETCH(QPoint, offset);
+ QFETCH(QSize, size);
+ QFETCH(uint, ulPixel);
+
+ effect->padMode = (QGraphicsEffectSource::PixmapPadMode) padMode;
+ effect->coordinateMode = (Qt::CoordinateSystem) coordinateMode;
+
+ scene->render(&dummyPainter, scene->itemsBoundingRect(), scene->itemsBoundingRect());
+
+ QCOMPARE(effect->pix.size(), size);
+ QCOMPARE(effect->offset, offset);
+ QCOMPARE(effect->pix.toImage().pixel(0, 0), ulPixel);
+
+ // ### Fix corruption in scene destruction, then enable...
+ // delete scene;
+}
+
QTEST_MAIN(tst_QGraphicsEffectSource)
#include "tst_qgraphicseffectsource.moc"