##// END OF EJS Templates
adds QLineAnimation fixes
Michal Klocek -
r1271:b11722f80588
parent child
Show More
@@ -37,7 +37,7 SplineAnimation::~SplineAnimation()
37 {
37 {
38 }
38 }
39
39
40 void SplineAnimation::setValues(QVector<QPointF> &oldPoints, QVector<QPointF> &newPoints, QVector<QPointF> &oldControlPoints, QVector<QPointF> &newControlPoints, int index)
40 void SplineAnimation::setup(QVector<QPointF> &oldPoints, QVector<QPointF> &newPoints, QVector<QPointF> &oldControlPoints, QVector<QPointF> &newControlPoints, int index)
41 {
41 {
42 int x = oldPoints.count();
42 int x = oldPoints.count();
43 int y = newPoints.count();
43 int y = newPoints.count();
@@ -34,7 +34,7 class SplineAnimation : public XYAnimation
34 public:
34 public:
35 SplineAnimation(SplineChartItem *item);
35 SplineAnimation(SplineChartItem *item);
36 ~SplineAnimation();
36 ~SplineAnimation();
37 void setValues(QVector<QPointF> &oldPoints, QVector<QPointF> &newPoints, QVector<QPointF> &oldContorlPoints, QVector<QPointF> &newControlPoints, int index);
37 void setup(QVector<QPointF> &oldPoints, QVector<QPointF> &newPoints, QVector<QPointF> &oldContorlPoints, QVector<QPointF> &newControlPoints, int index = -1);
38
38
39 protected:
39 protected:
40 QVariant interpolated(const QVariant &start, const QVariant &end, qreal progress) const;
40 QVariant interpolated(const QVariant &start, const QVariant &end, qreal progress) const;
@@ -39,50 +39,53 XYAnimation::~XYAnimation()
39 {
39 {
40 }
40 }
41
41
42 void XYAnimation::setAnimationType(Animation type)
42 void XYAnimation::setup(const QVector<QPointF> &oldPoints, const QVector<QPointF> &newPoints, int index)
43 {
43 {
44 if (state() != QAbstractAnimation::Stopped) stop();
44 m_type = NewAnimation;
45 m_type=type;
46 }
47
45
48 void XYAnimation::setValues(const QVector<QPointF> &oldPoints, const QVector<QPointF> &newPoints, int index)
46 if (state() != QAbstractAnimation::Stopped){
49 {
47 stop();
50 if (state() != QAbstractAnimation::Stopped) stop();
48 m_dirty=false;
49 }
51
50
52 if (m_item->isDirty()) {
51 if(!m_dirty){
53 m_oldPoints = oldPoints;
52 m_dirty = true;
54 m_newPoints = newPoints;
53 m_oldPoints = oldPoints;
55 m_dirty=false;
54 }
56 }
57 else {
58 if(m_dirty) {
59 m_newPoints = newPoints;
60 m_oldPoints = oldPoints;
61 m_dirty=false;
62 }
63 }
64
55
65 int x = m_oldPoints.count();
56 m_newPoints = newPoints;
66 int y = m_newPoints.count();
67
57
68 if (abs(x - y) == 1) {
58 int x = m_oldPoints.count();
69 if (y < x){
59 int y = m_newPoints.count();
70 if(!newPoints.isEmpty()) m_newPoints.insert(index,newPoints[index]);
60
71 m_index=index;if(newPoints.isEmpty())
61 if(x - y == 1 && index >= 0 && !newPoints.isEmpty()){
72 m_dirty=true;
62 //remove point
73 }
63 m_newPoints.insert(index, index >= 1 ? m_newPoints[index-1] : newPoints[index]);
74 if (y > x){
64 m_index=index;
75 m_oldPoints.insert(index, x > 0 ? m_oldPoints[index-1] : newPoints[index]);//add
65 m_type = RemovePointAnimation;
76 }
66 }
77 }else{
67
78 m_newPoints=newPoints;
68 if(x - y == -1 && index >= 0){
79 m_dirty=false;
69 //add point
80 m_oldPoints.resize(m_newPoints.size());
70 m_oldPoints.insert(index, x > 0 && index > 1 ? m_oldPoints[index-1] : newPoints[index]);
81 }
71 m_index=index;
72 m_type = AddPointAnimation;
73 }
74
75 x = m_oldPoints.count();
76 y = m_newPoints.count();
77
78 if(x != y)
79 {
80 m_type = NewAnimation;
81 }
82 else if(m_type == NewAnimation)
83 {
84 m_type = ReplacePointAnimation;
85 }
82
86
83 setKeyValueAt(0.0, qVariantFromValue(m_oldPoints));
87 setKeyValueAt(0.0, qVariantFromValue(m_oldPoints));
84 setKeyValueAt(1.0, qVariantFromValue(m_newPoints));
88 setKeyValueAt(1.0, qVariantFromValue(m_newPoints));
85
86 }
89 }
87
90
88 QVariant XYAnimation::interpolated(const QVariant &start, const QVariant &end, qreal progress ) const
91 QVariant XYAnimation::interpolated(const QVariant &start, const QVariant &end, qreal progress ) const
@@ -97,8 +100,9 QVariant XYAnimation::interpolated(const QVariant &start, const QVariant &end, q
97 case AddPointAnimation:
100 case AddPointAnimation:
98 case RemovePointAnimation:
101 case RemovePointAnimation:
99 {
102 {
100 if (startVector.count() != endVector.count())
103 if (startVector.count() != endVector.count()){
101 break;
104 break;
105 }
102
106
103 for(int i = 0; i < startVector.count(); i++) {
107 for(int i = 0; i < startVector.count(); i++) {
104 qreal x = startVector[i].x() + ((endVector[i].x() - startVector[i].x()) * progress);
108 qreal x = startVector[i].x() + ((endVector[i].x() - startVector[i].x()) * progress);
@@ -124,10 +128,13 QVariant XYAnimation::interpolated(const QVariant &start, const QVariant &end, q
124 void XYAnimation::updateCurrentValue (const QVariant &value)
128 void XYAnimation::updateCurrentValue (const QVariant &value)
125 {
129 {
126 if(state()!=QAbstractAnimation::Stopped){ //workaround
130 if(state()!=QAbstractAnimation::Stopped){ //workaround
131
127 QVector<QPointF> vector = qVariantValue<QVector<QPointF> >(value);
132 QVector<QPointF> vector = qVariantValue<QVector<QPointF> >(value);
128 m_item->setGeometryPoints(vector);
133 m_item->setGeometryPoints(vector);
129 m_item->updateGeometry();
134 m_item->updateGeometry();
130 m_item->setDirty(true);
135 m_item->setDirty(true);
136 m_dirty=false;
137
131 }
138 }
132 }
139 }
133
140
@@ -34,8 +34,7 public:
34 enum Animation { AddPointAnimation, RemovePointAnimation, ReplacePointAnimation, NewAnimation };
34 enum Animation { AddPointAnimation, RemovePointAnimation, ReplacePointAnimation, NewAnimation };
35 XYAnimation(XYChart *item);
35 XYAnimation(XYChart *item);
36 ~XYAnimation();
36 ~XYAnimation();
37 void setValues(const QVector<QPointF> &oldPoints, const QVector<QPointF> &newPoints,int index);
37 void setup(const QVector<QPointF> &oldPoints, const QVector<QPointF> &newPoints,int index = -1);
38 void setAnimationType(Animation type);
39 Animation animationType() const { return m_type; };
38 Animation animationType() const { return m_type; };
40
39
41 protected:
40 protected:
@@ -86,7 +86,9 void SplineChartItem::updateChart(QVector<QPointF> &oldPoints, QVector<QPointF>
86 }
86 }
87
87
88 if (m_animation) {
88 if (m_animation) {
89 m_animation->setValues(oldPoints,newPoints,m_controlPoints,controlPoints,index);
89 m_animation->setup(oldPoints,newPoints,m_controlPoints,controlPoints,index);
90 setGeometryPoints(newPoints);
91 setDirty(false);
90 presenter()->startAnimation(m_animation);
92 presenter()->startAnimation(m_animation);
91 }
93 }
92 else {
94 else {
@@ -107,7 +109,9 void SplineChartItem::updateGeometry()
107 const QVector<QPointF> &controlPoints = controlGeometryPoints();
109 const QVector<QPointF> &controlPoints = controlGeometryPoints();
108
110
109 if ((points.size()<2) || (controlPoints.size()<2)) {
111 if ((points.size()<2) || (controlPoints.size()<2)) {
112 prepareGeometryChange();
110 m_path = QPainterPath();
113 m_path = QPainterPath();
114 m_rect = QRect();
111 return;
115 return;
112 }
116 }
113
117
@@ -117,8 +117,9 QPointF XYChart::calculateDomainPoint(const QPointF &point) const
117
117
118 void XYChart::updateChart(QVector<QPointF> &oldPoints, QVector<QPointF> &newPoints,int index)
118 void XYChart::updateChart(QVector<QPointF> &oldPoints, QVector<QPointF> &newPoints,int index)
119 {
119 {
120
120 if (m_animation) {
121 if (m_animation) {
121 m_animation->setValues(oldPoints, newPoints, index);
122 m_animation->setup(oldPoints, newPoints, index);
122 setGeometryPoints(newPoints);
123 setGeometryPoints(newPoints);
123 setDirty(false);
124 setDirty(false);
124 presenter()->startAnimation(m_animation);
125 presenter()->startAnimation(m_animation);
@@ -138,10 +139,6 void XYChart::handlePointAdded(int index)
138
139
139 QVector<QPointF> points;
140 QVector<QPointF> points;
140
141
141 if(m_animation) {
142 m_animation->setAnimationType(XYAnimation::AddPointAnimation);
143 }
144
145 if(m_dirty) {
142 if(m_dirty) {
146 points = calculateGeometryPoints();
143 points = calculateGeometryPoints();
147 } else {
144 } else {
@@ -160,10 +157,6 void XYChart::handlePointRemoved(int index)
160
157
161 QVector<QPointF> points;
158 QVector<QPointF> points;
162
159
163 if(m_animation) {
164 m_animation->setAnimationType(XYAnimation::RemovePointAnimation);
165 }
166
167 if(m_dirty) {
160 if(m_dirty) {
168 points = calculateGeometryPoints();
161 points = calculateGeometryPoints();
169 } else {
162 } else {
@@ -181,10 +174,6 void XYChart::handlePointReplaced(int index)
181
174
182 QVector<QPointF> points;
175 QVector<QPointF> points;
183
176
184 if(m_animation) {
185 m_animation->setAnimationType(XYAnimation::ReplacePointAnimation);
186 }
187
188 if(m_dirty) {
177 if(m_dirty) {
189 points = calculateGeometryPoints();
178 points = calculateGeometryPoints();
190 } else {
179 } else {
@@ -206,10 +195,6 void XYChart::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY
206
195
207 QVector<QPointF> points = calculateGeometryPoints();
196 QVector<QPointF> points = calculateGeometryPoints();
208
197
209 if(m_animation) {
210 m_animation->setAnimationType(XYAnimation::ReplacePointAnimation);
211 }
212
213 updateChart(m_points,points);
198 updateChart(m_points,points);
214 }
199 }
215
200
@@ -224,10 +209,6 void XYChart::handleGeometryChanged(const QRectF &rect)
224
209
225 QVector<QPointF> points = calculateGeometryPoints();
210 QVector<QPointF> points = calculateGeometryPoints();
226
211
227 if(m_animation) {
228 m_animation->setAnimationType(XYAnimation::NewAnimation);
229 }
230
231 updateChart(m_points,points);
212 updateChart(m_points,points);
232 }
213 }
233
214
@@ -65,7 +65,7 Q_SIGNALS:
65 void clicked(const QPointF& point);
65 void clicked(const QPointF& point);
66
66
67 protected:
67 protected:
68 virtual void updateChart(QVector<QPointF> &oldPoints,QVector<QPointF> &newPoints,int index = 0);
68 virtual void updateChart(QVector<QPointF> &oldPoints,QVector<QPointF> &newPoints,int index = -1);
69 QPointF calculateGeometryPoint(const QPointF &point) const;
69 QPointF calculateGeometryPoint(const QPointF &point) const;
70 QPointF calculateGeometryPoint(int index) const;
70 QPointF calculateGeometryPoint(int index) const;
71 QPointF calculateDomainPoint(const QPointF &point) const;
71 QPointF calculateDomainPoint(const QPointF &point) const;
General Comments 0
You need to be logged in to leave comments. Login now