| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
| 4 | ** Contact: https://www.qt.io/licensing/ |
| 5 | ** |
| 6 | ** This file is part of the QtCore module of the Qt Toolkit. |
| 7 | ** |
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ |
| 9 | ** Commercial License Usage |
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
| 11 | ** accordance with the commercial license agreement provided with the |
| 12 | ** Software or, alternatively, in accordance with the terms contained in |
| 13 | ** a written agreement between you and The Qt Company. For licensing terms |
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
| 15 | ** information use the contact form at https://www.qt.io/contact-us. |
| 16 | ** |
| 17 | ** GNU Lesser General Public License Usage |
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
| 19 | ** General Public License version 3 as published by the Free Software |
| 20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
| 21 | ** packaging of this file. Please review the following information to |
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements |
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
| 24 | ** |
| 25 | ** GNU General Public License Usage |
| 26 | ** Alternatively, this file may be used under the terms of the GNU |
| 27 | ** General Public License version 2.0 or (at your option) the GNU General |
| 28 | ** Public license version 3 or any later version approved by the KDE Free |
| 29 | ** Qt Foundation. The licenses are as published by the Free Software |
| 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
| 31 | ** included in the packaging of this file. Please review the following |
| 32 | ** information to ensure the GNU General Public License requirements will |
| 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
| 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
| 35 | ** |
| 36 | ** $QT_END_LICENSE$ |
| 37 | ** |
| 38 | ****************************************************************************/ |
| 39 | |
| 40 | #ifndef QEASINGCURVE_H |
| 41 | #define QEASINGCURVE_H |
| 42 | |
| 43 | #include <QtCore/qglobal.h> |
| 44 | |
| 45 | QT_REQUIRE_CONFIG(easingcurve); |
| 46 | |
| 47 | #include <QtCore/qobjectdefs.h> |
| 48 | #include <QtCore/qvector.h> |
| 49 | #if QT_DEPRECATED_SINCE(5, 0) |
| 50 | # include <QtCore/qlist.h> |
| 51 | # include <QtCore/qpoint.h> |
| 52 | #endif |
| 53 | |
| 54 | QT_BEGIN_NAMESPACE |
| 55 | |
| 56 | |
| 57 | class QEasingCurvePrivate; |
| 58 | class QPointF; |
| 59 | class Q_CORE_EXPORT QEasingCurve |
| 60 | { |
| 61 | Q_GADGET |
| 62 | public: |
| 63 | enum Type { |
| 64 | Linear, |
| 65 | InQuad, OutQuad, InOutQuad, OutInQuad, |
| 66 | InCubic, OutCubic, InOutCubic, OutInCubic, |
| 67 | InQuart, OutQuart, InOutQuart, OutInQuart, |
| 68 | InQuint, OutQuint, InOutQuint, OutInQuint, |
| 69 | InSine, OutSine, InOutSine, OutInSine, |
| 70 | InExpo, OutExpo, InOutExpo, OutInExpo, |
| 71 | InCirc, OutCirc, InOutCirc, OutInCirc, |
| 72 | InElastic, OutElastic, InOutElastic, OutInElastic, |
| 73 | InBack, OutBack, InOutBack, OutInBack, |
| 74 | InBounce, OutBounce, InOutBounce, OutInBounce, |
| 75 | InCurve, OutCurve, SineCurve, CosineCurve, |
| 76 | BezierSpline, TCBSpline, Custom, NCurveTypes |
| 77 | }; |
| 78 | Q_ENUM(Type) |
| 79 | |
| 80 | QEasingCurve(Type type = Linear); |
| 81 | QEasingCurve(const QEasingCurve &other); |
| 82 | ~QEasingCurve(); |
| 83 | |
| 84 | QEasingCurve &operator=(const QEasingCurve &other) |
| 85 | { if ( this != &other ) { QEasingCurve copy(other); swap(other&: copy); } return *this; } |
| 86 | QEasingCurve(QEasingCurve &&other) noexcept : d_ptr(other.d_ptr) { other.d_ptr = nullptr; } |
| 87 | QEasingCurve &operator=(QEasingCurve &&other) noexcept |
| 88 | { qSwap(value1&: d_ptr, value2&: other.d_ptr); return *this; } |
| 89 | |
| 90 | void swap(QEasingCurve &other) noexcept { qSwap(value1&: d_ptr, value2&: other.d_ptr); } |
| 91 | |
| 92 | bool operator==(const QEasingCurve &other) const; |
| 93 | inline bool operator!=(const QEasingCurve &other) const |
| 94 | { return !(this->operator==(other)); } |
| 95 | |
| 96 | qreal amplitude() const; |
| 97 | void setAmplitude(qreal amplitude); |
| 98 | |
| 99 | qreal period() const; |
| 100 | void setPeriod(qreal period); |
| 101 | |
| 102 | qreal overshoot() const; |
| 103 | void setOvershoot(qreal overshoot); |
| 104 | |
| 105 | void addCubicBezierSegment(const QPointF & c1, const QPointF & c2, const QPointF & endPoint); |
| 106 | void addTCBSegment(const QPointF &nextPoint, qreal t, qreal c, qreal b); |
| 107 | QVector<QPointF> toCubicSpline() const; |
| 108 | #if QT_DEPRECATED_SINCE(5, 0) |
| 109 | QT_DEPRECATED QList<QPointF> cubicBezierSpline() const { return toCubicSpline().toList(); } |
| 110 | #endif |
| 111 | |
| 112 | Type type() const; |
| 113 | void setType(Type type); |
| 114 | typedef qreal (*EasingFunction)(qreal progress); |
| 115 | void setCustomType(EasingFunction func); |
| 116 | EasingFunction customType() const; |
| 117 | |
| 118 | qreal valueForProgress(qreal progress) const; |
| 119 | private: |
| 120 | QEasingCurvePrivate *d_ptr; |
| 121 | #ifndef QT_NO_DEBUG_STREAM |
| 122 | friend Q_CORE_EXPORT QDebug operator<<(QDebug debug, const QEasingCurve &item); |
| 123 | #endif |
| 124 | #ifndef QT_NO_DATASTREAM |
| 125 | friend Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QEasingCurve&); |
| 126 | friend Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QEasingCurve &); |
| 127 | #endif |
| 128 | }; |
| 129 | Q_DECLARE_SHARED(QEasingCurve) |
| 130 | |
| 131 | #ifndef QT_NO_DEBUG_STREAM |
| 132 | Q_CORE_EXPORT QDebug operator<<(QDebug debug, const QEasingCurve &item); |
| 133 | #endif |
| 134 | |
| 135 | #ifndef QT_NO_DATASTREAM |
| 136 | Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QEasingCurve&); |
| 137 | Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QEasingCurve &); |
| 138 | #endif |
| 139 | |
| 140 | QT_END_NAMESPACE |
| 141 | |
| 142 | #endif |
| 143 | |