@@ -1,138 +1,140 | |||
|
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 | 23 | |
|
24 | 24 | Q_DECLARE_METATYPE(QVector<qreal>) |
|
25 | 25 | |
|
26 | 26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | 27 | |
|
28 | 28 | |
|
29 | 29 | AxisAnimation::AxisAnimation(ChartAxis *axis) |
|
30 | 30 | : ChartAnimation(axis), |
|
31 | 31 | m_axis(axis), |
|
32 | 32 | m_type(DefaultAnimation) |
|
33 | 33 | { |
|
34 | 34 | setDuration(ChartAnimationDuration); |
|
35 | 35 | setEasingCurve(QEasingCurve::OutQuart); |
|
36 | 36 | } |
|
37 | 37 | |
|
38 | 38 | AxisAnimation::~AxisAnimation() |
|
39 | 39 | { |
|
40 | 40 | } |
|
41 | 41 | |
|
42 | 42 | void AxisAnimation::setAnimationType(Animation type) |
|
43 | 43 | { |
|
44 | 44 | if (state() != QAbstractAnimation::Stopped) |
|
45 | 45 | stop(); |
|
46 | 46 | m_type = type; |
|
47 | 47 | } |
|
48 | 48 | |
|
49 | 49 | void AxisAnimation::setAnimationPoint(const QPointF &point) |
|
50 | 50 | { |
|
51 | 51 | if (state() != QAbstractAnimation::Stopped) |
|
52 | 52 | stop(); |
|
53 | 53 | m_point = point; |
|
54 | 54 | } |
|
55 | 55 | |
|
56 | 56 | void AxisAnimation::setValues(QVector<qreal> &oldLayout, QVector<qreal> &newLayout) |
|
57 | 57 | { |
|
58 | 58 | if (state() != QAbstractAnimation::Stopped) stop(); |
|
59 | 59 | |
|
60 | if (newLayout.count() == 0) | |
|
61 | return; | |
|
60 | // TODO: cannot return even if layout is empty | |
|
61 | // New layout is not set properly without it (crash) | |
|
62 | // if (newLayout.count() == 0) | |
|
63 | // return; | |
|
62 | 64 | |
|
63 | 65 | switch (m_type) { |
|
64 | 66 | case ZoomOutAnimation: { |
|
65 | 67 | QRectF rect = m_axis->gridGeometry(); |
|
66 | 68 | oldLayout.resize(newLayout.count()); |
|
67 | 69 | |
|
68 | 70 | for (int i = 0, j = oldLayout.count() - 1; i < (oldLayout.count() + 1) / 2; ++i, --j) { |
|
69 | 71 | oldLayout[i] = m_axis->orientation() == Qt::Horizontal ? rect.left() : rect.bottom(); |
|
70 | 72 | oldLayout[j] = m_axis->orientation() == Qt::Horizontal ? rect.right() : rect.top(); |
|
71 | 73 | } |
|
72 | 74 | } |
|
73 | 75 | break; |
|
74 | 76 | case ZoomInAnimation: { |
|
75 | 77 | int index = qMin(oldLayout.count() * (m_axis->orientation() == Qt::Horizontal ? m_point.x() : (1 - m_point.y())), newLayout.count() - (qreal)1.0); |
|
76 | 78 | oldLayout.resize(newLayout.count()); |
|
77 | 79 | |
|
78 | 80 | for (int i = 0; i < oldLayout.count(); i++) |
|
79 | 81 | oldLayout[i] = oldLayout[index]; |
|
80 | 82 | } |
|
81 | 83 | break; |
|
82 | 84 | case MoveForwardAnimation: { |
|
83 | 85 | oldLayout.resize(newLayout.count()); |
|
84 | 86 | |
|
85 | 87 | for (int i = 0, j = i + 1; i < oldLayout.count() - 1; ++i, ++j) |
|
86 | 88 | oldLayout[i] = oldLayout[j]; |
|
87 | 89 | } |
|
88 | 90 | break; |
|
89 | 91 | case MoveBackwordAnimation: { |
|
90 | 92 | oldLayout.resize(newLayout.count()); |
|
91 | 93 | |
|
92 | 94 | for (int i = oldLayout.count() - 1, j = i - 1; i > 0; --i, --j) |
|
93 | 95 | oldLayout[i] = oldLayout[j]; |
|
94 | 96 | } |
|
95 | 97 | break; |
|
96 | 98 | default: { |
|
97 | 99 | oldLayout.resize(newLayout.count()); |
|
98 | 100 | QRectF rect = m_axis->gridGeometry(); |
|
99 | 101 | for (int i = 0, j = oldLayout.count() - 1; i < oldLayout.count(); ++i, --j) |
|
100 | 102 | oldLayout[i] = m_axis->orientation() == Qt::Horizontal ? rect.left() : rect.top(); |
|
101 | 103 | } |
|
102 | 104 | break; |
|
103 | 105 | } |
|
104 | 106 | |
|
105 | 107 | QVariantAnimation::KeyValues value; |
|
106 | 108 | setKeyValues(value); //workaround for wrong interpolation call |
|
107 | 109 | setKeyValueAt(0.0, qVariantFromValue(oldLayout)); |
|
108 | 110 | setKeyValueAt(1.0, qVariantFromValue(newLayout)); |
|
109 | 111 | } |
|
110 | 112 | |
|
111 | 113 | QVariant AxisAnimation::interpolated(const QVariant &start, const QVariant &end, qreal progress) const |
|
112 | 114 | { |
|
113 | 115 | QVector<qreal> startVector = qvariant_cast<QVector<qreal> >(start); |
|
114 | 116 | QVector<qreal> endVecotr = qvariant_cast<QVector<qreal> >(end); |
|
115 | 117 | QVector<qreal> result; |
|
116 | 118 | |
|
117 | 119 | Q_ASSERT(startVector.count() == endVecotr.count()) ; |
|
118 | 120 | |
|
119 | 121 | for (int i = 0; i < startVector.count(); i++) { |
|
120 | 122 | qreal value = startVector[i] + ((endVecotr[i] - startVector[i]) * progress); //qBound(0.0, progress, 1.0)); |
|
121 | 123 | result << value; |
|
122 | 124 | } |
|
123 | 125 | return qVariantFromValue(result); |
|
124 | 126 | } |
|
125 | 127 | |
|
126 | 128 | |
|
127 | 129 | void AxisAnimation::updateCurrentValue(const QVariant &value) |
|
128 | 130 | { |
|
129 | 131 | if (state() != QAbstractAnimation::Stopped) { //workaround |
|
130 | 132 | QVector<qreal> vector = qvariant_cast<QVector<qreal> >(value); |
|
131 | Q_ASSERT(vector.count() != 0); | |
|
133 | // Q_ASSERT(vector.count() != 0); | |
|
132 | 134 | m_axis->setLayout(vector); |
|
133 | 135 | m_axis->updateGeometry(); |
|
134 | 136 | } |
|
135 | 137 | |
|
136 | 138 | } |
|
137 | 139 | |
|
138 | 140 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now