summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorQt Continuous Integration System <qt-info@nokia.com>2010-07-20 04:08:24 (GMT)
committerQt Continuous Integration System <qt-info@nokia.com>2010-07-20 04:08:24 (GMT)
commitc4d7e13d79a34be8e87cbdfc0d933ecdfd3e6f70 (patch)
tree5a53380eae69d39313f190ba5204ac2bd1148e49
parent4ee47d5eede0e7b17fc1059cb63dd1287c6599cf (diff)
parent84f4daa03f99bc7977641d6f1ac29e3423fb4a14 (diff)
downloadQt-c4d7e13d79a34be8e87cbdfc0d933ecdfd3e6f70.zip
Qt-c4d7e13d79a34be8e87cbdfc0d933ecdfd3e6f70.tar.gz
Qt-c4d7e13d79a34be8e87cbdfc0d933ecdfd3e6f70.tar.bz2
Merge branch '4.7' of scm.dev.nokia.troll.no:qt/qt-qml into 4.7-integration
* '4.7' of scm.dev.nokia.troll.no:qt/qt-qml: Make Item::transformOriginPoint read-only Ensure the boundingRect() of Text is correctly calculated. Better defaults for MouseArea's drag. various doc improvements for animation elements fixes for dynamic object creation docs Change docs to show how to define enum properties Improve documentation on setting arbitray transform origin points Ensure released VisualItemModel items are removed from the scene. Improve QML text rendering when LCD smoothing is enabled for OS X.
-rw-r--r--doc/src/declarative/dynamicobjects.qdoc77
-rw-r--r--doc/src/declarative/extending-tutorial.qdoc26
-rw-r--r--doc/src/snippets/declarative/behavior.qml59
-rw-r--r--doc/src/snippets/declarative/componentCreation.js63
-rw-r--r--doc/src/snippets/declarative/createComponent.qml4
-rw-r--r--doc/src/snippets/declarative/createQmlObject.qml3
-rw-r--r--doc/src/snippets/declarative/parallelanimation.qml57
-rw-r--r--doc/src/snippets/declarative/parentchange.qml5
-rw-r--r--doc/src/snippets/declarative/rotationanimation.qml66
-rw-r--r--doc/src/snippets/declarative/sequentialanimation.qml57
-rw-r--r--doc/src/snippets/declarative/springanimation.qml6
-rw-r--r--src/declarative/graphicsitems/qdeclarativeitem.cpp12
-rw-r--r--src/declarative/graphicsitems/qdeclarativeitem.h1
-rw-r--r--src/declarative/graphicsitems/qdeclarativemousearea.cpp3
-rw-r--r--src/declarative/graphicsitems/qdeclarativepainteditem.cpp16
-rw-r--r--src/declarative/graphicsitems/qdeclarativetext.cpp18
-rw-r--r--src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp8
-rw-r--r--src/declarative/qml/qdeclarativeengine.cpp15
-rw-r--r--src/declarative/util/qdeclarativeanimation.cpp257
-rw-r--r--src/declarative/util/qdeclarativebehavior.cpp39
-rw-r--r--src/declarative/util/qdeclarativesmoothedanimation.cpp31
-rw-r--r--src/declarative/util/qdeclarativespringanimation.cpp39
-rw-r--r--src/declarative/util/qdeclarativetransition.cpp2
-rw-r--r--tests/auto/declarative/qdeclarativerepeater/data/itemlist.qml29
-rw-r--r--tests/auto/declarative/qdeclarativerepeater/tst_qdeclarativerepeater.cpp9
-rw-r--r--tests/auto/declarative/qdeclarativetext/tst_qdeclarativetext.cpp1
26 files changed, 634 insertions, 269 deletions
diff --git a/doc/src/declarative/dynamicobjects.qdoc b/doc/src/declarative/dynamicobjects.qdoc
index a5e53a9..6bce4fa 100644
--- a/doc/src/declarative/dynamicobjects.qdoc
+++ b/doc/src/declarative/dynamicobjects.qdoc
@@ -39,31 +39,35 @@ QML also supports the dynamic creation of objects from within JavaScript
code. This is useful if the existing QML elements do not fit the needs of your
application, and there are no C++ components involved.
-See the {declarative/toys/dynamicscene}{Dynamic Scene example} for a demonstration
+See the \l {declarative/toys/dynamicscene}{Dynamic Scene example} for a demonstration
of the concepts discussed on this page.
\section1 Creating Objects Dynamically
There are two ways to create objects dynamically from JavaScript. You can either call
-\l {QML:Qt::createComponent()}{Qt.createComponent()} to create
-a component which instantiates items, or use \l{QML:Qt::createQmlObject()}{Qt.createQmlObject()}
+\l {QML:Qt::createComponent()}{Qt.createComponent()} to dynamically create
+a \l Component object, or use \l{QML:Qt::createQmlObject()}{Qt.createQmlObject()}
to create an item from a string of QML.
-Creating a component is better if you have a predefined
-item, and you want to create dynamic instances of that item; creating an item from
-a string of QML is useful when the item QML itself is generated at runtime.
+Creating a component is better if you have an existing component defined in a \c .qml
+file, and you want to dynamically create instances of that component. Otherwise,
+creating an item from a string of QML is useful when the item QML itself is generated
+at runtime.
-If you have a component specified in a QML file, you can dynamically load it with
-the \l {QML:Qt::createComponent()}{Qt.createComponent()} function on the \l{QML Global Object}.
-This function takes the URL of the QML file as its only argument and returns
-a component object which can be used to create and load that QML file.
-Once you have a component you can use its \l {Component::createObject()}{createObject()} method to create an instance of
+\section2 Creating a Component dynamically
+
+To dynamically load a component defined in a QML file, call the
+\l {QML:Qt::createComponent()}{Qt.createComponent()} function on the \l{QML Global Object}.
+This function takes the URL of the QML file as its only argument and creates
+a \l Component object from this URL.
+
+Once you have a \l Component, you can call its \l {Component::createObject()}{createObject()} method to create an instance of
the component. This function takes exactly one argument, which is the parent for the new item. Since graphical items will
not appear on the scene without a parent, it is recommended that you set the parent this way. However, if you wish to set
-the parent later you can safely pass null to this function.
+the parent later you can safely pass \c null to this function.
-Here is an example. Here is a \c Sprite.qml, which defines a simple QML component:
+Here is an example. First there is \c Sprite.qml, which defines a simple QML component:
\snippet doc/src/snippets/declarative/Sprite.qml 0
@@ -72,35 +76,48 @@ that will create \c Sprite objects:
\snippet doc/src/snippets/declarative/createComponent.qml 0
-Here is \c componentCreation.js. Remember that QML files that might be loaded
-over the network cannot be expected to be ready immediately:
+Here is \c componentCreation.js. Notice it checks whether the component \l{Component::status}{status} is
+\c Component.Ready before calling \l {Component::createObject()}{createObject()}
+in case the QML file is loaded over a network and thus is not ready immediately.
-\snippet doc/src/snippets/declarative/componentCreation.js 0
+\snippet doc/src/snippets/declarative/componentCreation.js vars
\codeline
-\snippet doc/src/snippets/declarative/componentCreation.js 1
+\snippet doc/src/snippets/declarative/componentCreation.js func
+\snippet doc/src/snippets/declarative/componentCreation.js remote
+\snippet doc/src/snippets/declarative/componentCreation.js func-end
+\codeline
+\snippet doc/src/snippets/declarative/componentCreation.js finishCreation
-If you are certain the files will be local, you could simplify to:
+If you are certain the QML file to be loaded is a local file, you could omit the \c finishCreation()
+function and call \l {Component::createObject()}{createObject()} immediately:
-\snippet doc/src/snippets/declarative/componentCreation.js 2
+\snippet doc/src/snippets/declarative/componentCreation.js func
+\snippet doc/src/snippets/declarative/componentCreation.js local
+\snippet doc/src/snippets/declarative/componentCreation.js func-end
-Notice that once a \c Sprite object is created, its parent is set to \c appWindow (defined
-in \c main.qml). After creating an item, you must set its parent to an item within the scene.
-Otherwise your dynamically created item will not appear in the scene.
+Notice in both instances, \l {Component::createObject()}{createObject()} is called with
+\c appWindow passed as an argument so that the created object will become a child of the
+\c appWindow item in \c main.qml. Otherwise, the new item will not appear in the scene.
When using files with relative paths, the path should
be relative to the file where \l {QML:Qt::createComponent()}{Qt.createComponent()} is executed.
-If the QML component does not exist until runtime, you can create a QML item from
+
+\section2 Creating an object from a string of QML
+
+If the QML is not defined until runtime, you can create a QML item from
a string of QML using the \l{QML:Qt::createQmlObject()}{Qt.createQmlObject()} function, as in the following example:
\snippet doc/src/snippets/declarative/createQmlObject.qml 0
The first argument is the string of QML to create. Just like in a new file, you will need to
-import any types you wish to use. For importing files with relative paths, the path should
-be relative to the file where the item in the second argument is defined. Remember to set the parent after
-creating the item. The second argument is another item in the scene, and the new item is created
-in the same QML Context as this item. The third argument is the file path associated with this
-item, which is used for error reporting.
+import any types you wish to use. The second argument is the parent item for the new item;
+this should be an existing item in the scene. The third argument is the file path to associate
+with the new item; this is used for error reporting.
+
+If the string of QML imports files using relative paths, the path should be relative
+to the file in which the parent item (the second argument to the method) is defined.
+
\section1 Maintaining Dynamically Created Objects
@@ -114,9 +131,9 @@ The actual creation context depends on how an item is created:
\o If \l {QML:Qt::createComponent()}{Qt.createComponent()} is used, the creation context
is the QDeclarativeContext in which this method is called
\o If \l{QML:Qt::createQmlObject()}{Qt.createQmlObject()}
- if called, it is the context of the item used as the second argument to this method
+ if called, the creation context is the context of the parent item passed to this method
\o If a \c {Component{}} item is defined and \l {Component::createObject()}{createObject()}
- is called on that item, it is the context in which the \c Component is defined
+ is called on that item, the creation context is the context in which the \c Component is defined
\endlist
Also, note that while dynamically created objects may be used the same as other objects, they
diff --git a/doc/src/declarative/extending-tutorial.qdoc b/doc/src/declarative/extending-tutorial.qdoc
index cc93e86..bc849b0 100644
--- a/doc/src/declarative/extending-tutorial.qdoc
+++ b/doc/src/declarative/extending-tutorial.qdoc
@@ -260,20 +260,34 @@ custom QML types may see unexpected behavior if bindings are not implemented.
\example declarative/tutorials/extending/chapter4-customPropertyTypes
The \c PieChart type currently has a string-type property and a color-type property.
-It could have many other types of properties. For example, we could add an
-integer-type property to store an identifier for each pie chart:
+It could have many other types of properties. For example, it could have an
+enum-type property to store a display mode for each chart:
\code
+ // C++
class PieChart : public QDeclarativeItem
{
+ Q_ENUMS(DisplayMode)
+ Q_PROPERTY(DisplayMode displayMode READ displayMode WRITE setDisplayMode)
...
- Q_PROPERTY(int id READ id WRITE setId)
+
public:
- ...
- int id() const;
- void setId(int id);
+ enum DisplayMode {
+ MultiLevel,
+ Exploded,
+ ThreeDimensional
+ };
+
+ void setDisplayMode(DisplayMode mode);
+ DisplayMode displayMode() const;
...
};
+
+ // QML
+ PieChart {
+ ...
+ displayMode: PieChart.Exploded
+ }
\endcode
We can also use various other property types. QML has built-in support for the following
diff --git a/doc/src/snippets/declarative/behavior.qml b/doc/src/snippets/declarative/behavior.qml
new file mode 100644
index 0000000..420dfc4
--- /dev/null
+++ b/doc/src/snippets/declarative/behavior.qml
@@ -0,0 +1,59 @@
+/****************************************************************************
+**
+** 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$
+**
+****************************************************************************/
+
+//![0]
+import Qt 4.7
+
+Rectangle {
+ id: rect
+ width: 100; height: 100
+ color: "red"
+
+ Behavior on width {
+ NumberAnimation { duration: 1000 }
+ }
+
+ MouseArea {
+ anchors.fill: parent
+ onClicked: rect.width = 50
+ }
+}
+//![0]
diff --git a/doc/src/snippets/declarative/componentCreation.js b/doc/src/snippets/declarative/componentCreation.js
index 25bc10c..c29a1f9 100644
--- a/doc/src/snippets/declarative/componentCreation.js
+++ b/doc/src/snippets/declarative/componentCreation.js
@@ -1,7 +1,39 @@
-//![0]
+//![vars]
var component;
var sprite;
+//![vars]
+//![func]
+function createSpriteObjects() {
+//![func]
+
+//![remote]
+ component = Qt.createComponent("Sprite.qml");
+ if (component.status == Component.Ready)
+ finishCreation();
+ else
+ component.statusChanged.connect(finishCreation);
+//![remote]
+
+//![local]
+ component = Qt.createComponent("Sprite.qml");
+ sprite = component.createObject(appWindow);
+
+ if (sprite == null) {
+ // Error Handling
+ console.log("Error creating object");
+ } else {
+ sprite.x = 100;
+ sprite.y = 100;
+ // ...
+ }
+//![local]
+
+//![func-end]
+}
+//![func-end]
+
+//![finishCreation]
function finishCreation() {
if (component.status == Component.Ready) {
sprite = component.createObject(appWindow);
@@ -17,31 +49,4 @@ function finishCreation() {
console.log("Error loading component:", component.errorString());
}
}
-//![0]
-
-function createSpriteObjects() {
-
-//![1]
-component = Qt.createComponent("Sprite.qml");
-if (component.status == Component.Ready)
- finishCreation();
-else
- component.statusChanged.connect(finishCreation);
-//![1]
-
-//![2]
-component = Qt.createComponent("Sprite.qml");
-sprite = component.createObject(appWindow);
-
-if (sprite == null) {
- // Error Handling
- console.log("Error loading component:", component.errorString());
-} else {
- sprite.x = 100;
- sprite.y = 100;
- // ...
-}
-//![2]
-
-}
-
+//![finishCreation]
diff --git a/doc/src/snippets/declarative/createComponent.qml b/doc/src/snippets/declarative/createComponent.qml
index 8bfed07..0f9fad5 100644
--- a/doc/src/snippets/declarative/createComponent.qml
+++ b/doc/src/snippets/declarative/createComponent.qml
@@ -40,12 +40,12 @@
//![0]
import Qt 4.7
-import "componentCreation.js" as MyModule
+import "componentCreation.js" as MyScript
Rectangle {
id: appWindow
width: 300; height: 300
- Component.onCompleted: MyModule.createSpriteObjects();
+ Component.onCompleted: MyScript.createSpriteObjects();
}
//![0]
diff --git a/doc/src/snippets/declarative/createQmlObject.qml b/doc/src/snippets/declarative/createQmlObject.qml
index 380f6f1..64dd21d 100644
--- a/doc/src/snippets/declarative/createQmlObject.qml
+++ b/doc/src/snippets/declarative/createQmlObject.qml
@@ -42,14 +42,13 @@ import Qt 4.7
Rectangle {
id: parentItem
- property QtObject newObject
width: 100
height: 100
function createIt() {
//![0]
-newObject = Qt.createQmlObject('import Qt 4.7; Rectangle {color: "red"; width: 20; height: 20}',
+var newObject = Qt.createQmlObject('import Qt 4.7; Rectangle {color: "red"; width: 20; height: 20}',
parentItem, "dynamicSnippet1");
//![0]
}
diff --git a/doc/src/snippets/declarative/parallelanimation.qml b/doc/src/snippets/declarative/parallelanimation.qml
new file mode 100644
index 0000000..d823b4f
--- /dev/null
+++ b/doc/src/snippets/declarative/parallelanimation.qml
@@ -0,0 +1,57 @@
+/****************************************************************************
+**
+** 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$
+**
+****************************************************************************/
+
+//![0]
+import Qt 4.7
+
+Rectangle {
+ id: rect
+ width: 100; height: 100
+ color: "red"
+
+ ParallelAnimation {
+ running: true
+ NumberAnimation { target: rect; property: "x"; to: 50; duration: 1000 }
+ NumberAnimation { target: rect; property: "y"; to: 50; duration: 1000 }
+ }
+}
+//![0]
+
diff --git a/doc/src/snippets/declarative/parentchange.qml b/doc/src/snippets/declarative/parentchange.qml
index 7f5718a..ea50832 100644
--- a/doc/src/snippets/declarative/parentchange.qml
+++ b/doc/src/snippets/declarative/parentchange.qml
@@ -41,9 +41,8 @@
//![0]
import Qt 4.7
-Rectangle {
- width: 200
- height: 100
+Item {
+ width: 200; height: 100
Rectangle {
id: redRect
diff --git a/doc/src/snippets/declarative/rotationanimation.qml b/doc/src/snippets/declarative/rotationanimation.qml
new file mode 100644
index 0000000..c81395a
--- /dev/null
+++ b/doc/src/snippets/declarative/rotationanimation.qml
@@ -0,0 +1,66 @@
+/****************************************************************************
+**
+** 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$
+**
+****************************************************************************/
+
+//![0]
+import Qt 4.7
+
+Item {
+ width: 300; height: 300
+
+ Rectangle {
+ id: rect
+ width: 150; height: 100; anchors.centerIn: parent
+ color: "red"
+ smooth: true
+
+ states: State {
+ name: "rotated"; PropertyChanges { target: rect; rotation: 180 }
+ }
+
+ transitions: Transition {
+ RotationAnimation { duration: 1000; direction: RotationAnimation.Counterclockwise }
+ }
+ }
+
+ MouseArea { anchors.fill: parent; onClicked: rect.state = "rotated" }
+}
+//![0]
+
diff --git a/doc/src/snippets/declarative/sequentialanimation.qml b/doc/src/snippets/declarative/sequentialanimation.qml
new file mode 100644
index 0000000..a15f7f3
--- /dev/null
+++ b/doc/src/snippets/declarative/sequentialanimation.qml
@@ -0,0 +1,57 @@
+/****************************************************************************
+**
+** 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$
+**
+****************************************************************************/
+
+//![0]
+import Qt 4.7
+
+Rectangle {
+ id: rect
+ width: 100; height: 100
+ color: "red"
+
+ SequentialAnimation {
+ running: true
+ NumberAnimation { target: rect; property: "x"; to: 50; duration: 1000 }
+ NumberAnimation { target: rect; property: "y"; to: 50; duration: 1000 }
+ }
+}
+//![0]
+
diff --git a/doc/src/snippets/declarative/springanimation.qml b/doc/src/snippets/declarative/springanimation.qml
index b73a9d2..8e810e1 100644
--- a/doc/src/snippets/declarative/springanimation.qml
+++ b/doc/src/snippets/declarative/springanimation.qml
@@ -41,7 +41,7 @@
//![0]
import Qt 4.7
-Rectangle {
+Item {
width: 300; height: 300
Rectangle {
@@ -56,8 +56,8 @@ Rectangle {
MouseArea {
anchors.fill: parent
onClicked: {
- rect.x = mouse.x
- rect.y = mouse.y
+ rect.x = mouse.x - rect.width/2
+ rect.y = mouse.y - rect.height/2
}
}
}
diff --git a/src/declarative/graphicsitems/qdeclarativeitem.cpp b/src/declarative/graphicsitems/qdeclarativeitem.cpp
index 367a5d0..86ef0df 100644
--- a/src/declarative/graphicsitems/qdeclarativeitem.cpp
+++ b/src/declarative/graphicsitems/qdeclarativeitem.cpp
@@ -59,16 +59,13 @@
#include <QEvent>
#include <QGraphicsSceneMouseEvent>
#include <QtCore/qnumeric.h>
+#include <QtCore/qmath.h>
#include <QtScript/qscriptengine.h>
#include <QtGui/qgraphicstransform.h>
#include <qlistmodelinterface_p.h>
QT_BEGIN_NAMESPACE
-#ifndef FLT_MAX
-#define FLT_MAX 1E+37
-#endif
-
/*!
\qmlclass Transform QGraphicsTransform
\since 4.7
@@ -1514,6 +1511,9 @@ QDeclarativeItem::~QDeclarativeItem()
\endqml
The default transform origin is \c Item.Center.
+
+ To set an arbitrary transform origin point use the \l Scale or \l Rotation
+ transform elements.
*/
/*!
@@ -2192,6 +2192,8 @@ void QDeclarativeItem::setBaselineOffset(qreal offset)
}
\endqml
\endtable
+
+ \sa transform, Rotation
*/
/*!
@@ -2228,6 +2230,8 @@ void QDeclarativeItem::setBaselineOffset(qreal offset)
}
\endqml
\endtable
+
+ \sa transform, Scale
*/
/*!
diff --git a/src/declarative/graphicsitems/qdeclarativeitem.h b/src/declarative/graphicsitems/qdeclarativeitem.h
index 4f420f8..8878fa0 100644
--- a/src/declarative/graphicsitems/qdeclarativeitem.h
+++ b/src/declarative/graphicsitems/qdeclarativeitem.h
@@ -90,6 +90,7 @@ class Q_DECLARATIVE_EXPORT QDeclarativeItem : public QGraphicsObject, public QDe
Q_PROPERTY(bool wantsFocus READ wantsFocus NOTIFY wantsFocusChanged)
Q_PROPERTY(QDeclarativeListProperty<QGraphicsTransform> transform READ transform DESIGNABLE false FINAL)
Q_PROPERTY(TransformOrigin transformOrigin READ transformOrigin WRITE setTransformOrigin NOTIFY transformOriginChanged)
+ Q_PROPERTY(QPointF transformOriginPoint READ transformOriginPoint) // transformOriginPoint is read-only for Item
Q_PROPERTY(bool smooth READ smooth WRITE setSmooth NOTIFY smoothChanged)
Q_ENUMS(TransformOrigin)
Q_CLASSINFO("DefaultProperty", "data")
diff --git a/src/declarative/graphicsitems/qdeclarativemousearea.cpp b/src/declarative/graphicsitems/qdeclarativemousearea.cpp
index b7b0c9e..7e4a36f 100644
--- a/src/declarative/graphicsitems/qdeclarativemousearea.cpp
+++ b/src/declarative/graphicsitems/qdeclarativemousearea.cpp
@@ -45,12 +45,13 @@
#include "private/qdeclarativeevents_p_p.h"
#include <QGraphicsSceneMouseEvent>
+#include <QtCore/qmath.h>
QT_BEGIN_NAMESPACE
static const int PressAndHoldDelay = 800;
QDeclarativeDrag::QDeclarativeDrag(QObject *parent)
-: QObject(parent), _target(0), _axis(XandYAxis), _xmin(0), _xmax(0), _ymin(0), _ymax(0),
+: QObject(parent), _target(0), _axis(XandYAxis), _xmin(-FLT_MAX), _xmax(FLT_MAX), _ymin(-FLT_MAX), _ymax(FLT_MAX),
_active(false)
{
}
diff --git a/src/declarative/graphicsitems/qdeclarativepainteditem.cpp b/src/declarative/graphicsitems/qdeclarativepainteditem.cpp
index 3b9b8df..a6db1fa 100644
--- a/src/declarative/graphicsitems/qdeclarativepainteditem.cpp
+++ b/src/declarative/graphicsitems/qdeclarativepainteditem.cpp
@@ -90,6 +90,8 @@ QT_BEGIN_NAMESPACE
static int inpaint=0;
static int inpaint_clearcache=0;
+extern Q_GUI_EXPORT bool qt_applefontsmoothing_enabled;
+
/*!
Marks areas of the cache that intersect with the given \a rect as dirty and
in need of being refreshed.
@@ -287,7 +289,14 @@ void QDeclarativePaintedItem::paint(QPainter *p, const QStyleOptionGraphicsItem
QRectF target(area.x(), area.y(), area.width(), area.height());
if (!d->cachefrozen) {
if (!d->imagecache[i]->dirty.isNull() && topaint.contains(d->imagecache[i]->dirty)) {
+#ifdef Q_WS_MAC
+ bool oldSmooth = qt_applefontsmoothing_enabled;
+ qt_applefontsmoothing_enabled = false;
+#endif
QPainter qp(&d->imagecache[i]->image);
+#ifdef Q_WS_MAC
+ qt_applefontsmoothing_enabled = oldSmooth;
+#endif
qp.setRenderHints(QPainter::HighQualityAntialiasing | QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform, d->smoothCache);
qp.translate(-area.x(), -area.y());
qp.scale(d->contentsScale,d->contentsScale);
@@ -349,7 +358,14 @@ void QDeclarativePaintedItem::paint(QPainter *p, const QStyleOptionGraphicsItem
if (d->fillColor.isValid())
img.fill(d->fillColor);
{
+#ifdef Q_WS_MAC
+ bool oldSmooth = qt_applefontsmoothing_enabled;
+ qt_applefontsmoothing_enabled = false;
+#endif
QPainter qp(&img);
+#ifdef Q_WS_MAC
+ qt_applefontsmoothing_enabled = oldSmooth;
+#endif
qp.setRenderHints(QPainter::HighQualityAntialiasing | QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform, d->smoothCache);
qp.translate(-r.x(),-r.y());
diff --git a/src/declarative/graphicsitems/qdeclarativetext.cpp b/src/declarative/graphicsitems/qdeclarativetext.cpp
index ba4fa21..ec8bfb5 100644
--- a/src/declarative/graphicsitems/qdeclarativetext.cpp
+++ b/src/declarative/graphicsitems/qdeclarativetext.cpp
@@ -57,6 +57,8 @@
QT_BEGIN_NAMESPACE
+extern Q_GUI_EXPORT bool qt_applefontsmoothing_enabled;
+
class QTextDocumentWithImageResources : public QTextDocument {
Q_OBJECT
@@ -714,6 +716,8 @@ QRectF QDeclarativeText::boundingRect() const
// Could include font max left/right bearings to either side of rectangle.
if (d->cache || d->style != Normal) {
+ QDeclarativeTextPrivate *dd = const_cast<QDeclarativeTextPrivate *>(d);
+ dd->checkImgCache();
switch (d->hAlign) {
case AlignLeft:
x = 0;
@@ -1028,7 +1032,14 @@ QPixmap QDeclarativeTextPrivate::wrappedTextImage(bool drawStyle)
QPixmap img(size);
if (!size.isEmpty()) {
img.fill(Qt::transparent);
+#ifdef Q_WS_MAC
+ bool oldSmooth = qt_applefontsmoothing_enabled;
+ qt_applefontsmoothing_enabled = false;
+#endif
QPainter p(&img);
+#ifdef Q_WS_MAC
+ qt_applefontsmoothing_enabled = oldSmooth;
+#endif
drawWrappedText(&p, QPointF(0,0), drawStyle);
}
return img;
@@ -1051,7 +1062,14 @@ QPixmap QDeclarativeTextPrivate::richTextImage(bool drawStyle)
//paint text
QPixmap img(size);
img.fill(Qt::transparent);
+#ifdef Q_WS_MAC
+ bool oldSmooth = qt_applefontsmoothing_enabled;
+ qt_applefontsmoothing_enabled = false;
+#endif
QPainter p(&img);
+#ifdef Q_WS_MAC
+ qt_applefontsmoothing_enabled = oldSmooth;
+#endif
QAbstractTextDocumentLayout::PaintContext context;
diff --git a/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp b/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp
index cfa1c6d..7952b97 100644
--- a/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp
+++ b/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp
@@ -77,7 +77,7 @@ public:
QDeclarativeVisualItemModelPrivate() : QObjectPrivate() {}
static void children_append(QDeclarativeListProperty<QDeclarativeItem> *prop, QDeclarativeItem *item) {
- item->QObject::setParent(prop->object);
+ QDeclarative_setParent_noEvent(item, prop->object);
static_cast<QDeclarativeVisualItemModelPrivate *>(prop->data)->children.append(item);
static_cast<QDeclarativeVisualItemModelPrivate *>(prop->data)->itemAppended();
static_cast<QDeclarativeVisualItemModelPrivate *>(prop->data)->emitChildrenChanged();
@@ -185,9 +185,11 @@ QDeclarativeItem *QDeclarativeVisualItemModel::item(int index, bool)
return d->children.at(index);
}
-QDeclarativeVisualModel::ReleaseFlags QDeclarativeVisualItemModel::release(QDeclarativeItem *)
+QDeclarativeVisualModel::ReleaseFlags QDeclarativeVisualItemModel::release(QDeclarativeItem *item)
{
- // Nothing to do
+ if (item->scene())
+ item->scene()->removeItem(item);
+ QDeclarative_setParent_noEvent(item, this);
return 0;
}
diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp
index f2eb770..d1ba6ce 100644
--- a/src/declarative/qml/qdeclarativeengine.cpp
+++ b/src/declarative/qml/qdeclarativeengine.cpp
@@ -1080,13 +1080,20 @@ Here is an example. Notice it checks whether the component \l{Component::status}
\c Component.Ready before calling \l {Component::createObject()}{createObject()}
in case the QML file is loaded over a network and thus is not ready immediately.
-\snippet doc/src/snippets/declarative/componentCreation.js 0
+\snippet doc/src/snippets/declarative/componentCreation.js vars
\codeline
-\snippet doc/src/snippets/declarative/componentCreation.js 1
+\snippet doc/src/snippets/declarative/componentCreation.js func
+\snippet doc/src/snippets/declarative/componentCreation.js remote
+\snippet doc/src/snippets/declarative/componentCreation.js func-end
+\codeline
+\snippet doc/src/snippets/declarative/componentCreation.js finishCreation
-If you are certain the files will be local, you could simplify to:
+If you are certain the QML file to be loaded is a local file, you could omit the \c finishCreation()
+function and call \l {Component::createObject()}{createObject()} immediately:
-\snippet doc/src/snippets/declarative/componentCreation.js 2
+\snippet doc/src/snippets/declarative/componentCreation.js func
+\snippet doc/src/snippets/declarative/componentCreation.js local
+\snippet doc/src/snippets/declarative/componentCreation.js func-end
To create a QML object from an arbitrary string of QML (instead of a file),
use \l{QML:Qt::createQmlObject()}{Qt.createQmlObject()}.
diff --git a/src/declarative/util/qdeclarativeanimation.cpp b/src/declarative/util/qdeclarativeanimation.cpp
index 88ec5ba..3617031 100644
--- a/src/declarative/util/qdeclarativeanimation.cpp
+++ b/src/declarative/util/qdeclarativeanimation.cpp
@@ -632,17 +632,18 @@ QAbstractAnimation *QDeclarativePauseAnimation::qtAnimation()
\qmlclass ColorAnimation QDeclarativeColorAnimation
\since 4.7
\inherits PropertyAnimation
- \brief The ColorAnimation element allows you to animate color changes.
+ \brief The ColorAnimation element animates changes in color values.
- ColorAnimation defines an animation to be applied when a color value
- changes.
+ ColorAnimation is a specialized PropertyAnimation that defines an
+ animation to be applied when a color value changes.
Here is a ColorAnimation applied to the \c color property of a \l Rectangle
- as a property value source:
+ as a property value source. It animates the \c color property's value from
+ its current value to a value of "red", over 1000 milliseconds:
\snippet doc/src/snippets/declarative/coloranimation.qml 0
- Like any other animation element, a NumberAnimation can be applied in a
+ Like any other animation element, a ColorAnimation can be applied in a
number of ways, including transitions, behaviors and property value
sources. The \l PropertyAnimation documentation shows a variety of methods
for creating animations.
@@ -674,11 +675,12 @@ QDeclarativeColorAnimation::~QDeclarativeColorAnimation()
/*!
\qmlproperty color ColorAnimation::from
- This property holds the starting color.
+ This property holds the color value at which the animation should begin.
For example, the following animation is not applied until a color value
has reached "#c0c0c0":
+ \qml
Item {
states: [ ... ]
@@ -686,6 +688,11 @@ QDeclarativeColorAnimation::~QDeclarativeColorAnimation()
NumberAnimation { from: "#c0c0c0"; duration: 2000 }
}
}
+ \endqml
+
+ If this value is not set and the ColorAnimation is defined within
+ a \l Transition, it defaults to the value defined in the starting
+ state of the \l Transition.
*/
QColor QDeclarativeColorAnimation::from() const
{
@@ -700,7 +707,12 @@ void QDeclarativeColorAnimation::setFrom(const QColor &f)
/*!
\qmlproperty color ColorAnimation::to
- This property holds the ending color.
+
+ This property holds the color value at which the animation should end.
+
+ If this value is not set and the ColorAnimation is defined within
+ a \l Transition or \l Behavior, it defaults to the value defined in the end
+ state of the \l Transition or \l Behavior.
*/
QColor QDeclarativeColorAnimation::to() const
{
@@ -869,18 +881,27 @@ QAbstractAnimation *QDeclarativeScriptAction::qtAnimation()
\inherits Animation
\brief The PropertyAction element allows immediate property changes during animation.
- Explicitly set \c theimage.smooth=true during a transition:
+ PropertyAction is used to specify an immediate property change
+ during an animation. The property change is not animated.
+
+ For example, to explicitly set \c {theImage.smooth = true} during a \l Transition:
\code
- PropertyAction { target: theimage; property: "smooth"; value: true }
+ transitions: Transition {
+ ...
+ PropertyAction { target: theImage; property: "smooth"; value: true }
+ ...
+ }
\endcode
- Set \c thewebview.url to the value set for the destination state:
+ Or, to set \c theWebView.url to the value set for the destination state:
\code
- PropertyAction { target: thewebview; property: "url" }
+ transitions: Transition {
+ ...
+ PropertyAction { target: theWebView; property: "url" }
+ ...
+ }
\endcode
- The PropertyAction is immediate -
- the target property is not animated to the selected value in any way.
\sa QtDeclarative
*/
@@ -906,14 +927,6 @@ void QDeclarativePropertyActionPrivate::init()
QDeclarative_setParent_noEvent(spa, q);
}
-/*!
- \qmlproperty Object PropertyAction::target
- This property holds an explicit target object to animate.
-
- The exact effect of the \c target property depends on how the animation
- is being used. Refer to the \l {QML Animation} documentation for details.
-*/
-
QObject *QDeclarativePropertyAction::target() const
{
Q_D(const QDeclarativePropertyAction);
@@ -945,12 +958,12 @@ void QDeclarativePropertyAction::setProperty(const QString &n)
}
/*!
+ \qmlproperty Object PropertyAction::target
\qmlproperty list<Object> PropertyAction::targets
\qmlproperty string PropertyAction::property
\qmlproperty string PropertyAction::properties
- \qmlproperty Object PropertyAction::target
- These properties are used as a set to determine which properties should be
+ These properties determine the items and their properties that are
affected by this action.
The details of how these properties are interpreted in different situations
@@ -982,7 +995,7 @@ QDeclarativeListProperty<QObject> QDeclarativePropertyAction::targets()
/*!
\qmlproperty list<Object> PropertyAction::exclude
- This property holds the objects not to be affected by this animation.
+ This property holds the objects that should not be affected by this action.
\sa targets
*/
@@ -1117,13 +1130,14 @@ void QDeclarativePropertyAction::transition(QDeclarativeStateActions &actions,
\qmlclass NumberAnimation QDeclarativeNumberAnimation
\since 4.7
\inherits PropertyAnimation
- \brief The NumberAnimation element allows you to animate changes in properties of type qreal.
+ \brief The NumberAnimation element animates changes in qreal-type values.
- NumberAnimation defines an animation to be applied when a numerical value
- changes.
+ NumberAnimation is a specialized PropertyAnimation that defines an
+ animation to be applied when a numerical value changes.
Here is a NumberAnimation applied to the \c x property of a \l Rectangle
- as a property value source:
+ as a property value source. It animates the \c x value from its current
+ value to a value of 50, over 1000 milliseconds:
\snippet doc/src/snippets/declarative/numberanimation.qml 0
@@ -1174,6 +1188,7 @@ void QDeclarativeNumberAnimation::init()
For example, the following animation is not applied until the \c x value
has reached 100:
+ \qml
Item {
states: [ ... ]
@@ -1181,8 +1196,10 @@ void QDeclarativeNumberAnimation::init()
NumberAnimation { properties: "x"; from: 100; duration: 200 }
}
}
+ \endqml
- If this value is not set, it defaults to the value defined in the start
+ If this value is not set and the NumberAnimation is defined within
+ a \l Transition, it defaults to the value defined in the start
state of the \l Transition.
*/
@@ -1201,7 +1218,8 @@ void QDeclarativeNumberAnimation::setFrom(qreal f)
\qmlproperty real NumberAnimation::to
This property holds the ending number value.
- If this value is not set, it defaults to the value defined in the end
+ If this value is not set and the NumberAnimation is defined within
+ a \l Transition or \l Behavior, it defaults to the value defined in the end
state of the \l Transition or \l Behavior.
*/
qreal QDeclarativeNumberAnimation::to() const
@@ -1221,7 +1239,10 @@ void QDeclarativeNumberAnimation::setTo(qreal t)
\qmlclass Vector3dAnimation QDeclarativeVector3dAnimation
\since 4.7
\inherits PropertyAnimation
- \brief The Vector3dAnimation element allows you to animate changes in properties of type QVector3d.
+ \brief The Vector3dAnimation element animates changes in QVector3d values.
+
+ Vector3dAnimation is a specialized PropertyAnimation that defines an
+ animation to be applied when a Vector3d value changes.
\sa {QML Animation}, {declarative/animation/basics}{Animation basics example}
*/
@@ -1286,31 +1307,32 @@ void QDeclarativeVector3dAnimation::setTo(QVector3D t)
\qmlclass RotationAnimation QDeclarativeRotationAnimation
\since 4.7
\inherits PropertyAnimation
- \brief The RotationAnimation element allows you to animate rotations.
+ \brief The RotationAnimation element animates changes in rotation values.
RotationAnimation is a specialized PropertyAnimation that gives control
- over the direction of rotation. By default, it will rotate in the direction
+ over the direction of rotation during an animation.
+
+ By default, it rotates in the direction
of the numerical change; a rotation from 0 to 240 will rotate 220 degrees
clockwise, while a rotation from 240 to 0 will rotate 220 degrees
- counterclockwise.
+ counterclockwise. The \l direction property can be set to specify the
+ direction in which the rotation should occur.
+
+ In the following example we use RotationAnimation to animate the rotation
+ between states via the shortest path:
- When used in a transition RotationAnimation will rotate all
+ \snippet doc/src/snippets/declarative/rotationanimation.qml 0
+
+ Notice the RotationAnimation did not need to set a \l {RotationAnimation::}{target}
+ value. As a convenience, when used in a transition, RotationAnimation will rotate all
properties named "rotation" or "angle". You can override this by providing
your own properties via \l {PropertyAnimation::properties}{properties} or
\l {PropertyAnimation::property}{property}.
- In the following example we use RotationAnimation to animate the rotation
- between states via the shortest path.
- \qml
- states: {
- State { name: "180"; PropertyChanges { target: myItem; rotation: 180 } }
- State { name: "90"; PropertyChanges { target: myItem; rotation: 90 } }
- State { name: "-90"; PropertyChanges { target: myItem; rotation: -90 } }
- }
- transition: Transition {
- RotationAnimation { direction: RotationAnimation.Shortest }
- }
- \endqml
+ Like any other animation element, a RotationAnimation can be applied in a
+ number of ways, including transitions, behaviors and property value
+ sources. The \l PropertyAnimation documentation shows a variety of methods
+ for creating animations.
\sa {QML Animation}, {declarative/animation/basics}{Animation basics example}
*/
@@ -1377,6 +1399,7 @@ QDeclarativeRotationAnimation::~QDeclarativeRotationAnimation()
For example, the following animation is not applied until the \c angle value
has reached 100:
+ \qml
Item {
states: [ ... ]
@@ -1384,6 +1407,7 @@ QDeclarativeRotationAnimation::~QDeclarativeRotationAnimation()
RotationAnimation { properties: "angle"; from: 100; duration: 2000 }
}
}
+ \endqml
If this value is not set, it defaults to the value defined in the start
state of the \l Transition.
@@ -1419,7 +1443,7 @@ void QDeclarativeRotationAnimation::setTo(qreal t)
/*!
\qmlproperty enumeration RotationAnimation::direction
- The direction in which to rotate.
+ This property holds the direction of the rotation.
Possible values are:
@@ -1512,19 +1536,26 @@ QDeclarativeListProperty<QDeclarativeAbstractAnimation> QDeclarativeAnimationGro
\qmlclass SequentialAnimation QDeclarativeSequentialAnimation
\since 4.7
\inherits Animation
- \brief The SequentialAnimation element allows you to run animations sequentially.
+ \brief The SequentialAnimation element allows animations to be run sequentially.
- Animations controlled in SequentialAnimation will be run one after the other.
+ The SequentialAnimation and ParallelAnimation elements allow multiple
+ animations to be run together. Animations defined in a SequentialAnimation
+ are run one after the other, while animations defined in a ParallelAnimation
+ are run at the same time.
- The following example chains two numeric animations together. The \c MyItem
- object will animate from its current x position to 100, and then back to 0.
+ The following example runs two number animations in a sequence. The \l Rectangle
+ animates to a \c x position of 50, then to a \c y position of 50.
- \code
- SequentialAnimation {
- NumberAnimation { target: MyItem; property: "x"; to: 100 }
- NumberAnimation { target: MyItem; property: "x"; to: 0 }
- }
- \endcode
+ \snippet doc/src/snippets/declarative/sequentialanimation.qml 0
+
+ Animations defined within a \l Transition are automatically run in parallel,
+ so SequentialAnimation can be used to enclose the animations in a \l Transition
+ if this is the preferred behavior.
+
+ Like any other animation element, a SequentialAnimation can be applied in a
+ number of ways, including transitions, behaviors and property value
+ sources. The \l PropertyAnimation documentation shows a variety of methods
+ for creating animations.
\sa ParallelAnimation, {QML Animation}, {declarative/animation/basics}{Animation basics example}
*/
@@ -1574,19 +1605,22 @@ void QDeclarativeSequentialAnimation::transition(QDeclarativeStateActions &actio
\qmlclass ParallelAnimation QDeclarativeParallelAnimation
\since 4.7
\inherits Animation
- \brief The ParallelAnimation element allows you to run animations in parallel.
+ \brief The ParallelAnimation element allows animations to be run in parallel.
- Animations contained in ParallelAnimation will be run at the same time.
+ The SequentialAnimation and ParallelAnimation elements allow multiple
+ animations to be run together. Animations defined in a SequentialAnimation
+ are run one after the other, while animations defined in a ParallelAnimation
+ are run at the same time.
- The following animation demonstrates animating the \c MyItem item
- to (100,100) by animating the x and y properties in parallel.
+ The following animation runs two number animations in parallel. The \l Rectangle
+ moves to (50,50) by animating its \c x and \c y properties at the same time.
- \code
- ParallelAnimation {
- NumberAnimation { target: MyItem; property: "x"; to: 100 }
- NumberAnimation { target: MyItem; property: "y"; to: 100 }
- }
- \endcode
+ \snippet doc/src/snippets/declarative/parallelanimation.qml 0
+
+ Like any other animation element, a ParallelAnimation can be applied in a
+ number of ways, including transitions, behaviors and property value
+ sources. The \l PropertyAnimation documentation shows a variety of methods
+ for creating animations.
\sa SequentialAnimation, {QML Animation}, {declarative/animation/basics}{Animation basics example}
*/
@@ -1685,7 +1719,7 @@ void QDeclarativePropertyAnimationPrivate::convertVariant(QVariant &variant, int
\qmlclass PropertyAnimation QDeclarativePropertyAnimation
\since 4.7
\inherits Animation
- \brief The PropertyAnimation element allows you to animate property changes.
+ \brief The PropertyAnimation element animates changes in property values.
PropertyAnimation provides a way to animate changes to a property's value.
@@ -2353,43 +2387,30 @@ void QDeclarativePropertyAnimation::transition(QDeclarativeStateActions &actions
\qmlclass ParentAnimation QDeclarativeParentAnimation
\since 4.7
\inherits Animation
- \brief The ParentAnimation element allows you to animate parent changes.
+ \brief The ParentAnimation element animates changes in parent values.
- ParentAnimation is used in conjunction with NumberAnimation to smoothly
- animate changing an item's parent. In the following example,
- ParentAnimation wraps a NumberAnimation which animates from the
- current position in the old parent to the new position in the new
- parent.
+ ParentAnimation defines an animation to applied when a ParentChange
+ occurs. This allows parent changes to be smoothly animated.
- \qml
- ...
- State {
- //reparent myItem to newParent. myItem's final location
- //should be 10,10 in newParent.
- ParentChange {
- target: myItem
- parent: newParent
- x: 10; y: 10
- }
- }
- ...
- Transition {
- //smoothly reparent myItem and move into new position
- ParentAnimation {
- target: theItem
- NumberAnimation { properties: "x,y" }
- }
- }
- \endqml
+ For example, the following ParentChange changes \c blueRect to become
+ a child of \c redRect when it is clicked. The inclusion of the
+ ParentAnimation, which defines a NumberAnimation to be applied during
+ the transition, ensures the item animates smoothly as it moves to
+ its new parent:
+
+ \snippet doc/src/snippets/declarative/parentanimation.qml 0
- ParentAnimation can wrap any number of animations -- those animations will
- be run in parallel (like those in a ParallelAnimation group).
+ A ParentAnimation can contain any number of animations. These animations will
+ be run in parallel; to run them sequentially, define them within a
+ SequentialAnimation.
- In some cases, such as reparenting between items with clipping, it's useful
- to animate the parent change via another item with no clipping.
+ In some cases, such as when reparenting between items with clipping enabled, it is useful
+ to animate the parent change via another item that does not have clipping
+ enabled. Such an item can be set using the \l via property.
- When used in a transition, ParentAnimation will by default animate
- all ParentChanges.
+ By default, when used in a transition, ParentAnimation animates all parent
+ changes. This can be overriden by setting a specific target item using the
+ \l target property.
\sa {QML Animation}, {declarative/animation/basics}{Animation basics example}
*/
@@ -2426,8 +2447,8 @@ QDeclarativeParentAnimation::~QDeclarativeParentAnimation()
\qmlproperty Item ParentAnimation::target
The item to reparent.
- When used in a transition, if no target is specified all
- ParentChanges will be animated by the ParentAnimation.
+ When used in a transition, if no target is specified, all
+ ParentChange occurrences are animated by the ParentAnimation.
*/
QDeclarativeItem *QDeclarativeParentAnimation::target() const
{
@@ -2470,7 +2491,7 @@ void QDeclarativeParentAnimation::setNewParent(QDeclarativeItem *newParent)
/*!
\qmlproperty Item ParentAnimation::via
The item to reparent via. This provides a way to do an unclipped animation
- when both the old parent and new parent are clipped
+ when both the old parent and new parent are clipped.
\qml
ParentAnimation {
@@ -2720,28 +2741,14 @@ QAbstractAnimation *QDeclarativeParentAnimation::qtAnimation()
\qmlclass AnchorAnimation QDeclarativeAnchorAnimation
\since 4.7
\inherits Animation
- \brief The AnchorAnimation element allows you to animate anchor changes.
+ \brief The AnchorAnimation element animates changes in anchor values.
- AnchorAnimation will animated any changes specified by a state's AnchorChanges.
- In the following snippet we animate the addition of a right anchor to our item.
- \qml
- Item {
- id: myItem
- width: 100
- }
- ...
- State {
- AnchorChanges {
- target: myItem
- anchors.right: container.right
- }
- }
- ...
- Transition {
- //smoothly reanchor myItem and move into new position
- AnchorAnimation {}
- }
- \endqml
+ AnchorAnimation is used to animate an AnchorChange. It will anchor all
+ anchor changes specified in a \l State.
+
+ In the following snippet we animate the addition of a right anchor to a \l Rectangle:
+
+ \snippet doc/src/snippets/declarative/anchoranimation.qml 0
\sa AnchorChanges
*/
diff --git a/src/declarative/util/qdeclarativebehavior.cpp b/src/declarative/util/qdeclarativebehavior.cpp
index 2bb28c3..3719085 100644
--- a/src/declarative/util/qdeclarativebehavior.cpp
+++ b/src/declarative/util/qdeclarativebehavior.cpp
@@ -75,28 +75,21 @@ public:
\since 4.7
\brief The Behavior element allows you to specify a default animation for a property change.
- Behaviors provide one way to specify \l{qdeclarativeanimation.html}{animations} in QML.
-
- In the example below, the rectangle will use a bounce easing curve over 200 millisecond for any changes to its y property:
- \code
- Rectangle {
- width: 20; height: 20
- color: "#00ff00"
- y: 200 // initial value
- Behavior on y {
- NumberAnimation {
- easing.type: Easing.OutBounce
- easing.amplitude: 100
- duration: 200
- }
- }
- }
- \endcode
+ A Behavior defines the default animation to be applied whenever a
+ particular property value changes.
+
+ For example, the following Behavior defines a NumberAnimation to be run
+ whenever the \l Rectangle's \c width value changes. When the MouseArea
+ is clicked, the \c width is changed, triggering the behavior's animation:
+
+ \snippet doc/src/snippets/declarative/behavior.qml 0
- Currently only a single Behavior may be specified for a property;
- this Behavior can be enabled and disabled via the \l{enabled} property.
+ To run multiple animations within a Behavior, use ParallelAnimation or
+ SequentialAnimation.
- \sa {declarative/animation/behaviors}{Behavior example}, QtDeclarative
+ Note that a property cannot have more than one assigned Behavior.
+
+ \sa {Property Behaviors}, {declarative/animation/behaviors}{Behavior example}, QtDeclarative
*/
@@ -113,7 +106,7 @@ QDeclarativeBehavior::~QDeclarativeBehavior()
\qmlproperty Animation Behavior::animation
\default
- The animation to use when the behavior is triggered.
+ This property holds the animation to run when the behavior is triggered.
*/
QDeclarativeAbstractAnimation *QDeclarativeBehavior::animation()
@@ -152,7 +145,9 @@ void QDeclarativeBehavior::qtAnimationStateChanged(QAbstractAnimation::State new
/*!
\qmlproperty bool Behavior::enabled
- Whether the Behavior will be triggered when the property it is tracking changes.
+
+ This property holds whether the behavior will be triggered when the tracked
+ property changes value.
By default a Behavior is enabled.
*/
diff --git a/src/declarative/util/qdeclarativesmoothedanimation.cpp b/src/declarative/util/qdeclarativesmoothedanimation.cpp
index e0d1097..11c3d4b 100644
--- a/src/declarative/util/qdeclarativesmoothedanimation.cpp
+++ b/src/declarative/util/qdeclarativesmoothedanimation.cpp
@@ -253,15 +253,22 @@ void QSmoothedAnimation::init()
\inherits NumberAnimation
\brief The SmoothedAnimation element allows a property to smoothly track a value.
- The SmoothedAnimation 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
+ A SmoothedAnimation animates a property's value to a set target value
+ using an ease in/out quad easing curve. When the target value changes,
+ the easing curves used to animate between the old and new target values
+ are smoothly spliced together to create a smooth movement to the new
+ target value that maintains the current velocity.
+
+ The follow example shows one \l Rectangle tracking the position of another
+ using SmoothedAnimation. The green rectangle's \c x and \c y values are
+ bound to those of the red rectangle. Whenever these values change, the
+ green rectangle smoothly animates to its new position:
+
+ \snippet doc/src/snippets/declarative/smoothedanimation.qml 0
+
+ A SmoothedAnimation can be configured by setting the \l velocity at which the
+ animation should occur, or the \l duration that the animation should take.
+ If both the \l velocity and \l 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
@@ -271,10 +278,6 @@ void QSmoothedAnimation::init()
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.
-
- \snippet doc/src/snippets/declarative/smoothedanimation.qml 0
-
The default velocity of SmoothedAnimation 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.
@@ -287,7 +290,7 @@ void QSmoothedAnimation::init()
sources. The \l PropertyAnimation documentation shows a variety of methods
for creating animations.
- \sa {QML Animation}, {declarative/animation/basics}{Animation basics example}
+ \sa SpringAnimation, NumberAnimation, {QML Animation}, {declarative/animation/basics}{Animation basics example}
*/
QDeclarativeSmoothedAnimation::QDeclarativeSmoothedAnimation(QObject *parent)
diff --git a/src/declarative/util/qdeclarativespringanimation.cpp b/src/declarative/util/qdeclarativespringanimation.cpp
index be0af6d..8ce4832 100644
--- a/src/declarative/util/qdeclarativespringanimation.cpp
+++ b/src/declarative/util/qdeclarativespringanimation.cpp
@@ -215,7 +215,9 @@ void QDeclarativeSpringAnimationPrivate::updateMode()
You can also limit the maximum \l velocity of the animation.
The following \l Rectangle moves to the position of the mouse using a
- SpringAnimation when the mouse is clicked:
+ SpringAnimation when the mouse is clicked. The use of the \l Behavior
+ on the \c x and \c y values indicates that whenever these values are
+ changed, a SpringAnimation should be applied.
\snippet doc/src/snippets/declarative/springanimation.qml 0
@@ -224,7 +226,7 @@ void QDeclarativeSpringAnimationPrivate::updateMode()
sources. The \l PropertyAnimation documentation shows a variety of methods
for creating animations.
- \sa {QML Animation}, {declarative/animation/basics}{Animation basics example}, {declarative/toys/clocks}{Clocks example}
+ \sa SmoothedAnimation, {QML Animation}, {declarative/animation/basics}{Animation basics example}, {declarative/toys/clocks}{Clocks example}
*/
QDeclarativeSpringAnimation::QDeclarativeSpringAnimation(QObject *parent)
@@ -284,8 +286,8 @@ qreal QDeclarativeSpringAnimation::from() const
This property holds the value from which the animation will begin.
- If not set, the animation will start regardless of the
- value being tracked.
+ If not set, the animation will start whenever the tracked value has
+ changed, regardless of its value.
*/
void QDeclarativeSpringAnimation::setFrom(qreal value)
@@ -303,7 +305,10 @@ void QDeclarativeSpringAnimation::setFrom(qreal value)
/*!
\qmlproperty real SpringAnimation::velocity
+
This property holds the maximum velocity allowed when tracking the source.
+
+ The default value is 0 (no maximum velocity).
*/
qreal QDeclarativeSpringAnimation::velocity() const
@@ -322,13 +327,14 @@ void QDeclarativeSpringAnimation::setVelocity(qreal velocity)
/*!
\qmlproperty real SpringAnimation::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
+ This property describes how strongly the target is pulled towards the
+ source. The default value is 0 (that is, the spring-like motion is disabled).
+
+ The useful value range is 0 - 5.0.
- When a spring constant is set and the velocity property is greater than 0,
- velocity limits the maximum speed.
+ When this property is set and the \l velocity value is greater than 0,
+ the \l velocity limits the maximum speed.
*/
qreal QDeclarativeSpringAnimation::spring() const
{
@@ -347,10 +353,11 @@ void QDeclarativeSpringAnimation::setSpring(qreal spring)
\qmlproperty real SpringAnimation::damping
This property holds the spring damping value.
- This value describes how quickly a sprung follower comes to rest.
+ This value describes how quickly the spring-like motion comes to rest.
+ The default value is 0.
- The useful range is 0 - 1.0. The lower the value, the faster the
- follower comes to rest.
+ The useful value range is 0 - 1.0. The lower the value, the faster it
+ comes to rest.
*/
qreal QDeclarativeSpringAnimation::damping() const
{
@@ -392,7 +399,7 @@ void QDeclarativeSpringAnimation::setEpsilon(qreal epsilon)
/*!
\qmlproperty real SpringAnimation::modulus
- This property holds the modulus value.
+ This property holds the modulus value. The default value is 0.
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.
@@ -417,8 +424,10 @@ void QDeclarativeSpringAnimation::setModulus(qreal modulus)
\qmlproperty real SpringAnimation::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.
+ The value is 1.0 by default.
+
+ A greater mass causes slower movement and a greater spring-like
+ motion when an item comes to rest.
*/
qreal QDeclarativeSpringAnimation::mass() const
{
diff --git a/src/declarative/util/qdeclarativetransition.cpp b/src/declarative/util/qdeclarativetransition.cpp
index 6b7418e..6561b8c 100644
--- a/src/declarative/util/qdeclarativetransition.cpp
+++ b/src/declarative/util/qdeclarativetransition.cpp
@@ -66,8 +66,6 @@ QT_BEGIN_NAMESPACE
\snippet doc/src/snippets/declarative/transition.qml 0
- Items can have multiple transitions, if
-
To specify multiple transitions, specify \l Item::transitions as a list:
\qml
diff --git a/tests/auto/declarative/qdeclarativerepeater/data/itemlist.qml b/tests/auto/declarative/qdeclarativerepeater/data/itemlist.qml
index e8dd8cc..4810736 100644
--- a/tests/auto/declarative/qdeclarativerepeater/data/itemlist.qml
+++ b/tests/auto/declarative/qdeclarativerepeater/data/itemlist.qml
@@ -4,21 +4,27 @@
import Qt 4.7
Rectangle {
+ id: root
color: "lightgray"
width: 240
height: 320
+ property variant itemModel: itemModel1
function checkProperties() {
testObject.error = false;
- if (testObject.useModel && view.model != itemModel) {
+ if (testObject.useModel && view.model != root.itemModel) {
console.log("model property incorrect");
testObject.error = true;
}
}
+ function switchModel() {
+ root.itemModel = itemModel2
+ }
+
VisualItemModel {
- id: itemModel
- objectName: "itemModel"
+ id: itemModel1
+ objectName: "itemModel1"
Rectangle {
objectName: "item1"
height: 50; width: 100; color: "#FFFEF0"
@@ -36,12 +42,27 @@ Rectangle {
}
}
+ VisualItemModel {
+ id: itemModel2
+ objectName: "itemModel2"
+ Rectangle {
+ objectName: "item4"
+ height: 50; width: 100; color: "#FFFEF0"
+ Text { objectName: "text4"; text: "index: " + parent.VisualItemModel.index; font.bold: true; anchors.centerIn: parent }
+ }
+ Rectangle {
+ objectName: "item5"
+ height: 50; width: 100; color: "#F0FFF7"
+ Text { objectName: "text5"; text: "index: " + parent.VisualItemModel.index; font.bold: true; anchors.centerIn: parent }
+ }
+ }
+
Column {
objectName: "container"
Repeater {
id: view
objectName: "repeater"
- model: testObject.useModel ? itemModel : 0
+ model: testObject.useModel ? root.itemModel : 0
}
}
}
diff --git a/tests/auto/declarative/qdeclarativerepeater/tst_qdeclarativerepeater.cpp b/tests/auto/declarative/qdeclarativerepeater/tst_qdeclarativerepeater.cpp
index 7299a43..623b3d7 100644
--- a/tests/auto/declarative/qdeclarativerepeater/tst_qdeclarativerepeater.cpp
+++ b/tests/auto/declarative/qdeclarativerepeater/tst_qdeclarativerepeater.cpp
@@ -361,6 +361,15 @@ void tst_QDeclarativeRepeater::itemModel()
QVERIFY(qobject_cast<QObject*>(container->childItems().at(2))->objectName() == "item3");
QVERIFY(container->childItems().at(3) == repeater);
+ QMetaObject::invokeMethod(canvas->rootObject(), "switchModel");
+ QCOMPARE(container->childItems().count(), 3);
+ QVERIFY(qobject_cast<QObject*>(container->childItems().at(0))->objectName() == "item4");
+ QVERIFY(qobject_cast<QObject*>(container->childItems().at(1))->objectName() == "item5");
+ QVERIFY(container->childItems().at(2) == repeater);
+
+ testObject->setUseModel(false);
+ QCOMPARE(container->childItems().count(), 1);
+
delete testObject;
delete canvas;
}
diff --git a/tests/auto/declarative/qdeclarativetext/tst_qdeclarativetext.cpp b/tests/auto/declarative/qdeclarativetext/tst_qdeclarativetext.cpp
index 80198eb..53862ec 100644
--- a/tests/auto/declarative/qdeclarativetext/tst_qdeclarativetext.cpp
+++ b/tests/auto/declarative/qdeclarativetext/tst_qdeclarativetext.cpp
@@ -246,6 +246,7 @@ void tst_qdeclarativetext::width()
QDeclarativeText *textObject = qobject_cast<QDeclarativeText*>(textComponent.create());
QVERIFY(textObject != 0);
+ QVERIFY(textObject->boundingRect().width() > 0);
QCOMPARE(textObject->width(), qreal(metricWidth));
QVERIFY(textObject->textFormat() == QDeclarativeText::AutoText); // setting text doesn't change format
}