##// END OF EJS Templates
Namespace fix for piesliceanimation
Jani Honkonen -
r821:656d67e7f6bb
parent child
Show More
@@ -1,127 +1,127
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "piesliceanimation_p.h"
21 #include "piesliceanimation_p.h"
22 #include "piechartitem_p.h"
22 #include "piechartitem_p.h"
23 #include "qpieslice.h"
23 #include "qpieslice.h"
24
24
25 Q_DECLARE_METATYPE(QtCommercialChart::PieSliceData)
25 Q_DECLARE_METATYPE(QTCOMMERCIALCHART_NAMESPACE::PieSliceData)
26
26
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28
28
29 qreal linearPos(qreal start, qreal end, qreal pos)
29 qreal linearPos(qreal start, qreal end, qreal pos)
30 {
30 {
31 return start + ((end - start) * pos);
31 return start + ((end - start) * pos);
32 }
32 }
33
33
34 QPointF linearPos(QPointF start, QPointF end, qreal pos)
34 QPointF linearPos(QPointF start, QPointF end, qreal pos)
35 {
35 {
36 qreal x = linearPos(start.x(), end.x(), pos);
36 qreal x = linearPos(start.x(), end.x(), pos);
37 qreal y = linearPos(start.y(), end.y(), pos);
37 qreal y = linearPos(start.y(), end.y(), pos);
38 return QPointF(x, y);
38 return QPointF(x, y);
39 }
39 }
40
40
41 QPen linearPos(QPen start, QPen end, qreal pos)
41 QPen linearPos(QPen start, QPen end, qreal pos)
42 {
42 {
43 QColor c;
43 QColor c;
44 c.setRedF(linearPos(start.color().redF(), end.color().redF(), pos));
44 c.setRedF(linearPos(start.color().redF(), end.color().redF(), pos));
45 c.setGreenF(linearPos(start.color().greenF(), end.color().greenF(), pos));
45 c.setGreenF(linearPos(start.color().greenF(), end.color().greenF(), pos));
46 c.setBlueF(linearPos(start.color().blueF(), end.color().blueF(), pos));
46 c.setBlueF(linearPos(start.color().blueF(), end.color().blueF(), pos));
47 end.setColor(c);
47 end.setColor(c);
48 return end;
48 return end;
49 }
49 }
50
50
51 QBrush linearPos(QBrush start, QBrush end, qreal pos)
51 QBrush linearPos(QBrush start, QBrush end, qreal pos)
52 {
52 {
53 QColor c;
53 QColor c;
54 c.setRedF(linearPos(start.color().redF(), end.color().redF(), pos));
54 c.setRedF(linearPos(start.color().redF(), end.color().redF(), pos));
55 c.setGreenF(linearPos(start.color().greenF(), end.color().greenF(), pos));
55 c.setGreenF(linearPos(start.color().greenF(), end.color().greenF(), pos));
56 c.setBlueF(linearPos(start.color().blueF(), end.color().blueF(), pos));
56 c.setBlueF(linearPos(start.color().blueF(), end.color().blueF(), pos));
57 end.setColor(c);
57 end.setColor(c);
58 return end;
58 return end;
59 }
59 }
60
60
61 PieSliceAnimation::PieSliceAnimation(PieChartItem *item, QPieSlice *slice)
61 PieSliceAnimation::PieSliceAnimation(PieChartItem *item, QPieSlice *slice)
62 :QVariantAnimation(item),
62 :QVariantAnimation(item),
63 m_item(item),
63 m_item(item),
64 m_slice(slice)
64 m_slice(slice)
65 {
65 {
66 }
66 }
67
67
68 PieSliceAnimation::~PieSliceAnimation()
68 PieSliceAnimation::~PieSliceAnimation()
69 {
69 {
70 }
70 }
71
71
72 void PieSliceAnimation::setValue(const PieSliceData &startValue, const PieSliceData &endValue)
72 void PieSliceAnimation::setValue(const PieSliceData &startValue, const PieSliceData &endValue)
73 {
73 {
74 if (state() != QAbstractAnimation::Stopped)
74 if (state() != QAbstractAnimation::Stopped)
75 stop();
75 stop();
76
76
77 m_currentValue = startValue;
77 m_currentValue = startValue;
78
78
79 setKeyValueAt(0.0, qVariantFromValue(startValue));
79 setKeyValueAt(0.0, qVariantFromValue(startValue));
80 setKeyValueAt(1.0, qVariantFromValue(endValue));
80 setKeyValueAt(1.0, qVariantFromValue(endValue));
81 }
81 }
82
82
83 void PieSliceAnimation::updateValue(const PieSliceData &endValue)
83 void PieSliceAnimation::updateValue(const PieSliceData &endValue)
84 {
84 {
85 if (state() != QAbstractAnimation::Stopped)
85 if (state() != QAbstractAnimation::Stopped)
86 stop();
86 stop();
87
87
88 setKeyValueAt(0.0, qVariantFromValue(m_currentValue));
88 setKeyValueAt(0.0, qVariantFromValue(m_currentValue));
89 setKeyValueAt(1.0, qVariantFromValue(endValue));
89 setKeyValueAt(1.0, qVariantFromValue(endValue));
90 }
90 }
91
91
92 PieSliceData PieSliceAnimation::currentSliceValue()
92 PieSliceData PieSliceAnimation::currentSliceValue()
93 {
93 {
94 // NOTE:
94 // NOTE:
95 // We must use an internal current value because QVariantAnimation::currentValue() is updated
95 // We must use an internal current value because QVariantAnimation::currentValue() is updated
96 // before the animation is actually started. So if we get 2 updateValue() calls in a row the currentValue()
96 // before the animation is actually started. So if we get 2 updateValue() calls in a row the currentValue()
97 // will have the end value set from the first call and the second call will interpolate that instead of
97 // will have the end value set from the first call and the second call will interpolate that instead of
98 // the original current value as it was before the first call.
98 // the original current value as it was before the first call.
99 return m_currentValue;
99 return m_currentValue;
100 }
100 }
101
101
102 QVariant PieSliceAnimation::interpolated(const QVariant &start, const QVariant &end, qreal progress) const
102 QVariant PieSliceAnimation::interpolated(const QVariant &start, const QVariant &end, qreal progress) const
103 {
103 {
104 PieSliceData startValue = qVariantValue<PieSliceData>(start);
104 PieSliceData startValue = qVariantValue<PieSliceData>(start);
105 PieSliceData endValue = qVariantValue<PieSliceData>(end);
105 PieSliceData endValue = qVariantValue<PieSliceData>(end);
106
106
107 PieSliceData result;
107 PieSliceData result;
108 result = endValue;
108 result = endValue;
109 result.m_center = linearPos(startValue.m_center, endValue.m_center, progress);
109 result.m_center = linearPos(startValue.m_center, endValue.m_center, progress);
110 result.m_radius = linearPos(startValue.m_radius, endValue.m_radius, progress);
110 result.m_radius = linearPos(startValue.m_radius, endValue.m_radius, progress);
111 result.m_startAngle = linearPos(startValue.m_startAngle, endValue.m_startAngle, progress);
111 result.m_startAngle = linearPos(startValue.m_startAngle, endValue.m_startAngle, progress);
112 result.m_angleSpan = linearPos(startValue.m_angleSpan, endValue.m_angleSpan, progress);
112 result.m_angleSpan = linearPos(startValue.m_angleSpan, endValue.m_angleSpan, progress);
113 result.m_slicePen = linearPos(startValue.m_slicePen, endValue.m_slicePen, progress);
113 result.m_slicePen = linearPos(startValue.m_slicePen, endValue.m_slicePen, progress);
114 result.m_sliceBrush = linearPos(startValue.m_sliceBrush, endValue.m_sliceBrush, progress);
114 result.m_sliceBrush = linearPos(startValue.m_sliceBrush, endValue.m_sliceBrush, progress);
115
115
116 return qVariantFromValue(result);
116 return qVariantFromValue(result);
117 }
117 }
118
118
119 void PieSliceAnimation::updateCurrentValue(const QVariant &value)
119 void PieSliceAnimation::updateCurrentValue(const QVariant &value)
120 {
120 {
121 if (state() != QAbstractAnimation::Stopped) { //workaround
121 if (state() != QAbstractAnimation::Stopped) { //workaround
122 m_currentValue = qVariantValue<PieSliceData>(value);
122 m_currentValue = qVariantValue<PieSliceData>(value);
123 m_item->setLayout(m_slice, m_currentValue);
123 m_item->setLayout(m_slice, m_currentValue);
124 }
124 }
125 }
125 }
126
126
127 QTCOMMERCIALCHART_END_NAMESPACE
127 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now