diff options
Diffstat (limited to 'examples/declarative/states/states.qml')
-rw-r--r-- | examples/declarative/states/states.qml | 59 |
1 files changed, 35 insertions, 24 deletions
diff --git a/examples/declarative/states/states.qml b/examples/declarative/states/states.qml index c35cd63..4429e78 100644 --- a/examples/declarative/states/states.qml +++ b/examples/declarative/states/states.qml @@ -2,49 +2,60 @@ import Qt 4.7 Rectangle { id: page - width: 640; height: 480; color: "#343434" + width: 640; height: 480 + color: "#343434" + + Image { + id: userIcon + x: topLeftRect.x; y: topLeftRect.y + source: "user.png" + } - // A target region. Clicking in here sets the state to the default state Rectangle { - id: initialPosition + id: topLeftRect + anchors { left: parent.left; top: parent.top; leftMargin: 10; topMargin: 20 } - width: 64; height: 64; radius: 6 - color: "Transparent"; border.color: "Gray" + width: 64; height: 64 + color: "Transparent"; border.color: "Gray"; radius: 6 + + // Clicking in here sets the state to the default state, returning the image to + // its initial position MouseArea { anchors.fill: parent; onClicked: page.state = '' } } - // Another target region. Clicking in here sets the state to 'Position1' Rectangle { - id: position1 + id: middleRightRect + anchors { right: parent.right; verticalCenter: parent.verticalCenter; rightMargin: 20 } - width: 64; height: 64; radius: 6 - color: "Transparent"; border.color: "Gray" - MouseArea { anchors.fill: parent; onClicked: page.state = 'Position1' } + width: 64; height: 64 + color: "Transparent"; border.color: "Gray"; radius: 6 + + // Clicking in here sets the state to 'middleRight' + MouseArea { anchors.fill: parent; onClicked: page.state = 'middleRight' } } - // Another target region. Clicking in here sets the state to 'Position2' Rectangle { - id: position2 + id: bottomLeftRect + anchors { left: parent.left; bottom: parent.bottom; leftMargin: 10; bottomMargin: 20 } - width: 64; height: 64; radius: 6 - color: "Transparent"; border.color: "Gray" - MouseArea { anchors.fill: parent; onClicked: page.state = 'Position2' } - } + width: 64; height: 64 + color: "Transparent"; border.color: "Gray"; radius: 6 - // The image which will be moved when my state changes - Image { id: user; source: "user.png"; x: initialPosition.x; y: initialPosition.y } + // Clicking in here sets the state to 'bottomLeft' + MouseArea { anchors.fill: parent; onClicked: page.state = 'bottomLeft' } + } states: [ - // In state 'Position1', change the 'user' item position to rect2's position. + // In state 'middleRight', move the image to middleRightRect State { - name: "Position1" - PropertyChanges { target: user; x: position1.x; y: position1.y } + name: "middleRight" + PropertyChanges { target: userIcon; x: middleRightRect.x; y: middleRightRect.y } }, - // In state 'Position2', change the 'user' item position to rect3's position. + // In state 'bottomLeft', move the image to bottomLeftRect State { - name: "Position2" - PropertyChanges { target: user; x: position2.x; y: position2.y } + name: "bottomLeft" + PropertyChanges { target: userIcon; x: bottomLeftRect.x; y: bottomLeftRect.y } } ] } |