Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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
 
bool operator== (const QEasingCurve &other) const
 Compare this easing curve with other and returns true if they are equal.
 
bool operator!= (const QEasingCurve &other) const
 Compare this easing curve with other and returns true if they are not equal.
 
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 &, const QEasingCurve &)
 Writes the given easing curve to the given stream and returns a reference to the stream.
 
Q_CORE_EXPORT QDataStreamoperator>> (QDataStream &, QEasingCurve &)
 Reads an easing curve from the given stream into the given easing curve and returns a reference to the stream.
 

Related Symbols

(Note that these are not member symbols.)

QDataStreamoperator<< (QDataStream &stream, const QEasingCurve &easing)
 Writes the given easing curve to the given stream and returns a reference to the stream.
 
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.
 

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"

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:

\inmodule QtCore
qreal valueForProgress(qreal progress) const
Return the effective progress for the easing curve at progress.
void setStartValue(const QVariant &value)
void setEasingCurve(const QEasingCurve &easing)
void setDuration(int msecs)
void setEndValue(const QVariant &value)
QEasingCurve easing(QEasingCurve::InOutQuad)
[typedef]
QPropertyAnimation animation
[0]
qreal myEasingFunction(qreal progress)
[typedef]

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 18 of file qeasingcurve.h.

Member Typedef Documentation

◆ EasingFunction

QEasingCurve::EasingFunction

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

Definition at line 69 of file qeasingcurve.h.

Member Enumeration Documentation

◆ Type

The type of easing curve.

\value Linear\caption Easing curve for a linear (t) function: velocity is constant. \value InQuad\caption Easing curve for a quadratic (t^2) function: accelerating from zero velocity. \value OutQuad\caption Easing curve for a quadratic (t^2) function: decelerating to zero velocity. \value InOutQuad\caption Easing curve for a quadratic (t^2) function: acceleration until halfway, then deceleration. \value OutInQuad\caption Easing curve for a quadratic (t^2) function: deceleration until halfway, then acceleration. \value InCubic\caption Easing curve for a cubic (t^3) function: accelerating from zero velocity. \value OutCubic\caption Easing curve for a cubic (t^3) function: decelerating to zero velocity. \value InOutCubic\caption Easing curve for a cubic (t^3) function: acceleration until halfway, then deceleration. \value OutInCubic\caption Easing curve for a cubic (t^3) function: deceleration until halfway, then acceleration. \value InQuart\caption Easing curve for a quartic (t^4) function: accelerating from zero velocity. \value OutQuart\caption Easing curve for a quartic (t^4) function: decelerating to zero velocity. \value InOutQuart\caption Easing curve for a quartic (t^4) function: acceleration until halfway, then deceleration. \value OutInQuart\caption Easing curve for a quartic (t^4) function: deceleration until halfway, then acceleration. \value InQuint\caption Easing curve for a quintic (t^5) easing in: accelerating from zero velocity. \value OutQuint\caption Easing curve for a quintic (t^5) function: decelerating to zero velocity. \value InOutQuint\caption Easing curve for a quintic (t^5) function: acceleration until halfway, then deceleration. \value OutInQuint\caption Easing curve for a quintic (t^5) function: deceleration until halfway, then acceleration. \value InSine\caption Easing curve for a sinusoidal (sin(t)) function: accelerating from zero velocity. \value OutSine\caption Easing curve for a sinusoidal (sin(t)) function: decelerating to zero velocity. \value InOutSine\caption Easing curve for a sinusoidal (sin(t)) function: acceleration until halfway, then deceleration. \value OutInSine\caption Easing curve for a sinusoidal (sin(t)) function: deceleration until halfway, then acceleration. \value InExpo\caption Easing curve for an exponential (2^t) function: accelerating from zero velocity. \value OutExpo\caption Easing curve for an exponential (2^t) function: decelerating to zero velocity. \value InOutExpo\caption Easing curve for an exponential (2^t) function: acceleration until halfway, then deceleration. \value OutInExpo\caption Easing curve for an exponential (2^t) function: deceleration until halfway, then acceleration. \value InCirc\caption Easing curve for a circular (sqrt(1-t^2)) function: accelerating from zero velocity. \value OutCirc\caption Easing curve for a circular (sqrt(1-t^2)) function: decelerating to zero velocity. \value InOutCirc\caption Easing curve for a circular (sqrt(1-t^2)) function: acceleration until halfway, then deceleration. \value OutInCirc\caption Easing curve for a circular (sqrt(1-t^2)) function: deceleration until halfway, then acceleration. \value InElastic\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\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\caption Easing curve for an elastic (exponentially decaying sine wave) function: acceleration until halfway, then deceleration. \value OutInElastic\caption Easing curve for an elastic (exponentially decaying sine wave) function: deceleration until halfway, then acceleration. \value InBack\caption Easing curve for a back (overshooting cubic function: (s+1)*t^3 - s*t^2) easing in: accelerating from zero velocity. \value OutBack\caption Easing curve for a back (overshooting cubic function: (s+1)*t^3 - s*t^2) easing out: decelerating to zero velocity. \value InOutBack\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\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\caption Easing curve for a bounce (exponentially decaying parabolic bounce) function: accelerating from zero velocity. \value OutBounce\caption Easing curve for a bounce (exponentially decaying parabolic bounce) function: decelerating from zero velocity. \value InOutBounce\caption Easing curve for a bounce (exponentially decaying parabolic bounce) function easing in/out: acceleration until halfway, then deceleration. \value OutInBounce\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 22 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 1110 of file qeasingcurve.cpp.

References setType().

+ Here is the call graph for this function:

◆ QEasingCurve() [2/3]

