QEasingCurve Class
The QEasingCurve class provides easing curves for controlling animation. More…
| Header | #include <QEasingCurve> |
|---|---|
| CMake | target_link_libraries(app PRIVATE Nt::Core) |
| Module | Nt Core C++ Classes |
| Since | 4.6 |
List of all members, including inherited members
Public Types
| enum | Type |
| typedef | EasingFunction |
Public Functions
| QEasingCurve(Type type = Linear) | |
| QEasingCurve(const QEasingCurve &other) | |
| QEasingCurve(QEasingCurve &&other) | |
| ~QEasingCurve() | |
| QEasingCurve & | operator=(const QEasingCurve &other) |
| QEasingCurve & | operator=(QEasingCurve &&other) |
| void | swap(QEasingCurve &other) |
| qreal | amplitude() const |
| void | setAmplitude(qreal amplitude) |
| qreal | period() const |
| void | setPeriod(qreal period) |
| qreal | overshoot() const |
| void | setOvershoot(qreal overshoot) |
| void | addCubicBezierSegment(const QPointF &c1, const QPointF &c2, const QPointF &endPoint) |
| void | addTCBSegment(const QPointF &nextPoint, qreal t, qreal c, qreal b) |
| QList<QPointF> | toCubicSpline() const |
| Type | type() const |
| void | setType(Type type) |
| void | setCustomType(EasingFunction func) |
| EasingFunction | customType() const |
| qreal | valueForProgress(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
| Constant | Description |
|---|---|
QEasingCurve::Linear | Linear (t) function: velocity is constant. |
QEasingCurve::InQuad | Quadratic (t^2) easing in: accelerating from zero velocity. |
QEasingCurve::OutQuad | Quadratic easing out: decelerating to zero velocity. |
QEasingCurve::InOutQuad | Quadratic easing in and out. |
QEasingCurve::OutInQuad | Quadratic easing out and in. |
QEasingCurve::InCubic | Cubic (t^3) easing in. |
QEasingCurve::OutCubic | Cubic easing out. |
QEasingCurve::InOutCubic | Cubic easing in and out. |
QEasingCurve::OutInCubic | Cubic easing out and in. |
QEasingCurve::InQuart | Quartic (t^4) easing in. |
QEasingCurve::OutQuart | Quartic easing out. |
QEasingCurve::InOutQuart | Quartic easing in and out. |
QEasingCurve::OutInQuart | Quartic easing out and in. |
QEasingCurve::InQuint | Quintic (t^5) easing in. |
QEasingCurve::OutQuint | Quintic easing out. |
QEasingCurve::InOutQuint | Quintic easing in and out. |
QEasingCurve::OutInQuint | Quintic easing out and in. |
QEasingCurve::InSine | Sinusoidal easing in. |
QEasingCurve::OutSine | Sinusoidal easing out. |
QEasingCurve::InOutSine | Sinusoidal easing in and out. |
QEasingCurve::OutInSine | Sinusoidal easing out and in. |
QEasingCurve::InExpo | Exponential (2^t) easing in. |
QEasingCurve::OutExpo | Exponential easing out. |
QEasingCurve::InOutExpo | Exponential easing in and out. |
QEasingCurve::OutInExpo | Exponential easing out and in. |
QEasingCurve::InCirc | Circular (sqrt(1-t^2)) easing in. |
QEasingCurve::OutCirc | Circular easing out. |
QEasingCurve::InOutCirc | Circular easing in and out. |
QEasingCurve::OutInCirc | Circular easing out and in. |
QEasingCurve::InElastic | Elastic (exponentially decaying sine wave) easing in. |
QEasingCurve::OutElastic | Elastic easing out. |
QEasingCurve::InOutElastic | Elastic easing in and out. |
QEasingCurve::OutInElastic | Elastic easing out and in. |
QEasingCurve::InBack | Back (overshooting cubic) easing in. |
QEasingCurve::OutBack | Back easing out. |
QEasingCurve::InOutBack | Back easing in and out. |
QEasingCurve::OutInBack | Back easing out and in. |
QEasingCurve::InBounce | Bounce (exponentially decaying parabolic bounce) easing in. |
QEasingCurve::OutBounce | Bounce easing out. |
QEasingCurve::InOutBounce | Bounce easing in and out. |
QEasingCurve::OutInBounce | Bounce easing out and in. |
QEasingCurve::InCurve | A curve that starts slowly and speeds up. |
QEasingCurve::OutCurve | A curve that starts fast and slows down. |
QEasingCurve::SineCurve | A sine wave going from 0 to 1 and back to 0. |
QEasingCurve::CosineCurve | A cosine wave starting and ending at 0.5. |
QEasingCurve::BezierSpline | A curve made of cubic Bézier segments. |
QEasingCurve::TCBSpline | A curve made of Kochanek-Bartels (TCB) spline segments. |
QEasingCurve::Custom | A 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).