summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron Kennedy <aaron.kennedy@nokia.com>2009-10-22 06:51:34 (GMT)
committerAaron Kennedy <aaron.kennedy@nokia.com>2009-10-22 06:51:34 (GMT)
commit2b1438567cd570f02e70486f7fa173b11b571843 (patch)
tree72c77190a4a581748926308563a44d067ca8d6fb
parent1ec93e68c36902a14545fc02af80821131c52d57 (diff)
parente45f70af3270bd756cef872e5b3ebc00ef9db838 (diff)
downloadQt-2b1438567cd570f02e70486f7fa173b11b571843.zip
Qt-2b1438567cd570f02e70486f7fa173b11b571843.tar.gz
Qt-2b1438567cd570f02e70486f7fa173b11b571843.tar.bz2
Merge branch 'kinetic-declarativeui' of git@scm.dev.nokia.troll.no:qt/kinetic into kinetic-declarativeui
-rw-r--r--demos/declarative/samegame/content/BoomBlock.qml2
-rw-r--r--doc/src/declarative/animation.qdoc157
-rw-r--r--doc/src/declarative/qmlreference.qdoc10
-rw-r--r--doc/src/declarative/qmlstates.qdoc59
-rw-r--r--doc/src/declarative/qtdeclarative.qdoc1
-rw-r--r--examples/declarative/animation/color-animation.qml21
-rw-r--r--examples/declarative/behaviours/SideRect.qml17
-rw-r--r--examples/declarative/behaviours/behavior.qml72
-rw-r--r--examples/declarative/behaviours/test.qml38
-rw-r--r--src/declarative/extra/qmldatetimeformatter.cpp4
-rw-r--r--src/declarative/extra/qmlfontloader.cpp12
-rw-r--r--src/declarative/extra/qmlnumberformatter.cpp4
-rw-r--r--src/declarative/extra/qmlxmllistmodel.cpp4
-rw-r--r--src/declarative/fx/qfxanchors.cpp8
-rw-r--r--src/declarative/fx/qfxgridview.cpp59
-rw-r--r--src/declarative/fx/qfxitem.cpp47
-rw-r--r--src/declarative/fx/qfxlistview.cpp28
-rw-r--r--src/declarative/fx/qfxloader.cpp10
-rw-r--r--src/declarative/qml/qmlcomponent.cpp6
-rw-r--r--src/declarative/qml/qmldom.cpp8
-rw-r--r--src/declarative/qml/qmlengine.cpp4
-rw-r--r--src/declarative/qml/qmlexpression.cpp4
-rw-r--r--src/declarative/util/qmlanimation.cpp8
-rw-r--r--src/declarative/util/qmleasefollow.cpp14
-rw-r--r--src/declarative/util/qmllistmodel.cpp16
-rw-r--r--src/declarative/util/qmlspringfollow.cpp10
-rw-r--r--src/declarative/util/qmlsystempalette.cpp6
-rw-r--r--src/declarative/util/qmltimer.cpp4
-rw-r--r--tests/auto/declarative/qmlecmascript/data/TypeForDynamicCreation.qml2
-rw-r--r--tests/auto/declarative/qmlecmascript/data/dynamicCreation.qml5
-rw-r--r--tests/auto/declarative/qmlecmascript/tst_qmlecmascript.cpp29
-rw-r--r--tools/qmlviewer/qmlviewer.cpp4
32 files changed, 479 insertions, 194 deletions
diff --git a/demos/declarative/samegame/content/BoomBlock.qml b/demos/declarative/samegame/content/BoomBlock.qml
index a495cd0..34f6f56 100644
--- a/demos/declarative/samegame/content/BoomBlock.qml
+++ b/demos/declarative/samegame/content/BoomBlock.qml
@@ -21,7 +21,7 @@ Item { id:block
}
}
opacity: 0
- opacity: Behavior { NumberAnimation { properties:"opacity"; duration: 200 } }
+ opacity: Behavior { NumberAnimation { duration: 200 } }
anchors.fill: parent
}
diff --git a/doc/src/declarative/animation.qdoc b/doc/src/declarative/animation.qdoc
index caf78d3..2d98322 100644
--- a/doc/src/declarative/animation.qdoc
+++ b/doc/src/declarative/animation.qdoc
@@ -44,35 +44,26 @@
\target qmlanimation
\title QML Animation
-QML supports three different forms of animation - basic property animation,
-states and transitions and property behaviors.
+Animation in QML is done by animating properties of objects. Properties of type
+real, int, color, rect, point, and size can all be animated.
-\section1 Property Animation
+QML supports three different forms of animation - basic property animation,
+transitions, and property behaviors.
-Animation in QML is done by animating properties of objects.
+\section1 Basic Property Animation
-Any property of a recognizable type can be animated. Currently those types include:
-\list
-\o qreal
-\o int
-\o Most of QVariant's built-in types
-\endlist
+The simplest form of animation is directly using \l PropertyAnimation, which can animate all of the property
+types listed above. If the property you are animating is a number or color, you can alternatively use
+NumberAnimation or ColorAnimation. These elements don't add any additional functionality,
+but will help enforce type correctness and are slightly more efficient.
-Animations can also involve numerous properties on numerous objects.
-
-Other Features:
-\list
-\o Support for a large set of parameterized easing curves. (based on the Penner easing equations)
-\o Animation synchronization
-\endlist
-
-The simplest form of animation is using \l NumberAnimation
+A property animation can be specified as a value source. This is especially useful for repeating animations.
The following example creates a bouncing effect:
-\code
+\qml
Rectangle {
id: rect
- width: 120; height: 200; color: "white"
+ width: 120; height: 200;
Image {
id: img
source: "qt-logo.png"
@@ -87,64 +78,37 @@ Rectangle {
}
}
}
-\endcode
+\endqml
\image propanim.gif
-\target states-transitions
-\section1 States and Transitions
-
-\section2 States
-
-QML states describe user interface configurations, including:
-\list
-\o What UI elements are present
-\o The properties of those elements (including how they behave)
-\o What actions are available
-\endlist
-
-A state can also be thought of as a set of batched changes from a default configuration.
-
-Examples of states in modern UI:
-\list
-\o A Contacts application has a 'View Contact' state and an 'Edit Contact' State. In the first state the information presented is static (using labels), and in the second it is editable (using editors).
-\o A button has a pressed and unpressed state. When pressed the text moves down and to the right, and the button has a slightly darker appearance.
-\endlist
-
-In QML:
-\list
-\o Any object can use states.
-\o There is a default state. The default state can be explicitly set.
-\o A state can affect other the properties of other objects, not just the object owning the state (and not just that object's children).
-\endlist
-
-The following example shows a simple use of states. In the default state \c myrect is positioned at 0,0. In the 'moved' state it is positioned at 50,50.
+A property animation can also be specified as a resource that is manipulated from script.
-\code
-Item {
- Rectangle {
- id: myrect
- width: 100
- height: 100
+\qml
+PropertyAnimation {
+ id: animation
+ target: image
+ property: "scale"
+ from: 1; to: .5
+}
+Image {
+ id: image
+ source: "image.png"
+ MouseRegion {
+ anchors.fill: parent
+ onPressed: animation.start()
}
- states: [
- State {
- name: "moved"
- PropertyChanges {
- target: myrect
- x: 50
- y: 50
- }
- }
- ]
}
-\endcode
+\endqml
+
+Animations can be joined into a group using SequentialAnimation and ParallelAnimation.
-\section2 Transitions
+\target state-transitions
+\section1 Transitions
-QML transitions describe animations to perform when state changes occur.
+QML transitions describe animations to perform when \l{qmlstates}{state} changes occur.
-For the previous example, a transition could describe how \c myrect moved from its initial position to its new position:
+For example, a transition could describe how an item moves from its initial position to its new position:
\code
transitions: [
@@ -158,7 +122,13 @@ transitions: [
]
\endcode
-QML transitions can use selectors to determine which state changes a transition should apply to:
+As you can see from the above example, transitions make use of the same basic animation classes introduced
+above. However, you generally use a different set of properties when working with transitions. In the example,
+no target or property has been specified. Instead, we have specified properties, which acts as a selector to
+determine which property changes to animate; in this case, we will animate any x,y properties that have
+changed on any objects.
+
+QML transitions also selectors to determine which state changes a transition should apply to:
\code
Transition {
@@ -202,5 +172,48 @@ Transition {
\section1 Property Behaviors
-\note Property behaviors are currently experimental.
+A property behavior specifies a default animation to run whenever the property's value changes.
+
+In the following snippet, we specify that we want the x position of redRect to be animated
+whenever it changes. The animation will last 300 milliseconds and use an InOutQuad easing curve.
+
+\qml
+Rectangle {
+ id: redRect
+ color: "red"
+ width: 100; height: 100
+ x: Behavior { NumberAnimation { duration: 300; easing: "InOutQuad" } }
+}
+\endqml
+
+To trigger this behavior, we could:
+\list
+\o Enter a state that changes x
+
+\qml
+State {
+ name: "myState"
+ PropertyChanges {
+ target: redRect
+ x: 200
+ ...
+ }
+}
+\endqml
+
+\o Update x from a script
+
+\qml
+MouseRegion {
+ ....
+ onClicked: redRect.x = 24;
+}
+\endqml
+\endlist
+
+If x were bound to another property, triggering the binding would also trigger the behavior.
+
+If a state change has a transition animation matching a property with a Behavior, the transition animation
+will override the Behavior for that state change.
+
*/
diff --git a/doc/src/declarative/qmlreference.qdoc b/doc/src/declarative/qmlreference.qdoc
index 1498189..76269c3 100644
--- a/doc/src/declarative/qmlreference.qdoc
+++ b/doc/src/declarative/qmlreference.qdoc
@@ -65,13 +65,17 @@
\o \l {qmlexamples}{Examples}
\endlist
- Core QML Features:
+ \section1 Core QML Features:
\list
- \o \l {binding}{Data Binding}
+ \o \l {QML Documents}
+ \o \l {Property Binding}
+ \o \l {ECMAScript Blocks}
+ \o \l {Network Transparency}
\o \l {qmlmodels}{Data Models}
\o \l {anchor-layout}{Anchor-based Layout}
+ \o \l {qmlstates}{States}
\o \l {qmlanimation}{Animation}
- \o \l {qmlmodules}{Modules}
+ \o \l {qmlmodules.html}{Modules}
\o \l {qmlfocus}{Keyboard Focus}
\o \l {Extending types from QML}
\endlist
diff --git a/doc/src/declarative/qmlstates.qdoc b/doc/src/declarative/qmlstates.qdoc
new file mode 100644
index 0000000..955f7de
--- /dev/null
+++ b/doc/src/declarative/qmlstates.qdoc
@@ -0,0 +1,59 @@
+/*!
+\page qmlstates.html
+\target qmlstates
+\title QML States
+
+QML states describe user interface configurations, including:
+\list
+\o What UI elements are present
+\o The properties of those elements (including how they behave)
+\o What actions are available
+\endlist
+
+A state can also be thought of as a set of batched changes from a default configuration.
+
+Examples of states in modern UI:
+\list
+\o A Contacts application has a 'View Contact' state and an 'Edit Contact' State. In the first state the information presented is static (using labels), and in the second it is editable (using editors).
+\o A button has a pressed and unpressed state. When pressed the text moves down and to the right, and the button has a slightly darker appearance.
+\endlist
+
+In QML:
+\list
+\o Any object can use states.
+\o There is a default state. The default state can be explicitly set.
+\o A state can affect the properties of other objects, not just the object owning the state (and not just that object's children).
+\endlist
+
+The following example shows a simple use of states. In the default state \c myrect is positioned at 0,0. In the 'moved' state it is positioned at 50,50.
+
+\code
+Item {
+ Rectangle {
+ id: myrect
+ width: 100
+ height: 100
+ }
+ states: [
+ State {
+ name: "moved"
+ PropertyChanges {
+ target: myrect
+ x: 50
+ y: 50
+ }
+ }
+ ]
+}
+\endcode
+
+To animate state changes, you can use \l{state-transitions}{transitions}.
+
+Other things you can do in a state change:
+\list
+\o override signal handlers
+\o change an item's parent
+\o change an item's anchors
+\o run some script
+
+*/
diff --git a/doc/src/declarative/qtdeclarative.qdoc b/doc/src/declarative/qtdeclarative.qdoc
index e01b02d..7be98db 100644
--- a/doc/src/declarative/qtdeclarative.qdoc
+++ b/doc/src/declarative/qtdeclarative.qdoc
@@ -87,6 +87,7 @@ completely new applications. QML is fully \l {Extending QML}{extensible from C+
\o \l {Network Transparency}
\o \l {qmlmodels}{Data Models}
\o \l {anchor-layout}{Anchor-based Layout}
+\o \l {qmlstates}{States}
\o \l {qmlanimation}{Animation}
\o \l {qmlmodules.html}{Modules}
\o \l {qmlfocus}{Keyboard Focus}
diff --git a/examples/declarative/animation/color-animation.qml b/examples/declarative/animation/color-animation.qml
index ec3f90f..0cf8a44 100644
--- a/examples/declarative/animation/color-animation.qml
+++ b/examples/declarative/animation/color-animation.qml
@@ -25,18 +25,9 @@ Item {
}
}
}
- Particles {
- anchors.fill: parent; source: "images/star.png"; angleDeviation: 360; velocity: 0
- velocityDeviation: 0; count: parent.width / 10; fadeInDuration: 2800
- opacity: SequentialAnimation {
- running: true; repeat: true
- NumberAnimation { from: 0; to: 1; duration: 5000 }
- NumberAnimation { from: 1; to: 0; duration: 5000 }
- }
- }
}
- // the sun and the moon
+ // the sun, moon, and stars
Item {
width: parent.width; height: 2 * parent.height
transformOrigin: "Center"
@@ -52,6 +43,16 @@ Item {
source: "images/moon.png"; y: parent.height - 74; anchors.horizontalCenter: parent.horizontalCenter
transformOrigin: "Center"; rotation: -parent.rotation
}
+ Particles {
+ x: 0; y: parent.height/2; width: parent.width; height: parent.height/2
+ source: "images/star.png"; angleDeviation: 360; velocity: 0
+ velocityDeviation: 0; count: parent.width / 10; fadeInDuration: 2800
+ opacity: SequentialAnimation {
+ running: true; repeat: true
+ NumberAnimation { from: 0; to: 1; duration: 5000 }
+ NumberAnimation { from: 1; to: 0; duration: 5000 }
+ }
+ }
}
// ...and the ground.
diff --git a/examples/declarative/behaviours/SideRect.qml b/examples/declarative/behaviours/SideRect.qml
new file mode 100644
index 0000000..c7c7ebf
--- /dev/null
+++ b/examples/declarative/behaviours/SideRect.qml
@@ -0,0 +1,17 @@
+import Qt 4.6
+
+Rectangle {
+ id: myRect
+
+ property string text
+
+ color: "black"
+ width: 75; height: 50
+ radius: 5
+ border.width: 10; border.color: "white";
+ MouseRegion {
+ anchors.fill: parent
+ hoverEnabled: true
+ onEntered: { focusRect.x = myRect.x; focusRect.y = myRect.y; focusRect.text = myRect.text }
+ }
+}
diff --git a/examples/declarative/behaviours/behavior.qml b/examples/declarative/behaviours/behavior.qml
new file mode 100644
index 0000000..2732c0a
--- /dev/null
+++ b/examples/declarative/behaviours/behavior.qml
@@ -0,0 +1,72 @@
+import Qt 4.6
+
+Rectangle {
+ color: "black"
+ width: 400; height: 400
+
+ Rectangle {
+ color: "transparent"
+ anchors.centerIn: parent
+ width: 200; height: 200
+ radius: 30
+ border.width: 10; border.color: "white";
+
+ SideRect {
+ id: leftRect
+ anchors.verticalCenter: parent.verticalCenter
+ anchors.horizontalCenter: parent.left
+ text: "Left"
+ }
+
+ SideRect {
+ id: rightRect
+ anchors.verticalCenter: parent.verticalCenter
+ anchors.horizontalCenter: parent.right
+ text: "Right"
+ }
+
+ SideRect {
+ id: topRect
+ anchors.verticalCenter: parent.top
+ anchors.horizontalCenter: parent.horizontalCenter
+ text: "Top"
+ }
+
+ SideRect {
+ id: bottomRect
+ anchors.verticalCenter: parent.bottom
+ anchors.horizontalCenter: parent.horizontalCenter
+ text: "Bottom"
+ }
+
+
+ Rectangle {
+ id: focusRect
+
+ property string text
+
+ color: "red"
+ width: 75; height: 50
+ radius: 5
+ border.width: 10; border.color: "white";
+ x: 100-37; y: 100-25
+ x: Behavior { NumberAnimation { duration: 300 } }
+ y: Behavior { NumberAnimation { duration: 300 } }
+ Text {
+ id: focusText
+ text: focusRect.text;
+ text: Behavior {
+ SequentialAnimation {
+ NumberAnimation { target: focusText; property: "opacity"; to: 0; duration: 150 }
+ PropertyAction {}
+ NumberAnimation { target: focusText; property: "opacity"; to: 1; duration: 150 }
+ }
+ }
+ anchors.centerIn: parent;
+ color: "white";
+ font.pixelSize: 16
+ font.bold: true
+ }
+ }
+ }
+}
diff --git a/examples/declarative/behaviours/test.qml b/examples/declarative/behaviours/test.qml
index a15d05d..946559b 100644
--- a/examples/declarative/behaviours/test.qml
+++ b/examples/declarative/behaviours/test.qml
@@ -7,7 +7,7 @@ Rectangle {
id: page
MouseRegion {
anchors.fill: parent
- onClicked: { bluerect.parent = page; bluerect.x = mouseX; }
+ onClicked: { bluerect.parent = page; print(mouseX); bluerect.x = mouseX; }
}
MyRect {
color: "green"
@@ -57,25 +57,27 @@ Rectangle {
height: 100
id: bluerect
x: Behavior {
- SequentialAnimation {
- NumberAnimation {
- target: bluerect
- properties: "y"
- from: 0
- to: 10
- easing: "easeOutBounce(amplitude:30)"
- duration: 250
- }
- NumberAnimation {
- target: bluerect
- properties: "y"
- from: 10
- to: 0
- easing: "easeOutBounce(amplitude:30)"
- duration: 250
+ ParallelAnimation {
+ SequentialAnimation {
+ NumberAnimation {
+ target: bluerect
+ properties: "y"
+ from: 0
+ to: 10
+ easing: "easeOutBounce(amplitude:30)"
+ duration: 250
+ }
+ NumberAnimation {
+ target: bluerect
+ properties: "y"
+ from: 10
+ to: 0
+ easing: "easeOutBounce(amplitude:30)"
+ duration: 250
+ }
}
+ NumberAnimation { duration: 500 }
}
- NumberAnimation { duration: 500 }
}
parent: Behavior {
SequentialAnimation {
diff --git a/src/declarative/extra/qmldatetimeformatter.cpp b/src/declarative/extra/qmldatetimeformatter.cpp
index 3542657..9b3d37a 100644
--- a/src/declarative/extra/qmldatetimeformatter.cpp
+++ b/src/declarative/extra/qmldatetimeformatter.cpp
@@ -75,8 +75,8 @@ public:
\brief The DateTimeFormatter allows you to control the format of a date string.
\code
- DateTimeFormatter { id: Formatter; date: System.date }
- Text { text: Formatter.dateText }
+ DateTimeFormatter { id: formatter; date: System.date }
+ Text { text: formatter.dateText }
\endcode
By default, the text properties (dateText, timeText, and dateTimeText) will return the
diff --git a/src/declarative/extra/qmlfontloader.cpp b/src/declarative/extra/qmlfontloader.cpp
index 2193b68..f9857f6 100644
--- a/src/declarative/extra/qmlfontloader.cpp
+++ b/src/declarative/extra/qmlfontloader.cpp
@@ -76,11 +76,11 @@ QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,FontLoader,QmlFontLoader)
Example:
\qml
- FontLoader { id: FixedFont; name: "Courier" }
- FontLoader { id: WebFont; source: "http://www.mysite.com/myfont.ttf" }
+ FontLoader { id: fixedFont; name: "Courier" }
+ FontLoader { id: webFont; source: "http://www.mysite.com/myfont.ttf" }
- Text { text: "Fixed-size font"; font.family: FixedFont.name }
- Text { text: "Fancy font"; font.family: WebFont.name }
+ Text { text: "Fixed-size font"; font.family: fixedFont.name }
+ Text { text: "Fancy font"; font.family: webFont.name }
\endqml
*/
QmlFontLoader::QmlFontLoader(QObject *parent)
@@ -146,8 +146,8 @@ void QmlFontLoader::setSource(const QUrl &url)
Example:
\qml
- FontLoader { id: WebFont; source: "http://www.mysite.com/myfont.ttf" }
- Text { text: "Fancy font"; font.family: WebFont.name }
+ FontLoader { id: webFont; source: "http://www.mysite.com/myfont.ttf" }
+ Text { text: "Fancy font"; font.family: webFont.name }
\endqml
*/
QString QmlFontLoader::name() const
diff --git a/src/declarative/extra/qmlnumberformatter.cpp b/src/declarative/extra/qmlnumberformatter.cpp
index e937905..5b76e45 100644
--- a/src/declarative/extra/qmlnumberformatter.cpp
+++ b/src/declarative/extra/qmlnumberformatter.cpp
@@ -72,8 +72,8 @@ public:
In the following example, the text element will display the text "1,234.57".
\code
- NumberFormatter { id: Formatter; number: 1234.5678; format: "##,##0.##" }
- Text { text: Formatter.text }
+ NumberFormatter { id: formatter; number: 1234.5678; format: "##,##0.##" }
+ Text { text: formatter.text }
\endcode
*/
diff --git a/src/declarative/extra/qmlxmllistmodel.cpp b/src/declarative/extra/qmlxmllistmodel.cpp
index fb26915..df89f56 100644
--- a/src/declarative/extra/qmlxmllistmodel.cpp
+++ b/src/declarative/extra/qmlxmllistmodel.cpp
@@ -76,7 +76,7 @@ QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,XmlListModel,QmlXmlListModel)
...
Component {
- id: Delegate
+ id: myDelegate
Text { text: title }
}
\endqml
@@ -416,7 +416,7 @@ void QmlXmlRoleList::insert(int i, QmlXmlListModelRole *role)
The following is an example of a model containing news from a Yahoo RSS feed:
\qml
XmlListModel {
- id: FeedModel
+ id: feedModel
source: "http://rss.news.yahoo.com/rss/oceania"
query: "/rss/channel/item"
XmlRole { name: "title"; query: "title/string()" }
diff --git a/src/declarative/fx/qfxanchors.cpp b/src/declarative/fx/qfxanchors.cpp
index 09776e5..085bbc7 100644
--- a/src/declarative/fx/qfxanchors.cpp
+++ b/src/declarative/fx/qfxanchors.cpp
@@ -181,6 +181,9 @@ void QFxAnchorsPrivate::centerInChanged()
void QFxAnchorsPrivate::clearItem(QFxItem *item)
{
+ Q_Q(QFxAnchors);
+ if (!item)
+ return;
if (fill == item)
fill = 0;
if (centerIn == item)
@@ -213,6 +216,9 @@ void QFxAnchorsPrivate::clearItem(QFxItem *item)
baseline.item = 0;
usedAnchors &= ~QFxAnchors::HasBaselineAnchor;
}
+ QFxItemPrivate *p =
+ static_cast<QFxItemPrivate *>(QGraphicsItemPrivate::get(item));
+ p->dependantAnchors.removeAll(q);
}
void QFxAnchorsPrivate::addDepend(QFxItem *item)
@@ -232,7 +238,7 @@ void QFxAnchorsPrivate::remDepend(QFxItem *item)
return;
QFxItemPrivate *p =
static_cast<QFxItemPrivate *>(QGraphicsItemPrivate::get(item));
- p->dependantAnchors.removeAll(q);
+ p->dependantAnchors.removeOne(q);
}
bool QFxAnchorsPrivate::isItemComplete() const
diff --git a/src/declarative/fx/qfxgridview.cpp b/src/declarative/fx/qfxgridview.cpp
index 6abe88e..36c06a4 100644
--- a/src/declarative/fx/qfxgridview.cpp
+++ b/src/declarative/fx/qfxgridview.cpp
@@ -679,8 +679,6 @@ void QFxGridViewPrivate::updateCurrent(int modelIndex)
In this case ListModel is a handy way for us to test our UI. In practice
the model would be implemented in C++, or perhaps via a SQL data source.
-
-
*/
QFxGridView::QFxGridView(QFxItem *parent)
: QFxFlickable(*(new QFxGridViewPrivate), parent)
@@ -698,6 +696,59 @@ QFxGridView::~QFxGridView()
}
/*!
+ \qmlattachedproperty bool GridView::isCurrentItem
+ This attched property is true if this delegate is the current item; otherwise false.
+
+ It is attached to each instance of the delegate.
+*/
+
+/*!
+ \qmlattachedproperty GridView GridView::view
+ This attached property holds the view that manages this delegate instance.
+
+ It is attached to each instance of the delegate.
+*/
+
+/*!
+ \qmlattachedproperty bool GridView::delayRemove
+ This attached property holds whether the delegate may be destroyed.
+
+ It is attached to each instance of the delegate.
+
+ It is sometimes necessary to delay the destruction of an item
+ until an animation completes.
+
+ The example below ensures that the animation completes before
+ the item is removed from the grid.
+
+ \code
+ Component {
+ id: myDelegate
+ Item {
+ id: wrapper
+ GridView.onRemove: SequentialAnimation {
+ PropertyAction { target: wrapper.GridView; property: "delayRemove"; value: true }
+ NumberAnimation { target: wrapper; property: "scale"; to: 0; duration: 250; easing: "easeInOutQuad" }
+ PropertyAction { target: wrapper.GridView; property: "delayRemove"; value: false }
+ }
+ }
+ }
+ \endcode
+*/
+
+//XXX change to \qmlattachedsignal when it exists.
+/*!
+ \qmlattachedproperty void GridView::onAdd
+ This attached handler is called immediately after an item is added to the view.
+*/
+
+/*!
+ \qmlattachedproperty void GridView::onRemove
+ This attached handler is called immediately before an item is removed from the view.
+*/
+
+
+/*!
\qmlproperty model GridView::model
This property holds the model providing data for the grid.
@@ -871,9 +922,9 @@ void QFxGridView::setHighlight(QmlComponent *highlight)
\code
Component {
- id: Highlight
+ id: myHighlight
Rectangle {
- id: Wrapper; color: "lightsteelblue"; radius: 4; width: 320; height: 60 >
+ id: wrapper; color: "lightsteelblue"; radius: 4; width: 320; height: 60 >
y: SpringFollow { source: Wrapper.GridView.view.currentItem.y; spring: 3; damping: 0.2 }
x: SpringFollow { source: Wrapper.GridView.view.currentItem.x; spring: 3; damping: 0.2 }
}
diff --git a/src/declarative/fx/qfxitem.cpp b/src/declarative/fx/qfxitem.cpp
index bd94b8c..317a284 100644
--- a/src/declarative/fx/qfxitem.cpp
+++ b/src/declarative/fx/qfxitem.cpp
@@ -610,9 +610,9 @@ void QFxKeyNavigationAttached::keyReleased(QKeyEvent *event)
This example forwards key events to two lists:
\qml
- ListView { id: List1 ... }
- ListView { id: List2 ... }
- Keys.forwardTo: [List1, List2]
+ ListView { id: list1 ... }
+ ListView { id: list2 ... }
+ Keys.forwardTo: [list1, list2]
focus: true
\endqml
*/
@@ -876,6 +876,7 @@ void QFxKeyNavigationAttached::keyReleased(QKeyEvent *event)
parameter provides information about the event.
*/
+
class QFxKeysAttachedPrivate : public QObjectPrivate
{
public:
@@ -1194,19 +1195,13 @@ QFxKeysAttached *QFxKeysAttached::qmlAttachedProperties(QObject *obj)
/*!
\qmlclass Item QFxItem
\brief The Item is the most basic of all visual items in QML.
- */
-/*!
- \class QFxItem Item
- \brief The QFxItem class is a generic QmlView item. It is the base class for all other view items.
-
- \qmltext
- All visual items in Qt Declarative inherit from QFxItem. Although QFxItem
+ All visual items in Qt Declarative inherit from Item. Although Item
has no visual appearance, it defines all the properties that are
- common across visual items - like the x and y position, and the
- width and height. \l {Keys}{Key handling} is also provided by Item.
+ common across visual items - such as the x and y position, the
+ width and height, \l {anchor-layout}{anchoring} and key handling.
- QFxItem is also useful for grouping items together.
+ Item is also useful for grouping items together.
\qml
Item {
@@ -1229,7 +1224,31 @@ QFxKeysAttached *QFxKeysAttached::qmlAttachedProperties(QObject *obj)
}
\endqml
- \endqmltext
+ \section1 Key Handling
+
+ Key handling is available to all Item-based visual elements via the \l {Keys}{Keys}
+ attached property. The \e Keys attached property provides basic handlers such
+ as \l {Keys::onPressed(event)}{onPressed} and \l {Keys::onReleased(event)}{onReleased},
+ as well as handlers for specific keys, such as
+ \l {Keys::onCancelPressed(event)}{onCancelPressed}. The example below
+ assigns \l {qmlfocus}{focus} to the item and handles
+ the Left key via the general \e onPressed handler and the Select key via the
+ onSelectPressed handler:
+
+ \qml
+ Item {
+ focus: true
+ Keys.onPressed: {
+ if (event.key == Qt.Key_Left) {
+ print("move left");
+ event.accepted = true;
+ }
+ }
+ Keys.onSelectPressed: print("Selected");
+ }
+ \endqml
+
+ See the \l {Keys}{Keys} attached property for detailed documentation.
\ingroup group_coreitems
*/
diff --git a/src/declarative/fx/qfxlistview.cpp b/src/declarative/fx/qfxlistview.cpp
index 2ea1cb7..23bf573 100644
--- a/src/declarative/fx/qfxlistview.cpp
+++ b/src/declarative/fx/qfxlistview.cpp
@@ -907,6 +907,34 @@ QFxListView::~QFxListView()
It is sometimes necessary to delay the destruction of an item
until an animation completes.
+
+ The example below ensures that the animation completes before
+ the item is removed from the list.
+
+ \code
+ Component {
+ id: myDelegate
+ Item {
+ id: wrapper
+ ListView.onRemove: SequentialAnimation {
+ PropertyAction { target: wrapper.ListView; property: "delayRemove"; value: true }
+ NumberAnimation { target: wrapper; property: "scale"; to: 0; duration: 250; easing: "easeInOutQuad" }
+ PropertyAction { target: wrapper.ListView; property: "delayRemove"; value: false }
+ }
+ }
+ }
+ \endcode
+*/
+
+//XXX change to \qmlattachedsignal when it exists.
+/*!
+ \qmlattachedproperty void ListView::onAdd
+ This attached handler is called immediately after an item is added to the view.
+*/
+
+/*!
+ \qmlattachedproperty void ListView::onRemove
+ This attached handler is called immediately before an item is removed from the view.
*/
/*!
diff --git a/src/declarative/fx/qfxloader.cpp b/src/declarative/fx/qfxloader.cpp
index d0c2690..d60c135 100644
--- a/src/declarative/fx/qfxloader.cpp
+++ b/src/declarative/fx/qfxloader.cpp
@@ -69,9 +69,9 @@ QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Loader,QFxLoader)
It is also an effective means of delaying the creation of a component
until it is required:
\code
- Loader { id: PageLoader }
+ Loader { id: pageLoader }
Rectangle {
- MouseRegion { anchors.fill: parent; onClicked: PageLoader.source = "Page1.qml" }
+ MouseRegion { anchors.fill: parent; onClicked: pageLoader.source = "Page1.qml" }
}
\endcode
*/
@@ -155,12 +155,12 @@ void QFxLoader::setSource(const QUrl &url)
\qml
Item {
Component {
- id: RedSquare
+ id: redSquare
Rectangle { color: "red"; width: 10; height: 10 }
}
- Loader { sourceComponent: RedSquare }
- Loader { sourceComponent: RedSquare; x: 10 }
+ Loader { sourceComponent: redSquare }
+ Loader { sourceComponent: redSquare; x: 10 }
}
\endqml
diff --git a/src/declarative/qml/qmlcomponent.cpp b/src/declarative/qml/qmlcomponent.cpp
index dc71989..0c85574 100644
--- a/src/declarative/qml/qmlcomponent.cpp
+++ b/src/declarative/qml/qmlcomponent.cpp
@@ -84,15 +84,15 @@ int statusId = qRegisterMetaType<QmlComponent::Status>("QmlComponent::Status");
\qml
Item {
Component {
- id: RedSquare
+ id: redSquare
Rectangle {
color: "red"
width: 10
height: 10
}
}
- Loader { sourceComponent: RedSquare }
- Loader { sourceComponent: RedSquare; x: 20 }
+ Loader { sourceComponent: redSquare }
+ Loader { sourceComponent: redSquare; x: 20 }
}
\endqml
diff --git a/src/declarative/qml/qmldom.cpp b/src/declarative/qml/qmldom.cpp
index ce1bb93..a0601d7 100644
--- a/src/declarative/qml/qmldom.cpp
+++ b/src/declarative/qml/qmldom.cpp
@@ -764,7 +764,7 @@ int QmlDomObject::objectTypeMinorVersion() const
For example, the object id of this object would be "MyText".
\qml
-Text { id: MyText }
+Text { id: myText }
\endqml
*/
QString QmlDomObject::objectId() const
@@ -1599,12 +1599,12 @@ QList<int> QmlDomList:: commaPositions() const
Sub-components are QmlComponents defined within a QML document. The
following example shows the definition of a sub-component with the id
- "ListDelegate".
+ "listDelegate".
\qml
Item {
Component {
- id: ListDelegate
+ id: listDelegate
Text {
text: modelData.text
}
@@ -1653,7 +1653,7 @@ QmlDomComponent &QmlDomComponent::operator=(const QmlDomComponent &other)
\qml
Item {
Component {
- id: ListDelegate
+ id: listDelegate
Text {
text: modelData.text
}
diff --git a/src/declarative/qml/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp
index 9fad80b..354114a 100644
--- a/src/declarative/qml/qmlengine.cpp
+++ b/src/declarative/qml/qmlengine.cpp
@@ -747,7 +747,7 @@ QScriptValue QmlEnginePrivate::createQmlObject(QScriptContext *ctxt, QScriptEngi
\code
transform: Rotation {
- id: Rotation
+ id: rotation
origin.x: Container.width / 2;
axis: vector(0, 1, 1)
}
@@ -757,7 +757,7 @@ QScriptValue QmlEnginePrivate::createQmlObject(QScriptContext *ctxt, QScriptEngi
\code
transform: Rotation {
- id: Rotation
+ id: rotation
origin.x: Container.width / 2;
axis.x: 0; axis.y: 1; axis.z: 0
}
diff --git a/src/declarative/qml/qmlexpression.cpp b/src/declarative/qml/qmlexpression.cpp
index b07ee4c..d2bf4a8 100644
--- a/src/declarative/qml/qmlexpression.cpp
+++ b/src/declarative/qml/qmlexpression.cpp
@@ -109,7 +109,7 @@ void QmlExpressionPrivate::init(QmlContext *ctxt, void *expr, QmlRefCount *rc,
QmlEngine *engine = ctxt->engine();
QmlEnginePrivate *ep = QmlEnginePrivate::get(engine);
QScriptEngine *scriptEngine = QmlEnginePrivate::getScriptEngine(engine);
-#ifndef Q_OS_SYMBIAN //XXX Why doesn't this work?
+#if !defined(Q_OS_SYMBIAN) && !defined(Q_OS_WIN32) //XXX Why doesn't this work?
if (!dd->programs.at(progIdx)) {
dd->programs[progIdx] =
new QScriptProgram(scriptEngine->compile(data->expression, data->fileName, data->line));
@@ -119,7 +119,7 @@ void QmlExpressionPrivate::init(QmlContext *ctxt, void *expr, QmlRefCount *rc,
QScriptContext *scriptContext = scriptEngine->pushCleanContext();
scriptContext->pushScope(ep->contextClass->newContext(ctxt, me));
-#ifndef Q_OS_SYMBIAN
+#if !defined(Q_OS_SYMBIAN) && !defined(Q_OS_WIN32)
data->expressionFunction = scriptEngine->evaluate(*dd->programs[progIdx]);
#else
data->expressionFunction = scriptEngine->evaluate(data->expression);
diff --git a/src/declarative/util/qmlanimation.cpp b/src/declarative/util/qmlanimation.cpp
index f42aa4e..c5a7f38 100644
--- a/src/declarative/util/qmlanimation.cpp
+++ b/src/declarative/util/qmlanimation.cpp
@@ -179,10 +179,10 @@ QmlAbstractAnimation::QmlAbstractAnimation(QmlAbstractAnimationPrivate &dd, QObj
Rectangle {
width: 100; height: 100
x: NumberAnimation {
- running: MyMouse.pressed
+ running: myMouse.pressed
from: 0; to: 100
}
- MouseRegion { id: MyMouse }
+ MouseRegion { id: myMouse }
}
\endcode
@@ -191,8 +191,8 @@ QmlAbstractAnimation::QmlAbstractAnimation(QmlAbstractAnimationPrivate &dd, QObj
or not the animation is running.
\code
- NumberAnimation { id: MyAnimation }
- Text { text: MyAnimation.running ? "Animation is running" : "Animation is not running" }
+ NumberAnimation { id: myAnimation }
+ Text { text: myAnimation.running ? "Animation is running" : "Animation is not running" }
\endcode
Animations can also be started and stopped imperatively from JavaScript
diff --git a/src/declarative/util/qmleasefollow.cpp b/src/declarative/util/qmleasefollow.cpp
index 860c63a..f020395 100644
--- a/src/declarative/util/qmleasefollow.cpp
+++ b/src/declarative/util/qmleasefollow.cpp
@@ -225,21 +225,21 @@ Rectangle {
color: "green"
width: 60; height: 60;
x: -5; y: -5;
- x: EaseFollow { source: Rect1.x - 5; velocity: 200 }
- y: EaseFollow { source: Rect1.y - 5; velocity: 200 }
+ x: EaseFollow { source: rect1.x - 5; velocity: 200 }
+ y: EaseFollow { source: rect1.y - 5; velocity: 200 }
}
Rectangle {
- id: Rect1
+ id: rect1
color: "red"
width: 50; height: 50;
}
focus: true
- Keys.onRightPressed: Rect1.x = Rect1.x + 100
- Keys.onLeftPressed: Rect1.x = Rect1.x - 100
- Keys.onUpPressed: Rect1.y = Rect1.y - 100
- Keys.onDownPressed: Rect1.y = Rect1.y + 100
+ Keys.onRightPressed: rect1.x = rect1.x + 100
+ Keys.onLeftPressed: rect1.x = rect1.x - 100
+ Keys.onUpPressed: rect1.y = rect1.y - 100
+ Keys.onDownPressed: rect1.y = rect1.y + 100
}
\endcode
diff --git a/src/declarative/util/qmllistmodel.cpp b/src/declarative/util/qmllistmodel.cpp
index 4dc9bc5..7ccccec 100644
--- a/src/declarative/util/qmllistmodel.cpp
+++ b/src/declarative/util/qmllistmodel.cpp
@@ -82,7 +82,7 @@ static void dump(ModelNode *node, int ind);
\code
ListModel {
- id: FruitModel
+ id: fruitModel
ListElement {
name: "Apple"
cost: 2.45
@@ -104,7 +104,7 @@ static void dump(ModelNode *node, int ind);
The defined model can be used in views such as ListView:
\code
Component {
- id: FruitDelegate
+ id: fruitDelegate
Item {
width: 200; height: 50
Text { text: name }
@@ -113,8 +113,8 @@ static void dump(ModelNode *node, int ind);
}
ListView {
- model: FruitModel
- delegate: FruitDelegate
+ model: fruitModel
+ delegate: fruitDelegate
anchors.fill: parent
}
\endcode
@@ -123,7 +123,7 @@ static void dump(ModelNode *node, int ind);
\code
ListModel {
- id: FruitModel
+ id: fruitModel
ListElement {
name: "Apple"
cost: 2.45
@@ -153,7 +153,7 @@ static void dump(ModelNode *node, int ind);
The delegate below will list all the fruit attributes:
\code
Component {
- id: FruitDelegate
+ id: fruitDelegate
Item {
width: 200; height: 50
Text { id: Name; text: name }
@@ -176,7 +176,7 @@ static void dump(ModelNode *node, int ind);
\code
Component {
- id: FruitDelegate
+ id: fruitDelegate
Item {
width: 200; height: 50
Text { text: name }
@@ -185,7 +185,7 @@ static void dump(ModelNode *node, int ind);
// Double the price when clicked.
MouseRegion {
anchors.fill: parent
- onClicked: FruitModel.set(index, "cost", cost*2)
+ onClicked: fruitModel.set(index, "cost", cost*2)
}
}
}
diff --git a/src/declarative/util/qmlspringfollow.cpp b/src/declarative/util/qmlspringfollow.cpp
index 2dae448..34ec976 100644
--- a/src/declarative/util/qmlspringfollow.cpp
+++ b/src/declarative/util/qmlspringfollow.cpp
@@ -210,10 +210,10 @@ void QmlSpringFollowPrivate::stop()
\qmlclass SpringFollow QmlSpringFollow
\brief The SpringFollow element allows a property to track a value.
- In example below, Rect2 will follow Rect1 moving with a velocity of up to 200:
+ In example below, \e rect2 will follow \e rect1 moving with a velocity of up to 200:
\code
Rectangle {
- id: Rect1
+ id: rect1
width: 20; height: 20
color: "#00ff00"
y: 200 //initial value
@@ -229,11 +229,11 @@ void QmlSpringFollowPrivate::stop()
}
}
Rectangle {
- id: Rect2
- x: Rect1.width
+ id: rect2
+ x: rect1.width
width: 20; height: 20
color: "#ff0000"
- y: SpringFollow { source: Rect1.y; velocity: 200 }
+ y: SpringFollow { source: rect1.y; velocity: 200 }
}
\endcode
diff --git a/src/declarative/util/qmlsystempalette.cpp b/src/declarative/util/qmlsystempalette.cpp
index 88278c3..014eca8 100644
--- a/src/declarative/util/qmlsystempalette.cpp
+++ b/src/declarative/util/qmlsystempalette.cpp
@@ -62,14 +62,14 @@ QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,SystemPalette,QmlSystemPalette)
Example:
\qml
- SystemPalette { id: MyPalette; colorGroup: Qt.Active }
+ SystemPalette { id: myPalette; colorGroup: Qt.Active }
Rectangle {
width: 640; height: 480
- color: MyPalette.window
+ color: myPalette.window
Text {
anchors.fill: parent
- text: "Hello!"; color: MyPalette.windowText
+ text: "Hello!"; color: myPalette.windowText
}
}
\endqml
diff --git a/src/declarative/util/qmltimer.cpp b/src/declarative/util/qmltimer.cpp
index 3fbe15c..f1991f5 100644
--- a/src/declarative/util/qmltimer.cpp
+++ b/src/declarative/util/qmltimer.cpp
@@ -75,10 +75,10 @@ public:
\qml
Timer {
interval: 500; running: true; repeat: true
- onTriggered: Time.text = Date().toString()
+ onTriggered: time.text = Date().toString()
}
Text {
- id: Time
+ id: time
}
\endqml
diff --git a/tests/auto/declarative/qmlecmascript/data/TypeForDynamicCreation.qml b/tests/auto/declarative/qmlecmascript/data/TypeForDynamicCreation.qml
new file mode 100644
index 0000000..56e0625
--- /dev/null
+++ b/tests/auto/declarative/qmlecmascript/data/TypeForDynamicCreation.qml
@@ -0,0 +1,2 @@
+import Qt.test 1.0
+MyQmlObject{objectName:"objectThree"}
diff --git a/tests/auto/declarative/qmlecmascript/data/dynamicCreation.qml b/tests/auto/declarative/qmlecmascript/data/dynamicCreation.qml
index ef39590..ed5e571 100644
--- a/tests/auto/declarative/qmlecmascript/data/dynamicCreation.qml
+++ b/tests/auto/declarative/qmlecmascript/data/dynamicCreation.qml
@@ -13,4 +13,9 @@ MyQmlObject{
var component = createComponent('dynamicCreation.helper.qml');
obj.objectProperty = component.createObject();
}
+
+ function createThree()
+ {
+ obj.objectProperty = createQmlObject('TypeForDynamicCreation{}', obj);
+ }
}
diff --git a/tests/auto/declarative/qmlecmascript/tst_qmlecmascript.cpp b/tests/auto/declarative/qmlecmascript/tst_qmlecmascript.cpp
index f24882a..34b49e6 100644
--- a/tests/auto/declarative/qmlecmascript/tst_qmlecmascript.cpp
+++ b/tests/auto/declarative/qmlecmascript/tst_qmlecmascript.cpp
@@ -56,6 +56,7 @@ private slots:
void signalParameterTypes();
void objectsCompareAsEqual();
void scriptAccess();
+ void dynamicCreation_data();
void dynamicCreation();
void dynamicDestruction();
void objectToString();
@@ -639,27 +640,33 @@ void tst_qmlecmascript::scriptAccess()
QCOMPARE(object->property("test3").toInt(), 0);
}
+void tst_qmlecmascript::dynamicCreation_data()
+{
+ QTest::addColumn<QString>("method");
+ QTest::addColumn<QString>("createdName");
+
+ QTest::newRow("One") << "createOne" << "objectOne";
+ QTest::newRow("Two") << "createTwo" << "objectTwo";
+ QTest::newRow("Three") << "createThree" << "objectThree";
+}
+
/*
Test using createQmlObject to dynamically generate an item
Also using createComponent is tested.
*/
void tst_qmlecmascript::dynamicCreation()
{
+ QFETCH(QString, method);
+ QFETCH(QString, createdName);
+
QmlComponent component(&engine, TEST_FILE("dynamicCreation.qml"));
MyQmlObject *object = qobject_cast<MyQmlObject*>(component.create());
QVERIFY(object != 0);
- QObject *createdQmlObject = 0;
- QObject *createdComponent = 0;
-
- QMetaObject::invokeMethod(object, "createOne");
- createdQmlObject = object->objectProperty();
- QVERIFY(createdQmlObject);
- QCOMPARE(createdQmlObject->objectName(), QString("objectOne"));
- QMetaObject::invokeMethod(object, "createTwo");
- createdComponent = object->objectProperty();
- QVERIFY(createdComponent);
- QCOMPARE(createdComponent->objectName(), QString("objectTwo"));
+ QMetaObject::invokeMethod(object, method.toUtf8());
+ QObject *created = object->objectProperty();
+ QVERIFY(created);
+ QCOMPARE(created->objectName(), createdName);
}
/*
diff --git a/tools/qmlviewer/qmlviewer.cpp b/tools/qmlviewer/qmlviewer.cpp
index a8034cf..60fa13a 100644
--- a/tools/qmlviewer/qmlviewer.cpp
+++ b/tools/qmlviewer/qmlviewer.cpp
@@ -606,10 +606,8 @@ void QmlViewer::reload()
void QmlViewer::open()
{
QString fileName = QFileDialog::getOpenFileName(this, tr("Open QML file"), currentFileName, tr("QML Files (*.qml)"));
- if (!fileName.isEmpty()) {
+ if (!fileName.isEmpty())
openQml(fileName);
- QTimer::singleShot(0, this, SLOT(reload()));
- }
}
void QmlViewer::executeErrors()