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 QVARIANTANIMATION_P_H |
5 | #define QVARIANTANIMATION_P_H |
6 | |
7 | // |
8 | // W A R N I N G |
9 | // ------------- |
10 | // |
11 | // This file is not part of the Qt API. It exists purely as an |
12 | // implementation detail. This header file may change from version to |
13 | // version without notice, or even be removed. |
14 | // |
15 | // We mean it. |
16 | // |
17 | |
18 | #include "qvariantanimation.h" |
19 | #include <QtCore/qeasingcurve.h> |
20 | #include <QtCore/qmetaobject.h> |
21 | |
22 | #include "private/qabstractanimation_p.h" |
23 | #include "private/qproperty_p.h" |
24 | |
25 | #include <type_traits> |
26 | |
27 | QT_REQUIRE_CONFIG(animation); |
28 | |
29 | QT_BEGIN_NAMESPACE |
30 | |
31 | class QVariantAnimationPrivate : public QAbstractAnimationPrivate |
32 | { |
33 | Q_DECLARE_PUBLIC(QVariantAnimation) |
34 | public: |
35 | |
36 | QVariantAnimationPrivate(); |
37 | |
38 | static QVariantAnimationPrivate *get(QVariantAnimation *q) |
39 | { |
40 | return q->d_func(); |
41 | } |
42 | |
43 | void setDefaultStartEndValue(const QVariant &value); |
44 | |
45 | |
46 | QVariant currentValue; |
47 | QVariant defaultStartEndValue; |
48 | |
49 | //this is used to keep track of the KeyValue interval in which we currently are |
50 | struct |
51 | { |
52 | QVariantAnimation::KeyValue start, end; |
53 | } currentInterval; |
54 | |
55 | void setEasingCurve(const QEasingCurve &easing) { q_func()->setEasingCurve(easing); } |
56 | Q_OBJECT_COMPAT_PROPERTY(QVariantAnimationPrivate, QEasingCurve, easing, |
57 | &QVariantAnimationPrivate::setEasingCurve) |
58 | |
59 | void setDuration(int msecs) { q_func()->setDuration(msecs); } |
60 | Q_OBJECT_COMPAT_PROPERTY(QVariantAnimationPrivate, int, duration, |
61 | &QVariantAnimationPrivate::setDuration) |
62 | |
63 | QVariantAnimation::KeyValues keyValues; |
64 | QVariantAnimation::Interpolator interpolator; |
65 | |
66 | void setCurrentValueForProgress(const qreal progress); |
67 | void recalculateCurrentInterval(bool force=false); |
68 | void setValueAt(qreal, const QVariant &); |
69 | QVariant valueAt(qreal step) const; |
70 | void convertValues(int t); |
71 | |
72 | void updateInterpolator(); |
73 | |
74 | //XXX this is needed by dui |
75 | static Q_CORE_EXPORT QVariantAnimation::Interpolator getInterpolator(int interpolationType); |
76 | }; |
77 | |
78 | //this should make the interpolation faster |
79 | template<typename T> |
80 | typename std::enable_if<std::is_unsigned<T>::value, T>::type |
81 | _q_interpolate(const T &f, const T &t, qreal progress) |
82 | { |
83 | return T(f + t * progress - f * progress); |
84 | } |
85 | |
86 | // the below will apply also to all non-arithmetic types |
87 | template<typename T> |
88 | typename std::enable_if<!std::is_unsigned<T>::value, T>::type |
89 | _q_interpolate(const T &f, const T &t, qreal progress) |
90 | { |
91 | return T(f + (t - f) * progress); |
92 | } |
93 | |
94 | template<typename T > inline QVariant _q_interpolateVariant(const T &from, const T &to, qreal progress) |
95 | { |
96 | return _q_interpolate(from, to, progress); |
97 | } |
98 | |
99 | |
100 | QT_END_NAMESPACE |
101 | |
102 | #endif //QVARIANTANIMATION_P_H |
103 | |