From bbd7c13d0cf9d99413f2bea9a3acfba848e3520e Mon Sep 17 00:00:00 2001 From: David Boddie Date: Wed, 20 May 2009 18:22:17 +0200 Subject: Doc: Added a small example/test case for sequential animations. Reviewed-by: Trust Me --- doc/src/snippets/animation/sequential/icons.qrc | 6 +++ .../snippets/animation/sequential/icons/left.png | Bin 0 -> 413 bytes .../snippets/animation/sequential/icons/right.png | Bin 0 -> 414 bytes doc/src/snippets/animation/sequential/main.cpp | 50 +++++++++++++++++++++ .../snippets/animation/sequential/sequential.pro | 4 ++ doc/src/snippets/animation/sequential/tracer.cpp | 25 +++++++++++ doc/src/snippets/animation/sequential/tracer.h | 23 ++++++++++ 7 files changed, 108 insertions(+) create mode 100644 doc/src/snippets/animation/sequential/icons.qrc create mode 100644 doc/src/snippets/animation/sequential/icons/left.png create mode 100644 doc/src/snippets/animation/sequential/icons/right.png create mode 100644 doc/src/snippets/animation/sequential/main.cpp create mode 100644 doc/src/snippets/animation/sequential/sequential.pro create mode 100644 doc/src/snippets/animation/sequential/tracer.cpp create mode 100644 doc/src/snippets/animation/sequential/tracer.h diff --git a/doc/src/snippets/animation/sequential/icons.qrc b/doc/src/snippets/animation/sequential/icons.qrc new file mode 100644 index 0000000..d55f797 --- /dev/null +++ b/doc/src/snippets/animation/sequential/icons.qrc @@ -0,0 +1,6 @@ + + + icons/left.png + icons/right.png + + diff --git a/doc/src/snippets/animation/sequential/icons/left.png b/doc/src/snippets/animation/sequential/icons/left.png new file mode 100644 index 0000000..5dd8da0 Binary files /dev/null and b/doc/src/snippets/animation/sequential/icons/left.png differ diff --git a/doc/src/snippets/animation/sequential/icons/right.png b/doc/src/snippets/animation/sequential/icons/right.png new file mode 100644 index 0000000..ac61326 Binary files /dev/null and b/doc/src/snippets/animation/sequential/icons/right.png differ diff --git a/doc/src/snippets/animation/sequential/main.cpp b/doc/src/snippets/animation/sequential/main.cpp new file mode 100644 index 0000000..aff8f29 --- /dev/null +++ b/doc/src/snippets/animation/sequential/main.cpp @@ -0,0 +1,50 @@ +#include +#include +#include +#include +#include "tracer.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + + QWidget window; + window.resize(720, 96); + window.show(); + + QLabel *label1 = new QLabel(&window); + label1->setPixmap(QPixmap(":/icons/left.png")); + label1->move(16, 16); + label1->show(); + + QLabel *label2 = new QLabel(&window); + label2->setPixmap(QPixmap(":/icons/right.png")); + label2->move(320, 16); + label2->show(); + + QPropertyAnimation *anim1 = new QPropertyAnimation(label1, "pos"); + anim1->setDuration(2500); + anim1->setStartValue(QPoint(16, 16)); + anim1->setEndValue(QPoint(320, 16)); + + QPropertyAnimation *anim2 = new QPropertyAnimation(label2, "pos"); + anim2->setDuration(2500); + anim2->setStartValue(QPoint(320, 16)); + anim2->setEndValue(QPoint(640, 16)); + + QSequentialAnimationGroup group; + group.addAnimation(anim1); + group.addAnimation(anim2); + + Tracer tracer(&window); + + QObject::connect(anim1, SIGNAL(valueChanged(QVariant)), + &tracer, SLOT(recordValue(QVariant))); + QObject::connect(anim2, SIGNAL(valueChanged(QVariant)), + &tracer, SLOT(recordValue(QVariant))); + QObject::connect(anim1, SIGNAL(finished()), &tracer, SLOT(checkValue())); + QObject::connect(anim2, SIGNAL(finished()), &tracer, SLOT(checkValue())); + + group.start(); + return app.exec(); +} diff --git a/doc/src/snippets/animation/sequential/sequential.pro b/doc/src/snippets/animation/sequential/sequential.pro new file mode 100644 index 0000000..fcf017f --- /dev/null +++ b/doc/src/snippets/animation/sequential/sequential.pro @@ -0,0 +1,4 @@ +HEADERS = tracer.h +RESOURCES = icons.qrc +SOURCES = main.cpp \ + tracer.cpp diff --git a/doc/src/snippets/animation/sequential/tracer.cpp b/doc/src/snippets/animation/sequential/tracer.cpp new file mode 100644 index 0000000..49bd51e --- /dev/null +++ b/doc/src/snippets/animation/sequential/tracer.cpp @@ -0,0 +1,25 @@ +#include +#include +#include +#include "tracer.h" + +Tracer::Tracer(QObject *parent) + : QObject(parent) +{ +} + +void Tracer::checkValue() +{ + QAbstractAnimation *animation = static_cast(sender()); + if (time != animation->duration()) { + qDebug() << "Animation's last recorded time" << time; + qDebug() << "Expected" << animation->duration(); + } +} + +void Tracer::recordValue(const QVariant &value) +{ + QAbstractAnimation *animation = static_cast(sender()); + this->value = value; + time = animation->currentTime(); +} diff --git a/doc/src/snippets/animation/sequential/tracer.h b/doc/src/snippets/animation/sequential/tracer.h new file mode 100644 index 0000000..1adb018 --- /dev/null +++ b/doc/src/snippets/animation/sequential/tracer.h @@ -0,0 +1,23 @@ +#ifndef TRACER_H +#define TRACER_H + +#include +#include + +class Tracer : public QObject +{ + Q_OBJECT + +public: + Tracer(QObject *parent = 0); + +public slots: + void checkValue(); + void recordValue(const QVariant &value); + +private: + QVariant value; + int time; +}; + +#endif -- cgit v0.12