1 | NO CONTENT: modified file |
|
NO CONTENT: modified file |
1 | NO CONTENT: modified file |
|
NO CONTENT: modified file |
1 | NO CONTENT: modified file |
|
NO CONTENT: modified file |
1 | NO CONTENT: modified file |
|
NO CONTENT: modified file |
@@ -10,7 +10,7 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 | } |
@@ -19,7 +19,8 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 | |||
@@ -114,16 +115,15 void ChartAnimator::updateLayout(Axis* item , QVector<qreal>& newLayout) | |||||
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) | |
|
119 | return; | |||
118 |
|
120 | |||
119 | switch(m_state) |
|
121 | switch (m_state) { | |
120 | { |
|
|||
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 |
|
|
127 | oldLayout[i] = item->axisType() == Axis::X_AXIS ? rect.left() : rect.bottom(); | |
128 |
|
|
128 | oldLayout[j] = item->axisType() == Axis::X_AXIS ? rect.right() : rect.top(); | |
129 | } |
|
129 | } | |
@@ -134,46 +134,37 void ChartAnimator::updateLayout(Axis* item , QVector<qreal>& newLayout) | |||||
134 |
|
|
134 | oldLayout.resize(newLayout.count()); | |
135 |
|
135 | |||
136 |
|
|
136 | for(int i = 0; i < oldLayout.count(); i++) | |
137 | { |
|
|||
138 |
|
|
137 | oldLayout[i]= oldLayout[index]; | |
139 | } |
|
138 | } | |
140 | } |
|
|||
141 | break; |
|
139 | break; | |
142 |
|
|
140 | case ScrollDownState: | |
143 |
|
|
141 | case ScrollRightState: { | |
144 |
|
|
142 | oldLayout.resize(newLayout.count()); | |
145 |
|
143 | |||
146 |
|
|
144 | for(int i = 0, j = i + 1; i < oldLayout.count() - 1; i++, j++) | |
147 | { |
|
|||
148 |
|
|
145 | oldLayout[i]= oldLayout[j]; | |
149 | } |
|
146 | } | |
150 | } |
|
|||
151 | break; |
|
147 | break; | |
152 |
|
|
148 | case ScrollUpState: | |
153 |
|
|
149 | case ScrollLeftState: { | |
154 |
|
|
150 | oldLayout.resize(newLayout.count()); | |
155 |
|
151 | |||
156 |
|
|
152 | for(int i = oldLayout.count() - 1, j = i - 1; i > 0; i--, j--) | |
157 | { |
|
|||
158 |
|
|
153 | oldLayout[i]= oldLayout[j]; | |
159 | } |
|
154 | } | |
160 | } |
|
|||
161 | break; |
|
155 | break; | |
162 |
|
|
156 | default: { | |
163 |
|
|
157 | oldLayout.resize(newLayout.count()); | |
164 |
|
|
158 | QRectF rect = item->geometry(); | |
165 |
|
|
159 | for(int i = 0, j = oldLayout.count() - 1; i < oldLayout.count(); i++, j--) | |
166 | { |
|
|||
167 |
|
|
160 | oldLayout[i] = item->axisType() == Axis::X_AXIS ? rect.left() : rect.top(); | |
168 | } |
|
161 | } | |
169 | } |
|
|||
170 | break; |
|
162 | break; | |
171 | } |
|
163 | } | |
172 |
|
164 | |||
173 |
|
165 | |||
174 |
if(animation->state()!=QAbstractAnimation::Stopped) |
|
166 | if (animation->state() != QAbstractAnimation::Stopped) | |
175 | animation->stop(); |
|
167 | animation->stop(); | |
176 | } |
|
|||
177 |
|
168 | |||
178 | animation->setDuration(duration); |
|
169 | animation->setDuration(duration); | |
179 | animation->setEasingCurve(QEasingCurve::OutQuart); |
|
170 | animation->setEasingCurve(QEasingCurve::OutQuart); | |
@@ -191,14 +182,14 void ChartAnimator::updateLayout(SplineChartItem* item, QVector<QPointF>& oldPoi | |||||
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) | |
@@ -219,14 +210,14 void ChartAnimator::updateLayout(XYChartItem* item, QVector<QPointF>& oldPoints | |||||
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) |
1 | NO CONTENT: modified file |
|
NO CONTENT: modified file |
1 | NO CONTENT: modified file |
|
NO CONTENT: modified file |
1 | NO CONTENT: modified file |
|
NO CONTENT: modified file |
@@ -76,15 +76,16 QVariant SplineAnimation::interpolated(const QVariant &start, const QVariant & e | |||||
76 | switch(m_type) { |
|
76 | switch (m_type) { | |
77 |
|
77 | |||
78 |
|
|
78 | case MoveDownAnimation: { | |
79 |
|
79 | if (startPair.first.count() != endPair.first.count()) | ||
80 | if(startPair.first.count() != endPair.first.count()) break; |
|
80 | break; | |
81 |
|
|
81 | Q_ASSERT(startPair.first.count() * 2 - 2 == startPair.second.count()); | |
82 |
|
|
82 | Q_ASSERT(endPair.first.count() * 2 - 2 == endPair.second.count()); | |
83 |
|
|
83 | for(int i = 0; i < endPair.first.count(); i++) { | |
84 |
|
|
84 | qreal x = startPair.first[i].x() + ((endPair.first[i].x() - startPair.first[i].x()) * progress); | |
85 |
|
|
85 | qreal y = startPair.first[i].y() + ((endPair.first[i].y() - startPair.first[i].y()) * progress); | |
86 |
|
|
86 | result.first << QPointF(x,y); | |
87 |
|
|
87 | if (i + 1 >= endPair.first.count()) | |
|
88 | continue; | |||
88 |
|
|
89 | x = startPair.second[i * 2].x() + ((endPair.second[i * 2].x() - startPair.second[i * 2].x()) * progress); | |
89 |
|
|
90 | y = startPair.second[i * 2].y() + ((endPair.second[i * 2].y() - startPair.second[i * 2].y()) * progress); | |
90 |
|
|
91 | result.second << QPoint(x,y); | |
@@ -100,7 +101,8 QVariant SplineAnimation::interpolated(const QVariant &start, const QVariant & e | |||||
100 |
|
|
101 | int count = endPair.first.count()* qBound(0.0, progress, 1.0); | |
101 |
|
|
102 | for(int i = 0; i < count; i++) { | |
102 |
|
|
103 | result.first << endPair.first[i]; | |
103 |
|
|
104 | if(i + 1 == count) | |
|
105 | break; | |||
104 |
|
|
106 | result.second << endPair.second[2 * i]; | |
105 |
|
|
107 | result.second << endPair.second[2 * i + 1]; | |
106 |
|
|
108 | } |
@@ -7,7 +7,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 |
@@ -17,7 +17,6 XYAnimation::~XYAnimation() | |||||
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 | |||
@@ -34,8 +33,10 void XYAnimation::setValues(QVector<QPointF>& oldPoints,QVector<QPointF>& newPoi | |||||
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()); | |
@@ -52,7 +53,8 QVariant XYAnimation::interpolated(const QVariant &start, const QVariant & end, | |||||
52 |
|
53 | |||
53 |
|
|
54 | case MoveDownAnimation: { | |
54 |
|
55 | |||
55 |
|
|
56 | if (startVector.count() != endVector.count()) | |
|
57 | break; | |||
56 |
|
58 | |||
57 |
|
|
59 | for(int i = 0; i < startVector.count(); i++) { | |
58 |
|
|
60 | qreal x = startVector[i].x() + ((endVector[i].x() - startVector[i].x()) * progress); | |
@@ -63,10 +65,9 QVariant XYAnimation::interpolated(const QVariant &start, const QVariant & end, | |||||
63 |
|
|
65 | } | |
64 |
|
|
66 | break; | |
65 |
|
|
67 | case LineDrawAnimation: { | |
66 |
|
|
68 | for(int i = 0; i < endVector.count() * qBound(0.0, progress, 1.0); i++) | |
67 |
|
|
69 | result << endVector[i]; | |
68 | } |
|
70 | } | |
69 | } |
|
|||
70 |
|
|
71 | break; | |
71 |
|
|
72 | default: | |
72 |
|
|
73 | qWarning() << "Unknown type of animation"; |
1 | NO CONTENT: modified file |
|
NO CONTENT: modified file |
General Comments 0
You need to be logged in to leave comments.
Login now