6.0.0-rc4Source

QEasingCurve Class

The QEasingCurve class provides easing curves for controlling animation. More…

Header#include <QEasingCurve>
CMaketarget_link_libraries(app PRIVATE Nt::Core)
ModuleNt Core C++ Classes
Since4.6

List of all members, including inherited members

Public Types

enumType
typedefEasingFunction

Public Functions

QEasingCurve(Type type = Linear)
QEasingCurve(const QEasingCurve &other)
QEasingCurve(QEasingCurve &&other)
~QEasingCurve()
QEasingCurve &operator=(const QEasingCurve &other)
QEasingCurve &operator=(QEasingCurve &&other)
voidswap(QEasingCurve &other)
qrealamplitude() const
voidsetAmplitude(qreal amplitude)
qrealperiod() const
voidsetPeriod(qreal period)
qrealovershoot() const
voidsetOvershoot(qreal overshoot)
voidaddCubicBezierSegment(const QPointF &c1, const QPointF &c2, const QPointF &endPoint)
voidaddTCBSegment(const QPointF &nextPoint, qreal t, qreal c, qreal b)
QList<QPointF>toCubicSpline() const
Typetype() const
voidsetType(Type type)
voidsetCustomType(EasingFunction func)
EasingFunctioncustomType() const
qrealvalueForProgress(qreal progress) const

Detailed Description

An easing curve maps the progress of an animation, from 0 to 1, to the progress of the animated value, so that a movement can start slowly, overshoot or bounce. valueForProgress() evaluates the curve:

QEasingCurve curve(QEasingCurve::OutBounce);
for (qreal t = 0; t <= 1; t += 0.1)
    y = start + (end - start) * curve.valueForProgress(t);

The elastic curves use amplitude() and period(), the bounce curves amplitude(), and the back curves overshoot(). BezierSpline and TCBSpline curves are built from segments with addCubicBezierSegment() and addTCBSegment().

See also QTimeLine.

Differences from Qt

The exponential curves start at exactly 0 and end at exactly 1, without the small offset of Qt's formulas. InCurve and OutCurve follow the sine ease-in and ease-out shapes. There is no QDataStream support.

Member Type Documentation

typedef QEasingCurve::EasingFunction

A pointer to a function that maps progress (0 to 1) to a value, as used by setCustomType().

enum QEasingCurve::Type

ConstantDescription
QEasingCurve::LinearLinear (t) function: velocity is constant.
QEasingCurve::InQuadQuadratic (t^2) easing in: accelerating from zero velocity.
QEasingCurve::OutQuadQuadratic easing out: decelerating to zero velocity.
QEasingCurve::InOutQuadQuadratic easing in and out.
QEasingCurve::OutInQuadQuadratic easing out and in.
QEasingCurve::InCubicCubic (t^3) easing in.
QEasingCurve::OutCubicCubic easing out.
QEasingCurve::InOutCubicCubic easing in and out.
QEasingCurve::OutInCubicCubic easing out and in.
QEasingCurve::InQuartQuartic (t^4) easing in.
QEasingCurve::OutQuartQuartic easing out.
QEasingCurve::InOutQuartQuartic easing in and out.
QEasingCurve::OutInQuartQuartic easing out and in.
QEasingCurve::InQuintQuintic (t^5) easing in.
QEasingCurve::OutQuintQuintic easing out.
QEasingCurve::InOutQuintQuintic easing in and out.
QEasingCurve::OutInQuintQuintic easing out and in.
QEasingCurve::InSineSinusoidal easing in.
QEasingCurve::OutSineSinusoidal easing out.
QEasingCurve::InOutSineSinusoidal easing in and out.
QEasingCurve::OutInSineSinusoidal easing out and in.
QEasingCurve::InExpoExponential (2^t) easing in.
QEasingCurve::OutExpoExponential easing out.
QEasingCurve::InOutExpoExponential easing in and out.
QEasingCurve::OutInExpoExponential easing out and in.
QEasingCurve::InCircCircular (sqrt(1-t^2)) easing in.
QEasingCurve::OutCircCircular easing out.
QEasingCurve::InOutCircCircular easing in and out.
QEasingCurve::OutInCircCircular easing out and in.
QEasingCurve::InElasticElastic (exponentially decaying sine wave) easing in.
QEasingCurve::OutElasticElastic easing out.
QEasingCurve::InOutElasticElastic easing in and out.
QEasingCurve::OutInElasticElastic easing out and in.
QEasingCurve::InBackBack (overshooting cubic) easing in.
QEasingCurve::OutBackBack easing out.
QEasingCurve::InOutBackBack easing in and out.
QEasingCurve::OutInBackBack easing out and in.
QEasingCurve::InBounceBounce (exponentially decaying parabolic bounce) easing in.
QEasingCurve::OutBounceBounce easing out.
QEasingCurve::InOutBounceBounce easing in and out.
QEasingCurve::OutInBounceBounce easing out and in.
QEasingCurve::InCurveA curve that starts slowly and speeds up.
QEasingCurve::OutCurveA curve that starts fast and slows down.
QEasingCurve::SineCurveA sine wave going from 0 to 1 and back to 0.
QEasingCurve::CosineCurveA cosine wave starting and ending at 0.5.
QEasingCurve::BezierSplineA curve made of cubic Bézier segments.
QEasingCurve::TCBSplineA curve made of Kochanek-Bartels (TCB) spline segments.
QEasingCurve::CustomA curve given by a function; see setCustomType().

