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 <QLineF>
|
||||||
#include <QPainterPath>
|
#include <QPainterPath>
|
||||||
|
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
namespace DesignTools {
|
namespace DesignTools {
|
||||||
|
|
||||||
AnimationCurve::AnimationCurve()
|
AnimationCurve::AnimationCurve()
|
||||||
@@ -127,6 +129,21 @@ double AnimationCurve::maximumValue() const
|
|||||||
return m_maxY;
|
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 AnimationCurve::segment(double time) const
|
||||||
{
|
{
|
||||||
CurveSegment seg;
|
CurveSegment seg;
|
||||||
|
@@ -58,6 +58,8 @@ public:
|
|||||||
|
|
||||||
double maximumValue() const;
|
double maximumValue() const;
|
||||||
|
|
||||||
|
std::string string() const;
|
||||||
|
|
||||||
CurveSegment segment(double time) const;
|
CurveSegment segment(double time) const;
|
||||||
|
|
||||||
std::vector<CurveSegment> segments() const;
|
std::vector<CurveSegment> segments() const;
|
||||||
|
@@ -34,6 +34,7 @@
|
|||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
namespace DesignTools {
|
namespace DesignTools {
|
||||||
|
|
||||||
@@ -251,9 +252,8 @@ void CurveItem::restore()
|
|||||||
Keyframe curr = currItem->keyframe();
|
Keyframe curr = currItem->keyframe();
|
||||||
CurveSegment segment(prev, curr);
|
CurveSegment segment(prev, curr);
|
||||||
|
|
||||||
segment.setInterpolation(segment.interpolation());
|
|
||||||
|
|
||||||
prevItem->setRightHandle(segment.left().rightHandle());
|
prevItem->setRightHandle(segment.left().rightHandle());
|
||||||
|
currItem->setInterpolation(segment.interpolation());
|
||||||
currItem->setLeftHandle(segment.right().leftHandle());
|
currItem->setLeftHandle(segment.right().leftHandle());
|
||||||
|
|
||||||
prevItem = currItem;
|
prevItem = currItem;
|
||||||
@@ -329,12 +329,12 @@ void CurveItem::setInterpolation(Keyframe::Interpolation interpolation)
|
|||||||
segment.setInterpolation(interpolation);
|
segment.setInterpolation(interpolation);
|
||||||
prevItem->setKeyframe(segment.left());
|
prevItem->setKeyframe(segment.left());
|
||||||
currItem->setKeyframe(segment.right());
|
currItem->setKeyframe(segment.right());
|
||||||
|
|
||||||
setDirty(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
prevItem = currItem;
|
prevItem = currItem;
|
||||||
}
|
}
|
||||||
|
setDirty(false);
|
||||||
|
emit curveChanged(id(), curve());
|
||||||
}
|
}
|
||||||
|
|
||||||
void CurveItem::connect(GraphicsScene *scene)
|
void CurveItem::connect(GraphicsScene *scene)
|
||||||
@@ -358,6 +358,8 @@ void CurveItem::insertKeyframeByTime(double time)
|
|||||||
AnimationCurve acurve = curve();
|
AnimationCurve acurve = curve();
|
||||||
acurve.insert(time);
|
acurve.insert(time);
|
||||||
setCurve(acurve);
|
setCurve(acurve);
|
||||||
|
|
||||||
|
emit curveChanged(id(), curve());
|
||||||
}
|
}
|
||||||
|
|
||||||
void CurveItem::deleteSelectedKeyframes()
|
void CurveItem::deleteSelectedKeyframes()
|
||||||
|
@@ -31,6 +31,7 @@
|
|||||||
#include "selectableitem.h"
|
#include "selectableitem.h"
|
||||||
#include "treeitem.h"
|
#include "treeitem.h"
|
||||||
|
|
||||||
|
#include <string>
|
||||||
#include <QGraphicsObject>
|
#include <QGraphicsObject>
|
||||||
|
|
||||||
namespace DesignTools {
|
namespace DesignTools {
|
||||||
@@ -43,6 +44,9 @@ class CurveItem : public QGraphicsObject
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void curveChanged(unsigned int id, const AnimationCurve &curve);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CurveItem(QGraphicsItem *parent = nullptr);
|
CurveItem(QGraphicsItem *parent = nullptr);
|
||||||
|
|
||||||
|
@@ -69,6 +69,8 @@ void GraphicsScene::addCurveItem(CurveItem *item)
|
|||||||
m_dirty = true;
|
m_dirty = true;
|
||||||
item->setDirty(false);
|
item->setDirty(false);
|
||||||
|
|
||||||
|
connect(item, &CurveItem::curveChanged, this, &GraphicsScene::curveChanged);
|
||||||
|
|
||||||
addItem(item);
|
addItem(item);
|
||||||
item->connect(this);
|
item->connect(this);
|
||||||
}
|
}
|
||||||
|
@@ -174,6 +174,11 @@ void KeyframeItem::setKeyframe(const Keyframe &keyframe)
|
|||||||
setPos(m_transform.map(m_frame.position()));
|
setPos(m_transform.map(m_frame.position()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void KeyframeItem::setInterpolation(Keyframe::Interpolation interpolation)
|
||||||
|
{
|
||||||
|
m_frame.setInterpolation(interpolation);
|
||||||
|
}
|
||||||
|
|
||||||
void KeyframeItem::setLeftHandle(const QPointF &pos)
|
void KeyframeItem::setLeftHandle(const QPointF &pos)
|
||||||
{
|
{
|
||||||
m_frame.setLeftHandle(pos);
|
m_frame.setLeftHandle(pos);
|
||||||
|
@@ -75,6 +75,8 @@ public:
|
|||||||
|
|
||||||
void setKeyframe(const Keyframe &keyframe);
|
void setKeyframe(const Keyframe &keyframe);
|
||||||
|
|
||||||
|
void setInterpolation(Keyframe::Interpolation interpolation);
|
||||||
|
|
||||||
void setLeftHandle(const QPointF &pos);
|
void setLeftHandle(const QPointF &pos);
|
||||||
|
|
||||||
void setRightHandle(const QPointF &pos);
|
void setRightHandle(const QPointF &pos);
|
||||||
|
@@ -25,6 +25,8 @@
|
|||||||
|
|
||||||
#include "keyframe.h"
|
#include "keyframe.h"
|
||||||
|
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
namespace DesignTools {
|
namespace DesignTools {
|
||||||
|
|
||||||
Keyframe::Keyframe()
|
Keyframe::Keyframe()
|
||||||
@@ -101,6 +103,31 @@ QVariant Keyframe::data() const
|
|||||||
return m_data;
|
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
|
Keyframe::Interpolation Keyframe::interpolation() const
|
||||||
{
|
{
|
||||||
return m_interpolation;
|
return m_interpolation;
|
||||||
|
@@ -33,20 +33,13 @@ namespace DesignTools {
|
|||||||
class Keyframe
|
class Keyframe
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
enum class Interpolation
|
enum class Interpolation { Undefined, Step, Linear, Bezier, Easing };
|
||||||
{
|
|
||||||
Undefined,
|
|
||||||
Step,
|
|
||||||
Linear,
|
|
||||||
Bezier,
|
|
||||||
Easing
|
|
||||||
};
|
|
||||||
|
|
||||||
Keyframe();
|
Keyframe();
|
||||||
|
|
||||||
Keyframe(const QPointF &position);
|
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);
|
Keyframe(const QPointF &position, const QPointF &leftHandle, const QPointF &rightHandle);
|
||||||
|
|
||||||
@@ -66,6 +59,8 @@ public:
|
|||||||
|
|
||||||
QVariant data() const;
|
QVariant data() const;
|
||||||
|
|
||||||
|
std::string string() const;
|
||||||
|
|
||||||
Interpolation interpolation() const;
|
Interpolation interpolation() const;
|
||||||
|
|
||||||
void setPosition(const QPointF &pos);
|
void setPosition(const QPointF &pos);
|
||||||
@@ -74,7 +69,7 @@ public:
|
|||||||
|
|
||||||
void setRightHandle(const QPointF &pos);
|
void setRightHandle(const QPointF &pos);
|
||||||
|
|
||||||
void setData(const QVariant& data);
|
void setData(const QVariant &data);
|
||||||
|
|
||||||
void setInterpolation(Interpolation interpol);
|
void setInterpolation(Interpolation interpol);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user