The QEasingCurve class provides easing curves for controlling animation. 更多...
头: | #include <QEasingCurve> |
qmake: | QT += core |
Since: | Qt 4.6 |
typedef | EasingFunction |
enum | Type { Linear, InQuad, OutQuad, InOutQuad, ..., Custom } |
QEasingCurve (QEasingCurve::Type type = Linear) | |
QEasingCurve (const QEasingCurve & other ) | |
QEasingCurve (QEasingCurve && other ) | |
~QEasingCurve () | |
void | addCubicBezierSegment (const QPointF & c1 , const QPointF & c2 , const QPointF & endPoint ) |
void | addTCBSegment (const QPointF & nextPoint , qreal t , qreal c , qreal b ) |
qreal | amplitude () const |
QEasingCurve::EasingFunction | customType () const |
qreal | overshoot () const |
qreal | period () const |
void | setAmplitude (qreal amplitude ) |
void | setCustomType (QEasingCurve::EasingFunction func ) |
void | setOvershoot (qreal overshoot ) |
void | setPeriod (qreal period ) |
void | setType (QEasingCurve::Type type ) |
void | swap (QEasingCurve & other ) |
QVector<QPointF> | toCubicSpline () const |
QEasingCurve::Type | type () const |
qreal | valueForProgress (qreal progress ) const |
bool | operator!= (const QEasingCurve & other ) const |
QEasingCurve & | operator= (const QEasingCurve & other ) |
QEasingCurve & | operator= (QEasingCurve && other ) |
bool | operator== (const QEasingCurve & other ) const |
const QMetaObject | staticMetaObject |
QDataStream & | operator<< (QDataStream & stream , const QEasingCurve & easing ) |
QDataStream & | operator>> (QDataStream & stream , QEasingCurve & easing ) |
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.
例如,
QEasingCurve easing(QEasingCurve::InOutQuad); for (qreal t = 0.0; t < 1.0; t += 0.1) qWarning() << "Effective progress" << t << "is" << easing.valueForProgress(t);
will print the effective progress of the interpolation between 0 and 1.
当使用 QPropertyAnimation , the associated easing curve will be used to control the progress of the interpolation between startValue and endValue:
QPropertyAnimation animation; animation.setStartValue(0); animation.setEndValue(1000); animation.setDuration(1000); animation.setEasingCurve(QEasingCurve::InOutQuad);
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 ,和 OutInBack have overshoot settings. These curves will interpolate beyond the end points and return to the end point, acting similar to a boomerang.
The 缓和曲线范例 contains samples of QEasingCurve types and lets you change the curve settings.
这是采用以下签名的函数指针的 typedef:
qreal myEasingFunction(qreal progress);
The type of easing curve.
常量 | 值 |
---|---|
QEasingCurve::Linear
|
0
|
Easing curve for a linear (t) function: velocity is constant.
常量 | 值 |
---|---|
QEasingCurve::InQuad
|
1
|
Easing curve for a quadratic (t^2) function: accelerating from zero velocity.
常量 | 值 |
---|---|
QEasingCurve::OutQuad
|
2
|
Easing curve for a quadratic (t^2) function: decelerating to zero velocity.
常量 | 值 |
---|---|
QEasingCurve::InOutQuad
|
3
|
Easing curve for a quadratic (t^2) function: acceleration until halfway, then deceleration.
常量 | 值 |
---|---|
QEasingCurve::OutInQuad
|
4
|
Easing curve for a quadratic (t^2) function: deceleration until halfway, then acceleration.
常量 | 值 |
---|---|
QEasingCurve::InCubic
|
5
|
Easing curve for a cubic (t^3) function: accelerating from zero velocity.
常量 | 值 |
---|---|
QEasingCurve::OutCubic
|
6
|
Easing curve for a cubic (t^3) function: decelerating to zero velocity.
常量 | 值 |
---|---|
QEasingCurve::InOutCubic
|
7
|
Easing curve for a cubic (t^3) function: acceleration until halfway, then deceleration.
常量 | 值 |
---|---|
QEasingCurve::OutInCubic
|
8
|
Easing curve for a cubic (t^3) function: deceleration until halfway, then acceleration.
常量 | 值 |
---|---|
QEasingCurve::InQuart
|
9
|
Easing curve for a quartic (t^4) function: accelerating from zero velocity.
常量 | 值 |
---|---|
QEasingCurve::OutQuart
|
10
|
Easing curve for a quartic (t^4) function: decelerating to zero velocity.
常量 | 值 |
---|---|
QEasingCurve::InOutQuart
|
11
|
Easing curve for a quartic (t^4) function: acceleration until halfway, then deceleration.
常量 | 值 |
---|---|
QEasingCurve::OutInQuart
|
12
|
Easing curve for a quartic (t^4) function: deceleration until halfway, then acceleration.
常量 | 值 |
---|---|
QEasingCurve::InQuint
|
13
|
Easing curve for a quintic (t^5) easing in: accelerating from zero velocity.
常量 | 值 |
---|---|
QEasingCurve::OutQuint
|
14
|
Easing curve for a quintic (t^5) function: decelerating to zero velocity.
常量 | 值 |
---|---|
QEasingCurve::InOutQuint
|
15
|
Easing curve for a quintic (t^5) function: acceleration until halfway, then deceleration.
常量 | 值 |
---|---|
QEasingCurve::OutInQuint
|
16
|
Easing curve for a quintic (t^5) function: deceleration until halfway, then acceleration.
常量 | 值 |
---|---|
QEasingCurve::InSine
|
17
|
Easing curve for a sinusoidal (sin(t)) function: accelerating from zero velocity.
常量 | 值 |
---|---|
QEasingCurve::OutSine
|
18
|
Easing curve for a sinusoidal (sin(t)) function: decelerating to zero velocity.
常量 | 值 |
---|---|
QEasingCurve::InOutSine
|
19
|
Easing curve for a sinusoidal (sin(t)) function: acceleration until halfway, then deceleration.
常量 | 值 |
---|---|
QEasingCurve::OutInSine
|
20
|
Easing curve for a sinusoidal (sin(t)) function: deceleration until halfway, then acceleration.
常量 | 值 |
---|---|
QEasingCurve::InExpo
|
21
|
Easing curve for an exponential (2^t) function: accelerating from zero velocity.
常量 | 值 |
---|---|
QEasingCurve::OutExpo
|
22
|
Easing curve for an exponential (2^t) function: decelerating to zero velocity.
常量 | 值 |
---|---|
QEasingCurve::InOutExpo
|
23
|
Easing curve for an exponential (2^t) function: acceleration until halfway, then deceleration.
常量 | 值 |
---|---|
QEasingCurve::OutInExpo
|
24
|
Easing curve for an exponential (2^t) function: deceleration until halfway, then acceleration.
常量 | 值 |
---|---|
QEasingCurve::InCirc
|
25
|
Easing curve for a circular (sqrt(1-t^2)) function: accelerating from zero velocity.
常量 | 值 |
---|---|
QEasingCurve::OutCirc
|
26
|
Easing curve for a circular (sqrt(1-t^2)) function: decelerating to zero velocity.
常量 | 值 |
---|---|
QEasingCurve::InOutCirc
|
27
|
Easing curve for a circular (sqrt(1-t^2)) function: acceleration until halfway, then deceleration.
常量 | 值 |
---|---|
QEasingCurve::OutInCirc
|
28
|
Easing curve for a circular (sqrt(1-t^2)) function: deceleration until halfway, then acceleration.
常量 | 值 |
---|---|
QEasingCurve::InElastic
|
29
|
Easing curve for an elastic (exponentially decaying sine wave) function: accelerating from zero velocity. The peak amplitude can be set with the amplitude parameter, and the period of decay by the period 参数。
常量 | 值 |
---|---|
QEasingCurve::OutElastic
|
30
|
Easing curve for an elastic (exponentially decaying sine wave) function: decelerating to zero velocity. The peak amplitude can be set with the amplitude parameter, and the period of decay by the period 参数。
常量 | 值 |
---|---|
QEasingCurve::InOutElastic
|
31
|
Easing curve for an elastic (exponentially decaying sine wave) function: acceleration until halfway, then deceleration.
常量 | 值 |
---|---|
QEasingCurve::OutInElastic
|
32
|
Easing curve for an elastic (exponentially decaying sine wave) function: deceleration until halfway, then acceleration.
常量 | 值 |
---|---|
QEasingCurve::InBack
|
33
|
Easing curve for a back (overshooting cubic function: (s+1)*t^3 - s*t^2) easing in: accelerating from zero velocity.
常量 | 值 |
---|---|
QEasingCurve::OutBack
|
34
|
Easing curve for a back (overshooting cubic function: (s+1)*t^3 - s*t^2) easing out: decelerating to zero velocity.
常量 | 值 |
---|---|
QEasingCurve::InOutBack
|
35
|
Easing curve for a back (overshooting cubic function: (s+1)*t^3 - s*t^2) easing in/out: acceleration until halfway, then deceleration.
常量 | 值 |
---|---|
QEasingCurve::OutInBack
|
36
|
Easing curve for a back (overshooting cubic easing: (s+1)*t^3 - s*t^2) easing out/in: deceleration until halfway, then acceleration.
常量 | 值 |
---|---|
QEasingCurve::InBounce
|
37
|
Easing curve for a bounce (exponentially decaying parabolic bounce) function: accelerating from zero velocity.
常量 | 值 |
---|---|
QEasingCurve::OutBounce
|
38
|
Easing curve for a bounce (exponentially decaying parabolic bounce) function: decelerating from zero velocity.
常量 | 值 |
---|---|
QEasingCurve::InOutBounce
|
39
|
Easing curve for a bounce (exponentially decaying parabolic bounce) function easing in/out: acceleration until halfway, then deceleration.
常量 | 值 |
---|---|
QEasingCurve::OutInBounce
|
40
|
Easing curve for a bounce (exponentially decaying parabolic bounce) function easing out/in: deceleration until halfway, then acceleration.
常量 | 值 | 描述 |
---|---|---|
QEasingCurve::BezierSpline
|
45
|
Allows defining a custom easing curve using a cubic bezier spline |
QEasingCurve::TCBSpline
|
46
|
Allows defining a custom easing curve using a TCB spline |
QEasingCurve::Custom
|
47
|
This is returned if the user specified a custom curve type with setCustomType (). Note that you cannot call setType () with this value, but type () can return it. |
另请参阅 addCubicBezierSegment () 和 addTCBSegment ().
Constructs an easing curve of the given type .
Construct a copy of other .
移动构造 QEasingCurve 实例,使之指向同一对象如 other 所指向的。
该函数在 Qt 5.2 引入。
析构函数。
Adds a segment of a cubic bezier spline to define a custom easing curve. It is only applicable if type () 是 QEasingCurve::BezierSpline . Note that the spline implicitly starts at (0.0, 0.0) and has to end at (1.0, 1.0) to be a valid easing curve. c1 and c2 are the control points used for drawing the curve. endPoint is the endpoint of the curve.
Adds a segment of a TCB bezier spline to define a custom easing curve. It is only applicable if type () 是 QEasingCurve::TCBSpline . The spline has to start explitly at (0.0, 0.0) and has to end at (1.0, 1.0) to be a valid easing curve. The tension t changes the length of the tangent vector. The continuity c changes the sharpness in change between the tangents. The bias b changes the direction of the tangent vector. nextPoint is the sample position. All three parameters are valid between -1 and 1 and define the tangent of the control point. If all three parameters are 0 the resulting spline is a Catmull-Rom spline. The begin and endpoint always have a bias of -1 and 1, since the outer tangent is not defined.
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 ).
另请参阅 setAmplitude ().
Returns the function pointer to the custom easing curve. If type () does not return QEasingCurve::Custom , this function will return 0.
另请参阅 setCustomType ().
Returns the overshoot. This is not applicable for all curve types. It is only applicable if type () 是 QEasingCurve::InBack , QEasingCurve::OutBack , QEasingCurve::InOutBack or QEasingCurve::OutInBack .
另请参阅 setOvershoot ().
Returns the period. This is not applicable for all curve types. It is only applicable if type () 是 QEasingCurve::InElastic , QEasingCurve::OutElastic , QEasingCurve::InOutElastic or QEasingCurve::OutInElastic .
另请参阅 setPeriod ().
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.
另请参阅 amplitude ().
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 are considered to be normalized between 0 and 1. (In some cases the return value can be outside that range) After calling this function type () 会返回 QEasingCurve::Custom . func cannot be zero.
另请参阅 customType () 和 valueForProgress ().
Sets the overshoot to overshoot .
0 produces no overshoot, and the default value of 1.70158 produces an overshoot of 10 percent.
另请参阅 overshoot ().
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.
另请参阅 period ().
Sets the type of the easing curve to type .
另请参阅 type ().
Swaps curve other with this curve. This operation is very fast and never fails.
该函数在 Qt 5.0 引入。
Returns the cubicBezierSpline that defines a custom easing curve. If the easing curve does not have a custom bezier easing curve the list is empty.
该函数在 Qt 5.0 引入。
Returns the type of the easing curve.
另请参阅 setType ().
Return the effective progress for the easing curve at progress . Whereas progress must be between 0 and 1, the returned effective progress can be outside those bounds. For example, QEasingCurve::InBack will return negative values in the beginning of the function.
Compare this easing curve with
other
并返回
true
if they are not equal. It will also compare the properties of a curve.
另请参阅 operator== ().
Copy other .
移动赋值 other 到此 QEasingCurve 实例。
该函数在 Qt 5.2 引入。
Compare this easing curve with
other
并返回
true
if they are equal. It will also compare the properties of a curve.
写入给定 easing curve to the given stream 并返回流引用。
另请参阅 序列化 Qt 数据类型 .
Reads an easing curve from the given stream 进给定 easing curve and returns a reference to the stream.
另请参阅 序列化 Qt 数据类型 .