From 2c0255521f00a1fd95988161a03c39631350eaba Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Thu, 10 Sep 2009 13:21:36 +1000 Subject: Follow renamed to SpringFollow. --- demos/declarative/samegame/content/BoomBlock.qml | 4 +- demos/declarative/webbrowser/webbrowser.qml | 1 + .../declarative/aspectratio/face_fit_animated.qml | 2 +- examples/declarative/clock/Clock.qml | 6 +- examples/declarative/dial/DialLibrary/Dial.qml | 4 +- examples/declarative/follow/follow.qml | 10 +- examples/declarative/follow/pong.qml | 6 +- examples/declarative/listview/highlight.qml | 2 +- examples/declarative/snow/snow.qml | 6 +- examples/declarative/velocity/Day.qml | 2 +- src/declarative/QmlChanges.txt | 1 + src/declarative/fx/qfxgridview.cpp | 16 +- src/declarative/fx/qfxlistview.cpp | 52 ++- src/declarative/fx/qfxlistview.h | 1 + src/declarative/util/qmleasefollow.cpp | 28 +- src/declarative/util/qmleasefollow.h | 4 + src/declarative/util/qmlfollow.cpp | 456 --------------------- src/declarative/util/qmlfollow.h | 113 ----- src/declarative/util/qmlspringfollow.cpp | 456 +++++++++++++++++++++ src/declarative/util/qmlspringfollow.h | 113 +++++ src/declarative/util/util.pri | 4 +- 21 files changed, 676 insertions(+), 611 deletions(-) delete mode 100644 src/declarative/util/qmlfollow.cpp delete mode 100644 src/declarative/util/qmlfollow.h create mode 100644 src/declarative/util/qmlspringfollow.cpp create mode 100644 src/declarative/util/qmlspringfollow.h diff --git a/demos/declarative/samegame/content/BoomBlock.qml b/demos/declarative/samegame/content/BoomBlock.qml index 7860cf4..a495cd0 100644 --- a/demos/declarative/samegame/content/BoomBlock.qml +++ b/demos/declarative/samegame/content/BoomBlock.qml @@ -7,8 +7,8 @@ Item { id:block property int targetX: 0 property int targetY: 0 - x: Follow { enabled: spawned; source: targetX; spring: 2; damping: 0.2 } - y: Follow { source: targetY; spring: 2; damping: 0.2 } + x: SpringFollow { enabled: spawned; source: targetX; spring: 2; damping: 0.2 } + y: SpringFollow { source: targetY; spring: 2; damping: 0.2 } Image { id: img source: { diff --git a/demos/declarative/webbrowser/webbrowser.qml b/demos/declarative/webbrowser/webbrowser.qml index 9a8af29..ae3d048 100644 --- a/demos/declarative/webbrowser/webbrowser.qml +++ b/demos/declarative/webbrowser/webbrowser.qml @@ -167,6 +167,7 @@ Item { anchors.bottom: Footer.top anchors.left: parent.left anchors.right: parent.right + pressDelay: 200 WebView { id: MyWebView diff --git a/examples/declarative/aspectratio/face_fit_animated.qml b/examples/declarative/aspectratio/face_fit_animated.qml index 2768150..7db1c80 100644 --- a/examples/declarative/aspectratio/face_fit_animated.qml +++ b/examples/declarative/aspectratio/face_fit_animated.qml @@ -16,7 +16,7 @@ Rectangle { source: "pics/face.png" x: (parent.width-width*scale)/2 y: (parent.height-height*scale)/2 - scale: Follow { + scale: SpringFollow { source: Math.max(Math.min(Image.parent.width/Image.width*1.333,Image.parent.height/Image.height), Math.min(Image.parent.width/Image.width,Image.parent.height/Image.height*1.333)) spring: 1 diff --git a/examples/declarative/clock/Clock.qml b/examples/declarative/clock/Clock.qml index e152be3..6064dd4 100644 --- a/examples/declarative/clock/Clock.qml +++ b/examples/declarative/clock/Clock.qml @@ -28,7 +28,7 @@ Item { id: HourRotation origin.x: 4; origin.y: 45 angle: 0 - angle: Follow { + angle: SpringFollow { spring: 2 damping: .2 source: Clock.hours * 50 * 3 + Clock.minutes / 2 @@ -44,7 +44,7 @@ Item { id: MinuteRotation origin.x: 4; origin.y: 70 angle: 0 - angle: Follow { + angle: SpringFollow { spring: 2 damping: .2 source: Clock.minutes * 6 @@ -60,7 +60,7 @@ Item { id: SecondRotation origin.x: 2; origin.y: 60 angle: 0 - angle: Follow { + angle: SpringFollow { spring: 5 damping: .25 modulus: 360 diff --git a/examples/declarative/dial/DialLibrary/Dial.qml b/examples/declarative/dial/DialLibrary/Dial.qml index f53b25e..1a163a8 100644 --- a/examples/declarative/dial/DialLibrary/Dial.qml +++ b/examples/declarative/dial/DialLibrary/Dial.qml @@ -26,8 +26,8 @@ Item { id: NeedleRotation origin.x: 7; origin.y: 65 angle: -130 - angle: Follow { -id: MyFollow + angle: SpringFollow { + id: MyFollow spring: 1.4 damping: .15 source: Math.min(Math.max(-130, Root.value*2.2 - 130), 133) diff --git a/examples/declarative/follow/follow.qml b/examples/declarative/follow/follow.qml index 37dc2e8..1f585e2 100644 --- a/examples/declarative/follow/follow.qml +++ b/examples/declarative/follow/follow.qml @@ -26,7 +26,7 @@ Rectangle { color: "#ff0000" x: Rect.width; width: Rect.width; height: 20 y: 200 - y: Follow { source: Rect.y; velocity: 200 } + y: SpringFollow { source: Rect.y; velocity: 200 } } Text { x: Rect.width; y: 220; text: "Velocity" } @@ -35,13 +35,13 @@ Rectangle { color: "#ff0000" x: Rect.width * 2; width: Rect.width/2; height: 20 y: 200 - y: Follow { source: Rect.y; spring: 1.0; damping: 0.2 } + y: SpringFollow { source: Rect.y; spring: 1.0; damping: 0.2 } } Rectangle { color: "#880000" x: Rect.width * 2.5; width: Rect.width/2; height: 20 y: 200 - y: Follow { source: Rect.y; spring: 1.0; damping: 0.2; mass: 3.0 } // "heavier" object + y: SpringFollow { source: Rect.y; spring: 1.0; damping: 0.2; mass: 3.0 } // "heavier" object } Text { x: Rect.width * 2; y: 220; text: "Spring" } @@ -54,8 +54,8 @@ Rectangle { width: 20; height: 20 radius: 10 color: "#0000ff" - x: Follow { id: "F1"; source: Mouse.mouseX-10; spring: 1.0; damping: 0.05; epsilon: 0.25 } - y: Follow { id: "F2"; source: Mouse.mouseY-10; spring: 1.0; damping: 0.05; epsilon: 0.25 } + x: SpringFollow { id: "F1"; source: Mouse.mouseX-10; spring: 1.0; damping: 0.05; epsilon: 0.25 } + y: SpringFollow { id: "F2"; source: Mouse.mouseY-10; spring: 1.0; damping: 0.05; epsilon: 0.25 } states: [ State { name: "following" diff --git a/examples/declarative/follow/pong.qml b/examples/declarative/follow/pong.qml index 0314bb8..b51c0d0 100644 --- a/examples/declarative/follow/pong.qml +++ b/examples/declarative/follow/pong.qml @@ -25,7 +25,7 @@ Rectangle { } // Make y follow the target y coordinate, with a velocity of 200 - y: Follow { source: Ball.targetY; velocity: 200 } + y: SpringFollow { source: Ball.targetY; velocity: 200 } // Detect the ball hitting the top or bottom of the view and bounce it onYChanged: { @@ -42,7 +42,7 @@ Rectangle { id: LeftBat color: "#00ee00" x: 2; width: 20; height: 90 - y: Follow { + y: SpringFollow { source: Ball.y-45; velocity: 300 enabled: Ball.direction == 'left' } @@ -51,7 +51,7 @@ Rectangle { id: RightBat color: "#00ee00" x: Page.width-22; width: 20; height: 90 - y: Follow { + y: SpringFollow { source: Ball.y-45; velocity: 300 enabled: Ball.direction == 'right' } diff --git a/examples/declarative/listview/highlight.qml b/examples/declarative/listview/highlight.qml index 2bf3a9f..e707ac0 100644 --- a/examples/declarative/listview/highlight.qml +++ b/examples/declarative/listview/highlight.qml @@ -44,7 +44,7 @@ Rectangle { id: PetHighlight Rectangle { width: 200; height: 50; color: "#FFFF88" - y: Follow { source: List1.current.y; spring: 3; damping: 0.1 } + y: SpringFollow { source: List1.current.y; spring: 3; damping: 0.1 } } } ListView { diff --git a/examples/declarative/snow/snow.qml b/examples/declarative/snow/snow.qml index b6781c3..2241c3f 100644 --- a/examples/declarative/snow/snow.qml +++ b/examples/declarative/snow/snow.qml @@ -30,15 +30,15 @@ Rectangle { property bool slowDeform: true property real deform: 0 - deform: Follow { + deform: SpringFollow { id: "DeformFollow"; source: MyLayout.targetDeform; velocity: MyLayout.slowDeform?0.1:2 onSyncChanged: if(inSync) { MyLayout.slowDeform = true; MyLayout.targetDeform = 0; } } ImageBatch { offset: 0; ref: ImagePanel } - x: Follow { source: MyLayout.targetX; velocity: 1000 } - y: Follow { source: -(selectedY + imageHeight / 2); velocity: 500 } + x: SpringFollow { source: MyLayout.targetX; velocity: 1000 } + y: SpringFollow { source: -(selectedY + imageHeight / 2); velocity: 500 } } transform: Rotation { diff --git a/examples/declarative/velocity/Day.qml b/examples/declarative/velocity/Day.qml index 06d0bd4..4001a3e 100644 --- a/examples/declarative/velocity/Day.qml +++ b/examples/declarative/velocity/Day.qml @@ -31,7 +31,7 @@ Rectangle { x: Math.random() * 200 + 100 y: Math.random() * 300 + 50 id: StickyPage - rotation: Follow { + rotation: SpringFollow { source: -Flick.horizontalVelocity / 100 spring: 2.0 damping: 0.1 diff --git a/src/declarative/QmlChanges.txt b/src/declarative/QmlChanges.txt index 87873f2..9043421 100644 --- a/src/declarative/QmlChanges.txt +++ b/src/declarative/QmlChanges.txt @@ -29,6 +29,7 @@ SetPropertyAction -> PropertyAction RunScriptAction -> ScriptAction ParentChangeAction -> ParentAction VisualModel -> VisualDataModel +Follow -> SpringFollow Renamed properties: Item: contents -> childrenRect diff --git a/src/declarative/fx/qfxgridview.cpp b/src/declarative/fx/qfxgridview.cpp index cccd7a6..dfb04ad 100644 --- a/src/declarative/fx/qfxgridview.cpp +++ b/src/declarative/fx/qfxgridview.cpp @@ -41,7 +41,7 @@ #include "qfxvisualitemmodel.h" #include "qlistmodelinterface.h" -#include "qmlfollow.h" +#include "qmleasefollow.h" #include "private/qfxflickable_p.h" #include "qfxgridview.h" @@ -313,8 +313,8 @@ public: enum MovementReason { Other, Key, Mouse }; MovementReason moveReason; int buffer; - QmlFollow *highlightXAnimator; - QmlFollow *highlightYAnimator; + QmlEaseFollow *highlightXAnimator; + QmlEaseFollow *highlightYAnimator; int ownModel : 1; int wrap : 1; @@ -591,15 +591,13 @@ void QFxGridViewPrivate::createHighlight() if (item) { item->setParent(q->viewport()); highlight = new FxGridItem(item, q); - highlightXAnimator = new QmlFollow(q); + highlightXAnimator = new QmlEaseFollow(q); highlightXAnimator->setTarget(QmlMetaProperty(highlight->item, QLatin1String("x"))); - highlightXAnimator->setSpring(3); - highlightXAnimator->setDamping(0.3); + highlightXAnimator->setVelocity(400); highlightXAnimator->setEnabled(autoHighlight); - highlightYAnimator = new QmlFollow(q); + highlightYAnimator = new QmlEaseFollow(q); highlightYAnimator->setTarget(QmlMetaProperty(highlight->item, QLatin1String("y"))); - highlightYAnimator->setSpring(3); - highlightYAnimator->setDamping(0.3); + highlightYAnimator->setVelocity(400); highlightYAnimator->setEnabled(autoHighlight); } else { delete highlightContext; diff --git a/src/declarative/fx/qfxlistview.cpp b/src/declarative/fx/qfxlistview.cpp index 6c0a83e..49de016 100644 --- a/src/declarative/fx/qfxlistview.cpp +++ b/src/declarative/fx/qfxlistview.cpp @@ -40,7 +40,7 @@ ****************************************************************************/ #include "private/qfxflickable_p.h" -#include "qmlfollow.h" +#include "qmleasefollow.h" #include "qlistmodelinterface.h" #include "qfxvisualitemmodel.h" #include "qfxlistview.h" @@ -381,8 +381,8 @@ public: enum MovementReason { Other, Key, Mouse }; MovementReason moveReason; int buffer; - QmlFollow *highlightPosAnimator; - QmlFollow *highlightSizeAnimator; + QmlEaseFollow *highlightPosAnimator; + QmlEaseFollow *highlightSizeAnimator; QString sectionExpression; QString currentSection; int spacing; @@ -660,15 +660,18 @@ void QFxListViewPrivate::createHighlight() } if (item) { highlight = new FxListItem(item, q); + if (orient == Qt::Vertical) + highlight->item->setHeight(currentItem->item->height()); + else + highlight->item->setWidth(currentItem->item->width()); const QLatin1String posProp(orient == Qt::Vertical ? "y" : "x"); - highlightPosAnimator = new QmlFollow(q); + highlightPosAnimator = new QmlEaseFollow(q); highlightPosAnimator->setTarget(QmlMetaProperty(highlight->item, posProp)); - highlightPosAnimator->setEpsilon(0.25); - highlightPosAnimator->setSpring(2.5); - highlightPosAnimator->setDamping(0.35); + highlightPosAnimator->setVelocity(400); highlightPosAnimator->setEnabled(autoHighlight); const QLatin1String sizeProp(orient == Qt::Vertical ? "height" : "width"); - highlightSizeAnimator = new QmlFollow(q); + highlightSizeAnimator = new QmlEaseFollow(q); + highlightSizeAnimator->setVelocity(400); highlightSizeAnimator->setTarget(QmlMetaProperty(highlight->item, sizeProp)); highlightSizeAnimator->setEnabled(autoHighlight); } @@ -909,6 +912,7 @@ void QFxListView::setModel(const QVariant &model) if (d->model) { disconnect(d->model, SIGNAL(itemsInserted(int,int)), this, SLOT(itemsInserted(int,int))); disconnect(d->model, SIGNAL(itemsRemoved(int,int)), this, SLOT(itemsRemoved(int,int))); + disconnect(d->model, SIGNAL(itemsMoved(int,int,int)), this, SLOT(itemsMoved(int,int,int))); disconnect(d->model, SIGNAL(createdItem(int, QFxItem*)), this, SLOT(createdItem(int,QFxItem*))); disconnect(d->model, SIGNAL(destroyingItem(QFxItem*)), this, SLOT(destroyingItem(QFxItem*))); } @@ -937,6 +941,7 @@ void QFxListView::setModel(const QVariant &model) d->updateCurrent(d->currentIndex); connect(d->model, SIGNAL(itemsInserted(int,int)), this, SLOT(itemsInserted(int,int))); connect(d->model, SIGNAL(itemsRemoved(int,int)), this, SLOT(itemsRemoved(int,int))); + connect(d->model, SIGNAL(itemsMoved(int,int,int)), this, SLOT(itemsMoved(int,int,int))); connect(d->model, SIGNAL(createdItem(int, QFxItem*)), this, SLOT(createdItem(int,QFxItem*))); connect(d->model, SIGNAL(destroyingItem(QFxItem*)), this, SLOT(destroyingItem(QFxItem*))); refill(); @@ -1635,6 +1640,37 @@ void QFxListView::destroyRemoved() d->layout(); } +void QFxListView::itemsMoved(int from, int to, int count) +{ + qWarning() << "ListView does not support moving in models"; + + Q_D(QFxListView); + int fromCount = count; + int toCount = count; + bool fromVisible = d->mapRangeFromModel(from, fromCount); + bool toVisible = d->mapRangeFromModel(to, toCount); + + if (!fromVisible && !toVisible) { + // The items are outside the visible range. + if (d->visibleItems.count()) + d->visibleIndex = -1; + for (int i = 0; i < d->visibleItems.count(); ++i) { + FxListItem *listItem = d->visibleItems.at(i); + if (listItem->index != -1) { + listItem->index = d->model->indexOf(listItem->item, this); + if (d->visibleIndex < 0) + d->visibleIndex = listItem->index; + } + } + if (d->currentItem) { + d->currentItem->index = d->model->indexOf(d->currentItem->item, this); + d->currentIndex = d->currentItem->index; + } + return; + } + +} + void QFxListView::createdItem(int index, QFxItem *item) { Q_D(QFxListView); diff --git a/src/declarative/fx/qfxlistview.h b/src/declarative/fx/qfxlistview.h index dc0b039..829e202 100644 --- a/src/declarative/fx/qfxlistview.h +++ b/src/declarative/fx/qfxlistview.h @@ -155,6 +155,7 @@ private Q_SLOTS: void itemResized(); void itemsInserted(int index, int count); void itemsRemoved(int index, int count); + void itemsMoved(int from, int to, int count); void destroyRemoved(); void createdItem(int index, QFxItem *item); void destroyingItem(QFxItem *item); diff --git a/src/declarative/util/qmleasefollow.cpp b/src/declarative/util/qmleasefollow.cpp index 83dbde7..b58ad14 100644 --- a/src/declarative/util/qmleasefollow.cpp +++ b/src/declarative/util/qmleasefollow.cpp @@ -56,7 +56,7 @@ public: QmlEaseFollowPrivate() : source(0), velocity(200), duration(-1), reversingMode(QmlEaseFollow::Eased), initialVelocity(0), - initialValue(0), invert(false), trackVelocity(0), clockOffset(0), + initialValue(0), invert(false), enabled(true), trackVelocity(0), clockOffset(0), lastTick(0), clock(this) {} @@ -68,6 +68,7 @@ public: qreal initialVelocity; qreal initialValue; bool invert; + bool enabled; qreal trackVelocity; @@ -267,7 +268,7 @@ qreal QmlEaseFollow::sourceValue() const /*! \qmlproperty enumeration EaseFollow::reversingMode - Sets how the EaseFollow behaves if an animation diration is reversed. + Sets how the EaseFollow behaves if an animation direction is reversed. If reversing mode is \c Eased, the animation will smoothly decelerate, and then reverse direction. If the reversing mode is \c Immediate, the @@ -289,6 +290,9 @@ void QmlEaseFollow::setReversingMode(ReversingMode m) void QmlEaseFollowPrivate::restart() { + if (!enabled) + return; + initialValue = target.read().toReal(); if (source == initialValue) { @@ -382,6 +386,26 @@ void QmlEaseFollow::setVelocity(qreal v) d->restart(); } +/*! + \qmlproperty bool EaseFollow::enabled + This property holds whether the target will track the source. +*/ +bool QmlEaseFollow::enabled() const +{ + Q_D(const QmlEaseFollow); + return d->enabled; +} + +void QmlEaseFollow::setEnabled(bool enabled) +{ + Q_D(QmlEaseFollow); + d->enabled = enabled; + if (enabled) + d->restart(); + else + d->clockStop(); +} + void QmlEaseFollow::setTarget(const QmlMetaProperty &t) { Q_D(QmlEaseFollow); diff --git a/src/declarative/util/qmleasefollow.h b/src/declarative/util/qmleasefollow.h index adcb647..8e8c59d 100644 --- a/src/declarative/util/qmleasefollow.h +++ b/src/declarative/util/qmleasefollow.h @@ -66,6 +66,7 @@ class Q_DECLARATIVE_EXPORT QmlEaseFollow : public QObject, Q_PROPERTY(qreal velocity READ velocity WRITE setVelocity) Q_PROPERTY(qreal duration READ duration WRITE setDuration) Q_PROPERTY(ReversingMode reversingMode READ reversingMode WRITE setReversingMode) + Q_PROPERTY(bool enabled READ enabled WRITE setEnabled) public: enum ReversingMode { Eased, Immediate, Sync }; @@ -85,6 +86,9 @@ public: qreal duration() const; void setDuration(qreal); + bool enabled() const; + void setEnabled(bool enabled); + virtual void setTarget(const QmlMetaProperty &); }; diff --git a/src/declarative/util/qmlfollow.cpp b/src/declarative/util/qmlfollow.cpp deleted file mode 100644 index fe5303f..0000000 --- a/src/declarative/util/qmlfollow.cpp +++ /dev/null @@ -1,456 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (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 either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** 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.0, 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. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include -#include -#include -#include "private/qobject_p.h" -#include "qmlfollow.h" -#include "private/qmlanimation_p.h" - -QT_BEGIN_NAMESPACE - -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Follow,QmlFollow) - -class QmlFollowPrivate : public QObjectPrivate -{ - Q_DECLARE_PUBLIC(QmlFollow) -public: - QmlFollowPrivate() - : sourceValue(0), maxVelocity(0), lastTime(0) - , mass(1.0), useMass(false), spring(0.), damping(0.), velocity(0), epsilon(0.01) - , modulus(0.0), haveModulus(false), enabled(true), mode(Track), clock(this) {} - - QmlMetaProperty property; - qreal currentValue; - qreal sourceValue; - qreal maxVelocity; - qreal velocityms; - int lastTime; - qreal mass; - bool useMass; - qreal spring; - qreal damping; - qreal velocity; - qreal epsilon; - qreal modulus; - bool haveModulus; - bool enabled; - - enum Mode { - Track, - Velocity, - Spring - }; - Mode mode; - - void tick(int); - void updateMode(); - void start(); - void stop(); - - QTickAnimationProxy clock; -}; - -void QmlFollowPrivate::tick(int time) -{ - Q_Q(QmlFollow); - - int elapsed = time - lastTime; - if (!elapsed) - return; - qreal srcVal = sourceValue; - 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 > sourceValue) { - currentValue = sourceValue; - clock.stop(); - } - } else { - currentValue -= moveBy; - if (haveModulus && currentValue < 0.0) - currentValue = fmod(currentValue, modulus) + modulus; - if (currentValue < sourceValue) { - currentValue = sourceValue; - clock.stop(); - } - } - lastTime = time; - } - property.write(currentValue); - emit q->valueChanged(currentValue); - if (clock.state() != QAbstractAnimation::Running) - emit q->syncChanged(); -} - -void QmlFollowPrivate::updateMode() -{ - if (spring == 0. && maxVelocity == 0.) - mode = Track; - else if (spring > 0.) - mode = Spring; - else - mode = Velocity; -} - -void QmlFollowPrivate::start() -{ - if (!enabled) - return; - - Q_Q(QmlFollow); - if (mode == QmlFollowPrivate::Track) { - currentValue = sourceValue; - property.write(currentValue); - } else if (sourceValue != currentValue && clock.state() != QAbstractAnimation::Running) { - lastTime = 0; - currentValue = property.read().toDouble(); - clock.start(); // infinity?? - emit q->syncChanged(); - } -} - -void QmlFollowPrivate::stop() -{ - clock.stop(); -} - -/*! - \qmlclass Follow QmlFollow - \brief The Follow element allows a property to track a value. - - In example below, Rect2 will follow Rect1 moving with a velocity of up to 200: - \code - Rectangle { - id: Rect1 - width: 20; height: 20 - color: "#00ff00" - y: 200 //initial value - y: SequentialAnimation { - running: true - repeat: true - NumberAnimation { - to: 200 - easing: "easeOutBounce(amplitude:100)" - duration: 2000 - } - PauseAnimation { duration: 1000 } - } - } - Rectangle { - id: Rect2 - x: Rect1.width - width: 20; height: 20 - color: "#ff0000" - y: Follow { source: Rect1.y; velocity: 200 } - } - \endcode -*/ - -QmlFollow::QmlFollow(QObject *parent) -: QObject(*(new QmlFollowPrivate),parent) -{ -} - -QmlFollow::~QmlFollow() -{ -} - -void QmlFollow::setTarget(const QmlMetaProperty &property) -{ - Q_D(QmlFollow); - d->property = property; - d->currentValue = property.read().toDouble(); -} - -qreal QmlFollow::sourceValue() const -{ - Q_D(const QmlFollow); - return d->sourceValue; -} - -/*! - \qmlproperty qreal Follow::source - This property holds the source value which will be tracked. - - Bind to a property in order to track its changes. -*/ - -void QmlFollow::setSourceValue(qreal value) -{ - Q_D(QmlFollow); - if (d->sourceValue != value) { - d->sourceValue = value; - d->start(); - } -} - -/*! - \qmlproperty qreal Follow::velocity - This property holds the maximum velocity allowed when tracking the source. -*/ - -qreal QmlFollow::velocity() const -{ - Q_D(const QmlFollow); - return d->maxVelocity; -} - -void QmlFollow::setVelocity(qreal velocity) -{ - Q_D(QmlFollow); - d->maxVelocity = velocity; - d->velocityms = velocity / 1000.0; - d->updateMode(); -} - -/*! - \qmlproperty qreal Follow::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 QmlFollow::spring() const -{ - Q_D(const QmlFollow); - return d->spring; -} - -void QmlFollow::setSpring(qreal spring) -{ - Q_D(QmlFollow); - d->spring = spring; - d->updateMode(); -} - -/*! - \qmlproperty qreal Follow::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 QmlFollow::damping() const -{ - Q_D(const QmlFollow); - return d->damping; -} - -void QmlFollow::setDamping(qreal damping) -{ - Q_D(QmlFollow); - if (damping > 1.) - damping = 1.; - - d->damping = damping; -} - - -/*! - \qmlproperty qreal Follow::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 QmlFollow::epsilon() const -{ - Q_D(const QmlFollow); - return d->epsilon; -} - -void QmlFollow::setEpsilon(qreal epsilon) -{ - Q_D(QmlFollow); - d->epsilon = epsilon; -} - -/*! - \qmlproperty qreal Follow::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 QmlFollow::modulus() const -{ - Q_D(const QmlFollow); - return d->modulus; -} - -void QmlFollow::setModulus(qreal modulus) -{ - Q_D(QmlFollow); - if (d->modulus != modulus) { - d->haveModulus = modulus != 0.0; - d->modulus = modulus; - emit modulusChanged(); - } -} - -/*! - \qmlproperty qreal Follow::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 QmlFollow::mass() const -{ - Q_D(const QmlFollow); - return d->mass; -} - -void QmlFollow::setMass(qreal mass) -{ - Q_D(QmlFollow); - if (d->mass != mass && mass > 0.0) { - d->useMass = mass != 1.0; - d->mass = mass; - emit massChanged(); - } -} - -/*! - \qmlproperty qreal Follow::value - The current value. -*/ - -/*! - \qmlproperty bool Follow::enabled - This property holds whether the target will track the source. -*/ -bool QmlFollow::enabled() const -{ - Q_D(const QmlFollow); - return d->enabled; -} - -void QmlFollow::setEnabled(bool enabled) -{ - Q_D(QmlFollow); - d->enabled = enabled; - if (enabled) - d->start(); - else - d->stop(); -} - -/*! - \qmlproperty bool Follow::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 QmlFollow::inSync() const -{ - Q_D(const QmlFollow); - return d->enabled && d->clock.state() != QAbstractAnimation::Running; -} - -qreal QmlFollow::value() const -{ - Q_D(const QmlFollow); - return d->currentValue; -} - -QT_END_NAMESPACE diff --git a/src/declarative/util/qmlfollow.h b/src/declarative/util/qmlfollow.h deleted file mode 100644 index ff34d08..0000000 --- a/src/declarative/util/qmlfollow.h +++ /dev/null @@ -1,113 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (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 either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** 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.0, 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. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QMLFOLLOW_H -#define QMLFOLLOW_H - -#include -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QmlFollowPrivate; -class Q_DECLARATIVE_EXPORT QmlFollow : public QObject, - public QmlPropertyValueSource -{ - Q_OBJECT - Q_DECLARE_PRIVATE(QmlFollow) - Q_INTERFACES(QmlPropertyValueSource) - - Q_PROPERTY(qreal source READ sourceValue WRITE setSourceValue) - 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(qreal modulus READ modulus WRITE setModulus) - 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: - QmlFollow(QObject *parent=0); - ~QmlFollow(); - - virtual void setTarget(const QmlMetaProperty &); - - qreal sourceValue() const; - void setSourceValue(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(QmlFollow) - -QT_END_HEADER - -#endif // QFXFOLLOW_H diff --git a/src/declarative/util/qmlspringfollow.cpp b/src/declarative/util/qmlspringfollow.cpp new file mode 100644 index 0000000..8c902aa --- /dev/null +++ b/src/declarative/util/qmlspringfollow.cpp @@ -0,0 +1,456 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, 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. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include +#include "private/qobject_p.h" +#include "qmlspringfollow.h" +#include "private/qmlanimation_p.h" + +QT_BEGIN_NAMESPACE + +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,SpringFollow,QmlSpringFollow) + +class QmlSpringFollowPrivate : public QObjectPrivate +{ + Q_DECLARE_PUBLIC(QmlSpringFollow) +public: + QmlSpringFollowPrivate() + : sourceValue(0), maxVelocity(0), lastTime(0) + , mass(1.0), useMass(false), spring(0.), damping(0.), velocity(0), epsilon(0.01) + , modulus(0.0), haveModulus(false), enabled(true), mode(Track), clock(this) {} + + QmlMetaProperty property; + qreal currentValue; + qreal sourceValue; + qreal maxVelocity; + qreal velocityms; + int lastTime; + qreal mass; + bool useMass; + qreal spring; + qreal damping; + qreal velocity; + qreal epsilon; + qreal modulus; + bool haveModulus; + bool enabled; + + enum Mode { + Track, + Velocity, + Spring + }; + Mode mode; + + void tick(int); + void updateMode(); + void start(); + void stop(); + + QTickAnimationProxy clock; +}; + +void QmlSpringFollowPrivate::tick(int time) +{ + Q_Q(QmlSpringFollow); + + int elapsed = time - lastTime; + if (!elapsed) + return; + qreal srcVal = sourceValue; + 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 > sourceValue) { + currentValue = sourceValue; + clock.stop(); + } + } else { + currentValue -= moveBy; + if (haveModulus && currentValue < 0.0) + currentValue = fmod(currentValue, modulus) + modulus; + if (currentValue < sourceValue) { + currentValue = sourceValue; + clock.stop(); + } + } + lastTime = time; + } + property.write(currentValue); + emit q->valueChanged(currentValue); + if (clock.state() != QAbstractAnimation::Running) + emit q->syncChanged(); +} + +void QmlSpringFollowPrivate::updateMode() +{ + if (spring == 0. && maxVelocity == 0.) + mode = Track; + else if (spring > 0.) + mode = Spring; + else + mode = Velocity; +} + +void QmlSpringFollowPrivate::start() +{ + if (!enabled) + return; + + Q_Q(QmlSpringFollow); + if (mode == QmlSpringFollowPrivate::Track) { + currentValue = sourceValue; + property.write(currentValue); + } else if (sourceValue != currentValue && clock.state() != QAbstractAnimation::Running) { + lastTime = 0; + currentValue = property.read().toDouble(); + clock.start(); // infinity?? + emit q->syncChanged(); + } +} + +void QmlSpringFollowPrivate::stop() +{ + clock.stop(); +} + +/*! + \qmlclass SpringFollow QmlSpringFollow + \brief The SpringFollow element allows a property to track a value. + + In example below, Rect2 will follow Rect1 moving with a velocity of up to 200: + \code + Rectangle { + id: Rect1 + width: 20; height: 20 + color: "#00ff00" + y: 200 //initial value + y: SequentialAnimation { + running: true + repeat: true + NumberAnimation { + to: 200 + easing: "easeOutBounce(amplitude:100)" + duration: 2000 + } + PauseAnimation { duration: 1000 } + } + } + Rectangle { + id: Rect2 + x: Rect1.width + width: 20; height: 20 + color: "#ff0000" + y: SpringFollow { source: Rect1.y; velocity: 200 } + } + \endcode +*/ + +QmlSpringFollow::QmlSpringFollow(QObject *parent) +: QObject(*(new QmlSpringFollowPrivate),parent) +{ +} + +QmlSpringFollow::~QmlSpringFollow() +{ +} + +void QmlSpringFollow::setTarget(const QmlMetaProperty &property) +{ + Q_D(QmlSpringFollow); + d->property = property; + d->currentValue = property.read().toDouble(); +} + +qreal QmlSpringFollow::sourceValue() const +{ + Q_D(const QmlSpringFollow); + return d->sourceValue; +} + +/*! + \qmlproperty qreal SpringFollow::source + This property holds the source value which will be tracked. + + Bind to a property in order to track its changes. +*/ + +void QmlSpringFollow::setSourceValue(qreal value) +{ + Q_D(QmlSpringFollow); + if (d->sourceValue != value) { + d->sourceValue = value; + d->start(); + } +} + +/*! + \qmlproperty qreal SpringFollow::velocity + This property holds the maximum velocity allowed when tracking the source. +*/ + +qreal QmlSpringFollow::velocity() const +{ + Q_D(const QmlSpringFollow); + return d->maxVelocity; +} + +void QmlSpringFollow::setVelocity(qreal velocity) +{ + Q_D(QmlSpringFollow); + d->maxVelocity = velocity; + d->velocityms = velocity / 1000.0; + d->updateMode(); +} + +/*! + \qmlproperty qreal 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 QmlSpringFollow::spring() const +{ + Q_D(const QmlSpringFollow); + return d->spring; +} + +void QmlSpringFollow::setSpring(qreal spring) +{ + Q_D(QmlSpringFollow); + d->spring = spring; + d->updateMode(); +} + +/*! + \qmlproperty qreal 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 QmlSpringFollow::damping() const +{ + Q_D(const QmlSpringFollow); + return d->damping; +} + +void QmlSpringFollow::setDamping(qreal damping) +{ + Q_D(QmlSpringFollow); + if (damping > 1.) + damping = 1.; + + d->damping = damping; +} + + +/*! + \qmlproperty qreal 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 QmlSpringFollow::epsilon() const +{ + Q_D(const QmlSpringFollow); + return d->epsilon; +} + +void QmlSpringFollow::setEpsilon(qreal epsilon) +{ + Q_D(QmlSpringFollow); + d->epsilon = epsilon; +} + +/*! + \qmlproperty qreal 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 QmlSpringFollow::modulus() const +{ + Q_D(const QmlSpringFollow); + return d->modulus; +} + +void QmlSpringFollow::setModulus(qreal modulus) +{ + Q_D(QmlSpringFollow); + if (d->modulus != modulus) { + d->haveModulus = modulus != 0.0; + d->modulus = modulus; + emit modulusChanged(); + } +} + +/*! + \qmlproperty qreal 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 QmlSpringFollow::mass() const +{ + Q_D(const QmlSpringFollow); + return d->mass; +} + +void QmlSpringFollow::setMass(qreal mass) +{ + Q_D(QmlSpringFollow); + if (d->mass != mass && mass > 0.0) { + d->useMass = mass != 1.0; + d->mass = mass; + emit massChanged(); + } +} + +/*! + \qmlproperty qreal SpringFollow::value + The current value. +*/ + +/*! + \qmlproperty bool SpringFollow::enabled + This property holds whether the target will track the source. +*/ +bool QmlSpringFollow::enabled() const +{ + Q_D(const QmlSpringFollow); + return d->enabled; +} + +void QmlSpringFollow::setEnabled(bool enabled) +{ + Q_D(QmlSpringFollow); + 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 QmlSpringFollow::inSync() const +{ + Q_D(const QmlSpringFollow); + return d->enabled && d->clock.state() != QAbstractAnimation::Running; +} + +qreal QmlSpringFollow::value() const +{ + Q_D(const QmlSpringFollow); + return d->currentValue; +} + +QT_END_NAMESPACE diff --git a/src/declarative/util/qmlspringfollow.h b/src/declarative/util/qmlspringfollow.h new file mode 100644 index 0000000..1b77861 --- /dev/null +++ b/src/declarative/util/qmlspringfollow.h @@ -0,0 +1,113 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, 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. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QMLFOLLOW_H +#define QMLFOLLOW_H + +#include +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QmlSpringFollowPrivate; +class Q_DECLARATIVE_EXPORT QmlSpringFollow : public QObject, + public QmlPropertyValueSource +{ + Q_OBJECT + Q_DECLARE_PRIVATE(QmlSpringFollow) + Q_INTERFACES(QmlPropertyValueSource) + + Q_PROPERTY(qreal source READ sourceValue WRITE setSourceValue) + 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(qreal modulus READ modulus WRITE setModulus) + 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: + QmlSpringFollow(QObject *parent=0); + ~QmlSpringFollow(); + + virtual void setTarget(const QmlMetaProperty &); + + qreal sourceValue() const; + void setSourceValue(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(QmlSpringFollow) + +QT_END_HEADER + +#endif // QFXFOLLOW_H diff --git a/src/declarative/util/util.pri b/src/declarative/util/util.pri index a57f69f..442380a 100644 --- a/src/declarative/util/util.pri +++ b/src/declarative/util/util.pri @@ -7,7 +7,7 @@ SOURCES += \ util/qmlscript.cpp \ util/qmlanimation.cpp \ util/qmlsystempalette.cpp \ - util/qmlfollow.cpp \ + util/qmlspringfollow.cpp \ util/qmleasefollow.cpp \ util/qmlstate.cpp\ util/qmltransitionmanager.cpp \ @@ -33,7 +33,7 @@ HEADERS += \ util/qmlanimation.h \ util/qmlanimation_p.h \ util/qmlsystempalette.h \ - util/qmlfollow.h \ + util/qmlspringfollow.h \ util/qmleasefollow.h \ util/qmlstate.h\ util/qmlstateoperations.h \ -- cgit v0.12