axisanimationitem.cpp
77 lines
| 2.0 KiB
| text/x-c
|
CppLexer
/ src / axisanimationitem.cpp
|
r291 | #include "axisanimationitem_p.h" | ||
|
r393 | #include <QTimer> | ||
|
r291 | |||
Q_DECLARE_METATYPE(QVector<qreal>) | ||||
QTCOMMERCIALCHART_BEGIN_NAMESPACE | ||||
const static int duration = 500; | ||||
|
r439 | AxisAnimationItem::AxisAnimationItem(QChartAxis* axis,AxisType type,QGraphicsItem* parent) : | ||
AxisItem(axis,type,parent), | ||||
|
r393 | m_animation(new AxisAnimator(this,this)) | ||
|
r291 | { | ||
} | ||||
AxisAnimationItem::~AxisAnimationItem() | ||||
{ | ||||
} | ||||
|
r452 | void AxisAnimationItem::updateItem() | ||
|
r291 | { | ||
|
r452 | QVector<qreal> oldLayout = layout(); | ||
AxisItem::updateItem(); | ||||
QVector<qreal> newLayout = layout(); | ||||
|
r393 | if(newLayout.count()==0) return; | ||
oldLayout.resize(newLayout.size()); | ||||
if(m_animation->state()!=QAbstractAnimation::Stopped){ | ||||
m_animation->stop(); | ||||
} | ||||
m_animation->setDuration(duration); | ||||
m_animation->setEasingCurve(QEasingCurve::InOutBack); | ||||
m_animation->setKeyValueAt(0.0, qVariantFromValue(oldLayout)); | ||||
m_animation->setKeyValueAt(1.0, qVariantFromValue(newLayout)); | ||||
QTimer::singleShot(0,m_animation,SLOT(start())); | ||||
|
r291 | } | ||
void AxisAnimationItem::setLabelsAngle(int angle) | ||||
{ | ||||
AxisItem::setLabelsAngle(angle); | ||||
} | ||||
|
r303 | AxisAnimator::AxisAnimator(AxisItem *axis,QObject *parent): QVariantAnimation(parent), | ||
m_axis(axis) | ||||
|
r291 | { | ||
} | ||||
AxisAnimator::~AxisAnimator() | ||||
{ | ||||
} | ||||
QVariant AxisAnimator::interpolated(const QVariant &start, const QVariant & end, qreal progress ) const | ||||
{ | ||||
QVector<qreal> startVector = qVariantValue<QVector<qreal> >(start); | ||||
QVector<qreal> endVecotr = qVariantValue<QVector<qreal> >(end); | ||||
QVector<qreal> result; | ||||
Q_ASSERT(startVector.count() == endVecotr.count()); | ||||
for(int i =0 ;i< startVector.count();i++){ | ||||
qreal value = startVector[i] + ((endVecotr[i]- startVector[i]) * progress);//qBound(0.0, progress, 1.0)); | ||||
result << value; | ||||
} | ||||
return qVariantFromValue(result); | ||||
} | ||||
void AxisAnimator::updateCurrentValue (const QVariant & value ) | ||||
{ | ||||
QVector<qreal> vector = qVariantValue<QVector<qreal> >(value); | ||||
|
r452 | m_axis->setLayout(vector); | ||
|
r291 | } | ||
#include "moc_axisanimationitem_p.cpp" | ||||
QTCOMMERCIALCHART_END_NAMESPACE | ||||