diff options
author | Aaron Kennedy <aaron.kennedy@nokia.com> | 2010-07-09 05:36:49 (GMT) |
---|---|---|
committer | Aaron Kennedy <aaron.kennedy@nokia.com> | 2010-07-09 05:36:49 (GMT) |
commit | 74a248462ef36f7784fd0816ee08030412459930 (patch) | |
tree | ab41c0313467be480446397a8fe5463abee83035 /src/declarative | |
parent | 49b828102626ba6faa38ea48d9f570283dd7fa9f (diff) | |
parent | 31cd8c15c0fdb2f08c2652609a57413a715d1b13 (diff) | |
download | Qt-74a248462ef36f7784fd0816ee08030412459930.zip Qt-74a248462ef36f7784fd0816ee08030412459930.tar.gz Qt-74a248462ef36f7784fd0816ee08030412459930.tar.bz2 |
Merge branch '4.7' of scm.dev.nokia.troll.no:qt/qt-qml into 4.7
Diffstat (limited to 'src/declarative')
20 files changed, 61 insertions, 1041 deletions
diff --git a/src/declarative/QmlChanges.txt b/src/declarative/QmlChanges.txt index 91442c1..259d9a9 100644 --- a/src/declarative/QmlChanges.txt +++ b/src/declarative/QmlChanges.txt @@ -16,8 +16,11 @@ Component: - errorsString() renamed to errorString() ListView: - ListView.prevSection property changed to ListView.previousSection - -TextInput xToPosition -> positionAt (to match TextEdit.positionAt) +TextInput: + - xToPosition -> positionAt (to match TextEdit.positionAt) +Image: + - pixmap property removed, use QDeclarativeImageProvider to serve pixmaps + instead QList<QObject*> models no longer provide properties in model object. The properties are now updated when the object changes. An object's property @@ -35,6 +38,10 @@ The QDeclarativeExpression constructor has changed from to QDeclarativeExpression(context, scope, expression, parent = 0) +QDeclarativeImageProvider::request() has been renamed to +QDeclarativeImageProvider::image() and the class can now provide +both qimages and qpixmaps, and qimages can be served synchronously + QML Viewer ------------ The standalone qml executable has been renamed back to Qml Viewer. Runtime warnings diff --git a/src/declarative/graphicsitems/qdeclarativegridview.cpp b/src/declarative/graphicsitems/qdeclarativegridview.cpp index 3efb9ad..dce6f0e 100644 --- a/src/declarative/graphicsitems/qdeclarativegridview.cpp +++ b/src/declarative/graphicsitems/qdeclarativegridview.cpp @@ -1390,7 +1390,7 @@ void QDeclarativeGridView::setHighlight(QDeclarativeComponent *highlight) highlight is not moved by the view, and any movement must be implemented by the highlight. - Here is a highlight with its motion defined by a \l {SpringFollow} item: + Here is a highlight with its motion defined by a \l {SpringAnimation} item: \snippet doc/src/snippets/declarative/gridview/gridview.qml highlightFollowsCurrentItem */ diff --git a/src/declarative/graphicsitems/qdeclarativeimage.cpp b/src/declarative/graphicsitems/qdeclarativeimage.cpp index 666ff3f..34d33f5 100644 --- a/src/declarative/graphicsitems/qdeclarativeimage.cpp +++ b/src/declarative/graphicsitems/qdeclarativeimage.cpp @@ -116,15 +116,6 @@ QDeclarativeImage::~QDeclarativeImage() { } -/*! - \qmlproperty QPixmap Image::pixmap - - This property holds the QPixmap image to display. - - This is useful for displaying images provided by a C++ implementation, - for example, a model may provide a data role of type QPixmap. -*/ - QPixmap QDeclarativeImage::pixmap() const { Q_D(const QDeclarativeImage); @@ -524,7 +515,6 @@ void QDeclarativeImage::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWi void QDeclarativeImage::pixmapChange() { updatePaintedGeometry(); - emit pixmapChanged(); } QT_END_NAMESPACE diff --git a/src/declarative/graphicsitems/qdeclarativeimage_p.h b/src/declarative/graphicsitems/qdeclarativeimage_p.h index a4f4475..c8bb30b 100644 --- a/src/declarative/graphicsitems/qdeclarativeimage_p.h +++ b/src/declarative/graphicsitems/qdeclarativeimage_p.h @@ -57,7 +57,6 @@ class Q_AUTOTEST_EXPORT QDeclarativeImage : public QDeclarativeImageBase Q_OBJECT Q_ENUMS(FillMode) - Q_PROPERTY(QPixmap pixmap READ pixmap WRITE setPixmap NOTIFY pixmapChanged DESIGNABLE false) Q_PROPERTY(FillMode fillMode READ fillMode WRITE setFillMode NOTIFY fillModeChanged) Q_PROPERTY(qreal paintedWidth READ paintedWidth NOTIFY paintedGeometryChanged) Q_PROPERTY(qreal paintedHeight READ paintedHeight NOTIFY paintedGeometryChanged) @@ -79,7 +78,6 @@ public: void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); Q_SIGNALS: - void pixmapChanged(); void fillModeChanged(); void paintedGeometryChanged(); diff --git a/src/declarative/graphicsitems/qdeclarativelistview.cpp b/src/declarative/graphicsitems/qdeclarativelistview.cpp index 9497cb7..91e9995 100644 --- a/src/declarative/graphicsitems/qdeclarativelistview.cpp +++ b/src/declarative/graphicsitems/qdeclarativelistview.cpp @@ -1727,7 +1727,7 @@ void QDeclarativeListView::setHighlight(QDeclarativeComponent *highlight) highlight is not moved by the view, and any movement must be implemented by the highlight. - Here is a highlight with its motion defined by a \l {SpringFollow} item: + Here is a highlight with its motion defined by a \l {SpringAniamtion} item: \snippet doc/src/snippets/declarative/listview/listview.qml highlightFollowsCurrentItem diff --git a/src/declarative/qml/qdeclarativecomponent.cpp b/src/declarative/qml/qdeclarativecomponent.cpp index 04ec382..36c4b49 100644 --- a/src/declarative/qml/qdeclarativecomponent.cpp +++ b/src/declarative/qml/qdeclarativecomponent.cpp @@ -108,27 +108,45 @@ class QByteArray; \brief The Component element encapsulates a QML component definition. Components are reusable, encapsulated QML elements with well-defined interfaces. - They are often defined in \l {qdeclarativedocuments.html}{Component Files}. - The \e Component element allows defining components within a QML file. - This can be useful for reusing a small component within a single QML - file, or for defining a component that logically belongs with the - file containing it. + Components are often defined by \l {qdeclarativedocuments.html}{component files} - + that is, \c .qml files. The \e Component element allows components to be defined + within QML items rather than in a separate file. This may be useful for reusing + a small component within a QML file, or for defining a component that logically + belongs with other QML components within a file. + + For example, here is a component that is used by multiple \l Loader objects: \qml Item { Component { id: redSquare + Rectangle { color: "red" width: 10 height: 10 } } + Loader { sourceComponent: redSquare } Loader { sourceComponent: redSquare; x: 20 } } \endqml + + Notice that while a \l Rectangle by itself would be automatically + rendered and displayed, this is not the case for the above rectangle + because it is defined inside a \c Component. The component encapsulates the + QML elements within, as if they were defined in a separate \c .qml + file, and is not loaded until requested (in this case, by the + two \l Loader objects). + + The Component element is commonly used to provide graphical components + for views. For example, the ListView::delegate property requires a Component + to specify how each list item is to be displayed. + + Component objects can also be dynamically generated using + \l{Qt::createComponent}{Qt.createComponent()}. */ /*! diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp index 2e37af7..00bc1b7 100644 --- a/src/declarative/qml/qdeclarativeengine.cpp +++ b/src/declarative/qml/qdeclarativeengine.cpp @@ -1090,6 +1090,8 @@ If you are certain the files will be local, you could simplify to: To create a QML object from an arbitrary string of QML (instead of a file), use \l{QML:Qt::createQmlObject()}{Qt.createQmlObject()}. + +\sa {Dynamic Object Management} */ QScriptValue QDeclarativeEnginePrivate::createComponent(QScriptContext *ctxt, QScriptEngine *engine) @@ -1137,6 +1139,8 @@ Each object in this array has the members \c lineNumber, \c columnNumber, \c fil Note that this function returns immediately, and therefore may not work if the \a qml string loads new components (that is, external QML files that have not yet been loaded). If this is the case, consider using \l{QML:Qt::createComponent()}{Qt.createComponent()} instead. + +\sa {Dynamic Object Management} */ QScriptValue QDeclarativeEnginePrivate::createQmlObject(QScriptContext *ctxt, QScriptEngine *engine) diff --git a/src/declarative/util/qdeclarativeanimation.cpp b/src/declarative/util/qdeclarativeanimation.cpp index 6559bd5..bdb9510 100644 --- a/src/declarative/util/qdeclarativeanimation.cpp +++ b/src/declarative/util/qdeclarativeanimation.cpp @@ -142,8 +142,8 @@ bool QDeclarativeAbstractAnimation::isRunning() const return d->running; } -// the behavior connects the animation to this slot -void QDeclarativeAbstractAnimation::behaviorControlRunningChanged(bool running) +// the behavior calls this function +void QDeclarativeAbstractAnimation::notifyRunningChanged(bool running) { Q_D(QDeclarativeAbstractAnimation); if (d->disableUserControl && d->running != running) { diff --git a/src/declarative/util/qdeclarativeanimation_p.h b/src/declarative/util/qdeclarativeanimation_p.h index 2279b0e..59bd465 100644 --- a/src/declarative/util/qdeclarativeanimation_p.h +++ b/src/declarative/util/qdeclarativeanimation_p.h @@ -134,10 +134,12 @@ public: private Q_SLOTS: void timelineComplete(); void componentFinalized(); - void behaviorControlRunningChanged(bool running); - private: virtual void setTarget(const QDeclarativeProperty &); + void notifyRunningChanged(bool running); + friend class QDeclarativeBehavior; + + }; class QDeclarativePauseAnimationPrivate; diff --git a/src/declarative/util/qdeclarativebehavior.cpp b/src/declarative/util/qdeclarativebehavior.cpp index 4480e75..2bb28c3 100644 --- a/src/declarative/util/qdeclarativebehavior.cpp +++ b/src/declarative/util/qdeclarativebehavior.cpp @@ -138,10 +138,6 @@ void QDeclarativeBehavior::setAnimation(QDeclarativeAbstractAnimation *animation SIGNAL(stateChanged(QAbstractAnimation::State,QAbstractAnimation::State)), this, SLOT(qtAnimationStateChanged(QAbstractAnimation::State,QAbstractAnimation::State))); - connect(this, - SIGNAL(qtAnimationRunningChanged(bool)), - d->animation, - SLOT(behaviorControlRunningChanged(bool))); } } @@ -150,7 +146,7 @@ void QDeclarativeBehavior::qtAnimationStateChanged(QAbstractAnimation::State new { Q_D(QDeclarativeBehavior); if (!d->blockRunningChanged) - emit qtAnimationRunningChanged(newState == QAbstractAnimation::Running); + d->animation->notifyRunningChanged(newState == QAbstractAnimation::Running); } diff --git a/src/declarative/util/qdeclarativebehavior_p.h b/src/declarative/util/qdeclarativebehavior_p.h index a3132d9..9801fb2 100644 --- a/src/declarative/util/qdeclarativebehavior_p.h +++ b/src/declarative/util/qdeclarativebehavior_p.h @@ -83,7 +83,6 @@ public: Q_SIGNALS: void enabledChanged(); - void qtAnimationRunningChanged(bool running); private Q_SLOTS: void componentFinalized(); diff --git a/src/declarative/util/qdeclarativepixmapcache.cpp b/src/declarative/util/qdeclarativepixmapcache.cpp index f729ced..00dd922 100644 --- a/src/declarative/util/qdeclarativepixmapcache.cpp +++ b/src/declarative/util/qdeclarativepixmapcache.cpp @@ -952,10 +952,9 @@ void QDeclarativePixmap::load(QDeclarativeEngine *engine, const QUrl &url, const if (iter == store->m_cache.end()) { if (async) { + // pixmaps can only be loaded synchronously if (url.scheme() == QLatin1String("image") && QDeclarativeEnginePrivate::get(engine)->getImageProviderType(url) == QDeclarativeImageProvider::Pixmap) { - qWarning().nospace() << "Pixmaps must be loaded synchronously, ignoring asynchronous property for Image with source: " - << url.toString(); async = false; } } diff --git a/src/declarative/util/qdeclarativesmoothedanimation.cpp b/src/declarative/util/qdeclarativesmoothedanimation.cpp index 6b6df4d..5d47c30 100644 --- a/src/declarative/util/qdeclarativesmoothedanimation.cpp +++ b/src/declarative/util/qdeclarativesmoothedanimation.cpp @@ -307,7 +307,7 @@ Rectangle { set to a value such as 0.5 units/second. Animating from 0 to 1.0 with a velocity of 0.5 will take 2000 ms to complete. - \sa SpringFollow, {QML Animation}, {declarative/animation/basics}{Animation basics example} + \sa {QML Animation}, {declarative/animation/basics}{Animation basics example} */ QDeclarativeSmoothedAnimation::QDeclarativeSmoothedAnimation(QObject *parent) diff --git a/src/declarative/util/qdeclarativesmoothedfollow.cpp b/src/declarative/util/qdeclarativesmoothedfollow.cpp deleted file mode 100644 index f70df9d..0000000 --- a/src/declarative/util/qdeclarativesmoothedfollow.cpp +++ /dev/null @@ -1,299 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 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$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, 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. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qdeclarativesmoothedfollow_p.h" -#include "qdeclarativesmoothedanimation_p_p.h" - -#include <private/qobject_p.h> -#include <QtCore/qnumeric.h> - -#include "qdeclarativeglobal_p.h" - - -QT_BEGIN_NAMESPACE - -class QDeclarativeSmoothedFollowPrivate : public QObjectPrivate -{ - Q_DECLARE_PUBLIC(QDeclarativeSmoothedFollow) -public: - QDeclarativeSmoothedFollowPrivate(); - - bool enabled; - QSmoothedAnimation *anim; -}; - -/*! - \qmlclass SmoothedFollow QDeclarativeSmoothedFollow - \since 4.7 - \inherits NumberAnimation - \brief The SmoothedFollow element allows a property to smoothly track a value. - - The SmoothedFollow animates a property's value to a set target value - using an ease in/out quad easing curve. If the animation is restarted - with a different target value, the easing curves used to animate to the old - and the new target values are smoothly spliced together to avoid any obvious - visual glitches by maintaining the current velocity. - - The property animation is configured by setting the velocity at which the - animation should occur, or the duration that the animation should take. - If both a velocity and a duration are specified, the one that results in - the quickest animation is chosen for each change in the target value. - - For example, animating from 0 to 800 will take 4 seconds if a velocity - of 200 is set, will take 8 seconds with a duration of 8000 set, and will - take 4 seconds with both a velocity of 200 and a duration of 8000 set. - Animating from 0 to 20000 will take 10 seconds if a velocity of 200 is set, - will take 8 seconds with a duration of 8000 set, and will take 8 seconds - with both a velocity of 200 and a duration of 8000 set. - - The follow example shows one rectangle tracking the position of another. -\code -import Qt 4.7 - -Rectangle { - width: 800; height: 600; color: "blue" - - Rectangle { - color: "green" - width: 60; height: 60; - SmoothedFollow on x { to: rect1.x - 5; velocity: 200 } - SmoothedFollow on y { to: rect1.y - 5; velocity: 200 } - } - - Rectangle { - id: rect1 - color: "red" - width: 50; height: 50; - } - - focus: true - Keys.onRightPressed: rect1.x = rect1.x + 100 - Keys.onLeftPressed: rect1.x = rect1.x - 100 - Keys.onUpPressed: rect1.y = rect1.y - 100 - Keys.onDownPressed: rect1.y = rect1.y + 100 -} -\endcode - - The default velocity of SmoothedFollow is 200 units/second. Note that if the range of the - value being animated is small, then the velocity will need to be adjusted - appropriately. For example, the opacity of an item ranges from 0 - 1.0. - To enable a smooth animation in this range the velocity will need to be - set to a value such as 0.5 units/second. Animating from 0 to 1.0 with a velocity - of 0.5 will take 2000 ms to complete. - - \sa SpringFollow -*/ - -QDeclarativeSmoothedFollow::QDeclarativeSmoothedFollow(QObject *parent) - : QObject(*(new QDeclarativeSmoothedFollowPrivate), parent) -{ -} - -QDeclarativeSmoothedFollow::~QDeclarativeSmoothedFollow() -{ -} - -QDeclarativeSmoothedFollowPrivate::QDeclarativeSmoothedFollowPrivate() - : enabled(true), anim(new QSmoothedAnimation) -{ - Q_Q(QDeclarativeSmoothedFollow); - QDeclarative_setParent_noEvent(anim, q); -} - -/*! - \qmlproperty enumeration SmoothedFollow::reversingMode - - Sets how the SmoothedFollow behaves if an animation direction is reversed. - - If reversing mode is \c SmoothedFollow.Eased, the animation will smoothly decelerate, and - then reverse direction. If the reversing mode is \c SmoothedFollow.Immediate, the - animation will immediately begin accelerating in the reverse direction, - begining with a velocity of 0. If the reversing mode is \c SmoothedFollow.Sync, the - property is immediately set to the target value. -*/ -QDeclarativeSmoothedFollow::ReversingMode QDeclarativeSmoothedFollow::reversingMode() const -{ - Q_D(const QDeclarativeSmoothedFollow); - return (ReversingMode) d->anim->reversingMode; -} - -void QDeclarativeSmoothedFollow::setReversingMode(ReversingMode m) -{ - Q_D(QDeclarativeSmoothedFollow); - if (d->anim->reversingMode == (QDeclarativeSmoothedAnimation::ReversingMode) m) - return; - - d->anim->reversingMode = (QDeclarativeSmoothedAnimation::ReversingMode) m; - emit reversingModeChanged(); -} - -/*! - \qmlproperty int SmoothedFollow::duration - - This property holds the animation duration, in msecs, used when tracking the source. - - Setting this to -1 (the default) disables the duration value. -*/ -int QDeclarativeSmoothedFollow::duration() const -{ - Q_D(const QDeclarativeSmoothedFollow); - return d->anim->userDuration; -} - -void QDeclarativeSmoothedFollow::setDuration(int duration) -{ - Q_D(QDeclarativeSmoothedFollow); - if (duration == d->anim->duration()) - return; - - d->anim->userDuration = duration; - emit durationChanged(); -} - -qreal QDeclarativeSmoothedFollow::velocity() const -{ - Q_D(const QDeclarativeSmoothedFollow); - return d->anim->velocity; -} - -/*! - \qmlproperty real SmoothedFollow::velocity - - This property holds the average velocity allowed when tracking the 'to' value. - - The default velocity of SmoothedFollow is 200 units/second. - - Setting this to -1 disables the velocity value. -*/ -void QDeclarativeSmoothedFollow::setVelocity(qreal v) -{ - Q_D(QDeclarativeSmoothedFollow); - if (d->anim->velocity == v) - return; - - d->anim->velocity = v; - emit velocityChanged(); -} - -/*! - \qmlproperty int SmoothedFollow::maximumEasingTime - - This property specifies the maximum time, in msecs, an "eases" during the follow should take. - Setting this property causes the velocity to "level out" after at a time. Setting - a negative value reverts to the normal mode of easing over the entire animation - duration. - - The default value is -1. -*/ -int QDeclarativeSmoothedFollow::maximumEasingTime() const -{ - Q_D(const QDeclarativeSmoothedFollow); - return d->anim->maximumEasingTime; -} - -void QDeclarativeSmoothedFollow::setMaximumEasingTime(int v) -{ - Q_D(QDeclarativeSmoothedFollow); - d->anim->maximumEasingTime = v; - emit maximumEasingTimeChanged(); -} - -/*! - \qmlproperty real SmoothedFollow::to - This property holds the ending value. - If not set, then the value defined in the end state of the transition or Behavior. -*/ -qreal QDeclarativeSmoothedFollow::to() const -{ - Q_D(const QDeclarativeSmoothedFollow); - return d->anim->to; -} - -void QDeclarativeSmoothedFollow::setTo(qreal t) -{ - Q_D(QDeclarativeSmoothedFollow); - - if (qIsNaN(t)) - return; - - if (d->anim->to == t) - return; - - d->anim->to = t; - - if (d->enabled) - d->anim->restart(); -} - -/*! - \qmlproperty bool SmoothedFollow::enabled - This property whether this animation should automatically restart when - the 'to' property is upated. - - The default value of this property is 'true'. -*/ -bool QDeclarativeSmoothedFollow::enabled() const -{ - Q_D(const QDeclarativeSmoothedFollow); - return d->enabled; -} - -void QDeclarativeSmoothedFollow::setEnabled(bool e) -{ - Q_D(QDeclarativeSmoothedFollow); - if (d->enabled == e) - return; - d->enabled = e; - - if (d->enabled) - d->anim->restart(); - else - d->anim->stop(); - emit enabledChanged(); -} - -void QDeclarativeSmoothedFollow::setTarget(const QDeclarativeProperty &t) -{ - Q_D(QDeclarativeSmoothedFollow); - d->anim->target = t; -} - -QT_END_NAMESPACE diff --git a/src/declarative/util/qdeclarativesmoothedfollow_p.h b/src/declarative/util/qdeclarativesmoothedfollow_p.h deleted file mode 100644 index f852311..0000000 --- a/src/declarative/util/qdeclarativesmoothedfollow_p.h +++ /dev/null @@ -1,113 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 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$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, 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. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QDECLARATIVESMOOTHEDFOLLOW_H -#define QDECLARATIVESMOOTHEDFOLLOW_H - -#include <qdeclarative.h> -#include <qdeclarativepropertyvaluesource.h> - -#include <QtCore/qobject.h> - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QDeclarativeProperty; -class QDeclarativeSmoothedFollowPrivate; -class Q_AUTOTEST_EXPORT QDeclarativeSmoothedFollow : public QObject, - public QDeclarativePropertyValueSource -{ - Q_OBJECT - Q_DECLARE_PRIVATE(QDeclarativeSmoothedFollow) - Q_INTERFACES(QDeclarativePropertyValueSource) - Q_ENUMS(ReversingMode) - - Q_PROPERTY(qreal to READ to WRITE setTo NOTIFY toChanged) - Q_PROPERTY(qreal velocity READ velocity WRITE setVelocity NOTIFY velocityChanged) - Q_PROPERTY(int duration READ duration WRITE setDuration NOTIFY durationChanged) - Q_PROPERTY(ReversingMode reversingMode READ reversingMode WRITE setReversingMode NOTIFY reversingModeChanged) - Q_PROPERTY(qreal maximumEasingTime READ maximumEasingTime WRITE setMaximumEasingTime NOTIFY maximumEasingTimeChanged) - Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged) - -public: - enum ReversingMode { Eased, Immediate, Sync }; - - QDeclarativeSmoothedFollow(QObject *parent = 0); - ~QDeclarativeSmoothedFollow(); - - qreal to() const; - void setTo(qreal); - - ReversingMode reversingMode() const; - void setReversingMode(ReversingMode); - - int duration() const; - void setDuration(int); - - qreal velocity() const; - void setVelocity(qreal); - - int maximumEasingTime() const; - void setMaximumEasingTime(int); - - bool enabled() const; - void setEnabled(bool); - - virtual void setTarget(const QDeclarativeProperty &); - -Q_SIGNALS: - void velocityChanged(); - void durationChanged(); - void reversingModeChanged(); - void maximumEasingTimeChanged(); - void enabledChanged(); -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QDeclarativeSmoothedFollow) - -QT_END_HEADER - -#endif // QDECLARATIVESMOOTHEDFOLLOW_H diff --git a/src/declarative/util/qdeclarativespringanimation.cpp b/src/declarative/util/qdeclarativespringanimation.cpp index 314b82b..4cf2fc0 100644 --- a/src/declarative/util/qdeclarativespringanimation.cpp +++ b/src/declarative/util/qdeclarativespringanimation.cpp @@ -183,11 +183,13 @@ void QDeclarativeSpringAnimationPrivate::tick(int time) lastTime = time; } + qreal old_to = to; + QDeclarativePropertyPrivate::write(defaultProperty, currentValue, QDeclarativePropertyPrivate::BypassInterceptor | QDeclarativePropertyPrivate::DontRemoveBinding); - if (stop) + if (stop && old_to == to) // do not stop if we got restarted clock.stop(); } @@ -204,6 +206,15 @@ void QDeclarativeSpringAnimationPrivate::updateMode() /*! \qmlclass SpringAnimation QDeclarativeSpringAnimation \since 4.7 + + \brief The SpringAnimation element allows a property to track a value in a spring-like motion + + SpringAnimation mimics the oscillatory behavior of a spring, with the appropriate \l spring constant to + control the acceleration and the \l damping to control how quickly the effect dies away. + + You can also limit the maximum \l velocity of the animation. + + */ QDeclarativeSpringAnimation::QDeclarativeSpringAnimation(QObject *parent) @@ -232,7 +243,7 @@ qreal QDeclarativeSpringAnimation::to() const } /*! - \qmlproperty real SpringFollow::to + \qmlproperty real SpringAnimation::to */ void QDeclarativeSpringAnimation::setTo(qreal value) @@ -254,7 +265,7 @@ qreal QDeclarativeSpringAnimation::from() const } /*! - \qmlproperty real SpringFollow::from + \qmlproperty real SpringAnimation::from */ void QDeclarativeSpringAnimation::setFrom(qreal value) diff --git a/src/declarative/util/qdeclarativespringfollow.cpp b/src/declarative/util/qdeclarativespringfollow.cpp deleted file mode 100644 index aae66ac..0000000 --- a/src/declarative/util/qdeclarativespringfollow.cpp +++ /dev/null @@ -1,464 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 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$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, 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. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "private/qdeclarativespringfollow_p.h" - -#include "private/qdeclarativeanimation_p_p.h" - -#include <QtCore/qdebug.h> - -#include <private/qobject_p.h> - -#include <limits.h> -#include <math.h> - -QT_BEGIN_NAMESPACE - - - -class QDeclarativeSpringFollowPrivate : public QObjectPrivate -{ - Q_DECLARE_PUBLIC(QDeclarativeSpringFollow) -public: - QDeclarativeSpringFollowPrivate() - : currentValue(0), to(0), maxVelocity(0), lastTime(0) - , mass(1.0), spring(0.), damping(0.), velocity(0), epsilon(0.01) - , modulus(0.0), useMass(false), haveModulus(false), enabled(true), mode(Track), clock(this) {} - - QDeclarativeProperty property; - qreal currentValue; - qreal to; - qreal maxVelocity; - qreal velocityms; - int lastTime; - qreal mass; - qreal spring; - qreal damping; - qreal velocity; - qreal epsilon; - qreal modulus; - - bool useMass : 1; - bool haveModulus : 1; - bool enabled : 1; - - enum Mode { - Track, - Velocity, - Spring - }; - Mode mode; - - void tick(int); - void updateMode(); - void start(); - void stop(); - - QTickAnimationProxy<QDeclarativeSpringFollowPrivate, &QDeclarativeSpringFollowPrivate::tick> clock; -}; - -void QDeclarativeSpringFollowPrivate::tick(int time) -{ - Q_Q(QDeclarativeSpringFollow); - - int elapsed = time - lastTime; - if (!elapsed) - return; - qreal srcVal = to; - if (haveModulus) { - currentValue = fmod(currentValue, modulus); - srcVal = fmod(srcVal, modulus); - } - if (mode == Spring) { - if (elapsed < 16) // capped at 62fps. - return; - // Real men solve the spring DEs using RK4. - // We'll do something much simpler which gives a result that looks fine. - int count = elapsed / 16; - for (int i = 0; i < count; ++i) { - qreal diff = srcVal - currentValue; - if (haveModulus && qAbs(diff) > modulus / 2) { - if (diff < 0) - diff += modulus; - else - diff -= modulus; - } - if (useMass) - velocity = velocity + (spring * diff - damping * velocity) / mass; - else - velocity = velocity + spring * diff - damping * velocity; - if (maxVelocity > 0.) { - // limit velocity - if (velocity > maxVelocity) - velocity = maxVelocity; - else if (velocity < -maxVelocity) - velocity = -maxVelocity; - } - currentValue += velocity * 16.0 / 1000.0; - if (haveModulus) { - currentValue = fmod(currentValue, modulus); - if (currentValue < 0.0) - currentValue += modulus; - } - } - if (qAbs(velocity) < epsilon && qAbs(srcVal - currentValue) < epsilon) { - velocity = 0.0; - currentValue = srcVal; - clock.stop(); - } - lastTime = time - (elapsed - count * 16); - } else { - qreal moveBy = elapsed * velocityms; - qreal diff = srcVal - currentValue; - if (haveModulus && qAbs(diff) > modulus / 2) { - if (diff < 0) - diff += modulus; - else - diff -= modulus; - } - if (diff > 0) { - currentValue += moveBy; - if (haveModulus) - currentValue = fmod(currentValue, modulus); - if (currentValue > to) { - currentValue = to; - clock.stop(); - } - } else { - currentValue -= moveBy; - if (haveModulus && currentValue < 0.0) - currentValue = fmod(currentValue, modulus) + modulus; - if (currentValue < to) { - currentValue = to; - clock.stop(); - } - } - lastTime = time; - } - property.write(currentValue); - emit q->valueChanged(currentValue); - if (clock.state() != QAbstractAnimation::Running) - emit q->syncChanged(); -} - -void QDeclarativeSpringFollowPrivate::updateMode() -{ - if (spring == 0. && maxVelocity == 0.) - mode = Track; - else if (spring > 0.) - mode = Spring; - else - mode = Velocity; -} - -void QDeclarativeSpringFollowPrivate::start() -{ - if (!enabled) - return; - - Q_Q(QDeclarativeSpringFollow); - if (mode == QDeclarativeSpringFollowPrivate::Track) { - currentValue = to; - property.write(currentValue); - } else if (to != currentValue && clock.state() != QAbstractAnimation::Running) { - lastTime = 0; - currentValue = property.read().toReal(); - clock.start(); // infinity?? - emit q->syncChanged(); - } -} - -void QDeclarativeSpringFollowPrivate::stop() -{ - clock.stop(); -} - -/*! - \qmlclass SpringFollow QDeclarativeSpringFollow - \since 4.7 - \brief The SpringFollow element allows a property to track a value. - - In example below, \e rect2 will follow \e rect1 moving with a velocity of up to 200: - \code - Rectangle { - id: rect1 - width: 20; height: 20 - color: "#00ff00" - y: 200 // initial value - SequentialAnimation on y { - loops: Animation.Infinite - NumberAnimation { - to: 200 - easing.type: Easing.OutBounce - easing.amplitude: 100 - duration: 2000 - } - PauseAnimation { duration: 1000 } - } - } - Rectangle { - id: rect2 - x: rect1.width - width: 20; height: 20 - color: "#ff0000" - SpringFollow on y { to: rect1.y; velocity: 200 } - } - \endcode -*/ - -QDeclarativeSpringFollow::QDeclarativeSpringFollow(QObject *parent) -: QObject(*(new QDeclarativeSpringFollowPrivate),parent) -{ -} - -QDeclarativeSpringFollow::~QDeclarativeSpringFollow() -{ -} - -void QDeclarativeSpringFollow::setTarget(const QDeclarativeProperty &property) -{ - Q_D(QDeclarativeSpringFollow); - d->property = property; - d->currentValue = property.read().toReal(); -} - -qreal QDeclarativeSpringFollow::to() const -{ - Q_D(const QDeclarativeSpringFollow); - return d->to; -} - -/*! - \qmlproperty real SpringFollow::to - This property holds the target value which will be tracked. - - Bind to a property in order to track its changes. -*/ - -void QDeclarativeSpringFollow::setTo(qreal value) -{ - Q_D(QDeclarativeSpringFollow); - if (d->clock.state() == QAbstractAnimation::Running && d->to == value) - return; - - d->to = value; - d->start(); -} - -/*! - \qmlproperty real SpringFollow::velocity - This property holds the maximum velocity allowed when tracking the source. -*/ - -qreal QDeclarativeSpringFollow::velocity() const -{ - Q_D(const QDeclarativeSpringFollow); - return d->maxVelocity; -} - -void QDeclarativeSpringFollow::setVelocity(qreal velocity) -{ - Q_D(QDeclarativeSpringFollow); - d->maxVelocity = velocity; - d->velocityms = velocity / 1000.0; - d->updateMode(); -} - -/*! - \qmlproperty real SpringFollow::spring - This property holds the spring constant - - The spring constant describes how strongly the target is pulled towards the - source. Setting spring to 0 turns off spring tracking. Useful values 0 - 5.0 - - When a spring constant is set and the velocity property is greater than 0, - velocity limits the maximum speed. -*/ -qreal QDeclarativeSpringFollow::spring() const -{ - Q_D(const QDeclarativeSpringFollow); - return d->spring; -} - -void QDeclarativeSpringFollow::setSpring(qreal spring) -{ - Q_D(QDeclarativeSpringFollow); - d->spring = spring; - d->updateMode(); -} - -/*! - \qmlproperty real SpringFollow::damping - This property holds the spring damping constant - - The damping constant describes how quickly a sprung follower comes to rest. - Useful range is 0 - 1.0 -*/ -qreal QDeclarativeSpringFollow::damping() const -{ - Q_D(const QDeclarativeSpringFollow); - return d->damping; -} - -void QDeclarativeSpringFollow::setDamping(qreal damping) -{ - Q_D(QDeclarativeSpringFollow); - if (damping > 1.) - damping = 1.; - - d->damping = damping; -} - - -/*! - \qmlproperty real SpringFollow::epsilon - This property holds the spring epsilon - - The epsilon is the rate and amount of change in the value which is close enough - to 0 to be considered equal to zero. This will depend on the usage of the value. - For pixel positions, 0.25 would suffice. For scale, 0.005 will suffice. - - The default is 0.01. Tuning this value can provide small performance improvements. -*/ -qreal QDeclarativeSpringFollow::epsilon() const -{ - Q_D(const QDeclarativeSpringFollow); - return d->epsilon; -} - -void QDeclarativeSpringFollow::setEpsilon(qreal epsilon) -{ - Q_D(QDeclarativeSpringFollow); - d->epsilon = epsilon; -} - -/*! - \qmlproperty real SpringFollow::modulus - This property holds the modulus value. - - Setting a \a modulus forces the target value to "wrap around" at the modulus. - For example, setting the modulus to 360 will cause a value of 370 to wrap around to 10. -*/ -qreal QDeclarativeSpringFollow::modulus() const -{ - Q_D(const QDeclarativeSpringFollow); - return d->modulus; -} - -void QDeclarativeSpringFollow::setModulus(qreal modulus) -{ - Q_D(QDeclarativeSpringFollow); - if (d->modulus != modulus) { - d->haveModulus = modulus != 0.0; - d->modulus = modulus; - emit modulusChanged(); - } -} - -/*! - \qmlproperty real SpringFollow::mass - This property holds the "mass" of the property being moved. - - mass is 1.0 by default. Setting a different mass changes the dynamics of - a \l spring follow. -*/ -qreal QDeclarativeSpringFollow::mass() const -{ - Q_D(const QDeclarativeSpringFollow); - return d->mass; -} - -void QDeclarativeSpringFollow::setMass(qreal mass) -{ - Q_D(QDeclarativeSpringFollow); - if (d->mass != mass && mass > 0.0) { - d->useMass = mass != 1.0; - d->mass = mass; - emit massChanged(); - } -} - -/*! - \qmlproperty bool SpringFollow::enabled - This property holds whether the target will track the source. - - The default value of this property is 'true'. -*/ -bool QDeclarativeSpringFollow::enabled() const -{ - Q_D(const QDeclarativeSpringFollow); - return d->enabled; -} - -void QDeclarativeSpringFollow::setEnabled(bool enabled) -{ - Q_D(QDeclarativeSpringFollow); - d->enabled = enabled; - if (enabled) - d->start(); - else - d->stop(); -} - -/*! - \qmlproperty bool SpringFollow::inSync - This property is true when target is equal to the source; otherwise - false. If inSync is true the target is not being animated. - - If \l enabled is false then inSync will also be false. -*/ -bool QDeclarativeSpringFollow::inSync() const -{ - Q_D(const QDeclarativeSpringFollow); - return d->enabled && d->clock.state() != QAbstractAnimation::Running; -} - -/*! - \qmlproperty real SpringFollow::value - The current value. -*/ -qreal QDeclarativeSpringFollow::value() const -{ - Q_D(const QDeclarativeSpringFollow); - return d->currentValue; -} - -QT_END_NAMESPACE diff --git a/src/declarative/util/qdeclarativespringfollow_p.h b/src/declarative/util/qdeclarativespringfollow_p.h deleted file mode 100644 index b6277c3..0000000 --- a/src/declarative/util/qdeclarativespringfollow_p.h +++ /dev/null @@ -1,120 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 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$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, 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. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QDECLARATIVESMOOTHFOLLOW_H -#define QDECLARATIVESMOOTHFOLLOW_H - -#include <qdeclarativepropertyvaluesource.h> -#include <qdeclarative.h> - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QDeclarativeSpringFollowPrivate; -class Q_AUTOTEST_EXPORT QDeclarativeSpringFollow : public QObject, - public QDeclarativePropertyValueSource -{ - Q_OBJECT - Q_DECLARE_PRIVATE(QDeclarativeSpringFollow) - Q_INTERFACES(QDeclarativePropertyValueSource) - - Q_PROPERTY(qreal to READ to WRITE setTo) - Q_PROPERTY(qreal velocity READ velocity WRITE setVelocity) - Q_PROPERTY(qreal spring READ spring WRITE setSpring) - Q_PROPERTY(qreal damping READ damping WRITE setDamping) - Q_PROPERTY(qreal epsilon READ epsilon WRITE setEpsilon) - Q_PROPERTY(bool enabled READ enabled WRITE setEnabled) - Q_PROPERTY(qreal value READ value NOTIFY valueChanged) - Q_PROPERTY(qreal modulus READ modulus WRITE setModulus NOTIFY modulusChanged) - Q_PROPERTY(qreal mass READ mass WRITE setMass NOTIFY massChanged) - Q_PROPERTY(bool inSync READ inSync NOTIFY syncChanged) - -public: - QDeclarativeSpringFollow(QObject *parent=0); - ~QDeclarativeSpringFollow(); - - virtual void setTarget(const QDeclarativeProperty &); - - qreal to() const; - void setTo(qreal value); - - qreal velocity() const; - void setVelocity(qreal velocity); - - qreal spring() const; - void setSpring(qreal spring); - - qreal damping() const; - void setDamping(qreal damping); - - qreal epsilon() const; - void setEpsilon(qreal epsilon); - - qreal mass() const; - void setMass(qreal modulus); - - qreal modulus() const; - void setModulus(qreal modulus); - - bool enabled() const; - void setEnabled(bool enabled); - - bool inSync() const; - - qreal value() const; - -Q_SIGNALS: - void valueChanged(qreal); - void modulusChanged(); - void massChanged(); - void syncChanged(); -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QDeclarativeSpringFollow) - -QT_END_HEADER - -#endif // QDECLARATIVESMOOTHFOLLOW_H diff --git a/src/declarative/util/qdeclarativeutilmodule.cpp b/src/declarative/util/qdeclarativeutilmodule.cpp index 74fdac6..c5bfebd 100644 --- a/src/declarative/util/qdeclarativeutilmodule.cpp +++ b/src/declarative/util/qdeclarativeutilmodule.cpp @@ -46,7 +46,6 @@ #include "private/qdeclarativebind_p.h" #include "private/qdeclarativeconnections_p.h" #include "private/qdeclarativesmoothedanimation_p.h" -#include "private/qdeclarativesmoothedfollow_p.h" #include "private/qdeclarativefontloader_p.h" #include "private/qdeclarativelistaccessor_p.h" #include "private/qdeclarativelistmodel_p.h" @@ -56,7 +55,6 @@ #include "private/qdeclarativepixmapcache_p.h" #include "private/qdeclarativepropertychanges_p.h" #include "qdeclarativepropertymap.h" -#include "private/qdeclarativespringfollow_p.h" #include "private/qdeclarativespringanimation_p.h" #include "private/qdeclarativestategroup_p.h" #include "private/qdeclarativestateoperations_p.h" @@ -84,7 +82,6 @@ void QDeclarativeUtilModule::defineModule() qmlRegisterType<QDeclarativeColorAnimation>("Qt",4,7,"ColorAnimation"); qmlRegisterType<QDeclarativeConnections>("Qt",4,7,"Connections"); qmlRegisterType<QDeclarativeSmoothedAnimation>("Qt",4,7,"SmoothedAnimation"); - qmlRegisterType<QDeclarativeSmoothedFollow>("Qt",4,7,"SmoothedFollow"); qmlRegisterType<QDeclarativeFontLoader>("Qt",4,7,"FontLoader"); qmlRegisterType<QDeclarativeListElement>("Qt",4,7,"ListElement"); qmlRegisterType<QDeclarativeNumberAnimation>("Qt",4,7,"NumberAnimation"); @@ -98,7 +95,6 @@ void QDeclarativeUtilModule::defineModule() qmlRegisterType<QDeclarativeRotationAnimation>("Qt",4,7,"RotationAnimation"); qmlRegisterType<QDeclarativeScriptAction>("Qt",4,7,"ScriptAction"); qmlRegisterType<QDeclarativeSequentialAnimation>("Qt",4,7,"SequentialAnimation"); - qmlRegisterType<QDeclarativeSpringFollow>("Qt",4,7,"SpringFollow"); qmlRegisterType<QDeclarativeSpringAnimation>("Qt",4,7,"SpringAnimation"); qmlRegisterType<QDeclarativeStateChangeScript>("Qt",4,7,"StateChangeScript"); qmlRegisterType<QDeclarativeStateGroup>("Qt",4,7,"StateGroup"); diff --git a/src/declarative/util/util.pri b/src/declarative/util/util.pri index 0cbcbd7..fd57144 100644 --- a/src/declarative/util/util.pri +++ b/src/declarative/util/util.pri @@ -7,10 +7,8 @@ SOURCES += \ $$PWD/qdeclarativepackage.cpp \ $$PWD/qdeclarativeanimation.cpp \ $$PWD/qdeclarativesystempalette.cpp \ - $$PWD/qdeclarativespringfollow.cpp \ $$PWD/qdeclarativespringanimation.cpp \ $$PWD/qdeclarativesmoothedanimation.cpp \ - $$PWD/qdeclarativesmoothedfollow.cpp \ $$PWD/qdeclarativestate.cpp\ $$PWD/qdeclarativetransitionmanager.cpp \ $$PWD/qdeclarativestateoperations.cpp \ @@ -39,10 +37,8 @@ HEADERS += \ $$PWD/qdeclarativeanimation_p.h \ $$PWD/qdeclarativeanimation_p_p.h \ $$PWD/qdeclarativesystempalette_p.h \ - $$PWD/qdeclarativespringfollow_p.h \ $$PWD/qdeclarativespringanimation_p.h \ $$PWD/qdeclarativesmoothedanimation_p.h \ - $$PWD/qdeclarativesmoothedfollow_p.h \ $$PWD/qdeclarativesmoothedanimation_p_p.h \ $$PWD/qdeclarativestate_p.h\ $$PWD/qdeclarativestateoperations_p.h \ |