Member Function Documentation

QEasingCurve::QEasingCurve(Type type = Linear)

Constructs an easing curve of the given type.

QEasingCurve::QEasingCurve(const QEasingCurve &other)

Constructs a copy of other.

QEasingCurve::QEasingCurve(QEasingCurve &&other)

Move-constructs a curve from other.

QEasingCurve::~QEasingCurve()

Destroys the curve.

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

Adds a cubic Bézier segment with the control points c1 and c2 that ends at endPoint to a BezierSpline curve. The first segment starts at (0, 0), and the last should end at (1, 1).

This function was introduced in 5.0.

See also toCubicSpline().

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

Adds a segment ending at nextPoint to a TCBSpline curve, with the tension t, continuity c and bias b at that point. The curve starts at (0, 0), and the last point should be (1, 1).

This function was introduced in 5.0.

qreal QEasingCurve::amplitude() const

Returns the amplitude, which the elastic and bounce curves use. The default is 1.0.

See also setAmplitude().

EasingFunction QEasingCurve::customType() const

Returns the function of a Custom curve, or nullptr.

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

Assigns other to this curve and returns a reference to it.

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

Move-assigns other to this curve and returns a reference to it.

qreal QEasingCurve::overshoot() const

Returns the overshoot of the back curves. The default is 1.70158, an overshoot of 10 percent.

See also setOvershoot().

qreal QEasingCurve::period() const

Returns the period of the elastic curves. The default is 0.3.

See also setPeriod().

void QEasingCurve::setAmplitude(qreal amplitude)

Sets the amplitude to amplitude. It controls the height of the bounces of the bounce curves and of the oscillations of the elastic curves.

See also amplitude().

void QEasingCurve::setCustomType(EasingFunction func)

Makes this a Custom curve that calls func to map progress to a value.

See also customType().

void QEasingCurve::setOvershoot(qreal overshoot)

Sets the overshoot of the back curves to overshoot.

See also overshoot().

void QEasingCurve::setPeriod(qreal period)

Sets the period of the elastic curves to period. A small period gives a high frequency.

See also period().

void QEasingCurve::setType(Type type)

Sets the type of the curve to type. Setting Custom without a function has no effect; use setCustomType().

void QEasingCurve::swap(QEasingCurve &other)

Swaps this curve with other.

QList<QPointF> QEasingCurve::toCubicSpline() const

Returns the control and end points of the cubic Bézier segments of a BezierSpline or TCBSpline curve, three points per segment. A TCB spline is converted to Bézier segments.

This function was introduced in 5.0.

Type QEasingCurve::type() const

Returns the type of the curve.

See also setType().

qreal QEasingCurve::valueForProgress(qreal progress) const

Returns the value of the curve for progress, which is clamped to the range 0 to 1. The result is 0 at progress 0 and 1 at progress 1 for all curves except SineCurve and CosineCurve, and may leave that range in between (for the elastic and back curves).