##// END OF EJS Templates
Fixes missing intlization in chartanimator
Michal Klocek -
r720:605f266f80f8
parent child
Show More
@@ -1,288 +1,288
1 1 #include "chartanimator_p.h"
2 2 #include "axisanimation_p.h"
3 3 #include "xyanimation_p.h"
4 4 #include "splineanimation_p.h"
5 5 #include "xychartitem_p.h"
6 6 #include "pieanimation_p.h"
7 7 #include "baranimation_p.h"
8 8 #include "barchartitem_p.h"
9 9 #include "areachartitem_p.h"
10 10 #include "splinechartitem_p.h"
11 11 #include "scatterchartitem_p.h"
12 12 #include <QTimer>
13 13
14 14 Q_DECLARE_METATYPE(QVector<QPointF>)
15 15 Q_DECLARE_METATYPE(QVector<qreal>)
16 16 Q_DECLARE_METATYPE(QVector<QRectF>)
17 17
18 18 QTCOMMERCIALCHART_BEGIN_NAMESPACE
19 19
20 20 const static int duration = 1000;
21 21
22 ChartAnimator::ChartAnimator(QObject *parent):QObject(parent)
22 ChartAnimator::ChartAnimator(QObject *parent):QObject(parent),m_state(ShowState)
23 23 {
24 24 }
25 25
26 26 ChartAnimator::~ChartAnimator()
27 27 {
28 28 }
29 29
30 30 void ChartAnimator::addAnimation(Axis* item)
31 31 {
32 32 ChartAnimation* animation = m_animations.value(item);
33 33
34 34 if(!animation) {
35 35 animation = new AxisAnimation(item);
36 36 m_animations.insert(item,animation);
37 37 }
38 38
39 39 item->setAnimator(this);
40 40 }
41 41
42 42 void ChartAnimator::addAnimation(SplineChartItem* item)
43 43 {
44 44 ChartAnimation* animation = m_animations.value(item);
45 45
46 46 if(!animation) {
47 47 animation = new SplineAnimation(item);
48 48 m_animations.insert(item,animation);
49 49 }
50 50
51 51 item->setAnimator(this);
52 52 }
53 53
54 54 void ChartAnimator::addAnimation(ScatterChartItem* item)
55 55 {
56 56 ChartAnimation* animation = m_animations.value(item);
57 57
58 58 if(!animation) {
59 59 animation = new XYAnimation(item);
60 60 m_animations.insert(item,animation);
61 61 }
62 62
63 63 item->setAnimator(this);
64 64 }
65 65
66 66 void ChartAnimator::addAnimation(LineChartItem* item)
67 67 {
68 68 ChartAnimation* animation = m_animations.value(item);
69 69
70 70 if(!animation) {
71 71 animation = new XYAnimation(item);
72 72 m_animations.insert(item,animation);
73 73 }
74 74
75 75 item->setAnimator(this);
76 76 }
77 77
78 78 void ChartAnimator::addAnimation(PieChartItem* item)
79 79 {
80 80 ChartAnimation* animation = m_animations.value(item);
81 81
82 82 if(!animation) {
83 83 animation = new PieAnimation(item);
84 84 m_animations.insert(item,animation);
85 85 }
86 86
87 87 item->setAnimator(this);
88 88 }
89 89
90 90 void ChartAnimator::addAnimation(BarChartItem* item)
91 91 {
92 92 ChartAnimation* animation = m_animations.value(item);
93 93
94 94 if(!animation) {
95 95 animation = new BarAnimation(item);
96 96 m_animations.insert(item,animation);
97 97 }
98 98
99 99 item->setAnimator(this);
100 100 }
101 101
102 102
103 103 void ChartAnimator::removeAnimation(Chart* item)
104 104 {
105 105 item->setAnimator(0);
106 106 m_animations.remove(item);
107 107 }
108 108
109 109 void ChartAnimator::updateLayout(Axis* item , QVector<qreal>& newLayout)
110 110 {
111 111 AxisAnimation* animation = static_cast<AxisAnimation*>(m_animations.value(item));
112 112
113 113 Q_ASSERT(animation);
114 114
115 115 QVector<qreal> oldLayout = item->layout();
116 116
117 117 if(newLayout.count()==0) return;
118 118
119 119 switch(m_state)
120 120 {
121 121 case ZoomOutState: {
122 122 QRectF rect = item->geometry();
123 123 oldLayout.resize(newLayout.count());
124 124
125 125 for(int i=0,j=oldLayout.count()-1;i<(oldLayout.count()+1)/2;i++,j--)
126 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 }
130 130 }
131 131 break;
132 132 case ZoomInState: {
133 133 int index = qMin(oldLayout.count()*(item->axisType()==Axis::X_AXIS?m_point.x():(1 -m_point.y())),newLayout.count()-1.0);
134 134 oldLayout.resize(newLayout.count());
135 135
136 136 for(int i=0;i<oldLayout.count();i++)
137 137 {
138 138 oldLayout[i]= oldLayout[index];
139 139 }
140 140 }
141 141 break;
142 142 case ScrollDownState:
143 143 case ScrollRightState: {
144 144 oldLayout.resize(newLayout.count());
145 145
146 146 for(int i=0, j=i+1;i<oldLayout.count()-1;i++,j++)
147 147 {
148 148 oldLayout[i]= oldLayout[j];
149 149 }
150 150 }
151 151 break;
152 152 case ScrollUpState:
153 153 case ScrollLeftState: {
154 154 oldLayout.resize(newLayout.count());
155 155
156 156 for(int i=oldLayout.count()-1, j=i-1;i>0;i--,j--)
157 157 {
158 158 oldLayout[i]= oldLayout[j];
159 159 }
160 160 }
161 161 break;
162 162 default: {
163 163 oldLayout.resize(newLayout.count());
164 164 QRectF rect = item->geometry();
165 165 for(int i=0, j=oldLayout.count()-1;i<oldLayout.count();i++,j--)
166 166 {
167 167 oldLayout[i]= item->axisType()==Axis::X_AXIS?rect.left():rect.top();
168 168 }
169 169 }
170 170 break;
171 171 }
172 172
173 173
174 174 if(animation->state()!=QAbstractAnimation::Stopped) {
175 175 animation->stop();
176 176 }
177 177
178 178 animation->setDuration(duration);
179 179 animation->setEasingCurve(QEasingCurve::OutQuart);
180 180 QVariantAnimation::KeyValues value;
181 181 animation->setKeyValues(value); //workaround for wrong interpolation call
182 182 animation->setKeyValueAt(0.0, qVariantFromValue(oldLayout));
183 183 animation->setKeyValueAt(1.0, qVariantFromValue(newLayout));
184 184
185 185 QTimer::singleShot(0,animation,SLOT(start()));
186 186 }
187 187
188 188 void ChartAnimator::updateLayout(SplineChartItem* item, QVector<QPointF>& oldPoints ,QVector<QPointF>& newPoints, QVector<QPointF>& oldControlPoints, QVector<QPointF>& newControlPoints,int index)
189 189 {
190 190 SplineAnimation* animation = static_cast<SplineAnimation*>(m_animations.value(item));
191 191
192 192 Q_ASSERT(animation);
193 193
194 194 if(newPoints.count()<2 || newControlPoints.count()<2) return;
195 195
196 196 bool empty = oldPoints.count()==0;
197 197
198 198
199 199 if(animation->state()!=QAbstractAnimation::Stopped) {
200 200 animation->stop();
201 201 }
202 202
203 203 animation->setDuration(duration);
204 204 if(!empty)
205 205 animation->setAnimationType(ChartAnimation::MoveDownAnimation);
206 206 else
207 207 animation->setAnimationType(ChartAnimation::LineDrawAnimation);
208 208
209 209 animation->setEasingCurve(QEasingCurve::OutQuart);
210 210 animation->setValues(oldPoints,newPoints,oldControlPoints,newControlPoints,index);
211 211
212 212 QTimer::singleShot(0,animation,SLOT(start()));
213 213 }
214 214
215 215
216 216 void ChartAnimator::updateLayout(XYChartItem* item, QVector<QPointF>& oldPoints , QVector<QPointF>& newPoints, int index)
217 217 {
218 218 XYAnimation* animation = static_cast<XYAnimation*>(m_animations.value(item));
219 219
220 220 Q_ASSERT(animation);
221 221
222 222 if(newPoints.count()==0) return;
223 223
224 224 bool empty = oldPoints.count()==0;
225 225
226 226
227 227 if(animation->state()!=QAbstractAnimation::Stopped) {
228 228 animation->stop();
229 229 }
230 230
231 231 animation->setDuration(duration);
232 232 if(!empty)
233 233 animation->setAnimationType(ChartAnimation::MoveDownAnimation);
234 234 else
235 235 animation->setAnimationType(ChartAnimation::LineDrawAnimation);
236 236
237 237 animation->setEasingCurve(QEasingCurve::OutQuart);
238 238 animation->setValues(oldPoints,newPoints,index);
239 239
240 240 QTimer::singleShot(0,animation,SLOT(start()));
241 241 }
242 242
243 243 void ChartAnimator::addAnimation(PieChartItem* item, QPieSlice *slice, const PieSliceData &sliceData, bool isEmpty)
244 244 {
245 245 PieAnimation* animation = static_cast<PieAnimation*>(m_animations.value(item));
246 246 Q_ASSERT(animation);
247 247 animation->addSlice(slice, sliceData, isEmpty);
248 248 }
249 249
250 250 void ChartAnimator::removeAnimation(PieChartItem* item, QPieSlice *slice)
251 251 {
252 252 PieAnimation* animation = static_cast<PieAnimation*>(m_animations.value(item));
253 253 Q_ASSERT(animation);
254 254 animation->removeSlice(slice);
255 255 }
256 256
257 257 void ChartAnimator::updateLayout(PieChartItem* item, const PieLayout &layout)
258 258 {
259 259 PieAnimation* animation = static_cast<PieAnimation*>(m_animations.value(item));
260 260 Q_ASSERT(animation);
261 261 animation->updateValues(layout);
262 262 }
263 263
264 264 void ChartAnimator::updateLayout(PieChartItem* item, QPieSlice *slice, const PieSliceData &sliceData)
265 265 {
266 266 PieAnimation* animation = static_cast<PieAnimation*>(m_animations.value(item));
267 267 Q_ASSERT(animation);
268 268 animation->updateValue(slice, sliceData);
269 269 }
270 270
271 271 void ChartAnimator::updateLayout(BarChartItem* item, const QVector<QRectF> &oldLayout, const QVector<QRectF> &newLayout)
272 272 {
273 273 BarAnimation* animation = static_cast<BarAnimation*>(m_animations.value(item));
274 274 Q_ASSERT(animation);
275 275 animation->setDuration(duration);
276 276 animation->setKeyValueAt(0.0, qVariantFromValue(oldLayout));
277 277 animation->setKeyValueAt(1.0, qVariantFromValue(newLayout));
278 278 QTimer::singleShot(0,animation,SLOT(start()));
279 279 }
280 280
281 281
282 282 void ChartAnimator::setState(State state,const QPointF& point)
283 283 {
284 284 m_state=state;
285 285 m_point=point;
286 286 }
287 287
288 288 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,58 +1,57
1 1 #ifndef CHARTANIMATOR_P_H_
2 2 #define CHARTANIMATOR_P_H_
3 3 #include "qchartglobal.h"
4 4 #include "chartanimation_p.h"
5 5 #include "piechartitem_p.h"
6 6 #include "barchartitem_p.h"
7 7 #include <QPointF>
8 8
9 9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
10 10
11 11 class ChartItem;
12 12 class Axis;
13 13 class AreaChartItem;
14 14 class SplineChartItem;
15 15 class ScatterChartItem;
16 16 class LineChartItem;
17 17 class XYChartItem;
18 18
19 19 class ChartAnimator : public QObject {
20 20
21 21 public:
22 22 enum State{ShowState, ScrollUpState, ScrollDownState, ScrollLeftState,ScrollRightState,ZoomInState,ZoomOutState};
23 Q_DECLARE_FLAGS(States, State);
24 23
25 24 ChartAnimator(QObject *parent = 0);
26 25 virtual ~ChartAnimator();
27 26
28 27 void addAnimation(Axis* item);
29 28 void addAnimation(PieChartItem* item);
30 29 void addAnimation(ScatterChartItem* item);
31 30 void addAnimation(LineChartItem* item);
32 31 void addAnimation(SplineChartItem* item);
33 32 void addAnimation(BarChartItem* item);
34 33 void removeAnimation(Chart* item);
35 34
36 35 void animationStarted();
37 36 void updateLayout(XYChartItem* item, QVector<QPointF>& oldLayout,QVector<QPointF>& newLayout,int index);
38 37 void updateLayout(SplineChartItem* item, QVector<QPointF>& oldPoints , QVector<QPointF>& newPoints, QVector<QPointF>& oldControlPoints, QVector<QPointF>& newContorlPoints,int index);
39 38 void updateLayout(Axis* item, QVector<qreal>& layout);
40 39
41 40 void addAnimation(PieChartItem* item, QPieSlice *slice, const PieSliceData &sliceData, bool isEmpty);
42 41 void removeAnimation(PieChartItem* item, QPieSlice *slice);
43 42 void updateLayout(PieChartItem* item, const PieLayout &layout);
44 43 void updateLayout(PieChartItem* item, QPieSlice *slice, const PieSliceData &sliceData);
45 44
46 45 void updateLayout(BarChartItem* item, const QVector<QRectF> &oldLayout, const QVector<QRectF> &newLayout);
47 46
48 47 void setState(State state,const QPointF& point = QPointF());
49 48
50 49 private:
51 50 QMap<Chart*,ChartAnimation*> m_animations;
52 51 State m_state;
53 52 QPointF m_point;
54 53 };
55 54
56 55 QTCOMMERCIALCHART_END_NAMESPACE
57 56
58 57 #endif
General Comments 0
You need to be logged in to leave comments. Login now