tests/auto/declarative/qmlvisual/qdeclarativespringfollow/follow.qml
changeset 33 3e2da88830cd
parent 30 5dc02b23752f
equal deleted inserted replaced
30:5dc02b23752f 33:3e2da88830cd
     1 import Qt 4.7
     1 import Qt 4.7
     2 
     2 
     3 Rectangle {
     3 Rectangle {
     4     color: "#ffffff"
     4     color: "#ffffff"
     5     width: 320; height: 240
     5     width: 320; height: 240
       
     6 
     6     Rectangle {
     7     Rectangle {
     7         id: rect
     8         id: rect
     8         color: "#00ff00"
     9         color: "#00ff00"
     9         y: 200; width: 60; height: 20
    10         y: 200; width: 60; height: 20
    10         SequentialAnimation on y {
    11         SequentialAnimation on y {
    23 
    24 
    24     // Velocity
    25     // Velocity
    25     Rectangle {
    26     Rectangle {
    26         color: "#ff0000"
    27         color: "#ff0000"
    27         x: rect.width; width: rect.width; height: 20
    28         x: rect.width; width: rect.width; height: 20
    28         y: 200
    29         y: rect.y
    29         SpringFollow on y { to: rect.y; velocity: 200 }
    30         Behavior on y { SpringAnimation { velocity: 200 } }
    30     }
    31     }
    31 
    32 
    32     // Spring
    33     // Spring
    33     Rectangle {
    34     Rectangle {
    34         color: "#ff0000"
    35         color: "#ff0000"
    35         x: rect.width * 2; width: rect.width/2; height: 20
    36         x: rect.width * 2; width: rect.width/2; height: 20
    36         y: 200
    37         y: rect.y
    37         SpringFollow on y { to: rect.y; spring: 1.0; damping: 0.2 }
    38         Behavior on y { SpringAnimation { spring: 1.0; damping: 0.2 } }
    38     }
    39     }
    39     Rectangle {
    40     Rectangle {
    40         color: "#880000"
    41         color: "#880000"
    41         x: rect.width * 2.5; width: rect.width/2; height: 20
    42         x: rect.width * 2.5; width: rect.width/2; height: 20
    42         y: 200
    43         y: rect.y
    43         SpringFollow on y { to: rect.y; spring: 1.0; damping: 0.2; mass: 3.0 } // "heavier" object
    44         Behavior on y { SpringAnimation { spring: 1.0; damping: 0.2; mass: 3.0 } } // "heavier" object
    44     }
    45     }
    45 
    46 
    46     // Follow mouse
    47     // Follow mouse
    47     MouseArea {
    48     MouseArea {
    48         id: mouseRegion
    49         id: mouseRegion
    49         anchors.fill: parent
    50         anchors.fill: parent
    50         Rectangle {
    51         Rectangle {
    51             id: ball
    52             id: ball
       
    53             property int targetX: mouseRegion.mouseX - 10
       
    54             property int targetY: mouseRegion.mouseY - 10
       
    55 
       
    56             x: targetX
       
    57             y: targetY
    52             width: 20; height: 20
    58             width: 20; height: 20
    53             radius: 10
    59             radius: 10
    54             color: "#0000ff"
    60             color: "#0000ff"
    55             SpringFollow on x { id: f1; to: mouseRegion.mouseX-10; spring: 1.0; damping: 0.05; epsilon: 0.25 }
    61 
    56             SpringFollow on y { id: f2; to: mouseRegion.mouseY-10; spring: 1.0; damping: 0.05; epsilon: 0.25 }
    62             Behavior on x { SpringAnimation { spring: 1.0; damping: 0.05; epsilon: 0.25 } }
       
    63             Behavior on y { SpringAnimation { spring: 1.0; damping: 0.05; epsilon: 0.25 } }
       
    64 
    57             states: [
    65             states: [
    58                 State {
    66                 State {
    59                     name: "following"
    67                     name: "following"
    60                     when: !f1.inSync || !f2.inSync
    68                     when: ball.x != ball.targetX || ball.y != ball.targetY
    61                     PropertyChanges { target: ball; color: "#ff0000" }
    69                     PropertyChanges { target: ball; color: "#ff0000" }
    62                 }
    70                 }
    63             ]
    71             ]
    64             transitions: [
    72             transitions: [
    65                 Transition {
    73                 Transition {