1 | // Copyright (C) 2016 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
3 | |
4 | #include <private/baranimation_p.h> |
5 | #include <private/abstractbarchartitem_p.h> |
6 | |
7 | |
8 | QT_BEGIN_NAMESPACE |
9 | |
10 | BarAnimation::BarAnimation(AbstractBarChartItem *item, int duration, QEasingCurve &curve) |
11 | : ChartAnimation(item), |
12 | m_item(item) |
13 | { |
14 | setDuration(duration); |
15 | setEasingCurve(curve); |
16 | } |
17 | |
18 | BarAnimation::~BarAnimation() |
19 | { |
20 | } |
21 | |
22 | QVariant BarAnimation::interpolated(const QVariant &from, const QVariant &to, qreal progress) const |
23 | { |
24 | const QList<QRectF> startList = qvariant_cast<QList<QRectF>>(v: from); |
25 | const QList<QRectF> endList = qvariant_cast<QList<QRectF>>(v: to); |
26 | QList<QRectF> result; |
27 | |
28 | Q_ASSERT(startList.size() == endList.size()); |
29 | |
30 | for (int i = 0; i < startList.size(); i++) { |
31 | const QRectF start = startList[i].normalized(); |
32 | const QRectF end = endList[i].normalized(); |
33 | const qreal x1 = start.left() + progress * (end.left() - start.left()); |
34 | const qreal x2 = start.right() + progress * (end.right() - start.right()); |
35 | const qreal y1 = start.top() + progress * (end.top() - start.top()); |
36 | const qreal y2 = start.bottom() + progress * (end.bottom() - start.bottom()); |
37 | |
38 | QRectF value(QPointF(x1, y1), QPointF(x2, y2)); |
39 | result << value.normalized(); |
40 | } |
41 | return QVariant::fromValue(value: result); |
42 | } |
43 | |
44 | void BarAnimation::updateCurrentValue(const QVariant &value) |
45 | { |
46 | if (state() != QAbstractAnimation::Stopped) { //workaround |
47 | |
48 | const QList<QRectF> layout = qvariant_cast<QList<QRectF>>(v: value); |
49 | m_item->setLayout(layout); |
50 | } |
51 | } |
52 | |
53 | void BarAnimation::setup(const QList<QRectF> &oldLayout, const QList<QRectF> &newLayout) |
54 | { |
55 | QVariantAnimation::KeyValues value; |
56 | setKeyValues(value); //workaround for wrong interpolation call |
57 | setKeyValueAt(step: 0.0, value: QVariant::fromValue(value: oldLayout)); |
58 | setKeyValueAt(step: 1.0, value: QVariant::fromValue(value: newLayout)); |
59 | } |
60 | |
61 | QT_END_NAMESPACE |
62 | |
63 | #include "moc_baranimation_p.cpp" |
64 | |