diff options
Diffstat (limited to 'examples/animation')
-rw-r--r-- | examples/animation/states/main.cpp | 181 |
1 files changed, 85 insertions, 96 deletions
diff --git a/examples/animation/states/main.cpp b/examples/animation/states/main.cpp index dafa8ad..f9d654a 100644 --- a/examples/animation/states/main.cpp +++ b/examples/animation/states/main.cpp @@ -41,13 +41,12 @@ #include <QtGui> -class Pixmap : public QGraphicsWidget +class Pixmap : public QGraphicsObject { Q_OBJECT public: - Pixmap(const QPixmap &pix) : QGraphicsWidget(), p(pix) + Pixmap(const QPixmap &pix) : QGraphicsObject(), p(pix) { - setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); } void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) @@ -55,10 +54,9 @@ public: painter->drawPixmap(QPointF(), p); } -protected: - QSizeF sizeHint(Qt::SizeHint, const QSizeF & = QSizeF()) + QRectF boundingRect() const { - return QSizeF(p.width(), p.height()); + return QRectF( QPointF(0, 0), p.size()); } private: @@ -133,12 +131,12 @@ int main(int argc, char *argv[]) state1->assignProperty(button, "text", "Switch to state 2"); state1->assignProperty(widget, "geometry", QRectF(0, 0, 400, 150)); state1->assignProperty(box, "geometry", QRect(-200, 150, 200, 150)); - state1->assignProperty(p1, "geometry", QRectF(68, 185, 64, 64)); - state1->assignProperty(p2, "geometry", QRectF(168, 185, 64, 64)); - state1->assignProperty(p3, "geometry", QRectF(268, 185, 64, 64)); - state1->assignProperty(p4, "geometry", QRectF(68-150, 48-150, 64, 64)); - state1->assignProperty(p5, "geometry", QRectF(168, 48-150, 64, 64)); - state1->assignProperty(p6, "geometry", QRectF(268+150, 48-150, 64, 64)); + state1->assignProperty(p1, "pos", QPointF(68, 185)); + state1->assignProperty(p2, "pos", QPointF(168, 185)); + state1->assignProperty(p3, "pos", QPointF(268, 185)); + state1->assignProperty(p4, "pos", QPointF(68-150, 48-150)); + state1->assignProperty(p5, "pos", QPointF(168, 48-150)); + state1->assignProperty(p6, "pos", QPointF(268+150, 48-150)); state1->assignProperty(p1, "rotation", qreal(0)); state1->assignProperty(p2, "rotation", qreal(0)); state1->assignProperty(p3, "rotation", qreal(0)); @@ -157,12 +155,12 @@ int main(int argc, char *argv[]) state2->assignProperty(button, "text", "Switch to state 3"); state2->assignProperty(widget, "geometry", QRectF(200, 150, 200, 150)); state2->assignProperty(box, "geometry", QRect(9, 150, 190, 150)); - state2->assignProperty(p1, "geometry", QRectF(68-150, 185+150, 64, 64)); - state2->assignProperty(p2, "geometry", QRectF(168, 185+150, 64, 64)); - state2->assignProperty(p3, "geometry", QRectF(268+150, 185+150, 64, 64)); - state2->assignProperty(p4, "geometry", QRectF(64, 48, 64, 64)); - state2->assignProperty(p5, "geometry", QRectF(168, 48, 64, 64)); - state2->assignProperty(p6, "geometry", QRectF(268, 48, 64, 64)); + state2->assignProperty(p1, "pos", QPointF(68-150, 185+150)); + state2->assignProperty(p2, "pos", QPointF(168, 185+150)); + state2->assignProperty(p3, "pos", QPointF(268+150, 185+150)); + state2->assignProperty(p4, "pos", QPointF(64, 48)); + state2->assignProperty(p5, "pos", QPointF(168, 48)); + state2->assignProperty(p6, "pos", QPointF(268, 48)); state2->assignProperty(p1, "rotation", qreal(-270)); state2->assignProperty(p2, "rotation", qreal(90)); state2->assignProperty(p3, "rotation", qreal(270)); @@ -179,12 +177,12 @@ int main(int argc, char *argv[]) // State 3 state3->assignProperty(button, "text", "Switch to state 1"); - state3->assignProperty(p1, "geometry", QRectF(0, 5, 64, 64)); - state3->assignProperty(p2, "geometry", QRectF(0, 5 + 64 + 5, 64, 64)); - state3->assignProperty(p3, "geometry", QRectF(5, 5 + (64 + 5) + 64, 64, 64)); - state3->assignProperty(p4, "geometry", QRectF(5 + 64 + 5, 5, 64, 64)); - state3->assignProperty(p5, "geometry", QRectF(5 + 64 + 5, 5 + 64 + 5, 64, 64)); - state3->assignProperty(p6, "geometry", QRectF(5 + 64 + 5, 5 + (64 + 5) + 64, 64, 64)); + state3->assignProperty(p1, "pos", QPointF(0, 5)); + state3->assignProperty(p2, "pos", QPointF(0, 5 + 64 + 5)); + state3->assignProperty(p3, "pos", QPointF(5, 5 + (64 + 5) + 64)); + state3->assignProperty(p4, "pos", QPointF(5 + 64 + 5, 5)); + state3->assignProperty(p5, "pos", QPointF(5 + 64 + 5, 5 + 64 + 5)); + state3->assignProperty(p6, "pos", QPointF(5 + 64 + 5, 5 + (64 + 5) + 64)); state3->assignProperty(widget, "geometry", QRectF(138, 5, 400 - 138, 200)); state3->assignProperty(box, "geometry", QRect(5, 205, 400, 90)); state3->assignProperty(p1, "opacity", qreal(1)); @@ -194,83 +192,74 @@ int main(int argc, char *argv[]) state3->assignProperty(p5, "opacity", qreal(1)); state3->assignProperty(p6, "opacity", qreal(1)); - QParallelAnimationGroup animation1; - - QSequentialAnimationGroup *animation1SubGroup; - animation1SubGroup = new QSequentialAnimationGroup(&animation1); + QAbstractTransition *t1 = state1->addTransition(button, SIGNAL(clicked()), state2); + QSequentialAnimationGroup *animation1SubGroup = new QSequentialAnimationGroup; animation1SubGroup->addPause(250); animation1SubGroup->addAnimation(new QPropertyAnimation(box, "geometry")); + t1->addAnimation(animation1SubGroup); + t1->addAnimation(new QPropertyAnimation(widget, "geometry")); + t1->addAnimation(new QPropertyAnimation(p1, "pos")); + t1->addAnimation(new QPropertyAnimation(p2, "pos")); + t1->addAnimation(new QPropertyAnimation(p3, "pos")); + t1->addAnimation(new QPropertyAnimation(p4, "pos")); + t1->addAnimation(new QPropertyAnimation(p5, "pos")); + t1->addAnimation(new QPropertyAnimation(p6, "pos")); + t1->addAnimation(new QPropertyAnimation(p1, "rotation")); + t1->addAnimation(new QPropertyAnimation(p2, "rotation")); + t1->addAnimation(new QPropertyAnimation(p3, "rotation")); + t1->addAnimation(new QPropertyAnimation(p4, "rotation")); + t1->addAnimation(new QPropertyAnimation(p5, "rotation")); + t1->addAnimation(new QPropertyAnimation(p6, "rotation")); + t1->addAnimation(new QPropertyAnimation(p1, "opacity")); + t1->addAnimation(new QPropertyAnimation(p2, "opacity")); + t1->addAnimation(new QPropertyAnimation(p3, "opacity")); + t1->addAnimation(new QPropertyAnimation(p4, "opacity")); + t1->addAnimation(new QPropertyAnimation(p5, "opacity")); + t1->addAnimation(new QPropertyAnimation(p6, "opacity")); - animation1.addAnimation(new QPropertyAnimation(widget, "geometry")); - animation1.addAnimation(new QPropertyAnimation(p1, "geometry")); - animation1.addAnimation(new QPropertyAnimation(p2, "geometry")); - animation1.addAnimation(new QPropertyAnimation(p3, "geometry")); - animation1.addAnimation(new QPropertyAnimation(p4, "geometry")); - animation1.addAnimation(new QPropertyAnimation(p5, "geometry")); - animation1.addAnimation(new QPropertyAnimation(p6, "geometry")); - animation1.addAnimation(new QPropertyAnimation(p1, "rotation")); - animation1.addAnimation(new QPropertyAnimation(p2, "rotation")); - animation1.addAnimation(new QPropertyAnimation(p3, "rotation")); - animation1.addAnimation(new QPropertyAnimation(p4, "rotation")); - animation1.addAnimation(new QPropertyAnimation(p5, "rotation")); - animation1.addAnimation(new QPropertyAnimation(p6, "rotation")); - animation1.addAnimation(new QPropertyAnimation(p1, "opacity")); - animation1.addAnimation(new QPropertyAnimation(p2, "opacity")); - animation1.addAnimation(new QPropertyAnimation(p3, "opacity")); - animation1.addAnimation(new QPropertyAnimation(p4, "opacity")); - animation1.addAnimation(new QPropertyAnimation(p5, "opacity")); - animation1.addAnimation(new QPropertyAnimation(p6, "opacity")); - - QParallelAnimationGroup animation2; - animation2.addAnimation(new QPropertyAnimation(box, "geometry")); - animation2.addAnimation(new QPropertyAnimation(widget, "geometry")); - animation2.addAnimation(new QPropertyAnimation(p1, "geometry")); - animation2.addAnimation(new QPropertyAnimation(p2, "geometry")); - animation2.addAnimation(new QPropertyAnimation(p3, "geometry")); - animation2.addAnimation(new QPropertyAnimation(p4, "geometry")); - animation2.addAnimation(new QPropertyAnimation(p5, "geometry")); - animation2.addAnimation(new QPropertyAnimation(p6, "geometry")); - animation2.addAnimation(new QPropertyAnimation(p1, "rotation")); - animation2.addAnimation(new QPropertyAnimation(p2, "rotation")); - animation2.addAnimation(new QPropertyAnimation(p3, "rotation")); - animation2.addAnimation(new QPropertyAnimation(p4, "rotation")); - animation2.addAnimation(new QPropertyAnimation(p5, "rotation")); - animation2.addAnimation(new QPropertyAnimation(p6, "rotation")); - animation2.addAnimation(new QPropertyAnimation(p1, "opacity")); - animation2.addAnimation(new QPropertyAnimation(p2, "opacity")); - animation2.addAnimation(new QPropertyAnimation(p3, "opacity")); - animation2.addAnimation(new QPropertyAnimation(p4, "opacity")); - animation2.addAnimation(new QPropertyAnimation(p5, "opacity")); - animation2.addAnimation(new QPropertyAnimation(p6, "opacity")); - - QParallelAnimationGroup animation3; - animation3.addAnimation(new QPropertyAnimation(box, "geometry")); - animation3.addAnimation(new QPropertyAnimation(widget, "geometry")); - animation3.addAnimation(new QPropertyAnimation(p1, "geometry")); - animation3.addAnimation(new QPropertyAnimation(p2, "geometry")); - animation3.addAnimation(new QPropertyAnimation(p3, "geometry")); - animation3.addAnimation(new QPropertyAnimation(p4, "geometry")); - animation3.addAnimation(new QPropertyAnimation(p5, "geometry")); - animation3.addAnimation(new QPropertyAnimation(p6, "geometry")); - animation3.addAnimation(new QPropertyAnimation(p1, "rotation")); - animation3.addAnimation(new QPropertyAnimation(p2, "rotation")); - animation3.addAnimation(new QPropertyAnimation(p3, "rotation")); - animation3.addAnimation(new QPropertyAnimation(p4, "rotation")); - animation3.addAnimation(new QPropertyAnimation(p5, "rotation")); - animation3.addAnimation(new QPropertyAnimation(p6, "rotation")); - animation3.addAnimation(new QPropertyAnimation(p1, "opacity")); - animation3.addAnimation(new QPropertyAnimation(p2, "opacity")); - animation3.addAnimation(new QPropertyAnimation(p3, "opacity")); - animation3.addAnimation(new QPropertyAnimation(p4, "opacity")); - animation3.addAnimation(new QPropertyAnimation(p5, "opacity")); - animation3.addAnimation(new QPropertyAnimation(p6, "opacity")); - - QAbstractTransition *t1 = state1->addTransition(button, SIGNAL(clicked()), state2); - t1->addAnimation(&animation1); QAbstractTransition *t2 = state2->addTransition(button, SIGNAL(clicked()), state3); - t2->addAnimation(&animation2); + t2->addAnimation(new QPropertyAnimation(box, "geometry")); + t2->addAnimation(new QPropertyAnimation(widget, "geometry")); + t2->addAnimation(new QPropertyAnimation(p1, "pos")); + t2->addAnimation(new QPropertyAnimation(p2, "pos")); + t2->addAnimation(new QPropertyAnimation(p3, "pos")); + t2->addAnimation(new QPropertyAnimation(p4, "pos")); + t2->addAnimation(new QPropertyAnimation(p5, "pos")); + t2->addAnimation(new QPropertyAnimation(p6, "pos")); + t2->addAnimation(new QPropertyAnimation(p1, "rotation")); + t2->addAnimation(new QPropertyAnimation(p2, "rotation")); + t2->addAnimation(new QPropertyAnimation(p3, "rotation")); + t2->addAnimation(new QPropertyAnimation(p4, "rotation")); + t2->addAnimation(new QPropertyAnimation(p5, "rotation")); + t2->addAnimation(new QPropertyAnimation(p6, "rotation")); + t2->addAnimation(new QPropertyAnimation(p1, "opacity")); + t2->addAnimation(new QPropertyAnimation(p2, "opacity")); + t2->addAnimation(new QPropertyAnimation(p3, "opacity")); + t2->addAnimation(new QPropertyAnimation(p4, "opacity")); + t2->addAnimation(new QPropertyAnimation(p5, "opacity")); + t2->addAnimation(new QPropertyAnimation(p6, "opacity")); + QAbstractTransition *t3 = state3->addTransition(button, SIGNAL(clicked()), state1); - t3->addAnimation(&animation3); + t3->addAnimation(new QPropertyAnimation(box, "geometry")); + t3->addAnimation(new QPropertyAnimation(widget, "geometry")); + t3->addAnimation(new QPropertyAnimation(p1, "pos")); + t3->addAnimation(new QPropertyAnimation(p2, "pos")); + t3->addAnimation(new QPropertyAnimation(p3, "pos")); + t3->addAnimation(new QPropertyAnimation(p4, "pos")); + t3->addAnimation(new QPropertyAnimation(p5, "pos")); + t3->addAnimation(new QPropertyAnimation(p6, "pos")); + t3->addAnimation(new QPropertyAnimation(p1, "rotation")); + t3->addAnimation(new QPropertyAnimation(p2, "rotation")); + t3->addAnimation(new QPropertyAnimation(p3, "rotation")); + t3->addAnimation(new QPropertyAnimation(p4, "rotation")); + t3->addAnimation(new QPropertyAnimation(p5, "rotation")); + t3->addAnimation(new QPropertyAnimation(p6, "rotation")); + t3->addAnimation(new QPropertyAnimation(p1, "opacity")); + t3->addAnimation(new QPropertyAnimation(p2, "opacity")); + t3->addAnimation(new QPropertyAnimation(p3, "opacity")); + t3->addAnimation(new QPropertyAnimation(p4, "opacity")); + t3->addAnimation(new QPropertyAnimation(p5, "opacity")); + t3->addAnimation(new QPropertyAnimation(p6, "opacity")); machine.start(); |