~fginther/ubuntu-weather-app/cmake-plus-weather-channel-2

« back to all changes in this revision

Viewing changes to components/CurrentWeather.qml

  • Committer: Martin Borho
  • Date: 2014-01-22 22:02:58 UTC
  • Revision ID: martin@borho.net-20140122220258-zmreq3ms4bram24i
TWC, for real this time

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
 
27
27
    // For Status I take the same condition codes from OpenWeatherMap (http://openweathermap.org/wiki/API/Weather_Condition_Codes)
28
28
    property string icon
29
 
    property int currentTemp
30
 
    property int minTemp
31
 
    property int maxTemp
 
29
    property string currentTemp
 
30
    property string minTemp
 
31
    property string maxTemp
32
32
    property bool showMaxTemp
33
33
    property int windSpeed
34
34
    property string windDir
35
35
    property int humidity
36
36
    property real precipitation
37
37
    property string propPrecip
 
38
    property string precipType
 
39
    property string uvIndex
38
40
    property int pressure
39
41
    property variant hourly
40
42
    property string tempScale: (mainView.settings["units"] === "imperial") ? "F" : "C"
45
47
    anchors.fill: parent
46
48
    anchors.horizontalCenter: parent.horizontalCenter
47
49
 
 
50
    function getProcipLabel() {
 
51
        // show the right Label, depending on precipitation type
 
52
        return (precipType === "snow") ? i18n.tr("Chance of Snow") : i18n.tr("Chance of Rain")
 
53
    }
 
54
 
 
55
    function getUvLabel() {
 
56
        var label = "",
 
57
            uvInt = parseInt(uvIndex);
 
58
        if(uvInt <= 2) {
 
59
            label = i18n.tr("Low");
 
60
        } else if(uvInt <= 5) {
 
61
            label = i18n.tr("Moderate");
 
62
        } else if(uvInt <= 8) {
 
63
            label = i18n.tr("High");
 
64
        } else if(uvInt <= 10) {
 
65
            label = i18n.tr("Very high");
 
66
        } else {
 
67
            label = i18n.tr("Extreme");
 
68
        }
 
69
        return label;
 
70
    }
 
71
 
48
72
    Flipable {
49
73
            id: flipable
50
74
            height: parent.height
190
214
 
191
215
                            Components.WeatherDetailComponent {
192
216
                                value: (currentWeather.propPrecip !== "") ? currentWeather.propPrecip: currentWeather.pressure
193
 
                                measure: (currentWeather.propPrecip !== "") ? i18n.tr("Chance of Rain") : i18n.tr("Pressure")
 
217
                                measure: (currentWeather.propPrecip !== "") ?  getProcipLabel(): i18n.tr("Pressure")
194
218
                                unit: (currentWeather.propPrecip !== "") ? i18n.tr("Percent") : i18n.tr("mbar")
195
219
                                anchors.fill: parent
196
220
                            }
205
229
 
206
230
                            Components.WeatherDetailComponent {
207
231
                                objectName: "PrecipitationValue"
208
 
                                value: currentWeather.precipitation
209
 
                                measure: i18n.tr("Precipitation")
210
 
                                unit: currentWeather.precipScale
 
232
                                value: (currentWeather.uvIndex !== "") ? currentWeather.uvIndex : currentWeather.precipitation
 
233
                                measure: (currentWeather.uvIndex !== "") ? i18n.tr("UV index"): i18n.tr("Precipitation")
 
234
                                unit: (currentWeather.uvIndex !== "") ? getUvLabel() : i18n.tr("Percent");
211
235
                                anchors.fill: parent
212
236
                            }
213
237
                        }