Details
-
Suggestion
-
Resolution: Unresolved
-
P5: Not important
-
None
-
None
-
None
Description
Intro
I propose to introduce an alternative method to set a duration of an animation, based on the concept of "speed", instead of an absolute "duration" value. This method would not replace the current duration mechanism.
The difference is that, when speed is set and duration is not, then duration will be computed when animation starts, using speed and the difference of the starting and ending value. In other words, when animation starts, the start and end value are subtracted and divided by the speed to get the duration.
Speed = Change / Duration -> Duration = Change / Speed
Motivation
Currently, QVariantAnimation and QPropertyAnimation have methods to set a duration, start and end values. One of the starting and ending values may be not set and, in that case, the value will default to the value of the property when the animation starts (from Stopped to Running).
When start and end values are set, it is very easy to compute a duration based on a fixed speed, because the duration can be computed when setting up the animation (when QPropertyAnimation is created, for example).
On the other hand, when one of the values is not set, it is not possible to know the missing value during the creation of the animation, because it will be known when animation starts.
Therefore, if the user wants to set a duration dependent to start/end values, he needs to subclass, implement the required methods and retrieve by himself the information regarding the start/end values, handling the cases in which they are defined or not defined.
This could be solved by implementing a setSpeed method in QVariantAnimation which computes the speed as defined above, using the appropriate start and end value.
Implementation difficulties
The duration is computed as
Duration = Change / Speed
but "Change" involves QVariants: it is a distance between two variants, therefore it may be necessary to implement such distance function for the various QVariants value to be animated (euclidean distance could be used as a default distance for the supported QVariant types).
The user may be interested to specify custom distance functions, therefore it may be necessary to provide a mechanism to register those functions, similar to qRegisterAnimationInterpolator.
Beside this, the implementation should be pretty straightforward, probably can be done directly in QVariantAnimation and QPropertyAnimation could immediately benefit of it.