@@ -1,45 +1,45 | |||||
1 | #include "axisanimation_p.h" |
|
1 | #include "axisanimation_p.h" | |
2 | #include <QTimer> |
|
2 | #include <QTimer> | |
3 |
|
3 | |||
4 | Q_DECLARE_METATYPE(QVector<qreal>) |
|
4 | Q_DECLARE_METATYPE(QVector<qreal>) | |
5 |
|
5 | |||
6 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
6 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
7 |
|
7 | |||
8 |
|
8 | |||
9 | AxisAnimation::AxisAnimation(Axis *axis): ChartAnimation(axis), |
|
9 | AxisAnimation::AxisAnimation(Axis *axis): ChartAnimation(axis), | |
10 | m_axis(axis) |
|
10 | m_axis(axis) | |
11 | { |
|
11 | { | |
12 | } |
|
12 | } | |
13 |
|
13 | |||
14 | AxisAnimation::~AxisAnimation() |
|
14 | AxisAnimation::~AxisAnimation() | |
15 | { |
|
15 | { | |
16 | } |
|
16 | } | |
17 |
|
17 | |||
18 |
QVariant AxisAnimation::interpolated(const QVariant &start, const QVariant & |
|
18 | QVariant AxisAnimation::interpolated(const QVariant &start, const QVariant &end, qreal progress ) const | |
19 | { |
|
19 | { | |
20 | QVector<qreal> startVector = qVariantValue<QVector<qreal> >(start); |
|
20 | QVector<qreal> startVector = qVariantValue<QVector<qreal> >(start); | |
21 | QVector<qreal> endVecotr = qVariantValue<QVector<qreal> >(end); |
|
21 | QVector<qreal> endVecotr = qVariantValue<QVector<qreal> >(end); | |
22 | QVector<qreal> result; |
|
22 | QVector<qreal> result; | |
23 |
|
23 | |||
24 | Q_ASSERT(startVector.count() == endVecotr.count()) ; |
|
24 | Q_ASSERT(startVector.count() == endVecotr.count()) ; | |
25 |
|
25 | |||
26 |
for(int i =0 |
|
26 | for(int i = 0; i < startVector.count(); i++){ | |
27 | qreal value = startVector[i] + ((endVecotr[i]- startVector[i]) * progress);//qBound(0.0, progress, 1.0)); |
|
27 | qreal value = startVector[i] + ((endVecotr[i]- startVector[i]) * progress);//qBound(0.0, progress, 1.0)); | |
28 | result << value; |
|
28 | result << value; | |
29 | } |
|
29 | } | |
30 | return qVariantFromValue(result); |
|
30 | return qVariantFromValue(result); | |
31 | } |
|
31 | } | |
32 |
|
32 | |||
33 |
|
33 | |||
34 |
void AxisAnimation::updateCurrentValue (const QVariant & |
|
34 | void AxisAnimation::updateCurrentValue (const QVariant &value ) | |
35 | { |
|
35 | { | |
36 | if(state()!=QAbstractAnimation::Stopped)//workaround |
|
36 | if (state() != QAbstractAnimation::Stopped)//workaround | |
37 | { |
|
37 | { | |
38 | QVector<qreal> vector = qVariantValue<QVector<qreal> >(value); |
|
38 | QVector<qreal> vector = qVariantValue<QVector<qreal> >(value); | |
39 | Q_ASSERT(vector.count()!=0); |
|
39 | Q_ASSERT(vector.count() != 0); | |
40 | m_axis->setLayout(vector); |
|
40 | m_axis->setLayout(vector); | |
41 | } |
|
41 | } | |
42 |
|
42 | |||
43 | } |
|
43 | } | |
44 |
|
44 | |||
45 | QTCOMMERCIALCHART_END_NAMESPACE |
|
45 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,26 +1,26 | |||||
1 | #ifndef AXISANIMATIONITEM_H_ |
|
1 | #ifndef AXISANIMATIONITEM_H_ | |
2 | #define AXISANIMATIONITEM_H_ |
|
2 | #define AXISANIMATIONITEM_H_ | |
3 |
|
3 | |||
4 | #include "axisitem_p.h" |
|
4 | #include "axisitem_p.h" | |
5 | #include "chartanimation_p.h" |
|
5 | #include "chartanimation_p.h" | |
6 |
|
6 | |||
7 |
|
7 | |||
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
9 |
|
9 | |||
10 | class AxisAnimation: public ChartAnimation |
|
10 | class AxisAnimation: public ChartAnimation | |
11 | { |
|
11 | { | |
12 | public: |
|
12 | public: | |
13 | AxisAnimation(Axis *axis); |
|
13 | AxisAnimation(Axis *axis); | |
14 | ~AxisAnimation(); |
|
14 | ~AxisAnimation(); | |
15 | protected: |
|
15 | protected: | |
16 |
virtual QVariant interpolated |
|
16 | virtual QVariant interpolated(const QVariant &from, const QVariant &to, qreal progress ) const; | |
17 |
virtual void updateCurrentValue |
|
17 | virtual void updateCurrentValue(const QVariant &value ); | |
18 | private: |
|
18 | private: | |
19 |
Axis* |
|
19 | Axis *m_axis; | |
20 | }; |
|
20 | }; | |
21 |
|
21 | |||
22 | QTCOMMERCIALCHART_END_NAMESPACE |
|
22 | QTCOMMERCIALCHART_END_NAMESPACE | |
23 |
|
23 | |||
24 |
|
24 | |||
25 |
|
25 | |||
26 | #endif /* AXISITEM_H_ */ |
|
26 | #endif /* AXISITEM_H_ */ |
@@ -1,52 +1,52 | |||||
1 | #include "baranimation_p.h" |
|
1 | #include "baranimation_p.h" | |
2 | #include "barchartitem_p.h" |
|
2 | #include "barchartitem_p.h" | |
3 | #include <QParallelAnimationGroup> |
|
3 | #include <QParallelAnimationGroup> | |
4 | #include <QTimer> |
|
4 | #include <QTimer> | |
5 |
|
5 | |||
6 | Q_DECLARE_METATYPE(QVector<QRectF>) |
|
6 | Q_DECLARE_METATYPE(QVector<QRectF>) | |
7 | //Q_DECLARE_METATYPE(BarLayout) // TODO? |
|
7 | //Q_DECLARE_METATYPE(BarLayout) // TODO? | |
8 |
|
8 | |||
9 |
|
9 | |||
10 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
10 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
11 |
|
11 | |||
12 | BarAnimation::BarAnimation(BarChartItem *item) |
|
12 | BarAnimation::BarAnimation(BarChartItem *item) | |
13 | :ChartAnimation(item), |
|
13 | :ChartAnimation(item), | |
14 | m_item(item) |
|
14 | m_item(item) | |
15 | { |
|
15 | { | |
16 | } |
|
16 | } | |
17 |
|
17 | |||
18 | BarAnimation::~BarAnimation() |
|
18 | BarAnimation::~BarAnimation() | |
19 | { |
|
19 | { | |
20 | } |
|
20 | } | |
21 |
|
21 | |||
22 | QVariant BarAnimation::interpolated(const QVariant &from, const QVariant &to, qreal progress) const |
|
22 | QVariant BarAnimation::interpolated(const QVariant &from, const QVariant &to, qreal progress) const | |
23 | { |
|
23 | { | |
24 |
QVector<QRectF> startVector = qVariantValue<QVector<QRectF> > |
|
24 | QVector<QRectF> startVector = qVariantValue<QVector<QRectF> >(from); | |
25 |
QVector<QRectF> endVector = qVariantValue<QVector<QRectF> > |
|
25 | QVector<QRectF> endVector = qVariantValue<QVector<QRectF> >(to); | |
26 | QVector<QRectF> result; |
|
26 | QVector<QRectF> result; | |
27 |
|
27 | |||
28 | Q_ASSERT(startVector.count() == endVector.count()) ; |
|
28 | Q_ASSERT(startVector.count() == endVector.count()) ; | |
29 |
|
29 | |||
30 |
for(int i =0 |
|
30 | for(int i = 0; i < startVector.count(); i++) { | |
31 | qreal w = endVector[i].width(); |
|
31 | qreal w = endVector[i].width(); | |
32 | qreal h = startVector[i].height() + ((endVector[i].height() - startVector[i].height()) * progress); |
|
32 | qreal h = startVector[i].height() + ((endVector[i].height() - startVector[i].height()) * progress); | |
33 | qreal x = endVector[i].topLeft().x(); |
|
33 | qreal x = endVector[i].topLeft().x(); | |
34 | qreal y = endVector[i].topLeft().y() + endVector[i].height() - h; |
|
34 | qreal y = endVector[i].topLeft().y() + endVector[i].height() - h; | |
35 |
|
35 | |||
36 | QPointF topLeft(x,y); |
|
36 | QPointF topLeft(x,y); | |
37 | QSizeF size(w,h); |
|
37 | QSizeF size(w,h); | |
38 | QRectF value(topLeft,size); |
|
38 | QRectF value(topLeft,size); | |
39 | result << value; |
|
39 | result << value; | |
40 | } |
|
40 | } | |
41 | return qVariantFromValue(result); |
|
41 | return qVariantFromValue(result); | |
42 | } |
|
42 | } | |
43 |
|
43 | |||
44 | void BarAnimation::updateCurrentValue(const QVariant &value) |
|
44 | void BarAnimation::updateCurrentValue(const QVariant &value) | |
45 | { |
|
45 | { | |
46 | QVector<QRectF> layout = qVariantValue<QVector<QRectF> >(value); |
|
46 | QVector<QRectF> layout = qVariantValue<QVector<QRectF> >(value); | |
47 | m_item->setLayout(layout); |
|
47 | m_item->setLayout(layout); | |
48 | } |
|
48 | } | |
49 |
|
49 | |||
50 | #include "moc_baranimation_p.cpp" |
|
50 | #include "moc_baranimation_p.cpp" | |
51 |
|
51 | |||
52 | QTCOMMERCIALCHART_END_NAMESPACE |
|
52 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,34 +1,34 | |||||
1 | #ifndef BARANIMATION_P_H_ |
|
1 | #ifndef BARANIMATION_P_H_ | |
2 | #define BARANIMATION_P_H_ |
|
2 | #define BARANIMATION_P_H_ | |
3 |
|
3 | |||
4 | #include "chartanimation_p.h" |
|
4 | #include "chartanimation_p.h" | |
5 | #include "barchartitem_p.h" |
|
5 | #include "barchartitem_p.h" | |
6 |
|
6 | |||
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
8 |
|
8 | |||
9 | class BarChartItem; |
|
9 | class BarChartItem; | |
10 | class QBarSet; |
|
10 | class QBarSet; | |
11 | class BarSetAnimation; |
|
11 | class BarSetAnimation; | |
12 |
|
12 | |||
13 | class BarAnimation : public ChartAnimation |
|
13 | class BarAnimation : public ChartAnimation | |
14 | { |
|
14 | { | |
15 | Q_OBJECT |
|
15 | Q_OBJECT | |
16 |
|
16 | |||
17 | public: |
|
17 | public: | |
18 | BarAnimation(BarChartItem *item); |
|
18 | BarAnimation(BarChartItem *item); | |
19 | ~BarAnimation(); |
|
19 | ~BarAnimation(); | |
20 |
|
20 | |||
21 | public: // from QVariantAnimation |
|
21 | public: // from QVariantAnimation | |
22 |
virtual QVariant interpolated |
|
22 | virtual QVariant interpolated(const QVariant &from, const QVariant &to, qreal progress) const; | |
23 |
virtual void updateCurrentValue |
|
23 | virtual void updateCurrentValue(const QVariant &value); | |
24 |
|
24 | |||
25 | public Q_SLOTS: |
|
25 | public Q_SLOTS: | |
26 |
|
26 | |||
27 | private: |
|
27 | private: | |
28 | BarChartItem *m_item; |
|
28 | BarChartItem *m_item; | |
29 | QHash<QBarSet*, BarSetAnimation*> m_animations; |
|
29 | QHash<QBarSet *, BarSetAnimation *> m_animations; | |
30 | }; |
|
30 | }; | |
31 |
|
31 | |||
32 | QTCOMMERCIALCHART_END_NAMESPACE |
|
32 | QTCOMMERCIALCHART_END_NAMESPACE | |
33 |
|
33 | |||
34 | #endif |
|
34 | #endif |
@@ -1,26 +1,26 | |||||
1 | #ifndef CHARTANIMATION_H_ |
|
1 | #ifndef CHARTANIMATION_H_ | |
2 | #define CHARTANIMATION_H_ |
|
2 | #define CHARTANIMATION_H_ | |
3 |
|
3 | |||
4 | #include "qchartglobal.h" |
|
4 | #include "qchartglobal.h" | |
5 | #include <QVariantAnimation> |
|
5 | #include <QVariantAnimation> | |
6 |
|
6 | |||
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
8 |
|
8 | |||
9 | class ChartAnimation: public QVariantAnimation |
|
9 | class ChartAnimation: public QVariantAnimation | |
10 | { |
|
10 | { | |
11 | public: |
|
11 | public: | |
12 | enum Animation { LineDrawAnimation, MoveDownAnimation, MoveUpAnimation }; |
|
12 | enum Animation { LineDrawAnimation, MoveDownAnimation, MoveUpAnimation }; | |
13 |
ChartAnimation(QObject* parent=0):QVariantAnimation(parent),m_type(MoveDownAnimation){} |
|
13 | ChartAnimation(QObject* parent=0):QVariantAnimation(parent), m_type(MoveDownAnimation){} | |
14 | void setAnimationType(Animation type){ |
|
14 | void setAnimationType(Animation type){ | |
15 | m_type=type; |
|
15 | m_type=type; | |
16 | } |
|
16 | } | |
17 | protected: |
|
17 | protected: | |
18 | Animation m_type; |
|
18 | Animation m_type; | |
19 |
|
19 | |||
20 | }; |
|
20 | }; | |
21 |
|
21 | |||
22 | QTCOMMERCIALCHART_END_NAMESPACE |
|
22 | QTCOMMERCIALCHART_END_NAMESPACE | |
23 |
|
23 | |||
24 |
|
24 | |||
25 |
|
25 | |||
26 | #endif /* AXISITEM_H_ */ |
|
26 | #endif /* AXISITEM_H_ */ |
@@ -1,288 +1,279 | |||||
1 | #include "chartanimator_p.h" |
|
1 | #include "chartanimator_p.h" | |
2 | #include "axisanimation_p.h" |
|
2 | #include "axisanimation_p.h" | |
3 | #include "xyanimation_p.h" |
|
3 | #include "xyanimation_p.h" | |
4 | #include "splineanimation_p.h" |
|
4 | #include "splineanimation_p.h" | |
5 | #include "xychartitem_p.h" |
|
5 | #include "xychartitem_p.h" | |
6 | #include "pieanimation_p.h" |
|
6 | #include "pieanimation_p.h" | |
7 | #include "baranimation_p.h" |
|
7 | #include "baranimation_p.h" | |
8 | #include "barchartitem_p.h" |
|
8 | #include "barchartitem_p.h" | |
9 | #include "areachartitem_p.h" |
|
9 | #include "areachartitem_p.h" | |
10 | #include "splinechartitem_p.h" |
|
10 | #include "splinechartitem_p.h" | |
11 | #include "scatterchartitem_p.h" |
|
11 | #include "scatterchartitem_p.h" | |
12 | #include <QTimer> |
|
12 | #include <QTimer> | |
13 |
|
13 | |||
14 | Q_DECLARE_METATYPE(QVector<QPointF>) |
|
14 | Q_DECLARE_METATYPE(QVector<QPointF>) | |
15 | Q_DECLARE_METATYPE(QVector<qreal>) |
|
15 | Q_DECLARE_METATYPE(QVector<qreal>) | |
16 | Q_DECLARE_METATYPE(QVector<QRectF>) |
|
16 | Q_DECLARE_METATYPE(QVector<QRectF>) | |
17 |
|
17 | |||
18 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
18 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
19 |
|
19 | |||
20 | const static int duration = 1000; |
|
20 | const static int duration = 1000; | |
21 |
|
21 | |||
22 |
ChartAnimator::ChartAnimator(QObject *parent):QObject(parent), |
|
22 | ChartAnimator::ChartAnimator(QObject *parent):QObject(parent), | |
|
23 | m_state(ShowState) | |||
23 | { |
|
24 | { | |
24 | } |
|
25 | } | |
25 |
|
26 | |||
26 | ChartAnimator::~ChartAnimator() |
|
27 | ChartAnimator::~ChartAnimator() | |
27 | { |
|
28 | { | |
28 | } |
|
29 | } | |
29 |
|
30 | |||
30 |
void ChartAnimator::addAnimation(Axis* |
|
31 | void ChartAnimator::addAnimation(Axis *item) | |
31 | { |
|
32 | { | |
32 |
ChartAnimation* |
|
33 | ChartAnimation *animation = m_animations.value(item); | |
33 |
|
34 | |||
34 | if(!animation) { |
|
35 | if (!animation) { | |
35 | animation = new AxisAnimation(item); |
|
36 | animation = new AxisAnimation(item); | |
36 | m_animations.insert(item,animation); |
|
37 | m_animations.insert(item, animation); | |
37 | } |
|
38 | } | |
38 |
|
39 | |||
39 | item->setAnimator(this); |
|
40 | item->setAnimator(this); | |
40 | } |
|
41 | } | |
41 |
|
42 | |||
42 |
void ChartAnimator::addAnimation(SplineChartItem* |
|
43 | void ChartAnimator::addAnimation(SplineChartItem *item) | |
43 | { |
|
44 | { | |
44 |
ChartAnimation* |
|
45 | ChartAnimation *animation = m_animations.value(item); | |
45 |
|
46 | |||
46 | if(!animation) { |
|
47 | if (!animation) { | |
47 | animation = new SplineAnimation(item); |
|
48 | animation = new SplineAnimation(item); | |
48 | m_animations.insert(item,animation); |
|
49 | m_animations.insert(item, animation); | |
49 | } |
|
50 | } | |
50 |
|
51 | |||
51 | item->setAnimator(this); |
|
52 | item->setAnimator(this); | |
52 | } |
|
53 | } | |
53 |
|
54 | |||
54 |
void ChartAnimator::addAnimation(ScatterChartItem* |
|
55 | void ChartAnimator::addAnimation(ScatterChartItem *item) | |
55 | { |
|
56 | { | |
56 |
ChartAnimation* |
|
57 | ChartAnimation *animation = m_animations.value(item); | |
57 |
|
58 | |||
58 | if(!animation) { |
|
59 | if (!animation) { | |
59 | animation = new XYAnimation(item); |
|
60 | animation = new XYAnimation(item); | |
60 | m_animations.insert(item,animation); |
|
61 | m_animations.insert(item, animation); | |
61 | } |
|
62 | } | |
62 |
|
63 | |||
63 | item->setAnimator(this); |
|
64 | item->setAnimator(this); | |
64 | } |
|
65 | } | |
65 |
|
66 | |||
66 |
void ChartAnimator::addAnimation(LineChartItem* |
|
67 | void ChartAnimator::addAnimation(LineChartItem *item) | |
67 | { |
|
68 | { | |
68 |
ChartAnimation* |
|
69 | ChartAnimation *animation = m_animations.value(item); | |
69 |
|
70 | |||
70 | if(!animation) { |
|
71 | if (!animation) { | |
71 | animation = new XYAnimation(item); |
|
72 | animation = new XYAnimation(item); | |
72 | m_animations.insert(item,animation); |
|
73 | m_animations.insert(item, animation); | |
73 | } |
|
74 | } | |
74 |
|
75 | |||
75 | item->setAnimator(this); |
|
76 | item->setAnimator(this); | |
76 | } |
|
77 | } | |
77 |
|
78 | |||
78 |
void ChartAnimator::addAnimation(PieChartItem* |
|
79 | void ChartAnimator::addAnimation(PieChartItem *item) | |
79 | { |
|
80 | { | |
80 |
ChartAnimation* |
|
81 | ChartAnimation *animation = m_animations.value(item); | |
81 |
|
82 | |||
82 | if(!animation) { |
|
83 | if (!animation) { | |
83 | animation = new PieAnimation(item); |
|
84 | animation = new PieAnimation(item); | |
84 | m_animations.insert(item,animation); |
|
85 | m_animations.insert(item, animation); | |
85 | } |
|
86 | } | |
86 |
|
87 | |||
87 | item->setAnimator(this); |
|
88 | item->setAnimator(this); | |
88 | } |
|
89 | } | |
89 |
|
90 | |||
90 |
void ChartAnimator::addAnimation(BarChartItem* |
|
91 | void ChartAnimator::addAnimation(BarChartItem *item) | |
91 | { |
|
92 | { | |
92 |
ChartAnimation* |
|
93 | ChartAnimation *animation = m_animations.value(item); | |
93 |
|
94 | |||
94 | if(!animation) { |
|
95 | if (!animation) { | |
95 | animation = new BarAnimation(item); |
|
96 | animation = new BarAnimation(item); | |
96 | m_animations.insert(item,animation); |
|
97 | m_animations.insert(item, animation); | |
97 | } |
|
98 | } | |
98 |
|
99 | |||
99 | item->setAnimator(this); |
|
100 | item->setAnimator(this); | |
100 | } |
|
101 | } | |
101 |
|
102 | |||
102 |
|
103 | |||
103 |
void ChartAnimator::removeAnimation(Chart* |
|
104 | void ChartAnimator::removeAnimation(Chart *item) | |
104 | { |
|
105 | { | |
105 | item->setAnimator(0); |
|
106 | item->setAnimator(0); | |
106 | m_animations.remove(item); |
|
107 | m_animations.remove(item); | |
107 | } |
|
108 | } | |
108 |
|
109 | |||
109 |
void ChartAnimator::updateLayout(Axis* |
|
110 | void ChartAnimator::updateLayout(Axis *item , QVector<qreal> &newLayout) | |
110 | { |
|
111 | { | |
111 |
AxisAnimation* |
|
112 | AxisAnimation *animation = static_cast<AxisAnimation*>(m_animations.value(item)); | |
112 |
|
113 | |||
113 | Q_ASSERT(animation); |
|
114 | Q_ASSERT(animation); | |
114 |
|
115 | |||
115 | QVector<qreal> oldLayout = item->layout(); |
|
116 | QVector<qreal> oldLayout = item->layout(); | |
116 |
|
117 | |||
117 |
if(newLayout.count()==0) |
|
118 | if (newLayout.count() == 0) | |
118 |
|
119 | return; | ||
119 | switch(m_state) |
|
120 | ||
120 | { |
|
121 | switch (m_state) { | |
121 |
|
|
122 | case ZoomOutState: { | |
122 |
|
|
123 | QRectF rect = item->geometry(); | |
123 |
|
|
124 | oldLayout.resize(newLayout.count()); | |
124 |
|
125 | |||
125 |
|
|
126 | for(int i = 0, j = oldLayout.count() - 1; i < (oldLayout.count() + 1) / 2; i++, j--) { | |
126 | { |
|
127 | oldLayout[i] = item->axisType() == Axis::X_AXIS ? rect.left() : rect.bottom(); | |
127 |
|
|
128 | oldLayout[j] = item->axisType() == Axis::X_AXIS ? rect.right() : rect.top(); | |
128 | oldLayout[j]= item->axisType()==Axis::X_AXIS?rect.right():rect.top(); |
|
129 | } | |
129 |
|
|
130 | } | |
130 | } |
|
131 | break; | |
131 | break; |
|
132 | case ZoomInState: { | |
132 | case ZoomInState: { |
|
133 | int index = qMin(oldLayout.count() * (item->axisType() == Axis::X_AXIS ? m_point.x() : (1 - m_point.y())), newLayout.count() - 1.0); | |
133 | int index = qMin(oldLayout.count()*(item->axisType()==Axis::X_AXIS?m_point.x():(1 -m_point.y())),newLayout.count()-1.0); |
|
134 | oldLayout.resize(newLayout.count()); | |
134 | oldLayout.resize(newLayout.count()); |
|
135 | ||
135 |
|
136 | for(int i = 0; i < oldLayout.count(); i++) | ||
136 | for(int i=0;i<oldLayout.count();i++) |
|
137 | oldLayout[i]= oldLayout[index]; | |
137 | { |
|
|||
138 | oldLayout[i]= oldLayout[index]; |
|
|||
139 | } |
|
|||
140 | } |
|
|||
141 | break; |
|
|||
142 | case ScrollDownState: |
|
|||
143 | case ScrollRightState: { |
|
|||
144 | oldLayout.resize(newLayout.count()); |
|
|||
145 |
|
||||
146 | for(int i=0, j=i+1;i<oldLayout.count()-1;i++,j++) |
|
|||
147 | { |
|
|||
148 | oldLayout[i]= oldLayout[j]; |
|
|||
149 | } |
|
|||
150 | } |
|
|||
151 | break; |
|
|||
152 | case ScrollUpState: |
|
|||
153 | case ScrollLeftState: { |
|
|||
154 | oldLayout.resize(newLayout.count()); |
|
|||
155 |
|
||||
156 | for(int i=oldLayout.count()-1, j=i-1;i>0;i--,j--) |
|
|||
157 | { |
|
|||
158 | oldLayout[i]= oldLayout[j]; |
|
|||
159 | } |
|
|||
160 | } |
|
|||
161 | break; |
|
|||
162 | default: { |
|
|||
163 | oldLayout.resize(newLayout.count()); |
|
|||
164 | QRectF rect = item->geometry(); |
|
|||
165 | for(int i=0, j=oldLayout.count()-1;i<oldLayout.count();i++,j--) |
|
|||
166 | { |
|
|||
167 | oldLayout[i]= item->axisType()==Axis::X_AXIS?rect.left():rect.top(); |
|
|||
168 | } |
|
|||
169 | } |
|
|||
170 | break; |
|
|||
171 | } |
|
|||
172 |
|
||||
173 |
|
||||
174 | if(animation->state()!=QAbstractAnimation::Stopped) { |
|
|||
175 | animation->stop(); |
|
|||
176 | } |
|
138 | } | |
|
139 | break; | |||
|
140 | case ScrollDownState: | |||
|
141 | case ScrollRightState: { | |||
|
142 | oldLayout.resize(newLayout.count()); | |||
|
143 | ||||
|
144 | for(int i = 0, j = i + 1; i < oldLayout.count() - 1; i++, j++) | |||
|
145 | oldLayout[i]= oldLayout[j]; | |||
|
146 | } | |||
|
147 | break; | |||
|
148 | case ScrollUpState: | |||
|
149 | case ScrollLeftState: { | |||
|
150 | oldLayout.resize(newLayout.count()); | |||
|
151 | ||||
|
152 | for(int i = oldLayout.count() - 1, j = i - 1; i > 0; i--, j--) | |||
|
153 | oldLayout[i]= oldLayout[j]; | |||
|
154 | } | |||
|
155 | break; | |||
|
156 | default: { | |||
|
157 | oldLayout.resize(newLayout.count()); | |||
|
158 | QRectF rect = item->geometry(); | |||
|
159 | for(int i = 0, j = oldLayout.count() - 1; i < oldLayout.count(); i++, j--) | |||
|
160 | oldLayout[i] = item->axisType() == Axis::X_AXIS ? rect.left() : rect.top(); | |||
|
161 | } | |||
|
162 | break; | |||
|
163 | } | |||
|
164 | ||||
|
165 | ||||
|
166 | if (animation->state() != QAbstractAnimation::Stopped) | |||
|
167 | animation->stop(); | |||
177 |
|
168 | |||
178 | animation->setDuration(duration); |
|
169 | animation->setDuration(duration); | |
179 | animation->setEasingCurve(QEasingCurve::OutQuart); |
|
170 | animation->setEasingCurve(QEasingCurve::OutQuart); | |
180 | QVariantAnimation::KeyValues value; |
|
171 | QVariantAnimation::KeyValues value; | |
181 | animation->setKeyValues(value); //workaround for wrong interpolation call |
|
172 | animation->setKeyValues(value); //workaround for wrong interpolation call | |
182 | animation->setKeyValueAt(0.0, qVariantFromValue(oldLayout)); |
|
173 | animation->setKeyValueAt(0.0, qVariantFromValue(oldLayout)); | |
183 | animation->setKeyValueAt(1.0, qVariantFromValue(newLayout)); |
|
174 | animation->setKeyValueAt(1.0, qVariantFromValue(newLayout)); | |
184 |
|
175 | |||
185 | QTimer::singleShot(0,animation,SLOT(start())); |
|
176 | QTimer::singleShot(0, animation, SLOT(start())); | |
186 | } |
|
177 | } | |
187 |
|
178 | |||
188 |
void ChartAnimator::updateLayout(SplineChartItem* |
|
179 | void ChartAnimator::updateLayout(SplineChartItem *item, QVector<QPointF> &oldPoints, QVector<QPointF> &newPoints, QVector<QPointF> &oldControlPoints, QVector<QPointF> &newControlPoints, int index) | |
189 | { |
|
180 | { | |
190 |
SplineAnimation* |
|
181 | SplineAnimation *animation = static_cast<SplineAnimation *>(m_animations.value(item)); | |
191 |
|
182 | |||
192 | Q_ASSERT(animation); |
|
183 | Q_ASSERT(animation); | |
193 |
|
184 | |||
194 |
if(newPoints.count()<2 || newControlPoints.count()<2) |
|
185 | if (newPoints.count() < 2 || newControlPoints.count() < 2) | |
|
186 | return; | |||
195 |
|
187 | |||
196 | bool empty = oldPoints.count()==0; |
|
188 | bool empty = oldPoints.count() == 0; | |
197 |
|
189 | |||
198 |
|
190 | |||
199 |
if(animation->state()!=QAbstractAnimation::Stopped) |
|
191 | if (animation->state() != QAbstractAnimation::Stopped) | |
200 |
|
|
192 | animation->stop(); | |
201 | } |
|
|||
202 |
|
193 | |||
203 | animation->setDuration(duration); |
|
194 | animation->setDuration(duration); | |
204 | if(!empty) |
|
195 | if (!empty) | |
205 | animation->setAnimationType(ChartAnimation::MoveDownAnimation); |
|
196 | animation->setAnimationType(ChartAnimation::MoveDownAnimation); | |
206 | else |
|
197 | else | |
207 | animation->setAnimationType(ChartAnimation::LineDrawAnimation); |
|
198 | animation->setAnimationType(ChartAnimation::LineDrawAnimation); | |
208 |
|
199 | |||
209 | animation->setEasingCurve(QEasingCurve::OutQuart); |
|
200 | animation->setEasingCurve(QEasingCurve::OutQuart); | |
210 | animation->setValues(oldPoints,newPoints,oldControlPoints,newControlPoints,index); |
|
201 | animation->setValues(oldPoints, newPoints, oldControlPoints, newControlPoints, index); | |
211 |
|
202 | |||
212 | QTimer::singleShot(0,animation,SLOT(start())); |
|
203 | QTimer::singleShot(0, animation, SLOT(start())); | |
213 | } |
|
204 | } | |
214 |
|
205 | |||
215 |
|
206 | |||
216 |
void ChartAnimator::updateLayout(XYChartItem* |
|
207 | void ChartAnimator::updateLayout(XYChartItem *item, QVector<QPointF> &oldPoints, QVector<QPointF> &newPoints, int index) | |
217 | { |
|
208 | { | |
218 |
XYAnimation* |
|
209 | XYAnimation *animation = static_cast<XYAnimation *>(m_animations.value(item)); | |
219 |
|
210 | |||
220 | Q_ASSERT(animation); |
|
211 | Q_ASSERT(animation); | |
221 |
|
212 | |||
222 |
if(newPoints.count()==0) |
|
213 | if (newPoints.count() == 0) | |
|
214 | return; | |||
223 |
|
215 | |||
224 | bool empty = oldPoints.count()==0; |
|
216 | bool empty = oldPoints.count() == 0; | |
225 |
|
217 | |||
226 |
|
218 | |||
227 |
if(animation->state()!=QAbstractAnimation::Stopped) |
|
219 | if (animation->state() != QAbstractAnimation::Stopped) | |
228 | animation->stop(); |
|
220 | animation->stop(); | |
229 | } |
|
|||
230 |
|
221 | |||
231 | animation->setDuration(duration); |
|
222 | animation->setDuration(duration); | |
232 | if(!empty) |
|
223 | if (!empty) | |
233 | animation->setAnimationType(ChartAnimation::MoveDownAnimation); |
|
224 | animation->setAnimationType(ChartAnimation::MoveDownAnimation); | |
234 | else |
|
225 | else | |
235 | animation->setAnimationType(ChartAnimation::LineDrawAnimation); |
|
226 | animation->setAnimationType(ChartAnimation::LineDrawAnimation); | |
236 |
|
227 | |||
237 | animation->setEasingCurve(QEasingCurve::OutQuart); |
|
228 | animation->setEasingCurve(QEasingCurve::OutQuart); | |
238 | animation->setValues(oldPoints,newPoints,index); |
|
229 | animation->setValues(oldPoints, newPoints, index); | |
239 |
|
230 | |||
240 | QTimer::singleShot(0,animation,SLOT(start())); |
|
231 | QTimer::singleShot(0, animation, SLOT(start())); | |
241 | } |
|
232 | } | |
242 |
|
233 | |||
243 |
void ChartAnimator::addAnimation(PieChartItem* |
|
234 | void ChartAnimator::addAnimation(PieChartItem *item, QPieSlice *slice, const PieSliceData &sliceData, bool isEmpty) | |
244 | { |
|
235 | { | |
245 |
PieAnimation* |
|
236 | PieAnimation *animation = static_cast<PieAnimation *>(m_animations.value(item)); | |
246 | Q_ASSERT(animation); |
|
237 | Q_ASSERT(animation); | |
247 | animation->addSlice(slice, sliceData, isEmpty); |
|
238 | animation->addSlice(slice, sliceData, isEmpty); | |
248 | } |
|
239 | } | |
249 |
|
240 | |||
250 |
void ChartAnimator::removeAnimation(PieChartItem* |
|
241 | void ChartAnimator::removeAnimation(PieChartItem *item, QPieSlice *slice) | |
251 | { |
|
242 | { | |
252 |
PieAnimation* |
|
243 | PieAnimation *animation = static_cast<PieAnimation *>(m_animations.value(item)); | |
253 | Q_ASSERT(animation); |
|
244 | Q_ASSERT(animation); | |
254 | animation->removeSlice(slice); |
|
245 | animation->removeSlice(slice); | |
255 | } |
|
246 | } | |
256 |
|
247 | |||
257 |
void ChartAnimator::updateLayout(PieChartItem* |
|
248 | void ChartAnimator::updateLayout(PieChartItem *item, const PieLayout &layout) | |
258 | { |
|
249 | { | |
259 |
PieAnimation* |
|
250 | PieAnimation *animation = static_cast<PieAnimation *>(m_animations.value(item)); | |
260 | Q_ASSERT(animation); |
|
251 | Q_ASSERT(animation); | |
261 | animation->updateValues(layout); |
|
252 | animation->updateValues(layout); | |
262 | } |
|
253 | } | |
263 |
|
254 | |||
264 |
void ChartAnimator::updateLayout(PieChartItem* |
|
255 | void ChartAnimator::updateLayout(PieChartItem *item, QPieSlice *slice, const PieSliceData &sliceData) | |
265 | { |
|
256 | { | |
266 |
PieAnimation* |
|
257 | PieAnimation *animation = static_cast<PieAnimation *>(m_animations.value(item)); | |
267 | Q_ASSERT(animation); |
|
258 | Q_ASSERT(animation); | |
268 | animation->updateValue(slice, sliceData); |
|
259 | animation->updateValue(slice, sliceData); | |
269 | } |
|
260 | } | |
270 |
|
261 | |||
271 |
void ChartAnimator::updateLayout(BarChartItem* |
|
262 | void ChartAnimator::updateLayout(BarChartItem *item, const QVector<QRectF> &oldLayout, const QVector<QRectF> &newLayout) | |
272 | { |
|
263 | { | |
273 |
BarAnimation* |
|
264 | BarAnimation *animation = static_cast<BarAnimation *>(m_animations.value(item)); | |
274 | Q_ASSERT(animation); |
|
265 | Q_ASSERT(animation); | |
275 | animation->setDuration(duration); |
|
266 | animation->setDuration(duration); | |
276 | animation->setKeyValueAt(0.0, qVariantFromValue(oldLayout)); |
|
267 | animation->setKeyValueAt(0.0, qVariantFromValue(oldLayout)); | |
277 | animation->setKeyValueAt(1.0, qVariantFromValue(newLayout)); |
|
268 | animation->setKeyValueAt(1.0, qVariantFromValue(newLayout)); | |
278 | QTimer::singleShot(0,animation,SLOT(start())); |
|
269 | QTimer::singleShot(0, animation, SLOT(start())); | |
279 | } |
|
270 | } | |
280 |
|
271 | |||
281 |
|
272 | |||
282 |
void ChartAnimator::setState(State state,const QPointF& |
|
273 | void ChartAnimator::setState(State state, const QPointF &point) | |
283 | { |
|
274 | { | |
284 |
|
|
275 | m_state = state; | |
285 |
|
|
276 | m_point = point; | |
286 | } |
|
277 | } | |
287 |
|
278 | |||
288 | QTCOMMERCIALCHART_END_NAMESPACE |
|
279 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,57 +1,57 | |||||
1 | #ifndef CHARTANIMATOR_P_H_ |
|
1 | #ifndef CHARTANIMATOR_P_H_ | |
2 | #define CHARTANIMATOR_P_H_ |
|
2 | #define CHARTANIMATOR_P_H_ | |
3 | #include "qchartglobal.h" |
|
3 | #include "qchartglobal.h" | |
4 | #include "chartanimation_p.h" |
|
4 | #include "chartanimation_p.h" | |
5 | #include "piechartitem_p.h" |
|
5 | #include "piechartitem_p.h" | |
6 | #include "barchartitem_p.h" |
|
6 | #include "barchartitem_p.h" | |
7 | #include <QPointF> |
|
7 | #include <QPointF> | |
8 |
|
8 | |||
9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
10 |
|
10 | |||
11 | class ChartItem; |
|
11 | class ChartItem; | |
12 | class Axis; |
|
12 | class Axis; | |
13 | class AreaChartItem; |
|
13 | class AreaChartItem; | |
14 | class SplineChartItem; |
|
14 | class SplineChartItem; | |
15 | class ScatterChartItem; |
|
15 | class ScatterChartItem; | |
16 | class LineChartItem; |
|
16 | class LineChartItem; | |
17 | class XYChartItem; |
|
17 | class XYChartItem; | |
18 |
|
18 | |||
19 | class ChartAnimator : public QObject { |
|
19 | class ChartAnimator : public QObject { | |
20 |
|
20 | |||
21 | public: |
|
21 | public: | |
22 |
|
|
22 | enum State{ShowState, ScrollUpState, ScrollDownState, ScrollLeftState, ScrollRightState, ZoomInState, ZoomOutState}; | |
23 |
|
23 | |||
24 | ChartAnimator(QObject *parent = 0); |
|
24 | ChartAnimator(QObject *parent = 0); | |
25 | virtual ~ChartAnimator(); |
|
25 | virtual ~ChartAnimator(); | |
26 |
|
26 | |||
27 |
void addAnimation(Axis* |
|
27 | void addAnimation(Axis *item); | |
28 |
void addAnimation(PieChartItem* |
|
28 | void addAnimation(PieChartItem *item); | |
29 |
void addAnimation(ScatterChartItem* |
|
29 | void addAnimation(ScatterChartItem *item); | |
30 |
void addAnimation(LineChartItem* |
|
30 | void addAnimation(LineChartItem *item); | |
31 |
void addAnimation(SplineChartItem* |
|
31 | void addAnimation(SplineChartItem *item); | |
32 |
void addAnimation(BarChartItem* |
|
32 | void addAnimation(BarChartItem *item); | |
33 |
void removeAnimation(Chart* |
|
33 | void removeAnimation(Chart *item); | |
34 |
|
34 | |||
35 | void animationStarted(); |
|
35 | void animationStarted(); | |
36 |
void updateLayout(XYChartItem* |
|
36 | void updateLayout(XYChartItem *item, QVector<QPointF> &oldLayout, QVector<QPointF> &newLayout, int index); | |
37 |
void updateLayout(SplineChartItem* |
|
37 | void updateLayout(SplineChartItem *item, QVector<QPointF> &oldPoints, QVector<QPointF> &newPoints, QVector<QPointF> &oldControlPoints, QVector<QPointF> &newContorlPoints, int index); | |
38 |
void updateLayout(Axis* |
|
38 | void updateLayout(Axis *item, QVector<qreal> &layout); | |
39 |
|
39 | |||
40 |
void addAnimation(PieChartItem* |
|
40 | void addAnimation(PieChartItem *item, QPieSlice *slice, const PieSliceData &sliceData, bool isEmpty); | |
41 |
void removeAnimation(PieChartItem* |
|
41 | void removeAnimation(PieChartItem *item, QPieSlice *slice); | |
42 |
void updateLayout(PieChartItem* |
|
42 | void updateLayout(PieChartItem *item, const PieLayout &layout); | |
43 |
void updateLayout(PieChartItem* |
|
43 | void updateLayout(PieChartItem *item, QPieSlice *slice, const PieSliceData &sliceData); | |
44 |
|
44 | |||
45 |
void updateLayout(BarChartItem* |
|
45 | void updateLayout(BarChartItem *item, const QVector<QRectF> &oldLayout, const QVector<QRectF> &newLayout); | |
46 |
|
46 | |||
47 |
void setState(State state,const QPointF& |
|
47 | void setState(State state,const QPointF &point = QPointF()); | |
48 |
|
48 | |||
49 | private: |
|
49 | private: | |
50 | QMap<Chart*,ChartAnimation*> m_animations; |
|
50 | QMap<Chart *, ChartAnimation *> m_animations; | |
51 | State m_state; |
|
51 | State m_state; | |
52 | QPointF m_point; |
|
52 | QPointF m_point; | |
53 | }; |
|
53 | }; | |
54 |
|
54 | |||
55 | QTCOMMERCIALCHART_END_NAMESPACE |
|
55 | QTCOMMERCIALCHART_END_NAMESPACE | |
56 |
|
56 | |||
57 | #endif |
|
57 | #endif |
@@ -1,92 +1,92 | |||||
1 | #include "pieanimation_p.h" |
|
1 | #include "pieanimation_p.h" | |
2 | #include "piesliceanimation_p.h" |
|
2 | #include "piesliceanimation_p.h" | |
3 | #include "piechartitem_p.h" |
|
3 | #include "piechartitem_p.h" | |
4 | #include <QParallelAnimationGroup> |
|
4 | #include <QParallelAnimationGroup> | |
5 | #include <QTimer> |
|
5 | #include <QTimer> | |
6 |
|
6 | |||
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
8 |
|
8 | |||
9 | PieAnimation::PieAnimation(PieChartItem *item) |
|
9 | PieAnimation::PieAnimation(PieChartItem *item) | |
10 | :ChartAnimation(item), |
|
10 | :ChartAnimation(item), | |
11 | m_item(item) |
|
11 | m_item(item) | |
12 | { |
|
12 | { | |
13 | } |
|
13 | } | |
14 |
|
14 | |||
15 | PieAnimation::~PieAnimation() |
|
15 | PieAnimation::~PieAnimation() | |
16 | { |
|
16 | { | |
17 | } |
|
17 | } | |
18 |
|
18 | |||
19 | void PieAnimation::updateValues(const PieLayout &newValues) |
|
19 | void PieAnimation::updateValues(const PieLayout &newValues) | |
20 | { |
|
20 | { | |
21 |
foreach (QPieSlice* |
|
21 | foreach (QPieSlice *s, newValues.keys()) | |
22 | updateValue(s, newValues.value(s)); |
|
22 | updateValue(s, newValues.value(s)); | |
23 | } |
|
23 | } | |
24 |
|
24 | |||
25 | void PieAnimation::updateValue(QPieSlice *slice, const PieSliceData &sliceData) |
|
25 | void PieAnimation::updateValue(QPieSlice *slice, const PieSliceData &sliceData) | |
26 | { |
|
26 | { | |
27 | PieSliceAnimation *animation = m_animations.value(slice); |
|
27 | PieSliceAnimation *animation = m_animations.value(slice); | |
28 | Q_ASSERT(animation); |
|
28 | Q_ASSERT(animation); | |
29 | animation->stop(); |
|
29 | animation->stop(); | |
30 |
|
30 | |||
31 | animation->updateValue(sliceData); |
|
31 | animation->updateValue(sliceData); | |
32 | animation->setDuration(1000); |
|
32 | animation->setDuration(1000); | |
33 | animation->setEasingCurve(QEasingCurve::OutQuart); |
|
33 | animation->setEasingCurve(QEasingCurve::OutQuart); | |
34 |
|
34 | |||
35 | QTimer::singleShot(0, animation, SLOT(start())); |
|
35 | QTimer::singleShot(0, animation, SLOT(start())); | |
36 | } |
|
36 | } | |
37 |
|
37 | |||
38 | void PieAnimation::addSlice(QPieSlice *slice, const PieSliceData &sliceData, bool isEmpty) |
|
38 | void PieAnimation::addSlice(QPieSlice *slice, const PieSliceData &sliceData, bool isEmpty) | |
39 | { |
|
39 | { | |
40 | PieSliceAnimation *animation = new PieSliceAnimation(m_item, slice); |
|
40 | PieSliceAnimation *animation = new PieSliceAnimation(m_item, slice); | |
41 | m_animations.insert(slice, animation); |
|
41 | m_animations.insert(slice, animation); | |
42 |
|
42 | |||
43 | PieSliceData startValue = sliceData; |
|
43 | PieSliceData startValue = sliceData; | |
44 | startValue.m_radius = 0; |
|
44 | startValue.m_radius = 0; | |
45 | if (isEmpty) |
|
45 | if (isEmpty) | |
46 | startValue.m_startAngle = 0; |
|
46 | startValue.m_startAngle = 0; | |
47 | else |
|
47 | else | |
48 | startValue.m_startAngle = sliceData.m_startAngle + (sliceData.m_angleSpan/2); |
|
48 | startValue.m_startAngle = sliceData.m_startAngle + (sliceData.m_angleSpan / 2); | |
49 | startValue.m_angleSpan = 0; |
|
49 | startValue.m_angleSpan = 0; | |
50 | animation->setValue(startValue, sliceData); |
|
50 | animation->setValue(startValue, sliceData); | |
51 |
|
51 | |||
52 | animation->setDuration(1000); |
|
52 | animation->setDuration(1000); | |
53 | animation->setEasingCurve(QEasingCurve::OutQuart); |
|
53 | animation->setEasingCurve(QEasingCurve::OutQuart); | |
54 | QTimer::singleShot(0, animation, SLOT(start())); |
|
54 | QTimer::singleShot(0, animation, SLOT(start())); | |
55 | } |
|
55 | } | |
56 |
|
56 | |||
57 | void PieAnimation::removeSlice(QPieSlice *slice) |
|
57 | void PieAnimation::removeSlice(QPieSlice *slice) | |
58 | { |
|
58 | { | |
59 | PieSliceAnimation *animation = m_animations.value(slice); |
|
59 | PieSliceAnimation *animation = m_animations.value(slice); | |
60 | Q_ASSERT(animation); |
|
60 | Q_ASSERT(animation); | |
61 | animation->stop(); |
|
61 | animation->stop(); | |
62 |
|
62 | |||
63 | PieSliceData endValue = animation->currentSliceValue(); |
|
63 | PieSliceData endValue = animation->currentSliceValue(); | |
64 | endValue.m_radius = 0; |
|
64 | endValue.m_radius = 0; | |
65 | // TODO: find the actual angle where this slice disappears |
|
65 | // TODO: find the actual angle where this slice disappears | |
66 | endValue.m_startAngle = endValue.m_startAngle + endValue.m_angleSpan; |
|
66 | endValue.m_startAngle = endValue.m_startAngle + endValue.m_angleSpan; | |
67 | endValue.m_angleSpan = 0; |
|
67 | endValue.m_angleSpan = 0; | |
68 |
|
68 | |||
69 | animation->updateValue(endValue); |
|
69 | animation->updateValue(endValue); | |
70 | animation->setDuration(1000); |
|
70 | animation->setDuration(1000); | |
71 | animation->setEasingCurve(QEasingCurve::OutQuart); |
|
71 | animation->setEasingCurve(QEasingCurve::OutQuart); | |
72 |
|
72 | |||
73 | connect(animation, SIGNAL(finished()), this, SLOT(destroySliceAnimationComplete())); |
|
73 | connect(animation, SIGNAL(finished()), this, SLOT(destroySliceAnimationComplete())); | |
74 | QTimer::singleShot(0, animation, SLOT(start())); |
|
74 | QTimer::singleShot(0, animation, SLOT(start())); | |
75 | } |
|
75 | } | |
76 |
|
76 | |||
77 | void PieAnimation::updateCurrentValue(const QVariant &) |
|
77 | void PieAnimation::updateCurrentValue(const QVariant &) | |
78 | { |
|
78 | { | |
79 | // nothing to do... |
|
79 | // nothing to do... | |
80 | } |
|
80 | } | |
81 |
|
81 | |||
82 | void PieAnimation::destroySliceAnimationComplete() |
|
82 | void PieAnimation::destroySliceAnimationComplete() | |
83 | { |
|
83 | { | |
84 | PieSliceAnimation *animation = static_cast<PieSliceAnimation*>(sender()); |
|
84 | PieSliceAnimation *animation = static_cast<PieSliceAnimation *>(sender()); | |
85 | QPieSlice *slice = m_animations.key(animation); |
|
85 | QPieSlice *slice = m_animations.key(animation); | |
86 | m_item->destroySlice(slice); |
|
86 | m_item->destroySlice(slice); | |
87 | delete m_animations.take(slice); |
|
87 | delete m_animations.take(slice); | |
88 | } |
|
88 | } | |
89 |
|
89 | |||
90 | #include "moc_pieanimation_p.cpp" |
|
90 | #include "moc_pieanimation_p.cpp" | |
91 |
|
91 | |||
92 | QTCOMMERCIALCHART_END_NAMESPACE |
|
92 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,37 +1,37 | |||||
1 | #ifndef PIEANIMATION_P_H_ |
|
1 | #ifndef PIEANIMATION_P_H_ | |
2 | #define PIEANIMATION_P_H_ |
|
2 | #define PIEANIMATION_P_H_ | |
3 |
|
3 | |||
4 | #include "chartanimation_p.h" |
|
4 | #include "chartanimation_p.h" | |
5 | #include "piechartitem_p.h" |
|
5 | #include "piechartitem_p.h" | |
6 | #include "piesliceanimation_p.h" |
|
6 | #include "piesliceanimation_p.h" | |
7 |
|
7 | |||
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
9 |
|
9 | |||
10 | class PieChartItem; |
|
10 | class PieChartItem; | |
11 |
|
11 | |||
12 | class PieAnimation : public ChartAnimation |
|
12 | class PieAnimation : public ChartAnimation | |
13 | { |
|
13 | { | |
14 | Q_OBJECT |
|
14 | Q_OBJECT | |
15 |
|
15 | |||
16 | public: |
|
16 | public: | |
17 | PieAnimation(PieChartItem *item); |
|
17 | PieAnimation(PieChartItem *item); | |
18 | ~PieAnimation(); |
|
18 | ~PieAnimation(); | |
19 | void updateValues(const PieLayout &newValues); |
|
19 | void updateValues(const PieLayout &newValues); | |
20 | void updateValue(QPieSlice *slice, const PieSliceData &newValue); |
|
20 | void updateValue(QPieSlice *slice, const PieSliceData &newValue); | |
21 | void addSlice(QPieSlice *slice, const PieSliceData &endValue, bool isEmpty); |
|
21 | void addSlice(QPieSlice *slice, const PieSliceData &endValue, bool isEmpty); | |
22 | void removeSlice(QPieSlice *slice); |
|
22 | void removeSlice(QPieSlice *slice); | |
23 |
|
23 | |||
24 | public: // from QVariantAnimation |
|
24 | public: // from QVariantAnimation | |
25 | void updateCurrentValue(const QVariant &value); |
|
25 | void updateCurrentValue(const QVariant &value); | |
26 |
|
26 | |||
27 | public Q_SLOTS: |
|
27 | public Q_SLOTS: | |
28 | void destroySliceAnimationComplete(); |
|
28 | void destroySliceAnimationComplete(); | |
29 |
|
29 | |||
30 | private: |
|
30 | private: | |
31 | PieChartItem *m_item; |
|
31 | PieChartItem *m_item; | |
32 | QHash<QPieSlice*, PieSliceAnimation*> m_animations; |
|
32 | QHash<QPieSlice *, PieSliceAnimation *> m_animations; | |
33 | }; |
|
33 | }; | |
34 |
|
34 | |||
35 | QTCOMMERCIALCHART_END_NAMESPACE |
|
35 | QTCOMMERCIALCHART_END_NAMESPACE | |
36 |
|
36 | |||
37 | #endif |
|
37 | #endif |
@@ -1,127 +1,129 | |||||
1 | #include "splineanimation_p.h" |
|
1 | #include "splineanimation_p.h" | |
2 | #include "splinechartitem_p.h" |
|
2 | #include "splinechartitem_p.h" | |
3 |
|
3 | |||
4 | Q_DECLARE_METATYPE(QVector<QPointF>) |
|
4 | Q_DECLARE_METATYPE(QVector<QPointF>) | |
5 | Q_DECLARE_METATYPE(SplineVector) |
|
5 | Q_DECLARE_METATYPE(SplineVector) | |
6 |
|
6 | |||
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
8 |
|
8 | |||
9 | SplineAnimation::SplineAnimation(SplineChartItem* item):ChartAnimation(item), |
|
9 | SplineAnimation::SplineAnimation(SplineChartItem* item):ChartAnimation(item), | |
10 | m_item(item), |
|
10 | m_item(item), | |
11 | m_dirty(true) |
|
11 | m_dirty(true) | |
12 | { |
|
12 | { | |
13 | } |
|
13 | } | |
14 |
|
14 | |||
15 | SplineAnimation::~SplineAnimation() |
|
15 | SplineAnimation::~SplineAnimation() | |
16 | { |
|
16 | { | |
17 | } |
|
17 | } | |
18 |
|
18 | |||
19 |
void SplineAnimation::setValues(QVector<QPointF>& |
|
19 | void SplineAnimation::setValues(QVector<QPointF> &oldPoints, QVector<QPointF> &newPoints, QVector<QPointF> &oldControlPoints, QVector<QPointF> &newControlPoints, int index) | |
20 | { |
|
20 | { | |
21 | int x = oldPoints.count(); |
|
21 | int x = oldPoints.count(); | |
22 | int y = newPoints.count(); |
|
22 | int y = newPoints.count(); | |
23 |
|
23 | |||
24 | Q_ASSERT(newPoints.count()*2-2 == newControlPoints.count()); |
|
24 | Q_ASSERT(newPoints.count() * 2 - 2 == newControlPoints.count()); | |
25 |
|
25 | |||
26 | if(x!=y && abs(x-y)!=1) { |
|
26 | if (x != y && abs(x - y) != 1) { | |
27 | m_oldSpline.first= newPoints; |
|
27 | m_oldSpline.first = newPoints; | |
28 | m_oldSpline.second= newControlPoints; |
|
28 | m_oldSpline.second = newControlPoints; | |
29 | oldPoints.resize(newPoints.size()); |
|
29 | oldPoints.resize(newPoints.size()); | |
30 | oldControlPoints.resize(newControlPoints.size()); |
|
30 | oldControlPoints.resize(newControlPoints.size()); | |
31 | SplineVector oldPair; |
|
31 | SplineVector oldPair; | |
32 | oldPair.first=oldPoints; |
|
32 | oldPair.first = oldPoints; | |
33 | oldPair.second=oldControlPoints; |
|
33 | oldPair.second = oldControlPoints; | |
34 | SplineVector newPair; |
|
34 | SplineVector newPair; | |
35 | newPair.first=newPoints; |
|
35 | newPair.first = newPoints; | |
36 | newPair.second=newControlPoints; |
|
36 | newPair.second = newControlPoints; | |
37 | setKeyValueAt(0.0, qVariantFromValue(oldPair)); |
|
37 | setKeyValueAt(0.0, qVariantFromValue(oldPair)); | |
38 | setKeyValueAt(1.0, qVariantFromValue(newPair)); |
|
38 | setKeyValueAt(1.0, qVariantFromValue(newPair)); | |
39 | m_dirty=false; |
|
39 | m_dirty = false; | |
40 | } |
|
40 | } | |
41 | else { |
|
41 | else { | |
42 | if(m_dirty) { |
|
42 | if(m_dirty) { | |
43 | m_oldSpline.first = oldPoints; |
|
43 | m_oldSpline.first = oldPoints; | |
44 | m_oldSpline.second = oldControlPoints; |
|
44 | m_oldSpline.second = oldControlPoints; | |
45 | m_dirty=false; |
|
45 | m_dirty = false; | |
46 | } |
|
46 | } | |
47 | oldPoints = newPoints; |
|
47 | oldPoints = newPoints; | |
48 | oldControlPoints = newControlPoints; |
|
48 | oldControlPoints = newControlPoints; | |
49 | if (y<x) { |
|
49 | if (y < x) { | |
50 | m_oldSpline.first.remove(index); //remove |
|
50 | m_oldSpline.first.remove(index); //remove | |
51 | m_oldSpline.second.remove(index*2); |
|
51 | m_oldSpline.second.remove(index * 2); | |
52 | m_oldSpline.second.remove(index*2); |
|
52 | m_oldSpline.second.remove(index * 2); | |
53 | } |
|
53 | } | |
54 | if (y>x) { |
|
54 | if (y > x) { | |
55 | m_oldSpline.first.insert(index,x>0?m_oldSpline.first[index-1]:newPoints[index]); //add |
|
55 | m_oldSpline.first.insert(index, x > 0 ? m_oldSpline.first[index-1] : newPoints[index]); //add | |
56 | m_oldSpline.second.insert((index-1)*2,x>1?m_oldSpline.second[(index-2)*2]:newControlPoints[(index-1)*2]); //add |
|
56 | m_oldSpline.second.insert((index - 1) * 2, x > 1 ? m_oldSpline.second[(index-2)*2] : newControlPoints[(index - 1) * 2]); //add | |
57 | m_oldSpline.second.insert((index-1)*2+1,x>1?m_oldSpline.second[(index-2)*2+1]:newControlPoints[(index-1)*2+1]); //add |
|
57 | m_oldSpline.second.insert((index - 1) * 2 + 1, x > 1 ? m_oldSpline.second[(index - 2) * 2 + 1] : newControlPoints[(index - 1) * 2 + 1]); //add | |
58 | } |
|
58 | } | |
59 | SplineVector newPair; |
|
59 | SplineVector newPair; | |
60 | newPair.first=newPoints; |
|
60 | newPair.first=newPoints; | |
61 | newPair.second=newControlPoints; |
|
61 | newPair.second=newControlPoints; | |
62 | setKeyValueAt(0.0, qVariantFromValue(m_oldSpline)); |
|
62 | setKeyValueAt(0.0, qVariantFromValue(m_oldSpline)); | |
63 | setKeyValueAt(1.0, qVariantFromValue(newPair)); |
|
63 | setKeyValueAt(1.0, qVariantFromValue(newPair)); | |
64 |
|
64 | |||
65 | } |
|
65 | } | |
66 | } |
|
66 | } | |
67 |
|
67 | |||
68 |
QVariant SplineAnimation::interpolated(const QVariant &start, const QVariant & |
|
68 | QVariant SplineAnimation::interpolated(const QVariant &start, const QVariant &end, qreal progress ) const | |
69 | { |
|
69 | { | |
70 |
|
70 | |||
71 | SplineVector startPair = qVariantValue< SplineVector >(start); |
|
71 | SplineVector startPair = qVariantValue< SplineVector >(start); | |
72 | SplineVector endPair = qVariantValue< SplineVector >(end); |
|
72 | SplineVector endPair = qVariantValue< SplineVector >(end); | |
73 | SplineVector result; |
|
73 | SplineVector result; | |
74 |
|
74 | |||
75 |
|
75 | |||
76 | switch(m_type) { |
|
76 | switch (m_type) { | |
77 |
|
||||
78 | case MoveDownAnimation: { |
|
|||
79 |
|
77 | |||
80 | if(startPair.first.count() != endPair.first.count()) break; |
|
78 | case MoveDownAnimation: { | |
81 |
|
|
79 | if (startPair.first.count() != endPair.first.count()) | |
82 | Q_ASSERT(endPair.first.count()*2-2 == endPair.second.count()); |
|
|||
83 | for(int i =0;i< endPair.first.count();i++) { |
|
|||
84 | qreal x = startPair.first[i].x() + ((endPair.first[i].x()- startPair.first[i].x()) * progress); |
|
|||
85 | qreal y = startPair.first[i].y() + ((endPair.first[i].y()- startPair.first[i].y()) * progress); |
|
|||
86 | result.first << QPointF(x,y); |
|
|||
87 | if(i +1 >= endPair.first.count()) continue; |
|
|||
88 | x = startPair.second[i*2].x() + ((endPair.second[i*2].x()- startPair.second[i*2].x()) * progress); |
|
|||
89 | y = startPair.second[i*2].y() + ((endPair.second[i*2].y()- startPair.second[i*2].y()) * progress); |
|
|||
90 | result.second << QPoint(x,y); |
|
|||
91 | x = startPair.second[i*2+1].x() + ((endPair.second[i*2+1].x()- startPair.second[i*2+1].x()) * progress); |
|
|||
92 | y = startPair.second[i*2+1].y() + ((endPair.second[i*2+1].y()- startPair.second[i*2+1].y()) * progress); |
|
|||
93 | result.second << QPoint(x,y); |
|
|||
94 | } |
|
|||
95 |
|
||||
96 | } |
|
|||
97 | break; |
|
80 | break; | |
98 | case LineDrawAnimation:{ |
|
81 | Q_ASSERT(startPair.first.count() * 2 - 2 == startPair.second.count()); | |
99 |
|
|
82 | Q_ASSERT(endPair.first.count() * 2 - 2 == endPair.second.count()); | |
100 | int count = endPair.first.count()* qBound(0.0, progress, 1.0); |
|
83 | for(int i = 0; i < endPair.first.count(); i++) { | |
101 | for(int i =0;i<count;i++) { |
|
84 | qreal x = startPair.first[i].x() + ((endPair.first[i].x() - startPair.first[i].x()) * progress); | |
102 | result.first << endPair.first[i]; |
|
85 | qreal y = startPair.first[i].y() + ((endPair.first[i].y() - startPair.first[i].y()) * progress); | |
103 | if(i+1==count) break; |
|
86 | result.first << QPointF(x,y); | |
104 | result.second << endPair.second[2*i]; |
|
87 | if (i + 1 >= endPair.first.count()) | |
105 | result.second << endPair.second[2*i+1]; |
|
88 | continue; | |
106 | } |
|
89 | x = startPair.second[i * 2].x() + ((endPair.second[i * 2].x() - startPair.second[i * 2].x()) * progress); | |
|
90 | y = startPair.second[i * 2].y() + ((endPair.second[i * 2].y() - startPair.second[i * 2].y()) * progress); | |||
|
91 | result.second << QPoint(x,y); | |||
|
92 | x = startPair.second[i * 2 + 1].x() + ((endPair.second[i * 2 + 1].x() - startPair.second[i * 2 + 1].x()) * progress); | |||
|
93 | y = startPair.second[i * 2 + 1].y() + ((endPair.second[i * 2 + 1].y() - startPair.second[i * 2 + 1].y()) * progress); | |||
|
94 | result.second << QPoint(x,y); | |||
107 | } |
|
95 | } | |
108 | break; |
|
96 | ||
109 | default: |
|
97 | } | |
110 | qWarning()<<"Unknow type of animation"; |
|
98 | break; | |
111 | break; |
|
99 | case LineDrawAnimation:{ | |
|
100 | Q_ASSERT(endPair.first.count() * 2 - 2 == endPair.second.count()); | |||
|
101 | int count = endPair.first.count()* qBound(0.0, progress, 1.0); | |||
|
102 | for(int i = 0; i < count; i++) { | |||
|
103 | result.first << endPair.first[i]; | |||
|
104 | if(i + 1 == count) | |||
|
105 | break; | |||
|
106 | result.second << endPair.second[2 * i]; | |||
|
107 | result.second << endPair.second[2 * i + 1]; | |||
|
108 | } | |||
|
109 | } | |||
|
110 | break; | |||
|
111 | default: | |||
|
112 | qWarning() << "Unknow type of animation"; | |||
|
113 | break; | |||
112 | } |
|
114 | } | |
113 |
|
115 | |||
114 | return qVariantFromValue(result); |
|
116 | return qVariantFromValue(result); | |
115 | } |
|
117 | } | |
116 |
|
118 | |||
117 |
void SplineAnimation::updateCurrentValue (const QVariant & |
|
119 | void SplineAnimation::updateCurrentValue (const QVariant &value ) | |
118 | { |
|
120 | { | |
119 | if(state()!=QAbstractAnimation::Stopped){ //workaround |
|
121 | if (state() != QAbstractAnimation::Stopped) { //workaround | |
120 | m_dirty=true; |
|
122 | m_dirty = true; | |
121 | QPair<QVector<QPointF >, QVector<QPointF > > pair = qVariantValue< QPair< QVector<QPointF>, QVector<QPointF> > >(value); |
|
123 | QPair<QVector<QPointF >, QVector<QPointF > > pair = qVariantValue< QPair< QVector<QPointF>, QVector<QPointF> > >(value); | |
122 | m_item->setLayout(pair.first,pair.second); |
|
124 | m_item->setLayout(pair.first, pair.second); | |
123 | } |
|
125 | } | |
124 | } |
|
126 | } | |
125 |
|
127 | |||
126 |
|
128 | |||
127 | QTCOMMERCIALCHART_END_NAMESPACE |
|
129 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,33 +1,32 | |||||
1 | #ifndef SPLINEANIMATION_P_H_ |
|
1 | #ifndef SPLINEANIMATION_P_H_ | |
2 | #define SPLINEANIMATION_P_H_ |
|
2 | #define SPLINEANIMATION_P_H_ | |
3 | #include "chartanimation_p.h" |
|
3 | #include "chartanimation_p.h" | |
4 | #include <QPointF> |
|
4 | #include <QPointF> | |
5 |
|
5 | |||
6 | typedef QPair<QVector<QPointF >, QVector<QPointF > > SplineVector; |
|
6 | typedef QPair<QVector<QPointF >, QVector<QPointF > > SplineVector; | |
7 |
|
7 | |||
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
9 |
|
9 | |||
10 |
|
||||
11 | class SplineChartItem; |
|
10 | class SplineChartItem; | |
12 |
|
11 | |||
13 | class SplineAnimation : public ChartAnimation |
|
12 | class SplineAnimation : public ChartAnimation | |
14 | { |
|
13 | { | |
15 | public: |
|
14 | public: | |
16 |
|
15 | |||
17 | SplineAnimation(SplineChartItem* item); |
|
16 | SplineAnimation(SplineChartItem* item); | |
18 | ~SplineAnimation(); |
|
17 | ~SplineAnimation(); | |
19 |
void setValues(QVector<QPointF>& |
|
18 | void setValues(QVector<QPointF> &oldPoints, QVector<QPointF> &newPoints, QVector<QPointF> &oldContorlPoints, QVector<QPointF> &newControlPoints, int index); | |
20 |
|
19 | |||
21 | protected: |
|
20 | protected: | |
22 |
QVariant interpolated(const QVariant &start, const QVariant & |
|
21 | QVariant interpolated(const QVariant &start, const QVariant &end, qreal progress) const; | |
23 |
void updateCurrentValue |
|
22 | void updateCurrentValue(const QVariant &value); | |
24 |
|
23 | |||
25 | private: |
|
24 | private: | |
26 | SplineVector m_oldSpline; |
|
25 | SplineVector m_oldSpline; | |
27 |
SplineChartItem* |
|
26 | SplineChartItem *m_item; | |
28 | bool m_dirty; |
|
27 | bool m_dirty; | |
29 | }; |
|
28 | }; | |
30 |
|
29 | |||
31 | QTCOMMERCIALCHART_END_NAMESPACE |
|
30 | QTCOMMERCIALCHART_END_NAMESPACE | |
32 |
|
31 | |||
33 | #endif |
|
32 | #endif |
@@ -1,88 +1,89 | |||||
1 | #include "xyanimation_p.h" |
|
1 | #include "xyanimation_p.h" | |
2 | #include "xychartitem_p.h" |
|
2 | #include "xychartitem_p.h" | |
3 |
|
3 | |||
4 | Q_DECLARE_METATYPE(QVector<QPointF>) |
|
4 | Q_DECLARE_METATYPE(QVector<QPointF>) | |
5 |
|
5 | |||
6 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
6 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
7 |
|
7 | |||
8 | XYAnimation::XYAnimation(XYChartItem *item):ChartAnimation(item), |
|
8 | XYAnimation::XYAnimation(XYChartItem *item):ChartAnimation(item), | |
9 | m_item(item), |
|
9 | m_item(item), | |
10 | m_dirty(false) |
|
10 | m_dirty(false) | |
11 | { |
|
11 | { | |
12 | } |
|
12 | } | |
13 |
|
13 | |||
14 | XYAnimation::~XYAnimation() |
|
14 | XYAnimation::~XYAnimation() | |
15 | { |
|
15 | { | |
16 | } |
|
16 | } | |
17 |
|
17 | |||
18 |
void XYAnimation::setValues(QVector<QPointF>& |
|
18 | void XYAnimation::setValues(QVector<QPointF> &oldPoints, QVector<QPointF> &newPoints, int index) | |
19 | { |
|
19 | { | |
20 |
|
||||
21 | int x = oldPoints.count(); |
|
20 | int x = oldPoints.count(); | |
22 | int y = newPoints.count(); |
|
21 | int y = newPoints.count(); | |
23 |
|
22 | |||
24 | if(x!=y && abs(x-y)!=1) { |
|
23 | if (x != y && abs(x - y) != 1) { | |
25 | m_oldPoints = newPoints; |
|
24 | m_oldPoints = newPoints; | |
26 | oldPoints.resize(newPoints.size()); |
|
25 | oldPoints.resize(newPoints.size()); | |
27 | setKeyValueAt(0.0, qVariantFromValue(oldPoints)); |
|
26 | setKeyValueAt(0.0, qVariantFromValue(oldPoints)); | |
28 | setKeyValueAt(1.0, qVariantFromValue(newPoints)); |
|
27 | setKeyValueAt(1.0, qVariantFromValue(newPoints)); | |
29 | m_dirty=false; |
|
28 | m_dirty = false; | |
30 | } |
|
29 | } | |
31 | else { |
|
30 | else { | |
32 | if(m_dirty) { |
|
31 | if (m_dirty) { | |
33 | m_oldPoints = oldPoints; |
|
32 | m_oldPoints = oldPoints; | |
34 | m_dirty=false; |
|
33 | m_dirty = false; | |
35 | } |
|
34 | } | |
36 | oldPoints = newPoints; |
|
35 | oldPoints = newPoints; | |
37 | if (y<x) (m_oldPoints.remove(index)); //remove |
|
36 | if (y < x) | |
38 | if (y>x) (m_oldPoints.insert(index,x>0?m_oldPoints[index-1]:newPoints[index])); //add |
|
37 | m_oldPoints.remove(index); //remove | |
|
38 | if (y > x) | |||
|
39 | m_oldPoints.insert(index, x > 0 ? m_oldPoints[index-1] : newPoints[index]); //add | |||
39 | setKeyValueAt(0.0, qVariantFromValue(m_oldPoints)); |
|
40 | setKeyValueAt(0.0, qVariantFromValue(m_oldPoints)); | |
40 | setKeyValueAt(1.0, qVariantFromValue(newPoints)); |
|
41 | setKeyValueAt(1.0, qVariantFromValue(newPoints)); | |
41 | Q_ASSERT(m_oldPoints.count() == newPoints.count()); |
|
42 | Q_ASSERT(m_oldPoints.count() == newPoints.count()); | |
42 | } |
|
43 | } | |
43 | } |
|
44 | } | |
44 |
|
45 | |||
45 |
QVariant XYAnimation::interpolated(const QVariant &start, const QVariant & |
|
46 | QVariant XYAnimation::interpolated(const QVariant &start, const QVariant &end, qreal progress ) const | |
46 | { |
|
47 | { | |
47 | QVector<QPointF> startVector = qVariantValue<QVector<QPointF> >(start); |
|
48 | QVector<QPointF> startVector = qVariantValue<QVector<QPointF> >(start); | |
48 | QVector<QPointF> endVector = qVariantValue<QVector<QPointF> >(end); |
|
49 | QVector<QPointF> endVector = qVariantValue<QVector<QPointF> >(end); | |
49 | QVector<QPointF> result; |
|
50 | QVector<QPointF> result; | |
50 |
|
51 | |||
51 | switch(m_type) { |
|
52 | switch (m_type) { | |
52 |
|
||||
53 | case MoveDownAnimation: { |
|
|||
54 |
|
||||
55 | if(startVector.count() != endVector.count()) break; |
|
|||
56 |
|
53 | |||
57 | for(int i =0;i< startVector.count();i++) { |
|
54 | case MoveDownAnimation: { | |
58 | qreal x = startVector[i].x() + ((endVector[i].x()- startVector[i].x()) * progress); |
|
|||
59 | qreal y = startVector[i].y() + ((endVector[i].y()- startVector[i].y()) * progress); |
|
|||
60 | result << QPointF(x,y); |
|
|||
61 | } |
|
|||
62 |
|
55 | |||
63 | } |
|
56 | if (startVector.count() != endVector.count()) | |
64 | break; |
|
57 | break; | |
65 | case LineDrawAnimation:{ |
|
58 | ||
66 |
|
|
59 | for(int i = 0; i < startVector.count(); i++) { | |
67 | result << endVector[i]; |
|
60 | qreal x = startVector[i].x() + ((endVector[i].x() - startVector[i].x()) * progress); | |
68 | } |
|
61 | qreal y = startVector[i].y() + ((endVector[i].y() - startVector[i].y()) * progress); | |
|
62 | result << QPointF(x, y); | |||
69 | } |
|
63 | } | |
70 | break; |
|
64 | ||
71 | default: |
|
65 | } | |
72 | qWarning()<<"Unknown type of animation"; |
|
66 | break; | |
73 | break; |
|
67 | case LineDrawAnimation: { | |
|
68 | for(int i = 0; i < endVector.count() * qBound(0.0, progress, 1.0); i++) | |||
|
69 | result << endVector[i]; | |||
|
70 | } | |||
|
71 | break; | |||
|
72 | default: | |||
|
73 | qWarning() << "Unknown type of animation"; | |||
|
74 | break; | |||
74 | } |
|
75 | } | |
75 |
|
76 | |||
76 | return qVariantFromValue(result); |
|
77 | return qVariantFromValue(result); | |
77 | } |
|
78 | } | |
78 |
|
79 | |||
79 |
void XYAnimation::updateCurrentValue (const QVariant & |
|
80 | void XYAnimation::updateCurrentValue (const QVariant &value) | |
80 | { |
|
81 | { | |
81 | if(state()!=QAbstractAnimation::Stopped){ //workaround |
|
82 | if(state()!=QAbstractAnimation::Stopped){ //workaround | |
82 | m_dirty=true; |
|
83 | m_dirty = true; | |
83 | QVector<QPointF> vector = qVariantValue<QVector<QPointF> >(value); |
|
84 | QVector<QPointF> vector = qVariantValue<QVector<QPointF> >(value); | |
84 | m_item->setLayout(vector); |
|
85 | m_item->setLayout(vector); | |
85 | } |
|
86 | } | |
86 | } |
|
87 | } | |
87 |
|
88 | |||
88 | QTCOMMERCIALCHART_END_NAMESPACE |
|
89 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,30 +1,30 | |||||
1 | #ifndef XYCHARTANIMATION_P_H_ |
|
1 | #ifndef XYCHARTANIMATION_P_H_ | |
2 | #define XYCHARTANIMATION_P_H_ |
|
2 | #define XYCHARTANIMATION_P_H_ | |
3 | #include "chartanimation_p.h" |
|
3 | #include "chartanimation_p.h" | |
4 | #include <QPointF> |
|
4 | #include <QPointF> | |
5 |
|
5 | |||
6 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
6 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
7 |
|
7 | |||
8 | class XYChartItem; |
|
8 | class XYChartItem; | |
9 |
|
9 | |||
10 | class XYAnimation : public ChartAnimation |
|
10 | class XYAnimation : public ChartAnimation | |
11 | { |
|
11 | { | |
12 | public: |
|
12 | public: | |
13 |
|
|
13 | enum Animation { LineDrawAnimation, MoveDownAnimation, MoveUpAnimation }; | |
14 | XYAnimation(XYChartItem *item); |
|
14 | XYAnimation(XYChartItem *item); | |
15 | ~XYAnimation(); |
|
15 | ~XYAnimation(); | |
16 |
void setValues(QVector<QPointF>& |
|
16 | void setValues(QVector<QPointF> &oldPoints, QVector<QPointF> &newPoints,int index); | |
17 |
|
17 | |||
18 | protected: |
|
18 | protected: | |
19 |
QVariant interpolated(const QVariant &start, const QVariant & |
|
19 | QVariant interpolated(const QVariant &start, const QVariant &end, qreal progress ) const; | |
20 |
void updateCurrentValue (const QVariant & |
|
20 | void updateCurrentValue (const QVariant &value ); | |
21 |
|
21 | |||
22 | private: |
|
22 | private: | |
23 | XYChartItem *m_item; |
|
23 | XYChartItem *m_item; | |
24 | QVector<QPointF> m_oldPoints; |
|
24 | QVector<QPointF> m_oldPoints; | |
25 | bool m_dirty; |
|
25 | bool m_dirty; | |
26 | }; |
|
26 | }; | |
27 |
|
27 | |||
28 | QTCOMMERCIALCHART_END_NAMESPACE |
|
28 | QTCOMMERCIALCHART_END_NAMESPACE | |
29 |
|
29 | |||
30 | #endif |
|
30 | #endif |
General Comments 0
You need to be logged in to leave comments.
Login now