1 | // Copyright (C) 2016 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #ifndef QEASINGCURVE_H |
5 | #define QEASINGCURVE_H |
6 | |
7 | #include <QtCore/qglobal.h> |
8 | |
9 | QT_REQUIRE_CONFIG(easingcurve); |
10 | |
11 | #include <QtCore/qlist.h> |
12 | #include <QtCore/qobjectdefs.h> |
13 | |
14 | QT_BEGIN_NAMESPACE |
15 | |
16 | class QEasingCurvePrivate; |
17 | class QPointF; |
18 | class Q_CORE_EXPORT QEasingCurve |
19 | { |
20 | Q_GADGET |
21 | public: |
22 | enum Type { |
23 | Linear, |
24 | InQuad, OutQuad, InOutQuad, OutInQuad, |
25 | InCubic, OutCubic, InOutCubic, OutInCubic, |
26 | InQuart, OutQuart, InOutQuart, OutInQuart, |
27 | InQuint, OutQuint, InOutQuint, OutInQuint, |
28 | InSine, OutSine, InOutSine, OutInSine, |
29 | InExpo, OutExpo, InOutExpo, OutInExpo, |
30 | InCirc, OutCirc, InOutCirc, OutInCirc, |
31 | InElastic, OutElastic, InOutElastic, OutInElastic, |
32 | InBack, OutBack, InOutBack, OutInBack, |
33 | InBounce, OutBounce, InOutBounce, OutInBounce, |
34 | InCurve, OutCurve, SineCurve, CosineCurve, |
35 | BezierSpline, TCBSpline, Custom, NCurveTypes |
36 | }; |
37 | Q_ENUM(Type) |
38 | |
39 | QEasingCurve(Type type = Linear); |
40 | QEasingCurve(const QEasingCurve &other); |
41 | ~QEasingCurve(); |
42 | |
43 | QEasingCurve &operator=(const QEasingCurve &other) |
44 | { if ( this != &other ) { QEasingCurve copy(other); swap(other&: copy); } return *this; } |
45 | QEasingCurve(QEasingCurve &&other) noexcept : d_ptr(other.d_ptr) { other.d_ptr = nullptr; } |
46 | QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QEasingCurve) |
47 | |
48 | void swap(QEasingCurve &other) noexcept { qt_ptr_swap(lhs&: d_ptr, rhs&: other.d_ptr); } |
49 | |
50 | bool operator==(const QEasingCurve &other) const; |
51 | inline bool operator!=(const QEasingCurve &other) const |
52 | { return !(this->operator==(other)); } |
53 | |
54 | qreal amplitude() const; |
55 | void setAmplitude(qreal amplitude); |
56 | |
57 | qreal period() const; |
58 | void setPeriod(qreal period); |
59 | |
60 | qreal overshoot() const; |
61 | void setOvershoot(qreal overshoot); |
62 | |
63 | void addCubicBezierSegment(const QPointF &c1, const QPointF &c2, const QPointF &endPoint); |
64 | void addTCBSegment(const QPointF &nextPoint, qreal t, qreal c, qreal b); |
65 | QList<QPointF> toCubicSpline() const; |
66 | |
67 | Type type() const; |
68 | void setType(Type type); |
69 | typedef qreal (*EasingFunction)(qreal progress); |
70 | void setCustomType(EasingFunction func); |
71 | EasingFunction customType() const; |
72 | |
73 | qreal valueForProgress(qreal progress) const; |
74 | |
75 | private: |
76 | QEasingCurvePrivate *d_ptr; |
77 | #ifndef QT_NO_DEBUG_STREAM |
78 | friend Q_CORE_EXPORT QDebug operator<<(QDebug debug, const QEasingCurve &item); |
79 | #endif |
80 | #ifndef QT_NO_DATASTREAM |
81 | friend Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QEasingCurve &); |
82 | friend Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QEasingCurve &); |
83 | #endif |
84 | }; |
85 | Q_DECLARE_SHARED(QEasingCurve) |
86 | |
87 | #ifndef QT_NO_DEBUG_STREAM |
88 | Q_CORE_EXPORT QDebug operator<<(QDebug debug, const QEasingCurve &item); |
89 | #endif |
90 | |
91 | #ifndef QT_NO_DATASTREAM |
92 | Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QEasingCurve &); |
93 | Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QEasingCurve &); |
94 | #endif |
95 | |
96 | QT_END_NAMESPACE |
97 | |
98 | #endif |
99 | |