@@ -1,79 +1,82 | |||
|
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 | 23 | |
|
24 | 24 | Q_DECLARE_METATYPE(QVector<QRectF>) |
|
25 | 25 | |
|
26 | 26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | 27 | |
|
28 | 28 | BarAnimation::BarAnimation(AbstractBarChartItem *item) |
|
29 | 29 | : ChartAnimation(item), |
|
30 | 30 | m_item(item) |
|
31 | 31 | { |
|
32 | 32 | setDuration(ChartAnimationDuration); |
|
33 | 33 | setEasingCurve(QEasingCurve::OutQuart); |
|
34 | 34 | } |
|
35 | 35 | |
|
36 | 36 | BarAnimation::~BarAnimation() |
|
37 | 37 | { |
|
38 | 38 | } |
|
39 | 39 | |
|
40 | 40 | QVariant BarAnimation::interpolated(const QVariant &from, const QVariant &to, qreal progress) const |
|
41 | 41 | { |
|
42 | 42 | QVector<QRectF> startVector = qvariant_cast<QVector<QRectF> >(from); |
|
43 | 43 | QVector<QRectF> endVector = qvariant_cast<QVector<QRectF> >(to); |
|
44 | 44 | QVector<QRectF> result; |
|
45 | 45 | |
|
46 | 46 | Q_ASSERT(startVector.count() == endVector.count()); |
|
47 | 47 | |
|
48 | 48 | for (int i = 0; i < startVector.count(); i++) { |
|
49 | 49 | QRectF start = startVector[i].normalized(); |
|
50 | 50 | QRectF end = endVector[i].normalized(); |
|
51 | 51 | qreal x1 = start.left() + progress * (end.left() - start.left()); |
|
52 | 52 | qreal x2 = start.right() + progress * (end.right() - start.right()); |
|
53 | 53 | qreal y1 = start.top() + progress * (end.top() - start.top()); |
|
54 | 54 | qreal y2 = start.bottom() + progress * (end.bottom() - start.bottom()); |
|
55 | 55 | |
|
56 | 56 | QRectF value(QPointF(x1, y1), QPointF(x2, y2)); |
|
57 | 57 | result << value.normalized(); |
|
58 | 58 | } |
|
59 | 59 | return qVariantFromValue(result); |
|
60 | 60 | } |
|
61 | 61 | |
|
62 | 62 | void BarAnimation::updateCurrentValue(const QVariant &value) |
|
63 | 63 | { |
|
64 | if (state() != QAbstractAnimation::Stopped) { //workaround | |
|
65 | ||
|
64 | 66 | QVector<QRectF> layout = qvariant_cast<QVector<QRectF> >(value); |
|
65 | 67 | m_item->setLayout(layout); |
|
66 | 68 | } |
|
69 | } | |
|
67 | 70 | |
|
68 | 71 | void BarAnimation::setup(const QVector<QRectF> &oldLayout, const QVector<QRectF> &newLayout) |
|
69 | 72 | { |
|
70 | 73 | QVariantAnimation::KeyValues value; |
|
71 | 74 | setKeyValues(value); //workaround for wrong interpolation call |
|
72 | 75 | setKeyValueAt(0.0, qVariantFromValue(oldLayout)); |
|
73 | 76 | setKeyValueAt(1.0, qVariantFromValue(newLayout)); |
|
74 | 77 | } |
|
75 | 78 | |
|
76 | 79 | #include "moc_baranimation_p.cpp" |
|
77 | 80 | |
|
78 | 81 | QTCOMMERCIALCHART_END_NAMESPACE |
|
79 | 82 |
General Comments 0
You need to be logged in to leave comments.
Login now