~feng-kylin/youker-assistant/youker-assistant

« back to all changes in this revision

Viewing changes to qml/func/others/WeatherZone.qml

  • Committer: kobe
  • Date: 2015-02-13 07:37:10 UTC
  • Revision ID: xiangli@ubuntukylin.com-20150213073710-0jyp02ilyi5njj10
Qt Version

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright (C) 2013 ~ 2014 National University of Defense Technology(NUDT) & Kylin Ltd.
3
 
 *
4
 
 * This program is free software; you can redistribute it and/or modify
5
 
 * it under the terms of the GNU General Public License as published by
6
 
 * the Free Software Foundation; version 3.
7
 
 *
8
 
 * This program is distributed in the hope that it will be useful,
9
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 
 * GNU General Public License for more details.
12
 
 *
13
 
 * You should have received a copy of the GNU General Public License
14
 
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
15
 
 */
16
 
 
17
 
import QtQuick 1.1
18
 
import "../common" as Common
19
 
 
20
 
Rectangle {
21
 
    id: weahterzone
22
 
    width: 208;height: 147
23
 
    SystemPalette { id: myPalette; colorGroup: SystemPalette.Active }
24
 
    color: "transparent"
25
 
 
26
 
    //当启动时没有网络的时候,设置默认界面
27
 
    function setDefaultWeather() {
28
 
        weatherIcon.source = "../../img/weather/d0.gif"
29
 
        weatherText.text = qsTr("Weather");//天气
30
 
        pmText.text = qsTr("AQI");//空气质量指数
31
 
        tempText.text = qsTr("Current temperature");//当前温度(℃)
32
 
    }
33
 
 
34
 
    //设置天气数据到QML界面上
35
 
    function resetCurrentWeather() {
36
 
        var ptime = sessiondispatcher.getSingleWeatherInfo("ptime", "current");//eg: 08:00
37
 
        var need_str = ptime.substr(0, ptime.lastIndexOf(":"));//eg: 08
38
 
        //将字符串类型的时间转成整形
39
 
        var pIntTime = parseInt(need_str, 10);//eg: 8
40
 
        if(pIntTime > 7 && pIntTime < 20) {
41
 
            var img1 = sessiondispatcher.getSingleWeatherInfo("img1", "current");
42
 
            weatherIcon.source = sessiondispatcher.getSingleWeatherInfo(img1, "weathericon");
43
 
        }
44
 
        else {
45
 
            var img2 = sessiondispatcher.getSingleWeatherInfo("img2", "current");
46
 
            weatherIcon.source = sessiondispatcher.getSingleWeatherInfo(img2, "weathericon");
47
 
        }
48
 
        locationText.text = sessiondispatcher.getSingleWeatherInfo("city", "current");
49
 
        ptimeText.text = sessiondispatcher.getSingleWeatherInfo("time", "current") + qsTr(" ");// 发布
50
 
        weatherText.text = sessiondispatcher.getSingleWeatherInfo("weather", "current");
51
 
        pmText.text = qsTr("AQI:") + sessiondispatcher.getSingleWeatherInfo("aqi", "current");;//空气质量指数:
52
 
        tempText.text = qsTr("Current temperature:") + sessiondispatcher.getSingleWeatherInfo("temp", "current") + "℃";//当前温度:
53
 
    }
54
 
 
55
 
    //设置yahoo天气到界面上
56
 
    function resetCurrentYahooWeather() {
57
 
        weatherIcon.source = "http://l.yimg.com/a/i/us/we/52/" + sessiondispatcher.getSingleWeatherInfo("code", "yahoo") + ".gif";
58
 
        locationText.text = sessiondispatcher.getSingleWeatherInfo("city", "yahoo");//城市
59
 
        ptimeText.text = "";
60
 
        pmText.text = sessiondispatcher.getSingleWeatherInfo("time", "yahoo");//发布时间
61
 
        weatherText.text = sessiondispatcher.getSingleWeatherInfo("text", "yahoo");//当前天气
62
 
        tempText.text = qsTr("Current temperature:") + sessiondispatcher.getSingleWeatherInfo("temp", "yahoo");//当前温度:
63
 
    }
64
 
 
65
 
    Connections
66
 
    {
67
 
        target: sessiondispatcher
68
 
        onStartUpdateForecastWeahter: {
69
 
            if(flag == "weather") {
70
 
                weahterzone.resetCurrentWeather();
71
 
            }
72
 
            else if(flag == "yahoo") {
73
 
                weahterzone.resetCurrentYahooWeather();
74
 
            }
75
 
        }
76
 
 
77
 
        //用户修改了城市时更新
78
 
        onStartChangeQMLCity: {
79
 
            sessiondispatcher.get_current_weather_qt();
80
 
        }
81
 
    }
82
 
 
83
 
    Component.onCompleted: {
84
 
        weahterzone.setDefaultWeather();
85
 
        sessiondispatcher.get_current_weather_qt();//0104
86
 
    }
87
 
    Text {
88
 
        id: locationText
89
 
        text: qsTr("City")//城市
90
 
        font.bold: true
91
 
        font.pixelSize: 14
92
 
        color: "#383838"
93
 
        anchors.left: parent.left
94
 
    }
95
 
    Common.StyleButton {
96
 
        id: changeCityBtn
97
 
        anchors.left: locationText.right
98
 
        wordname: qsTr("[Change]")//[切换]
99
 
        width: 60
100
 
        height: locationText.height
101
 
        onClicked: {
102
 
            sessiondispatcher.showWizardController();
103
 
        }
104
 
    }
105
 
 
106
 
    Text {
107
 
        id: ptimeText
108
 
        text: qsTr("Publish")//发布时间
109
 
        font.bold: true
110
 
        font.pixelSize: 14
111
 
        color: "#383838"
112
 
        anchors.right: parent.right
113
 
    }
114
 
    Image {
115
 
        id: weatherIcon
116
 
        anchors {
117
 
            top: ptimeText.bottom
118
 
            topMargin: 5
119
 
            right: parent.right
120
 
        }
121
 
        width: 48; height: 48
122
 
        source: ""
123
 
     }
124
 
    Row {
125
 
        anchors.top: parent.top
126
 
        anchors.topMargin: 25
127
 
        spacing: 15
128
 
 
129
 
        Column {
130
 
            spacing: 5
131
 
            Text {
132
 
                id: weatherText
133
 
                text: qsTr("N/A")//未知
134
 
                font.pixelSize: 12
135
 
                color: "#7a7a7a"
136
 
            }
137
 
            Text {
138
 
                id: pmText
139
 
                text: qsTr("AQI:N/A")//空气质量指数:未知
140
 
                font.pixelSize: 12
141
 
                color: "#7a7a7a"
142
 
            }
143
 
            Text {
144
 
                id: tempText
145
 
                text: qsTr("Temperature:N/A")//温度:未知
146
 
                font.pixelSize: 12
147
 
                color: "#7a7a7a"
148
 
            }
149
 
        }
150
 
    }
151
 
//    Timer{
152
 
//        id: updateTime
153
 
//        interval: 600000;running: true;repeat: true
154
 
//        onTriggered: {
155
 
//            sessiondispatcher.get_current_weather_qt();
156
 
////            console.log(Qt.formatDateTime(new Date(), "dddd\nyyyy-MM-dd\n-MMM-\nhh-mm-ss"));
157
 
//        }
158
 
//    }
159
 
}