Commit 034e6725 authored by Thomas Hartmann's avatar Thomas Hartmann

QmlDesigner: Add support for timeline items

Change-Id: Ie7e05c78c2d817da9dd91c345f1949daa640c6bc
Reviewed-by: Tim Jenssen's avatarTim Jenssen <tim.jenssen@qt.io>
parent 2c93654e
......@@ -70,6 +70,10 @@ public:
void moveAllFrames(qreal offset);
void scaleAllFrames(qreal factor);
int getSupposedTargetIndex(qreal newFrame) const;
int indexOfFrame(const ModelNode &frame) const;
void slideFrame(int sourceIndex, int targetIndex);
};
} //QmlDesigner
......@@ -54,6 +54,8 @@ public:
qreal currentFrame() const;
qreal duration() const;
bool isEnabled() const;
qreal minActualFrame(const ModelNode &target) const;
qreal maxActualFrame(const ModelNode &target) const;
......
......@@ -90,6 +90,35 @@ void QmlTimelineFrames::setPropertyName(const PropertyName &propertyName)
modelNode().variantProperty("property").setValue(QString::fromUtf8(propertyName));
}
int QmlTimelineFrames::getSupposedTargetIndex(qreal newFrame) const
{
const NodeListProperty nodeListProperty = modelNode().defaultNodeListProperty();
int i = 0;
for (auto node : nodeListProperty.toModelNodeList()) {
if (node.hasVariantProperty("frame")) {
const qreal currentFrame = node.variantProperty("frame").value().toReal();
if (!qFuzzyCompare(currentFrame, newFrame)) { //Ignore the frame itself
if (currentFrame > newFrame)
return i;
++i;
}
}
}
return nodeListProperty.count();
}
int QmlTimelineFrames::indexOfFrame(const ModelNode &frame) const
{
return modelNode().defaultNodeListProperty().indexOf(frame);
}
void QmlTimelineFrames::slideFrame(int sourceIndex, int targetIndex)
{
if (targetIndex != sourceIndex)
modelNode().defaultNodeListProperty().slide(sourceIndex, targetIndex);
}
void QmlTimelineFrames::setValue(const QVariant &value, qreal currentFrame)
{
......@@ -104,7 +133,14 @@ void QmlTimelineFrames::setValue(const QVariant &value, qreal currentFrame)
{PropertyName("value"), value}};
ModelNode frame = modelNode().view()->createModelNode("QtQuick.Timeline.Keyframe", 1, 0, propertyPairList);
modelNode().defaultNodeListProperty().reparentHere(frame);
NodeListProperty nodeListProperty = modelNode().defaultNodeListProperty();
const int sourceIndex = nodeListProperty.count();
const int targetIndex = getSupposedTargetIndex(currentFrame);
nodeListProperty.reparentHere(frame);
slideFrame(sourceIndex, targetIndex);
}
QVariant QmlTimelineFrames::value(qreal frame) const
......
......@@ -130,6 +130,11 @@ qreal QmlTimelineMutator::duration() const
return endFrame() - startFrame();
}
bool QmlTimelineMutator::isEnabled() const
{
return QmlObjectNode(modelNode()).modelValue("enabled").toBool();
}
qreal QmlTimelineMutator::minActualFrame(const ModelNode &target) const
{
qreal min = std::numeric_limits<double>::max();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment