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