Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/app/GUI/Expressions/expressionhighlighter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ ExpressionHighlighter::ExpressionHighlighter(
mErrorFormat.setForeground(Qt::red);
mAssignFormat.setForeground(QColor(255, 128, 128));

const QString propPath = "([a-zA-Z0-9_\\.]+[a-zA-Z0-9_ \\.]*[a-zA-Z0-9_\\.]+)";
const QString propPath = "((?:\\$parent\\.)*"
"[a-zA-Z0-9_\\.]+"
"[a-zA-Z0-9_ \\.]*"
"[a-zA-Z0-9_\\.]+)";
mPropSetRegex = QRegularExpression("^\\s*"
"([A-Za-z_][A-Za-z0-9_]*)"
"\\s*=\\s*" + propPath);
Expand All @@ -62,6 +65,7 @@ ExpressionHighlighter::ExpressionHighlighter(
const QStringList specs = {
QStringLiteral("$value"),
QStringLiteral("$frame"),
QStringLiteral("$parent"),
QStringLiteral("$scene.fps"),
QStringLiteral("$scene.width"),
QStringLiteral("$scene.height"),
Expand Down
27 changes: 27 additions & 0 deletions src/core/Animators/complexanimator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "Sound/esound.h"
#include <QPainter>
#include "Boxes/boundingbox.h"
#include "Animators/transformanimator.h"

ComplexAnimator::ComplexAnimator(const QString &name) :
Animator(name) {
Expand Down Expand Up @@ -205,6 +206,32 @@ void ComplexAnimator::ca_updateDescendatKeyFrame(Key* key) {
Property *ComplexAnimator::ca_findPropertyWithPathRec(
const int id, const QStringList &path,
QStringList * const completions) const {
if(id < path.count() && path.at(id) == QStringLiteral("$parent")) {
const auto currentBox = getFirstAncestor<BoundingBox>();
const auto findParentBox = [](const BoundingBox* const box) {
const auto parentTransform = box ? box->getParentTransform() : nullptr;
return parentTransform ?
parentTransform->getFirstAncestor<BoundingBox>() : nullptr;
};
auto parentBox = findParentBox(currentBox);
int nextId = id + 1;
while(parentBox && nextId < path.count() &&
path.at(nextId) == QStringLiteral("$parent")) {
parentBox = findParentBox(parentBox);
++nextId;
}
if(!parentBox) return nullptr;
if(nextId == path.count()) {
if(completions) {
parentBox->ca_findPropertyWithPath(
0, QStringList() << QString(), completions);
}
return parentBox;
}
return parentBox->ca_findPropertyWithPath(
nextId, path, completions);
}

Property* found = nullptr;
const ComplexAnimator* acestorIter = this;
while(acestorIter && (completions || !found)) {
Expand Down
1 change: 1 addition & 0 deletions src/core/Boxes/boundingbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,7 @@ void BoundingBox::setParentTransform(BasicTransformAnimator *parent) {
if(parent == mParentTransform) return;
mParentTransform = parent;
mTransformAnimator->setParentTransformAnimator(mParentTransform);
emit prp_pathChanged();
}

void BoundingBox::afterTotalTransformChanged(const UpdateReason reason) {
Expand Down
2 changes: 2 additions & 0 deletions src/core/Boxes/boundingbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,8 @@ class CORE_EXPORT BoundingBox : public eBoxOrSound {

void clearParent();
void setParentTransform(BasicTransformAnimator *parent);
BasicTransformAnimator* getParentTransform() const
{ return mParentTransform; }

bool isContainedIn(const QRectF &absRect) const;

Expand Down
2 changes: 2 additions & 0 deletions src/core/Expressions/propertybinding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ Property *PropertyBinding::sFindPropertyToBind(const QString& binding,

void PropertyBinding::updateBindPath() {
if(!mBindProperty || !mContext) return;
if(mPath == QStringLiteral("$parent") ||
mPath.startsWith(QStringLiteral("$parent."))) return;
QStringList prntPath;
mContext->prp_getFullPath(prntPath);
QStringList srcPath;
Expand Down
3 changes: 2 additions & 1 deletion src/core/Expressions/propertybindingparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ bool parseSceneRangeMin(const QString& exp, int& pos) {
void parseBinding(const QString& exp, int& pos, QString& binding) {
while(pos < exp.count()) {
const auto& c = exp.at(pos++);
if(!c.isLetterOrNumber() && c != ' ' && c != '.' && c != '_') break;
if(!c.isLetterOrNumber() && c != ' ' && c != '.' &&
c != '_' && c != '$') break;
binding.append(c);
}
}
Expand Down
Loading