void tst_QGraphicsItemAnimation::checkReturnedLists() { QGraphicsItemAnimation animation; animation.setPosAt(1.0, QPointF(10, -10)); animation.setPosAt(0.5, QPointF(5, -5)); animation.setRotationAt(0.3, 2.3); animation.setTranslationAt(0.3, 15, 15); animation.setScaleAt(0.3, 2.5, 1.8); animation.setShearAt(0.3, 5, 5); QCOMPARE(animation.posList().at(0), (QPair<qreal, QPointF>(0.5, QPointF(5, -5)))); QCOMPARE(animation.posList().at(1), (QPair<qreal, QPointF>(1.0, QPointF(10, -10)))); QCOMPARE(animation.rotationList().at(0), (QPair<qreal, qreal>(0.3, 2.3))); QCOMPARE(animation.translationList().at(0), (QPair<qreal, QPointF>(0.3, QPointF(15, 15)))); QCOMPARE(animation.scaleList().at(0), (QPair<qreal, QPointF>(0.3, QPointF(2.5, 1.8)))); QCOMPARE(animation.shearList().at(0), (QPair<qreal, QPointF>(0.3, QPointF(5, 5)))); QCOMPARE(animation.posList().size(), 2); QCOMPARE(animation.rotationList().size(), 1); QCOMPARE(animation.translationList().size(), 1); QCOMPARE(animation.scaleList().size(), 1); QCOMPARE(animation.shearList().size(), 1); }
void tst_QGraphicsItemAnimation::overwriteValueForStep() { QGraphicsItemAnimation animation; for (int i=0; i<3; i++){ animation.setPosAt(0.3, QPointF(3, -3.1)); animation.setRotationAt(0.3, 2.3); animation.setTranslationAt(0.3, 15, 15); animation.setScaleAt(0.3, 2.5, 1.8); animation.setShearAt(0.3, 5, 5); QCOMPARE(animation.posList().size(), 1); QCOMPARE(animation.rotationList().size(), 1); QCOMPARE(animation.translationList().size(), 1); QCOMPARE(animation.scaleList().size(), 1); QCOMPARE(animation.shearList().size(), 1); } }
MyScene::MyScene(qreal x,qreal y,qreal width,qreal height,QObject *parent):QGraphicsScene(x,y,width,height,parent) { // 預計加一個圓形,然後,執徑逐漸變大 QGraphicsEllipseItem *ball = new QGraphicsEllipseItem(-15,-15,30,30); ball->setPen(QPen(QColor(125,125,125,125),3)); addItem(ball); ball->setPos(this->width()/2,this->height()/2); // setPos(x,y):設定此小座標的原點在此(x,y) timeLine = new QTimeLine; QGraphicsItemAnimation *headAnimation = new QGraphicsItemAnimation; headAnimation->setItem(ball); headAnimation->setTimeLine(timeLine); headAnimation->setScaleAt(1,10,10); timeLine->setUpdateInterval(1000 / 25); timeLine->setCurveShape(QTimeLine::SineCurve); timeLine->setLoopCount(0); timeLine->setDuration(2000); timeLine->start(); }
Robot::Robot() { QGraphicsItem *torsoItem = new RobotTorso(this); QGraphicsItem *headItem = new RobotHead(torsoItem); QGraphicsItem *upperLeftArmItem = new RobotLimb(torsoItem); QGraphicsItem *lowerLeftArmItem = new RobotLimb(upperLeftArmItem); QGraphicsItem *upperRightArmItem = new RobotLimb(torsoItem); QGraphicsItem *lowerRightArmItem = new RobotLimb(upperRightArmItem); QGraphicsItem *upperRightLegItem = new RobotLimb(torsoItem); QGraphicsItem *lowerRightLegItem = new RobotLimb(upperRightLegItem); QGraphicsItem *upperLeftLegItem = new RobotLimb(torsoItem); QGraphicsItem *lowerLeftLegItem = new RobotLimb(upperLeftLegItem); headItem->setPos(0, -18); upperLeftArmItem->setPos(-15, -10); lowerLeftArmItem->setPos(30, 0); upperRightArmItem->setPos(15, -10); lowerRightArmItem->setPos(30, 0); upperRightLegItem->setPos(10, 32); lowerRightLegItem->setPos(30, 0); upperLeftLegItem->setPos(-10, 32); lowerLeftLegItem->setPos(30, 0); timeLine = new QTimeLine; QGraphicsItemAnimation *headAnimation = new QGraphicsItemAnimation; headAnimation->setItem(headItem); headAnimation->setTimeLine(timeLine); headAnimation->setRotationAt(0, 20); headAnimation->setRotationAt(1, -20); headAnimation->setScaleAt(1, 1.1, 1.1); QGraphicsItemAnimation *upperLeftArmAnimation = new QGraphicsItemAnimation; upperLeftArmAnimation->setItem(upperLeftArmItem); upperLeftArmAnimation->setTimeLine(timeLine); upperLeftArmAnimation->setRotationAt(0, 190); upperLeftArmAnimation->setRotationAt(1, 180); QGraphicsItemAnimation *lowerLeftArmAnimation = new QGraphicsItemAnimation; lowerLeftArmAnimation->setItem(lowerLeftArmItem); lowerLeftArmAnimation->setTimeLine(timeLine); lowerLeftArmAnimation->setRotationAt(0, 50); lowerLeftArmAnimation->setRotationAt(1, 10); QGraphicsItemAnimation *upperRightArmAnimation = new QGraphicsItemAnimation; upperRightArmAnimation->setItem(upperRightArmItem); upperRightArmAnimation->setTimeLine(timeLine); upperRightArmAnimation->setRotationAt(0, 300); upperRightArmAnimation->setRotationAt(1, 310); QGraphicsItemAnimation *lowerRightArmAnimation = new QGraphicsItemAnimation; lowerRightArmAnimation->setItem(lowerRightArmItem); lowerRightArmAnimation->setTimeLine(timeLine); lowerRightArmAnimation->setRotationAt(0, 0); lowerRightArmAnimation->setRotationAt(1, -70); QGraphicsItemAnimation *upperLeftLegAnimation = new QGraphicsItemAnimation; upperLeftLegAnimation->setItem(upperLeftLegItem); upperLeftLegAnimation->setTimeLine(timeLine); upperLeftLegAnimation->setRotationAt(0, 150); upperLeftLegAnimation->setRotationAt(1, 80); QGraphicsItemAnimation *lowerLeftLegAnimation = new QGraphicsItemAnimation; lowerLeftLegAnimation->setItem(lowerLeftLegItem); lowerLeftLegAnimation->setTimeLine(timeLine); lowerLeftLegAnimation->setRotationAt(0, 70); lowerLeftLegAnimation->setRotationAt(1, 10); QGraphicsItemAnimation *upperRightLegAnimation = new QGraphicsItemAnimation; upperRightLegAnimation->setItem(upperRightLegItem); upperRightLegAnimation->setTimeLine(timeLine); upperRightLegAnimation->setRotationAt(0, 40); upperRightLegAnimation->setRotationAt(1, 120); QGraphicsItemAnimation *lowerRightLegAnimation = new QGraphicsItemAnimation; lowerRightLegAnimation->setItem(lowerRightLegItem); lowerRightLegAnimation->setTimeLine(timeLine); lowerRightLegAnimation->setRotationAt(0, 10); lowerRightLegAnimation->setRotationAt(1, 50); QGraphicsItemAnimation *torsoAnimation = new QGraphicsItemAnimation; torsoAnimation->setItem(torsoItem); torsoAnimation->setTimeLine(timeLine); torsoAnimation->setRotationAt(0, 5); torsoAnimation->setRotationAt(1, -20); timeLine->setUpdateInterval(1000 / 25); timeLine->setCurveShape(QTimeLine::SineCurve); timeLine->setLoopCount(0); timeLine->setDuration(2000); timeLine->start(); }