QtDeclarative: fixed modelviews example
authorChristiaan Janssen <christiaan.janssen@digia.com>
Thu, 22 Nov 2012 16:54:33 +0000 (17:54 +0100)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Fri, 23 Nov 2012 10:14:41 +0000 (11:14 +0100)
Change-Id: I3d31beb6a23b7c74061cf66d3c13616911cda7c6
Reviewed-by: Christian Stenger <christian.stenger@digia.com>

examples/quick/modelviews/listview/highlight.qml
examples/quick/modelviews/listview/highlightranges.qml

index ec33cda..bf6c902 100644 (file)
@@ -91,6 +91,7 @@ Rectangle {
     ListView {
         id: listView
         width: 200; height: parent.height
+        x: 30
 
         model: PetsModel {}
         delegate: petDelegate
index 815890f..f0cc142 100644 (file)
@@ -45,25 +45,36 @@ import "content"
 Rectangle {
     id: root
     property int current: 0
+    property bool increasing: true
     // Example index automation for convenience, disabled on click or tap
-    SequentialAnimation on current {
+    SequentialAnimation {
         id: anim
         loops: -1
-        NumberAnimation {
-            duration: 5000
-            to: aModel.count - 1
-        }
-        NumberAnimation {
-            duration: 5000
-            to: 0
+        running: true
+        ScriptAction {
+            script: if (increasing) {
+                        current++;
+                        if (current >= aModel.count -1) {
+                            current = aModel.count - 1;
+                            increasing = !increasing;
+                        }
+                    } else {
+                        current--;
+                        if (current <= 0) {
+                            current = 0;
+                            increasing = !increasing;
+                        }
+                    }
         }
+
+        PauseAnimation { duration: 500 }
     }
 //! [0]
     MouseArea{
         id: ma
         z: 1
         anchors.fill: parent
-        onClicked: {ma.enabled = false; anim.running = false;}
+        onClicked: { z = 1 - z; if (anim.running) anim.stop(); else anim.restart();}
     }
 
     width: 320; height: 480
@@ -94,7 +105,7 @@ Rectangle {
 //! [1]
     ListView {
         id: list1
-        height: 160; width: parent.width
+        height: 50; width: parent.width
         model: PetsModel {id: aModel}
         delegate: petDelegate
         orientation: ListView.Horizontal
@@ -107,8 +118,8 @@ Rectangle {
 
     ListView {
         id: list2
-        y: list1.height
-        height: 160; width: parent.width
+        y: 160
+        height: 50; width: parent.width
         model: PetsModel {}
         delegate: petDelegate
         orientation: ListView.Horizontal
@@ -121,8 +132,8 @@ Rectangle {
 
     ListView {
         id: list3
-        y: list1.height + list2.height
-        height: 160; width: parent.width
+        y: 320
+        height: 50; width: parent.width
         model: PetsModel {}
         delegate: petDelegate
         orientation: ListView.Horizontal
@@ -149,7 +160,7 @@ Rectangle {
 
             MouseArea {
                 anchors.fill: parent
-                onClicked: wrapper.ListView.view.currentIndex = index
+                onClicked: root.current = index
             }
         }
     }