Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
QEasingCurve Class Reference

\inmodule QtCore More...

#include <qeasingcurve.h>

Collaboration diagram for QEasingCurve:

Public Types

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 , BezierSpline , TCBSpline , Custom ,
  NCurveTypes
}
 The type of easing curve. More...
typedef qreal(* EasingFunction) (qreal progress)
 This is a typedef for a pointer to a function with the following signature:

Public Member Functions

 QEasingCurve (Type type=Linear)
 Constructs an easing curve of the given type.
 QEasingCurve (const QEasingCurve &other)
 Construct a copy of other.
 ~QEasingCurve ()
 Destructor.
QEasingCurveoperator= (const QEasingCurve &other)
 Copy other.
 QEasingCurve (QEasingCurve &&other) noexcept
 Move-constructs a QEasingCurve instance, making it point at the same object that other was pointing to.
void swap (QEasingCurve &other) noexcept
qreal amplitude () const
 Returns the amplitude.
void setAmplitude (qreal amplitude)
 Sets the amplitude to amplitude.
qreal period () const
 Returns the period.
void setPeriod (qreal period)
 Sets the period to period.
qreal overshoot () const
 Returns the overshoot.
void setOvershoot (qreal overshoot)
 Sets the overshoot to overshoot.
void addCubicBezierSegment (const QPointF &c1, const QPointF &c2, const QPointF &endPoint)
 Adds a segment of a cubic bezier spline to define a custom easing curve.
void addTCBSegment (const QPointF &nextPoint, qreal t, qreal c, qreal b)
 Adds a segment of a TCB bezier spline to define a custom easing curve.
QList< QPointFtoCubicSpline () const
Type type () const
 Returns the type of the easing curve.
void setType (Type type)
 Sets the type of the easing curve to type.
void setCustomType (EasingFunction func)
 Sets a custom easing curve that is defined by the user in the function func.
EasingFunction customType () const
 Returns the function pointer to the custom easing curve.
qreal valueForProgress (qreal progress) const
 Return the effective progress for the easing curve at progress.

Friends

Q_CORE_EXPORT QDebug operator<< (QDebug debug, const QEasingCurve &item)
Q_CORE_EXPORT QDataStreamoperator<< (QDataStream &stream, const QEasingCurve &easing)
 Writes the given easing curve to the given stream and returns a reference to the stream.
Q_CORE_EXPORT QDataStreamoperator>> (QDataStream &stream, QEasingCurve &easing)
 Reads an easing curve from the given stream into the given easing curve and returns a reference to the stream.
Q_CORE_EXPORT bool comparesEqual (const QEasingCurve &lhs, const QEasingCurve &rhs)

Detailed Description

\inmodule QtCore

Since
4.6

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,

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.

When using a 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);

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 \l{Easing Curves Example} contains samples of QEasingCurve types and lets you change the curve settings.

Definition at line 19 of file qeasingcurve.h.

Member Typedef Documentation

◆ EasingFunction

typedef qreal(* QEasingCurve::EasingFunction) (qreal progress)

This is a typedef for a pointer to a function with the following signature:

Definition at line 72 of file qeasingcurve.h.

Member Enumeration Documentation

◆ Type

The type of easing curve.

