summaryrefslogtreecommitdiff
path: root/qmapwatchlet/compass-metawatch-digital.qml
blob: 37d6e1137809786d544508975794916d02f54bfd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import QtQuick 1.0
import QtMobility.location 1.2
import com.javispedro.sowatch.metawatch 1.0
import com.javispedro.sowatch.qmap 1.0

MWPage {
	id: page

	function formatSpeed(speed) {
		var kmh = speed * 3.6;
		if (kmh < 0 || isNaN(kmh)) {
			return "";
		} else if (kmh < 10) {
			return kmh.toFixed(1);
		} else {
			return kmh.toFixed(0);
		}
	}

	function formatAltitude(alt) {
		if (isNaN(alt)) {
			return "";
		} else {
			return alt.toFixed(0);
		}
	}

	Column {
		anchors.top: parent.top
		width: parent.width

		spacing: 2

		MWTitle {
			text: qsTr("Compass")
			icon.source: "compass-icon.png"
		}

		CompassView {
			anchors.horizontalCenter: parent.horizontalCenter
			id: compass
			updateEnabled: watch.active
			updateInterval: 3000
			width: 48
			height: 48
		}

		Row {
			Column {
				width: page.width / 2
				id: speedColumn

				MWLabel {
					anchors.horizontalCenter: parent.horizontalCenter
					text: qsTr("Speed")
				}
				Row {
					anchors.horizontalCenter: parent.horizontalCenter
					spacing: 2
					MWLabel {
						id: speedLabel
						anchors.top: parent.top
						text: formatSpeed(compass.currentSpeed)
						font.pointSize: 12
					}
					MWLabel {
						anchors.top: parent.top
						text: altitudeLabel.text ? qsTr("km<br>h") : "";
						font.family: "MetaWatch Small caps 8pt"
						font.pointSize: 6
					}
				}
			}
			Column {
				width: page.width / 2
				id: altitudeColumn

				MWLabel {
					anchors.horizontalCenter: parent.horizontalCenter
					text: qsTr("Altitude")
				}
				Row {
					anchors.horizontalCenter: parent.horizontalCenter
					spacing: 2
					MWLabel {
						id: altitudeLabel
						anchors.top: parent.top
						text: formatAltitude(compass.currentAltitude)
						font.pointSize: 12
					}
					MWLabel {
						anchors.top: parent.top
						text: altitudeLabel.text ? qsTr("m") : "";
						font.family: "MetaWatch Small caps 8pt"
						font.pointSize: 6
					}
				}
			}
		}
	}
}