diff options
Diffstat (limited to 'src/declarative/util/qdeclarativeanimation.cpp')
-rw-r--r-- | src/declarative/util/qdeclarativeanimation.cpp | 513 |
1 files changed, 0 insertions, 513 deletions
diff --git a/src/declarative/util/qdeclarativeanimation.cpp b/src/declarative/util/qdeclarativeanimation.cpp index ce21bcd30e..213ebe564a 100644 --- a/src/declarative/util/qdeclarativeanimation.cpp +++ b/src/declarative/util/qdeclarativeanimation.cpp @@ -2431,519 +2431,6 @@ void QDeclarativePropertyAnimation::transition(QDeclarativeStateActions &actions } } -/*! - \qmlclass ParentAnimation QDeclarativeParentAnimation - \ingroup qml-animation-transition - \since 4.7 - \inherits Animation - \brief The ParentAnimation element animates changes in parent values. - - ParentAnimation is used to animate a parent change for an \l Item. - - For example, the following ParentChange changes \c blueRect to become - a child of \c redRect when it is clicked. The inclusion of the - ParentAnimation, which defines a NumberAnimation to be applied during - the transition, ensures the item animates smoothly as it moves to - its new parent: - - \snippet doc/src/snippets/declarative/parentanimation.qml 0 - - A ParentAnimation can contain any number of animations. These animations will - be run in parallel; to run them sequentially, define them within a - SequentialAnimation. - - In some cases, such as when reparenting between items with clipping enabled, it is useful - to animate the parent change via another item that does not have clipping - enabled. Such an item can be set using the \l via property. - - For convenience, when a ParentAnimation is used in a \l Transition, it will - animate any ParentChange that has occurred during the state change. - This can be overridden by setting a specific target item using the - \l target property. - - Like any other animation element, a ParentAnimation can be applied in a - number of ways, including transitions, behaviors and property value - sources. The \l {QML Animation and Transitions} documentation shows a - variety of methods for creating animations. - - \sa {QML Animation and Transitions}, {declarative/animation/basics}{Animation basics example} -*/ -QDeclarativeParentAnimation::QDeclarativeParentAnimation(QObject *parent) - : QDeclarativeAnimationGroup(*(new QDeclarativeParentAnimationPrivate), parent) -{ - Q_D(QDeclarativeParentAnimation); - d->topLevelGroup = new QSequentialAnimationGroup; - QDeclarative_setParent_noEvent(d->topLevelGroup, this); - - d->startAction = new QActionAnimation; - QDeclarative_setParent_noEvent(d->startAction, d->topLevelGroup); - d->topLevelGroup->addAnimation(d->startAction); - - d->ag = new QParallelAnimationGroup; - QDeclarative_setParent_noEvent(d->ag, d->topLevelGroup); - d->topLevelGroup->addAnimation(d->ag); - - d->endAction = new QActionAnimation; - QDeclarative_setParent_noEvent(d->endAction, d->topLevelGroup); - d->topLevelGroup->addAnimation(d->endAction); -} - -QDeclarativeParentAnimation::~QDeclarativeParentAnimation() -{ -} - -/*! - \qmlproperty Item ParentAnimation::target - The item to reparent. - - When used in a transition, if no target is specified, all - ParentChange occurrences are animated by the ParentAnimation. -*/ -QDeclarativeItem *QDeclarativeParentAnimation::target() const -{ - Q_D(const QDeclarativeParentAnimation); - return d->target; -} - -void QDeclarativeParentAnimation::setTarget(QDeclarativeItem *target) -{ - Q_D(QDeclarativeParentAnimation); - if (target == d->target) - return; - - d->target = target; - emit targetChanged(); -} - -/*! - \qmlproperty Item ParentAnimation::newParent - The new parent to animate to. - - If the ParentAnimation is defined within a \l Transition or \l Behavior, - this value defaults to the value defined in the end state of the - \l Transition, or the value of the property change that triggered the - \l Behavior. -*/ -QDeclarativeItem *QDeclarativeParentAnimation::newParent() const -{ - Q_D(const QDeclarativeParentAnimation); - return d->newParent; -} - -void QDeclarativeParentAnimation::setNewParent(QDeclarativeItem *newParent) -{ - Q_D(QDeclarativeParentAnimation); - if (newParent == d->newParent) - return; - - d->newParent = newParent; - emit newParentChanged(); -} - -/*! - \qmlproperty Item ParentAnimation::via - The item to reparent via. This provides a way to do an unclipped animation - when both the old parent and new parent are clipped. - - \qml - ParentAnimation { - target: myItem - via: topLevelItem - // ... - } - \endqml -*/ -QDeclarativeItem *QDeclarativeParentAnimation::via() const -{ - Q_D(const QDeclarativeParentAnimation); - return d->via; -} - -void QDeclarativeParentAnimation::setVia(QDeclarativeItem *via) -{ - Q_D(QDeclarativeParentAnimation); - if (via == d->via) - return; - - d->via = via; - emit viaChanged(); -} - -//### mirrors same-named function in QDeclarativeItem -QPointF QDeclarativeParentAnimationPrivate::computeTransformOrigin(QDeclarativeItem::TransformOrigin origin, qreal width, qreal height) const -{ - switch(origin) { - default: - case QDeclarativeItem::TopLeft: - return QPointF(0, 0); - case QDeclarativeItem::Top: - return QPointF(width / 2., 0); - case QDeclarativeItem::TopRight: - return QPointF(width, 0); - case QDeclarativeItem::Left: - return QPointF(0, height / 2.); - case QDeclarativeItem::Center: - return QPointF(width / 2., height / 2.); - case QDeclarativeItem::Right: - return QPointF(width, height / 2.); - case QDeclarativeItem::BottomLeft: - return QPointF(0, height); - case QDeclarativeItem::Bottom: - return QPointF(width / 2., height); - case QDeclarativeItem::BottomRight: - return QPointF(width, height); - } -} - -void QDeclarativeParentAnimation::transition(QDeclarativeStateActions &actions, - QDeclarativeProperties &modified, - TransitionDirection direction) -{ - Q_D(QDeclarativeParentAnimation); - - struct QDeclarativeParentAnimationData : public QAbstractAnimationAction - { - QDeclarativeParentAnimationData() {} - ~QDeclarativeParentAnimationData() { qDeleteAll(pc); } - - QDeclarativeStateActions actions; - //### reverse should probably apply on a per-action basis - bool reverse; - QList<QDeclarativeParentChange *> pc; - virtual void doAction() - { - for (int ii = 0; ii < actions.count(); ++ii) { - const QDeclarativeAction &action = actions.at(ii); - if (reverse) - action.event->reverse(); - else - action.event->execute(); - } - } - }; - - QDeclarativeParentAnimationData *data = new QDeclarativeParentAnimationData; - QDeclarativeParentAnimationData *viaData = new QDeclarativeParentAnimationData; - - bool hasExplicit = false; - if (d->target && d->newParent) { - data->reverse = false; - QDeclarativeAction myAction; - QDeclarativeParentChange *pc = new QDeclarativeParentChange; - pc->setObject(d->target); - pc->setParent(d->newParent); - myAction.event = pc; - data->pc << pc; - data->actions << myAction; - hasExplicit = true; - if (d->via) { - viaData->reverse = false; - QDeclarativeAction myVAction; - QDeclarativeParentChange *vpc = new QDeclarativeParentChange; - vpc->setObject(d->target); - vpc->setParent(d->via); - myVAction.event = vpc; - viaData->pc << vpc; - viaData->actions << myVAction; - } - //### once actions have concept of modified, - // loop to match appropriate ParentChanges and mark as modified - } - - if (!hasExplicit) - for (int i = 0; i < actions.size(); ++i) { - QDeclarativeAction &action = actions[i]; - if (action.event && action.event->typeName() == QLatin1String("ParentChange") - && (!d->target || static_cast<QDeclarativeParentChange*>(action.event)->object() == d->target)) { - - QDeclarativeParentChange *pc = static_cast<QDeclarativeParentChange*>(action.event); - QDeclarativeAction myAction = action; - data->reverse = action.reverseEvent; - - //### this logic differs from PropertyAnimation - // (probably a result of modified vs. done) - if (d->newParent) { - QDeclarativeParentChange *epc = new QDeclarativeParentChange; - epc->setObject(static_cast<QDeclarativeParentChange*>(action.event)->object()); - epc->setParent(d->newParent); - myAction.event = epc; - data->pc << epc; - data->actions << myAction; - pc = epc; - } else { - action.actionDone = true; - data->actions << myAction; - } - - if (d->via) { - viaData->reverse = false; - QDeclarativeAction myAction; - QDeclarativeParentChange *vpc = new QDeclarativeParentChange; - vpc->setObject(pc->object()); - vpc->setParent(d->via); - myAction.event = vpc; - viaData->pc << vpc; - viaData->actions << myAction; - QDeclarativeAction dummyAction; - QDeclarativeAction &xAction = pc->xIsSet() && i < actions.size()-1 ? actions[++i] : dummyAction; - QDeclarativeAction &yAction = pc->yIsSet() && i < actions.size()-1 ? actions[++i] : dummyAction; - QDeclarativeAction &sAction = pc->scaleIsSet() && i < actions.size()-1 ? actions[++i] : dummyAction; - QDeclarativeAction &rAction = pc->rotationIsSet() && i < actions.size()-1 ? actions[++i] : dummyAction; - QDeclarativeItem *target = pc->object(); - QDeclarativeItem *targetParent = action.reverseEvent ? pc->originalParent() : pc->parent(); - - //### this mirrors the logic in QDeclarativeParentChange. - bool ok; - const QTransform &transform = targetParent->itemTransform(d->via, &ok); - if (transform.type() >= QTransform::TxShear || !ok) { - qmlInfo(this) << QDeclarativeParentAnimation::tr("Unable to preserve appearance under complex transform"); - ok = false; - } - - qreal scale = 1; - qreal rotation = 0; - bool isRotate = (transform.type() == QTransform::TxRotate) || (transform.m11() < 0); - if (ok && !isRotate) { - if (transform.m11() == transform.m22()) - scale = transform.m11(); - else { - qmlInfo(this) << QDeclarativeParentAnimation::tr("Unable to preserve appearance under non-uniform scale"); - ok = false; - } - } else if (ok && isRotate) { - if (transform.m11() == transform.m22()) - scale = qSqrt(transform.m11()*transform.m11() + transform.m12()*transform.m12()); - else { - qmlInfo(this) << QDeclarativeParentAnimation::tr("Unable to preserve appearance under non-uniform scale"); - ok = false; - } - - if (scale != 0) - rotation = atan2(transform.m12()/scale, transform.m11()/scale) * 180/M_PI; - else { - qmlInfo(this) << QDeclarativeParentAnimation::tr("Unable to preserve appearance under scale of 0"); - ok = false; - } - } - - const QPointF &point = transform.map(QPointF(xAction.toValue.toReal(),yAction.toValue.toReal())); - qreal x = point.x(); - qreal y = point.y(); - if (ok && target->transformOrigin() != QDeclarativeItem::TopLeft) { - qreal w = target->width(); - qreal h = target->height(); - if (pc->widthIsSet() && i < actions.size() - 1) - w = actions[++i].toValue.toReal(); - if (pc->heightIsSet() && i < actions.size() - 1) - h = actions[++i].toValue.toReal(); - const QPointF &transformOrigin - = d->computeTransformOrigin(target->transformOrigin(), w,h); - qreal tempxt = transformOrigin.x(); - qreal tempyt = transformOrigin.y(); - QTransform t; - t.translate(-tempxt, -tempyt); - t.rotate(rotation); - t.scale(scale, scale); - t.translate(tempxt, tempyt); - const QPointF &offset = t.map(QPointF(0,0)); - x += offset.x(); - y += offset.y(); - } - - if (ok) { - //qDebug() << x << y << rotation << scale; - xAction.toValue = x; - yAction.toValue = y; - sAction.toValue = sAction.toValue.toReal() * scale; - rAction.toValue = rAction.toValue.toReal() + rotation; - } - } - } - } - - if (data->actions.count()) { - if (direction == QDeclarativeAbstractAnimation::Forward) { - d->startAction->setAnimAction(d->via ? viaData : data, QActionAnimation::DeleteWhenStopped); - d->endAction->setAnimAction(d->via ? data : 0, QActionAnimation::DeleteWhenStopped); - } else { - d->endAction->setAnimAction(d->via ? viaData : data, QActionAnimation::DeleteWhenStopped); - d->startAction->setAnimAction(d->via ? data : 0, QActionAnimation::DeleteWhenStopped); - } - if (!d->via) - delete viaData; - } else { - delete data; - delete viaData; - } - - //take care of any child animations - bool valid = d->defaultProperty.isValid(); - for (int ii = 0; ii < d->animations.count(); ++ii) { - if (valid) - d->animations.at(ii)->setDefaultTarget(d->defaultProperty); - d->animations.at(ii)->transition(actions, modified, direction); - } - -} - -QAbstractAnimation *QDeclarativeParentAnimation::qtAnimation() -{ - Q_D(QDeclarativeParentAnimation); - return d->topLevelGroup; -} - -/*! - \qmlclass AnchorAnimation QDeclarativeAnchorAnimation - \ingroup qml-animation-transition - \since 4.7 - \inherits Animation - \brief The AnchorAnimation element animates changes in anchor values. - - AnchorAnimation is used to animate an anchor change. - - In the following snippet we animate the addition of a right anchor to a \l Rectangle: - - \snippet doc/src/snippets/declarative/anchoranimation.qml 0 - - For convenience, when an AnchorAnimation is used in a \l Transition, it will - animate any AnchorChanges that have occurred during the state change. - This can be overridden by setting a specific target item using the - \l target property. - - Like any other animation element, an AnchorAnimation can be applied in a - number of ways, including transitions, behaviors and property value - sources. The \l {QML Animation and Transitions} documentation shows a - variety of methods for creating animations. - - \sa {QML Animation and Transitions}, AnchorChanges -*/ - -QDeclarativeAnchorAnimation::QDeclarativeAnchorAnimation(QObject *parent) -: QDeclarativeAbstractAnimation(*(new QDeclarativeAnchorAnimationPrivate), parent) -{ - Q_D(QDeclarativeAnchorAnimation); - d->va = new QDeclarativeBulkValueAnimator; - QDeclarative_setParent_noEvent(d->va, this); -} - -QDeclarativeAnchorAnimation::~QDeclarativeAnchorAnimation() -{ -} - -QAbstractAnimation *QDeclarativeAnchorAnimation::qtAnimation() -{ - Q_D(QDeclarativeAnchorAnimation); - return d->va; -} - -/*! - \qmlproperty list<Item> AnchorAnimation::targets - The items to reanchor. - - If no targets are specified all AnchorChanges will be - animated by the AnchorAnimation. -*/ -QDeclarativeListProperty<QDeclarativeItem> QDeclarativeAnchorAnimation::targets() -{ - Q_D(QDeclarativeAnchorAnimation); - return QDeclarativeListProperty<QDeclarativeItem>(this, d->targets); -} - -/*! - \qmlproperty int AnchorAnimation::duration - This property holds the duration of the animation, in milliseconds. - - The default value is 250. -*/ -int QDeclarativeAnchorAnimation::duration() const -{ - Q_D(const QDeclarativeAnchorAnimation); - return d->va->duration(); -} - -void QDeclarativeAnchorAnimation::setDuration(int duration) -{ - if (duration < 0) { - qmlInfo(this) << tr("Cannot set a duration of < 0"); - return; - } - - Q_D(QDeclarativeAnchorAnimation); - if (d->va->duration() == duration) - return; - d->va->setDuration(duration); - emit durationChanged(duration); -} - -/*! - \qmlproperty enumeration AnchorAnimation::easing.type - \qmlproperty real AnchorAnimation::easing.amplitude - \qmlproperty real AnchorAnimation::easing.overshoot - \qmlproperty real AnchorAnimation::easing.period - \brief the easing curve used for the animation. - - To specify an easing curve you need to specify at least the type. For some curves you can also specify - amplitude, period and/or overshoot. The default easing curve is - Linear. - - \qml - AnchorAnimation { easing.type: Easing.InOutQuad } - \endqml - - See the \l{PropertyAnimation::easing.type} documentation for information - about the different types of easing curves. -*/ - -QEasingCurve QDeclarativeAnchorAnimation::easing() const -{ - Q_D(const QDeclarativeAnchorAnimation); - return d->va->easingCurve(); -} - -void QDeclarativeAnchorAnimation::setEasing(const QEasingCurve &e) -{ - Q_D(QDeclarativeAnchorAnimation); - if (d->va->easingCurve() == e) - return; - - d->va->setEasingCurve(e); - emit easingChanged(e); -} - -void QDeclarativeAnchorAnimation::transition(QDeclarativeStateActions &actions, - QDeclarativeProperties &modified, - TransitionDirection direction) -{ - Q_UNUSED(modified); - Q_D(QDeclarativeAnchorAnimation); - QDeclarativeAnimationPropertyUpdater *data = new QDeclarativeAnimationPropertyUpdater; - data->interpolatorType = QMetaType::QReal; - data->interpolator = d->interpolator; - - data->reverse = direction == Backward ? true : false; - data->fromSourced = false; - data->fromDefined = false; - - for (int ii = 0; ii < actions.count(); ++ii) { - QDeclarativeAction &action = actions[ii]; - if (action.event && action.event->typeName() == QLatin1String("AnchorChanges") - && (d->targets.isEmpty() || d->targets.contains(static_cast<QDeclarativeAnchorChanges*>(action.event)->object()))) { - data->actions << static_cast<QDeclarativeAnchorChanges*>(action.event)->additionalActions(); - } - } - - if (data->actions.count()) { - if (!d->rangeIsSet) { - d->va->setStartValue(qreal(0)); - d->va->setEndValue(qreal(1)); - d->rangeIsSet = true; - } - d->va->setAnimValue(data, QAbstractAnimation::DeleteWhenStopped); - d->va->setFromSourcedValue(&data->fromSourced); - } else { - delete data; - } -} QDeclarativeScriptActionPrivate::QDeclarativeScriptActionPrivate() : QDeclarativeAbstractAnimationPrivate(), hasRunScriptScript(false), reversing(false), proxy(this), rsa(0) {} |