##// END OF EJS Templates
Use light outline color instead of dark for bar, area and scatter
Use light outline color instead of dark for bar, area and scatter

File last commit:

r635:c28f6c761b2a
r653:f4e416c6727f
Show More
chartanimator.cpp
261 lines | 6.7 KiB | text/x-c | CppLexer
Michal Klocek
Animation refactor...
r530 #include "chartanimator_p.h"
#include "axisanimation_p.h"
#include "xyanimation_p.h"
Michal Klocek
Improves spline interpolation...
r622 #include "splineanimation_p.h"
Michal Klocek
Animation refactor...
r530 #include "xychartitem_p.h"
Jani Honkonen
Add animations to pie. Works but has some visual issues when adding slices.
r618 #include "pieanimation_p.h"
Michal Klocek
Adds area chart animations...
r560 #include "areachartitem_p.h"
Michal Klocek
Improves spline interpolation...
r622 #include "splinechartitem_p.h"
#include "scatterchartitem_p.h"
Michal Klocek
Animation refactor...
r530 #include <QTimer>
Q_DECLARE_METATYPE(QVector<QPointF>)
Q_DECLARE_METATYPE(QVector<qreal>)
QTCOMMERCIALCHART_BEGIN_NAMESPACE
const static int duration = 1000;
ChartAnimator::ChartAnimator(QObject *parent):QObject(parent)
{
}
ChartAnimator::~ChartAnimator()
{
}
void ChartAnimator::addAnimation(AxisItem* item)
{
Michal Klocek
Adds area chart animations...
r560 ChartAnimation* animation = m_animations.value(item);
Michal Klocek
Animation refactor...
r530
if(!animation) {
animation = new AxisAnimation(item);
m_animations.insert(item,animation);
}
item->setAnimator(this);
}
Michal Klocek
Improves spline interpolation...
r622 void ChartAnimator::addAnimation(SplineChartItem* item)
{
ChartAnimation* animation = m_animations.value(item);
if(!animation) {
animation = new SplineAnimation(item);
m_animations.insert(item,animation);
}
item->setAnimator(this);
}
void ChartAnimator::addAnimation(ScatterChartItem* item)
{
ChartAnimation* animation = m_animations.value(item);
if(!animation) {
animation = new XYAnimation(item);
m_animations.insert(item,animation);
}
item->setAnimator(this);
}
void ChartAnimator::addAnimation(LineChartItem* item)
Michal Klocek
Animation refactor...
r530 {
Michal Klocek
Adds area chart animations...
r560 ChartAnimation* animation = m_animations.value(item);
Michal Klocek
Animation refactor...
r530
if(!animation) {
animation = new XYAnimation(item);
m_animations.insert(item,animation);
}
item->setAnimator(this);
}
Jani Honkonen
Add animations to pie. Works but has some visual issues when adding slices.
r618 void ChartAnimator::addAnimation(PieChartItem* item)
{
ChartAnimation* animation = m_animations.value(item);
if(!animation) {
animation = new PieAnimation(item);
m_animations.insert(item,animation);
}
item->setAnimator(this);
}
Michal Klocek
Animation refactor...
r530 void ChartAnimator::removeAnimation(ChartItem* item)
{
item->setAnimator(0);
m_animations.remove(item);
}
Michal Klocek
Renames axisitem applyLayout to updateLayout
r635 void ChartAnimator::updateLayout(AxisItem* item , QVector<qreal>& newLayout)
Michal Klocek
Animation refactor...
r530 {
AxisAnimation* animation = static_cast<AxisAnimation*>(m_animations.value(item));
Michal Klocek
Adds area chart animations...
r560 Q_ASSERT(animation);
Michal Klocek
Animation refactor...
r530
QVector<qreal> oldLayout = item->layout();
if(newLayout.count()==0) return;
Michal Klocek
Adds scroll support...
r531 switch(m_state)
{
case ZoomOutState: {
QRectF rect = item->geometry();
oldLayout.resize(newLayout.count());
for(int i=0,j=oldLayout.count()-1;i<(oldLayout.count()+1)/2;i++,j--)
{
oldLayout[i]= item->axisType()==AxisItem::X_AXIS?rect.left():rect.bottom();
oldLayout[j]= item->axisType()==AxisItem::X_AXIS?rect.right():rect.top();
}
}
break;
case ZoomInState: {
int index = qMin(oldLayout.count()*(item->axisType()==AxisItem::X_AXIS?m_point.x():(1 -m_point.y())),newLayout.count()-1.0);
oldLayout.resize(newLayout.count());
for(int i=0;i<oldLayout.count();i++)
{
oldLayout[i]= oldLayout[index];
}
}
break;
case ScrollDownState:
case ScrollRightState: {
oldLayout.resize(newLayout.count());
for(int i=0, j=i+1;i<oldLayout.count()-1;i++,j++)
{
oldLayout[i]= oldLayout[j];
}
}
break;
case ScrollUpState:
case ScrollLeftState: {
oldLayout.resize(newLayout.count());
for(int i=oldLayout.count()-1, j=i-1;i>0;i--,j--)
{
oldLayout[i]= oldLayout[j];
}
}
break;
default: {
oldLayout.resize(newLayout.count());
QRectF rect = item->geometry();
for(int i=0, j=oldLayout.count()-1;i<oldLayout.count();i++,j--)
{
oldLayout[i]= item->axisType()==AxisItem::X_AXIS?rect.left():rect.top();
}
}
break;
}
Michal Klocek
Animation refactor...
r530
if(animation->state()!=QAbstractAnimation::Stopped) {
animation->stop();
}
animation->setDuration(duration);
animation->setEasingCurve(QEasingCurve::OutQuart);
QVariantAnimation::KeyValues value;
animation->setKeyValues(value); //workaround for wrong interpolation call
animation->setKeyValueAt(0.0, qVariantFromValue(oldLayout));
animation->setKeyValueAt(1.0, qVariantFromValue(newLayout));
QTimer::singleShot(0,animation,SLOT(start()));
}
Michal Klocek
Improves spline interpolation...
r622 void ChartAnimator::updateLayout(SplineChartItem* item, QVector<QPointF>& oldPoints ,QVector<QPointF>& newPoints, QVector<QPointF>& oldControlPoints, QVector<QPointF>& newControlPoints,int index)
Michal Klocek
Animation refactor...
r530 {
Michal Klocek
Improves spline interpolation...
r622 SplineAnimation* animation = static_cast<SplineAnimation*>(m_animations.value(item));
Michal Klocek
Animation refactor...
r530
Michal Klocek
Adds area chart animations...
r560 Q_ASSERT(animation);
Michal Klocek
Animation refactor...
r530
Michal Klocek
Improves spline interpolation...
r622 if(newPoints.count()<2 || newControlPoints.count()<2) return;
Michal Klocek
Animation refactor...
r530
bool empty = oldPoints.count()==0;
Michal Klocek
Improves spline interpolation...
r622
Michal Klocek
Animation refactor...
r530
if(animation->state()!=QAbstractAnimation::Stopped) {
Michal Klocek
Improves spline interpolation...
r622 animation->stop();
Michal Klocek
Animation refactor...
r530 }
animation->setDuration(duration);
if(!empty)
Michal Klocek
Improves spline interpolation...
r622 animation->setAnimationType(ChartAnimation::MoveDownAnimation);
Michal Klocek
Animation refactor...
r530 else
Michal Klocek
Improves spline interpolation...
r622 animation->setAnimationType(ChartAnimation::LineDrawAnimation);
Michal Klocek
Animation refactor...
r530 animation->setEasingCurve(QEasingCurve::OutQuart);
Michal Klocek
Improves spline interpolation...
r622 animation->setValues(oldPoints,newPoints,oldControlPoints,newControlPoints,index);
Michal Klocek
Animation refactor...
r530 QTimer::singleShot(0,animation,SLOT(start()));
}
Michal Klocek
Improves spline interpolation...
r622
void ChartAnimator::updateLayout(XYChartItem* item, QVector<QPointF>& oldPoints , QVector<QPointF>& newPoints, int index)
Michal Klocek
Animation refactor...
r530 {
XYAnimation* animation = static_cast<XYAnimation*>(m_animations.value(item));
Michal Klocek
Adds area chart animations...
r560 Q_ASSERT(animation);
Michal Klocek
Animation refactor...
r530
Michal Klocek
Improves spline interpolation...
r622 if(newPoints.count()==0) return;
bool empty = oldPoints.count()==0;
if(animation->state()!=QAbstractAnimation::Stopped) {
animation->stop();
}
Michal Klocek
Animation refactor...
r530 animation->setDuration(duration);
Michal Klocek
Improves spline interpolation...
r622 if(!empty)
animation->setAnimationType(ChartAnimation::MoveDownAnimation);
else
animation->setAnimationType(ChartAnimation::LineDrawAnimation);
Michal Klocek
Animation refactor...
r530 animation->setEasingCurve(QEasingCurve::OutQuart);
Michal Klocek
Improves spline interpolation...
r622 animation->setValues(oldPoints,newPoints,index);
Michal Klocek
Animation refactor...
r530
QTimer::singleShot(0,animation,SLOT(start()));
}
Jani Honkonen
Nicer animation for adding a pie initially.
r634 void ChartAnimator::addAnimation(PieChartItem* item, QPieSlice *slice, const PieSliceLayout &layout, bool isEmpty)
Jani Honkonen
Add animations to pie. Works but has some visual issues when adding slices.
r618 {
PieAnimation* animation = static_cast<PieAnimation*>(m_animations.value(item));
Q_ASSERT(animation);
Jani Honkonen
Nicer animation for adding a pie initially.
r634 animation->addSlice(slice, layout, isEmpty);
Jani Honkonen
Refactoring pie series and animations.
r621 }
void ChartAnimator::removeAnimation(PieChartItem* item, QPieSlice *slice)
{
PieAnimation* animation = static_cast<PieAnimation*>(m_animations.value(item));
Q_ASSERT(animation);
animation->removeSlice(slice);
}
Jani Honkonen
Getting rid of slice pointer in PieSliceLayout.
r629 void ChartAnimator::updateLayout(PieChartItem* item, const PieLayout &layout)
Jani Honkonen
Refactoring pie series and animations.
r621 {
PieAnimation* animation = static_cast<PieAnimation*>(m_animations.value(item));
Q_ASSERT(animation);
animation->updateValues(layout);
Jani Honkonen
Add animations to pie. Works but has some visual issues when adding slices.
r618 }
Jani Honkonen
Getting rid of slice pointer in PieSliceLayout.
r629 void ChartAnimator::updateLayout(PieChartItem* item, QPieSlice *slice, const PieSliceLayout &layout)
Jani Honkonen
Add animations to pie. Works but has some visual issues when adding slices.
r618 {
PieAnimation* animation = static_cast<PieAnimation*>(m_animations.value(item));
Q_ASSERT(animation);
Jani Honkonen
Getting rid of slice pointer in PieSliceLayout.
r629 animation->updateValue(slice, layout);
Jani Honkonen
Add animations to pie. Works but has some visual issues when adding slices.
r618 }
Michal Klocek
Adds scroll support...
r531 void ChartAnimator::setState(State state,const QPointF& point)
{
m_state=state;
m_point=point;
}
Michal Klocek
Animation refactor...
r530 QTCOMMERCIALCHART_END_NAMESPACE