@@ -1,141 +1,138 | |||
|
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 "axisanimation_p.h" |
|
22 | 22 | #include "chartaxis_p.h" |
|
23 | #include "chartpresenter_p.h" | |
|
24 | #include <QTimer> | |
|
25 | #include <QDebug> | |
|
26 | 23 | |
|
27 | 24 | Q_DECLARE_METATYPE(QVector<qreal>) |
|
28 | 25 | |
|
29 | 26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | 27 | |
|
31 | 28 | |
|
32 | 29 | AxisAnimation::AxisAnimation(ChartAxis *axis) |
|
33 | 30 | : ChartAnimation(axis), |
|
34 | 31 | m_axis(axis), |
|
35 | 32 | m_type(DefaultAnimation) |
|
36 | 33 | { |
|
37 | 34 | setDuration(ChartAnimationDuration); |
|
38 | 35 | setEasingCurve(QEasingCurve::OutQuart); |
|
39 | 36 | } |
|
40 | 37 | |
|
41 | 38 | AxisAnimation::~AxisAnimation() |
|
42 | 39 | { |
|
43 | 40 | } |
|
44 | 41 | |
|
45 | 42 | void AxisAnimation::setAnimationType(Animation type) |
|
46 | 43 | { |
|
47 | 44 | if (state() != QAbstractAnimation::Stopped) |
|
48 | 45 | stop(); |
|
49 | 46 | m_type = type; |
|
50 | 47 | } |
|
51 | 48 | |
|
52 | 49 | void AxisAnimation::setAnimationPoint(const QPointF &point) |
|
53 | 50 | { |
|
54 | 51 | if (state() != QAbstractAnimation::Stopped) |
|
55 | 52 | stop(); |
|
56 | 53 | m_point = point; |
|
57 | 54 | } |
|
58 | 55 | |
|
59 | 56 | void AxisAnimation::setValues(QVector<qreal> &oldLayout, QVector<qreal> &newLayout) |
|
60 | 57 | { |
|
61 | 58 | if (state() != QAbstractAnimation::Stopped) stop(); |
|
62 | 59 | |
|
63 | 60 | if (newLayout.count() == 0) |
|
64 | 61 | return; |
|
65 | 62 | |
|
66 | 63 | switch (m_type) { |
|
67 | 64 | case ZoomOutAnimation: { |
|
68 | 65 | QRectF rect = m_axis->gridGeometry(); |
|
69 | 66 | oldLayout.resize(newLayout.count()); |
|
70 | 67 | |
|
71 | 68 | for (int i = 0, j = oldLayout.count() - 1; i < (oldLayout.count() + 1) / 2; ++i, --j) { |
|
72 | 69 | oldLayout[i] = m_axis->orientation() == Qt::Horizontal ? rect.left() : rect.bottom(); |
|
73 | 70 | oldLayout[j] = m_axis->orientation() == Qt::Horizontal ? rect.right() : rect.top(); |
|
74 | 71 | } |
|
75 | 72 | } |
|
76 | 73 | break; |
|
77 | 74 | case ZoomInAnimation: { |
|
78 | 75 | int index = qMin(oldLayout.count() * (m_axis->orientation() == Qt::Horizontal ? m_point.x() : (1 - m_point.y())), newLayout.count() - (qreal)1.0); |
|
79 | 76 | oldLayout.resize(newLayout.count()); |
|
80 | 77 | |
|
81 | 78 | for (int i = 0; i < oldLayout.count(); i++) |
|
82 | 79 | oldLayout[i] = oldLayout[index]; |
|
83 | 80 | } |
|
84 | 81 | break; |
|
85 | 82 | case MoveForwardAnimation: { |
|
86 | 83 | oldLayout.resize(newLayout.count()); |
|
87 | 84 | |
|
88 | 85 | for (int i = 0, j = i + 1; i < oldLayout.count() - 1; ++i, ++j) |
|
89 | 86 | oldLayout[i] = oldLayout[j]; |
|
90 | 87 | } |
|
91 | 88 | break; |
|
92 | 89 | case MoveBackwordAnimation: { |
|
93 | 90 | oldLayout.resize(newLayout.count()); |
|
94 | 91 | |
|
95 | 92 | for (int i = oldLayout.count() - 1, j = i - 1; i > 0; --i, --j) |
|
96 | 93 | oldLayout[i] = oldLayout[j]; |
|
97 | 94 | } |
|
98 | 95 | break; |
|
99 | 96 | default: { |
|
100 | 97 | oldLayout.resize(newLayout.count()); |
|
101 | 98 | QRectF rect = m_axis->gridGeometry(); |
|
102 | 99 | for (int i = 0, j = oldLayout.count() - 1; i < oldLayout.count(); ++i, --j) |
|
103 | 100 | oldLayout[i] = m_axis->orientation() == Qt::Horizontal ? rect.left() : rect.top(); |
|
104 | 101 | } |
|
105 | 102 | break; |
|
106 | 103 | } |
|
107 | 104 | |
|
108 | 105 | QVariantAnimation::KeyValues value; |
|
109 | 106 | setKeyValues(value); //workaround for wrong interpolation call |
|
110 | 107 | setKeyValueAt(0.0, qVariantFromValue(oldLayout)); |
|
111 | 108 | setKeyValueAt(1.0, qVariantFromValue(newLayout)); |
|
112 | 109 | } |
|
113 | 110 | |
|
114 | 111 | QVariant AxisAnimation::interpolated(const QVariant &start, const QVariant &end, qreal progress) const |
|
115 | 112 | { |
|
116 | 113 | QVector<qreal> startVector = qvariant_cast<QVector<qreal> >(start); |
|
117 | 114 | QVector<qreal> endVecotr = qvariant_cast<QVector<qreal> >(end); |
|
118 | 115 | QVector<qreal> result; |
|
119 | 116 | |
|
120 | 117 | Q_ASSERT(startVector.count() == endVecotr.count()) ; |
|
121 | 118 | |
|
122 | 119 | for (int i = 0; i < startVector.count(); i++) { |
|
123 | 120 | qreal value = startVector[i] + ((endVecotr[i] - startVector[i]) * progress); //qBound(0.0, progress, 1.0)); |
|
124 | 121 | result << value; |
|
125 | 122 | } |
|
126 | 123 | return qVariantFromValue(result); |
|
127 | 124 | } |
|
128 | 125 | |
|
129 | 126 | |
|
130 | 127 | void AxisAnimation::updateCurrentValue(const QVariant &value) |
|
131 | 128 | { |
|
132 | 129 | if (state() != QAbstractAnimation::Stopped) { //workaround |
|
133 | 130 | QVector<qreal> vector = qvariant_cast<QVector<qreal> >(value); |
|
134 | 131 | Q_ASSERT(vector.count() != 0); |
|
135 | 132 | m_axis->setLayout(vector); |
|
136 | 133 | m_axis->updateGeometry(); |
|
137 | 134 | } |
|
138 | 135 | |
|
139 | 136 | } |
|
140 | 137 | |
|
141 | 138 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,80 +1,79 | |||
|
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 "baranimation_p.h" |
|
22 | 22 | #include "abstractbarchartitem_p.h" |
|
23 | #include <QTimer> | |
|
24 | 23 | |
|
25 | 24 | Q_DECLARE_METATYPE(QVector<QRectF>) |
|
26 | 25 | |
|
27 | 26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | 27 | |
|
29 | 28 | BarAnimation::BarAnimation(AbstractBarChartItem *item) |
|
30 | 29 | : ChartAnimation(item), |
|
31 | 30 | m_item(item) |
|
32 | 31 | { |
|
33 | 32 | setDuration(ChartAnimationDuration); |
|
34 | 33 | setEasingCurve(QEasingCurve::OutQuart); |
|
35 | 34 | } |
|
36 | 35 | |
|
37 | 36 | BarAnimation::~BarAnimation() |
|
38 | 37 | { |
|
39 | 38 | } |
|
40 | 39 | |
|
41 | 40 | QVariant BarAnimation::interpolated(const QVariant &from, const QVariant &to, qreal progress) const |
|
42 | 41 | { |
|
43 | 42 | QVector<QRectF> startVector = qvariant_cast<QVector<QRectF> >(from); |
|
44 | 43 | QVector<QRectF> endVector = qvariant_cast<QVector<QRectF> >(to); |
|
45 | 44 | QVector<QRectF> result; |
|
46 | 45 | |
|
47 | 46 | Q_ASSERT(startVector.count() == endVector.count()); |
|
48 | 47 | |
|
49 | 48 | for (int i = 0; i < startVector.count(); i++) { |
|
50 | 49 | QRectF start = startVector[i].normalized(); |
|
51 | 50 | QRectF end = endVector[i].normalized(); |
|
52 | 51 | qreal x1 = start.left() + progress * (end.left() - start.left()); |
|
53 | 52 | qreal x2 = start.right() + progress * (end.right() - start.right()); |
|
54 | 53 | qreal y1 = start.top() + progress * (end.top() - start.top()); |
|
55 | 54 | qreal y2 = start.bottom() + progress * (end.bottom() - start.bottom()); |
|
56 | 55 | |
|
57 | 56 | QRectF value(QPointF(x1, y1), QPointF(x2, y2)); |
|
58 | 57 | result << value.normalized(); |
|
59 | 58 | } |
|
60 | 59 | return qVariantFromValue(result); |
|
61 | 60 | } |
|
62 | 61 | |
|
63 | 62 | void BarAnimation::updateCurrentValue(const QVariant &value) |
|
64 | 63 | { |
|
65 | 64 | QVector<QRectF> layout = qvariant_cast<QVector<QRectF> >(value); |
|
66 | 65 | m_item->setLayout(layout); |
|
67 | 66 | } |
|
68 | 67 | |
|
69 | 68 | void BarAnimation::setup(const QVector<QRectF> &oldLayout, const QVector<QRectF> &newLayout) |
|
70 | 69 | { |
|
71 | 70 | QVariantAnimation::KeyValues value; |
|
72 | 71 | setKeyValues(value); //workaround for wrong interpolation call |
|
73 | 72 | setKeyValueAt(0.0, qVariantFromValue(oldLayout)); |
|
74 | 73 | setKeyValueAt(1.0, qVariantFromValue(newLayout)); |
|
75 | 74 | } |
|
76 | 75 | |
|
77 | 76 | #include "moc_baranimation_p.cpp" |
|
78 | 77 | |
|
79 | 78 | QTCOMMERCIALCHART_END_NAMESPACE |
|
80 | 79 |
@@ -1,59 +1,59 | |||
|
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 | // W A R N I N G |
|
22 | 22 | // ------------- |
|
23 | 23 | // |
|
24 | 24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
25 | 25 | // implementation detail. This header file may change from version to |
|
26 | 26 | // version without notice, or even be removed. |
|
27 | 27 | // |
|
28 | 28 | // We mean it. |
|
29 | 29 | |
|
30 |
#ifndef |
|
|
31 |
#define |
|
|
30 | #ifndef BARANIMATION_P_H | |
|
31 | #define BARANIMATION_P_H | |
|
32 | 32 | |
|
33 | 33 | #include "chartanimation_p.h" |
|
34 | 34 | |
|
35 | 35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
36 | 36 | |
|
37 | 37 | class AbstractBarChartItem; |
|
38 | 38 | |
|
39 | 39 | class BarAnimation : public ChartAnimation |
|
40 | 40 | { |
|
41 | 41 | Q_OBJECT |
|
42 | 42 | |
|
43 | 43 | public: |
|
44 | 44 | BarAnimation(AbstractBarChartItem *item); |
|
45 | 45 | ~BarAnimation(); |
|
46 | 46 | |
|
47 | 47 | public: // from QVariantAnimation |
|
48 | 48 | virtual QVariant interpolated(const QVariant &from, const QVariant &to, qreal progress) const; |
|
49 | 49 | virtual void updateCurrentValue(const QVariant &value); |
|
50 | 50 | |
|
51 | 51 | void setup(const QVector<QRectF> &oldLayout, const QVector<QRectF> &newLayout); |
|
52 | 52 | |
|
53 | 53 | protected: |
|
54 | 54 | AbstractBarChartItem *m_item; |
|
55 | 55 | }; |
|
56 | 56 | |
|
57 | 57 | QTCOMMERCIALCHART_END_NAMESPACE |
|
58 | 58 | |
|
59 |
#endif // |
|
|
59 | #endif // BARANIMATION_P_H |
@@ -1,107 +1,106 | |||
|
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 "pieanimation_p.h" |
|
22 | 22 | #include "piesliceanimation_p.h" |
|
23 | 23 | #include "piechartitem_p.h" |
|
24 | #include <QTimer> | |
|
25 | 24 | |
|
26 | 25 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | 26 | |
|
28 | 27 | PieAnimation::PieAnimation(PieChartItem *item) |
|
29 | 28 | : ChartAnimation(item), |
|
30 | 29 | m_item(item) |
|
31 | 30 | { |
|
32 | 31 | } |
|
33 | 32 | |
|
34 | 33 | PieAnimation::~PieAnimation() |
|
35 | 34 | { |
|
36 | 35 | } |
|
37 | 36 | |
|
38 | 37 | ChartAnimation *PieAnimation::updateValue(PieSliceItem *sliceItem, const PieSliceData &sliceData) |
|
39 | 38 | { |
|
40 | 39 | PieSliceAnimation *animation = m_animations.value(sliceItem); |
|
41 | 40 | Q_ASSERT(animation); |
|
42 | 41 | animation->stop(); |
|
43 | 42 | |
|
44 | 43 | animation->updateValue(sliceData); |
|
45 | 44 | animation->setDuration(ChartAnimationDuration); |
|
46 | 45 | animation->setEasingCurve(QEasingCurve::OutQuart); |
|
47 | 46 | |
|
48 | 47 | return animation; |
|
49 | 48 | } |
|
50 | 49 | |
|
51 | 50 | ChartAnimation *PieAnimation::addSlice(PieSliceItem *sliceItem, const PieSliceData &sliceData, bool startupAnimation) |
|
52 | 51 | { |
|
53 | 52 | PieSliceAnimation *animation = new PieSliceAnimation(sliceItem); |
|
54 | 53 | m_animations.insert(sliceItem, animation); |
|
55 | 54 | |
|
56 | 55 | PieSliceData startValue = sliceData; |
|
57 | 56 | startValue.m_radius = 0; |
|
58 | 57 | if (startupAnimation) |
|
59 | 58 | startValue.m_startAngle = 0; |
|
60 | 59 | else |
|
61 | 60 | startValue.m_startAngle = sliceData.m_startAngle + (sliceData.m_angleSpan / 2); |
|
62 | 61 | startValue.m_angleSpan = 0; |
|
63 | 62 | |
|
64 | 63 | if (sliceData.m_holeRadius > 0) |
|
65 | 64 | startValue.m_radius = sliceData.m_holeRadius; |
|
66 | 65 | |
|
67 | 66 | animation->setValue(startValue, sliceData); |
|
68 | 67 | animation->setDuration(ChartAnimationDuration); |
|
69 | 68 | animation->setEasingCurve(QEasingCurve::OutQuart); |
|
70 | 69 | |
|
71 | 70 | return animation; |
|
72 | 71 | } |
|
73 | 72 | |
|
74 | 73 | ChartAnimation *PieAnimation::removeSlice(PieSliceItem *sliceItem) |
|
75 | 74 | { |
|
76 | 75 | PieSliceAnimation *animation = m_animations.value(sliceItem); |
|
77 | 76 | Q_ASSERT(animation); |
|
78 | 77 | animation->stop(); |
|
79 | 78 | |
|
80 | 79 | PieSliceData endValue = animation->currentSliceValue(); |
|
81 | 80 | if (endValue.m_holeRadius > 0) |
|
82 | 81 | endValue.m_radius = endValue.m_holeRadius; |
|
83 | 82 | else |
|
84 | 83 | endValue.m_radius = 0; |
|
85 | 84 | endValue.m_startAngle = endValue.m_startAngle + endValue.m_angleSpan; |
|
86 | 85 | endValue.m_angleSpan = 0; |
|
87 | 86 | endValue.m_isLabelVisible = false; |
|
88 | 87 | |
|
89 | 88 | animation->updateValue(endValue); |
|
90 | 89 | animation->setDuration(ChartAnimationDuration); |
|
91 | 90 | animation->setEasingCurve(QEasingCurve::OutQuart); |
|
92 | 91 | |
|
93 | 92 | // PieSliceItem is the parent of PieSliceAnimation so the animation will be deleted as well.. |
|
94 | 93 | connect(animation, SIGNAL(finished()), sliceItem, SLOT(deleteLater())); |
|
95 | 94 | m_animations.remove(sliceItem); |
|
96 | 95 | |
|
97 | 96 | return animation; |
|
98 | 97 | } |
|
99 | 98 | |
|
100 | 99 | void PieAnimation::updateCurrentValue(const QVariant &) |
|
101 | 100 | { |
|
102 | 101 | // nothing to do... |
|
103 | 102 | } |
|
104 | 103 | |
|
105 | 104 | #include "moc_pieanimation_p.cpp" |
|
106 | 105 | |
|
107 | 106 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now