QEasingCurve::QEasingCurve ( const QEasingCurve & other)

Construct a copy of other.

Definition at line 1119 of file qeasingcurve.cpp.

◆ ~QEasingCurve()

QEasingCurve::~QEasingCurve ( )

Destructor.

Definition at line 1129 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 45 of file qeasingcurve.h.

References other().

+ Here is the call graph for this function:

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

References QEasingCurveFunction::_bezierCurves, c2, QEasingCurvePrivate::config, curveToFunctionObject(), and QEasingCurvePrivate::type.

Referenced by QQuickUniversalBusyIndicatorNode::QQuickUniversalBusyIndicatorNode(), and QQuickUniversalProgressBarNode::updateCurrentTime().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

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

References QEasingCurveFunction::_bezierCurves, QEasingCurveFunction::_tcbPoints, QList< T >::append(), QList< T >::clear(), QEasingCurvePrivate::config, curveToFunctionObject(), tcbToBezier(), and QEasingCurvePrivate::type.

+ Here is the call graph for this function:

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

References QEasingCurveFunction::_a, and QEasingCurvePrivate::config.

Referenced by operator==(), and setAmplitude().

+ Here is the caller graph for this function:

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

References Custom, QEasingCurvePrivate::func, and QEasingCurvePrivate::type.

◆ operator!=()

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

Compare this easing curve with other and returns true if they are not equal.

It will also compare the properties of a curve.

See also
operator==()

Definition at line 51 of file qeasingcurve.h.

References operator==().

+ Here is the call graph for this function:

◆ operator=()

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

Copy other.

Move-assigns other to this QEasingCurve instance.

Since
5.2

Definition at line 43 of file qeasingcurve.h.

References copy(), other(), and swap().

+ Here is the call graph for this function:

◆ operator==()

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

References amplitude(), QEasingCurvePrivate::config, QEasingCurvePrivate::func, other(), overshoot(), period(), qFuzzyCompare(), and QEasingCurvePrivate::type.

+ Here is the call graph for this function:

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

References QEasingCurveFunction::_o, and QEasingCurvePrivate::config.

Referenced by operator==(), and setOvershoot().

+ Here is the caller graph for this function:

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

References QEasingCurveFunction::_p, and QEasingCurvePrivate::config.

Referenced by operator==(), and setPeriod().

+ Here is the caller graph for this function:

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

References QEasingCurveFunction::_a, amplitude(), QEasingCurvePrivate::config, curveToFunctionObject(), and QEasingCurvePrivate::type.

+ Here is the call graph for this function:

◆ 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 zero.

See also
customType()
valueForProgress()

Definition at line 1433 of file qeasingcurve.cpp.

References Custom, QEasingCurvePrivate::func, qWarning, and QEasingCurvePrivate::setType_helper().

+ Here is the call graph for this function:

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

References QEasingCurveFunction::_o, QEasingCurvePrivate::config, curveToFunctionObject(), overshoot(), and QEasingCurvePrivate::type.

+ Here is the call graph for this function:

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

References QEasingCurveFunction::_p, QEasingCurvePrivate::config, curveToFunctionObject(), period(), and QEasingCurvePrivate::type.

+ Here is the call graph for this function:

◆ setType()

void QEasingCurve::setType ( Type type)

Sets the type of the easing curve to type.

Definition at line 1410 of file qeasingcurve.cpp.

References NCurveTypes, qWarning, QEasingCurvePrivate::setType_helper(), and QEasingCurvePrivate::type.

Referenced by QEasingCurve().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ swap()

void QEasingCurve::swap ( QEasingCurve & other)
inlinenoexcept
Since
5.0

Swaps curve other with this curve. This operation is very fast and never fails.

Definition at line 48 of file qeasingcurve.h.

References other(), and qt_ptr_swap().

+ Here is the call graph for this function:

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

References QEasingCurveFunction::_bezierCurves, and QEasingCurvePrivate::config.

◆ type()

QEasingCurve::Type QEasingCurve::type ( ) const

Returns the type of the easing curve.

Definition at line 1364 of file qeasingcurve.cpp.

References QEasingCurvePrivate::type.

Referenced by differentialForProgress(), progressForValue(), and QQuickTimeLinePrivate::value().

+ Here is the caller graph for this function:

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

References QEasingCurvePrivate::config, QEasingCurvePrivate::func, and QEasingCurveFunction::value().

Referenced by QQuick3DParticleScaleAffector::affectParticle(), differentialForProgress(), QQuickBoundaryRulePrivate::easedOvershoot(), QQuickAnimatorJob::progress(), progressForValue(), QVariantAnimationPrivate::recalculateCurrentInterval(), QQuickBulkValueAnimator::updateCurrentTime(), QQuickBasicProgressBarNode::updateCurrentTime(), QQuickUniversalBusyIndicatorNode::updateCurrentTime(), QQuickUniversalProgressBarNode::updateCurrentTime(), QQuickBoundaryReturnJob::updateCurrentTime(), and QQuickTimeLinePrivate::value().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Friends And Related Symbol Documentation

◆ operator<< [1/3]

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

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

See also
{Serializing Qt Data Types}

Definition at line 1496 of file qeasingcurve.cpp.

◆ operator<<() [2/3]

QDataStream & operator<< ( QDataStream & stream,
const QEasingCurve & easing )
related

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

See also
{Serializing Qt Data Types}

Definition at line 1496 of file qeasingcurve.cpp.

◆ operator<< [3/3]

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

Definition at line 1471 of file qeasingcurve.cpp.

◆ operator>> [1/2]

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

◆ operator>>() [2/2]

QDataStream & operator>> ( QDataStream & stream,
QEasingCurve & easing )
related

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


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