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#include <QtGui/qtguiglobal.h>
4
5#include <QtCore/qvariantanimation.h>
6#include <private/qvariantanimation_p.h>
7#include <QtGui/qcolor.h>
8#include <QtGui/qvector2d.h>
9#include <QtGui/qvector3d.h>
10#include <QtGui/qvector4d.h>
11#include <QtGui/qquaternion.h>
12
13QT_BEGIN_NAMESPACE
14
15template<> Q_INLINE_TEMPLATE QColor _q_interpolate(const QColor &f,const QColor &t, qreal progress)
16{
17 return QColor(qBound(min: 0,val: _q_interpolate(f: f.red(), t: t.red(), progress),max: 255),
18 qBound(min: 0,val: _q_interpolate(f: f.green(), t: t.green(), progress),max: 255),
19 qBound(min: 0,val: _q_interpolate(f: f.blue(), t: t.blue(), progress),max: 255),
20 qBound(min: 0,val: _q_interpolate(f: f.alpha(), t: t.alpha(), progress),max: 255));
21}
22
23template<> Q_INLINE_TEMPLATE QQuaternion _q_interpolate(const QQuaternion &f,const QQuaternion &t, qreal progress)
24{
25 return QQuaternion::slerp(q1: f, q2: t, t: progress);
26}
27
28void qRegisterGuiGetInterpolator()
29{
30 qRegisterAnimationInterpolator<QColor>(func: _q_interpolateVariant<QColor>);
31 qRegisterAnimationInterpolator<QVector2D>(func: _q_interpolateVariant<QVector2D>);
32 qRegisterAnimationInterpolator<QVector3D>(func: _q_interpolateVariant<QVector3D>);
33 qRegisterAnimationInterpolator<QVector4D>(func: _q_interpolateVariant<QVector4D>);
34 qRegisterAnimationInterpolator<QQuaternion>(func: _q_interpolateVariant<QQuaternion>);
35}
36Q_CONSTRUCTOR_FUNCTION(qRegisterGuiGetInterpolator)
37
38static void qUnregisterGuiGetInterpolator()
39{
40 // casts required by Sun CC 5.5
41 qRegisterAnimationInterpolator<QColor>(
42 func: (QVariant (*)(const QColor &, const QColor &, qreal))nullptr);
43 qRegisterAnimationInterpolator<QVector2D>(
44 func: (QVariant (*)(const QVector2D &, const QVector2D &, qreal))nullptr);
45 qRegisterAnimationInterpolator<QVector3D>(
46 func: (QVariant (*)(const QVector3D &, const QVector3D &, qreal))nullptr);
47 qRegisterAnimationInterpolator<QVector4D>(
48 func: (QVariant (*)(const QVector4D &, const QVector4D &, qreal))nullptr);
49 qRegisterAnimationInterpolator<QQuaternion>(
50 func: (QVariant (*)(const QQuaternion &, const QQuaternion &, qreal))nullptr);
51}
52Q_DESTRUCTOR_FUNCTION(qUnregisterGuiGetInterpolator)
53
54QT_END_NAMESPACE
55

source code of qtbase/src/gui/animation/qguivariantanimation.cpp