diff --git a/src/plugins/qmldesigner/components/curveeditor/animationcurve.cpp b/src/plugins/qmldesigner/components/curveeditor/animationcurve.cpp index bd11405bd2b..5a849316b0b 100644 --- a/src/plugins/qmldesigner/components/curveeditor/animationcurve.cpp +++ b/src/plugins/qmldesigner/components/curveeditor/animationcurve.cpp @@ -31,6 +31,8 @@ #include #include +#include + 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 fbd75594da5..3122074bfe9 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 segments() const; diff --git a/src/plugins/qmldesigner/components/curveeditor/detail/curveitem.cpp b/src/plugins/qmldesigner/components/curveeditor/detail/curveitem.cpp index faa3c320eba..a7eb612a291 100644 --- a/src/plugins/qmldesigner/components/curveeditor/detail/curveitem.cpp +++ b/src/plugins/qmldesigner/components/curveeditor/detail/curveitem.cpp @@ -34,6 +34,7 @@ #include #include +#include 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 a83b5304639..146c3035853 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 #include 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 42a7f1b8a89..d29bb849281 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 7bff0045647..4640b3eb827 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 55109f435ad..ea239af6fd2 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 4beea4b716b..0ac23c36153 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 + 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 be801e96f24..76284b2ff96 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);