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