summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Brasser <michael.brasser@nokia.com>2009-11-11 01:37:15 (GMT)
committerMichael Brasser <michael.brasser@nokia.com>2009-11-11 01:37:15 (GMT)
commit318775ded2371b4033b9a06ffec23e75c6dbad96 (patch)
tree977a140f2453e71c013529b44849f6f7ef30fa73
parent24ee7d2fe5481658f350172b9c211bc3b4d89a65 (diff)
downloadQt-318775ded2371b4033b9a06ffec23e75c6dbad96.zip
Qt-318775ded2371b4033b9a06ffec23e75c6dbad96.tar.gz
Qt-318775ded2371b4033b9a06ffec23e75c6dbad96.tar.bz2
AnimatedImage cleanup and tests.
-rw-r--r--src/declarative/extra/extra.pri3
-rw-r--r--src/declarative/graphicsitems/graphicsitems.pri3
-rw-r--r--src/declarative/graphicsitems/qmlgraphicsanimatedimage.cpp (renamed from src/declarative/extra/qmlgraphicsanimatedimageitem.cpp)71
-rw-r--r--src/declarative/graphicsitems/qmlgraphicsanimatedimage_p.h (renamed from src/declarative/extra/qmlgraphicsanimatedimageitem_p.h)19
-rw-r--r--src/declarative/graphicsitems/qmlgraphicsanimatedimage_p_p.h (renamed from src/declarative/extra/qmlgraphicsanimatedimageitem_p_p.h)6
-rw-r--r--tests/auto/declarative/animatedimage/data/colors.gifbin0 -> 505 bytes
-rw-r--r--tests/auto/declarative/animatedimage/data/colors.qml5
-rw-r--r--tests/auto/declarative/animatedimage/data/stickmanstopped.qml6
-rw-r--r--tests/auto/declarative/animatedimage/tst_animatedimage.cpp38
9 files changed, 92 insertions, 59 deletions
diff --git a/src/declarative/extra/extra.pri b/src/declarative/extra/extra.pri
index 78272a9..85ff6ea 100644
--- a/src/declarative/extra/extra.pri
+++ b/src/declarative/extra/extra.pri
@@ -2,7 +2,6 @@ SOURCES += \
extra/qnumberformat.cpp \
extra/qmlnumberformatter.cpp \
extra/qmldatetimeformatter.cpp \
- extra/qmlgraphicsanimatedimageitem.cpp \
extra/qmlbehavior.cpp \
extra/qmlfontloader.cpp
@@ -10,8 +9,6 @@ HEADERS += \
extra/qnumberformat_p.h \
extra/qmlnumberformatter_p.h \
extra/qmldatetimeformatter_p.h \
- extra/qmlgraphicsanimatedimageitem_p.h \
- extra/qmlgraphicsanimatedimageitem_p_p.h \
extra/qmlbehavior_p.h \
extra/qmlfontloader_p.h
diff --git a/src/declarative/graphicsitems/graphicsitems.pri b/src/declarative/graphicsitems/graphicsitems.pri
index 3c4e39a..ef10e51 100644
--- a/src/declarative/graphicsitems/graphicsitems.pri
+++ b/src/declarative/graphicsitems/graphicsitems.pri
@@ -14,6 +14,8 @@ HEADERS += \
graphicsitems/qmlgraphicsimage_p_p.h \
graphicsitems/qmlgraphicsborderimage_p_p.h \
graphicsitems/qmlgraphicsimagebase_p_p.h \
+ graphicsitems/qmlgraphicsanimatedimage_p.h \
+ graphicsitems/qmlgraphicsanimatedimage_p_p.h \
graphicsitems/qmlgraphicsitem.h \
graphicsitems/qmlgraphicsitem_p.h \
graphicsitems/qmlgraphicsfocuspanel_p.h \
@@ -55,6 +57,7 @@ SOURCES += \
graphicsitems/qmlgraphicsimage.cpp \
graphicsitems/qmlgraphicsborderimage.cpp \
graphicsitems/qmlgraphicsimagebase.cpp \
+ graphicsitems/qmlgraphicsanimatedimage.cpp \
graphicsitems/qmlgraphicspainteditem.cpp \
graphicsitems/qmlgraphicsitem.cpp \
graphicsitems/qmlgraphicsfocuspanel.cpp \
diff --git a/src/declarative/extra/qmlgraphicsanimatedimageitem.cpp b/src/declarative/graphicsitems/qmlgraphicsanimatedimage.cpp
index 2405bde..db28134 100644
--- a/src/declarative/extra/qmlgraphicsanimatedimageitem.cpp
+++ b/src/declarative/graphicsitems/qmlgraphicsanimatedimage.cpp
@@ -41,20 +41,20 @@
#include <QMovie>
#include <QtDeclarative/qmlengine.h>
-#include "qmlgraphicsanimatedimageitem_p.h"
-#include "qmlgraphicsanimatedimageitem_p_p.h"
+#include "qmlgraphicsanimatedimage_p.h"
+#include "qmlgraphicsanimatedimage_p_p.h"
#include <QNetworkRequest>
#include <QNetworkReply>
QT_BEGIN_NAMESPACE
/*!
- \class QmlGraphicsAnimatedImageItem
+ \class QmlGraphicsAnimatedImage
\internal
*/
/*!
- \qmlclass AnimatedImage QFxAnimatedImageItem
+ \qmlclass AnimatedImage QmlGraphicsAnimatedImage
\inherits Image
This item provides for playing animations stored as images containing a series of frames,
@@ -76,21 +76,16 @@ Item {
\endqml
\endtable
*/
-QML_DEFINE_TYPE(Qt,4,6,AnimatedImage,QmlGraphicsAnimatedImageItem)
+QML_DEFINE_TYPE(Qt,4,6,AnimatedImage,QmlGraphicsAnimatedImage)
-QmlGraphicsAnimatedImageItem::QmlGraphicsAnimatedImageItem(QmlGraphicsItem *parent)
- : QmlGraphicsImage(*(new QmlGraphicsAnimatedImageItemPrivate), parent)
+QmlGraphicsAnimatedImage::QmlGraphicsAnimatedImage(QmlGraphicsItem *parent)
+ : QmlGraphicsImage(*(new QmlGraphicsAnimatedImagePrivate), parent)
{
}
-QmlGraphicsAnimatedImageItem::QmlGraphicsAnimatedImageItem(QmlGraphicsAnimatedImageItemPrivate &dd, QmlGraphicsItem *parent)
- : QmlGraphicsImage(dd, parent)
+QmlGraphicsAnimatedImage::~QmlGraphicsAnimatedImage()
{
-}
-
-QmlGraphicsAnimatedImageItem::~QmlGraphicsAnimatedImageItem()
-{
- Q_D(QmlGraphicsAnimatedImageItem);
+ Q_D(QmlGraphicsAnimatedImage);
delete d->_movie;
}
@@ -100,17 +95,17 @@ QmlGraphicsAnimatedImageItem::~QmlGraphicsAnimatedImageItem()
Defaults to false, and can be set to true when you want to pause.
*/
-bool QmlGraphicsAnimatedImageItem::isPaused() const
+bool QmlGraphicsAnimatedImage::isPaused() const
{
- Q_D(const QmlGraphicsAnimatedImageItem);
+ Q_D(const QmlGraphicsAnimatedImage);
if(!d->_movie)
return false;
return d->_movie->state()==QMovie::Paused;
}
-void QmlGraphicsAnimatedImageItem::setPaused(bool pause)
+void QmlGraphicsAnimatedImage::setPaused(bool pause)
{
- Q_D(QmlGraphicsAnimatedImageItem);
+ Q_D(QmlGraphicsAnimatedImage);
if(pause == d->paused)
return;
d->paused = pause;
@@ -124,17 +119,17 @@ void QmlGraphicsAnimatedImageItem::setPaused(bool pause)
Defaults to true, so as to start playing immediately.
*/
-bool QmlGraphicsAnimatedImageItem::isPlaying() const
+bool QmlGraphicsAnimatedImage::isPlaying() const
{
- Q_D(const QmlGraphicsAnimatedImageItem);
+ Q_D(const QmlGraphicsAnimatedImage);
if (!d->_movie)
return false;
return d->_movie->state()!=QMovie::NotRunning;
}
-void QmlGraphicsAnimatedImageItem::setPlaying(bool play)
+void QmlGraphicsAnimatedImage::setPlaying(bool play)
{
- Q_D(QmlGraphicsAnimatedImageItem);
+ Q_D(QmlGraphicsAnimatedImage);
if(play == d->playing)
return;
d->playing = play;
@@ -154,17 +149,17 @@ void QmlGraphicsAnimatedImageItem::setPlaying(bool play)
allow other things to animate at the same time as the image. frameCount is the number
of frames in the animation. For some animation formats, frameCount is unknown and set to zero.
*/
-int QmlGraphicsAnimatedImageItem::currentFrame() const
+int QmlGraphicsAnimatedImage::currentFrame() const
{
- Q_D(const QmlGraphicsAnimatedImageItem);
+ Q_D(const QmlGraphicsAnimatedImage);
if (!d->_movie)
return d->preset_currentframe;
return d->_movie->currentFrameNumber();
}
-void QmlGraphicsAnimatedImageItem::setCurrentFrame(int frame)
+void QmlGraphicsAnimatedImage::setCurrentFrame(int frame)
{
- Q_D(QmlGraphicsAnimatedImageItem);
+ Q_D(QmlGraphicsAnimatedImage);
if (!d->_movie) {
d->preset_currentframe = frame;
return;
@@ -172,9 +167,9 @@ void QmlGraphicsAnimatedImageItem::setCurrentFrame(int frame)
d->_movie->jumpToFrame(frame);
}
-int QmlGraphicsAnimatedImageItem::frameCount() const
+int QmlGraphicsAnimatedImage::frameCount() const
{
- Q_D(const QmlGraphicsAnimatedImageItem);
+ Q_D(const QmlGraphicsAnimatedImage);
if (!d->_movie)
return 0;
return d->_movie->frameCount();
@@ -188,9 +183,9 @@ static QString toLocalFileOrQrc(const QUrl& url)
return r;
}
-void QmlGraphicsAnimatedImageItem::setSource(const QUrl &url)
+void QmlGraphicsAnimatedImage::setSource(const QUrl &url)
{
- Q_D(QmlGraphicsAnimatedImageItem);
+ Q_D(QmlGraphicsAnimatedImage);
if (url == d->url)
return;
@@ -249,9 +244,9 @@ void QmlGraphicsAnimatedImageItem::setSource(const QUrl &url)
emit statusChanged(d->status);
}
-void QmlGraphicsAnimatedImageItem::movieRequestFinished()
+void QmlGraphicsAnimatedImage::movieRequestFinished()
{
- Q_D(QmlGraphicsAnimatedImageItem);
+ Q_D(QmlGraphicsAnimatedImage);
d->_movie = new QMovie(d->reply);
if (!d->_movie->isValid()){
qWarning() << "Error Reading Animated Image File " << d->url;
@@ -275,16 +270,16 @@ void QmlGraphicsAnimatedImageItem::movieRequestFinished()
d->setPixmap(d->_movie->currentPixmap());
}
-void QmlGraphicsAnimatedImageItem::movieUpdate()
+void QmlGraphicsAnimatedImage::movieUpdate()
{
- Q_D(QmlGraphicsAnimatedImageItem);
+ Q_D(QmlGraphicsAnimatedImage);
d->setPixmap(d->_movie->currentPixmap());
emit frameChanged();
}
-void QmlGraphicsAnimatedImageItem::playingStatusChanged()
+void QmlGraphicsAnimatedImage::playingStatusChanged()
{
- Q_D(QmlGraphicsAnimatedImageItem);
+ Q_D(QmlGraphicsAnimatedImage);
if((d->_movie->state() != QMovie::NotRunning) != d->playing){
d->playing = (d->_movie->state() != QMovie::NotRunning);
emit playingChanged();
@@ -295,9 +290,9 @@ void QmlGraphicsAnimatedImageItem::playingStatusChanged()
}
}
-void QmlGraphicsAnimatedImageItem::componentComplete()
+void QmlGraphicsAnimatedImage::componentComplete()
{
- Q_D(QmlGraphicsAnimatedImageItem);
+ Q_D(QmlGraphicsAnimatedImage);
setCurrentFrame(d->preset_currentframe);
d->preset_currentframe = 0;
}
diff --git a/src/declarative/extra/qmlgraphicsanimatedimageitem_p.h b/src/declarative/graphicsitems/qmlgraphicsanimatedimage_p.h
index b581ea3..79daa0f 100644
--- a/src/declarative/extra/qmlgraphicsanimatedimageitem_p.h
+++ b/src/declarative/graphicsitems/qmlgraphicsanimatedimage_p.h
@@ -39,8 +39,8 @@
**
****************************************************************************/
-#ifndef QMLGRAPHICSANIMATEDIMAGEITEM_H
-#define QMLGRAPHICSANIMATEDIMAGEITEM_H
+#ifndef QMLGRAPHICSANIMATEDIMAGE_H
+#define QMLGRAPHICSANIMATEDIMAGE_H
#include <private/qmlgraphicsimage_p.h>
@@ -51,9 +51,9 @@ QT_BEGIN_NAMESPACE
QT_MODULE(Declarative)
class QMovie;
-class QmlGraphicsAnimatedImageItemPrivate;
+class QmlGraphicsAnimatedImagePrivate;
-class Q_DECLARATIVE_EXPORT QmlGraphicsAnimatedImageItem : public QmlGraphicsImage
+class Q_DECLARATIVE_EXPORT QmlGraphicsAnimatedImage : public QmlGraphicsImage
{
Q_OBJECT
@@ -62,8 +62,8 @@ class Q_DECLARATIVE_EXPORT QmlGraphicsAnimatedImageItem : public QmlGraphicsImag
Q_PROPERTY(int currentFrame READ currentFrame WRITE setCurrentFrame NOTIFY frameChanged)
Q_PROPERTY(int frameCount READ frameCount)
public:
- QmlGraphicsAnimatedImageItem(QmlGraphicsItem *parent=0);
- ~QmlGraphicsAnimatedImageItem();
+ QmlGraphicsAnimatedImage(QmlGraphicsItem *parent=0);
+ ~QmlGraphicsAnimatedImage();
bool isPlaying() const;
void setPlaying(bool play);
@@ -90,17 +90,16 @@ private Q_SLOTS:
void playingStatusChanged();
protected:
- QmlGraphicsAnimatedImageItem(QmlGraphicsAnimatedImageItemPrivate &dd, QmlGraphicsItem *parent);
void componentComplete();
private:
- Q_DISABLE_COPY(QmlGraphicsAnimatedImageItem)
- Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsAnimatedImageItem)
+ Q_DISABLE_COPY(QmlGraphicsAnimatedImage)
+ Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsAnimatedImage)
};
QT_END_NAMESPACE
-QML_DECLARE_TYPE(QmlGraphicsAnimatedImageItem)
+QML_DECLARE_TYPE(QmlGraphicsAnimatedImage)
QT_END_HEADER
diff --git a/src/declarative/extra/qmlgraphicsanimatedimageitem_p_p.h b/src/declarative/graphicsitems/qmlgraphicsanimatedimage_p_p.h
index 2256b9b..c24afa0 100644
--- a/src/declarative/extra/qmlgraphicsanimatedimageitem_p_p.h
+++ b/src/declarative/graphicsitems/qmlgraphicsanimatedimage_p_p.h
@@ -60,12 +60,12 @@ QT_BEGIN_NAMESPACE
class QMovie;
class QNetworkReply;
-class QmlGraphicsAnimatedImageItemPrivate : public QmlGraphicsImagePrivate
+class QmlGraphicsAnimatedImagePrivate : public QmlGraphicsImagePrivate
{
- Q_DECLARE_PUBLIC(QmlGraphicsAnimatedImageItem)
+ Q_DECLARE_PUBLIC(QmlGraphicsAnimatedImage)
public:
- QmlGraphicsAnimatedImageItemPrivate()
+ QmlGraphicsAnimatedImagePrivate()
: playing(true), paused(false), preset_currentframe(0), _movie(0), reply(0)
{
}
diff --git a/tests/auto/declarative/animatedimage/data/colors.gif b/tests/auto/declarative/animatedimage/data/colors.gif
new file mode 100644
index 0000000..1270bfa
--- /dev/null
+++ b/tests/auto/declarative/animatedimage/data/colors.gif
Binary files differ
diff --git a/tests/auto/declarative/animatedimage/data/colors.qml b/tests/auto/declarative/animatedimage/data/colors.qml
new file mode 100644
index 0000000..5bada34
--- /dev/null
+++ b/tests/auto/declarative/animatedimage/data/colors.qml
@@ -0,0 +1,5 @@
+import Qt 4.6
+
+AnimatedImage {
+ source: "colors.gif"
+}
diff --git a/tests/auto/declarative/animatedimage/data/stickmanstopped.qml b/tests/auto/declarative/animatedimage/data/stickmanstopped.qml
new file mode 100644
index 0000000..53b0c3a
--- /dev/null
+++ b/tests/auto/declarative/animatedimage/data/stickmanstopped.qml
@@ -0,0 +1,6 @@
+import Qt 4.6
+
+AnimatedImage {
+ source: "stickman.gif"
+ playing: false
+}
diff --git a/tests/auto/declarative/animatedimage/tst_animatedimage.cpp b/tests/auto/declarative/animatedimage/tst_animatedimage.cpp
index 262ddda..484fd1a 100644
--- a/tests/auto/declarative/animatedimage/tst_animatedimage.cpp
+++ b/tests/auto/declarative/animatedimage/tst_animatedimage.cpp
@@ -44,7 +44,7 @@
#include <QtDeclarative/qmlview.h>
#include <private/qmlgraphicsrectangle_p.h>
#include <private/qmlgraphicsimage_p.h>
-#include <private/qmlgraphicsanimatedimageitem_p.h>
+#include <private/qmlgraphicsanimatedimage_p.h>
class tst_animatedimage : public QObject
{
@@ -55,6 +55,7 @@ public:
private slots:
void play();
void pause();
+ void stopped();
void setFrame();
void frameCount();
};
@@ -63,34 +64,61 @@ void tst_animatedimage::play()
{
QmlEngine engine;
QmlComponent component(&engine, QUrl("file://" SRCDIR "/data/stickman.qml"));
- QmlGraphicsAnimatedImageItem *anim = qobject_cast<QmlGraphicsAnimatedImageItem *>(component.create());
+ QmlGraphicsAnimatedImage *anim = qobject_cast<QmlGraphicsAnimatedImage *>(component.create());
QVERIFY(anim);
QVERIFY(anim->isPlaying());
+
+ delete anim;
}
void tst_animatedimage::pause()
{
QmlEngine engine;
QmlComponent component(&engine, QUrl("file://" SRCDIR "/data/stickmanpause.qml"));
- QmlGraphicsAnimatedImageItem *anim = qobject_cast<QmlGraphicsAnimatedImageItem *>(component.create());
+ QmlGraphicsAnimatedImage *anim = qobject_cast<QmlGraphicsAnimatedImage *>(component.create());
QVERIFY(anim);
QVERIFY(anim->isPlaying());
QVERIFY(anim->isPaused());
+
+ delete anim;
+}
+
+void tst_animatedimage::stopped()
+{
+ QmlEngine engine;
+ QmlComponent component(&engine, QUrl("file://" SRCDIR "/data/stickmanstopped.qml"));
+ QmlGraphicsAnimatedImage *anim = qobject_cast<QmlGraphicsAnimatedImage *>(component.create());
+ QVERIFY(anim);
+ QVERIFY(!anim->isPlaying());
+ QCOMPARE(anim->currentFrame(), 0);
+
+ delete anim;
}
void tst_animatedimage::setFrame()
{
QmlEngine engine;
QmlComponent component(&engine, QUrl("file://" SRCDIR "/data/stickmanpause.qml"));
- QmlGraphicsAnimatedImageItem *anim = qobject_cast<QmlGraphicsAnimatedImageItem *>(component.create());
+ QmlGraphicsAnimatedImage *anim = qobject_cast<QmlGraphicsAnimatedImage *>(component.create());
QVERIFY(anim);
QVERIFY(anim->isPlaying());
QCOMPARE(anim->currentFrame(), 2);
+
+ delete anim;
}
void tst_animatedimage::frameCount()
{
- // GIF doesn't support frameCount until first pass through
+ QmlEngine engine;
+ QmlComponent component(&engine, QUrl("file://" SRCDIR "/data/colors.qml"));
+ QmlGraphicsAnimatedImage *anim = qobject_cast<QmlGraphicsAnimatedImage *>(component.create());
+ QVERIFY(anim);
+ QVERIFY(anim->isPlaying());
+ QCOMPARE(anim->frameCount(), 0); // GIF doesn't support frameCount until first pass through
+ QTest::qWait(600 + 100);
+ QCOMPARE(anim->frameCount(), 3);
+
+ delete anim;
}
QTEST_MAIN(tst_animatedimage)