xyanimation.cpp
88 lines
| 2.5 KiB
| text/x-c
|
CppLexer
Michal Klocek
|
r530 | #include "xyanimation_p.h" | ||
#include "xychartitem_p.h" | ||||
Q_DECLARE_METATYPE(QVector<QPointF>) | ||||
QTCOMMERCIALCHART_BEGIN_NAMESPACE | ||||
XYAnimation::XYAnimation(XYChartItem *item):ChartAnimation(item), | ||||
m_item(item), | ||||
m_dirty(false) | ||||
{ | ||||
} | ||||
XYAnimation::~XYAnimation() | ||||
{ | ||||
} | ||||
Michal Klocek
|
r622 | void XYAnimation::setValues(QVector<QPointF>& oldPoints,QVector<QPointF>& newPoints,int index) | ||
Michal Klocek
|
r530 | { | ||
Michal Klocek
|
r622 | int x = oldPoints.count(); | ||
int y = newPoints.count(); | ||||
Michal Klocek
|
r530 | |||
Michal Klocek
|
r622 | if(x!=y && abs(x-y)!=1) { | ||
m_oldPoints = newPoints; | ||||
oldPoints.resize(newPoints.size()); | ||||
setKeyValueAt(0.0, qVariantFromValue(oldPoints)); | ||||
setKeyValueAt(1.0, qVariantFromValue(newPoints)); | ||||
Michal Klocek
|
r530 | m_dirty=false; | ||
} | ||||
Michal Klocek
|
r622 | else { | ||
if(m_dirty) { | ||||
m_oldPoints = oldPoints; | ||||
m_dirty=false; | ||||
} | ||||
oldPoints = newPoints; | ||||
if (y<x) (m_oldPoints.remove(index)); //remove | ||||
if (y>x) (m_oldPoints.insert(index,x>0?m_oldPoints[index-1]:newPoints[index])); //add | ||||
setKeyValueAt(0.0, qVariantFromValue(m_oldPoints)); | ||||
setKeyValueAt(1.0, qVariantFromValue(newPoints)); | ||||
Q_ASSERT(m_oldPoints.count() == newPoints.count()); | ||||
} | ||||
Michal Klocek
|
r530 | } | ||
QVariant XYAnimation::interpolated(const QVariant &start, const QVariant & end, qreal progress ) const | ||||
{ | ||||
QVector<QPointF> startVector = qVariantValue<QVector<QPointF> >(start); | ||||
QVector<QPointF> endVector = qVariantValue<QVector<QPointF> >(end); | ||||
QVector<QPointF> result; | ||||
switch(m_type) { | ||||
case MoveDownAnimation: { | ||||
Michal Klocek
|
r602 | if(startVector.count() != endVector.count()) break; | ||
Michal Klocek
|
r530 | for(int i =0;i< startVector.count();i++) { | ||
qreal x = startVector[i].x() + ((endVector[i].x()- startVector[i].x()) * progress); | ||||
qreal y = startVector[i].y() + ((endVector[i].y()- startVector[i].y()) * progress); | ||||
result << QPointF(x,y); | ||||
} | ||||
} | ||||
break; | ||||
case LineDrawAnimation:{ | ||||
for(int i =0;i< endVector.count()* qBound(0.0, progress, 1.0);i++) { | ||||
result << endVector[i]; | ||||
} | ||||
} | ||||
break; | ||||
default: | ||||
Michal Klocek
|
r677 | qWarning()<<"Unknown type of animation"; | ||
Michal Klocek
|
r530 | break; | ||
} | ||||
return qVariantFromValue(result); | ||||
} | ||||
void XYAnimation::updateCurrentValue (const QVariant & value ) | ||||
{ | ||||
if(state()!=QAbstractAnimation::Stopped){ //workaround | ||||
Michal Klocek
|
r622 | m_dirty=true; | ||
Michal Klocek
|
r530 | QVector<QPointF> vector = qVariantValue<QVector<QPointF> >(value); | ||
Michal Klocek
|
r557 | m_item->setLayout(vector); | ||
Michal Klocek
|
r530 | } | ||
} | ||||
QTCOMMERCIALCHART_END_NAMESPACE | ||||