\value Linear{Graph of a linear function.} \caption Easing curve for a linear (t) function: velocity is constant. \value InQuad{Graph of a InQuadratic function.} \caption Easing curve for a quadratic (t^2) function: accelerating from zero velocity. \value OutQuad{Graph of a OutQuadratic function} \caption Easing curve for a quadratic (t^2) function: decelerating to zero velocity. \value InOutQuad{Graph of a InOutquad quadratic function} \caption Easing curve for a quadratic (t^2) function: acceleration until halfway, then deceleration. \value OutInQuad{Graph of a OutInquad quadratic function} \caption Easing curve for a quadratic (t^2) function: deceleration until halfway, then acceleration. \value InCubic{Graph of a InCubic function} \caption Easing curve for a cubic (t^3) function: accelerating from zero velocity. \value OutCubic{Graph of a OutCubic function} \caption Easing curve for a cubic (t^3) function: decelerating to zero velocity. \value InOutCubic{Graph of a InOutCubic function.} \caption Easing curve for a cubic (t^3) function: acceleration until halfway, then deceleration. \value OutInCubic{Graph of a OutInCubic function.} \caption Easing curve for a cubic (t^3) function: deceleration until halfway, then acceleration. \value InQuart{Graph of a InQuartic function.} \caption Easing curve for a quartic (t^4) function: accelerating from zero velocity. \value OutQuart{Graph of a OutQuartic function.} \caption Easing curve for a quartic (t^4) function: decelerating to zero velocity. \value InOutQuart{Graph of a InOutQuartic function.} \caption Easing curve for a quartic (t^4) function: acceleration until halfway, then deceleration. \value OutInQuart{Graph of a OutInQuartic function.} \caption Easing curve for a quartic (t^4) function: deceleration until halfway, then acceleration. \value InQuint{Graph of a InQuintic function} \caption Easing curve for a quintic (t^5) easing in: accelerating from zero velocity. \value OutQuint{Graph of a OutQuintic function} \caption Easing curve for a quintic (t^5) function: decelerating to zero velocity. \value InOutQuint{Graph of a InOutQuintic function} \caption Easing curve for a quintic (t^5) function: acceleration until halfway, then deceleration. \value OutInQuint{Graph of a OutInQuintic function} \caption Easing curve for a quintic (t^5) function: deceleration until halfway, then acceleration. \value InSine{Graph of a InSinusoidal function} \caption Easing curve for a sinusoidal (sin(t)) function: accelerating from zero velocity. \value OutSine{Graph of a OutSinusoidal function} \caption Easing curve for a sinusoidal (sin(t)) function: decelerating to zero velocity. \value InOutSine{Graph of a InOutSinusoidal function} \caption Easing curve for a sinusoidal (sin(t)) function: acceleration until halfway, then deceleration. \value OutInSine{Graph of a OutInSinusoidal function} \caption Easing curve for a sinusoidal (sin(t)) function: deceleration until halfway, then acceleration. \value InExpo{Graph of a InExponential function} \caption Easing curve for an exponential (2^t) function: accelerating from zero velocity. \value OutExpo{Graph of a OutExponential function} \caption Easing curve for an exponential (2^t) function: decelerating to zero velocity. \value InOutExpo{Graph of a InOutExponential function} \caption Easing curve for an exponential (2^t) function: acceleration until halfway, then deceleration. \value OutInExpo{Graph of a OutInExponential function} \caption Easing curve for an exponential (2^t) function: deceleration until halfway, then acceleration. \value InCirc{Graph of a InCircular function} \caption Easing curve for a circular (sqrt(1-t^2)) function: accelerating from zero velocity. \value OutCirc{Graph of a OutCircular function} \caption Easing curve for a circular (sqrt(1-t^2)) function: decelerating to zero velocity. \value InOutCirc{Graph of a InOutCircular function} \caption Easing curve for a circular (sqrt(1-t^2)) function: acceleration until halfway, then deceleration. \value OutInCirc{Graph of a OutInCircular function} \caption Easing curve for a circular (sqrt(1-t^2)) function: deceleration until halfway, then acceleration. \value InElastic{Graph of a InElastic function} \caption 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 parameter. \value OutElastic{Graph of a OutElastic function} \caption 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 parameter. \value InOutElastic{Graph of a InOutElastic function} \caption Easing curve for an elastic (exponentially decaying sine wave) function: acceleration until halfway, then deceleration. \value OutInElastic{Graph of a OutInElastic function} \caption Easing curve for an elastic (exponentially decaying sine wave) function: deceleration until halfway, then acceleration. \value InBack{Graph of a InBack function} \caption Easing curve for a back (overshooting cubic function: (s+1)*t^3 - s*t^2) easing in: accelerating from zero velocity. \value OutBack{Graph of a OutBack function} \caption Easing curve for a back (overshooting cubic function: (s+1)*t^3 - s*t^2) easing out: decelerating to zero velocity. \value InOutBackGraph of a InOutBack function} \caption Easing curve for a back (overshooting cubic function: (s+1)*t^3 - s*t^2) easing in/out: acceleration until halfway, then deceleration. \value OutInBack{Graph of a OutInBack function} \caption Easing curve for a back (overshooting cubic easing: (s+1)*t^3 - s*t^2) easing out/in: deceleration until halfway, then acceleration. \value InBounce{Graph of a InBounce function} \caption Easing curve for a bounce (exponentially decaying parabolic bounce) function: accelerating from zero velocity. \value OutBounce{Graph of a OutBounce function} \caption Easing curve for a bounce (exponentially decaying parabolic bounce) function: decelerating from zero velocity. \value InOutBounce{Graph of a InOutBounce function} \caption Easing curve for a bounce (exponentially decaying parabolic bounce) function easing in/out: acceleration until halfway, then deceleration. \value OutInBounce{Graph of a OutInBounce function} \caption Easing curve for a bounce (exponentially decaying parabolic bounce) function easing out/in: deceleration until halfway, then acceleration. \omitvalue InCurve \omitvalue OutCurve \omitvalue SineCurve \omitvalue CosineCurve \value BezierSpline Allows defining a custom easing curve using a cubic bezier spline

See also
addCubicBezierSegment() \value TCBSpline Allows defining a custom easing curve using a TCB spline
addTCBSegment() \value Custom 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. \omitvalue NCurveTypes
Enumerator
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 
BezierSpline 
TCBSpline 
Custom 
NCurveTypes 

Definition at line 23 of file qeasingcurve.h.

