Qt Animation Framework reloaded

We released the first version of the animation framework quite some time ago and I guess lots of you have been wondering what we were doing. Well we've spent that time improving the API and make it work seamlessly.

So now we're proud to present you the Qt Animation Framework version 2.

What's new:
* we removed the QtState and QtTransition we had previously and replaced them with the newer and much more powerful State Machine Framework Kent blogged about a few days ago.
* the animation groups allows you to run animations in sequence or in parallel. They now are 2 distinct subclasses (QtParallelAnimationGroup and QtSequentialAnimationGroup). This allows for more specific API to each of the class.
* the animations were previously all done through QtAnimation and the support for QGraphicsItem was, let's be honest, hacked into it. Now we have added QtPropertyAnimation that adds support for QObject's property feature. We killed the explicit support for QGraphicsItem. We initially had another subclass of QtAnimation that would animate QGraphicsItem but that ended not helping much because the default QGraphicsItem can't do much (only position). If you feel like to you can still subclass QtAnimation to add support for your own types.

For animations the first-class citizen is now QtPropertyAnimation. It can handle variants and has support for easing curve, interpolation and key frames. We know that the main concern people usually have when it come to using intensively Qt's property system is that it uses QVariant which is slow. We did quite some profiling and performance is also much improved in that direction since the last version of this framework. When you want to animate "something", the only thing you need now is to add a property and then use a QtPropertyAnimation on it.

On the demo side we still have our little demos including the nice sub-attaq. API-wise the new stuff is hidden behind the scene and you'll have to have a look at the code or implement your own little demos to see the changes.

Hmmm OK we know that's not good enough!
So we know you're a big fan of stick men so here's a little video and you can see him do some actions. This demo is called stickman and is also provided with this solution (press D, C or J to change the current "action").

Here you can enjoy it before he dies ;-).

To download the solution you can go here. Don't forget to give us feedback. The new target for the framework is to be included into Qt 4.6.


Blog Topics:

Comments

?
Kromain
0 points
195 months ago

Animations on QGraphicsItem were pretty much useless, indeed :)
Now, one thing that would rock and that shouldn't be too hard to add is a bridging class between QGraphicsItemAnimation and QtAnimation, something similar to QtAnimationGroup : not an animation in itself, but it controls the QGraphicsAnimation and integrates with the rest of the framework.
This could make for a simple and sufficient solution for QGV-based animations : you get the power of QGIA, and all the features of the framework such as sequential/parallel animations, states and transitions, etc.

As a matter of fact, I might even try to hack such a briding class myself if the weather sucks during the weekend :)

... and cheers for stickman !

?
tstout
0 points
195 months ago

This really looks like it's coming along! Very nice stuff. I'm curious about QGraphicsItem. Will we still be able to use them through subclasses or are you saying the support for animating them has been removed?

?
Scorp1us
0 points
195 months ago

I can't compile. Something about a missing common.h

