void tst_qsganimatedimage::mirror_notRunning() { QFETCH(QUrl, fileUrl); QSGView *canvas = new QSGView; canvas->show(); canvas->setSource(fileUrl); QSGAnimatedImage *anim = qobject_cast<QSGAnimatedImage *>(canvas->rootObject()); QVERIFY(anim); int width = anim->property("width").toInt(); QPixmap screenshot = canvas->renderPixmap(); QTransform transform; transform.translate(width, 0).scale(-1, 1.0); QPixmap expected = screenshot.transformed(transform); int frame = anim->currentFrame(); bool playing = anim->isPlaying(); bool paused = anim->isPlaying(); anim->setProperty("mirror", true); screenshot = canvas->renderPixmap(); QSKIP("Skip while QTBUG-19351 and QTBUG-19252 are not resolved", SkipSingle); QCOMPARE(screenshot, expected); // mirroring should not change the current frame or playing status QCOMPARE(anim->currentFrame(), frame); QCOMPARE(anim->isPlaying(), playing); QCOMPARE(anim->isPaused(), paused); delete canvas; }
void tst_qsganimatedimage::mirror_running() { // test where mirror is set to true after animation has started QSGView *canvas = new QSGView; canvas->show(); canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/hearts.qml")); QSGAnimatedImage *anim = qobject_cast<QSGAnimatedImage *>(canvas->rootObject()); QVERIFY(anim); int width = anim->property("width").toInt(); QCOMPARE(anim->currentFrame(), 0); QPixmap frame0 = canvas->renderPixmap(); anim->setCurrentFrame(1); QPixmap frame1 = canvas->renderPixmap(); anim->setCurrentFrame(0); QSignalSpy spy(anim, SIGNAL(frameChanged())); anim->setPlaying(true); QTRY_VERIFY(spy.count() == 1); spy.clear(); anim->setProperty("mirror", true); QCOMPARE(anim->currentFrame(), 1); QPixmap frame1_flipped = canvas->renderPixmap(); QTRY_VERIFY(spy.count() == 1); spy.clear(); QCOMPARE(anim->currentFrame(), 0); // animation only has 2 frames, should cycle back to first QPixmap frame0_flipped = canvas->renderPixmap(); QSKIP("Skip while QTBUG-19351 and QTBUG-19252 are not resolved", SkipSingle); QTransform transform; transform.translate(width, 0).scale(-1, 1.0); QPixmap frame0_expected = frame0.transformed(transform); QPixmap frame1_expected = frame1.transformed(transform); QCOMPARE(frame0_flipped, frame0_expected); QCOMPARE(frame1_flipped, frame1_expected); delete canvas; }
int main(int argc, char ** argv) { QApplication app(argc, argv); //![0] QStringList dataList; dataList.append("Item 1"); dataList.append("Item 2"); dataList.append("Item 3"); dataList.append("Item 4"); QSGView view; QDeclarativeContext *ctxt = view.rootContext(); ctxt->setContextProperty("myModel", QVariant::fromValue(dataList)); //![0] view.setSource(QUrl("qrc:view.qml")); view.show(); return app.exec(); }