| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
| 4 | ** Contact: https://www.qt.io/licensing/ |
| 5 | ** |
| 6 | ** This file is part of the Qt Charts module of the Qt Toolkit. |
| 7 | ** |
| 8 | ** $QT_BEGIN_LICENSE:GPL$ |
| 9 | ** Commercial License Usage |
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
| 11 | ** accordance with the commercial license agreement provided with the |
| 12 | ** Software or, alternatively, in accordance with the terms contained in |
| 13 | ** a written agreement between you and The Qt Company. For licensing terms |
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
| 15 | ** information use the contact form at https://www.qt.io/contact-us. |
| 16 | ** |
| 17 | ** GNU General Public License Usage |
| 18 | ** Alternatively, this file may be used under the terms of the GNU |
| 19 | ** General Public License version 3 or (at your option) any later version |
| 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
| 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
| 22 | ** included in the packaging of this file. Please review the following |
| 23 | ** information to ensure the GNU General Public License requirements will |
| 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
| 25 | ** |
| 26 | ** $QT_END_LICENSE$ |
| 27 | ** |
| 28 | ****************************************************************************/ |
| 29 | |
| 30 | #include <private/baranimation_p.h> |
| 31 | #include <private/abstractbarchartitem_p.h> |
| 32 | |
| 33 | Q_DECLARE_METATYPE(QVector<QRectF>) |
| 34 | |
| 35 | QT_CHARTS_BEGIN_NAMESPACE |
| 36 | |
| 37 | BarAnimation::BarAnimation(AbstractBarChartItem *item, int duration, QEasingCurve &curve) |
| 38 | : ChartAnimation(item), |
| 39 | m_item(item) |
| 40 | { |
| 41 | setDuration(duration); |
| 42 | setEasingCurve(curve); |
| 43 | } |
| 44 | |
| 45 | BarAnimation::~BarAnimation() |
| 46 | { |
| 47 | } |
| 48 | |
| 49 | QVariant BarAnimation::interpolated(const QVariant &from, const QVariant &to, qreal progress) const |
| 50 | { |
| 51 | QVector<QRectF> startVector = qvariant_cast<QVector<QRectF> >(v: from); |
| 52 | QVector<QRectF> endVector = qvariant_cast<QVector<QRectF> >(v: to); |
| 53 | QVector<QRectF> result; |
| 54 | |
| 55 | Q_ASSERT(startVector.count() == endVector.count()); |
| 56 | |
| 57 | for (int i = 0; i < startVector.count(); i++) { |
| 58 | QRectF start = startVector[i].normalized(); |
| 59 | QRectF end = endVector[i].normalized(); |
| 60 | qreal x1 = start.left() + progress * (end.left() - start.left()); |
| 61 | qreal x2 = start.right() + progress * (end.right() - start.right()); |
| 62 | qreal y1 = start.top() + progress * (end.top() - start.top()); |
| 63 | qreal y2 = start.bottom() + progress * (end.bottom() - start.bottom()); |
| 64 | |
| 65 | QRectF value(QPointF(x1, y1), QPointF(x2, y2)); |
| 66 | result << value.normalized(); |
| 67 | } |
| 68 | return QVariant::fromValue(value: result); |
| 69 | } |
| 70 | |
| 71 | void BarAnimation::updateCurrentValue(const QVariant &value) |
| 72 | { |
| 73 | if (state() != QAbstractAnimation::Stopped) { //workaround |
| 74 | |
| 75 | QVector<QRectF> layout = qvariant_cast<QVector<QRectF> >(v: value); |
| 76 | m_item->setLayout(layout); |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | void BarAnimation::setup(const QVector<QRectF> &oldLayout, const QVector<QRectF> &newLayout) |
| 81 | { |
| 82 | QVariantAnimation::KeyValues value; |
| 83 | setKeyValues(value); //workaround for wrong interpolation call |
| 84 | setKeyValueAt(step: 0.0, value: QVariant::fromValue(value: oldLayout)); |
| 85 | setKeyValueAt(step: 1.0, value: QVariant::fromValue(value: newLayout)); |
| 86 | } |
| 87 | |
| 88 | QT_CHARTS_END_NAMESPACE |
| 89 | |
| 90 | #include "moc_baranimation_p.cpp" |
| 91 | |