o main.cpp
In file included from ../../../kinetic/include/QtCore/qnamespace.h:40,
from ../../../kinetic/include/QtCore/qobjectdefs.h:40,
from ../../../kinetic/include/QtCore/qobject.h:42,
from ../../../kinetic/include/QtCore/qabstractanimation.h:40,
from ../../../kinetic/include/QtCore/QtCore:3,
from main.cpp:26:
../../../kinetic/include/QtCore/qglobal.h:1229:1: warning: "QANIMATIONEXPORT"
redefined
:7:1: warning: this is the location of the previous definition
In file included from ../../../kinetic/include/QtCore/QtCore:3,
from main.cpp:26:
../../../kinetic/include/QtCore/qabstractanimation.h:43:21: common.h: No such fi
le or directory
main.cpp:78: error: expected class-name before '{' token
main.cpp: In constructor StateSwitchTransition::StateSwitchTransition(int)': main.cpp:81: error: classStateSwitchTransition' does not have any field named
`QtAbstractTransition'

?
Scorp1us
0 points
195 months ago

Well I got the last published snapshot of the kinetic branch, and started looking at it.
It was a shame you took out the QGraphicsItem stuff. You should have been able to keep that and animate:
position
size,
opacity,
rotation (2D),
transforms (3D),

While I can do most of that I have never had luck on doing the transforms. And I certainly would like to do rotation and transform about an arbitrary point. I think neglecting Graphics Items is a huge mistake.

?
eskil
0 points
195 months ago

Scorp1us: A trick for the graphics items which do not inherit QObject is to make a proxy class which is a QObject and has property declarations for the specific properties that you want to animate. It's not ideal, but I think the issue would be minimized if more of the default graphics item types become QObjects.

?
tbastian
0 points
195 months ago

Kromain: bridging the new animation API with the exisiting QGraphicsItemAnimation could indeed be a good idea. We'll see if it makes sense to add it.

tstout: You will still be able to subclass QtAnimation and animate your own objects. In our branch we still have QItemAnimation that animates size, opacity and transform operations.

Scorp1us:
1.It seems you've got old headers somehow. common.h has disappeared... Are you trying to run the solution on top of the kinetic branch? If yes, well you shouldn't. The kinetic branch already containes the animations classes and the solution is there to add functionality to Qt 4.4 (soon 4.5).

  1. hmm you apparently have the kinetic branch. So you'll see that the QItemAnimation is there to animate size opacity and transform operations. This class operates on QGraphicsItem. However, we also have QGraphicsWidget that inherits QObject and declares properties (more to come with 4.5: opacity, geometry and pos). The idea is that if you can base your current classes on QGraphicsWidget, you'll be able to use QtPropertyAnimation, rendering QItemAnimation useless.
?
Scorp1us
0 points
195 months ago

@eskil: Yeah, I figured as much. I started work on it, but I don't know how good it will be. I don't know why QGraphicsItems don't inherit QObject... I guess that would make them a heavier-weight solution, which would not be desireable? Maybe we need a subclass that combines the two (QObject, QGraphicsItem) that would map the sensible parts?

@tbastian: Thanks, I did not notice QItemAnimation. That should be enough for me (for now!).

I am confused, though, the docs have a prefix of "Qt" and the kinetic branch I got uses just "Q" for the classes. Other than that it matches up.

In terms of what I want animated:
Opacity, Position, Scale, Rotation (X,Y,ZAxis), and finally ZValue. I realize that ZValue is probably not anticipated as an animated effect, but it does do a very nice "bring to front" effect.

Thanks I Looked at QItemAnimation and it looks like it'll work. I can hack it to add ZValue when I need it. The problem was it's not documented in the main API (snapshot) or the solution's docs.

?
eskil
0 points
195 months ago

Scorp1us: Yes, the reason was to minimize the overhead of adding an item to a scene. Since Qt 4.4 we have had the QGraphicsWidget which inherits both QObject and QGraphicsItem and which has property declared the regular graphics item properties.

"Qt" is the prefix used for Qt Solutions to distinguish the classes from Qt, which uses the "Q" prefix.

?
Scorp1us
0 points
195 months ago

How would I create a QGraphicsWidget that is also a QGraphicsPixmapItem? or QGraphicsTextItem? I read the docs, but this is not obvious. It seems like I would need to use a QLabel instead?

?
abierbaum
0 points
195 months ago

Will the animation framework be released under LGPL at some point in the future? We are planning to use Qt 4.5 under LGPL and would love to use the animation framework, but until it is released LGPL we don't have a good way to do so.

?
eskil
0 points
195 months ago

Scorp1us: At this point you would have to make a QObject which holds a pointer to the item and proxies the properties. We are looking into making QObject-based item classes.

?
Thierry
0 points
195 months ago

Scorp1us: You have 3 choices there:
1/ your subclass has to reimplement the functionality. That's the most light-weight solution. We're considering doing that on our side too.
2/ you subclass inherit QGraphics*Item and QObject and you redeclare the properties with Q_PROPERTY macro.
3/ For eanch of the items you want to animate, you create a parent that is a QGraphicsWidget and you animate this one. Not pretty but with a very small amount of items it will work.

abierbaum: The only reason it hasn't be LGPL-ed yet is that is was released before 4.5. Now that 4.5 is out, any newer release of the animation framework solution will be LGPL-ed.

?
abierbaum
0 points
194 months ago

Thierry: Any chance to relicense the existing release so those of use using 4.5 LGPL can being using it? I would love to start using all of these capabilities right now but we can't do it until it is under the LGPL license. :(