summaryrefslogtreecommitdiff
path: root/metawatchwatchlets/metawatch-digital-watchface.qml
blob: 68af34c6d96e77006592dea6d9047f90ae0e05e3 (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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
import QtQuick 1.0
import com.javispedro.sowatch 1.0
import com.javispedro.sowatch.metawatch 1.0

MWPage {
	id: page

	Column {
		Item {
			id: systemArea
			// Firmware draws top 30 lines;
			// ensure we do not draw anything on top
			width: page.width
			height: 30
		}

		Image {
			width: page.width
			height: 2
			source: "idle-border.png"
		}

		Row {
			width: page.width
			height: 30

			Text {
				id: labelForecast
				width: 36
				anchors.verticalCenter: parent.verticalCenter
				font.family: "MetaWatch Small caps 8pt"
				font.pixelSize: 8
				wrapMode: Text.Wrap
			}

			Image {
				id: iconForecast
				anchors.verticalCenter: parent.verticalCenter
				width: 24
			}

			Text {
				id: labelTemperature
				width: 36
				anchors.verticalCenter: parent.verticalCenter
				font.family: "MetaWatch Large 16pt"
				font.pixelSize: 16
				wrapMode: Text.Wrap
			}
		}

		Image {
			width: page.width
			height: 2
			source: "idle-border.png"
		}

		Item {
			width: page.width
			height: 2
		}

		Row {
			anchors.horizontalCenter: parent.horizontalCenter
			height: 30
			spacing: 8
			Column {
				spacing: 2
				Image {
					width: 24
					height: 18
					source: "idle-call.png"
				}
				Text {
					id: labelCalls
					anchors.horizontalCenter: parent.horizontalCenter
					font.family: "MetaWatch Large caps 8pt"
					font.pixelSize: 8
					text: "0"
				}
			}
			Column {
				spacing: 2
				Image {
					width: 24
					height: 18
					source: "idle-msg.png"
				}
				Text {
					id: labelMsgs
					anchors.horizontalCenter: parent.horizontalCenter
					font.family: "MetaWatch Large caps 8pt"
					font.pixelSize: 8
					text: "0"
				}
			}
			Column {
				spacing: 2
				Image {
					width: 24
					height: 18
					source: "idle-mail.png"
				}
				Text {
					id: labelMails
					anchors.horizontalCenter: parent.horizontalCenter
					font.family: "MetaWatch Large caps 8pt"
					font.pixelSize: 8
					text: "0"
				}
			}
		}
	}

	function _getImageForWeather(type) {
		switch (type) {
		case WeatherNotification.Sunny:
			return "weather-sunny.png";
		case WeatherNotification.PartlyCloudy:
		case WeatherNotification.Cloudy:
		case WeatherNotification.Fog:
			return "weather-cloudy.png";
		case WeatherNotification.Rain:
			return "weather-rain.png";
		case WeatherNotification.Thunderstorm:
			return "weather-thunderstorm.png";
		case WeatherNotification.Snow:
			return "weather-snow.png";
		}
	}

	function updateUnreadCounts() {
		labelCalls.text = notifications.fullCountByType(Notification.MissedCallNotification);
		labelMsgs.text = notifications.fullCountByType(Notification.SmsNotification) +
				notifications.fullCountByType(Notification.MmsNotification) +
				notifications.fullCountByType(Notification.ImNotification);
		labelMails.text = notifications.fullCountByType(Notification.EmailNotification);
	}

	function updateWeather() {
		var weather = notifications.getMostRecentByType(Notification.WeatherNotification);
		if (weather) {
			var unit = weather.temperatureUnits == WeatherNotification.Celsius ? "°C" : "°F";
			labelForecast.text = weather.body
			labelTemperature.text = weather.temperature + unit
			iconForecast.source = _getImageForWeather(weather.forecast)
		} else {
			labelForecast.text = ""
			labelTemperature.text = ""
			iconForecast.source = ""
		}
	}

	function update() {
		updateUnreadCounts();
		updateWeather();
	}

	Connections {
		target: notifications
		onModelChanged: update();
	}
}