• 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
  • src
  • apps
  • marble-touch
  • activities
Weather.qml
Go to the documentation of this file.
1 // This file is part of the Marble Virtual Globe.
2 //
3 // This program is free software licensed under the GNU LGPL. You can
4 // find a copy of this license in LICENSE.txt in the top directory of
5 // the source code.
6 //
7 // Copyright 2011 Dennis Nienhüser <earthwings@gentoo.org>
8 // Copyright 2011 Daniel Marth <danielmarth@gmx.at>
9 
10 import QtQuick 1.0
11 import com.nokia.meego 1.0
12 import org.kde.edu.marble 0.11
13 import ".."
14 
15 /*
16  * Page for the weather activity.
17  */
18 Page {
19  id: weatherActivityPage
20  anchors.fill: parent
21 
22  property bool horizontal: width / height > 1.20
23 
24  tools: ToolBarLayout {
25  MarbleToolIcon {
26  iconSource: main.icon( "actions/go-home", 48 );
27  onClicked: main.showNavigation()
28  }
29  MarbleToolIcon {
30  iconSource: main.icon( "places/user-identity", 48 );
31  onClicked: {
32  marbleWidget.centerOn( marbleWidget.tracking.lastKnownPosition.longitude, marbleWidget.tracking.lastKnownPosition.latitude )
33  if (marbleWidget.zoom < 403 ) {
34  marbleWidget.zoom = 22026
35  }
36  }
37  }
38 
39  ToolButton {
40  id: favoriteButton
41  checkable: true
42  checked: marbleWidget.renderPlugin("weather").favoriteItemsOnly
43  width: 60
44  flat: true
45  iconSource: main.icon( "places/favorites", 48 );
46  onCheckedChanged: marbleWidget.renderPlugin("weather").favoriteItemsOnly = checked
47  }
48 
49  ToolButton {
50  id: searchButton
51  checkable: true
52  checked: false
53  width: 60
54  flat: true
55  iconSource: main.icon( "actions/edit-find", 48 );
56  }
57  }
58 
59  SearchField {
60  id: searchField
61  anchors.left: parent.left
62  anchors.right: parent.right
63  anchors.top: parent.top
64  visible: searchButton.checked
65  onSearch: {
66  searchField.busy = true
67  marbleWidget.find( term )
68  }
69 
70  Component.onCompleted: {
71  marbleWidget.search.searchFinished.connect( searchFinished )
72  }
73 
74  function searchFinished() {
75  searchField.busy = false
76  }
77  }
78 
79  Rectangle {
80  id: stationDetails
81  property bool minimized: station === ""
82  visible: !minimized
83 
84  property string identifier
85  property string station
86  property double temperature
87  property string image
88  property string description
89  property bool favorite: false
90 
91  anchors.bottom: weatherActivityPage.bottom
92  anchors.left: weatherActivityPage.left
93  width: weatherActivityPage.horizontal ? (minimized ? 0 : weatherActivityPage.width / 2) : weatherActivityPage.width
94  height: weatherActivityPage.horizontal ? weatherActivityPage.height : (minimized ? 0 : 20 + label.height + Math.max(descriptionLabel.height, icon.height))
95 
96  radius: 5
97  border.color: "darkgray"
98  border.width: 2
99 
100  Item {
101  anchors.fill: parent
102  anchors.margins: 10
103 
104  ToolButton {
105  id: bookmarkButton
106  anchors.right: parent.right
107 
108  iconSource: stationDetails.favorite ? "qrc:/icons/bookmark.png" : "qrc:/icons/bookmark-disabled.png"
109 
110  width: 32
111  height: 32
112  flat: true
113 
114  onClicked: stationDetails.favorite = !stationDetails.favorite
115  }
116 
117  Label {
118  id: label
119  text: stationDetails.temperature + " °C " + stationDetails.station
120  anchors.left: parent.left
121  anchors.right: bookmarkButton.left
122  wrapMode: Text.Wrap
123  }
124 
125  Text {
126  id: descriptionLabel
127  anchors.margins: 10
128  anchors.top: label.bottom
129  anchors.left: icon.right
130  text: stationDetails.description
131  }
132 
133  Image {
134  id: icon
135  anchors.top: label.bottom
136  source: stationDetails.image !== "" ? ("file://" + stationDetails.image) : ""
137  }
138  }
139 
140  Behavior on height {
141  enabled: !weatherActivityPage.horizontal;
142  NumberAnimation {
143  easing.type: Easing.InOutQuad;
144  duration: 250
145  }
146  }
147  }
148 
149  Item {
150  id: mapContainer
151  anchors.left: weatherActivityPage.horizontal ? stationDetails.right : weatherActivityPage.left
152  anchors.bottom: weatherActivityPage.horizontal ? weatherActivityPage.bottom : stationDetails.top
153  anchors.right: weatherActivityPage.right
154  anchors.top: searchButton.checked ? searchField.bottom : weatherActivityPage.top
155  clip: true
156 
157  function embedMarbleWidget() {
158  marbleWidget.parent = mapContainer
159  settings.projection = "Spherical"
160  var plugins = settings.defaultRenderPlugins
161  plugins.push( "weather" )
162  settings.activeRenderPlugins = plugins
163  settings.mapTheme = settings.streetMapTheme
164  settings.gpsTracking = true
165  settings.showPositionIndicator = false
166  settings.showTrack = false
167  marbleWidget.tracking.positionMarkerType = Tracking.Circle
168  marbleWidget.visible = true
169  marbleWidget.setDataPluginDelegate( "weather", weatherDelegate )
170  }
171 
172  Component.onDestruction: {
173  marbleWidget.setDataPluginDelegate( "weather", 0 )
174  if ( marbleWidget.parent === mapContainer ) {
175  marbleWidget.parent = null
176  marbleWidget.visible = false
177  }
178  }
179  }
180 
181  onStatusChanged: {
182  if ( status === PageStatus.Activating ) {
183  mapContainer.embedMarbleWidget()
184  }
185  }
186 
187  Rectangle {
188  anchors.top: parent.top
189  anchors.left: parent.left
190  anchors.topMargin: 30
191  anchors.leftMargin: 15
192  width: legend.width
193  height: legend.height
194  radius: 5
195  color: Qt.rgba(192/255, 192/255, 192/255, 192/255)
196  border.width: 1
197  border.color: "black"
198  smooth: true
199 
200  Column {
201  id: legend
202  x: 6
203  y: 6
204  width: 60
205  height: items*(10+spacing)+2*x
206  property int items: 22
207  spacing: 2
208 
209  Repeater {
210  id: repeater
211  model: parent.items
212 
213  Row {
214  spacing: 4
215  height: 10
216  property int temperature: -3*index+36
217 
218  Rectangle {
219  anchors.verticalCenter: parent.verticalCenter
220  width: 10
221  height: 10
222  radius: 3
223  smooth: true
224  color: Qt.hsla( weatherActivityPage.temperatureToHue(parent.temperature)/255.0, 1.0, 0.5, 1.0 )
225  }
226 
227  Text {
228  text: parent.temperature + " °C"
229  width: 34
230  horizontalAlignment: Text.AlignRight
231  anchors.verticalCenter: parent.verticalCenter
232  }
233  }
234  }
235  }
236  }
237 
238  Component {
239  id: weatherDelegate
240  Item {
241  id: containerItem
242  width: Math.max(icon.width, label.width)
243  height: Math.max(icon.height, label.height)
244  clip: true
245  property bool showDetails: false
246 
247  Image {
248  id: icon
249  z: 0
250  width: 64
251  scale: 0.0
252  smooth: true
253  fillMode: Image.PreserveAspectFit
254  source: image !== "" ? ("file://" + image) : ""
255 
256  MouseArea {
257  anchors.fill: parent
258  onClicked: containerItem.updateDetails()
259  }
260  }
261 
262  Text {
263  id: label
264  z: 0
265  visible: !icon.visible
266  anchors.centerIn: parent
267  font.pixelSize: 24
268  style: Text.Outline;
269  font.bold: true
270  color: Qt.hsla( weatherActivityPage.temperatureToHue(temperature)/255.0, 1.0, 0.5, 1.0 )
271  styleColor: "black"
272  text: temperature.toFixed(0) + " °C"
273 
274  MouseArea {
275  anchors.fill: parent
276  onClicked: containerItem.updateDetails()
277  }
278  }
279 
280  SequentialAnimation {
281  id: appearAnimation
282  PauseAnimation { duration: Math.random() * 100 }
283  NumberAnimation {
284  target: icon
285  property: "scale"
286  to: 1.0
287  duration: 150
288  }
289  }
290 
291  function updateDetails() {
292  stationDetails.identifier = identifier
293  stationDetails.favorite = favorite
294  stationDetails.station = station
295  stationDetails.description = description
296  stationDetails.image = image
297  stationDetails.temperature = temperature
298  }
299 
300  Connections {
301  target: stationDetails
302  onFavoriteChanged: {
303  if (stationDetails.identifier === identifier) {
304  favorite = stationDetails.favorite
305  }
306  }
307  }
308 
309  Component.onCompleted: {
310  icon.visible = image !== "" && Math.random() >= 0.3
311  appearAnimation.running = true
312  }
313  }
314  }
315 
316  function temperatureToHue(temperature) {
317  var factor = temperature > 20 ? 1.8 : ( temperature > 5 ? 2.1 : 2.7 )
318  return -factor*(Math.max(-40, Math.min(40, temperature))-40)
319  }
320 }
Tracking
Definition: Tracking.qml:16
ToolButton
SearchField
Definition: SearchField.qml:14
Rectangle
Tracking::Circle
Definition: Tracking.h:48
Item
MarbleWindow::icon
void icon(name, size)
MarbleToolIcon
Definition: harmattan/MarbleToolIcon.qml:10
MarbleWindow::showNavigation
void showNavigation()
main
Definition: main.qml:12
SearchField::busy
bool busy
Definition: SearchField.qml:19
Page
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