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
27QT_REQUIRE_CONFIG(animation);
28
29QT_BEGIN_NAMESPACE
30
31class QVariantAnimationPrivate : public QAbstractAnimationPrivate
32{
33 Q_DECLARE_PUBLIC(QVariantAnimation)
34public:
35
36 QVariantAnimationPrivate();
37 ~QVariantAnimationPrivate() override;
38
39 static QVariantAnimationPrivate *get(QVariantAnimation *q)
40 {
41 return q->d_func();
42 }
43
44 void setDefaultStartEndValue(const QVariant &value);
45
46
47 QVariant currentValue;
48 QVariant defaultStartEndValue;
49
50 //this is used to keep track of the KeyValue interval in which we currently are
51 struct
52 {
53 QVariantAnimation::KeyValue start, end;
54 } currentInterval;
55
56 void setEasingCurve(const QEasingCurve &easing) { q_func()->setEasingCurve(easing); }
57 Q_OBJECT_COMPAT_PROPERTY(QVariantAnimationPrivate, QEasingCurve, easing,
58 &QVariantAnimationPrivate::setEasingCurve)
59
60 void setDuration(int msecs) { q_func()->setDuration(msecs); }
61 Q_OBJECT_COMPAT_PROPERTY(QVariantAnimationPrivate, int, duration,
62 &QVariantAnimationPrivate::setDuration)
63
64 QVariantAnimation::KeyValues keyValues;
65 QVariantAnimation::Interpolator interpolator;
66
67 void setCurrentValueForProgress(const qreal progress);
68 void recalculateCurrentInterval(bool force=false);
69 void setValueAt(qreal, const QVariant &);
70 QVariant valueAt(qreal step) const;
71 void convertValues(int t);
72
73 void updateInterpolator();
74
75 //XXX this is needed by dui
76 static Q_CORE_EXPORT QVariantAnimation::Interpolator getInterpolator(int interpolationType);
77};
78
79//this should make the interpolation faster
80template<typename T>
81typename std::enable_if<std::is_unsigned<T>::value, T>::type
82_q_interpolate(const T &f, const T &t, qreal progress)
83{
84 return T(f + t * progress - f * progress);
85}
86
87// the below will apply also to all non-arithmetic types
88template<typename T>
89typename std::enable_if<!std::is_unsigned<T>::value, T>::type
90_q_interpolate(const T &f, const T &t, qreal progress)
91{
92 return T(f + (t - f) * progress);
93}
94
95template<typename T > inline QVariant _q_interpolateVariant(const T &from, const T &to, qreal progress)
96{
97 return _q_interpolate(from, to, progress);
98}
99
100
101QT_END_NAMESPACE
102
103#endif //QVARIANTANIMATION_P_H
104

Provided by KDAB

Privacy Policy
Learn to use CMake with our Intro Training
Find out more

source code of qtbase/src/corelib/animation/qvariantanimation_p.h