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