Qt 4.8
|
The QEasingCurve class provides easing curves for controlling animation. More...
#include <qeasingcurve.h>
Public Types | |
typedef qreal(* | EasingFunction) (qreal progress) |
This is a typedef for a pointer to a function with the following signature: More... | |
enum | Type { Linear, InQuad, OutQuad, InOutQuad, OutInQuad, InCubic, OutCubic, InOutCubic, OutInCubic, InQuart, OutQuart, InOutQuart, OutInQuart, InQuint, OutQuint, InOutQuint, OutInQuint, InSine, OutSine, InOutSine, OutInSine, InExpo, OutExpo, InOutExpo, OutInExpo, InCirc, OutCirc, InOutCirc, OutInCirc, InElastic, OutElastic, InOutElastic, OutInElastic, InBack, OutBack, InOutBack, OutInBack, InBounce, OutBounce, InOutBounce, OutInBounce, InCurve, OutCurve, SineCurve, CosineCurve, Custom, NCurveTypes } |
The type of easing curve. More... | |
Public Functions | |
qreal | amplitude () const |
Returns the amplitude. More... | |
EasingFunction | customType () const |
Returns the function pointer to the custom easing curve. More... | |
bool | operator!= (const QEasingCurve &other) const |
Compare this easing curve with other and returns true if they are not equal. More... | |
QEasingCurve & | operator= (const QEasingCurve &other) |
Copy other. More... | |
bool | operator== (const QEasingCurve &other) const |
Compare this easing curve with other and returns true if they are equal. More... | |
qreal | overshoot () const |
Returns the overshoot. More... | |
qreal | period () const |
Returns the period. More... | |
QEasingCurve (Type type=Linear) | |
Constructs an easing curve of the given type. More... | |
QEasingCurve (const QEasingCurve &other) | |
Construct a copy of other. More... | |
void | setAmplitude (qreal amplitude) |
Sets the amplitude to amplitude. More... | |
void | setCustomType (EasingFunction func) |
Sets a custom easing curve that is defined by the user in the function func. More... | |
void | setOvershoot (qreal overshoot) |
Sets the overshoot to overshoot. More... | |
void | setPeriod (qreal period) |
Sets the period to period. More... | |
void | setType (Type type) |
Sets the type of the easing curve to type. More... | |
Type | type () const |
Returns the type of the easing curve. More... | |
qreal | valueForProgress (qreal progress) const |
Return the effective progress for the easing curve at progress. More... | |
~QEasingCurve () | |
Destructor. More... | |
Properties | |
QEasingCurvePrivate * | d_ptr |
Friends | |
Q_CORE_EXPORT QDebug | operator<< (QDebug debug, const QEasingCurve &item) |
Q_CORE_EXPORT QDataStream & | operator<< (QDataStream &, const QEasingCurve &) |
Writes the given easing curve to the given stream and returns a reference to the stream. More... | |
Q_CORE_EXPORT QDataStream & | operator>> (QDataStream &, QEasingCurve &) |
The QEasingCurve class provides easing curves for controlling animation.
Easing curves describe a function that controls how the speed of the interpolation between 0 and 1 should be. Easing curves allow transitions from one value to another to appear more natural than a simple constant speed would allow. The QEasingCurve class is usually used in conjunction with the QVariantAnimation and QPropertyAnimation classes but can be used on its own. It is usually used to accelerate the interpolation from zero velocity (ease in) or decelerate to zero velocity (ease out). Ease in and ease out can also be combined in the same easing curve.
To calculate the speed of the interpolation, the easing curve provides the function valueForProgress(), where the progress argument specifies the progress of the interpolation: 0 is the start value of the interpolation, 1 is the end value of the interpolation. The returned value is the effective progress of the interpolation. If the returned value is the same as the input value for all input values the easing curve is a linear curve. This is the default behaviour.
For example,
will print the effective progress of the interpolation between 0 and 1.
When using a QPropertyAnimation, the associated easing curve will be used to control the progress of the interpolation between startValue and endValue:
The ability to set an amplitude, overshoot, or period depends on the QEasingCurve type. Amplitude access is available to curves that behave as springs such as elastic and bounce curves. Changing the amplitude changes the height of the curve. Period access is only available to elastic curves and setting a higher period slows the rate of bounce. Only curves that have "boomerang" behaviors such as the InBack, OutBack, InOutBack, and OutInBack have overshoot settings. These curves will interpolate beyond the end points and return to the end point, acting similar to a boomerang.
The Easing Curves Example contains samples of QEasingCurve types and lets you change the curve settings.
Definition at line 55 of file qeasingcurve.h.
QEasingCurve::EasingFunction |
This is a typedef for a pointer to a function with the following signature:
Definition at line 96 of file qeasingcurve.h.
enum QEasingCurve::Type |
The type of easing curve.
Easing curve for a linear (t) function: velocity is constant.
Easing curve for a quadratic (t^2) function: accelerating from zero velocity.
Easing curve for a quadratic (t^2) function: decelerating to zero velocity.
Easing curve for a quadratic (t^2) function: acceleration until halfway, then deceleration.
Easing curve for a quadratic (t^2) function: deceleration until halfway, then acceleration.
Easing curve for a cubic (t^3) function: accelerating from zero velocity.
Easing curve for a cubic (t^3) function: decelerating to zero velocity.
Easing curve for a cubic (t^3) function: acceleration until halfway, then deceleration.
Easing curve for a cubic (t^3) function: deceleration until halfway, then acceleration.
Easing curve for a quartic (t^4) function: accelerating from zero velocity.
Easing curve for a quartic (t^4) function: decelerating to zero velocity.
Easing curve for a quartic (t^4) function: acceleration until halfway, then deceleration.
Easing curve for a quartic (t^4) function: deceleration until halfway, then acceleration.
Easing curve for a quintic (t^5) easing in: accelerating from zero velocity.
Easing curve for a quintic (t^5) function: decelerating to zero velocity.
Easing curve for a quintic (t^5) function: acceleration until halfway, then deceleration.
Easing curve for a quintic (t^5) function: deceleration until halfway, then acceleration.
Easing curve for a sinusoidal (sin(t)) function: accelerating from zero velocity.
Easing curve for a sinusoidal (sin(t)) function: decelerating from zero velocity.
Easing curve for a sinusoidal (sin(t)) function: acceleration until halfway, then deceleration.
Easing curve for a sinusoidal (sin(t)) function: deceleration until halfway, then acceleration.
Easing curve for an exponential (2^t) function: accelerating from zero velocity.
Easing curve for an exponential (2^t) function: decelerating from zero velocity.
Easing curve for an exponential (2^t) function: acceleration until halfway, then deceleration.
Easing curve for an exponential (2^t) function: deceleration until halfway, then acceleration.
Easing curve for a circular (sqrt(1-t^2)) function: accelerating from zero velocity.
Easing curve for a circular (sqrt(1-t^2)) function: decelerating from zero velocity.
Easing curve for a circular (sqrt(1-t^2)) function: acceleration until halfway, then deceleration.
Easing curve for a circular (sqrt(1-t^2)) function: deceleration until halfway, then acceleration.
Easing curve for an elastic (exponentially decaying sine wave) function: accelerating from zero velocity. The peak amplitude can be set with the \e amplitude parameter, and the period of decay by the \e period parameter.
Easing curve for an elastic (exponentially decaying sine wave) function: decelerating from zero velocity. The peak amplitude can be set with the \e amplitude parameter, and the period of decay by the \e period parameter.
Easing curve for an elastic (exponentially decaying sine wave) function: acceleration until halfway, then deceleration.
Easing curve for an elastic (exponentially decaying sine wave) function: deceleration until halfway, then acceleration.
Easing curve for a back (overshooting cubic function: (s+1)*t^3 - s*t^2) easing in: accelerating from zero velocity.
Easing curve for a back (overshooting cubic function: (s+1)*t^3 - s*t^2) easing out: decelerating to zero velocity.
Easing curve for a back (overshooting cubic function: (s+1)*t^3 - s*t^2) easing in/out: acceleration until halfway, then deceleration.
Easing curve for a back (overshooting cubic easing: (s+1)*t^3 - s*t^2) easing out/in: deceleration until halfway, then acceleration.
Easing curve for a bounce (exponentially decaying parabolic bounce) function: accelerating from zero velocity.
Easing curve for a bounce (exponentially decaying parabolic bounce) function: decelerating from zero velocity.
Easing curve for a bounce (exponentially decaying parabolic bounce) function easing in/out: acceleration until halfway, then deceleration.
Easing curve for a bounce (exponentially decaying parabolic bounce) function easing out/in: deceleration until halfway, then acceleration.
Definition at line 60 of file qeasingcurve.h.
Constructs an easing curve of the given type.
Definition at line 615 of file qeasingcurve.cpp.
QEasingCurve::QEasingCurve | ( | const QEasingCurve & | other | ) |
Construct a copy of other.
Definition at line 624 of file qeasingcurve.cpp.
QEasingCurve::~QEasingCurve | ( | ) |
qreal QEasingCurve::amplitude | ( | ) | const |
Returns the amplitude.
This is not applicable for all curve types. It is only applicable for bounce and elastic curves (curves of type() QEasingCurve::InBounce, QEasingCurve::OutBounce, QEasingCurve::InOutBounce, QEasingCurve::OutInBounce, QEasingCurve::InElastic, QEasingCurve::OutElastic, QEasingCurve::InOutElastic or QEasingCurve::OutInElastic).
Definition at line 701 of file qeasingcurve.cpp.
Referenced by operator==(), setAmplitude(), and QDeclarativeEasingValueType::setValue().
QEasingCurve::EasingFunction QEasingCurve::customType | ( | ) | const |
Returns the function pointer to the custom easing curve.
If type() does not return QEasingCurve::Custom, this function will return 0.
Definition at line 847 of file qeasingcurve.cpp.
|
inline |
Compare this easing curve with other and returns true if they are not equal.
It will also compare the properties of a curve.
Definition at line 82 of file qeasingcurve.h.
QEasingCurve & QEasingCurve::operator= | ( | const QEasingCurve & | other | ) |
Copy other.
Definition at line 645 of file qeasingcurve.cpp.
bool QEasingCurve::operator== | ( | const QEasingCurve & | other | ) | const |
Compare this easing curve with other and returns true if they are equal.
It will also compare the properties of a curve.
Definition at line 664 of file qeasingcurve.cpp.
qreal QEasingCurve::overshoot | ( | ) | const |
Returns the overshoot.
This is not applicable for all curve types. It is only applicable if type() is QEasingCurve::InBack, QEasingCurve::OutBack, QEasingCurve::InOutBack or QEasingCurve::OutInBack.
Definition at line 749 of file qeasingcurve.cpp.
Referenced by operator==(), setOvershoot(), QEasingCurvePrivate::setType_helper(), and QDeclarativeEasingValueType::setValue().
qreal QEasingCurve::period | ( | ) | const |
Returns the period.
This is not applicable for all curve types. It is only applicable if type() is QEasingCurve::InElastic, QEasingCurve::OutElastic, QEasingCurve::InOutElastic or QEasingCurve::OutInElastic.
Definition at line 725 of file qeasingcurve.cpp.
Referenced by operator==(), setPeriod(), QEasingCurvePrivate::setType_helper(), and QDeclarativeEasingValueType::setValue().
void QEasingCurve::setAmplitude | ( | qreal | amplitude | ) |
Sets the amplitude to amplitude.
This will set the amplitude of the bounce or the amplitude of the elastic "spring" effect. The higher the number, the higher the amplitude.
Definition at line 713 of file qeasingcurve.cpp.
Referenced by QDeclarativeEasingValueType::setAmplitude().
void QEasingCurve::setCustomType | ( | EasingFunction | func | ) |
Sets a custom easing curve that is defined by the user in the function func.
The signature of the function is qreal myEasingFunction(qreal progress), where progress and the return value is considered to be normalized between 0 and 1. (In some cases the return value can be outside that range) After calling this function type() will return QEasingCurve::Custom. func cannot be zero.
Definition at line 832 of file qeasingcurve.cpp.
void QEasingCurve::setOvershoot | ( | qreal | overshoot | ) |
Sets the overshoot to overshoot.
0 produces no overshoot, and the default value of 1.70158 produces an overshoot of 10 percent.
Definition at line 761 of file qeasingcurve.cpp.
Referenced by QDeclarativeEasingValueType::setOvershoot().
void QEasingCurve::setPeriod | ( | qreal | period | ) |
Sets the period to period.
Setting a small period value will give a high frequency of the curve. A large period will give it a small frequency.
Definition at line 737 of file qeasingcurve.cpp.
Referenced by QDeclarativeEasingValueType::setPeriod().
void QEasingCurve::setType | ( | Type | type | ) |
Sets the type of the easing curve to type.
Definition at line 809 of file qeasingcurve.cpp.
Referenced by operator>>(), QEasingCurve(), and QDeclarativeEasingValueType::setType().
QEasingCurve::Type QEasingCurve::type | ( | ) | const |
Returns the type of the easing curve.
Definition at line 771 of file qeasingcurve.cpp.
Referenced by operator>>(), QEasingCurvePrivate::setType_helper(), QDeclarativeEasingValueType::setValue(), and QDeclarativeTimeLinePrivate::value().
Return the effective progress for the easing curve at progress.
While progress must be between 0 and 1, the returned effective progress can be outside those bounds. For instance, QEasingCurve::InBack will return negative values in the beginning of the function.
Definition at line 858 of file qeasingcurve.cpp.
Referenced by QVariantAnimationPrivate::recalculateCurrentInterval(), and QDeclarativeTimeLinePrivate::value().
|
friend |
Definition at line 870 of file qeasingcurve.cpp.
|
friend |
Writes the given easing curve to the given stream and returns a reference to the stream.
Definition at line 897 of file qeasingcurve.cpp.
|
friend |
Definition at line 925 of file qeasingcurve.cpp.
|
private |
Definition at line 102 of file qeasingcurve.h.
Referenced by amplitude(), customType(), operator<<(), operator=(), operator==(), operator>>(), overshoot(), period(), QEasingCurve(), setAmplitude(), setCustomType(), setOvershoot(), setPeriod(), setType(), type(), valueForProgress(), and ~QEasingCurve().