summaryrefslogtreecommitdiffstats
path: root/src/animations/axisanimation.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/animations/axisanimation.cpp')
-rw-r--r--src/animations/axisanimation.cpp75
1 files changed, 74 insertions, 1 deletions
diff --git a/src/animations/axisanimation.cpp b/src/animations/axisanimation.cpp
index 9f694ed4..e27cf1cc 100644
--- a/src/animations/axisanimation.cpp
+++ b/src/animations/axisanimation.cpp
@@ -19,7 +19,9 @@
****************************************************************************/
#include "axisanimation_p.h"
+#include "chartaxis_p.h"
#include <QTimer>
+#include <QDebug>
Q_DECLARE_METATYPE(QVector<qreal>)
@@ -27,14 +29,84 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE
AxisAnimation::AxisAnimation(ChartAxis *axis): ChartAnimation(axis),
- m_axis(axis)
+ m_axis(axis),
+ m_type(DefaultAnimation)
{
+ setDuration(ChartAnimationDuration);
+ setEasingCurve(QEasingCurve::OutQuart);
}
AxisAnimation::~AxisAnimation()
{
}
+void AxisAnimation::setAnimationType(Animation type)
+{
+ if (state() != QAbstractAnimation::Stopped) stop();
+ m_type=type;
+}
+
+void AxisAnimation::setAnimationPoint(const QPointF& point)
+{
+ if (state() != QAbstractAnimation::Stopped) stop();
+ m_point=point;
+}
+
+void AxisAnimation::setValues(QVector<qreal> &oldLayout, QVector<qreal> &newLayout)
+{
+ if (state() != QAbstractAnimation::Stopped) stop();
+
+ if (newLayout.count() == 0)
+ return;
+
+ switch (m_type) {
+ case ZoomOutAnimation: {
+ QRectF rect = m_axis->geometry();
+ oldLayout.resize(newLayout.count());
+
+ for(int i = 0, j = oldLayout.count() - 1; i < (oldLayout.count() + 1) / 2; ++i, --j) {
+ oldLayout[i] = m_axis->axisType() == ChartAxis::X_AXIS ? rect.left() : rect.bottom();
+ oldLayout[j] = m_axis->axisType() == ChartAxis::X_AXIS ? rect.right() : rect.top();
+ }
+ }
+ break;
+ case ZoomInAnimation: {
+ int index = qMin(oldLayout.count() * (m_axis->axisType() == ChartAxis::X_AXIS ? m_point.x() : (1 - m_point.y())), newLayout.count() - 1.0);
+ oldLayout.resize(newLayout.count());
+
+ for(int i = 0; i < oldLayout.count(); i++)
+ oldLayout[i]= oldLayout[index];
+ }
+ break;
+ case MoveForwardAnimation: {
+ oldLayout.resize(newLayout.count());
+
+ for(int i = 0, j = i + 1; i < oldLayout.count() - 1; ++i, ++j)
+ oldLayout[i]= oldLayout[j];
+ }
+ break;
+ case MoveBackwordAnimation: {
+ oldLayout.resize(newLayout.count());
+
+ for(int i = oldLayout.count() - 1, j = i - 1; i > 0; --i, --j)
+ oldLayout[i]= oldLayout[j];
+ }
+ break;
+ default: {
+ oldLayout.resize(newLayout.count());
+ QRectF rect = m_axis->geometry();
+ for(int i = 0, j = oldLayout.count() - 1; i < oldLayout.count(); ++i, --j)
+ oldLayout[i] = m_axis->axisType() == ChartAxis::X_AXIS ? rect.left() : rect.top();
+ }
+ break;
+ }
+
+ QVariantAnimation::KeyValues value;
+ setKeyValues(value); //workaround for wrong interpolation call
+ setKeyValueAt(0.0, qVariantFromValue(oldLayout));
+ setKeyValueAt(1.0, qVariantFromValue(newLayout));
+}
+
QVariant AxisAnimation::interpolated(const QVariant &start, const QVariant &end, qreal progress ) const
{
QVector<qreal> startVector = qVariantValue<QVector<qreal> >(start);
@@ -58,6 +130,7 @@ void AxisAnimation::updateCurrentValue (const QVariant &value )
QVector<qreal> vector = qVariantValue<QVector<qreal> >(value);
Q_ASSERT(vector.count() != 0);
m_axis->setLayout(vector);
+ m_axis->updateGeometry();
}
}