@@ -1,61 +1,73 | |||||
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 "baranimation_p.h" |
|
21 | #include "baranimation_p.h" | |
22 | #include "abstractbarchartitem_p.h" |
|
22 | #include "abstractbarchartitem_p.h" | |
23 | #include <QTimer> |
|
23 | #include <QTimer> | |
24 |
|
24 | |||
25 | Q_DECLARE_METATYPE(QVector<QRectF>) |
|
25 | Q_DECLARE_METATYPE(QVector<QRectF>) | |
26 |
|
26 | |||
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
28 |
|
28 | |||
29 | BarAnimation::BarAnimation(AbstractBarChartItem *item) |
|
29 | BarAnimation::BarAnimation(AbstractBarChartItem *item) | |
30 | :AbstractBarAnimation(item) |
|
30 | :AbstractBarAnimation(item) | |
31 | { |
|
31 | { | |
32 |
|
32 | |||
33 | } |
|
33 | } | |
34 |
|
34 | |||
35 | BarAnimation::~BarAnimation() |
|
35 | BarAnimation::~BarAnimation() | |
36 | { |
|
36 | { | |
37 | } |
|
37 | } | |
38 |
|
38 | |||
39 | QVariant BarAnimation::interpolated(const QVariant &from, const QVariant &to, qreal progress) const |
|
39 | QVariant BarAnimation::interpolated(const QVariant &from, const QVariant &to, qreal progress) const | |
40 | { |
|
40 | { | |
41 | QVector<QRectF> startVector = qVariantValue<QVector<QRectF> >(from); |
|
41 | QVector<QRectF> startVector = qVariantValue<QVector<QRectF> >(from); | |
42 | QVector<QRectF> endVector = qVariantValue<QVector<QRectF> >(to); |
|
42 | QVector<QRectF> endVector = qVariantValue<QVector<QRectF> >(to); | |
43 | QVector<QRectF> result; |
|
43 | QVector<QRectF> result; | |
44 |
|
44 | |||
45 | Q_ASSERT(startVector.count() == endVector.count()); |
|
45 | Q_ASSERT(startVector.count() == endVector.count()); | |
46 |
|
46 | |||
47 | for(int i = 0; i < startVector.count(); i++) { |
|
47 | for(int i = 0; i < startVector.count(); i++) { | |
48 |
|
|
48 | QRectF start = startVector[i].normalized(); | |
49 | qreal h = startVector[i].height() + ((endVector[i].height() - startVector[i].height()) * progress); |
|
49 | QRectF end = endVector[i].normalized(); | |
50 | qreal x = endVector[i].topLeft().x(); |
|
50 | ||
51 | qreal y = endVector[i].topLeft().y() + endVector[i].height() - h; |
|
51 | qreal x = end.left(); | |
|
52 | qreal y; | |||
|
53 | qreal w = end.width(); | |||
|
54 | qreal h; | |||
|
55 | ||||
|
56 | if (endVector[i].height() < 0) { | |||
|
57 | // Negative bar | |||
|
58 | y = end.top(); | |||
|
59 | h = start.height() + ((end.height() - start.height()) * progress); | |||
|
60 | } else { | |||
|
61 | h = startVector[i].height() + ((endVector[i].height() - startVector[i].height()) * progress); | |||
|
62 | y = endVector[i].top() + endVector[i].height() - h; | |||
|
63 | } | |||
52 |
|
64 | |||
53 | QRectF value(x,y,w,h); |
|
65 | QRectF value(x,y,w,h); | |
54 | result << value.normalized(); |
|
66 | result << value.normalized(); | |
55 | } |
|
67 | } | |
56 | return qVariantFromValue(result); |
|
68 | return qVariantFromValue(result); | |
57 | } |
|
69 | } | |
58 |
|
70 | |||
59 | #include "moc_baranimation_p.cpp" |
|
71 | #include "moc_baranimation_p.cpp" | |
60 |
|
72 | |||
61 | QTCOMMERCIALCHART_END_NAMESPACE |
|
73 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,62 +1,74 | |||||
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 "horizontalbaranimation_p.h" |
|
21 | #include "horizontalbaranimation_p.h" | |
22 | #include "abstractbarchartitem_p.h" |
|
22 | #include "abstractbarchartitem_p.h" | |
23 | #include <QTimer> |
|
23 | #include <QTimer> | |
24 |
|
24 | |||
25 | Q_DECLARE_METATYPE(QVector<QRectF>) |
|
25 | Q_DECLARE_METATYPE(QVector<QRectF>) | |
26 |
|
26 | |||
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
28 |
|
28 | |||
29 | HorizontalBarAnimation::HorizontalBarAnimation(AbstractBarChartItem *item) : |
|
29 | HorizontalBarAnimation::HorizontalBarAnimation(AbstractBarChartItem *item) : | |
30 | AbstractBarAnimation(item) |
|
30 | AbstractBarAnimation(item) | |
31 | { |
|
31 | { | |
32 | } |
|
32 | } | |
33 |
|
33 | |||
34 | HorizontalBarAnimation::~HorizontalBarAnimation() |
|
34 | HorizontalBarAnimation::~HorizontalBarAnimation() | |
35 | { |
|
35 | { | |
36 |
|
36 | |||
37 | } |
|
37 | } | |
38 |
|
38 | |||
39 |
|
39 | |||
40 | QVariant HorizontalBarAnimation::interpolated(const QVariant &from, const QVariant &to, qreal progress) const |
|
40 | QVariant HorizontalBarAnimation::interpolated(const QVariant &from, const QVariant &to, qreal progress) const | |
41 | { |
|
41 | { | |
42 | QVector<QRectF> startVector = qVariantValue<QVector<QRectF> >(from); |
|
42 | QVector<QRectF> startVector = qVariantValue<QVector<QRectF> >(from); | |
43 | QVector<QRectF> endVector = qVariantValue<QVector<QRectF> >(to); |
|
43 | QVector<QRectF> endVector = qVariantValue<QVector<QRectF> >(to); | |
44 | QVector<QRectF> result; |
|
44 | QVector<QRectF> result; | |
45 |
|
45 | |||
46 | Q_ASSERT(startVector.count() == endVector.count()); |
|
46 | Q_ASSERT(startVector.count() == endVector.count()); | |
47 |
|
47 | |||
48 | for(int i = 0; i < startVector.count(); i++) { |
|
48 | for(int i = 0; i < startVector.count(); i++) { | |
49 | qreal h = endVector[i].height(); |
|
49 | QRectF start = startVector[i].normalized(); | |
50 | qreal w = startVector[i].width() + ((endVector[i].width() - startVector[i].width()) * progress); |
|
50 | QRectF end = endVector[i].normalized(); | |
51 | qreal x = endVector[i].left(); |
|
51 | ||
52 | qreal y = endVector[i].top(); |
|
52 | qreal x; | |
|
53 | qreal y = end.top(); | |||
|
54 | qreal w; | |||
|
55 | qreal h = end.height(); | |||
|
56 | ||||
|
57 | if (endVector[i].width() < 0) { | |||
|
58 | // Negative bar | |||
|
59 | w = start.width() + ((end.width() - start.width()) * progress); | |||
|
60 | x = endVector[i].right() - endVector[i].width() - w; | |||
|
61 | } else { | |||
|
62 | w = startVector[i].width() + ((endVector[i].width() - startVector[i].width()) * progress); | |||
|
63 | x = end.left(); | |||
|
64 | } | |||
53 |
|
65 | |||
54 | QRectF value(x,y,w,h); |
|
66 | QRectF value(x,y,w,h); | |
55 | result << value.normalized(); |
|
67 | result << value.normalized(); | |
56 | } |
|
68 | } | |
57 | return qVariantFromValue(result); |
|
69 | return qVariantFromValue(result); | |
58 | } |
|
70 | } | |
59 |
|
71 | |||
60 | #include "moc_horizontalbaranimation_p.cpp" |
|
72 | #include "moc_horizontalbaranimation_p.cpp" | |
61 |
|
73 | |||
62 | QTCOMMERCIALCHART_END_NAMESPACE |
|
74 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now