diff options
author | Qt Continuous Integration System <qt-info@nokia.com> | 2010-07-21 21:40:46 (GMT) |
---|---|---|
committer | Qt Continuous Integration System <qt-info@nokia.com> | 2010-07-21 21:40:46 (GMT) |
commit | 91215b48022b3b3980960f1b5f301ac84f14d49d (patch) | |
tree | c71963ebb5270b0f8a85177c22377b7e625fb994 /doc | |
parent | 07f131927faa09402589da7b4bfb516482f59e46 (diff) | |
parent | b05e07835c376857da0a0f9cb85bbab001f145dd (diff) | |
download | Qt-91215b48022b3b3980960f1b5f301ac84f14d49d.zip Qt-91215b48022b3b3980960f1b5f301ac84f14d49d.tar.gz Qt-91215b48022b3b3980960f1b5f301ac84f14d49d.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: (26 commits)
Expand QDeclarativeExtensionPlugin docs
Add missing snippet files
Expand QtObject doc
Indicate default values
Use snippets instead to avoid quoting license headers
Rename remaining 'wantsFocus'.
Bounding rect of text was not always calculated correctly.
Add QML tutorials to the tutorials page
QML focus API updates.
Do not show copyright header in documentation.
Ensure redirects (and indeed all reply process) is done in the right thread.
Only ignore the same target value for a Behavior when it is running.
Fix clock example: make sure hands always moves forward.
font.letterSpacing used percentage rather than absolute values.
Rewinding AnchorChanges should not make target item's implicit width and height explicit
Compile: include <float.h> for usage of FLT_MAX.
Restore the FLT_MAX define.
Make Item::transformOriginPoint read-only
Ensure the boundingRect() of Text is correctly calculated.
Better defaults for MouseArea's drag.
...
Diffstat (limited to 'doc')
18 files changed, 562 insertions, 80 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/declarative/focus.qdoc b/doc/src/declarative/focus.qdoc index 0dd5eb3..e3ca963 100644 --- a/doc/src/declarative/focus.qdoc +++ b/doc/src/declarative/focus.qdoc @@ -73,12 +73,12 @@ See also the \l {Keys}{Keys attached property} and \l {KeyNavigation}{KeyNavigat \section1 Querying the Active Focus Item Whether or not an \l Item has \e {active focus} can be queried through the -property \c {Item::focus}. For example, here we have a \l Text +property \c {Item::activeFocus}. For example, here we have a \l Text element whose text is determined by whether or not it has \e {active focus}. \code Text { - text: focus ? "I have active focus!" : "I do not have active focus" + text: activeFocus ? "I have active focus!" : "I do not have active focus" } \endcode @@ -174,7 +174,7 @@ Rectangle { The right hand side of the example shows the expanded code - the equivalent QML without the use of the component \c {MyWidget}. From this, the problem is evident - there are no less than three elements that have the \c {Item::focus} -property set to true. Ultimately only one element can have focus, and the +property set to true. Ultimately only one element can have keyboard focus, and the system has to decide which on. In this case the first appearance of the \c {Item::focus} property being set to true on line 4 is selected, and the value of \c {Item::focus} in the other two instances is reverted back to false. This @@ -233,7 +233,7 @@ and the others are unset, just like when there are no \e {focus scopes}. \o When a \e {focus scope} receives \e {active focus}, the contained element with \c {Item::focus} set (if any) also gets \e {active focus}. If this element is also a \l FocusScope, the proxying behaviour continues. Both the -\e {focus scope} and the sub-focused item will have \c {Item::focus} set. +\e {focus scope} and the sub-focused item will have \c {Item::activeFocus} set. \endlist So far the example has the second component statically selected. It is trivial diff --git a/doc/src/declarative/qdeclarativeintro.qdoc b/doc/src/declarative/qdeclarativeintro.qdoc index 3f1b184..75055d8 100644 --- a/doc/src/declarative/qdeclarativeintro.qdoc +++ b/doc/src/declarative/qdeclarativeintro.qdoc @@ -129,7 +129,7 @@ Commenting in QML is similar to JavaScript. \o Multiline comments start with /* and finish with *\/ \endlist -\quotefile doc/src/snippets/declarative/comments.qml +\snippet doc/src/snippets/declarative/comments.qml 0 Comments are ignored by the engine. They are useful for explaining what you are doing; for referring back to at a later date, or for others reading diff --git a/doc/src/getting-started/tutorials.qdoc b/doc/src/getting-started/tutorials.qdoc index 0a83170..46a5808 100644 --- a/doc/src/getting-started/tutorials.qdoc +++ b/doc/src/getting-started/tutorials.qdoc @@ -84,6 +84,18 @@ \o \row + \o{2,1} \l{QML Tutorial}{\bold QML Tutorial} + \o{2,1} \l{QML Advanced Tutorial}{\bold SameGame} + \row + \o{2,1} + This tutorial provides a very basic introduction to QML. + \o \image qml-samegame-demo-small.png Samegame + \o + This tutorial walks through creating a complete application with QML, + in this case a simple game. It is recommended that you complete the basic QML + tutorial first. + + \row \o{2,1} \l{QTestLib Tutorial}{\bold QTestLib} \o{2,1} \l{qmake Tutorial}{\bold qmake} \row diff --git a/doc/src/snippets/declarative/anchoranimation.qml b/doc/src/snippets/declarative/anchoranimation.qml new file mode 100644 index 0000000..6c7aaf6 --- /dev/null +++ b/doc/src/snippets/declarative/anchoranimation.qml @@ -0,0 +1,65 @@ +/**************************************************************************** +** +** 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:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ +//![0] +import Qt 4.7 + +Item { + id: container + width: 200; height: 200 + + Rectangle { + id: myRect + width: 100; height: 100 + color: "red" + } + + states: State { + name: "reanchored" + AnchorChanges { target: myRect; anchors.right: container.right } + } + + transitions: Transition { + // smoothly reanchor myRect and move into new position + AnchorAnimation { duration: 1000 } + } + + Component.onCompleted: container.state = "reanchored" +} +//![0] 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/comments.qml b/doc/src/snippets/declarative/comments.qml index f4bedb8..9be0ce5 100644 --- a/doc/src/snippets/declarative/comments.qml +++ b/doc/src/snippets/declarative/comments.qml @@ -38,8 +38,10 @@ ** ****************************************************************************/ +//![0] import Qt 4.7 +//![0] Text { text: "Hello world!" //a basic greeting /* @@ -49,3 +51,4 @@ Text { font.family: "Helvetica" font.pointSize: 24 } +//![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/parentanimation.qml b/doc/src/snippets/declarative/parentanimation.qml new file mode 100644 index 0000000..7f11a43 --- /dev/null +++ b/doc/src/snippets/declarative/parentanimation.qml @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** 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: 200; height: 100 + + Rectangle { + id: redRect + width: 100; height: 100 + color: "red" + } + + Rectangle { + id: blueRect + x: redRect.width + width: 50; height: 50 + color: "blue" + + states: State { + name: "reparented" + ParentChange { target: blueRect; parent: redRect; x: 10; y: 10 } + } + + transitions: Transition { + ParentAnimation { + NumberAnimation { properties: "x,y"; duration: 1000 } + } + } + + MouseArea { anchors.fill: parent; onClicked: blueRect.state = "reparented" } + } +} +//![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/qtobject.qml b/doc/src/snippets/declarative/qtobject.qml new file mode 100644 index 0000000..970fa16 --- /dev/null +++ b/doc/src/snippets/declarative/qtobject.qml @@ -0,0 +1,55 @@ +/**************************************************************************** +** +** 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 { + QtObject { + id: attributes + property string name + property int size + property variant attributes + } + + Text { text: attributes.name } +} +//![0] + 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 } } } |