##// END OF EJS Templates
legend refactoring.
legend refactoring.

File last commit:

r738:ce991d3dee26
r792:f33d64d30a1c
Show More
splineanimation.cpp
129 lines | 4.7 KiB | text/x-c | CppLexer
/ src / animations / splineanimation.cpp
Michal Klocek
Improves spline interpolation...
r622 #include "splineanimation_p.h"
#include "splinechartitem_p.h"
Q_DECLARE_METATYPE(QVector<QPointF>)
Q_DECLARE_METATYPE(SplineVector)
QTCOMMERCIALCHART_BEGIN_NAMESPACE
SplineAnimation::SplineAnimation(SplineChartItem* item):ChartAnimation(item),
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738 m_item(item),
m_dirty(true)
Michal Klocek
Improves spline interpolation...
r622 {
}
SplineAnimation::~SplineAnimation()
{
}
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738 void SplineAnimation::setValues(QVector<QPointF> &oldPoints, QVector<QPointF> &newPoints, QVector<QPointF> &oldControlPoints, QVector<QPointF> &newControlPoints, int index)
Michal Klocek
Improves spline interpolation...
r622 {
int x = oldPoints.count();
int y = newPoints.count();
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738 Q_ASSERT(newPoints.count() * 2 - 2 == newControlPoints.count());
Michal Klocek
Improves spline interpolation...
r622
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738 if (x != y && abs(x - y) != 1) {
m_oldSpline.first = newPoints;
m_oldSpline.second = newControlPoints;
Michal Klocek
Improves spline interpolation...
r622 oldPoints.resize(newPoints.size());
oldControlPoints.resize(newControlPoints.size());
SplineVector oldPair;
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738 oldPair.first = oldPoints;
oldPair.second = oldControlPoints;
Michal Klocek
Improves spline interpolation...
r622 SplineVector newPair;
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738 newPair.first = newPoints;
newPair.second = newControlPoints;
Michal Klocek
Improves spline interpolation...
r622 setKeyValueAt(0.0, qVariantFromValue(oldPair));
setKeyValueAt(1.0, qVariantFromValue(newPair));
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738 m_dirty = false;
Michal Klocek
Improves spline interpolation...
r622 }
else {
if(m_dirty) {
m_oldSpline.first = oldPoints;
m_oldSpline.second = oldControlPoints;
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738 m_dirty = false;
Michal Klocek
Improves spline interpolation...
r622 }
oldPoints = newPoints;
oldControlPoints = newControlPoints;
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738 if (y < x) {
Michal Klocek
Improves spline interpolation...
r622 m_oldSpline.first.remove(index); //remove
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738 m_oldSpline.second.remove(index * 2);
m_oldSpline.second.remove(index * 2);
Michal Klocek
Improves spline interpolation...
r622 }
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738 if (y > x) {
m_oldSpline.first.insert(index, x > 0 ? m_oldSpline.first[index-1] : newPoints[index]); //add
m_oldSpline.second.insert((index - 1) * 2, x > 1 ? m_oldSpline.second[(index-2)*2] : newControlPoints[(index - 1) * 2]); //add
m_oldSpline.second.insert((index - 1) * 2 + 1, x > 1 ? m_oldSpline.second[(index - 2) * 2 + 1] : newControlPoints[(index - 1) * 2 + 1]); //add
Michal Klocek
Improves spline interpolation...
r622 }
SplineVector newPair;
newPair.first=newPoints;
newPair.second=newControlPoints;
setKeyValueAt(0.0, qVariantFromValue(m_oldSpline));
setKeyValueAt(1.0, qVariantFromValue(newPair));
}
}
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738 QVariant SplineAnimation::interpolated(const QVariant &start, const QVariant &end, qreal progress ) const
Michal Klocek
Improves spline interpolation...
r622 {
SplineVector startPair = qVariantValue< SplineVector >(start);
SplineVector endPair = qVariantValue< SplineVector >(end);
SplineVector result;
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738 switch (m_type) {
Michal Klocek
Improves spline interpolation...
r622
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738 case MoveDownAnimation: {
if (startPair.first.count() != endPair.first.count())
Michal Klocek
Improves spline interpolation...
r622 break;
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738 Q_ASSERT(startPair.first.count() * 2 - 2 == startPair.second.count());
Q_ASSERT(endPair.first.count() * 2 - 2 == endPair.second.count());
for(int i = 0; i < endPair.first.count(); i++) {
qreal x = startPair.first[i].x() + ((endPair.first[i].x() - startPair.first[i].x()) * progress);
qreal y = startPair.first[i].y() + ((endPair.first[i].y() - startPair.first[i].y()) * progress);
result.first << QPointF(x,y);
if (i + 1 >= endPair.first.count())
continue;
x = startPair.second[i * 2].x() + ((endPair.second[i * 2].x() - startPair.second[i * 2].x()) * progress);
y = startPair.second[i * 2].y() + ((endPair.second[i * 2].y() - startPair.second[i * 2].y()) * progress);
result.second << QPoint(x,y);
x = startPair.second[i * 2 + 1].x() + ((endPair.second[i * 2 + 1].x() - startPair.second[i * 2 + 1].x()) * progress);
y = startPair.second[i * 2 + 1].y() + ((endPair.second[i * 2 + 1].y() - startPair.second[i * 2 + 1].y()) * progress);
result.second << QPoint(x,y);
Michal Klocek
Improves spline interpolation...
r622 }
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738
}
break;
case LineDrawAnimation:{
Q_ASSERT(endPair.first.count() * 2 - 2 == endPair.second.count());
int count = endPair.first.count()* qBound(0.0, progress, 1.0);
for(int i = 0; i < count; i++) {
result.first << endPair.first[i];
if(i + 1 == count)
break;
result.second << endPair.second[2 * i];
result.second << endPair.second[2 * i + 1];
}
}
break;
default:
qWarning() << "Unknow type of animation";
break;
Michal Klocek
Improves spline interpolation...
r622 }
return qVariantFromValue(result);
}
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738 void SplineAnimation::updateCurrentValue (const QVariant &value )
Michal Klocek
Improves spline interpolation...
r622 {
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738 if (state() != QAbstractAnimation::Stopped) { //workaround
m_dirty = true;
Michal Klocek
Improves spline interpolation...
r622 QPair<QVector<QPointF >, QVector<QPointF > > pair = qVariantValue< QPair< QVector<QPointF>, QVector<QPointF> > >(value);
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738 m_item->setLayout(pair.first, pair.second);
Michal Klocek
Improves spline interpolation...
r622 }
}
QTCOMMERCIALCHART_END_NAMESPACE