2022-05-10 10:06:48 +00:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
#ifndef ANIMATION_H
|
|
|
|
#define ANIMATION_H
|
|
|
|
|
2011-05-07 20:57:49 +00:00
|
|
|
#include <QtWidgets>
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
#include <QtCore/qpropertyanimation.h>
|
|
|
|
|
|
|
|
class Animation : public QPropertyAnimation {
|
|
|
|
public:
|
|
|
|
enum PathType {
|
|
|
|
LinearPath,
|
|
|
|
CirclePath,
|
|
|
|
NPathTypes
|
|
|
|
};
|
|
|
|
Animation(QObject *target, const QByteArray &prop)
|
|
|
|
: QPropertyAnimation(target, prop)
|
|
|
|
{
|
|
|
|
setPathType(LinearPath);
|
|
|
|
}
|
|
|
|
|
|
|
|
void setPathType(PathType pathType)
|
|
|
|
{
|
|
|
|
if (pathType >= NPathTypes)
|
|
|
|
qWarning("Unknown pathType %d", pathType);
|
|
|
|
|
|
|
|
m_pathType = pathType;
|
|
|
|
m_path = QPainterPath();
|
|
|
|
}
|
|
|
|
|
2016-06-15 08:12:35 +00:00
|
|
|
void updateCurrentTime(int currentTime) override
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
if (m_pathType == CirclePath) {
|
|
|
|
if (m_path.isEmpty()) {
|
|
|
|
QPointF to = endValue().toPointF();
|
|
|
|
QPointF from = startValue().toPointF();
|
|
|
|
m_path.moveTo(from);
|
|
|
|
m_path.addEllipse(QRectF(from, to));
|
|
|
|
}
|
|
|
|
int dura = duration();
|
|
|
|
const qreal progress = ((dura == 0) ? 1 : ((((currentTime - 1) % dura) + 1) / qreal(dura)));
|
|
|
|
|
|
|
|
qreal easedProgress = easingCurve().valueForProgress(progress);
|
|
|
|
if (easedProgress > 1.0) {
|
|
|
|
easedProgress -= 1.0;
|
|
|
|
} else if (easedProgress < 0) {
|
|
|
|
easedProgress += 1.0;
|
|
|
|
}
|
|
|
|
QPointF pt = m_path.pointAtPercent(easedProgress);
|
|
|
|
updateCurrentValue(pt);
|
|
|
|
emit valueChanged(pt);
|
|
|
|
} else {
|
|
|
|
QPropertyAnimation::updateCurrentTime(currentTime);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QPainterPath m_path;
|
|
|
|
PathType m_pathType;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // ANIMATION_H
|