diff options
author | Michael Brasser <michael.brasser@nokia.com> | 2009-07-22 03:41:56 (GMT) |
---|---|---|
committer | Michael Brasser <michael.brasser@nokia.com> | 2009-07-22 03:41:56 (GMT) |
commit | 1777678767e1f30ff5df0b0a7d19c0af9c5c9590 (patch) | |
tree | c16315aaae4132d86b0992a0410d05d3c9aa4115 /src/declarative | |
parent | 34055e0160e2e94b0dd6b972c5bdc96a421adcf1 (diff) | |
download | Qt-1777678767e1f30ff5df0b0a7d19c0af9c5c9590.zip Qt-1777678767e1f30ff5df0b0a7d19c0af9c5c9590.tar.gz Qt-1777678767e1f30ff5df0b0a7d19c0af9c5c9590.tar.bz2 |
Remove moveToParent property.
Functionality has been moved to ParentChange.
Diffstat (limited to 'src/declarative')
-rw-r--r-- | src/declarative/fx/qfxitem.cpp | 64 | ||||
-rw-r--r-- | src/declarative/fx/qfxitem.h | 3 | ||||
-rw-r--r-- | src/declarative/util/qmlanimation.cpp | 35 | ||||
-rw-r--r-- | src/declarative/util/qmlstate.cpp | 47 | ||||
-rw-r--r-- | src/declarative/util/qmlstate.h | 3 | ||||
-rw-r--r-- | src/declarative/util/qmlstate_p.h | 5 | ||||
-rw-r--r-- | src/declarative/util/qmlstateoperations.cpp | 114 | ||||
-rw-r--r-- | src/declarative/util/qmlstateoperations.h | 19 |
8 files changed, 152 insertions, 138 deletions
diff --git a/src/declarative/fx/qfxitem.cpp b/src/declarative/fx/qfxitem.cpp index 4ea515a..c439032 100644 --- a/src/declarative/fx/qfxitem.cpp +++ b/src/declarative/fx/qfxitem.cpp @@ -460,70 +460,6 @@ void QFxItem::setItemParent(QFxItem *parent) } /*! - \internal - \property QFxItem::moveToParent - Playing around with view2view transitions. - */ - -/*! - \internal - */ -void QFxItem::moveToParent(QFxItem *parent) -{ - if (parent && itemParent()) { - QPointF me = itemParent()->mapToScene(QPointF(0,0)); - QPointF them = parent->mapToScene(QPointF(0,0)); - - QPointF themx = parent->mapToScene(QPointF(1,0)); - QPointF themy = parent->mapToScene(QPointF(0,1)); - - themx -= them; - themy -= them; - - setItemParent(parent); - - // XXX - this is silly and will only work in a few cases - - /* - xDiff = rx * themx_x + ry * themy_x - yDiff = rx * themx_y + ry * themy_y - */ - - qreal rx = 0; - qreal ry = 0; - qreal xDiff = them.x() - me.x(); - qreal yDiff = them.y() - me.y(); - - - if (themx.x() == 0.) { - ry = xDiff / themy.x(); - rx = (yDiff - ry * themy.y()) / themx.y(); - } else if (themy.x() == 0.) { - rx = xDiff / themx.x(); - ry = (yDiff - rx * themx.y()) / themy.y(); - } else if (themx.y() == 0.) { - ry = yDiff / themy.y(); - rx = (xDiff - ry * themy.x()) / themx.x(); - } else if (themy.y() == 0.) { - rx = yDiff / themx.y(); - ry = (xDiff - rx * themx.x()) / themy.x(); - } else { - qreal div = (themy.x() * themx.y() - themy.y() * themx.x()); - - if (div != 0.) - rx = (themx.y() * xDiff - themx.x() * yDiff) / div; - - if (themy.y() != 0.) ry = (yDiff - rx * themx.y()) / themy.y(); - } - - setX(x() - rx); - setY(y() - ry); - } else { - setItemParent(parent); - } -} - -/*! Returns the QFxItem parent of this item. */ QFxItem *QFxItem::itemParent() const diff --git a/src/declarative/fx/qfxitem.h b/src/declarative/fx/qfxitem.h index 67b60c1..53992d3 100644 --- a/src/declarative/fx/qfxitem.h +++ b/src/declarative/fx/qfxitem.h @@ -100,7 +100,6 @@ class Q_DECLARATIVE_EXPORT QFxItem : public QGraphicsObject, public QmlParserSta Q_INTERFACES(QmlParserStatus) Q_PROPERTY(QFxItem * parent READ itemParent WRITE setItemParent NOTIFY parentChanged DESIGNABLE false FINAL) - Q_PROPERTY(QFxItem * moveToParent READ itemParent WRITE moveToParent NOTIFY parentChanged DESIGNABLE false) Q_PROPERTY(QString id READ id WRITE setId) Q_PROPERTY(QmlList<QFxItem *>* children READ children DESIGNABLE false) Q_PROPERTY(QmlList<QObject *>* resources READ resources DESIGNABLE false) @@ -165,8 +164,6 @@ public: QFxItem *parentItem() const; void setItemParent(QFxItem *parent); - void moveToParent(QFxItem *parent); - QString id() const; void setId(const QString &); diff --git a/src/declarative/util/qmlanimation.cpp b/src/declarative/util/qmlanimation.cpp index ff070c1..7d9e30f 100644 --- a/src/declarative/util/qmlanimation.cpp +++ b/src/declarative/util/qmlanimation.cpp @@ -1128,54 +1128,39 @@ void QmlParentChangeAction::transition(QmlStateActions &actions, TransitionDirection direction) { Q_D(QmlParentChangeAction); + Q_UNUSED(modified); Q_UNUSED(direction); struct QmlParentChangeActionData : public QAbstractAnimationAction { QmlStateActions actions; + bool reverse; virtual void doAction() { for (int ii = 0; ii < actions.count(); ++ii) { const Action &action = actions.at(ii); - QmlBehaviour::_ignore = true; - action.property.write(action.toValue); - QmlBehaviour::_ignore = false; + if (reverse) + action.event->reverse(); + else + action.event->execute(); } } }; QmlParentChangeActionData *data = new QmlParentChangeActionData; - QSet<QObject *> objs; for (int ii = 0; ii < actions.count(); ++ii) { Action &action = actions[ii]; - QObject *obj = action.property.object(); - QString propertyName = action.property.name(); - - if ((!target() || target() == obj) && propertyName == QString(QLatin1String("moveToParent"))) { - objs.insert(obj); + //### should we still use target to filter? + if (action.event /*&& action.event->name() == d->parentChange*/) { //### Action myAction = action; - - /*if (d->value.isValid()) - myAction.toValue = d->value;*/ - - modified << action.property; + data->reverse = action.reverseEvent; data->actions << myAction; - action.fromValue = myAction.toValue; + action.actionDone = true; } } - /*if (d->value.isValid() && target() && !objs.contains(target())) { - QObject *obj = target(); - for (int jj = 0; jj < props.count(); ++jj) { - Action myAction; - myAction.property = QmlMetaProperty(obj, props.at(jj)); - myAction.toValue = d->value; - data->actions << myAction; - } - }*/ - if (data->actions.count()) { d->cpa->setAnimAction(data, QAbstractAnimation::DeleteWhenStopped); } else { diff --git a/src/declarative/util/qmlstate.cpp b/src/declarative/util/qmlstate.cpp index 73ea9c2..2c44c86 100644 --- a/src/declarative/util/qmlstate.cpp +++ b/src/declarative/util/qmlstate.cpp @@ -54,14 +54,14 @@ QT_BEGIN_NAMESPACE DEFINE_BOOL_CONFIG_OPTION(stateChangeDebug, STATECHANGE_DEBUG); Action::Action() -: restore(true), actionDone(false), fromBinding(0), toBinding(0), event(0), +: restore(true), actionDone(false), reverseEvent(false), fromBinding(0), toBinding(0), event(0), specifiedObject(0) { } Action::Action(QObject *target, const QString &propertyName, const QVariant &value) -: restore(true), actionDone(false), toValue(value), fromBinding(0), +: restore(true), actionDone(false), reverseEvent(false), toValue(value), fromBinding(0), toBinding(0), event(0), specifiedObject(target), specifiedProperty(propertyName) { @@ -83,6 +83,15 @@ void ActionEvent::execute() { } +bool ActionEvent::isReversable() +{ + return false; +} + +void ActionEvent::reverse() +{ +} + /*! \internal */ @@ -345,23 +354,33 @@ void QmlState::apply(QmlStateGroup *group, QmlTransition *trans, QmlState *rever for (int ii = 0; ii < applyList.count(); ++ii) { Action &action = applyList[ii]; - if (action.event) - continue; - - action.fromBinding = action.property.binding(); - bool found = false; + int jj; - for (jj = 0; jj < d->revertList.count(); ++jj) { - if (d->revertList.at(jj).property == action.property) { - found = true; - break; + if (action.event) { + if (!action.event->isReversable()) + continue; + for (jj = 0; jj < d->revertList.count(); ++jj) { + ActionEvent *event = d->revertList.at(jj).event; + if (event && event->name() == action.event->name()) { + found = true; + break; + } + } + } else { + action.fromBinding = action.property.binding(); + + for (jj = 0; jj < d->revertList.count(); ++jj) { + if (d->revertList.at(jj).property == action.property) { + found = true; + break; + } } } if (!found) { if (!action.restore) { - action.deleteFromBinding(); + action.deleteFromBinding(); } else { // Only need to revert the applyList action if the previous // state doesn't have a higher priority revert already @@ -394,8 +413,10 @@ void QmlState::apply(QmlStateGroup *group, QmlTransition *trans, QmlState *rever a.fromValue = cur; a.toValue = d->revertList.at(ii).value; a.toBinding = d->revertList.at(ii).binding; - a.specifiedObject = d->revertList.at(ii).specifiedObject; //### + a.specifiedObject = d->revertList.at(ii).specifiedObject; a.specifiedProperty = d->revertList.at(ii).specifiedProperty; + a.event = d->revertList.at(ii).event; + a.reverseEvent = d->revertList.at(ii).reverseEvent; applyList << a; // Store these special reverts in the reverting list d->reverting << d->revertList.at(ii).property; diff --git a/src/declarative/util/qmlstate.h b/src/declarative/util/qmlstate.h index 90649a1..1c0d67f 100644 --- a/src/declarative/util/qmlstate.h +++ b/src/declarative/util/qmlstate.h @@ -63,6 +63,7 @@ public: bool restore:1; bool actionDone:1; + bool reverseEvent:1; QmlMetaProperty property; QVariant fromValue; @@ -84,6 +85,8 @@ public: virtual ~ActionEvent(); virtual QString name() const; virtual void execute(); + virtual bool isReversable(); + virtual void reverse(); }; class QmlStateGroup; diff --git a/src/declarative/util/qmlstate_p.h b/src/declarative/util/qmlstate_p.h index 73e2377..b601b57 100644 --- a/src/declarative/util/qmlstate_p.h +++ b/src/declarative/util/qmlstate_p.h @@ -69,12 +69,15 @@ public: property = a.property; specifiedObject = a.specifiedObject; specifiedProperty = a.specifiedProperty; + event = a.event; if (state == StartState) { value = a.fromValue; binding = property.binding(); + reverseEvent = true; } else { value = a.toValue; binding = a.toBinding; + reverseEvent = false; } } @@ -83,6 +86,8 @@ public: QmlBinding *binding; QObject *specifiedObject; QString specifiedProperty; + ActionEvent *event; + bool reverseEvent; }; class QmlStatePrivate : public QObjectPrivate diff --git a/src/declarative/util/qmlstateoperations.cpp b/src/declarative/util/qmlstateoperations.cpp index 8d6abe6..dc7fef6 100644 --- a/src/declarative/util/qmlstateoperations.cpp +++ b/src/declarative/util/qmlstateoperations.cpp @@ -52,12 +52,70 @@ QT_BEGIN_NAMESPACE class QmlParentChangePrivate : public QObjectPrivate { public: - QmlParentChangePrivate() : target(0), parent(0) {} + QmlParentChangePrivate() : target(0), parent(0), origParent(0) {} - QObject *target; - QObject *parent; + QFxItem *target; + QFxItem *parent; + QFxItem *origParent; + + void doChange(QFxItem *targetParent); }; +void QmlParentChangePrivate::doChange(QFxItem *targetParent) +{ + if (targetParent && target && target->itemParent()) { + QPointF me = target->itemParent()->mapToScene(QPointF(0,0)); + QPointF them = targetParent->mapToScene(QPointF(0,0)); + + QPointF themx = targetParent->mapToScene(QPointF(1,0)); + QPointF themy = targetParent->mapToScene(QPointF(0,1)); + + themx -= them; + themy -= them; + + target->setItemParent(targetParent); + + // XXX - this is silly and will only work in a few cases + + /* + xDiff = rx * themx_x + ry * themy_x + yDiff = rx * themx_y + ry * themy_y + */ + + qreal rx = 0; + qreal ry = 0; + qreal xDiff = them.x() - me.x(); + qreal yDiff = them.y() - me.y(); + + + if (themx.x() == 0.) { + ry = xDiff / themy.x(); + rx = (yDiff - ry * themy.y()) / themx.y(); + } else if (themy.x() == 0.) { + rx = xDiff / themx.x(); + ry = (yDiff - rx * themx.y()) / themy.y(); + } else if (themx.y() == 0.) { + ry = yDiff / themy.y(); + rx = (xDiff - ry * themy.x()) / themx.x(); + } else if (themy.y() == 0.) { + rx = yDiff / themx.y(); + ry = (xDiff - rx * themx.x()) / themy.x(); + } else { + qreal div = (themy.x() * themx.y() - themy.y() * themx.x()); + + if (div != 0.) + rx = (themx.y() * xDiff - themx.x() * yDiff) / div; + + if (themy.y() != 0.) ry = (yDiff - rx * themx.y()) / themy.y(); + } + + target->setX(target->x() - rx); + target->setY(target->y() - ry); + } else if (target) { + target->setItemParent(targetParent); + } +} + /*! \preliminary \qmlclass ParentChange @@ -76,32 +134,32 @@ QmlParentChange::~QmlParentChange() /*! \qmlproperty Object ParentChange::target - This property holds the object to be reparented + This property holds the item to be reparented */ -QObject *QmlParentChange::object() const +QFxItem *QmlParentChange::object() const { Q_D(const QmlParentChange); return d->target; } -void QmlParentChange::setObject(QObject *target) +void QmlParentChange::setObject(QFxItem *target) { Q_D(QmlParentChange); d->target = target; } /*! - \qmlproperty Object ParentChange::parent - This property holds the parent for the object in this state + \qmlproperty Item ParentChange::parent + This property holds the parent for the item in this state */ -QObject *QmlParentChange::parent() const +QFxItem *QmlParentChange::parent() const { Q_D(const QmlParentChange); return d->parent; } -void QmlParentChange::setParent(QObject *parent) +void QmlParentChange::setParent(QFxItem *parent) { Q_D(QmlParentChange); d->parent = parent; @@ -113,27 +171,31 @@ QmlStateOperation::ActionList QmlParentChange::actions() if (!d->target || !d->parent) return ActionList(); - QString propName(QLatin1String("moveToParent")); - QmlMetaProperty prop(d->target, propName); - if (!prop.isValid()) { - qmlInfo(this) << d->target->metaObject()->className() - << "has no property named" << propName; - return ActionList(); - }else if (!prop.isWritable()){ - qmlInfo(this) << d->target->metaObject()->className() << propName - << "is not a writable property and cannot be set."; - return ActionList(); - } - QVariant cur = prop.read(); - Action a; - a.property = prop; - a.fromValue = cur; - a.toValue = qVariantFromValue(d->parent); + a.event = this; return ActionList() << a; } +void QmlParentChange::execute() +{ + Q_D(QmlParentChange); + if (d->target) + d->origParent = d->target->itemParent(); + d->doChange(d->parent); +} + +bool QmlParentChange::isReversable() +{ + return true; +} + +void QmlParentChange::reverse() +{ + Q_D(QmlParentChange); + d->doChange(d->origParent); +} + class QmlRunScriptPrivate : public QObjectPrivate { public: diff --git a/src/declarative/util/qmlstateoperations.h b/src/declarative/util/qmlstateoperations.h index 221373b..acbe05e 100644 --- a/src/declarative/util/qmlstateoperations.h +++ b/src/declarative/util/qmlstateoperations.h @@ -43,6 +43,7 @@ #define QMLSTATEOPERATIONS_H #include <QtDeclarative/qmlstate.h> +#include <QtDeclarative/qfxitem.h> QT_BEGIN_HEADER @@ -51,24 +52,28 @@ QT_BEGIN_NAMESPACE QT_MODULE(Declarative) class QmlParentChangePrivate; -class Q_DECLARATIVE_EXPORT QmlParentChange : public QmlStateOperation +class Q_DECLARATIVE_EXPORT QmlParentChange : public QmlStateOperation, public ActionEvent { Q_OBJECT Q_DECLARE_PRIVATE(QmlParentChange) - Q_PROPERTY(QObject *target READ object WRITE setObject) - Q_PROPERTY(QObject *parent READ parent WRITE setParent) + Q_PROPERTY(QFxItem *target READ object WRITE setObject) + Q_PROPERTY(QFxItem *parent READ parent WRITE setParent) public: QmlParentChange(QObject *parent=0); ~QmlParentChange(); - QObject *object() const; - void setObject(QObject *); + QFxItem *object() const; + void setObject(QFxItem *); - QObject *parent() const; - void setParent(QObject *); + QFxItem *parent() const; + void setParent(QFxItem *); virtual ActionList actions(); + + virtual void execute(); + virtual bool isReversable(); + virtual void reverse(); }; class QmlRunScriptPrivate; |