Commit 89dcc22d authored by Thomas Hartmann's avatar Thomas Hartmann

QmlDesigner: Add enablers for timeline

Change-Id: Id5a75aaeb7de329a72ca468c8299d4f798f60766
Reviewed-by: Thomas Hartmann's avatarThomas Hartmann <thomas.hartmann@qt.io>
parent 8fd3f55d
......@@ -58,6 +58,11 @@ public:
bool hasKeyframe(qreal frame);
qreal minActualFrame() const;
qreal maxActualFrame() const;
const QList<ModelNode> keyframePositions() const;
static bool isValidKeyframe(const ModelNode &node);
static QmlTimelineFrames keyframesForKeyframe(const ModelNode &node);
};
......
......@@ -52,6 +52,13 @@ public:
qreal startFrame() const;
qreal endFrame() const;
qreal currentFrame() const;
qreal duration() const;
qreal minActualFrame() const;
qreal maxActualFrame() const;
QList<ModelNode> allTargets() const;
QList<QmlTimelineFrames> framesForTarget(const ModelNode &target) const;
private:
void addFramesIfNotExists(const ModelNode &node, const PropertyName &propertyName);
......
......@@ -34,6 +34,8 @@
#include <utils/qtcassert.h>
#include <limits>
namespace QmlDesigner {
QmlTimelineFrames::QmlTimelineFrames()
......@@ -126,6 +128,42 @@ bool QmlTimelineFrames::hasKeyframe(qreal frame)
return false;
}
qreal QmlTimelineFrames::minActualFrame() const
{
qreal min = std::numeric_limits<double>::max();
for (const ModelNode &childNode : modelNode().defaultNodeListProperty().toModelNodeList()) {
QVariant value = childNode.variantProperty("frame").value();
if (value.isValid() && value.toReal() < min)
min = value.toReal();
}
return min;
}
qreal QmlTimelineFrames::maxActualFrame() const
{
qreal max = std::numeric_limits<double>::min();
for (const ModelNode &childNode : modelNode().defaultNodeListProperty().toModelNodeList()) {
QVariant value = childNode.variantProperty("frame").value();
if (value.isValid() && value.toReal() > max)
max = value.toReal();
}
return max;
}
const QList<ModelNode> QmlTimelineFrames::keyframePositions() const
{
QList<ModelNode> returnValues;
for (const ModelNode &childNode : modelNode().defaultNodeListProperty().toModelNodeList()) {
QVariant value = childNode.variantProperty("frame").value();
if (value.isValid())
returnValues.append(childNode);
}
return returnValues;
}
bool QmlTimelineFrames::isValidKeyframe(const ModelNode &node)
{
return isValidQmlModelNodeFacade(node)
......
......@@ -36,6 +36,8 @@
#include <utils/qtcassert.h>
#include <limits>
namespace QmlDesigner {
QmlTimelineMutator::QmlTimelineMutator()
......@@ -123,6 +125,73 @@ qreal QmlTimelineMutator::currentFrame() const
return 0;
}
qreal QmlTimelineMutator::duration() const
{
return endFrame() - startFrame();
}
qreal QmlTimelineMutator::minActualFrame() const
{
qreal min = std::numeric_limits<double>::max();
for (const ModelNode &childNode : modelNode().defaultNodeListProperty().toModelNodeList()) {
if (QmlTimelineFrames::isValidQmlTimelineFrames(childNode)) {
QmlTimelineFrames frames(childNode);
qreal value = frames.minActualFrame();
if (value < min)
min = value;
}
}
return min;
}
qreal QmlTimelineMutator::maxActualFrame() const
{
qreal max = std::numeric_limits<double>::min();
for (const ModelNode &childNode : modelNode().defaultNodeListProperty().toModelNodeList()) {
if (QmlTimelineFrames::isValidQmlTimelineFrames(childNode)) {
QmlTimelineFrames frames(childNode);
qreal value = frames.maxActualFrame();
if (value > max)
max = value;
}
}
return max;
}
QList<ModelNode> QmlTimelineMutator::allTargets() const
{
QList<ModelNode> result;
if (isValid()) {
for (const ModelNode &childNode : modelNode().defaultNodeListProperty().toModelNodeList()) {
if (QmlTimelineFrames::isValidQmlTimelineFrames(childNode)) {
const QmlTimelineFrames frames(childNode);
if (!result.contains(frames.target()))
result.append(frames.target());
}
}
}
return result;
}
QList<QmlTimelineFrames> QmlTimelineMutator::framesForTarget(const ModelNode &target) const
{
QList<QmlTimelineFrames> result;
if (isValid()) {
for (const ModelNode &childNode : modelNode().defaultNodeListProperty().toModelNodeList()) {
if (QmlTimelineFrames::isValidQmlTimelineFrames(childNode)) {
const QmlTimelineFrames frames(childNode);
if (frames.target() == target)
result.append(frames);
}
}
}
return result;
}
void QmlTimelineMutator::addFramesIfNotExists(const ModelNode &node, const PropertyName &propertyName)
{
if (!isValid())
......
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