summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKnud Dollereder <knud.dollereder@qt.io>2019-08-27 14:02:48 +0200
committerKnud Dollereder <knud.dollereder@qt.io>2019-08-27 13:12:43 +0000
commitd17840ba92f09eb7e524865e9a8bcbb2ed177d02 (patch)
tree242b8eb7fc3c07f11dad0ce60a216b999fabc1d9
parent1d319876c87c7983075d0a2c44d0aceaa5c99e41 (diff)
downloadqt-creator-d17840ba92f09eb7e524865e9a8bcbb2ed177d02.tar.gz
Apply interpolation when restoring an animation-curve
+ Notify timeline when inserting a keyframe Change-Id: I91548c4e45306e9a6c6490cc94b88080de3910ac Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
-rw-r--r--src/plugins/qmldesigner/components/curveeditor/animationcurve.cpp17
-rw-r--r--src/plugins/qmldesigner/components/curveeditor/animationcurve.h2
-rw-r--r--src/plugins/qmldesigner/components/curveeditor/detail/curveitem.cpp10
-rw-r--r--src/plugins/qmldesigner/components/curveeditor/detail/curveitem.h4
-rw-r--r--src/plugins/qmldesigner/components/curveeditor/detail/graphicsscene.cpp2
-rw-r--r--src/plugins/qmldesigner/components/curveeditor/detail/keyframeitem.cpp5
-rw-r--r--src/plugins/qmldesigner/components/curveeditor/detail/keyframeitem.h2
-rw-r--r--src/plugins/qmldesigner/components/curveeditor/keyframe.cpp27
-rw-r--r--src/plugins/qmldesigner/components/curveeditor/keyframe.h15
9 files changed, 70 insertions, 14 deletions
diff --git a/src/plugins/qmldesigner/components/curveeditor/animationcurve.cpp b/src/plugins/qmldesigner/components/curveeditor/animationcurve.cpp
index bd11405bd2..5a849316b0 100644
--- a/src/plugins/qmldesigner/components/curveeditor/animationcurve.cpp
+++ b/src/plugins/qmldesigner/components/curveeditor/animationcurve.cpp
@@ -31,6 +31,8 @@
#include <QLineF>
#include <QPainterPath>
+#include <sstream>
+
namespace DesignTools {
AnimationCurve::AnimationCurve()
@@ -127,6 +129,21 @@ double AnimationCurve::maximumValue() const
return m_maxY;
}
+std::string AnimationCurve::string() const
+{
+ std::stringstream sstream;
+ sstream << "{ ";
+ for (size_t i = 0; i < m_frames.size(); ++i) {
+ if (i == m_frames.size() - 1)
+ sstream << m_frames[i].string();
+ else
+ sstream << m_frames[i].string() << ", ";
+ }
+ sstream << " }";
+
+ return sstream.str();
+}
+
CurveSegment AnimationCurve::segment(double time) const
{
CurveSegment seg;
diff --git a/src/plugins/qmldesigner/components/curveeditor/animationcurve.h b/src/plugins/qmldesigner/components/curveeditor/animationcurve.h
index fbd75594da..3122074bfe 100644
--- a/src/plugins/qmldesigner/components/curveeditor/animationcurve.h
+++ b/src/plugins/qmldesigner/components/curveeditor/animationcurve.h
@@ -58,6 +58,8 @@ public:
double maximumValue() const;
+ std::string string() const;
+
CurveSegment segment(double time) const;
std::vector<CurveSegment> segments() const;
diff --git a/src/plugins/qmldesigner/components/curveeditor/detail/curveitem.cpp b/src/plugins/qmldesigner/components/curveeditor/detail/curveitem.cpp
index faa3c320eb..a7eb612a29 100644
--- a/src/plugins/qmldesigner/components/curveeditor/detail/curveitem.cpp
+++ b/src/plugins/qmldesigner/components/curveeditor/detail/curveitem.cpp
@@ -34,6 +34,7 @@
#include <algorithm>
#include <cmath>
+#include <sstream>
namespace DesignTools {
@@ -251,9 +252,8 @@ void CurveItem::restore()
Keyframe curr = currItem->keyframe();
CurveSegment segment(prev, curr);
- segment.setInterpolation(segment.interpolation());
-
prevItem->setRightHandle(segment.left().rightHandle());
+ currItem->setInterpolation(segment.interpolation());
currItem->setLeftHandle(segment.right().leftHandle());
prevItem = currItem;
@@ -329,12 +329,12 @@ void CurveItem::setInterpolation(Keyframe::Interpolation interpolation)
segment.setInterpolation(interpolation);
prevItem->setKeyframe(segment.left());
currItem->setKeyframe(segment.right());
-
- setDirty(true);
}
prevItem = currItem;
}
+ setDirty(false);
+ emit curveChanged(id(), curve());
}
void CurveItem::connect(GraphicsScene *scene)
@@ -358,6 +358,8 @@ void CurveItem::insertKeyframeByTime(double time)
AnimationCurve acurve = curve();
acurve.insert(time);
setCurve(acurve);
+
+ emit curveChanged(id(), curve());
}
void CurveItem::deleteSelectedKeyframes()
diff --git a/src/plugins/qmldesigner/components/curveeditor/detail/curveitem.h b/src/plugins/qmldesigner/components/curveeditor/detail/curveitem.h
index a83b530463..146c303585 100644
--- a/src/plugins/qmldesigner/components/curveeditor/detail/curveitem.h
+++ b/src/plugins/qmldesigner/components/curveeditor/detail/curveitem.h
@@ -31,6 +31,7 @@
#include "selectableitem.h"
#include "treeitem.h"
+#include <string>
#include <QGraphicsObject>
namespace DesignTools {
@@ -43,6 +44,9 @@ class CurveItem : public QGraphicsObject
{
Q_OBJECT
+signals:
+ void curveChanged(unsigned int id, const AnimationCurve &curve);
+
public:
CurveItem(QGraphicsItem *parent = nullptr);
diff --git a/src/plugins/qmldesigner/components/curveeditor/detail/graphicsscene.cpp b/src/plugins/qmldesigner/components/curveeditor/detail/graphicsscene.cpp
index 42a7f1b8a8..d29bb84928 100644
--- a/src/plugins/qmldesigner/components/curveeditor/detail/graphicsscene.cpp
+++ b/src/plugins/qmldesigner/components/curveeditor/detail/graphicsscene.cpp
@@ -69,6 +69,8 @@ void GraphicsScene::addCurveItem(CurveItem *item)
m_dirty = true;
item->setDirty(false);
+ connect(item, &CurveItem::curveChanged, this, &GraphicsScene::curveChanged);
+
addItem(item);
item->connect(this);
}
diff --git a/src/plugins/qmldesigner/components/curveeditor/detail/keyframeitem.cpp b/src/plugins/qmldesigner/components/curveeditor/detail/keyframeitem.cpp
index 7bff004564..4640b3eb82 100644
--- a/src/plugins/qmldesigner/components/curveeditor/detail/keyframeitem.cpp
+++ b/src/plugins/qmldesigner/components/curveeditor/detail/keyframeitem.cpp
@@ -174,6 +174,11 @@ void KeyframeItem::setKeyframe(const Keyframe &keyframe)
setPos(m_transform.map(m_frame.position()));
}
+void KeyframeItem::setInterpolation(Keyframe::Interpolation interpolation)
+{
+ m_frame.setInterpolation(interpolation);
+}
+
void KeyframeItem::setLeftHandle(const QPointF &pos)
{
m_frame.setLeftHandle(pos);
diff --git a/src/plugins/qmldesigner/components/curveeditor/detail/keyframeitem.h b/src/plugins/qmldesigner/components/curveeditor/detail/keyframeitem.h
index 55109f435a..ea239af6fd 100644
--- a/src/plugins/qmldesigner/components/curveeditor/detail/keyframeitem.h
+++ b/src/plugins/qmldesigner/components/curveeditor/detail/keyframeitem.h
@@ -75,6 +75,8 @@ public:
void setKeyframe(const Keyframe &keyframe);
+ void setInterpolation(Keyframe::Interpolation interpolation);
+
void setLeftHandle(const QPointF &pos);
void setRightHandle(const QPointF &pos);
diff --git a/src/plugins/qmldesigner/components/curveeditor/keyframe.cpp b/src/plugins/qmldesigner/components/curveeditor/keyframe.cpp
index 4beea4b716..0ac23c3615 100644
--- a/src/plugins/qmldesigner/components/curveeditor/keyframe.cpp
+++ b/src/plugins/qmldesigner/components/curveeditor/keyframe.cpp
@@ -25,6 +25,8 @@
#include "keyframe.h"
+#include <sstream>
+
namespace DesignTools {
Keyframe::Keyframe()
@@ -101,6 +103,31 @@ QVariant Keyframe::data() const
return m_data;
}
+std::string Keyframe::string() const
+{
+ std::stringstream istream;
+ if (m_interpolation == Interpolation::Linear)
+ istream << "L";
+ else if (m_interpolation == Interpolation::Bezier)
+ istream << "B";
+ else if (m_interpolation == Interpolation::Easing)
+ istream << "E";
+
+ std::stringstream sstream;
+ sstream << "[" << istream.str() << (hasData() ? "*" : "") << "Frame P: " << m_position.x()
+ << ", " << m_position.y();
+
+ if (hasLeftHandle())
+ sstream << " L: " << m_leftHandle.x() << ", " << m_leftHandle.y();
+
+ if (hasRightHandle())
+ sstream << " R: " << m_rightHandle.x() << ", " << m_rightHandle.y();
+
+ sstream << "]";
+
+ return sstream.str();
+}
+
Keyframe::Interpolation Keyframe::interpolation() const
{
return m_interpolation;
diff --git a/src/plugins/qmldesigner/components/curveeditor/keyframe.h b/src/plugins/qmldesigner/components/curveeditor/keyframe.h
index be801e96f2..76284b2ff9 100644
--- a/src/plugins/qmldesigner/components/curveeditor/keyframe.h
+++ b/src/plugins/qmldesigner/components/curveeditor/keyframe.h
@@ -33,20 +33,13 @@ namespace DesignTools {
class Keyframe
{
public:
- enum class Interpolation
- {
- Undefined,
- Step,
- Linear,
- Bezier,
- Easing
- };
+ enum class Interpolation { Undefined, Step, Linear, Bezier, Easing };
Keyframe();
Keyframe(const QPointF &position);
- Keyframe(const QPointF &position, const QVariant& data);
+ Keyframe(const QPointF &position, const QVariant &data);
Keyframe(const QPointF &position, const QPointF &leftHandle, const QPointF &rightHandle);
@@ -66,6 +59,8 @@ public:
QVariant data() const;
+ std::string string() const;
+
Interpolation interpolation() const;
void setPosition(const QPointF &pos);
@@ -74,7 +69,7 @@ public:
void setRightHandle(const QPointF &pos);
- void setData(const QVariant& data);
+ void setData(const QVariant &data);
void setInterpolation(Interpolation interpol);