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