forked from qt-creator/qt-creator
Apply interpolation when restoring an animation-curve
+ Notify timeline when inserting a keyframe Change-Id: I91548c4e45306e9a6c6490cc94b88080de3910ac Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
@@ -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;
|
||||
|
@@ -58,6 +58,8 @@ public:
|
||||
|
||||
double maximumValue() const;
|
||||
|
||||
std::string string() const;
|
||||
|
||||
CurveSegment segment(double time) const;
|
||||
|
||||
std::vector<CurveSegment> segments() const;
|
||||
|
@@ -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()
|
||||
|
@@ -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);
|
||||
|
||||
|
@@ -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);
|
||||
}
|
||||
|
@@ -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);
|
||||
|
@@ -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);
|
||||
|
@@ -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;
|
||||
|
@@ -33,14 +33,7 @@ namespace DesignTools {
|
||||
class Keyframe
|
||||
{
|
||||
public:
|
||||
enum class Interpolation
|
||||
{
|
||||
Undefined,
|
||||
Step,
|
||||
Linear,
|
||||
Bezier,
|
||||
Easing
|
||||
};
|
||||
enum class Interpolation { Undefined, Step, Linear, Bezier, Easing };
|
||||
|
||||
Keyframe();
|
||||
|
||||
@@ -66,6 +59,8 @@ public:
|
||||
|
||||
QVariant data() const;
|
||||
|
||||
std::string string() const;
|
||||
|
||||
Interpolation interpolation() const;
|
||||
|
||||
void setPosition(const QPointF &pos);
|
||||
|
Reference in New Issue
Block a user