Constructor & Destructor Documentation

◆ QEasingCurve() [1/3]

QEasingCurve::QEasingCurve ( Type type = Linear)

Constructs an easing curve of the given type.

Definition at line 1151 of file qeasingcurve.cpp.

◆ QEasingCurve() [2/3]

QEasingCurve::QEasingCurve ( const QEasingCurve & other)

Construct a copy of other.

Definition at line 1160 of file qeasingcurve.cpp.

◆ ~QEasingCurve()

QEasingCurve::~QEasingCurve ( )

Destructor.

Definition at line 1170 of file qeasingcurve.cpp.

◆ QEasingCurve() [3/3]

QEasingCurve::QEasingCurve ( QEasingCurve && other)
inlinenoexcept

Move-constructs a QEasingCurve instance, making it point at the same object that other was pointing to.

Since
5.2

Definition at line 46 of file qeasingcurve.h.

Member Function Documentation

◆ addCubicBezierSegment()

void QEasingCurve::addCubicBezierSegment ( const QPointF & c1,
const QPointF & c2,
const QPointF & endPoint )

Adds a segment of a cubic bezier spline to define a custom easing curve.

It is only applicable if type() is 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.

Definition at line 1312 of file qeasingcurve.cpp.

◆ addTCBSegment()

void QEasingCurve::addTCBSegment ( const QPointF & nextPoint,
qreal t,
qreal c,
qreal b )

Adds a segment of a TCB bezier spline to define a custom easing curve.

It is only applicable if type() is QEasingCurve::TCBSpline. The spline has to start explicitly 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.

Definition at line 1379 of file qeasingcurve.cpp.

◆ amplitude()

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 1237 of file qeasingcurve.cpp.

◆ customType()

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 1492 of file qeasingcurve.cpp.

◆ operator=()

QEasingCurve & QEasingCurve::operator= ( const QEasingCurve & other)
inline

Copy other.

Move-assigns other to this QEasingCurve instance.

Since
5.2

Definition at line 44 of file qeasingcurve.h.

◆ overshoot()

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 1285 of file qeasingcurve.cpp.

◆ period()

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 1261 of file qeasingcurve.cpp.

◆ setAmplitude()

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.

See also
amplitude()

Definition at line 1249 of file qeasingcurve.cpp.

◆ setCustomType()

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 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() will return QEasingCurve::Custom. func cannot be \nullptr.

See also
customType()
valueForProgress()

Definition at line 1477 of file qeasingcurve.cpp.

◆ setOvershoot()

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.

See also
overshoot()

Definition at line 1297 of file qeasingcurve.cpp.

◆ setPeriod()

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.

See also
period()

Definition at line 1273 of file qeasingcurve.cpp.

◆ setType()

void QEasingCurve::setType ( Type type)

Sets the type of the easing curve to type.

Definition at line 1454 of file qeasingcurve.cpp.

◆ swap()

void QEasingCurve::swap ( QEasingCurve & other)
inlinenoexcept
Since
5.0 \memberswap{curve}

Definition at line 49 of file qeasingcurve.h.

◆ toCubicSpline()

QList< QPointF > QEasingCurve::toCubicSpline ( ) const
Since
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.

Definition at line 1400 of file qeasingcurve.cpp.

◆ type()

QEasingCurve::Type QEasingCurve::type ( ) const

Returns the type of the easing curve.

Definition at line 1408 of file qeasingcurve.cpp.

◆ valueForProgress()

qreal QEasingCurve::valueForProgress ( qreal progress) const

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.

Definition at line 1503 of file qeasingcurve.cpp.

◆ comparesEqual

Q_CORE_EXPORT bool comparesEqual ( const QEasingCurve & lhs,
const QEasingCurve & rhs )
friend

Definition at line 1201 of file qeasingcurve.cpp.

◆ operator<< [1/2]

Q_CORE_EXPORT QDataStream & operator<< ( QDataStream & stream,
const QEasingCurve & easing )
friend

Writes the given easing curve to the given stream and returns a reference to the stream.

Warning
Writing easing curves of QEasingCurve::Custom type (that is, curves with a custom easing function) is not supported.
See also
{Serializing Qt Data Types}

Definition at line 1543 of file qeasingcurve.cpp.

◆ operator<< [2/2]

Q_CORE_EXPORT QDebug operator<< ( QDebug debug,
const QEasingCurve & item )
friend

Definition at line 1515 of file qeasingcurve.cpp.

◆ operator>>

Q_CORE_EXPORT QDataStream & operator>> ( QDataStream & stream,
QEasingCurve & easing )
friend

Reads an easing curve from the given stream into the given easing curve and returns a reference to the stream.

See also
{Serializing Qt Data Types}

Definition at line 1580 of file qeasingcurve.cpp.

References curveToFunctionObject().


The documentation for this class was generated from the following files: