diff options
Diffstat (limited to 'src/declarative/util')
-rw-r--r-- | src/declarative/util/qbindablemap.cpp | 4 | ||||
-rw-r--r-- | src/declarative/util/qmlanimation.cpp | 78 | ||||
-rw-r--r-- | src/declarative/util/qmlbehaviour.cpp | 20 | ||||
-rw-r--r-- | src/declarative/util/qmlbind.cpp | 4 | ||||
-rw-r--r-- | src/declarative/util/qmldatetimeformatter.cpp | 28 | ||||
-rw-r--r-- | src/declarative/util/qmlfollow.cpp | 65 | ||||
-rw-r--r-- | src/declarative/util/qmlfollow.h | 3 | ||||
-rw-r--r-- | src/declarative/util/qmlscript.cpp | 6 | ||||
-rw-r--r-- | src/declarative/util/qmlsetproperties.cpp | 14 | ||||
-rw-r--r-- | src/declarative/util/qmlstateoperations.cpp | 41 | ||||
-rw-r--r-- | src/declarative/util/qmltransition.cpp | 6 |
11 files changed, 169 insertions, 100 deletions
diff --git a/src/declarative/util/qbindablemap.cpp b/src/declarative/util/qbindablemap.cpp index 341dd31..c8c8ced 100644 --- a/src/declarative/util/qbindablemap.cpp +++ b/src/declarative/util/qbindablemap.cpp @@ -87,8 +87,8 @@ private: Then, in QML: \code - <Text text="{owner.name}"/> - <Text text="{owner.phone}"/> + Text { text: owner.name } + Text { text: owner.phone } \endcode The binding is dynamic - whenever a key's value is updated, anything bound to that diff --git a/src/declarative/util/qmlanimation.cpp b/src/declarative/util/qmlanimation.cpp index 4bcc550..d5765c1 100644 --- a/src/declarative/util/qmlanimation.cpp +++ b/src/declarative/util/qmlanimation.cpp @@ -177,12 +177,14 @@ QmlAbstractAnimation::QmlAbstractAnimation(QmlAbstractAnimationPrivate &dd, QObj whenever the \l MouseRegion is pressed. \code - <Rect width="100" height="100"> - <x> - <NumericAnimation running="{MyMouse.pressed}" from="0" to="100" /> - </x> - <MouseRegion id="MyMouse" /> - </Rect> + Rect { + width: 100; height: 100 + x: NumericAnimation { + running: MyMouse.pressed + from: 0; to: 100 + } + MouseRegion { id: MyMouse } + } \endcode Likewise, the \c running property can be read to determine if the animation @@ -190,8 +192,8 @@ QmlAbstractAnimation::QmlAbstractAnimation(QmlAbstractAnimationPrivate &dd, QObj or not the animation is running. \code - <NumericAnimation id="MyAnimation" /> - <Text text="{MyAnimation.running?'Animation is running':'Animation is not running'}" /> + NumericAnimation { id: MyAnimation } + Text { text: MyAnimation.running ? "Animation is running" : "Animation is not running" } \endcode Animations can also be started and stopped imperatively from JavaScript @@ -304,11 +306,9 @@ void QmlAbstractAnimation::setFinishPlaying(bool f) In the following example, the rectangle will spin indefinately. \code - <Rect> - <rotation> - <NumericAnimation running="true" repeat="true" from="0" to="360" /> - </rotation> - </Rect> + Rect { + rotation: NumericAnimation { running: true; repeat: true; from: 0 to: 360 } + } \endcode */ bool QmlAbstractAnimation::repeat() const @@ -435,11 +435,9 @@ void QmlAbstractAnimation::start() Normally \c stop() stops the animation immediately, and the animation has no further influence on property values. In this example animation \code - <Rect> - <x> - <NumericAnimation from="0" to="100" duration="500" /> - </x> - </Rect> + Rect { + x: NumericAnimation { from: 0; to: 100; duration: 500 } + } \endcode was stopped at time 250ms, the \c x property will have a value of 50. @@ -475,11 +473,9 @@ void QmlAbstractAnimation::restart() Unlike \c stop(), \c complete() immediately fast-forwards the animation to its end. In the following example, \code - <Rect> - <x> - <NumericAnimation from="0" to="100" duration="500" /> - </x> - </Rect> + Rect { + x: NumericAnimation { from: 0; to: 100; duration: 500 } + } \endcode calling \c stop() at time 250ms will result in the \c x property having a value of 50, while calling \c complete() will set the \c x property to @@ -529,11 +525,11 @@ void QmlAbstractAnimation::timelineComplete() A 500ms animation sequence, with a 100ms pause between two animations: \code - <SequentialAnimation> - <NumericAnimation ... duration="200"/> - <PauseAnimation duration="100"/> - <NumericAnimation ... duration="200"/> - </SequentialAnimation> + SequentialAnimation { + NumericAnimation { ... duration: 200 } + PauseAnimation { duration: 100 } + NumericAnimation { ... duration: 200 } + } \endcode */ /*! @@ -621,7 +617,7 @@ QAbstractAnimation *QmlPauseAnimation::qtAnimation() \brief The ColorAnimation allows you to animate color changes. \code - <ColorAnimation from="white" to="#c0c0c0" duration="100"/> + ColorAnimation { from: "white" to: "#c0c0c0"; duration: 100 } \endcode The default property animated is \c color, but like other animations, @@ -1016,12 +1012,12 @@ QML_DEFINE_TYPE(QmlRunScriptAction, RunScriptAction); Explicitly set \c theimage.smooth=true during a transition: \code - <SetPropertyAction target="{theimage}" property="smooth" value="true"/> + SetPropertyAction { target: theimage; property: "smooth"; value: true } \endcode Set \c thewebview.url to the value set for the destination state: \code - <SetPropertyAction target="{thewebview}" property="url"/> + SetPropertyAction { target: thewebview; property: "url" } \endcode The SetPropertyAction is immediate - @@ -1324,7 +1320,7 @@ QML_DEFINE_TYPE(QmlParentChangeAction,ParentChangeAction); Animate a set of properties over 200ms, from their values in the start state to their values in the end state of the transition: \code - <NumericAnimation properties="x,y,scale" duration="200"/> + NumericAnimation { properties: "x,y,scale"; duration: 200 } \endcode */ @@ -1723,10 +1719,10 @@ QmlList<QmlAbstractAnimation *> *QmlAnimationGroup::animations() object will animate from its current x position to 100, and then back to 0. \code - <SequentialAnimation> - <NumericAnimation target="{MyItem}" property="x" to="100" /> - <NumericAnimation target="{MyItem}" property="x" to="0" /> - <SequentialAnimation> + SequentialAnimation { + NumericAnimation { target: MyItem; property: "x"; to: 100 } + NumericAnimation { target: MyItem; property: "x"; to: 0 } + } \endcode \sa ParallelAnimation @@ -1800,10 +1796,10 @@ QML_DEFINE_TYPE(QmlSequentialAnimation,SequentialAnimation); to (100,100) by animating the x and y properties in parallel. \code - <ParallelAnimation> - <NumericAnimation target="{MyItem}" property="x" to="100" /> - <NumericAnimation target="{MyItem}" property="y" to="100" /> - </ParallelAnimation> + ParallelAnimation { + NumericAnimation { target: MyItem; property: "x"; to: 100 } + NumericAnimation { target: MyItem; property: "y"; to: 100 } + } \endcode \sa SequentialAnimation @@ -1924,7 +1920,7 @@ void QmlVariantAnimationPrivate::convertVariant(QVariant &variant, QVariant::Typ Animate a size property over 200ms, from its current size to 20-by-20: \code - <VariantAnimation property="size" to="20x20" duration="200"/> + VariantAnimation { property: "size"; to: "20x20"; duration: 200 } \endcode */ diff --git a/src/declarative/util/qmlbehaviour.cpp b/src/declarative/util/qmlbehaviour.cpp index 58e515f..354c7e3 100644 --- a/src/declarative/util/qmlbehaviour.cpp +++ b/src/declarative/util/qmlbehaviour.cpp @@ -105,15 +105,19 @@ public: \qmlclass Behaviour QmlBehaviour \brief The Behaviour element allows you to specify a default animation for a property change. - In example below, Rect1 will use a bounce easing curve over 200 millisecond for any changes to its y property: + In example below, the rect will use a bounce easing curve over 200 millisecond for any changes to its y property: \code - <Rect id="Rect1" y="200" width="20" height="20" color="#00ff00"> - <y> - <Behaviour> - <NumericAnimation easing="easeOutBounce(amplitude:100)" duration="200" /> - </Behaviour> - </y> - </Rect> + Rect { + width: 20; height: 20 + color: "#00ff00" + y: 200 //initial value + y: Behaviour { + NumericAnimation { + easing: "easeOutBounce(amplitude:100)" + duration: 200 + } + } + } \endcode */ diff --git a/src/declarative/util/qmlbind.cpp b/src/declarative/util/qmlbind.cpp index 3b51c6a..59bfd75 100644 --- a/src/declarative/util/qmlbind.cpp +++ b/src/declarative/util/qmlbind.cpp @@ -77,8 +77,8 @@ QML_DEFINE_TYPE(QmlBind,Bind); property into QML. You could use Bind to update the enteredText property like this. \code - <TextEdit id="myTextField" text="Please type here..." /> - <Bind target="{app}" property="enteredText" value="{myTextField.text}" /> + TextEdit { id: myTextField; text: "Please type here..." } + Bind { target: app; property: "enteredText"; value: myTextField.text /> \endcode Whenever the text in the TextEdit is updated, the C++ property will be updated also. diff --git a/src/declarative/util/qmldatetimeformatter.cpp b/src/declarative/util/qmldatetimeformatter.cpp index efddd81..94b87ee 100644 --- a/src/declarative/util/qmldatetimeformatter.cpp +++ b/src/declarative/util/qmldatetimeformatter.cpp @@ -74,8 +74,8 @@ public: \brief The DateTimeFormatter allows you to control the format of a date string. \code - <DateTimeFormatter id="Formatter" date="{System.date}"/> - <Text text="{Formatter.dateText}"/> + DateTimeFormatter { id: Formatter; date: System.date } + Text { text: Formatter.dateText } \endcode By default, the text properties (dateText, timeText, and dateTimeText) will return the @@ -110,18 +110,18 @@ QmlDateTimeFormatter::~QmlDateTimeFormatter() will use the system locale's default 'short' setting. \code - <!-- specify source date (assuming today is February 19, 2009) --> - <DateTimeFormatter id="formatter" dateTime="{Today.date}"/> + // specify source date (assuming today is February 19, 2009) + DateTimeFormatter { id: formatter; dateTime: Today.date } - <!-- display the full date and time --> - <Text text="{formatter.dateText}"/> + // display the full date and time + Text { text: formatter.dateText } \endcode Would be equivalent to the following for a US English locale: \code - <!-- display the date --> - <Text text="2/19/09"/> + // display the date + Text { text: "2/19/09" } \endcode */ QString QmlDateTimeFormatter::dateTimeText() const @@ -150,14 +150,14 @@ QString QmlDateTimeFormatter::timeText() const The source date and time to be used by the formatter. \code - <!-- setting the date and time --> - <DateTimeFormatter date="{System.date}" time="{System.time}"/> + // setting the date and time + DateTimeFormatter { date: System.date; time: System.time } \endcode For convienience it is possible to set the datetime property to set both the date and the time. \code - <!-- setting the datetime --> - <DateTimeFormatter dateTime="{System.dateTime}"/> + // setting the datetime + DateTimeFormatter { dateTime: System.dateTime } \endcode There can only be one instance of date and time per formatter; if date, time, and dateTime are all @@ -208,8 +208,8 @@ QDateTime QmlDateTimeFormatter::dateTime() const Syntax for the format is based on the QDateTime::toString() formatting options. \code - <!-- Format the date such that the dateText is: '1997-12-12'> - <DateFormatter id="formatter" dateTime="{Today.dateTime}" formatDate="yyyy-MM-d"/> + // Format the date such that the dateText is: '1997-12-12' + DateTimeFormatter { id: formatter; dateTime: Today.dateTime; formatDate: "yyyy-MM-d" } \endcode Assigning an empty string to a particular format will reset it. diff --git a/src/declarative/util/qmlfollow.cpp b/src/declarative/util/qmlfollow.cpp index 35f3c49..8e5ae69 100644 --- a/src/declarative/util/qmlfollow.cpp +++ b/src/declarative/util/qmlfollow.cpp @@ -55,7 +55,7 @@ class QmlFollowPrivate : public QObjectPrivate public: QmlFollowPrivate() : sourceValue(0), maxVelocity(0), lastTime(0) - , mass(1.0), spring(0.), damping(0.), velocity(0), enabled(true), mode(Track), clock(this) {} + , mass(1.0), spring(0.), damping(0.), velocity(0), epsilon(0.005), enabled(true), mode(Track), clock(this) {} QmlMetaProperty property; qreal currentValue; @@ -67,6 +67,7 @@ public: qreal spring; qreal damping; qreal velocity; + qreal epsilon; bool enabled; enum Mode { @@ -111,7 +112,7 @@ void QmlFollowPrivate::tick(int time) } currentValue += velocity * 10.0 / 1000.0; } - if (qAbs(velocity) < 0.5 && qAbs(sourceValue - currentValue) < 0.5) { + if (qAbs(velocity) < epsilon && qAbs(sourceValue - currentValue) < epsilon) { velocity = 0.0; currentValue = sourceValue; clock.stop(); @@ -174,19 +175,29 @@ void QmlFollowPrivate::stop() In example below, Rect2 will follow Rect1 moving with a velocity of up to 200: \code - <Rect id="Rect1" y="{200}" width="20" height="20" color="#00ff00"> - <y> - <SequentialAnimation running="true" repeat="true"> - <NumericAnimation to="{200}" easing="easeOutBounce(amplitude:100)" duration="2000" /> - <PauseAnimation duration="1000" /> - </SequentialAnimation> - </y> - </Rect> - <Rect id="Rect2" x="{Rect1.width}" width="20" height="20" color="#ff0000"> - <y> - <Follow source="{Rect1.y}" velocity="200"/> - </y> - </Rect> + Rect { + id: Rect1 + width: 20; height: 20 + color: "#00ff00" + y: 200 //initial value + y: SequentialAnimation { + running: true + repeat: true + NumericAnimation { + to: 200 + easing: "easeOutBounce(amplitude:100)" + duration: 2000 + } + PauseAnimation { duration: 1000 } + } + } + Rect { + id: Rect2 + x: Rect1.width + width: 20; height: 20 + color: "#ff0000" + y: Follow { source: Rect1.y; velocity: 200 } + } \endcode */ @@ -290,6 +301,30 @@ void QmlFollow::setDamping(qreal damping) 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.005. Small performance improvements can result in tuning this + value. +*/ +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::followValue The current value. diff --git a/src/declarative/util/qmlfollow.h b/src/declarative/util/qmlfollow.h index aac4c01..bd9363a 100644 --- a/src/declarative/util/qmlfollow.h +++ b/src/declarative/util/qmlfollow.h @@ -63,6 +63,7 @@ class Q_DECLARATIVE_EXPORT QmlFollow : public QmlPropertyValueSource, 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 followValue READ value NOTIFY valueChanged); @@ -80,6 +81,8 @@ public: void setSpring(qreal spring); qreal damping() const; void setDamping(qreal damping); + qreal epsilon() const; + void setEpsilon(qreal epsilon); bool enabled() const; void setEnabled(bool enabled); diff --git a/src/declarative/util/qmlscript.cpp b/src/declarative/util/qmlscript.cpp index 757ae09..7e33502 100644 --- a/src/declarative/util/qmlscript.cpp +++ b/src/declarative/util/qmlscript.cpp @@ -85,13 +85,13 @@ public: within a QmlScript, it is best to limit yourself to defining functions. \qml - <Script> + Script { function debugMyComponent() { print(text.text); print(otherinterestingitem.property); } - </Script> - <MouseRegion onClicked="debugMyComponent()" /> + } + MouseRegion { onClicked: debugMyComponent() } \endqml \note QmlScript executes JavaScript as soon as it is specified. diff --git a/src/declarative/util/qmlsetproperties.cpp b/src/declarative/util/qmlsetproperties.cpp index 108f2b2..9b5a58e 100644 --- a/src/declarative/util/qmlsetproperties.cpp +++ b/src/declarative/util/qmlsetproperties.cpp @@ -108,7 +108,12 @@ void QmlSetPropertiesMetaObject::propertyWrite(int id) you normally would specify them for the actual item: \code - <SetProperties target="{myRect}" x="52" y="300" width="48"/> + SetProperties { + target: myRect + x: 52 + y: 300 + width: 48 + } \endcode \c target is a property of \c SetProperties, so if the property you want to change @@ -129,7 +134,12 @@ void QmlSetPropertiesMetaObject::propertyWrite(int id) you normally would specify them for the actual item: \code - <SetProperties target="{myRect}" x="52" y="300" width="48"/> + SetProperties { + target: myRect + x: 52 + y: 300 + width: 48 + } \endcode \c target is a property of \c SetProperties, so if the property you want to change diff --git a/src/declarative/util/qmlstateoperations.cpp b/src/declarative/util/qmlstateoperations.cpp index 755befe..01f9cdd 100644 --- a/src/declarative/util/qmlstateoperations.cpp +++ b/src/declarative/util/qmlstateoperations.cpp @@ -212,17 +212,36 @@ QmlRunScript::ActionList QmlRunScript::actions() the current state: \code - <Rect id="myrect" width="50" height="50" color="red"/> - - <states> - <State name="Position1"> - <SetProperty target="{myrect}" property="x" value="150"/> - <SetProperty target="{myrect}" property="y" value="50"/> - </State> - <State name="Position2"> - <SetProperty target="{myrect}" property="y" value="200"/> - </State> - </states> + Rect { + id: myrect + width: 50 + height: 50 + color: "red" + } + + states: [ + State { + name: "Position1" + SetProperty { + target: myrect + property: "x" + value: 150 + } + SetProperty { + target: myrect + property: "y" + value: 50 + } + }, + State { + name: "Position2" + SetProperty { + target: myrect + property: "y" + value: 200 + } + } + ] \endcode \sa SetProperties diff --git a/src/declarative/util/qmltransition.cpp b/src/declarative/util/qmltransition.cpp index a515f58..47e70ad 100644 --- a/src/declarative/util/qmltransition.cpp +++ b/src/declarative/util/qmltransition.cpp @@ -188,9 +188,11 @@ void QmlTransition::prepare(QmlStateOperation::ActionList &actions, be applied. By default fromState and toState are both "*" (any state). In the following example, the transition is applied when changing from state1 to state2. \code - <Transition fromState="state1" toState="state2"> + Transition { + fromState: "state1" + toState: "state2" ... - </Transition> + } \endcode */ |