Replaced self made UI rotation with system's rotation, portrait panels need some...
[situare] / src / qmlui / Map.qml
1 import Qt 4.7
2 import MapPlugin 1.0
3
4 Rectangle {
5     id: mapRect
6     clip: true
7
8     property alias centerLatitude: map.centerLatitude
9     property alias centerLongitude: map.centerLongitude
10     property alias gpsLocationLatitude: map.gpsLocationLatitude
11     property alias gpsLocationLongitude: map.gpsLocationLongitude
12
13     ParallelAnimation {
14         id: panAnimation
15         running: false
16         property alias latitude: animLatitude.to
17         property alias longitude: animLongitude.to
18         PropertyAnimation {
19             id: animLatitude
20             target: mapRect
21             property: "centerLatitude"
22             from: map.centerLatitude
23             duration: 500
24             easing.type: Easing.InOutCubic
25         }
26         PropertyAnimation {
27             id: animLongitude
28             target: mapRect
29             property: "centerLongitude"
30             from: map.centerLongitude
31             duration: 500
32             easing.type: Easing.InOutCubic
33         }
34     }
35
36     function panTo(latitude, longitude) {
37         console.log("Map.panTo", latitude, longitude)
38         if (!panAnimation.running) {
39             panAnimation.latitude = latitude
40             panAnimation.longitude = longitude
41             panAnimation.running = true
42         }
43     }
44
45     color: palette.window
46
47     GeoMap {
48         id: map
49         anchors.fill: parent
50         mapType: "StreetMap"
51         zoomLevel: 5.0
52     }
53
54     Rectangle {
55         color: "#222222"
56         width: logo.width + 20
57         height: logo.height + 20
58         x: -10
59         y: -10
60         radius: 10
61         Image {
62             id: logo
63             source: "qrc:/res/ixonos_logo.png"
64             anchors.centerIn: parent
65             anchors.horizontalCenterOffset: 3
66             anchors.verticalCenterOffset: 5
67         }
68     }
69
70     MouseArea {
71         property int prevMouseX: 0
72         property int prevMouseY: 0
73         anchors.fill: map
74         onPressed: {
75             prevMouseX = mouse.x
76             prevMouseY = mouse.y;
77         }
78         onMousePositionChanged: {
79             if (mouse.buttons & Qt.LeftButton) {
80                 var diffX = mouse.x - prevMouseX
81                 var diffY = mouse.y - prevMouseY
82                 map.pan(-diffX, -diffY)
83                 prevMouseX = mouse.x
84                 prevMouseY = mouse.y
85             }
86         }
87         onClicked: {
88             map.onClicked(mouseX, mouseY)
89         }
90     }
91
92     Keys.onPressed: {
93         if (event.key == Qt.Key_F7)
94             map.zoomIn()
95         else if (event.key == Qt.Key_F8)
96             map.zoomOut()
97     }
98
99     Image {
100         id: sight
101         x: parent.width/2 - width/2
102         y: parent.height/2 - height/2
103         opacity: 1.0
104         source: "qrc:/res/sight.png"
105     }
106
107     Rectangle {
108         id: gpsDistance
109         x: 5
110         y: parent.height - height - 5
111         width: zoomIn.width
112         height: zoomIn.height / 2
113         radius: 10
114         opacity: 1
115         color: palette.button
116         border.color: palette.highlight
117         border.width: 3
118
119         Text {
120             anchors.fill: parent
121             verticalAlignment: "AlignVCenter"
122             horizontalAlignment: "AlignHCenter"
123             text: map.distanceToGpsLocationText
124             color: palette.text
125             font.pixelSize: height / 3
126         }
127     }
128
129     Rectangle {
130         id: gpsLocation
131         x: 5
132         y: parent.height - height - gpsDistance.height - 10
133         width: zoomIn.width
134         height: zoomIn.height
135         radius: 10
136         opacity: 1
137         color: palette.button
138         border.color: palette.highlight
139         border.width: 3
140
141         Image {
142             source: "qrc:/res/gps_position.png"
143             anchors.verticalCenter: parent.verticalCenter
144             anchors.horizontalCenter: parent.horizontalCenter
145         }
146
147         Image {
148              source: "qrc:/res/gps_position_dir.png"
149              anchors.verticalCenter: parent.verticalCenter
150              anchors.horizontalCenter: parent.horizontalCenter
151              rotation: map.angleToGpsLocation
152              opacity: map.distanceToGpsLocation < 1.0 ? 0.0 : 1.0
153         }
154
155         MouseArea {
156             id: mouseArea3
157             anchors.fill: parent
158             onClicked: ParallelAnimation {
159                 PropertyAnimation {
160                     target: map
161                     property: "centerLatitude"
162                     from: map.centerLatitude
163                     to: map.gpsLocationLatitude
164                     duration: 500
165                     easing.type: Easing.InOutCubic
166                 }
167                 PropertyAnimation {
168                     target: map
169                     property: "centerLongitude"
170                     from: map.centerLongitude
171                     to: map.gpsLocationLongitude
172                     duration: 500
173                     easing.type: Easing.InOutCubic
174                 }
175             }
176         }
177         states: [
178             State {
179                 name: "active"
180                 when: mouseArea3.pressed
181                 PropertyChanges {
182                     target: gpsLocation
183                     opacity: 1.0
184                 }
185             }
186         ]
187     }
188
189     Image {
190         id: zoomIn
191         x: 5
192         y: 33
193         opacity: 1.0
194         source: "qrc:/res/zoom_in.png"
195
196         MouseArea {
197             id: mouseArea1
198             anchors.fill: parent
199             onClicked: {
200                map.zoomIn()
201             }
202         }
203
204         states: [
205             State {
206                 name: "active"
207                 when: mouseArea1.pressed
208                 PropertyChanges {
209                     target: zoomIn
210                     opacity: 1.0
211                 }
212             }
213         ]
214     }
215
216     Image {
217         id: zoomOut
218         x: 5
219         y: zoomIn.y + zoomIn.height + 5
220         opacity: 1.0
221         source: "qrc:/res/zoom_out.png"
222
223         MouseArea {
224             id: mouseArea2
225             anchors.fill: parent
226             onClicked: {
227                 map.zoomOut()
228             }
229         }
230         states: [
231             State {
232                 name: "active"
233                 when: mouseArea2.pressed
234                 PropertyChanges {
235                     target: zoomOut
236                     opacity: 1.0
237                 }
238             }
239         ]
240     }
241 }