• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

marble

  • sources
  • kde-4.12
  • kdeedu
  • marble
  • examples
  • qml
  • where-is-that
where-is-that.qml
Go to the documentation of this file.
1 //
2 // This file is part of the Marble Virtual Globe.
3 //
4 // This program is free software licensed under the GNU LGPL. You can
5 // find a copy of this license in LICENSE.txt in the top directory of
6 // the source code.
7 //
8 // Copyright 2010 Dennis Nienhüser <earthwings@gentoo.org>
9 //
10 
11 import Qt 4.7
12 import org.kde.edu.marble 0.11
13 
14 Rectangle {
15  id: screen
16  width: 800;
17  height: 400
18 
19  Rectangle
20  {
21  id: banner
22  x: 0
23  y: 0
24  width: screen.width
25  height: 30
26  color: "yellow"
27 
28  // XmlListModel {
29  // id: questionModel
30  // source: "questions.xml"
31  // query: "/items/item"
32  // XmlRole { name: "question"; query: "question/string()" }
33  // XmlRole { name: "lon"; query: "lon/string()" }
34  // XmlRole { name: "lat"; query: "lat/string()" }
35  // }
36 
37  // @todo: XmlListModel would be nicer, but does not yet allow data access for non-views
38  ListModel {
39  id: questionModel
40  ListElement {
41  question: "Tom Sawyer paints aunt Polly's fence. Where was that?"
42  lon: -91.3775
43  lat: 39.704167
44  }
45  ListElement {
46  question: "Jonathan Harker meets Count Dracula. Where?"
47  lon: 25.370894
48  lat: 45.517444
49  }
50  ListElement {
51  question: "Henry Jekyll becomes Edward Hyde in...?"
52  lon: -0.11832
53  lat: 51.50939
54  }
55  ListElement {
56  question: "Where did Quasimodo ring the bells?"
57  lon: 2.35
58  lat: 48.852778
59  }
60  }
61 
62  Component {
63  id: questionDelegate
64  Row {
65  Text {
66  id: questionItem
67  text: question
68  font { pointSize: 12; bold: true }
69  color: "#606060"
70  }
71  }
72  }
73 
74  ListView {
75  id: questionView
76 
77  x: 10
78  y: 5
79  width: banner.width - button.width - 30
80  height: 20
81 
82  visible: false
83  clip: true
84 
85  model: questionModel
86  delegate: questionDelegate
87  }
88 
89  FloatButton
90  {
91  id: button
92  y: 2
93  anchors.left: questionView.right
94  font { pointSize: 12; bold: true }
95  color: "#606060"
96  label: "Start"
97 
98  onClicked:
99  {
100  if ( screen.state == "moving" ) {
101  screen.state = "solving"
102  } else if ( screen.state == "solving" ) {
103  if ( questionView.currentIndex < questionView.count - 1 ) {
104  questionView.visible = true
105  questionView.currentIndex = questionView.currentIndex + 1
106  screen.state = "selecting"
107  messages.text = "Select the target in the map"
108  } else {
109  screen.state = "finished"
110  messages.text = ""
111  }
112  } else if ( screen.state == "finished" ) {
113  questionView.currentIndex = 0
114  screen.state = "selecting"
115  }
116  else {
117  screen.state = "selecting"
118  }
119  }
120  }
121  }
122 
123  MouseArea
124  {
125  id: area
126  anchors.top: banner.bottom
127  width: screen.width
128  height: screen.height - banner.height
129 
130  onClicked:
131  {
132  if ( screen.state == "selecting" || screen.state == "moving" ) {
133  screen.state = "selecting"
134 
135  var opx = pointer.x
136  var opy = pointer.y
137  pointer.x = area.mouseX
138  pointer.y = area.mouseY
139  selection.x = pointer.x;
140  selection.y = pointer.y - selection.height
141  screen.state = "moving"
142  messages.text = "Done? Click 'Solve'"
143 
144  var diff = (pointer.x-opx) * (pointer.x-opx);
145  diff += (pointer.y-opy) * (pointer.y-opy);
146  if ( diff > 2000 ) {
147  animation.duration = 500
148  animation.start()
149  } else {
150  animation.duration = 100
151  }
152  }
153  }
154 
155  MarbleWidget {
156  id: map
157  width: area.width
158  height: area.height
159 
160  projection: "Mercator"
161  mapThemeId: "earth/plain/plain.dgml"
162  }
163 
164  Image
165  {
166  id: selection
167  x: 200
168  y: 200
169  source: "fixing-pin.svg"
170  visible: false
171  }
172 
173  Rectangle
174  {
175  id: pointer
176  x: 200
177  y: 200
178  width: 1
179  height: 1
180  visible: false
181  }
182 
183  PropertyAnimation {
184  id: solutionanimation
185  target: solution
186  property: "scale"
187  from: .01; to: 1
188  duration: 1500
189  }
190 
191  Image
192  {
193  id: solution
194  x: 200
195  y: 200
196  visible: false
197  source: "target.svg"
198  }
199 
200  Rectangle
201  {
202  x: 5
203  y: parent.height - 40
204  width: 300
205  height: 30
206  radius: 5
207  color: "yellow"
208 
209  Text
210  {
211  id: messages
212  x: 10
213  y: 5
214  width: 280
215  text: "Where is that?"
216  font { pointSize: 12; bold: true }
217  color: "#606060"
218  visible: true
219  }
220  }
221  }
222 
223  PropertyAnimation {
224  id: animation
225  target: selection
226  property: "scale"
227  from: .1; to: 1
228  duration: 500
229  }
230 
231  function calculateSolution()
232  {
233  var lon = questionModel.get(questionView.currentIndex).lon
234  var lat = questionModel.get(questionView.currentIndex).lat
235  var pixel = map.pixel( lon, lat )
236  solution.x = pixel.x
237  solution.y = pixel.y - solution.height
238  }
239 
240  function solve()
241  {
242  var flon = questionModel.get(questionView.currentIndex).lon
243  var flat = questionModel.get(questionView.currentIndex).lat
244  var coordinate = map.coordinate( pointer.x, pointer.y )
245  var dist = coordinate.distance( flon, flat ) / 1000
246  messages.text = "Target distance: " + dist.toFixed(1) + " km"
247  }
248 
249  states: [
250  State {
251  name: "selecting"
252  PropertyChanges { target: questionView; visible: true }
253  PropertyChanges { target: button; label: "Solve" }
254  PropertyChanges { target: button; visible: false }
255  PropertyChanges { target: solution; visible: false }
256  PropertyChanges { target: map; inputEnabled: false }
257  PropertyChanges { target: selection; visible: false }
258  StateChangeScript{ script: calculateSolution(); }
259  },
260  State {
261  name: "moving"
262  PropertyChanges { target: questionView; visible: true }
263  PropertyChanges { target: button; label: "Solve" }
264  PropertyChanges { target: button; visible: true }
265  PropertyChanges { target: solution; visible: false }
266  PropertyChanges { target: map; inputEnabled: false }
267  PropertyChanges { target: selection; visible: true; }
268  },
269  State {
270  name: "solving"
271  PropertyChanges { target: questionView; visible: true }
272  PropertyChanges { target: button; label: "Next" }
273  PropertyChanges { target: button; visible: true }
274  PropertyChanges { target: solution; visible: true }
275  PropertyChanges { target: map; inputEnabled: false }
276  PropertyChanges { target: selection; visible: true }
277  StateChangeScript{ script: solutionanimation.start(); }
278  StateChangeScript{ script: solve(); }
279  },
280  State {
281  name: "finished"
282  PropertyChanges { target: questionView; visible: true }
283  PropertyChanges { target: button; label: "Try Again" }
284  PropertyChanges { target: button; visible: true }
285  PropertyChanges { target: solution; visible: false }
286  PropertyChanges { target: messages; text: "" }
287  PropertyChanges { target: map; inputEnabled: true }
288  PropertyChanges { target: selection; visible: false }
289  }
290  ]
291 
292  transitions: [
293  Transition {
294  id: movetransition
295  from: "selecting"
296  to: "moving"
297  reversible: true
298  NumberAnimation {
299  target: selection
300  properties: "x,y"
301  duration: animation.duration
302  }
303  }
304  ]
305 
306 }
ListModel
FloatButton
Definition: explore/FloatButton.qml:11
Coordinate::distance
Q_INVOKABLE qreal distance(qreal longitude, qreal latitude) const
Distance (in meter) to the given coordinate.
Definition: Coordinate.cpp:70
Rectangle
MarbleWidget
Wraps a Marble::MarbleWidget, providing access to important properties and methods.
Definition: MarbleDeclarativeWidget.h:50
coordinate
Coordinate coordinate
Definition: tools/osm-addresses/OsmParser.cpp:38
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:38:53 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

marble

Skip menu "marble"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal