#ifndef XYCHARTANIMATOR_P_H_ #define XYCHARTANIMATOR_P_H_ #include "qchartglobal.h" #include #include QTCOMMERCIALCHART_BEGIN_NAMESPACE template class XYChartAnimationItem; template class XYChartAnimator : public QVariantAnimation { public: enum Animation { LineDrawAnimation, MoveDownAnimation, MoveUpAnimation }; XYChartAnimator(XYChartAnimationItem *item, QObject *parent = 0 ); ~XYChartAnimator(); void setAnimationType(Animation type); protected: QVariant interpolated(const QVariant &start, const QVariant & end, qreal progress ) const; void updateCurrentValue (const QVariant & value ); void updateState ( QAbstractAnimation::State newState, QAbstractAnimation::State oldState); private: XYChartAnimationItem *m_item; Animation m_type; }; template XYChartAnimator::XYChartAnimator(XYChartAnimationItem *item , QObject *parent):QVariantAnimation(parent), m_item(item), m_type(MoveDownAnimation) { } template XYChartAnimator::~XYChartAnimator() { } template void XYChartAnimator::setAnimationType(Animation type) { m_type=type; } template QVariant XYChartAnimator::interpolated(const QVariant &start, const QVariant & end, qreal progress ) const { QVector startVector = qVariantValue >(start); QVector endVector = qVariantValue >(end); QVector result; switch(m_type) { case MoveDownAnimation: { Q_ASSERT(startVector.count() == endVector.count()); 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: qWarning()<<"Unknow type of animation"; break; } return qVariantFromValue(result); } template void XYChartAnimator::updateCurrentValue (const QVariant & value ) { if(state()!=QAbstractAnimation::Stopped){ //workaround QVector vector = qVariantValue >(value); m_item->setGeometry(vector); } } template void XYChartAnimator::updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState) { Q_UNUSED(oldState) if (newState==QAbstractAnimation::Running) m_item->animationStarted(); QVariantAnimation::updateState(newState,oldState); } QTCOMMERCIALCHART_END_NAMESPACE #endif /* XYCHARTANIMATOR_P_H_ */