diff options
Diffstat (limited to 'src/declarative/util')
-rw-r--r-- | src/declarative/util/qdeclarativeanimation.cpp | 513 | ||||
-rw-r--r-- | src/declarative/util/qdeclarativeanimation_p.h | 69 | ||||
-rw-r--r-- | src/declarative/util/qdeclarativeanimation_p_p.h | 33 | ||||
-rw-r--r-- | src/declarative/util/qdeclarativepath.cpp | 922 | ||||
-rw-r--r-- | src/declarative/util/qdeclarativepath_p.h | 284 | ||||
-rw-r--r-- | src/declarative/util/qdeclarativepath_p_p.h (renamed from src/declarative/util/qdeclarativenullablevalue_p_p.h) | 46 | ||||
-rw-r--r-- | src/declarative/util/qdeclarativestateoperations.cpp | 1424 | ||||
-rw-r--r-- | src/declarative/util/qdeclarativestateoperations_p.h | 211 | ||||
-rw-r--r-- | src/declarative/util/qdeclarativeutilmodule.cpp | 128 | ||||
-rw-r--r-- | src/declarative/util/qdeclarativeutilmodule_p.h | 1 | ||||
-rw-r--r-- | src/declarative/util/qdeclarativeview.cpp | 737 | ||||
-rw-r--r-- | src/declarative/util/qdeclarativeview.h | 120 | ||||
-rw-r--r-- | src/declarative/util/util.pri | 6 |
13 files changed, 1274 insertions, 3220 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) {} diff --git a/src/declarative/util/qdeclarativeanimation_p.h b/src/declarative/util/qdeclarativeanimation_p.h index 09350ce61e..30f05ececa 100644 --- a/src/declarative/util/qdeclarativeanimation_p.h +++ b/src/declarative/util/qdeclarativeanimation_p.h @@ -235,7 +235,6 @@ protected: virtual QAbstractAnimation *qtAnimation(); }; -class QDeclarativeItem; class QDeclarativePropertyAnimationPrivate; class Q_AUTOTEST_EXPORT QDeclarativePropertyAnimation : public QDeclarativeAbstractAnimation { @@ -440,72 +439,6 @@ protected: virtual QAbstractAnimation *qtAnimation(); }; -class QDeclarativeParentAnimationPrivate; -class QDeclarativeParentAnimation : public QDeclarativeAnimationGroup -{ - Q_OBJECT - Q_DECLARE_PRIVATE(QDeclarativeParentAnimation) - - Q_PROPERTY(QDeclarativeItem *target READ target WRITE setTarget NOTIFY targetChanged) - Q_PROPERTY(QDeclarativeItem *newParent READ newParent WRITE setNewParent NOTIFY newParentChanged) - Q_PROPERTY(QDeclarativeItem *via READ via WRITE setVia NOTIFY viaChanged) - -public: - QDeclarativeParentAnimation(QObject *parent=0); - virtual ~QDeclarativeParentAnimation(); - - QDeclarativeItem *target() const; - void setTarget(QDeclarativeItem *); - - QDeclarativeItem *newParent() const; - void setNewParent(QDeclarativeItem *); - - QDeclarativeItem *via() const; - void setVia(QDeclarativeItem *); - -Q_SIGNALS: - void targetChanged(); - void newParentChanged(); - void viaChanged(); - -protected: - virtual void transition(QDeclarativeStateActions &actions, - QDeclarativeProperties &modified, - TransitionDirection direction); - virtual QAbstractAnimation *qtAnimation(); -}; - -class QDeclarativeAnchorAnimationPrivate; -class QDeclarativeAnchorAnimation : public QDeclarativeAbstractAnimation -{ - Q_OBJECT - Q_DECLARE_PRIVATE(QDeclarativeAnchorAnimation) - Q_PROPERTY(QDeclarativeListProperty<QDeclarativeItem> targets READ targets) - Q_PROPERTY(int duration READ duration WRITE setDuration NOTIFY durationChanged) - Q_PROPERTY(QEasingCurve easing READ easing WRITE setEasing NOTIFY easingChanged) - -public: - QDeclarativeAnchorAnimation(QObject *parent=0); - virtual ~QDeclarativeAnchorAnimation(); - - QDeclarativeListProperty<QDeclarativeItem> targets(); - - int duration() const; - void setDuration(int); - - QEasingCurve easing() const; - void setEasing(const QEasingCurve &); - -Q_SIGNALS: - void durationChanged(int); - void easingChanged(const QEasingCurve&); - -protected: - virtual void transition(QDeclarativeStateActions &actions, - QDeclarativeProperties &modified, - TransitionDirection direction); - virtual QAbstractAnimation *qtAnimation(); -}; QT_END_NAMESPACE @@ -520,8 +453,6 @@ QML_DECLARE_TYPE(QDeclarativeSequentialAnimation) QML_DECLARE_TYPE(QDeclarativeParallelAnimation) QML_DECLARE_TYPE(QDeclarativeVector3dAnimation) QML_DECLARE_TYPE(QDeclarativeRotationAnimation) -QML_DECLARE_TYPE(QDeclarativeParentAnimation) -QML_DECLARE_TYPE(QDeclarativeAnchorAnimation) QT_END_HEADER diff --git a/src/declarative/util/qdeclarativeanimation_p_p.h b/src/declarative/util/qdeclarativeanimation_p_p.h index 8e00b4b65a..b46475b5bd 100644 --- a/src/declarative/util/qdeclarativeanimation_p_p.h +++ b/src/declarative/util/qdeclarativeanimation_p_p.h @@ -59,7 +59,6 @@ #include "private/qdeclarativetimeline_p_p.h" #include <qdeclarative.h> -#include <qdeclarativeitem.h> #include <qdeclarativecontext.h> #include <QtCore/QPauseAnimation> @@ -344,38 +343,6 @@ public: QDeclarativeRotationAnimation::RotationDirection direction; }; -class QDeclarativeParentAnimationPrivate : public QDeclarativeAnimationGroupPrivate -{ - Q_DECLARE_PUBLIC(QDeclarativeParentAnimation) -public: - QDeclarativeParentAnimationPrivate() - : QDeclarativeAnimationGroupPrivate(), target(0), newParent(0), - via(0), topLevelGroup(0), startAction(0), endAction(0) {} - - QDeclarativeItem *target; - QDeclarativeItem *newParent; - QDeclarativeItem *via; - - QSequentialAnimationGroup *topLevelGroup; - QActionAnimation *startAction; - QActionAnimation *endAction; - - QPointF computeTransformOrigin(QDeclarativeItem::TransformOrigin origin, qreal width, qreal height) const; -}; - -class QDeclarativeAnchorAnimationPrivate : public QDeclarativeAbstractAnimationPrivate -{ - Q_DECLARE_PUBLIC(QDeclarativeAnchorAnimation) -public: - QDeclarativeAnchorAnimationPrivate() : rangeIsSet(false), va(0), - interpolator(QVariantAnimationPrivate::getInterpolator(QMetaType::QReal)) {} - - bool rangeIsSet; - QDeclarativeBulkValueAnimator *va; - QVariantAnimation::Interpolator interpolator; - QList<QDeclarativeItem*> targets; -}; - class Q_AUTOTEST_EXPORT QDeclarativeAnimationPropertyUpdater : public QDeclarativeBulkValueUpdater { public: diff --git a/src/declarative/util/qdeclarativepath.cpp b/src/declarative/util/qdeclarativepath.cpp new file mode 100644 index 0000000000..3437e82d30 --- /dev/null +++ b/src/declarative/util/qdeclarativepath.cpp @@ -0,0 +1,922 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "private/qdeclarativepath_p.h" +#include "private/qdeclarativepath_p_p.h" + +#include <QSet> +#include <QTime> + +#include <private/qbezier_p.h> +#include <QtCore/qmath.h> +#include <QtCore/qnumeric.h> + +QT_BEGIN_NAMESPACE + +/*! + \qmlclass PathElement QDeclarativePathElement + \ingroup qml-view-elements + \since 4.7 + \brief PathElement is the base path type. + + This type is the base for all path types. It cannot + be instantiated. + + \sa Path, PathAttribute, PathPercent, PathLine, PathQuad, PathCubic +*/ + +/*! + \qmlclass Path QDeclarativePath + \ingroup qml-view-elements + \since 4.7 + \brief A Path object defines a path for use by \l PathView. + + A Path is composed of one or more path segments - PathLine, PathQuad, + PathCubic. + + The spacing of the items along the Path can be adjusted via a + PathPercent object. + + PathAttribute allows named attributes with values to be defined + along the path. + + \sa PathView, PathAttribute, PathPercent, PathLine, PathQuad, PathCubic +*/ +QDeclarativePath::QDeclarativePath(QObject *parent) + : QObject(*(new QDeclarativePathPrivate), parent) +{ +} + +QDeclarativePath::~QDeclarativePath() +{ +} + +/*! + \qmlproperty real Path::startX + \qmlproperty real Path::startY + These properties hold the starting position of the path. +*/ +qreal QDeclarativePath::startX() const +{ + Q_D(const QDeclarativePath); + return d->startX; +} + +void QDeclarativePath::setStartX(qreal x) +{ + Q_D(QDeclarativePath); + if (qFuzzyCompare(x, d->startX)) + return; + d->startX = x; + emit startXChanged(); + processPath(); +} + +qreal QDeclarativePath::startY() const +{ + Q_D(const QDeclarativePath); + return d->startY; +} + +void QDeclarativePath::setStartY(qreal y) +{ + Q_D(QDeclarativePath); + if (qFuzzyCompare(y, d->startY)) + return; + d->startY = y; + emit startYChanged(); + processPath(); +} + +/*! + \qmlproperty bool Path::closed + This property holds whether the start and end of the path are identical. +*/ +bool QDeclarativePath::isClosed() const +{ + Q_D(const QDeclarativePath); + return d->closed; +} + +/*! + \qmlproperty list<PathElement> Path::pathElements + This property holds the objects composing the path. + + \default + + A path can contain the following path objects: + \list + \i \l PathLine - a straight line to a given position. + \i \l PathQuad - a quadratic Bezier curve to a given position with a control point. + \i \l PathCubic - a cubic Bezier curve to a given position with two control points. + \i \l PathAttribute - an attribute at a given position in the path. + \i \l PathPercent - a way to spread out items along various segments of the path. + \endlist + + \snippet doc/src/snippets/declarative/pathview/pathattributes.qml 2 +*/ + +QDeclarativeListProperty<QDeclarativePathElement> QDeclarativePath::pathElements() +{ + Q_D(QDeclarativePath); + return QDeclarativeListProperty<QDeclarativePathElement>(this, d->_pathElements); +} + +void QDeclarativePath::interpolate(int idx, const QString &name, qreal value) +{ + Q_D(QDeclarativePath); + if (!idx) + return; + + qreal lastValue = 0; + qreal lastPercent = 0; + int search = idx - 1; + while(search >= 0) { + const AttributePoint &point = d->_attributePoints.at(search); + if (point.values.contains(name)) { + lastValue = point.values.value(name); + lastPercent = point.origpercent; + break; + } + --search; + } + + ++search; + + const AttributePoint &curPoint = d->_attributePoints.at(idx); + + for (int ii = search; ii < idx; ++ii) { + AttributePoint &point = d->_attributePoints[ii]; + + qreal val = lastValue + (value - lastValue) * (point.origpercent - lastPercent) / (curPoint.origpercent - lastPercent); + point.values.insert(name, val); + } +} + +void QDeclarativePath::endpoint(const QString &name) +{ + Q_D(QDeclarativePath); + const AttributePoint &first = d->_attributePoints.first(); + qreal val = first.values.value(name); + for (int ii = d->_attributePoints.count() - 1; ii >= 0; ii--) { + const AttributePoint &point = d->_attributePoints.at(ii); + if (point.values.contains(name)) { + for (int jj = ii + 1; jj < d->_attributePoints.count(); ++jj) { + AttributePoint &setPoint = d->_attributePoints[jj]; + setPoint.values.insert(name, val); + } + return; + } + } +} + +void QDeclarativePath::processPath() +{ + Q_D(QDeclarativePath); + + if (!d->componentComplete) + return; + + d->_pointCache.clear(); + d->_attributePoints.clear(); + d->_path = QPainterPath(); + + AttributePoint first; + for (int ii = 0; ii < d->_attributes.count(); ++ii) + first.values[d->_attributes.at(ii)] = 0; + d->_attributePoints << first; + + d->_path.moveTo(d->startX, d->startY); + + QDeclarativeCurve *lastCurve = 0; + foreach (QDeclarativePathElement *pathElement, d->_pathElements) { + if (QDeclarativeCurve *curve = qobject_cast<QDeclarativeCurve *>(pathElement)) { + curve->addToPath(d->_path); + AttributePoint p; + p.origpercent = d->_path.length(); + d->_attributePoints << p; + lastCurve = curve; + } else if (QDeclarativePathAttribute *attribute = qobject_cast<QDeclarativePathAttribute *>(pathElement)) { + AttributePoint &point = d->_attributePoints.last(); + point.values[attribute->name()] = attribute->value(); + interpolate(d->_attributePoints.count() - 1, attribute->name(), attribute->value()); + } else if (QDeclarativePathPercent *percent = qobject_cast<QDeclarativePathPercent *>(pathElement)) { + AttributePoint &point = d->_attributePoints.last(); + point.values[QLatin1String("_qfx_percent")] = percent->value(); + interpolate(d->_attributePoints.count() - 1, QLatin1String("_qfx_percent"), percent->value()); + } + } + + // Fixup end points + const AttributePoint &last = d->_attributePoints.last(); + for (int ii = 0; ii < d->_attributes.count(); ++ii) { + if (!last.values.contains(d->_attributes.at(ii))) + endpoint(d->_attributes.at(ii)); + } + + // Adjust percent + qreal length = d->_path.length(); + qreal prevpercent = 0; + qreal prevorigpercent = 0; + for (int ii = 0; ii < d->_attributePoints.count(); ++ii) { + const AttributePoint &point = d->_attributePoints.at(ii); + if (point.values.contains(QLatin1String("_qfx_percent"))) { //special string for QDeclarativePathPercent + if ( ii > 0) { + qreal scale = (d->_attributePoints[ii].origpercent/length - prevorigpercent) / + (point.values.value(QLatin1String("_qfx_percent"))-prevpercent); + d->_attributePoints[ii].scale = scale; + } + d->_attributePoints[ii].origpercent /= length; + d->_attributePoints[ii].percent = point.values.value(QLatin1String("_qfx_percent")); + prevorigpercent = d->_attributePoints[ii].origpercent; + prevpercent = d->_attributePoints[ii].percent; + } else { + d->_attributePoints[ii].origpercent /= length; + d->_attributePoints[ii].percent = d->_attributePoints[ii].origpercent; + } + } + + d->closed = lastCurve && d->startX == lastCurve->x() && d->startY == lastCurve->y(); + + emit changed(); +} + +void QDeclarativePath::classBegin() +{ + Q_D(QDeclarativePath); + d->componentComplete = false; +} + +void QDeclarativePath::componentComplete() +{ + Q_D(QDeclarativePath); + QSet<QString> attrs; + d->componentComplete = true; + + // First gather up all the attributes + foreach (QDeclarativePathElement *pathElement, d->_pathElements) { + if (QDeclarativePathAttribute *attribute = + qobject_cast<QDeclarativePathAttribute *>(pathElement)) + attrs.insert(attribute->name()); + } + d->_attributes = attrs.toList(); + + processPath(); + + foreach (QDeclarativePathElement *pathElement, d->_pathElements) + connect(pathElement, SIGNAL(changed()), this, SLOT(processPath())); +} + +QPainterPath QDeclarativePath::path() const +{ + Q_D(const QDeclarativePath); + return d->_path; +} + +QStringList QDeclarativePath::attributes() const +{ + Q_D(const QDeclarativePath); + if (!d->componentComplete) { + QSet<QString> attrs; + + // First gather up all the attributes + foreach (QDeclarativePathElement *pathElement, d->_pathElements) { + if (QDeclarativePathAttribute *attribute = + qobject_cast<QDeclarativePathAttribute *>(pathElement)) + attrs.insert(attribute->name()); + } + return attrs.toList(); + } + return d->_attributes; +} + +static inline QBezier nextBezier(const QPainterPath &path, int *from, qreal *bezLength) +{ + const int lastElement = path.elementCount() - 1; + for (int i=*from; i <= lastElement; ++i) { + const QPainterPath::Element &e = path.elementAt(i); + + switch (e.type) { + case QPainterPath::MoveToElement: + break; + case QPainterPath::LineToElement: + { + QLineF line(path.elementAt(i-1), e); + *bezLength = line.length(); + QPointF a = path.elementAt(i-1); + QPointF delta = e - a; + *from = i+1; + return QBezier::fromPoints(a, a + delta / 3, a + 2 * delta / 3, e); + } + case QPainterPath::CurveToElement: + { + QBezier b = QBezier::fromPoints(path.elementAt(i-1), + e, + path.elementAt(i+1), + path.elementAt(i+2)); + *bezLength = b.length(); + *from = i+3; + return b; + } + default: + break; + } + } + *from = lastElement; + *bezLength = 0; + return QBezier(); +} + +void QDeclarativePath::createPointCache() const +{ + Q_D(const QDeclarativePath); + qreal pathLength = d->_path.length(); + if (pathLength <= 0 || qIsNaN(pathLength)) + return; + // more points means less jitter between items as they move along the + // path, but takes longer to generate + const int points = qCeil(pathLength*5); + const int lastElement = d->_path.elementCount() - 1; + d->_pointCache.resize(points+1); + + int currElement = 0; + qreal bezLength = 0; + QBezier currBez = nextBezier(d->_path, &currElement, &bezLength); + qreal currLength = bezLength; + qreal epc = currLength / pathLength; + + for (int i = 0; i < d->_pointCache.size(); i++) { + //find which set we are in + qreal prevPercent = 0; + qreal prevOrigPercent = 0; + for (int ii = 0; ii < d->_attributePoints.count(); ++ii) { + qreal percent = qreal(i)/points; + const AttributePoint &point = d->_attributePoints.at(ii); + if (percent < point.percent || ii == d->_attributePoints.count() - 1) { //### || is special case for very last item + qreal elementPercent = (percent - prevPercent); + + qreal spc = prevOrigPercent + elementPercent * point.scale; + + while (spc > epc) { + if (currElement > lastElement) + break; + currBez = nextBezier(d->_path, &currElement, &bezLength); + if (bezLength == 0.0) { + currLength = pathLength; + epc = 1.0; + break; + } + currLength += bezLength; + epc = currLength / pathLength; + } + qreal realT = (pathLength * spc - (currLength - bezLength)) / bezLength; + d->_pointCache[i] = currBez.pointAt(qBound(qreal(0), realT, qreal(1))); + break; + } + prevOrigPercent = point.origpercent; + prevPercent = point.percent; + } + } +} + +QPointF QDeclarativePath::pointAt(qreal p) const +{ + Q_D(const QDeclarativePath); + if (d->_pointCache.isEmpty()) { + createPointCache(); + if (d->_pointCache.isEmpty()) + return QPointF(); + } + int idx = qRound(p*d->_pointCache.size()); + if (idx >= d->_pointCache.size()) + idx = d->_pointCache.size() - 1; + else if (idx < 0) + idx = 0; + return d->_pointCache.at(idx); +} + +qreal QDeclarativePath::attributeAt(const QString &name, qreal percent) const +{ + Q_D(const QDeclarativePath); + if (percent < 0 || percent > 1) + return 0; + + for (int ii = 0; ii < d->_attributePoints.count(); ++ii) { + const AttributePoint &point = d->_attributePoints.at(ii); + + if (point.percent == percent) { + return point.values.value(name); + } else if (point.percent > percent) { + qreal lastValue = + ii?(d->_attributePoints.at(ii - 1).values.value(name)):0; + qreal lastPercent = + ii?(d->_attributePoints.at(ii - 1).percent):0; + qreal curValue = point.values.value(name); + qreal curPercent = point.percent; + + return lastValue + (curValue - lastValue) * (percent - lastPercent) / (curPercent - lastPercent); + } + } + + return 0; +} + +/****************************************************************************/ + +qreal QDeclarativeCurve::x() const +{ + return _x; +} + +void QDeclarativeCurve::setX(qreal x) +{ + if (_x != x) { + _x = x; + emit xChanged(); + emit changed(); + } +} + +qreal QDeclarativeCurve::y() const +{ + return _y; +} + +void QDeclarativeCurve::setY(qreal y) +{ + if (_y != y) { + _y = y; + emit yChanged(); + emit changed(); + } +} + +/****************************************************************************/ + +/*! + \qmlclass PathAttribute QDeclarativePathAttribute + \ingroup qml-view-elements + \since 4.7 + \brief The PathAttribute allows setting an attribute at a given position in a Path. + + The PathAttribute object allows attributes consisting of a name and + a value to be specified for various points along a path. The + attributes are exposed to the delegate as + \l{qdeclarativeintroduction.html#attached-properties} {Attached Properties}. + The value of an attribute at any particular point along the path is interpolated + from the PathAttributes bounding that point. + + The example below shows a path with the items scaled to 30% with + opacity 50% at the top of the path and scaled 100% with opacity + 100% at the bottom. Note the use of the PathView.iconScale and + PathView.iconOpacity attached properties to set the scale and opacity + of the delegate. + + \table + \row + \o \image declarative-pathattribute.png + \o + \snippet doc/src/snippets/declarative/pathview/pathattributes.qml 0 + (see the PathView documentation for the specification of ContactModel.qml + used for ContactModel above.) + \endtable + + + \sa Path +*/ + +/*! + \qmlproperty string PathAttribute::name + This property holds the name of the attribute to change. + + This attribute will be available to the delegate as PathView.<name> + + Note that using an existing Item property name such as "opacity" as an + attribute is allowed. This is because path attributes add a new + \l{qdeclarativeintroduction.html#attached-properties} {Attached Property} + which in no way clashes with existing properties. +*/ + +/*! + the name of the attribute to change. +*/ + +QString QDeclarativePathAttribute::name() const +{ + return _name; +} + +void QDeclarativePathAttribute::setName(const QString &name) +{ + if (_name == name) + return; + _name = name; + emit nameChanged(); +} + +/*! + \qmlproperty real PathAttribute::value + This property holds the value for the attribute. + + The value specified can be used to influence the visual appearance + of an item along the path. For example, the following Path specifies + an attribute named \e itemRotation, which has the value \e 0 at the + beginning of the path, and the value 90 at the end of the path. + + \qml + Path { + startX: 0 + startY: 0 + PathAttribute { name: "itemRotation"; value: 0 } + PathLine { x: 100; y: 100 } + PathAttribute { name: "itemRotation"; value: 90 } + } + \endqml + + In our delegate, we can then bind the \e rotation property to the + \l{qdeclarativeintroduction.html#attached-properties} {Attached Property} + \e PathView.itemRotation created for this attribute. + + \qml + Rectangle { + width: 10; height: 10 + rotation: PathView.itemRotation + } + \endqml + + As each item is positioned along the path, it will be rotated accordingly: + an item at the beginning of the path with be not be rotated, an item at + the end of the path will be rotated 90 degrees, and an item mid-way along + the path will be rotated 45 degrees. +*/ + +/*! + the new value of the attribute. +*/ +qreal QDeclarativePathAttribute::value() const +{ + return _value; +} + +void QDeclarativePathAttribute::setValue(qreal value) +{ + if (_value != value) { + _value = value; + emit valueChanged(); + emit changed(); + } +} + +/****************************************************************************/ + +/*! + \qmlclass PathLine QDeclarativePathLine + \ingroup qml-view-elements + \since 4.7 + \brief The PathLine defines a straight line. + + The example below creates a path consisting of a straight line from + 0,100 to 200,100: + + \qml + Path { + startX: 0; startY: 100 + PathLine { x: 200; y: 100 } + } + \endqml + + \sa Path, PathQuad, PathCubic +*/ + +/*! + \qmlproperty real PathLine::x + \qmlproperty real PathLine::y + + Defines the end point of the line. +*/ + +void QDeclarativePathLine::addToPath(QPainterPath &path) +{ + path.lineTo(x(), y()); +} + +/****************************************************************************/ + +/*! + \qmlclass PathQuad QDeclarativePathQuad + \ingroup qml-view-elements + \since 4.7 + \brief The PathQuad defines a quadratic Bezier curve with a control point. + + The following QML produces the path shown below: + \table + \row + \o \image declarative-pathquad.png + \o + \qml + Path { + startX: 0; startY: 0 + PathQuad { x: 200; y: 0; controlX: 100; controlY: 150 } + } + \endqml + \endtable + + \sa Path, PathCubic, PathLine +*/ + +/*! + \qmlproperty real PathQuad::x + \qmlproperty real PathQuad::y + + Defines the end point of the curve. +*/ + +/*! + \qmlproperty real PathQuad::controlX + \qmlproperty real PathQuad::controlY + + Defines the position of the control point. +*/ + +/*! + the x position of the control point. +*/ +qreal QDeclarativePathQuad::controlX() const +{ + return _controlX; +} + +void QDeclarativePathQuad::setControlX(qreal x) +{ + if (_controlX != x) { + _controlX = x; + emit controlXChanged(); + emit changed(); + } +} + + +/*! + the y position of the control point. +*/ +qreal QDeclarativePathQuad::controlY() const +{ + return _controlY; +} + +void QDeclarativePathQuad::setControlY(qreal y) +{ + if (_controlY != y) { + _controlY = y; + emit controlYChanged(); + emit changed(); + } +} + +void QDeclarativePathQuad::addToPath(QPainterPath &path) +{ + path.quadTo(controlX(), controlY(), x(), y()); +} + +/****************************************************************************/ + +/*! + \qmlclass PathCubic QDeclarativePathCubic + \ingroup qml-view-elements + \since 4.7 + \brief The PathCubic defines a cubic Bezier curve with two control points. + + The following QML produces the path shown below: + \table + \row + \o \image declarative-pathcubic.png + \o + \qml + Path { + startX: 20; startY: 0 + PathCubic { + x: 180; y: 0 + control1X: -10; control1Y: 90 + control2X: 210; control2Y: 90 + } + } + \endqml + \endtable + + \sa Path, PathQuad, PathLine +*/ + +/*! + \qmlproperty real PathCubic::x + \qmlproperty real PathCubic::y + + Defines the end point of the curve. +*/ + +/*! + \qmlproperty real PathCubic::control1X + \qmlproperty real PathCubic::control1Y + + Defines the position of the first control point. +*/ +qreal QDeclarativePathCubic::control1X() const +{ + return _control1X; +} + +void QDeclarativePathCubic::setControl1X(qreal x) +{ + if (_control1X != x) { + _control1X = x; + emit control1XChanged(); + emit changed(); + } +} + +qreal QDeclarativePathCubic::control1Y() const +{ + return _control1Y; +} + +void QDeclarativePathCubic::setControl1Y(qreal y) +{ + if (_control1Y != y) { + _control1Y = y; + emit control1YChanged(); + emit changed(); + } +} + +/*! + \qmlproperty real PathCubic::control2X + \qmlproperty real PathCubic::control2Y + + Defines the position of the second control point. +*/ +qreal QDeclarativePathCubic::control2X() const +{ + return _control2X; +} + +void QDeclarativePathCubic::setControl2X(qreal x) +{ + if (_control2X != x) { + _control2X = x; + emit control2XChanged(); + emit changed(); + } +} + +qreal QDeclarativePathCubic::control2Y() const +{ + return _control2Y; +} + +void QDeclarativePathCubic::setControl2Y(qreal y) +{ + if (_control2Y != y) { + _control2Y = y; + emit control2YChanged(); + emit changed(); + } +} + +void QDeclarativePathCubic::addToPath(QPainterPath &path) +{ + path.cubicTo(control1X(), control1Y(), control2X(), control2Y(), x(), y()); +} + +/****************************************************************************/ + +/*! + \qmlclass PathPercent QDeclarativePathPercent + \ingroup qml-view-elements + \since 4.7 + \brief The PathPercent manipulates the way a path is interpreted. + + PathPercent allows you to manipulate the spacing between items on a + PathView's path. You can use it to bunch together items on part of + the path, and spread them out on other parts of the path. + + The examples below show the normal distrubution of items along a path + compared to a distribution which places 50% of the items along the + PathLine section of the path. + \table + \row + \o \image declarative-nopercent.png + \o + \qml + PathView { + // ... + Path { + startX: 20; startY: 0 + PathQuad { x: 50; y: 80; controlX: 0; controlY: 80 } + PathLine { x: 150; y: 80 } + PathQuad { x: 180; y: 0; controlX: 200; controlY: 80 } + } + } + \endqml + \row + \o \image declarative-percent.png + \o + \qml + PathView { + // ... + Path { + startX: 20; startY: 0 + PathQuad { x: 50; y: 80; controlX: 0; controlY: 80 } + PathPercent { value: 0.25 } + PathLine { x: 150; y: 80 } + PathPercent { value: 0.75 } + PathQuad { x: 180; y: 0; controlX: 200; controlY: 80 } + PathPercent { value: 1 } + } + } + \endqml + \endtable + + \sa Path +*/ + +/*! + \qmlproperty real PathPercent::value + The proporation of items that should be laid out up to this point. + + This value should always be higher than the last value specified + by a PathPercent at a previous position in the Path. + + In the following example we have a Path made up of three PathLines. + Normally, the items of the PathView would be laid out equally along + this path, with an equal number of items per line segment. PathPercent + allows us to specify that the first and third lines should each hold + 10% of the laid out items, while the second line should hold the remaining + 80%. + + \qml + PathView { + // ... + Path { + startX: 0; startY: 0 + PathLine { x:100; y: 0; } + PathPercent { value: 0.1 } + PathLine { x: 100; y: 100 } + PathPercent { value: 0.9 } + PathLine { x: 100; y: 0 } + PathPercent { value: 1 } + } + } + \endqml +*/ + +qreal QDeclarativePathPercent::value() const +{ + return _value; +} + +void QDeclarativePathPercent::setValue(qreal value) +{ + if (_value != value) { + _value = value; + emit valueChanged(); + emit changed(); + } +} +QT_END_NAMESPACE diff --git a/src/declarative/util/qdeclarativepath_p.h b/src/declarative/util/qdeclarativepath_p.h new file mode 100644 index 0000000000..c8420eb996 --- /dev/null +++ b/src/declarative/util/qdeclarativepath_p.h @@ -0,0 +1,284 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QDECLARATIVEPATH_H +#define QDECLARATIVEPATH_H + +#include <qdeclarative.h> + +#include <QtCore/QObject> +#include <QtGui/QPainterPath> + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) +class Q_AUTOTEST_EXPORT QDeclarativePathElement : public QObject +{ + Q_OBJECT +public: + QDeclarativePathElement(QObject *parent=0) : QObject(parent) {} +Q_SIGNALS: + void changed(); +}; + +class Q_AUTOTEST_EXPORT QDeclarativePathAttribute : public QDeclarativePathElement +{ + Q_OBJECT + + Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) + Q_PROPERTY(qreal value READ value WRITE setValue NOTIFY valueChanged) +public: + QDeclarativePathAttribute(QObject *parent=0) : QDeclarativePathElement(parent), _value(0) {} + + + QString name() const; + void setName(const QString &name); + + qreal value() const; + void setValue(qreal value); + +Q_SIGNALS: + void nameChanged(); + void valueChanged(); + +private: + QString _name; + qreal _value; +}; + +class Q_AUTOTEST_EXPORT QDeclarativeCurve : public QDeclarativePathElement +{ + Q_OBJECT + + Q_PROPERTY(qreal x READ x WRITE setX NOTIFY xChanged) + Q_PROPERTY(qreal y READ y WRITE setY NOTIFY yChanged) +public: + QDeclarativeCurve(QObject *parent=0) : QDeclarativePathElement(parent), _x(0), _y(0) {} + + qreal x() const; + void setX(qreal x); + + qreal y() const; + void setY(qreal y); + + virtual void addToPath(QPainterPath &) {} + +Q_SIGNALS: + void xChanged(); + void yChanged(); + +private: + qreal _x; + qreal _y; +}; + +class Q_AUTOTEST_EXPORT QDeclarativePathLine : public QDeclarativeCurve +{ + Q_OBJECT +public: + QDeclarativePathLine(QObject *parent=0) : QDeclarativeCurve(parent) {} + + void addToPath(QPainterPath &path); +}; + +class Q_AUTOTEST_EXPORT QDeclarativePathQuad : public QDeclarativeCurve +{ + Q_OBJECT + + Q_PROPERTY(qreal controlX READ controlX WRITE setControlX NOTIFY controlXChanged) + Q_PROPERTY(qreal controlY READ controlY WRITE setControlY NOTIFY controlYChanged) +public: + QDeclarativePathQuad(QObject *parent=0) : QDeclarativeCurve(parent), _controlX(0), _controlY(0) {} + + qreal controlX() const; + void setControlX(qreal x); + + qreal controlY() const; + void setControlY(qreal y); + + void addToPath(QPainterPath &path); + +Q_SIGNALS: + void controlXChanged(); + void controlYChanged(); + +private: + qreal _controlX; + qreal _controlY; +}; + +class Q_AUTOTEST_EXPORT QDeclarativePathCubic : public QDeclarativeCurve +{ + Q_OBJECT + + Q_PROPERTY(qreal control1X READ control1X WRITE setControl1X NOTIFY control1XChanged) + Q_PROPERTY(qreal control1Y READ control1Y WRITE setControl1Y NOTIFY control1YChanged) + Q_PROPERTY(qreal control2X READ control2X WRITE setControl2X NOTIFY control2XChanged) + Q_PROPERTY(qreal control2Y READ control2Y WRITE setControl2Y NOTIFY control2YChanged) +public: + QDeclarativePathCubic(QObject *parent=0) : QDeclarativeCurve(parent), _control1X(0), _control1Y(0), _control2X(0), _control2Y(0) {} + + qreal control1X() const; + void setControl1X(qreal x); + + qreal control1Y() const; + void setControl1Y(qreal y); + + qreal control2X() const; + void setControl2X(qreal x); + + qreal control2Y() const; + void setControl2Y(qreal y); + + void addToPath(QPainterPath &path); + +Q_SIGNALS: + void control1XChanged(); + void control1YChanged(); + void control2XChanged(); + void control2YChanged(); + +private: + qreal _control1X; + qreal _control1Y; + qreal _control2X; + qreal _control2Y; +}; + +class Q_AUTOTEST_EXPORT QDeclarativePathPercent : public QDeclarativePathElement +{ + Q_OBJECT + Q_PROPERTY(qreal value READ value WRITE setValue NOTIFY valueChanged) +public: + QDeclarativePathPercent(QObject *parent=0) : QDeclarativePathElement(parent) {} + + qreal value() const; + void setValue(qreal value); + +signals: + void valueChanged(); + +private: + qreal _value; +}; + +class QDeclarativePathPrivate; +class Q_AUTOTEST_EXPORT QDeclarativePath : public QObject, public QDeclarativeParserStatus +{ + Q_OBJECT + + Q_INTERFACES(QDeclarativeParserStatus) + Q_PROPERTY(QDeclarativeListProperty<QDeclarativePathElement> pathElements READ pathElements) + Q_PROPERTY(qreal startX READ startX WRITE setStartX NOTIFY startXChanged) + Q_PROPERTY(qreal startY READ startY WRITE setStartY NOTIFY startYChanged) + Q_PROPERTY(bool closed READ isClosed NOTIFY changed) + Q_CLASSINFO("DefaultProperty", "pathElements") + Q_INTERFACES(QDeclarativeParserStatus) +public: + QDeclarativePath(QObject *parent=0); + ~QDeclarativePath(); + + QDeclarativeListProperty<QDeclarativePathElement> pathElements(); + + qreal startX() const; + void setStartX(qreal x); + + qreal startY() const; + void setStartY(qreal y); + + bool isClosed() const; + + QPainterPath path() const; + QStringList attributes() const; + qreal attributeAt(const QString &, qreal) const; + QPointF pointAt(qreal) const; + +Q_SIGNALS: + void changed(); + void startXChanged(); + void startYChanged(); + +protected: + virtual void componentComplete(); + virtual void classBegin(); + +private Q_SLOTS: + void processPath(); + +private: + struct AttributePoint { + AttributePoint() : percent(0), scale(1), origpercent(0) {} + AttributePoint(const AttributePoint &other) + : percent(other.percent), scale(other.scale), origpercent(other.origpercent), values(other.values) {} + AttributePoint &operator=(const AttributePoint &other) { + percent = other.percent; scale = other.scale; origpercent = other.origpercent; values = other.values; return *this; + } + qreal percent; //massaged percent along the painter path + qreal scale; + qreal origpercent; //'real' percent along the painter path + QHash<QString, qreal> values; + }; + + void interpolate(int idx, const QString &name, qreal value); + void endpoint(const QString &name); + void createPointCache() const; + +private: + Q_DISABLE_COPY(QDeclarativePath) + Q_DECLARE_PRIVATE(QDeclarativePath) +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QDeclarativePathElement) +QML_DECLARE_TYPE(QDeclarativePathAttribute) +QML_DECLARE_TYPE(QDeclarativeCurve) +QML_DECLARE_TYPE(QDeclarativePathLine) +QML_DECLARE_TYPE(QDeclarativePathQuad) +QML_DECLARE_TYPE(QDeclarativePathCubic) +QML_DECLARE_TYPE(QDeclarativePathPercent) +QML_DECLARE_TYPE(QDeclarativePath) + +QT_END_HEADER + +#endif // QDECLARATIVEPATH_H diff --git a/src/declarative/util/qdeclarativenullablevalue_p_p.h b/src/declarative/util/qdeclarativepath_p_p.h index 630f39d446..4e407eca35 100644 --- a/src/declarative/util/qdeclarativenullablevalue_p_p.h +++ b/src/declarative/util/qdeclarativepath_p_p.h @@ -39,8 +39,8 @@ ** ****************************************************************************/ -#ifndef QDECLARATIVENULLABLEVALUE_P_H -#define QDECLARATIVENULLABLEVALUE_P_H +#ifndef QDECLARATIVEPATH_P_H +#define QDECLARATIVEPATH_P_H // // W A R N I N G @@ -53,29 +53,31 @@ // We mean it. // -QT_BEGIN_NAMESPACE +#include "private/qdeclarativepath_p.h" + +#include <qdeclarative.h> + +#include <qstringlist.h> +#include <private/qobject_p.h> -template<typename T> -struct QDeclarativeNullableValue +QT_BEGIN_NAMESPACE +class QDeclarativePathPrivate : public QObjectPrivate { - QDeclarativeNullableValue() - : isNull(true), value(T()) {} - QDeclarativeNullableValue(const QDeclarativeNullableValue<T> &o) - : isNull(o.isNull), value(o.value) {} - QDeclarativeNullableValue(const T &t) - : isNull(false), value(t) {} - QDeclarativeNullableValue<T> &operator=(const T &t) - { isNull = false; value = t; return *this; } - QDeclarativeNullableValue<T> &operator=(const QDeclarativeNullableValue<T> &o) - { isNull = o.isNull; value = o.value; return *this; } - operator T() const { return value; } + Q_DECLARE_PUBLIC(QDeclarativePath) + +public: + QDeclarativePathPrivate() : startX(0), startY(0), closed(false), componentComplete(true) { } - void invalidate() { isNull = true; } - bool isValid() const { return !isNull; } - bool isNull; - T value; + QPainterPath _path; + QList<QDeclarativePathElement*> _pathElements; + mutable QVector<QPointF> _pointCache; + QList<QDeclarativePath::AttributePoint> _attributePoints; + QStringList _attributes; + int startX; + int startY; + bool closed; + bool componentComplete; }; QT_END_NAMESPACE - -#endif // QDECLARATIVENULLABLEVALUE_P_H +#endif diff --git a/src/declarative/util/qdeclarativestateoperations.cpp b/src/declarative/util/qdeclarativestateoperations.cpp index c260684eef..0ced8ebd61 100644 --- a/src/declarative/util/qdeclarativestateoperations.cpp +++ b/src/declarative/util/qdeclarativestateoperations.cpp @@ -45,8 +45,6 @@ #include <qdeclarativecontext.h> #include <qdeclarativeexpression.h> #include <qdeclarativeinfo.h> -#include <qdeclarativeanchors_p_p.h> -#include <qdeclarativeitem_p.h> #include <qdeclarativeguard_p.h> #include <qdeclarativenullablevalue_p_p.h> #include "private/qdeclarativecontext_p.h" @@ -62,532 +60,6 @@ QT_BEGIN_NAMESPACE -class QDeclarativeParentChangePrivate : public QDeclarativeStateOperationPrivate -{ - Q_DECLARE_PUBLIC(QDeclarativeParentChange) -public: - QDeclarativeParentChangePrivate() : target(0), parent(0), origParent(0), origStackBefore(0), - rewindParent(0), rewindStackBefore(0) {} - - QDeclarativeItem *target; - QDeclarativeGuard<QDeclarativeItem> parent; - QDeclarativeGuard<QDeclarativeItem> origParent; - QDeclarativeGuard<QDeclarativeItem> origStackBefore; - QDeclarativeItem *rewindParent; - QDeclarativeItem *rewindStackBefore; - - QDeclarativeNullableValue<QDeclarativeScriptString> xString; - QDeclarativeNullableValue<QDeclarativeScriptString> yString; - QDeclarativeNullableValue<QDeclarativeScriptString> widthString; - QDeclarativeNullableValue<QDeclarativeScriptString> heightString; - QDeclarativeNullableValue<QDeclarativeScriptString> scaleString; - QDeclarativeNullableValue<QDeclarativeScriptString> rotationString; - - QDeclarativeNullableValue<qreal> x; - QDeclarativeNullableValue<qreal> y; - QDeclarativeNullableValue<qreal> width; - QDeclarativeNullableValue<qreal> height; - QDeclarativeNullableValue<qreal> scale; - QDeclarativeNullableValue<qreal> rotation; - - void doChange(QDeclarativeItem *targetParent, QDeclarativeItem *stackBefore = 0); -}; - -void QDeclarativeParentChangePrivate::doChange(QDeclarativeItem *targetParent, QDeclarativeItem *stackBefore) -{ - if (targetParent && target && target->parentItem()) { - Q_Q(QDeclarativeParentChange); - bool ok; - const QTransform &transform = target->parentItem()->itemTransform(targetParent, &ok); - if (transform.type() >= QTransform::TxShear || !ok) { - qmlInfo(q) << QDeclarativeParentChange::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(q) << QDeclarativeParentChange::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(q) << QDeclarativeParentChange::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(q) << QDeclarativeParentChange::tr("Unable to preserve appearance under scale of 0"); - ok = false; - } - } - - const QPointF &point = transform.map(QPointF(target->x(),target->y())); - qreal x = point.x(); - qreal y = point.y(); - - // setParentItem will update the transformOriginPoint if needed - target->setParentItem(targetParent); - - if (ok && target->transformOrigin() != QDeclarativeItem::TopLeft) { - qreal tempxt = target->transformOriginPoint().x(); - qreal tempyt = target->transformOriginPoint().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; - target->setX(x); - target->setY(y); - target->setRotation(target->rotation() + rotation); - target->setScale(target->scale() * scale); - } - } else if (target) { - target->setParentItem(targetParent); - } - - //restore the original stack position. - //### if stackBefore has also been reparented this won't work - if (stackBefore) - target->stackBefore(stackBefore); -} - -/*! - \preliminary - \qmlclass ParentChange QDeclarativeParentChange - \ingroup qml-state-elements - \brief The ParentChange element allows you to reparent an Item in a state change. - - ParentChange reparents an item while preserving its visual appearance (position, size, - rotation, and scale) on screen. You can then specify a transition to move/resize/rotate/scale - the item to its final intended appearance. - - ParentChange can only preserve visual appearance if no complex transforms are involved. - More specifically, it will not work if the transform property has been set for any - items involved in the reparenting (i.e. items in the common ancestor tree - for the original and new parent). - - The example below displays a large red rectangle and a small blue rectangle, side by side. - When the \c blueRect is clicked, it changes to the "reparented" state: its parent is changed to \c redRect and it is - positioned at (10, 10) within the red rectangle, as specified in the ParentChange. - - \snippet doc/src/snippets/declarative/parentchange.qml 0 - - \image parentchange.png - - You can specify at which point in a transition you want a ParentChange to occur by - using a ParentAnimation. -*/ - - -QDeclarativeParentChange::QDeclarativeParentChange(QObject *parent) - : QDeclarativeStateOperation(*(new QDeclarativeParentChangePrivate), parent) -{ -} - -QDeclarativeParentChange::~QDeclarativeParentChange() -{ -} - -/*! - \qmlproperty real ParentChange::x - \qmlproperty real ParentChange::y - \qmlproperty real ParentChange::width - \qmlproperty real ParentChange::height - \qmlproperty real ParentChange::scale - \qmlproperty real ParentChange::rotation - These properties hold the new position, size, scale, and rotation - for the item in this state. -*/ -QDeclarativeScriptString QDeclarativeParentChange::x() const -{ - Q_D(const QDeclarativeParentChange); - return d->xString.value; -} - -void tryReal(QDeclarativeNullableValue<qreal> &value, const QString &string) -{ - bool ok = false; - qreal realValue = string.toFloat(&ok); - if (ok) - value = realValue; - else - value.invalidate(); -} - -void QDeclarativeParentChange::setX(QDeclarativeScriptString x) -{ - Q_D(QDeclarativeParentChange); - d->xString = x; - tryReal(d->x, x.script()); -} - -bool QDeclarativeParentChange::xIsSet() const -{ - Q_D(const QDeclarativeParentChange); - return d->xString.isValid(); -} - -QDeclarativeScriptString QDeclarativeParentChange::y() const -{ - Q_D(const QDeclarativeParentChange); - return d->yString.value; -} - -void QDeclarativeParentChange::setY(QDeclarativeScriptString y) -{ - Q_D(QDeclarativeParentChange); - d->yString = y; - tryReal(d->y, y.script()); -} - -bool QDeclarativeParentChange::yIsSet() const -{ - Q_D(const QDeclarativeParentChange); - return d->yString.isValid(); -} - -QDeclarativeScriptString QDeclarativeParentChange::width() const -{ - Q_D(const QDeclarativeParentChange); - return d->widthString.value; -} - -void QDeclarativeParentChange::setWidth(QDeclarativeScriptString width) -{ - Q_D(QDeclarativeParentChange); - d->widthString = width; - tryReal(d->width, width.script()); -} - -bool QDeclarativeParentChange::widthIsSet() const -{ - Q_D(const QDeclarativeParentChange); - return d->widthString.isValid(); -} - -QDeclarativeScriptString QDeclarativeParentChange::height() const -{ - Q_D(const QDeclarativeParentChange); - return d->heightString.value; -} - -void QDeclarativeParentChange::setHeight(QDeclarativeScriptString height) -{ - Q_D(QDeclarativeParentChange); - d->heightString = height; - tryReal(d->height, height.script()); -} - -bool QDeclarativeParentChange::heightIsSet() const -{ - Q_D(const QDeclarativeParentChange); - return d->heightString.isValid(); -} - -QDeclarativeScriptString QDeclarativeParentChange::scale() const -{ - Q_D(const QDeclarativeParentChange); - return d->scaleString.value; -} - -void QDeclarativeParentChange::setScale(QDeclarativeScriptString scale) -{ - Q_D(QDeclarativeParentChange); - d->scaleString = scale; - tryReal(d->scale, scale.script()); -} - -bool QDeclarativeParentChange::scaleIsSet() const -{ - Q_D(const QDeclarativeParentChange); - return d->scaleString.isValid(); -} - -QDeclarativeScriptString QDeclarativeParentChange::rotation() const -{ - Q_D(const QDeclarativeParentChange); - return d->rotationString.value; -} - -void QDeclarativeParentChange::setRotation(QDeclarativeScriptString rotation) -{ - Q_D(QDeclarativeParentChange); - d->rotationString = rotation; - tryReal(d->rotation, rotation.script()); -} - -bool QDeclarativeParentChange::rotationIsSet() const -{ - Q_D(const QDeclarativeParentChange); - return d->rotationString.isValid(); -} - -QDeclarativeItem *QDeclarativeParentChange::originalParent() const -{ - Q_D(const QDeclarativeParentChange); - return d->origParent; -} - -/*! - \qmlproperty Item ParentChange::target - This property holds the item to be reparented -*/ - -QDeclarativeItem *QDeclarativeParentChange::object() const -{ - Q_D(const QDeclarativeParentChange); - return d->target; -} - -void QDeclarativeParentChange::setObject(QDeclarativeItem *target) -{ - Q_D(QDeclarativeParentChange); - d->target = target; -} - -/*! - \qmlproperty Item ParentChange::parent - This property holds the new parent for the item in this state. -*/ - -QDeclarativeItem *QDeclarativeParentChange::parent() const -{ - Q_D(const QDeclarativeParentChange); - return d->parent; -} - -void QDeclarativeParentChange::setParent(QDeclarativeItem *parent) -{ - Q_D(QDeclarativeParentChange); - d->parent = parent; -} - -QDeclarativeStateOperation::ActionList QDeclarativeParentChange::actions() -{ - Q_D(QDeclarativeParentChange); - if (!d->target || !d->parent) - return ActionList(); - - ActionList actions; - - QDeclarativeAction a; - a.event = this; - actions << a; - - QDeclarativeContext *ctxt = qmlContext(this); - - if (d->xString.isValid()) { - if (d->x.isValid()) { - QDeclarativeAction xa(d->target, QLatin1String("x"), ctxt, d->x.value); - actions << xa; - } else { - QDeclarativeBinding *newBinding = new QDeclarativeBinding(d->xString.value.script(), d->target, ctxt); - newBinding->setTarget(QDeclarativeProperty(d->target, QLatin1String("x"), ctxt)); - QDeclarativeAction xa; - xa.property = newBinding->property(); - xa.toBinding = newBinding; - xa.fromValue = xa.property.read(); - xa.deletableToBinding = true; - actions << xa; - } - } - - if (d->yString.isValid()) { - if (d->y.isValid()) { - QDeclarativeAction ya(d->target, QLatin1String("y"), ctxt, d->y.value); - actions << ya; - } else { - QDeclarativeBinding *newBinding = new QDeclarativeBinding(d->yString.value.script(), d->target, ctxt); - newBinding->setTarget(QDeclarativeProperty(d->target, QLatin1String("y"), ctxt)); - QDeclarativeAction ya; - ya.property = newBinding->property(); - ya.toBinding = newBinding; - ya.fromValue = ya.property.read(); - ya.deletableToBinding = true; - actions << ya; - } - } - - if (d->scaleString.isValid()) { - if (d->scale.isValid()) { - QDeclarativeAction sa(d->target, QLatin1String("scale"), ctxt, d->scale.value); - actions << sa; - } else { - QDeclarativeBinding *newBinding = new QDeclarativeBinding(d->scaleString.value.script(), d->target, ctxt); - newBinding->setTarget(QDeclarativeProperty(d->target, QLatin1String("scale"), ctxt)); - QDeclarativeAction sa; - sa.property = newBinding->property(); - sa.toBinding = newBinding; - sa.fromValue = sa.property.read(); - sa.deletableToBinding = true; - actions << sa; - } - } - - if (d->rotationString.isValid()) { - if (d->rotation.isValid()) { - QDeclarativeAction ra(d->target, QLatin1String("rotation"), ctxt, d->rotation.value); - actions << ra; - } else { - QDeclarativeBinding *newBinding = new QDeclarativeBinding(d->rotationString.value.script(), d->target, ctxt); - newBinding->setTarget(QDeclarativeProperty(d->target, QLatin1String("rotation"), ctxt)); - QDeclarativeAction ra; - ra.property = newBinding->property(); - ra.toBinding = newBinding; - ra.fromValue = ra.property.read(); - ra.deletableToBinding = true; - actions << ra; - } - } - - if (d->widthString.isValid()) { - if (d->width.isValid()) { - QDeclarativeAction wa(d->target, QLatin1String("width"), ctxt, d->width.value); - actions << wa; - } else { - QDeclarativeBinding *newBinding = new QDeclarativeBinding(d->widthString.value.script(), d->target, ctxt); - newBinding->setTarget(QDeclarativeProperty(d->target, QLatin1String("width"), ctxt)); - QDeclarativeAction wa; - wa.property = newBinding->property(); - wa.toBinding = newBinding; - wa.fromValue = wa.property.read(); - wa.deletableToBinding = true; - actions << wa; - } - } - - if (d->heightString.isValid()) { - if (d->height.isValid()) { - QDeclarativeAction ha(d->target, QLatin1String("height"), ctxt, d->height.value); - actions << ha; - } else { - QDeclarativeBinding *newBinding = new QDeclarativeBinding(d->heightString.value.script(), d->target, ctxt); - newBinding->setTarget(QDeclarativeProperty(d->target, QLatin1String("height"), ctxt)); - QDeclarativeAction ha; - ha.property = newBinding->property(); - ha.toBinding = newBinding; - ha.fromValue = ha.property.read(); - ha.deletableToBinding = true; - actions << ha; - } - } - - return actions; -} - -class AccessibleFxItem : public QDeclarativeItem -{ - Q_OBJECT - Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QDeclarativeItem) -public: - int siblingIndex() { - Q_D(QDeclarativeItem); - return d->siblingIndex; - } -}; - -void QDeclarativeParentChange::saveOriginals() -{ - Q_D(QDeclarativeParentChange); - saveCurrentValues(); - d->origParent = d->rewindParent; - d->origStackBefore = d->rewindStackBefore; -} - -/*void QDeclarativeParentChange::copyOriginals(QDeclarativeActionEvent *other) -{ - Q_D(QDeclarativeParentChange); - QDeclarativeParentChange *pc = static_cast<QDeclarativeParentChange*>(other); - - d->origParent = pc->d_func()->rewindParent; - d->origStackBefore = pc->d_func()->rewindStackBefore; - - saveCurrentValues(); -}*/ - -void QDeclarativeParentChange::execute(Reason) -{ - Q_D(QDeclarativeParentChange); - d->doChange(d->parent); -} - -bool QDeclarativeParentChange::isReversable() -{ - return true; -} - -void QDeclarativeParentChange::reverse(Reason) -{ - Q_D(QDeclarativeParentChange); - d->doChange(d->origParent, d->origStackBefore); -} - -QString QDeclarativeParentChange::typeName() const -{ - return QLatin1String("ParentChange"); -} - -bool QDeclarativeParentChange::override(QDeclarativeActionEvent*other) -{ - Q_D(QDeclarativeParentChange); - if (other->typeName() != QLatin1String("ParentChange")) - return false; - if (QDeclarativeParentChange *otherPC = static_cast<QDeclarativeParentChange*>(other)) - return (d->target == otherPC->object()); - return false; -} - -void QDeclarativeParentChange::saveCurrentValues() -{ - Q_D(QDeclarativeParentChange); - if (!d->target) { - d->rewindParent = 0; - d->rewindStackBefore = 0; - return; - } - - d->rewindParent = d->target->parentItem(); - d->rewindStackBefore = 0; - - if (!d->rewindParent) - return; - - //try to determine the item's original stack position so we can restore it - int siblingIndex = ((AccessibleFxItem*)d->target)->siblingIndex() + 1; - QList<QGraphicsItem*> children = d->rewindParent->childItems(); - for (int i = 0; i < children.count(); ++i) { - QDeclarativeItem *child = qobject_cast<QDeclarativeItem*>(children.at(i)); - if (!child) - continue; - if (((AccessibleFxItem*)child)->siblingIndex() == siblingIndex) { - d->rewindStackBefore = child; - break; - } - } -} - -void QDeclarativeParentChange::rewind() -{ - Q_D(QDeclarativeParentChange); - d->doChange(d->rewindParent, d->rewindStackBefore); -} - class QDeclarativeStateChangeScriptPrivate : public QDeclarativeStateOperationPrivate { public: @@ -684,903 +156,7 @@ QString QDeclarativeStateChangeScript::typeName() const return QLatin1String("StateChangeScript"); } -/*! - \qmlclass AnchorChanges QDeclarativeAnchorChanges - \ingroup qml-state-elements - \brief The AnchorChanges element allows you to change the anchors of an item in a state. - - The AnchorChanges element is used to modify the anchors of an item in a \l State. - - AnchorChanges cannot be used to modify the margins on an item. For this, use - PropertyChanges intead. - - In the following example we change the top and bottom anchors of an item - using AnchorChanges, and the top and bottom anchor margins using - PropertyChanges: - - \snippet doc/src/snippets/declarative/anchorchanges.qml 0 - - \image anchorchanges.png - - AnchorChanges can be animated using AnchorAnimation. - \qml - //animate our anchor changes - Transition { - AnchorAnimation {} - } - \endqml - - Margin animations can be animated using NumberAnimation. - - For more information on anchors see \l {anchor-layout}{Anchor Layouts}. -*/ - -class QDeclarativeAnchorSetPrivate : public QObjectPrivate -{ - Q_DECLARE_PUBLIC(QDeclarativeAnchorSet) -public: - QDeclarativeAnchorSetPrivate() - : usedAnchors(0), resetAnchors(0), fill(0), - centerIn(0)/*, leftMargin(0), rightMargin(0), topMargin(0), bottomMargin(0), - margins(0), vCenterOffset(0), hCenterOffset(0), baselineOffset(0)*/ - { - } - - QDeclarativeAnchors::Anchors usedAnchors; - QDeclarativeAnchors::Anchors resetAnchors; - - QDeclarativeItem *fill; - QDeclarativeItem *centerIn; - - QDeclarativeScriptString leftScript; - QDeclarativeScriptString rightScript; - QDeclarativeScriptString topScript; - QDeclarativeScriptString bottomScript; - QDeclarativeScriptString hCenterScript; - QDeclarativeScriptString vCenterScript; - QDeclarativeScriptString baselineScript; - - /*qreal leftMargin; - qreal rightMargin; - qreal topMargin; - qreal bottomMargin; - qreal margins; - qreal vCenterOffset; - qreal hCenterOffset; - qreal baselineOffset;*/ -}; - -QDeclarativeAnchorSet::QDeclarativeAnchorSet(QObject *parent) - : QObject(*new QDeclarativeAnchorSetPrivate, parent) -{ -} - -QDeclarativeAnchorSet::~QDeclarativeAnchorSet() -{ -} - -QDeclarativeScriptString QDeclarativeAnchorSet::top() const -{ - Q_D(const QDeclarativeAnchorSet); - return d->topScript; -} - -void QDeclarativeAnchorSet::setTop(const QDeclarativeScriptString &edge) -{ - Q_D(QDeclarativeAnchorSet); - d->usedAnchors |= QDeclarativeAnchors::TopAnchor; - d->topScript = edge; - if (edge.script() == QLatin1String("undefined")) - resetTop(); -} - -void QDeclarativeAnchorSet::resetTop() -{ - Q_D(QDeclarativeAnchorSet); - d->usedAnchors &= ~QDeclarativeAnchors::TopAnchor; - d->topScript = QDeclarativeScriptString(); - d->resetAnchors |= QDeclarativeAnchors::TopAnchor; -} - -QDeclarativeScriptString QDeclarativeAnchorSet::bottom() const -{ - Q_D(const QDeclarativeAnchorSet); - return d->bottomScript; -} - -void QDeclarativeAnchorSet::setBottom(const QDeclarativeScriptString &edge) -{ - Q_D(QDeclarativeAnchorSet); - d->usedAnchors |= QDeclarativeAnchors::BottomAnchor; - d->bottomScript = edge; - if (edge.script() == QLatin1String("undefined")) - resetBottom(); -} - -void QDeclarativeAnchorSet::resetBottom() -{ - Q_D(QDeclarativeAnchorSet); - d->usedAnchors &= ~QDeclarativeAnchors::BottomAnchor; - d->bottomScript = QDeclarativeScriptString(); - d->resetAnchors |= QDeclarativeAnchors::BottomAnchor; -} - -QDeclarativeScriptString QDeclarativeAnchorSet::verticalCenter() const -{ - Q_D(const QDeclarativeAnchorSet); - return d->vCenterScript; -} - -void QDeclarativeAnchorSet::setVerticalCenter(const QDeclarativeScriptString &edge) -{ - Q_D(QDeclarativeAnchorSet); - d->usedAnchors |= QDeclarativeAnchors::VCenterAnchor; - d->vCenterScript = edge; - if (edge.script() == QLatin1String("undefined")) - resetVerticalCenter(); -} - -void QDeclarativeAnchorSet::resetVerticalCenter() -{ - Q_D(QDeclarativeAnchorSet); - d->usedAnchors &= ~QDeclarativeAnchors::VCenterAnchor; - d->vCenterScript = QDeclarativeScriptString(); - d->resetAnchors |= QDeclarativeAnchors::VCenterAnchor; -} - -QDeclarativeScriptString QDeclarativeAnchorSet::baseline() const -{ - Q_D(const QDeclarativeAnchorSet); - return d->baselineScript; -} - -void QDeclarativeAnchorSet::setBaseline(const QDeclarativeScriptString &edge) -{ - Q_D(QDeclarativeAnchorSet); - d->usedAnchors |= QDeclarativeAnchors::BaselineAnchor; - d->baselineScript = edge; - if (edge.script() == QLatin1String("undefined")) - resetBaseline(); -} - -void QDeclarativeAnchorSet::resetBaseline() -{ - Q_D(QDeclarativeAnchorSet); - d->usedAnchors &= ~QDeclarativeAnchors::BaselineAnchor; - d->baselineScript = QDeclarativeScriptString(); - d->resetAnchors |= QDeclarativeAnchors::BaselineAnchor; -} - -QDeclarativeScriptString QDeclarativeAnchorSet::left() const -{ - Q_D(const QDeclarativeAnchorSet); - return d->leftScript; -} - -void QDeclarativeAnchorSet::setLeft(const QDeclarativeScriptString &edge) -{ - Q_D(QDeclarativeAnchorSet); - d->usedAnchors |= QDeclarativeAnchors::LeftAnchor; - d->leftScript = edge; - if (edge.script() == QLatin1String("undefined")) - resetLeft(); -} - -void QDeclarativeAnchorSet::resetLeft() -{ - Q_D(QDeclarativeAnchorSet); - d->usedAnchors &= ~QDeclarativeAnchors::LeftAnchor; - d->leftScript = QDeclarativeScriptString(); - d->resetAnchors |= QDeclarativeAnchors::LeftAnchor; -} - -QDeclarativeScriptString QDeclarativeAnchorSet::right() const -{ - Q_D(const QDeclarativeAnchorSet); - return d->rightScript; -} - -void QDeclarativeAnchorSet::setRight(const QDeclarativeScriptString &edge) -{ - Q_D(QDeclarativeAnchorSet); - d->usedAnchors |= QDeclarativeAnchors::RightAnchor; - d->rightScript = edge; - if (edge.script() == QLatin1String("undefined")) - resetRight(); -} - -void QDeclarativeAnchorSet::resetRight() -{ - Q_D(QDeclarativeAnchorSet); - d->usedAnchors &= ~QDeclarativeAnchors::RightAnchor; - d->rightScript = QDeclarativeScriptString(); - d->resetAnchors |= QDeclarativeAnchors::RightAnchor; -} - -QDeclarativeScriptString QDeclarativeAnchorSet::horizontalCenter() const -{ - Q_D(const QDeclarativeAnchorSet); - return d->hCenterScript; -} - -void QDeclarativeAnchorSet::setHorizontalCenter(const QDeclarativeScriptString &edge) -{ - Q_D(QDeclarativeAnchorSet); - d->usedAnchors |= QDeclarativeAnchors::HCenterAnchor; - d->hCenterScript = edge; - if (edge.script() == QLatin1String("undefined")) - resetHorizontalCenter(); -} - -void QDeclarativeAnchorSet::resetHorizontalCenter() -{ - Q_D(QDeclarativeAnchorSet); - d->usedAnchors &= ~QDeclarativeAnchors::HCenterAnchor; - d->hCenterScript = QDeclarativeScriptString(); - d->resetAnchors |= QDeclarativeAnchors::HCenterAnchor; -} - -QDeclarativeItem *QDeclarativeAnchorSet::fill() const -{ - Q_D(const QDeclarativeAnchorSet); - return d->fill; -} - -void QDeclarativeAnchorSet::setFill(QDeclarativeItem *f) -{ - Q_D(QDeclarativeAnchorSet); - d->fill = f; -} - -void QDeclarativeAnchorSet::resetFill() -{ - setFill(0); -} - -QDeclarativeItem *QDeclarativeAnchorSet::centerIn() const -{ - Q_D(const QDeclarativeAnchorSet); - return d->centerIn; -} - -void QDeclarativeAnchorSet::setCenterIn(QDeclarativeItem* c) -{ - Q_D(QDeclarativeAnchorSet); - d->centerIn = c; -} - -void QDeclarativeAnchorSet::resetCenterIn() -{ - setCenterIn(0); -} - - -class QDeclarativeAnchorChangesPrivate : public QDeclarativeStateOperationPrivate -{ -public: - QDeclarativeAnchorChangesPrivate() - : target(0), anchorSet(new QDeclarativeAnchorSet), - leftBinding(0), rightBinding(0), hCenterBinding(0), - topBinding(0), bottomBinding(0), vCenterBinding(0), baselineBinding(0), - origLeftBinding(0), origRightBinding(0), origHCenterBinding(0), - origTopBinding(0), origBottomBinding(0), origVCenterBinding(0), - origBaselineBinding(0) - { - - } - ~QDeclarativeAnchorChangesPrivate() { delete anchorSet; } - - QDeclarativeItem *target; - QDeclarativeAnchorSet *anchorSet; - - QDeclarativeBinding *leftBinding; - QDeclarativeBinding *rightBinding; - QDeclarativeBinding *hCenterBinding; - QDeclarativeBinding *topBinding; - QDeclarativeBinding *bottomBinding; - QDeclarativeBinding *vCenterBinding; - QDeclarativeBinding *baselineBinding; - - QDeclarativeAbstractBinding *origLeftBinding; - QDeclarativeAbstractBinding *origRightBinding; - QDeclarativeAbstractBinding *origHCenterBinding; - QDeclarativeAbstractBinding *origTopBinding; - QDeclarativeAbstractBinding *origBottomBinding; - QDeclarativeAbstractBinding *origVCenterBinding; - QDeclarativeAbstractBinding *origBaselineBinding; - - QDeclarativeAnchorLine rewindLeft; - QDeclarativeAnchorLine rewindRight; - QDeclarativeAnchorLine rewindHCenter; - QDeclarativeAnchorLine rewindTop; - QDeclarativeAnchorLine rewindBottom; - QDeclarativeAnchorLine rewindVCenter; - QDeclarativeAnchorLine rewindBaseline; - - qreal fromX; - qreal fromY; - qreal fromWidth; - qreal fromHeight; - - qreal toX; - qreal toY; - qreal toWidth; - qreal toHeight; - - qreal rewindX; - qreal rewindY; - qreal rewindWidth; - qreal rewindHeight; - - bool applyOrigLeft; - bool applyOrigRight; - bool applyOrigHCenter; - bool applyOrigTop; - bool applyOrigBottom; - bool applyOrigVCenter; - bool applyOrigBaseline; - - QDeclarativeNullableValue<qreal> origWidth; - QDeclarativeNullableValue<qreal> origHeight; - qreal origX; - qreal origY; - - QList<QDeclarativeAbstractBinding*> oldBindings; - - QDeclarativeProperty leftProp; - QDeclarativeProperty rightProp; - QDeclarativeProperty hCenterProp; - QDeclarativeProperty topProp; - QDeclarativeProperty bottomProp; - QDeclarativeProperty vCenterProp; - QDeclarativeProperty baselineProp; -}; - -/*! - \qmlproperty Item AnchorChanges::target - This property holds the \l Item for which the anchor changes will be applied. -*/ - -QDeclarativeAnchorChanges::QDeclarativeAnchorChanges(QObject *parent) - : QDeclarativeStateOperation(*(new QDeclarativeAnchorChangesPrivate), parent) -{ -} - -QDeclarativeAnchorChanges::~QDeclarativeAnchorChanges() -{ -} - -QDeclarativeAnchorChanges::ActionList QDeclarativeAnchorChanges::actions() -{ - Q_D(QDeclarativeAnchorChanges); - d->leftBinding = d->rightBinding = d->hCenterBinding = d->topBinding - = d->bottomBinding = d->vCenterBinding = d->baselineBinding = 0; - - d->leftProp = QDeclarativeProperty(d->target, QLatin1String("anchors.left")); - d->rightProp = QDeclarativeProperty(d->target, QLatin1String("anchors.right")); - d->hCenterProp = QDeclarativeProperty(d->target, QLatin1String("anchors.horizontalCenter")); - d->topProp = QDeclarativeProperty(d->target, QLatin1String("anchors.top")); - d->bottomProp = QDeclarativeProperty(d->target, QLatin1String("anchors.bottom")); - d->vCenterProp = QDeclarativeProperty(d->target, QLatin1String("anchors.verticalCenter")); - d->baselineProp = QDeclarativeProperty(d->target, QLatin1String("anchors.baseline")); - - QDeclarativeContext *ctxt = qmlContext(this); - - if (d->anchorSet->d_func()->usedAnchors & QDeclarativeAnchors::LeftAnchor) { - d->leftBinding = new QDeclarativeBinding(d->anchorSet->d_func()->leftScript.script(), d->target, ctxt); - d->leftBinding->setTarget(d->leftProp); - } - if (d->anchorSet->d_func()->usedAnchors & QDeclarativeAnchors::RightAnchor) { - d->rightBinding = new QDeclarativeBinding(d->anchorSet->d_func()->rightScript.script(), d->target, ctxt); - d->rightBinding->setTarget(d->rightProp); - } - if (d->anchorSet->d_func()->usedAnchors & QDeclarativeAnchors::HCenterAnchor) { - d->hCenterBinding = new QDeclarativeBinding(d->anchorSet->d_func()->hCenterScript.script(), d->target, ctxt); - d->hCenterBinding->setTarget(d->hCenterProp); - } - if (d->anchorSet->d_func()->usedAnchors & QDeclarativeAnchors::TopAnchor) { - d->topBinding = new QDeclarativeBinding(d->anchorSet->d_func()->topScript.script(), d->target, ctxt); - d->topBinding->setTarget(d->topProp); - } - if (d->anchorSet->d_func()->usedAnchors & QDeclarativeAnchors::BottomAnchor) { - d->bottomBinding = new QDeclarativeBinding(d->anchorSet->d_func()->bottomScript.script(), d->target, ctxt); - d->bottomBinding->setTarget(d->bottomProp); - } - if (d->anchorSet->d_func()->usedAnchors & QDeclarativeAnchors::VCenterAnchor) { - d->vCenterBinding = new QDeclarativeBinding(d->anchorSet->d_func()->vCenterScript.script(), d->target, ctxt); - d->vCenterBinding->setTarget(d->vCenterProp); - } - if (d->anchorSet->d_func()->usedAnchors & QDeclarativeAnchors::BaselineAnchor) { - d->baselineBinding = new QDeclarativeBinding(d->anchorSet->d_func()->baselineScript.script(), d->target, ctxt); - d->baselineBinding->setTarget(d->baselineProp); - } - - QDeclarativeAction a; - a.event = this; - return ActionList() << a; -} - -QDeclarativeAnchorSet *QDeclarativeAnchorChanges::anchors() -{ - Q_D(QDeclarativeAnchorChanges); - return d->anchorSet; -} - -QDeclarativeItem *QDeclarativeAnchorChanges::object() const -{ - Q_D(const QDeclarativeAnchorChanges); - return d->target; -} - -void QDeclarativeAnchorChanges::setObject(QDeclarativeItem *target) -{ - Q_D(QDeclarativeAnchorChanges); - d->target = target; -} - -/*! - \qmlproperty AnchorLine AnchorChanges::anchors.left - \qmlproperty AnchorLine AnchorChanges::anchors.right - \qmlproperty AnchorLine AnchorChanges::anchors.horizontalCenter - \qmlproperty AnchorLine AnchorChanges::anchors.top - \qmlproperty AnchorLine AnchorChanges::anchors.bottom - \qmlproperty AnchorLine AnchorChanges::anchors.verticalCenter - \qmlproperty AnchorLine AnchorChanges::anchors.baseline - - These properties change the respective anchors of the item. - - To reset an anchor you can assign \c undefined: - \qml - AnchorChanges { - target: myItem - anchors.left: undefined //remove myItem's left anchor - anchors.right: otherItem.right - } - \endqml -*/ - -void QDeclarativeAnchorChanges::execute(Reason reason) -{ - Q_D(QDeclarativeAnchorChanges); - if (!d->target) - return; - - QDeclarativeItemPrivate *targetPrivate = QDeclarativeItemPrivate::get(d->target); - //incorporate any needed "reverts" - if (d->applyOrigLeft) { - if (!d->origLeftBinding) - targetPrivate->anchors()->resetLeft(); - QDeclarativePropertyPrivate::setBinding(d->leftProp, d->origLeftBinding); - } - if (d->applyOrigRight) { - if (!d->origRightBinding) - targetPrivate->anchors()->resetRight(); - QDeclarativePropertyPrivate::setBinding(d->rightProp, d->origRightBinding); - } - if (d->applyOrigHCenter) { - if (!d->origHCenterBinding) - targetPrivate->anchors()->resetHorizontalCenter(); - QDeclarativePropertyPrivate::setBinding(d->hCenterProp, d->origHCenterBinding); - } - if (d->applyOrigTop) { - if (!d->origTopBinding) - targetPrivate->anchors()->resetTop(); - QDeclarativePropertyPrivate::setBinding(d->topProp, d->origTopBinding); - } - if (d->applyOrigBottom) { - if (!d->origBottomBinding) - targetPrivate->anchors()->resetBottom(); - QDeclarativePropertyPrivate::setBinding(d->bottomProp, d->origBottomBinding); - } - if (d->applyOrigVCenter) { - if (!d->origVCenterBinding) - targetPrivate->anchors()->resetVerticalCenter(); - QDeclarativePropertyPrivate::setBinding(d->vCenterProp, d->origVCenterBinding); - } - if (d->applyOrigBaseline) { - if (!d->origBaselineBinding) - targetPrivate->anchors()->resetBaseline(); - QDeclarativePropertyPrivate::setBinding(d->baselineProp, d->origBaselineBinding); - } - - //destroy old bindings - if (reason == ActualChange) { - for (int i = 0; i < d->oldBindings.size(); ++i) { - QDeclarativeAbstractBinding *binding = d->oldBindings.at(i); - if (binding) - binding->destroy(); - } - d->oldBindings.clear(); - } - - //reset any anchors that have been specified as "undefined" - if (d->anchorSet->d_func()->resetAnchors & QDeclarativeAnchors::LeftAnchor) { - targetPrivate->anchors()->resetLeft(); - QDeclarativePropertyPrivate::setBinding(d->leftProp, 0); - } - if (d->anchorSet->d_func()->resetAnchors & QDeclarativeAnchors::RightAnchor) { - targetPrivate->anchors()->resetRight(); - QDeclarativePropertyPrivate::setBinding(d->rightProp, 0); - } - if (d->anchorSet->d_func()->resetAnchors & QDeclarativeAnchors::HCenterAnchor) { - targetPrivate->anchors()->resetHorizontalCenter(); - QDeclarativePropertyPrivate::setBinding(d->hCenterProp, 0); - } - if (d->anchorSet->d_func()->resetAnchors & QDeclarativeAnchors::TopAnchor) { - targetPrivate->anchors()->resetTop(); - QDeclarativePropertyPrivate::setBinding(d->topProp, 0); - } - if (d->anchorSet->d_func()->resetAnchors & QDeclarativeAnchors::BottomAnchor) { - targetPrivate->anchors()->resetBottom(); - QDeclarativePropertyPrivate::setBinding(d->bottomProp, 0); - } - if (d->anchorSet->d_func()->resetAnchors & QDeclarativeAnchors::VCenterAnchor) { - targetPrivate->anchors()->resetVerticalCenter(); - QDeclarativePropertyPrivate::setBinding(d->vCenterProp, 0); - } - if (d->anchorSet->d_func()->resetAnchors & QDeclarativeAnchors::BaselineAnchor) { - targetPrivate->anchors()->resetBaseline(); - QDeclarativePropertyPrivate::setBinding(d->baselineProp, 0); - } - - //set any anchors that have been specified - if (d->leftBinding) - QDeclarativePropertyPrivate::setBinding(d->leftBinding->property(), d->leftBinding); - if (d->rightBinding) - QDeclarativePropertyPrivate::setBinding(d->rightBinding->property(), d->rightBinding); - if (d->hCenterBinding) - QDeclarativePropertyPrivate::setBinding(d->hCenterBinding->property(), d->hCenterBinding); - if (d->topBinding) - QDeclarativePropertyPrivate::setBinding(d->topBinding->property(), d->topBinding); - if (d->bottomBinding) - QDeclarativePropertyPrivate::setBinding(d->bottomBinding->property(), d->bottomBinding); - if (d->vCenterBinding) - QDeclarativePropertyPrivate::setBinding(d->vCenterBinding->property(), d->vCenterBinding); - if (d->baselineBinding) - QDeclarativePropertyPrivate::setBinding(d->baselineBinding->property(), d->baselineBinding); -} - -bool QDeclarativeAnchorChanges::isReversable() -{ - return true; -} - -void QDeclarativeAnchorChanges::reverse(Reason reason) -{ - Q_D(QDeclarativeAnchorChanges); - if (!d->target) - return; - - QDeclarativeItemPrivate *targetPrivate = QDeclarativeItemPrivate::get(d->target); - //reset any anchors set by the state - if (d->leftBinding) { - targetPrivate->anchors()->resetLeft(); - QDeclarativePropertyPrivate::setBinding(d->leftBinding->property(), 0); - if (reason == ActualChange) { - d->leftBinding->destroy(); d->leftBinding = 0; - } - } - if (d->rightBinding) { - targetPrivate->anchors()->resetRight(); - QDeclarativePropertyPrivate::setBinding(d->rightBinding->property(), 0); - if (reason == ActualChange) { - d->rightBinding->destroy(); d->rightBinding = 0; - } - } - if (d->hCenterBinding) { - targetPrivate->anchors()->resetHorizontalCenter(); - QDeclarativePropertyPrivate::setBinding(d->hCenterBinding->property(), 0); - if (reason == ActualChange) { - d->hCenterBinding->destroy(); d->hCenterBinding = 0; - } - } - if (d->topBinding) { - targetPrivate->anchors()->resetTop(); - QDeclarativePropertyPrivate::setBinding(d->topBinding->property(), 0); - if (reason == ActualChange) { - d->topBinding->destroy(); d->topBinding = 0; - } - } - if (d->bottomBinding) { - targetPrivate->anchors()->resetBottom(); - QDeclarativePropertyPrivate::setBinding(d->bottomBinding->property(), 0); - if (reason == ActualChange) { - d->bottomBinding->destroy(); d->bottomBinding = 0; - } - } - if (d->vCenterBinding) { - targetPrivate->anchors()->resetVerticalCenter(); - QDeclarativePropertyPrivate::setBinding(d->vCenterBinding->property(), 0); - if (reason == ActualChange) { - d->vCenterBinding->destroy(); d->vCenterBinding = 0; - } - } - if (d->baselineBinding) { - targetPrivate->anchors()->resetBaseline(); - QDeclarativePropertyPrivate::setBinding(d->baselineBinding->property(), 0); - if (reason == ActualChange) { - d->baselineBinding->destroy(); d->baselineBinding = 0; - } - } - - //restore previous anchors - if (d->origLeftBinding) - QDeclarativePropertyPrivate::setBinding(d->leftProp, d->origLeftBinding); - if (d->origRightBinding) - QDeclarativePropertyPrivate::setBinding(d->rightProp, d->origRightBinding); - if (d->origHCenterBinding) - QDeclarativePropertyPrivate::setBinding(d->hCenterProp, d->origHCenterBinding); - if (d->origTopBinding) - QDeclarativePropertyPrivate::setBinding(d->topProp, d->origTopBinding); - if (d->origBottomBinding) - QDeclarativePropertyPrivate::setBinding(d->bottomProp, d->origBottomBinding); - if (d->origVCenterBinding) - QDeclarativePropertyPrivate::setBinding(d->vCenterProp, d->origVCenterBinding); - if (d->origBaselineBinding) - QDeclarativePropertyPrivate::setBinding(d->baselineProp, d->origBaselineBinding); - - //restore any absolute geometry changed by the state's anchors - QDeclarativeAnchors::Anchors stateVAnchors = d->anchorSet->d_func()->usedAnchors & QDeclarativeAnchors::Vertical_Mask; - QDeclarativeAnchors::Anchors origVAnchors = targetPrivate->anchors()->usedAnchors() & QDeclarativeAnchors::Vertical_Mask; - QDeclarativeAnchors::Anchors stateHAnchors = d->anchorSet->d_func()->usedAnchors & QDeclarativeAnchors::Horizontal_Mask; - QDeclarativeAnchors::Anchors origHAnchors = targetPrivate->anchors()->usedAnchors() & QDeclarativeAnchors::Horizontal_Mask; - - bool stateSetWidth = (stateHAnchors && - stateHAnchors != QDeclarativeAnchors::LeftAnchor && - stateHAnchors != QDeclarativeAnchors::RightAnchor && - stateHAnchors != QDeclarativeAnchors::HCenterAnchor); - bool origSetWidth = (origHAnchors && - origHAnchors != QDeclarativeAnchors::LeftAnchor && - origHAnchors != QDeclarativeAnchors::RightAnchor && - origHAnchors != QDeclarativeAnchors::HCenterAnchor); - if (d->origWidth.isValid() && stateSetWidth && !origSetWidth) - d->target->setWidth(d->origWidth.value); - - bool stateSetHeight = (stateVAnchors && - stateVAnchors != QDeclarativeAnchors::TopAnchor && - stateVAnchors != QDeclarativeAnchors::BottomAnchor && - stateVAnchors != QDeclarativeAnchors::VCenterAnchor && - stateVAnchors != QDeclarativeAnchors::BaselineAnchor); - bool origSetHeight = (origVAnchors && - origVAnchors != QDeclarativeAnchors::TopAnchor && - origVAnchors != QDeclarativeAnchors::BottomAnchor && - origVAnchors != QDeclarativeAnchors::VCenterAnchor && - origVAnchors != QDeclarativeAnchors::BaselineAnchor); - if (d->origHeight.isValid() && stateSetHeight && !origSetHeight) - d->target->setHeight(d->origHeight.value); - - if (stateHAnchors && !origHAnchors) - d->target->setX(d->origX); - - if (stateVAnchors && !origVAnchors) - d->target->setY(d->origY); -} - -QString QDeclarativeAnchorChanges::typeName() const -{ - return QLatin1String("AnchorChanges"); -} - -QList<QDeclarativeAction> QDeclarativeAnchorChanges::additionalActions() -{ - Q_D(QDeclarativeAnchorChanges); - QList<QDeclarativeAction> extra; - - QDeclarativeAnchors::Anchors combined = d->anchorSet->d_func()->usedAnchors | d->anchorSet->d_func()->resetAnchors; - bool hChange = combined & QDeclarativeAnchors::Horizontal_Mask; - bool vChange = combined & QDeclarativeAnchors::Vertical_Mask; - - if (d->target) { - QDeclarativeContext *ctxt = qmlContext(this); - QDeclarativeAction a; - if (hChange && d->fromX != d->toX) { - a.property = QDeclarativeProperty(d->target, QLatin1String("x"), ctxt); - a.toValue = d->toX; - extra << a; - } - if (vChange && d->fromY != d->toY) { - a.property = QDeclarativeProperty(d->target, QLatin1String("y"), ctxt); - a.toValue = d->toY; - extra << a; - } - if (hChange && d->fromWidth != d->toWidth) { - a.property = QDeclarativeProperty(d->target, QLatin1String("width"), ctxt); - a.toValue = d->toWidth; - extra << a; - } - if (vChange && d->fromHeight != d->toHeight) { - a.property = QDeclarativeProperty(d->target, QLatin1String("height"), ctxt); - a.toValue = d->toHeight; - extra << a; - } - } - - return extra; -} - -bool QDeclarativeAnchorChanges::changesBindings() -{ - return true; -} - -void QDeclarativeAnchorChanges::saveOriginals() -{ - Q_D(QDeclarativeAnchorChanges); - if (!d->target) - return; - - d->origLeftBinding = QDeclarativePropertyPrivate::binding(d->leftProp); - d->origRightBinding = QDeclarativePropertyPrivate::binding(d->rightProp); - d->origHCenterBinding = QDeclarativePropertyPrivate::binding(d->hCenterProp); - d->origTopBinding = QDeclarativePropertyPrivate::binding(d->topProp); - d->origBottomBinding = QDeclarativePropertyPrivate::binding(d->bottomProp); - d->origVCenterBinding = QDeclarativePropertyPrivate::binding(d->vCenterProp); - d->origBaselineBinding = QDeclarativePropertyPrivate::binding(d->baselineProp); - - QDeclarativeItemPrivate *targetPrivate = QDeclarativeItemPrivate::get(d->target); - if (targetPrivate->widthValid) - d->origWidth = d->target->width(); - if (targetPrivate->heightValid) - d->origHeight = d->target->height(); - d->origX = d->target->x(); - d->origY = d->target->y(); - - d->applyOrigLeft = d->applyOrigRight = d->applyOrigHCenter = d->applyOrigTop - = d->applyOrigBottom = d->applyOrigVCenter = d->applyOrigBaseline = false; - - saveCurrentValues(); -} - -void QDeclarativeAnchorChanges::copyOriginals(QDeclarativeActionEvent *other) -{ - Q_D(QDeclarativeAnchorChanges); - QDeclarativeAnchorChanges *ac = static_cast<QDeclarativeAnchorChanges*>(other); - QDeclarativeAnchorChangesPrivate *acp = ac->d_func(); - - QDeclarativeAnchors::Anchors combined = acp->anchorSet->d_func()->usedAnchors | - acp->anchorSet->d_func()->resetAnchors; - - //probably also need to revert some things - d->applyOrigLeft = (combined & QDeclarativeAnchors::LeftAnchor); - d->applyOrigRight = (combined & QDeclarativeAnchors::RightAnchor); - d->applyOrigHCenter = (combined & QDeclarativeAnchors::HCenterAnchor); - d->applyOrigTop = (combined & QDeclarativeAnchors::TopAnchor); - d->applyOrigBottom = (combined & QDeclarativeAnchors::BottomAnchor); - d->applyOrigVCenter = (combined & QDeclarativeAnchors::VCenterAnchor); - d->applyOrigBaseline = (combined & QDeclarativeAnchors::BaselineAnchor); - - d->origLeftBinding = acp->origLeftBinding; - d->origRightBinding = acp->origRightBinding; - d->origHCenterBinding = acp->origHCenterBinding; - d->origTopBinding = acp->origTopBinding; - d->origBottomBinding = acp->origBottomBinding; - d->origVCenterBinding = acp->origVCenterBinding; - d->origBaselineBinding = acp->origBaselineBinding; - - d->origWidth = acp->origWidth; - d->origHeight = acp->origHeight; - d->origX = acp->origX; - d->origY = acp->origY; - - d->oldBindings.clear(); - d->oldBindings << acp->leftBinding << acp->rightBinding << acp->hCenterBinding - << acp->topBinding << acp->bottomBinding << acp->baselineBinding; - - saveCurrentValues(); -} - -void QDeclarativeAnchorChanges::clearBindings() -{ - Q_D(QDeclarativeAnchorChanges); - if (!d->target) - return; - - //### should this (saving "from" values) be moved to saveCurrentValues()? - d->fromX = d->target->x(); - d->fromY = d->target->y(); - d->fromWidth = d->target->width(); - d->fromHeight = d->target->height(); - - QDeclarativeItemPrivate *targetPrivate = QDeclarativeItemPrivate::get(d->target); - //reset any anchors with corresponding reverts - //reset any anchors that have been specified as "undefined" - //reset any anchors that we'll be setting in the state - QDeclarativeAnchors::Anchors combined = d->anchorSet->d_func()->resetAnchors | - d->anchorSet->d_func()->usedAnchors; - if (d->applyOrigLeft || (combined & QDeclarativeAnchors::LeftAnchor)) { - targetPrivate->anchors()->resetLeft(); - QDeclarativePropertyPrivate::setBinding(d->leftProp, 0); - } - if (d->applyOrigRight || (combined & QDeclarativeAnchors::RightAnchor)) { - targetPrivate->anchors()->resetRight(); - QDeclarativePropertyPrivate::setBinding(d->rightProp, 0); - } - if (d->applyOrigHCenter || (combined & QDeclarativeAnchors::HCenterAnchor)) { - targetPrivate->anchors()->resetHorizontalCenter(); - QDeclarativePropertyPrivate::setBinding(d->hCenterProp, 0); - } - if (d->applyOrigTop || (combined & QDeclarativeAnchors::TopAnchor)) { - targetPrivate->anchors()->resetTop(); - QDeclarativePropertyPrivate::setBinding(d->topProp, 0); - } - if (d->applyOrigBottom || (combined & QDeclarativeAnchors::BottomAnchor)) { - targetPrivate->anchors()->resetBottom(); - QDeclarativePropertyPrivate::setBinding(d->bottomProp, 0); - } - if (d->applyOrigVCenter || (combined & QDeclarativeAnchors::VCenterAnchor)) { - targetPrivate->anchors()->resetVerticalCenter(); - QDeclarativePropertyPrivate::setBinding(d->vCenterProp, 0); - } - if (d->applyOrigBaseline || (combined & QDeclarativeAnchors::BaselineAnchor)) { - targetPrivate->anchors()->resetBaseline(); - QDeclarativePropertyPrivate::setBinding(d->baselineProp, 0); - } -} - -bool QDeclarativeAnchorChanges::override(QDeclarativeActionEvent*other) -{ - if (other->typeName() != QLatin1String("AnchorChanges")) - return false; - if (static_cast<QDeclarativeActionEvent*>(this) == other) - return true; - if (static_cast<QDeclarativeAnchorChanges*>(other)->object() == object()) - return true; - return false; -} - -void QDeclarativeAnchorChanges::rewind() -{ - Q_D(QDeclarativeAnchorChanges); - if (!d->target) - return; - - QDeclarativeItemPrivate *targetPrivate = QDeclarativeItemPrivate::get(d->target); - - //restore previous values (but not previous bindings, i.e. anchors) - d->target->setX(d->rewindX); - d->target->setY(d->rewindY); - if (targetPrivate->widthValid) { - d->target->setWidth(d->rewindWidth); - } - if (targetPrivate->heightValid) { - d->target->setHeight(d->rewindHeight); - } -} - -void QDeclarativeAnchorChanges::saveCurrentValues() -{ - Q_D(QDeclarativeAnchorChanges); - if (!d->target) - return; - - QDeclarativeItemPrivate *targetPrivate = QDeclarativeItemPrivate::get(d->target); - d->rewindLeft = targetPrivate->anchors()->left(); - d->rewindRight = targetPrivate->anchors()->right(); - d->rewindHCenter = targetPrivate->anchors()->horizontalCenter(); - d->rewindTop = targetPrivate->anchors()->top(); - d->rewindBottom = targetPrivate->anchors()->bottom(); - d->rewindVCenter = targetPrivate->anchors()->verticalCenter(); - d->rewindBaseline = targetPrivate->anchors()->baseline(); - - d->rewindX = d->target->x(); - d->rewindY = d->target->y(); - d->rewindWidth = d->target->width(); - d->rewindHeight = d->target->height(); -} - -void QDeclarativeAnchorChanges::saveTargetValues() -{ - Q_D(QDeclarativeAnchorChanges); - if (!d->target) - return; - - d->toX = d->target->x(); - d->toY = d->target->y(); - d->toWidth = d->target->width(); - d->toHeight = d->target->height(); -} -#include <qdeclarativestateoperations.moc> #include <moc_qdeclarativestateoperations_p.cpp> QT_END_NAMESPACE diff --git a/src/declarative/util/qdeclarativestateoperations_p.h b/src/declarative/util/qdeclarativestateoperations_p.h index 6a6dda6526..9d30bf7578 100644 --- a/src/declarative/util/qdeclarativestateoperations_p.h +++ b/src/declarative/util/qdeclarativestateoperations_p.h @@ -43,9 +43,6 @@ #define QDECLARATIVESTATEOPERATIONS_H #include "private/qdeclarativestate_p.h" - -#include <qdeclarativeitem.h> -#include <private/qdeclarativeanchors_p.h> #include <qdeclarativescriptstring.h> QT_BEGIN_HEADER @@ -54,68 +51,6 @@ QT_BEGIN_NAMESPACE QT_MODULE(Declarative) -class QDeclarativeParentChangePrivate; -class Q_AUTOTEST_EXPORT QDeclarativeParentChange : public QDeclarativeStateOperation, public QDeclarativeActionEvent -{ - Q_OBJECT - Q_DECLARE_PRIVATE(QDeclarativeParentChange) - - Q_PROPERTY(QDeclarativeItem *target READ object WRITE setObject) - Q_PROPERTY(QDeclarativeItem *parent READ parent WRITE setParent) - Q_PROPERTY(QDeclarativeScriptString x READ x WRITE setX) - Q_PROPERTY(QDeclarativeScriptString y READ y WRITE setY) - Q_PROPERTY(QDeclarativeScriptString width READ width WRITE setWidth) - Q_PROPERTY(QDeclarativeScriptString height READ height WRITE setHeight) - Q_PROPERTY(QDeclarativeScriptString scale READ scale WRITE setScale) - Q_PROPERTY(QDeclarativeScriptString rotation READ rotation WRITE setRotation) -public: - QDeclarativeParentChange(QObject *parent=0); - ~QDeclarativeParentChange(); - - QDeclarativeItem *object() const; - void setObject(QDeclarativeItem *); - - QDeclarativeItem *parent() const; - void setParent(QDeclarativeItem *); - - QDeclarativeItem *originalParent() const; - - QDeclarativeScriptString x() const; - void setX(QDeclarativeScriptString x); - bool xIsSet() const; - - QDeclarativeScriptString y() const; - void setY(QDeclarativeScriptString y); - bool yIsSet() const; - - QDeclarativeScriptString width() const; - void setWidth(QDeclarativeScriptString width); - bool widthIsSet() const; - - QDeclarativeScriptString height() const; - void setHeight(QDeclarativeScriptString height); - bool heightIsSet() const; - - QDeclarativeScriptString scale() const; - void setScale(QDeclarativeScriptString scale); - bool scaleIsSet() const; - - QDeclarativeScriptString rotation() const; - void setRotation(QDeclarativeScriptString rotation); - bool rotationIsSet() const; - - virtual ActionList actions(); - - virtual void saveOriginals(); - //virtual void copyOriginals(QDeclarativeActionEvent*); - virtual void execute(Reason reason = ActualChange); - virtual bool isReversable(); - virtual void reverse(Reason reason = ActualChange); - virtual QString typeName() const; - virtual bool override(QDeclarativeActionEvent*other); - virtual void rewind(); - virtual void saveCurrentValues(); -}; class QDeclarativeStateChangeScriptPrivate; class Q_AUTOTEST_EXPORT QDeclarativeStateChangeScript : public QDeclarativeStateOperation, public QDeclarativeActionEvent @@ -143,156 +78,10 @@ public: virtual void execute(Reason reason = ActualChange); }; -class QDeclarativeAnchorChanges; -class QDeclarativeAnchorSetPrivate; -class Q_AUTOTEST_EXPORT QDeclarativeAnchorSet : public QObject -{ - Q_OBJECT - - Q_PROPERTY(QDeclarativeScriptString left READ left WRITE setLeft RESET resetLeft) - Q_PROPERTY(QDeclarativeScriptString right READ right WRITE setRight RESET resetRight) - Q_PROPERTY(QDeclarativeScriptString horizontalCenter READ horizontalCenter WRITE setHorizontalCenter RESET resetHorizontalCenter) - Q_PROPERTY(QDeclarativeScriptString top READ top WRITE setTop RESET resetTop) - Q_PROPERTY(QDeclarativeScriptString bottom READ bottom WRITE setBottom RESET resetBottom) - Q_PROPERTY(QDeclarativeScriptString verticalCenter READ verticalCenter WRITE setVerticalCenter RESET resetVerticalCenter) - Q_PROPERTY(QDeclarativeScriptString baseline READ baseline WRITE setBaseline RESET resetBaseline) - //Q_PROPERTY(QDeclarativeItem *fill READ fill WRITE setFill RESET resetFill) - //Q_PROPERTY(QDeclarativeItem *centerIn READ centerIn WRITE setCenterIn RESET resetCenterIn) - - /*Q_PROPERTY(qreal margins READ margins WRITE setMargins NOTIFY marginsChanged) - Q_PROPERTY(qreal leftMargin READ leftMargin WRITE setLeftMargin NOTIFY leftMarginChanged) - Q_PROPERTY(qreal rightMargin READ rightMargin WRITE setRightMargin NOTIFY rightMarginChanged) - Q_PROPERTY(qreal horizontalCenterOffset READ horizontalCenterOffset WRITE setHorizontalCenterOffset NOTIFY horizontalCenterOffsetChanged()) - Q_PROPERTY(qreal topMargin READ topMargin WRITE setTopMargin NOTIFY topMarginChanged) - Q_PROPERTY(qreal bottomMargin READ bottomMargin WRITE setBottomMargin NOTIFY bottomMarginChanged) - Q_PROPERTY(qreal verticalCenterOffset READ verticalCenterOffset WRITE setVerticalCenterOffset NOTIFY verticalCenterOffsetChanged()) - Q_PROPERTY(qreal baselineOffset READ baselineOffset WRITE setBaselineOffset NOTIFY baselineOffsetChanged())*/ - -public: - QDeclarativeAnchorSet(QObject *parent=0); - virtual ~QDeclarativeAnchorSet(); - - QDeclarativeScriptString left() const; - void setLeft(const QDeclarativeScriptString &edge); - void resetLeft(); - - QDeclarativeScriptString right() const; - void setRight(const QDeclarativeScriptString &edge); - void resetRight(); - - QDeclarativeScriptString horizontalCenter() const; - void setHorizontalCenter(const QDeclarativeScriptString &edge); - void resetHorizontalCenter(); - - QDeclarativeScriptString top() const; - void setTop(const QDeclarativeScriptString &edge); - void resetTop(); - - QDeclarativeScriptString bottom() const; - void setBottom(const QDeclarativeScriptString &edge); - void resetBottom(); - - QDeclarativeScriptString verticalCenter() const; - void setVerticalCenter(const QDeclarativeScriptString &edge); - void resetVerticalCenter(); - - QDeclarativeScriptString baseline() const; - void setBaseline(const QDeclarativeScriptString &edge); - void resetBaseline(); - - QDeclarativeItem *fill() const; - void setFill(QDeclarativeItem *); - void resetFill(); - - QDeclarativeItem *centerIn() const; - void setCenterIn(QDeclarativeItem *); - void resetCenterIn(); - - /*qreal leftMargin() const; - void setLeftMargin(qreal); - - qreal rightMargin() const; - void setRightMargin(qreal); - - qreal horizontalCenterOffset() const; - void setHorizontalCenterOffset(qreal); - - qreal topMargin() const; - void setTopMargin(qreal); - - qreal bottomMargin() const; - void setBottomMargin(qreal); - - qreal margins() const; - void setMargins(qreal); - - qreal verticalCenterOffset() const; - void setVerticalCenterOffset(qreal); - - qreal baselineOffset() const; - void setBaselineOffset(qreal);*/ - - QDeclarativeAnchors::Anchors usedAnchors() const; - -/*Q_SIGNALS: - void leftMarginChanged(); - void rightMarginChanged(); - void topMarginChanged(); - void bottomMarginChanged(); - void marginsChanged(); - void verticalCenterOffsetChanged(); - void horizontalCenterOffsetChanged(); - void baselineOffsetChanged();*/ - -private: - friend class QDeclarativeAnchorChanges; - Q_DISABLE_COPY(QDeclarativeAnchorSet) - Q_DECLARE_PRIVATE(QDeclarativeAnchorSet) -}; - -class QDeclarativeAnchorChangesPrivate; -class Q_AUTOTEST_EXPORT QDeclarativeAnchorChanges : public QDeclarativeStateOperation, public QDeclarativeActionEvent -{ - Q_OBJECT - Q_DECLARE_PRIVATE(QDeclarativeAnchorChanges) - - Q_PROPERTY(QDeclarativeItem *target READ object WRITE setObject) - Q_PROPERTY(QDeclarativeAnchorSet *anchors READ anchors CONSTANT) - -public: - QDeclarativeAnchorChanges(QObject *parent=0); - ~QDeclarativeAnchorChanges(); - - virtual ActionList actions(); - - QDeclarativeAnchorSet *anchors(); - - QDeclarativeItem *object() const; - void setObject(QDeclarativeItem *); - - virtual void execute(Reason reason = ActualChange); - virtual bool isReversable(); - virtual void reverse(Reason reason = ActualChange); - virtual QString typeName() const; - virtual bool override(QDeclarativeActionEvent*other); - virtual bool changesBindings(); - virtual void saveOriginals(); - virtual bool needsCopy() { return true; } - virtual void copyOriginals(QDeclarativeActionEvent*); - virtual void clearBindings(); - virtual void rewind(); - virtual void saveCurrentValues(); - - QList<QDeclarativeAction> additionalActions(); - virtual void saveTargetValues(); -}; QT_END_NAMESPACE -QML_DECLARE_TYPE(QDeclarativeParentChange) QML_DECLARE_TYPE(QDeclarativeStateChangeScript) -QML_DECLARE_TYPE(QDeclarativeAnchorSet) -QML_DECLARE_TYPE(QDeclarativeAnchorChanges) QT_END_HEADER diff --git a/src/declarative/util/qdeclarativeutilmodule.cpp b/src/declarative/util/qdeclarativeutilmodule.cpp index 4bea2e651a..9f3c9b05bf 100644 --- a/src/declarative/util/qdeclarativeutilmodule.cpp +++ b/src/declarative/util/qdeclarativeutilmodule.cpp @@ -17,7 +17,7 @@ ** ** In addition, as a special exception, Nokia gives you certain additional ** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** version 1.2, included in the file LGPL_EXCEPTION.txt in this package. ** ** GNU General Public License Usage ** Alternatively, this file may be used under the terms of the GNU General @@ -67,108 +67,60 @@ #include "private/qdeclarativetransitionmanager_p_p.h" #include "private/qdeclarativetransition_p.h" #include "private/qdeclarativeapplication_p.h" -#include "qdeclarativeview.h" #include "qdeclarativeinfo.h" #include "private/qdeclarativetypenotavailable_p.h" #ifndef QT_NO_XMLPATTERNS #include "private/qdeclarativexmllistmodel_p.h" #endif -void QDeclarativeUtilModule::defineModule() +void QDeclarativeUtilModule::registerBaseTypes(const char *uri, int versionMajor, int versionMinor) { - qmlRegisterUncreatableType<QDeclarativeApplication>("QtQuick",1,1,"Application", QDeclarativeApplication::tr("Application is an abstract class")); - - qmlRegisterType<QDeclarativeAnchorAnimation>("QtQuick",1,0,"AnchorAnimation"); - qmlRegisterType<QDeclarativeAnchorChanges>("QtQuick",1,0,"AnchorChanges"); - qmlRegisterType<QDeclarativeBehavior>("QtQuick",1,0,"Behavior"); - qmlRegisterType<QDeclarativeBind>("QtQuick",1,0,"Binding"); - qmlRegisterType<QDeclarativeColorAnimation>("QtQuick",1,0,"ColorAnimation"); - qmlRegisterType<QDeclarativeConnections>("QtQuick",1,0,"Connections"); - qmlRegisterType<QDeclarativeSmoothedAnimation>("QtQuick",1,0,"SmoothedAnimation"); - qmlRegisterType<QDeclarativeFontLoader>("QtQuick",1,0,"FontLoader"); - qmlRegisterType<QDeclarativeListElement>("QtQuick",1,0,"ListElement"); - qmlRegisterType<QDeclarativeNumberAnimation>("QtQuick",1,0,"NumberAnimation"); - qmlRegisterType<QDeclarativePackage>("QtQuick",1,0,"Package"); - qmlRegisterType<QDeclarativeParallelAnimation>("QtQuick",1,0,"ParallelAnimation"); - qmlRegisterType<QDeclarativeParentAnimation>("QtQuick",1,0,"ParentAnimation"); - qmlRegisterType<QDeclarativeParentChange>("QtQuick",1,0,"ParentChange"); - qmlRegisterType<QDeclarativePauseAnimation>("QtQuick",1,0,"PauseAnimation"); - qmlRegisterType<QDeclarativePropertyAction>("QtQuick",1,0,"PropertyAction"); - qmlRegisterType<QDeclarativePropertyAnimation>("QtQuick",1,0,"PropertyAnimation"); - qmlRegisterType<QDeclarativeRotationAnimation>("QtQuick",1,0,"RotationAnimation"); - qmlRegisterType<QDeclarativeScriptAction>("QtQuick",1,0,"ScriptAction"); - qmlRegisterType<QDeclarativeSequentialAnimation>("QtQuick",1,0,"SequentialAnimation"); - qmlRegisterType<QDeclarativeSpringAnimation>("QtQuick",1,0,"SpringAnimation"); - qmlRegisterType<QDeclarativeStateChangeScript>("QtQuick",1,0,"StateChangeScript"); - qmlRegisterType<QDeclarativeStateGroup>("QtQuick",1,0,"StateGroup"); - qmlRegisterType<QDeclarativeState>("QtQuick",1,0,"State"); - qmlRegisterType<QDeclarativeSystemPalette>("QtQuick",1,0,"SystemPalette"); - qmlRegisterType<QDeclarativeTimer>("QtQuick",1,0,"Timer"); - qmlRegisterType<QDeclarativeTransition>("QtQuick",1,0,"Transition"); - qmlRegisterType<QDeclarativeVector3dAnimation>("QtQuick",1,0,"Vector3dAnimation"); -#ifdef QT_NO_XMLPATTERNS - qmlRegisterTypeNotAvailable("QtQuick",1,0,"XmlListModel", - qApp->translate("QDeclarativeXmlListModel","Qt was built without support for xmlpatterns")); - qmlRegisterTypeNotAvailable("QtQuick",1,0,"XmlRole", - qApp->translate("QDeclarativeXmlListModel","Qt was built without support for xmlpatterns")); -#else - qmlRegisterType<QDeclarativeXmlListModel>("QtQuick",1,0,"XmlListModel"); - qmlRegisterType<QDeclarativeXmlListModelRole>("QtQuick",1,0,"XmlRole"); -#endif - - qmlRegisterType<QDeclarativeAnchors>(); - qmlRegisterType<QDeclarativeStateOperation>(); - qmlRegisterType<QDeclarativeAnchorSet>(); + qmlRegisterType<QDeclarativeListElement>(uri, versionMajor, versionMinor,"ListElement"); + qmlRegisterCustomType<QDeclarativeListModel>(uri, versionMajor, versionMinor,"ListModel", new QDeclarativeListModelParser); +} - qmlRegisterUncreatableType<QDeclarativeAbstractAnimation>("QtQuick",1,0,"Animation",QDeclarativeAbstractAnimation::tr("Animation is an abstract class")); +void QDeclarativeUtilModule::defineModule() +{ + qmlRegisterUncreatableType<QDeclarativeApplication>("QtQuick",2,0,"Application", QDeclarativeApplication::tr("Application is an abstract class")); - qmlRegisterCustomType<QDeclarativeListModel>("QtQuick",1,0,"ListModel", new QDeclarativeListModelParser); - qmlRegisterCustomType<QDeclarativePropertyChanges>("QtQuick",1,0,"PropertyChanges", new QDeclarativePropertyChangesParser); - qmlRegisterCustomType<QDeclarativeConnections>("QtQuick",1,0,"Connections", new QDeclarativeConnectionsParser); + qmlRegisterUncreatableType<QDeclarativeAbstractAnimation>("QtQuick",2,0,"Animation",QDeclarativeAbstractAnimation::tr("Animation is an abstract class")); -#ifndef QT_NO_IMPORT_QT47_QML - qmlRegisterType<QDeclarativeAnchorAnimation>("Qt",4,7,"AnchorAnimation"); - qmlRegisterType<QDeclarativeAnchorChanges>("Qt",4,7,"AnchorChanges"); - qmlRegisterType<QDeclarativeBehavior>("Qt",4,7,"Behavior"); - qmlRegisterType<QDeclarativeBind>("Qt",4,7,"Binding"); - qmlRegisterType<QDeclarativeColorAnimation>("Qt",4,7,"ColorAnimation"); - qmlRegisterType<QDeclarativeConnections>("Qt",4,7,"Connections"); - qmlRegisterType<QDeclarativeSmoothedAnimation>("Qt",4,7,"SmoothedAnimation"); - qmlRegisterType<QDeclarativeFontLoader>("Qt",4,7,"FontLoader"); - qmlRegisterType<QDeclarativeListElement>("Qt",4,7,"ListElement"); - qmlRegisterType<QDeclarativeNumberAnimation>("Qt",4,7,"NumberAnimation"); - qmlRegisterType<QDeclarativePackage>("Qt",4,7,"Package"); - qmlRegisterType<QDeclarativeParallelAnimation>("Qt",4,7,"ParallelAnimation"); - qmlRegisterType<QDeclarativeParentAnimation>("Qt",4,7,"ParentAnimation"); - qmlRegisterType<QDeclarativeParentChange>("Qt",4,7,"ParentChange"); - qmlRegisterType<QDeclarativePauseAnimation>("Qt",4,7,"PauseAnimation"); - qmlRegisterType<QDeclarativePropertyAction>("Qt",4,7,"PropertyAction"); - qmlRegisterType<QDeclarativePropertyAnimation>("Qt",4,7,"PropertyAnimation"); - qmlRegisterType<QDeclarativeRotationAnimation>("Qt",4,7,"RotationAnimation"); - qmlRegisterType<QDeclarativeScriptAction>("Qt",4,7,"ScriptAction"); - qmlRegisterType<QDeclarativeSequentialAnimation>("Qt",4,7,"SequentialAnimation"); - qmlRegisterType<QDeclarativeSpringAnimation>("Qt",4,7,"SpringAnimation"); - qmlRegisterType<QDeclarativeStateChangeScript>("Qt",4,7,"StateChangeScript"); - qmlRegisterType<QDeclarativeStateGroup>("Qt",4,7,"StateGroup"); - qmlRegisterType<QDeclarativeState>("Qt",4,7,"State"); - qmlRegisterType<QDeclarativeSystemPalette>("Qt",4,7,"SystemPalette"); - qmlRegisterType<QDeclarativeTimer>("Qt",4,7,"Timer"); - qmlRegisterType<QDeclarativeTransition>("Qt",4,7,"Transition"); - qmlRegisterType<QDeclarativeVector3dAnimation>("Qt",4,7,"Vector3dAnimation"); + qmlRegisterType<QDeclarativeBehavior>("QtQuick",2,0,"Behavior"); + qmlRegisterType<QDeclarativeBind>("QtQuick",2,0,"Binding"); + qmlRegisterType<QDeclarativeColorAnimation>("QtQuick",2,0,"ColorAnimation"); + qmlRegisterType<QDeclarativeConnections>("QtQuick",2,0,"Connections"); + qmlRegisterType<QDeclarativeSmoothedAnimation>("QtQuick",2,0,"SmoothedAnimation"); + qmlRegisterType<QDeclarativeFontLoader>("QtQuick",2,0,"FontLoader"); + qmlRegisterType<QDeclarativeNumberAnimation>("QtQuick",2,0,"NumberAnimation"); + qmlRegisterType<QDeclarativePackage>("QtQuick",2,0,"Package"); + qmlRegisterType<QDeclarativeParallelAnimation>("QtQuick",2,0,"ParallelAnimation"); + qmlRegisterType<QDeclarativePauseAnimation>("QtQuick",2,0,"PauseAnimation"); + qmlRegisterType<QDeclarativePropertyAction>("QtQuick",2,0,"PropertyAction"); + qmlRegisterType<QDeclarativePropertyAnimation>("QtQuick",2,0,"PropertyAnimation"); + qmlRegisterType<QDeclarativeRotationAnimation>("QtQuick",2,0,"RotationAnimation"); + qmlRegisterType<QDeclarativeScriptAction>("QtQuick",2,0,"ScriptAction"); + qmlRegisterType<QDeclarativeSequentialAnimation>("QtQuick",2,0,"SequentialAnimation"); + qmlRegisterType<QDeclarativeSpringAnimation>("QtQuick",2,0,"SpringAnimation"); + qmlRegisterType<QDeclarativeStateChangeScript>("QtQuick",2,0,"StateChangeScript"); + qmlRegisterType<QDeclarativeStateGroup>("QtQuick",2,0,"StateGroup"); + qmlRegisterType<QDeclarativeState>("QtQuick",2,0,"State"); + qmlRegisterType<QDeclarativeSystemPalette>("QtQuick",2,0,"SystemPalette"); + qmlRegisterType<QDeclarativeTimer>("QtQuick",2,0,"Timer"); + qmlRegisterType<QDeclarativeTransition>("QtQuick",2,0,"Transition"); + qmlRegisterType<QDeclarativeVector3dAnimation>("QtQuick",2,0,"Vector3dAnimation"); #ifdef QT_NO_XMLPATTERNS - qmlRegisterTypeNotAvailable("Qt",4,7,"XmlListModel", + qmlRegisterTypeNotAvailable("QtQuick",2,0,"XmlListModel", qApp->translate("QDeclarativeXmlListModel","Qt was built without support for xmlpatterns")); - qmlRegisterTypeNotAvailable("Qt",4,7,"XmlRole", + qmlRegisterTypeNotAvailable("QtQuick",2,0,"XmlRole", qApp->translate("QDeclarativeXmlListModel","Qt was built without support for xmlpatterns")); #else - qmlRegisterType<QDeclarativeXmlListModel>("Qt",4,7,"XmlListModel"); - qmlRegisterType<QDeclarativeXmlListModelRole>("Qt",4,7,"XmlRole"); + qmlRegisterType<QDeclarativeXmlListModel>("QtQuick",2,0,"XmlListModel"); + qmlRegisterType<QDeclarativeXmlListModelRole>("QtQuick",2,0,"XmlRole"); #endif - qmlRegisterUncreatableType<QDeclarativeAbstractAnimation>("Qt",4,7,"Animation",QDeclarativeAbstractAnimation::tr("Animation is an abstract class")); + qmlRegisterType<QDeclarativeStateOperation>(); - qmlRegisterCustomType<QDeclarativeListModel>("Qt", 4,7, "ListModel", new QDeclarativeListModelParser); - qmlRegisterCustomType<QDeclarativePropertyChanges>("Qt", 4, 7, "PropertyChanges", new QDeclarativePropertyChangesParser); - qmlRegisterCustomType<QDeclarativeConnections>("Qt", 4, 7, "Connections", new QDeclarativeConnectionsParser); -#endif + qmlRegisterCustomType<QDeclarativePropertyChanges>("QtQuick",2,0,"PropertyChanges", new QDeclarativePropertyChangesParser); + qmlRegisterCustomType<QDeclarativeConnections>("QtQuick",2,0,"Connections", new QDeclarativeConnectionsParser); + registerBaseTypes("QtQuick",2,0); } diff --git a/src/declarative/util/qdeclarativeutilmodule_p.h b/src/declarative/util/qdeclarativeutilmodule_p.h index 7304f6fd77..42a1e02097 100644 --- a/src/declarative/util/qdeclarativeutilmodule_p.h +++ b/src/declarative/util/qdeclarativeutilmodule_p.h @@ -53,6 +53,7 @@ QT_MODULE(Declarative) class QDeclarativeUtilModule { public: + static void registerBaseTypes(const char *uri, int versionMajor, int versionMinor); static void defineModule(); }; diff --git a/src/declarative/util/qdeclarativeview.cpp b/src/declarative/util/qdeclarativeview.cpp deleted file mode 100644 index bab991b175..0000000000 --- a/src/declarative/util/qdeclarativeview.cpp +++ /dev/null @@ -1,737 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qdeclarativeview.h" - -#include <qdeclarative.h> -#include <qdeclarativeitem.h> -#include <qdeclarativeengine.h> -#include <qdeclarativecontext.h> -#include <qdeclarativeglobal_p.h> -#include <qdeclarativeguard_p.h> - -#include <private/qdeclarativedebugtrace_p.h> -#include <private/qdeclarativeinspectorservice_p.h> - -#include <qscriptvalueiterator.h> -#include <qdebug.h> -#include <qtimer.h> -#include <qevent.h> -#include <qdir.h> -#include <qcoreapplication.h> -#include <qfontdatabase.h> -#include <qicon.h> -#include <qurl.h> -#include <qlayout.h> -#include <qwidget.h> -#include <qgraphicswidget.h> -#include <qbasictimer.h> -#include <QtCore/qabstractanimation.h> -#include <private/qgraphicsview_p.h> -#include <private/qdeclarativeitem_p.h> -#include <private/qabstractanimation_p.h> -#include <private/qdeclarativeitemchangelistener_p.h> - -QT_BEGIN_NAMESPACE - -DEFINE_BOOL_CONFIG_OPTION(frameRateDebug, QML_SHOW_FRAMERATE) - -class QDeclarativeScene : public QGraphicsScene -{ -public: - QDeclarativeScene(QObject *parent = 0); - -protected: - virtual void keyPressEvent(QKeyEvent *); - virtual void keyReleaseEvent(QKeyEvent *); - - virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *); - virtual void mousePressEvent(QGraphicsSceneMouseEvent *); - virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *); -}; - -QDeclarativeScene::QDeclarativeScene(QObject *parent) : QGraphicsScene(parent) -{ -} - -void QDeclarativeScene::keyPressEvent(QKeyEvent *e) -{ - QDeclarativeDebugTrace::addEvent(QDeclarativeDebugTrace::Key); - - QGraphicsScene::keyPressEvent(e); -} - -void QDeclarativeScene::keyReleaseEvent(QKeyEvent *e) -{ - QDeclarativeDebugTrace::addEvent(QDeclarativeDebugTrace::Key); - - QGraphicsScene::keyReleaseEvent(e); -} - -void QDeclarativeScene::mouseMoveEvent(QGraphicsSceneMouseEvent *e) -{ - QDeclarativeDebugTrace::addEvent(QDeclarativeDebugTrace::Mouse); - - QGraphicsScene::mouseMoveEvent(e); -} - -void QDeclarativeScene::mousePressEvent(QGraphicsSceneMouseEvent *e) -{ - QDeclarativeDebugTrace::addEvent(QDeclarativeDebugTrace::Mouse); - - QGraphicsScene::mousePressEvent(e); -} - -void QDeclarativeScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *e) -{ - QDeclarativeDebugTrace::addEvent(QDeclarativeDebugTrace::Mouse); - - QGraphicsScene::mouseReleaseEvent(e); -} - -class QDeclarativeViewPrivate : public QGraphicsViewPrivate, public QDeclarativeItemChangeListener -{ - Q_DECLARE_PUBLIC(QDeclarativeView) -public: - QDeclarativeViewPrivate() - : root(0), declarativeItemRoot(0), graphicsWidgetRoot(0), component(0), - resizeMode(QDeclarativeView::SizeViewToRootObject), initialSize(0,0) {} - ~QDeclarativeViewPrivate() { delete root; delete engine; } - void execute(); - void itemGeometryChanged(QDeclarativeItem *item, const QRectF &newGeometry, const QRectF &oldGeometry); - void initResize(); - void updateSize(); - inline QSize rootObjectSize() const; - - QDeclarativeGuard<QGraphicsObject> root; - QDeclarativeGuard<QDeclarativeItem> declarativeItemRoot; - QDeclarativeGuard<QGraphicsWidget> graphicsWidgetRoot; - - QUrl source; - - QDeclarativeEngine* engine; - QDeclarativeComponent *component; - QBasicTimer resizetimer; - - QDeclarativeView::ResizeMode resizeMode; - QSize initialSize; - QElapsedTimer frameTimer; - - void init(); -}; - -void QDeclarativeViewPrivate::execute() -{ - Q_Q(QDeclarativeView); - if (root) { - delete root; - root = 0; - } - if (component) { - delete component; - component = 0; - } - if (!source.isEmpty()) { - component = new QDeclarativeComponent(engine, source, q); - if (!component->isLoading()) { - q->continueExecute(); - } else { - QObject::connect(component, SIGNAL(statusChanged(QDeclarativeComponent::Status)), q, SLOT(continueExecute())); - } - } -} - -void QDeclarativeViewPrivate::itemGeometryChanged(QDeclarativeItem *resizeItem, const QRectF &newGeometry, const QRectF &oldGeometry) -{ - Q_Q(QDeclarativeView); - if (resizeItem == root && resizeMode == QDeclarativeView::SizeViewToRootObject) { - // wait for both width and height to be changed - resizetimer.start(0,q); - } - QDeclarativeItemChangeListener::itemGeometryChanged(resizeItem, newGeometry, oldGeometry); -} - -/*! - \class QDeclarativeView - \since 4.7 - \brief The QDeclarativeView class provides a widget for displaying a Qt Declarative user interface. - - QDeclarativeItem objects can be placed on a standard QGraphicsScene and - displayed with QGraphicsView. QDeclarativeView is a QGraphicsView subclass - provided as a convenience for displaying QML files, and connecting between - QML and C++ Qt objects. - - QDeclarativeView provides: - - \list - \o Management of QDeclarativeComponent loading and object creation - \o Initialization of QGraphicsView for optimal performance with QML using these settings: - \list - \o QGraphicsView::setOptimizationFlags(QGraphicsView::DontSavePainterState) - \o QGraphicsView::setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate) - \o QGraphicsScene::setItemIndexMethod(QGraphicsScene::NoIndex) - \endlist - \o Initialization of QGraphicsView for QML key handling using these settings: - \list - \o QGraphicsView::viewport()->setFocusPolicy(Qt::NoFocus) - \o QGraphicsView::setFocusPolicy(Qt::StrongFocus) - \o QGraphicsScene::setStickyFocus(true) - \endlist - \endlist - - Typical usage: - - \code - QDeclarativeView *view = new QDeclarativeView; - view->setSource(QUrl::fromLocalFile("myqmlfile.qml")); - view->show(); - \endcode - - Since QDeclarativeView is a QWidget-based class, it can be used to - display QML interfaces within QWidget-based GUI applications that do not - use the Graphics View framework. - - To receive errors related to loading and executing QML with QDeclarativeView, - you can connect to the statusChanged() signal and monitor for QDeclarativeView::Error. - The errors are available via QDeclarativeView::errors(). - - If you're using your own QGraphicsScene-based scene with QDeclarativeView, remember to - enable scene's sticky focus mode and to set itemIndexMethod to QGraphicsScene::NoIndex. - - \sa {Integrating QML Code with Existing Qt UI Code}, {Using QML Bindings in C++ Applications} -*/ - - -/*! \fn void QDeclarativeView::sceneResized(QSize size) - This signal is emitted when the view is resized to \a size. -*/ - -/*! \fn void QDeclarativeView::statusChanged(QDeclarativeView::Status status) - This signal is emitted when the component's current \a status changes. -*/ - -/*! - \fn QDeclarativeView::QDeclarativeView(QWidget *parent) - - Constructs a QDeclarativeView with the given \a parent. -*/ -QDeclarativeView::QDeclarativeView(QWidget *parent) - : QGraphicsView(*(new QDeclarativeViewPrivate), parent) -{ - Q_D(QDeclarativeView); - setSizePolicy(QSizePolicy::Preferred,QSizePolicy::Preferred); - d->init(); -} - -/*! - \fn QDeclarativeView::QDeclarativeView(const QUrl &source, QWidget *parent) - - Constructs a QDeclarativeView with the given QML \a source and \a parent. -*/ -QDeclarativeView::QDeclarativeView(const QUrl &source, QWidget *parent) - : QGraphicsView(*(new QDeclarativeViewPrivate), parent) -{ - Q_D(QDeclarativeView); - setSizePolicy(QSizePolicy::Preferred,QSizePolicy::Preferred); - d->init(); - setSource(source); -} - -void QDeclarativeViewPrivate::init() -{ - Q_Q(QDeclarativeView); - engine = new QDeclarativeEngine(); - q->setScene(new QDeclarativeScene(q)); - - q->setOptimizationFlags(QGraphicsView::DontSavePainterState); - q->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - q->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - q->setFrameStyle(0); - - // These seem to give the best performance - q->setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate); - q->scene()->setItemIndexMethod(QGraphicsScene::NoIndex); - q->viewport()->setFocusPolicy(Qt::NoFocus); - q->setFocusPolicy(Qt::StrongFocus); - - q->scene()->setStickyFocus(true); //### needed for correct focus handling - -#ifdef QDECLARATIVEVIEW_NOBACKGROUND - q->setAttribute(Qt::WA_OpaquePaintEvent); - q->setAttribute(Qt::WA_NoSystemBackground); - q->viewport()->setAttribute(Qt::WA_OpaquePaintEvent); - q->viewport()->setAttribute(Qt::WA_NoSystemBackground); -#endif - - QDeclarativeInspectorService::instance()->addView(q); -} - -/*! - Destroys the view. - */ -QDeclarativeView::~QDeclarativeView() -{ - QDeclarativeInspectorService::instance()->removeView(this); -} - -/*! \property QDeclarativeView::source - \brief The URL of the source of the QML component. - - Changing this property causes the QML component to be reloaded. - - Ensure that the URL provided is full and correct, in particular, use - \l QUrl::fromLocalFile() when loading a file from the local filesystem. - */ - -/*! - Sets the source to the \a url, loads the QML component and instantiates it. - - Ensure that the URL provided is full and correct, in particular, use - \l QUrl::fromLocalFile() when loading a file from the local filesystem. - - Calling this methods multiple times with the same url will result - in the QML being reloaded. - */ -void QDeclarativeView::setSource(const QUrl& url) -{ - Q_D(QDeclarativeView); - d->source = url; - d->execute(); -} - -/*! - Returns the source URL, if set. - - \sa setSource() - */ -QUrl QDeclarativeView::source() const -{ - Q_D(const QDeclarativeView); - return d->source; -} - -/*! - Returns a pointer to the QDeclarativeEngine used for instantiating - QML Components. - */ -QDeclarativeEngine* QDeclarativeView::engine() const -{ - Q_D(const QDeclarativeView); - return d->engine; -} - -/*! - This function returns the root of the context hierarchy. Each QML - component is instantiated in a QDeclarativeContext. QDeclarativeContext's are - essential for passing data to QML components. In QML, contexts are - arranged hierarchically and this hierarchy is managed by the - QDeclarativeEngine. - */ -QDeclarativeContext* QDeclarativeView::rootContext() const -{ - Q_D(const QDeclarativeView); - return d->engine->rootContext(); -} - -/*! - \enum QDeclarativeView::Status - Specifies the loading status of the QDeclarativeView. - - \value Null This QDeclarativeView has no source set. - \value Ready This QDeclarativeView has loaded and created the QML component. - \value Loading This QDeclarativeView is loading network data. - \value Error One or more errors has occurred. Call errors() to retrieve a list - of errors. -*/ - -/*! \enum QDeclarativeView::ResizeMode - - This enum specifies how to resize the view. - - \value SizeViewToRootObject The view resizes with the root item in the QML. - \value SizeRootObjectToView The view will automatically resize the root item to the size of the view. -*/ - -/*! - \property QDeclarativeView::status - The component's current \l{QDeclarativeView::Status} {status}. -*/ - -QDeclarativeView::Status QDeclarativeView::status() const -{ - Q_D(const QDeclarativeView); - if (!d->component) - return QDeclarativeView::Null; - - return QDeclarativeView::Status(d->component->status()); -} - -/*! - Return the list of errors that occurred during the last compile or create - operation. When the status is not Error, an empty list is returned. -*/ -QList<QDeclarativeError> QDeclarativeView::errors() const -{ - Q_D(const QDeclarativeView); - if (d->component) - return d->component->errors(); - return QList<QDeclarativeError>(); -} - -/*! - \property QDeclarativeView::resizeMode - \brief whether the view should resize the canvas contents - - If this property is set to SizeViewToRootObject (the default), the view - resizes with the root item in the QML. - - If this property is set to SizeRootObjectToView, the view will - automatically resize the root item. - - Regardless of this property, the sizeHint of the view - is the initial size of the root item. Note though that - since QML may load dynamically, that size may change. -*/ - -void QDeclarativeView::setResizeMode(ResizeMode mode) -{ - Q_D(QDeclarativeView); - if (d->resizeMode == mode) - return; - - if (d->declarativeItemRoot) { - if (d->resizeMode == SizeViewToRootObject) { - QDeclarativeItemPrivate *p = - static_cast<QDeclarativeItemPrivate *>(QGraphicsItemPrivate::get(d->declarativeItemRoot)); - p->removeItemChangeListener(d, QDeclarativeItemPrivate::Geometry); - } - } else if (d->graphicsWidgetRoot) { - if (d->resizeMode == QDeclarativeView::SizeViewToRootObject) { - d->graphicsWidgetRoot->removeEventFilter(this); - } - } - - d->resizeMode = mode; - if (d->root) { - d->initResize(); - } -} - -void QDeclarativeViewPrivate::initResize() -{ - Q_Q(QDeclarativeView); - if (declarativeItemRoot) { - if (resizeMode == QDeclarativeView::SizeViewToRootObject) { - QDeclarativeItemPrivate *p = - static_cast<QDeclarativeItemPrivate *>(QGraphicsItemPrivate::get(declarativeItemRoot)); - p->addItemChangeListener(this, QDeclarativeItemPrivate::Geometry); - } - } else if (graphicsWidgetRoot) { - if (resizeMode == QDeclarativeView::SizeViewToRootObject) { - graphicsWidgetRoot->installEventFilter(q); - } - } - updateSize(); -} - -void QDeclarativeViewPrivate::updateSize() -{ - Q_Q(QDeclarativeView); - if (!root) - return; - if (declarativeItemRoot) { - if (resizeMode == QDeclarativeView::SizeViewToRootObject) { - QSize newSize = QSize(declarativeItemRoot->width(), declarativeItemRoot->height()); - if (newSize.isValid() && newSize != q->size()) { - q->resize(newSize); - } - } else if (resizeMode == QDeclarativeView::SizeRootObjectToView) { - if (!qFuzzyCompare(q->width(), declarativeItemRoot->width())) - declarativeItemRoot->setWidth(q->width()); - if (!qFuzzyCompare(q->height(), declarativeItemRoot->height())) - declarativeItemRoot->setHeight(q->height()); - } - } else if (graphicsWidgetRoot) { - if (resizeMode == QDeclarativeView::SizeViewToRootObject) { - QSize newSize = QSize(graphicsWidgetRoot->size().width(), graphicsWidgetRoot->size().height()); - if (newSize.isValid() && newSize != q->size()) { - q->resize(newSize); - } - } else if (resizeMode == QDeclarativeView::SizeRootObjectToView) { - QSizeF newSize = QSize(q->size().width(), q->size().height()); - if (newSize.isValid() && newSize != graphicsWidgetRoot->size()) { - graphicsWidgetRoot->resize(newSize); - } - } - } - q->updateGeometry(); -} - -QSize QDeclarativeViewPrivate::rootObjectSize() const -{ - QSize rootObjectSize(0,0); - int widthCandidate = -1; - int heightCandidate = -1; - if (root) { - QSizeF size = root->boundingRect().size(); - widthCandidate = size.width(); - heightCandidate = size.height(); - } - if (widthCandidate > 0) { - rootObjectSize.setWidth(widthCandidate); - } - if (heightCandidate > 0) { - rootObjectSize.setHeight(heightCandidate); - } - return rootObjectSize; -} - -QDeclarativeView::ResizeMode QDeclarativeView::resizeMode() const -{ - Q_D(const QDeclarativeView); - return d->resizeMode; -} - -/*! - \internal - */ -void QDeclarativeView::continueExecute() -{ - Q_D(QDeclarativeView); - disconnect(d->component, SIGNAL(statusChanged(QDeclarativeComponent::Status)), this, SLOT(continueExecute())); - - if (d->component->isError()) { - QList<QDeclarativeError> errorList = d->component->errors(); - foreach (const QDeclarativeError &error, errorList) { - qWarning() << error; - } - emit statusChanged(status()); - return; - } - - QObject *obj = d->component->create(); - - if(d->component->isError()) { - QList<QDeclarativeError> errorList = d->component->errors(); - foreach (const QDeclarativeError &error, errorList) { - qWarning() << error; - } - emit statusChanged(status()); - return; - } - - setRootObject(obj); - emit statusChanged(status()); -} - -/*! - \internal -*/ -void QDeclarativeView::setRootObject(QObject *obj) -{ - Q_D(QDeclarativeView); - if (d->root == obj || !scene()) - return; - if (QDeclarativeItem *declarativeItem = qobject_cast<QDeclarativeItem *>(obj)) { - scene()->addItem(declarativeItem); - d->root = declarativeItem; - d->declarativeItemRoot = declarativeItem; - } else if (QGraphicsObject *graphicsObject = qobject_cast<QGraphicsObject *>(obj)) { - scene()->addItem(graphicsObject); - d->root = graphicsObject; - if (graphicsObject->isWidget()) { - d->graphicsWidgetRoot = static_cast<QGraphicsWidget*>(graphicsObject); - } else { - qWarning() << "QDeclarativeView::resizeMode is not honored for components of type QGraphicsObject"; - } - } else if (obj) { - qWarning() << "QDeclarativeView only supports loading of root objects that derive from QGraphicsObject"; - if (QWidget* widget = qobject_cast<QWidget *>(obj)) { - window()->setAttribute(Qt::WA_OpaquePaintEvent, false); - window()->setAttribute(Qt::WA_NoSystemBackground, false); - if (layout() && layout()->count()) { - // Hide the QGraphicsView in GV mode. - QLayoutItem *item = layout()->itemAt(0); - if (item->widget()) - item->widget()->hide(); - } - widget->setParent(this); - if (isVisible()) { - widget->setVisible(true); - } - resize(widget->size()); - } - } - - if (d->root) { - d->initialSize = d->rootObjectSize(); - if (d->initialSize != size()) { - if (!(parentWidget() && parentWidget()->layout())) { - resize(d->initialSize); - } - } - d->initResize(); - } -} - -/*! - \internal - If the \l {QTimerEvent} {timer event} \a e is this - view's resize timer, sceneResized() is emitted. - */ -void QDeclarativeView::timerEvent(QTimerEvent* e) -{ - Q_D(QDeclarativeView); - if (!e || e->timerId() == d->resizetimer.timerId()) { - d->updateSize(); - d->resizetimer.stop(); - } -} - -/*! \internal */ -bool QDeclarativeView::eventFilter(QObject *watched, QEvent *e) -{ - Q_D(QDeclarativeView); - if (watched == d->root && d->resizeMode == SizeViewToRootObject) { - if (d->graphicsWidgetRoot) { - if (e->type() == QEvent::GraphicsSceneResize) { - d->updateSize(); - } - } - } - return QGraphicsView::eventFilter(watched, e); -} - -/*! - \internal - Preferred size follows the root object geometry. -*/ -QSize QDeclarativeView::sizeHint() const -{ - Q_D(const QDeclarativeView); - QSize rootObjectSize = d->rootObjectSize(); - if (rootObjectSize.isEmpty()) { - return size(); - } else { - return rootObjectSize; - } -} - -/*! - Returns the initial size of the root object -*/ -QSize QDeclarativeView::initialSize() const -{ - Q_D(const QDeclarativeView); - return d->initialSize; -} - -/*! - Returns the view's root \l {QGraphicsObject} {item}. - */ -QGraphicsObject *QDeclarativeView::rootObject() const -{ - Q_D(const QDeclarativeView); - return d->root; -} - -/*! - \internal - This function handles the \l {QResizeEvent} {resize event} - \a e. - */ -void QDeclarativeView::resizeEvent(QResizeEvent *e) -{ - Q_D(QDeclarativeView); - if (d->resizeMode == SizeRootObjectToView) { - d->updateSize(); - } - if (d->declarativeItemRoot) { - setSceneRect(QRectF(0, 0, d->declarativeItemRoot->width(), d->declarativeItemRoot->height())); - } else if (d->root) { - setSceneRect(d->root->boundingRect()); - } else { - setSceneRect(rect()); - } - emit sceneResized(e->size()); - QGraphicsView::resizeEvent(e); -} - -/*! - \internal -*/ -void QDeclarativeView::paintEvent(QPaintEvent *event) -{ - Q_D(QDeclarativeView); - - QDeclarativeDebugTrace::addEvent(QDeclarativeDebugTrace::FramePaint); - QDeclarativeDebugTrace::startRange(QDeclarativeDebugTrace::Painting); - - int time = 0; - if (frameRateDebug()) - time = d->frameTimer.restart(); - - QGraphicsView::paintEvent(event); - - QDeclarativeDebugTrace::endRange(QDeclarativeDebugTrace::Painting); - - if (frameRateDebug()) - qDebug() << "paintEvent:" << d->frameTimer.elapsed() << "time since last frame:" << time; - -#if QT_SHOW_DECLARATIVEVIEW_FPS - static QTime timer; - static int frames; - - if (frames == 0) { - timer.start(); - } else if (timer.elapsed() > 5000) { - qreal avgtime = timer.elapsed() / (qreal) frames; - qDebug("Average time per frame: %f ms (%i fps)", avgtime, int(1000 / avgtime)); - timer.start(); - frames = 0; - } - ++frames; - scene()->update(); -#endif - -} - -QT_END_NAMESPACE diff --git a/src/declarative/util/qdeclarativeview.h b/src/declarative/util/qdeclarativeview.h deleted file mode 100644 index 6959d246e4..0000000000 --- a/src/declarative/util/qdeclarativeview.h +++ /dev/null @@ -1,120 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QDECLARATIVEVIEW_H -#define QDECLARATIVEVIEW_H - -#include <QtCore/qdatetime.h> -#include <QtCore/qurl.h> -#include <QtGui/qgraphicssceneevent.h> -#include <QtGui/qgraphicsview.h> -#include <QtGui/qwidget.h> - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QGraphicsObject; -class QDeclarativeEngine; -class QDeclarativeContext; -class QDeclarativeError; - -class QDeclarativeViewPrivate; -class Q_DECLARATIVE_EXPORT QDeclarativeView : public QGraphicsView -{ - Q_OBJECT - Q_PROPERTY(ResizeMode resizeMode READ resizeMode WRITE setResizeMode) - Q_PROPERTY(Status status READ status NOTIFY statusChanged) - Q_PROPERTY(QUrl source READ source WRITE setSource DESIGNABLE true) - Q_ENUMS(ResizeMode Status) -public: - explicit QDeclarativeView(QWidget *parent = 0); - QDeclarativeView(const QUrl &source, QWidget *parent = 0); - virtual ~QDeclarativeView(); - - QUrl source() const; - - QDeclarativeEngine* engine() const; - QDeclarativeContext* rootContext() const; - - QGraphicsObject *rootObject() const; - - enum ResizeMode { SizeViewToRootObject, SizeRootObjectToView }; - ResizeMode resizeMode() const; - void setResizeMode(ResizeMode); - - enum Status { Null, Ready, Loading, Error }; - Status status() const; - - QList<QDeclarativeError> errors() const; - - QSize sizeHint() const; - QSize initialSize() const; - -public Q_SLOTS: - void setSource(const QUrl&); - -Q_SIGNALS: - void sceneResized(QSize size); // ??? - void statusChanged(QDeclarativeView::Status); - -private Q_SLOTS: - void continueExecute(); - -protected: - virtual void resizeEvent(QResizeEvent *); - virtual void paintEvent(QPaintEvent *event); - virtual void timerEvent(QTimerEvent*); - virtual void setRootObject(QObject *obj); - virtual bool eventFilter(QObject *watched, QEvent *e); - -private: - Q_DISABLE_COPY(QDeclarativeView) - Q_DECLARE_PRIVATE(QDeclarativeView) -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QDECLARATIVEVIEW_H diff --git a/src/declarative/util/util.pri b/src/declarative/util/util.pri index 4bd1f1bb1b..965acf80c6 100644 --- a/src/declarative/util/util.pri +++ b/src/declarative/util/util.pri @@ -3,7 +3,6 @@ INCLUDEPATH += $$PWD SOURCES += \ $$PWD/qdeclarativeapplication.cpp \ $$PWD/qdeclarativeutilmodule.cpp\ - $$PWD/qdeclarativeview.cpp \ $$PWD/qdeclarativeconnections.cpp \ $$PWD/qdeclarativepackage.cpp \ $$PWD/qdeclarativeanimation.cpp \ @@ -28,13 +27,13 @@ SOURCES += \ $$PWD/qdeclarativefontloader.cpp \ $$PWD/qdeclarativestyledtext.cpp \ $$PWD/qdeclarativelistmodelworkeragent.cpp \ + $$PWD/qdeclarativepath.cpp \ $$PWD/qdeclarativechangeset.cpp \ $$PWD/qlistmodelinterface.cpp HEADERS += \ $$PWD/qdeclarativeapplication_p.h \ $$PWD/qdeclarativeutilmodule_p.h\ - $$PWD/qdeclarativeview.h \ $$PWD/qdeclarativeconnections_p.h \ $$PWD/qdeclarativepackage_p.h \ $$PWD/qdeclarativeanimation_p.h \ @@ -54,7 +53,6 @@ HEADERS += \ $$PWD/qdeclarativelistmodel_p_p.h\ $$PWD/qdeclarativelistaccessor_p.h \ $$PWD/qdeclarativeopenmetaobject_p.h \ - $$PWD/qdeclarativenullablevalue_p_p.h \ $$PWD/qdeclarativetimeline_p_p.h \ $$PWD/qdeclarativetimer_p.h \ $$PWD/qdeclarativebind_p.h \ @@ -64,6 +62,8 @@ HEADERS += \ $$PWD/qdeclarativefontloader_p.h \ $$PWD/qdeclarativestyledtext_p.h \ $$PWD/qdeclarativelistmodelworkeragent_p.h \ + $$PWD/qdeclarativepath_p.h \ + $$PWD/qdeclarativepath_p_p.h \ $$PWD/qdeclarativechangeset_p.h \ $$PWD/qlistmodelinterface_p.h |