Initial import from the monolithic Qt.
[profile/ivi/qtdeclarative.git] / tests / auto / declarative / qmlvisual / qdeclarativemousearea / mousearea-visual.qml
1 import QtQuick 1.0
2
3 /*
4 This test displays 6 red rects -- 4 in the top row, 2 in the bottom.
5
6 Sequence:
7 1. the bottom-left rect turns blue, then green
8 2. the second rect in the top row turns blue
9 3. the third rect in the top row turns blue
10 4. the last rect in the top row quickly turns blue then back to red
11 5. the bottom-left rect turns blue, then green
12 */
13
14 Rectangle {
15     id: root
16     width: 400
17     height: 100
18
19     // Left click on me
20     Rectangle {
21         width: 98; height: 48
22         color: "red"
23         MouseArea {
24             id: mr1
25             anchors.fill: parent
26             enabled: false
27             onClicked: { parent.color = "blue"; root.error = "mr1 should ignore presses"; }
28         }
29     }
30
31     // Left click, then right click
32     Rectangle {
33         x: 100
34         width: 98; height: 48
35         color: "red"
36         MouseArea {
37             id: mr2
38             anchors.fill: parent
39             acceptedButtons: Qt.RightButton
40             onClicked: {
41                 if (mouse.button == Qt.RightButton) {
42                     parent.color = "blue";
43                 } else {
44                     parent.color = "green";
45                     root.error = "mr1 should ignore presses";
46                 }
47             }
48         }
49     }
50
51     // press and hold me
52     Rectangle {
53         x: 200
54         width: 98; height: 48
55         color: "red"
56         MouseArea {
57             id: mr3
58             anchors.fill: parent
59             onPressAndHold: {
60                 parent.color = "blue";
61             }
62         }
63     }
64
65     // click me
66     Rectangle {
67         x: 300
68         width: 98; height: 48
69         color: "red"
70         MouseArea {
71             id: mr4
72             anchors.fill: parent
73             onPressed: {
74                 parent.color = "blue";
75             }
76             onReleased: {
77                 parent.color = "red";
78             }
79         }
80     }
81
82     // move into and out of me
83     Rectangle {
84         x: 0
85         y: 50
86         width: 98; height: 48
87         color: "red"
88         MouseArea {
89             id: mr5
90             anchors.fill: parent
91             hoverEnabled: true
92             onEntered: {
93                 parent.color = "blue";
94             }
95             onExited: {
96                 parent.color = "green";
97             }
98         }
99     }
100
101     // click, then double click me
102     Rectangle {
103         x: 100
104         y: 50
105         width: 98; height: 48
106         color: "red"
107         MouseArea {
108             id: mr6
109             anchors.fill: parent
110             onClicked: {
111                 parent.color = "blue";
112             }
113             onDoubleClicked: {
114                 parent.color = "green";
115             }
116         }
117     }
118
119     // click, then double click me - nothing should happen
120     Rectangle {
121         x: 100
122         y: 50
123         width: 98; height: 48
124         color: "red"
125         MouseArea {
126             id: mr7
127             anchors.fill: parent
128             enabled: false
129             onClicked: { parent.color = "blue" }
130             onPressed: { parent.color = "yellow" }
131             onReleased: { parent.color = "cyan" }
132             onDoubleClicked: { parent.color = "green" }
133         }
134     }
135 }