Source init for master branch.
[lichviet] / qml / LichViet / FullMonth.qml
1 /*
2 Copyright (C) 2011  by Cuong Le <metacuong@gmail.com>
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, either version 3 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program.  If not, see <http://www.gnu.org/licenses/>
16 */
17
18 import QtQuick 1.0
19 import "../DatePicker/component" as Comp
20 import "amlich-hnd.js" as AmLich
21
22 Item{
23     id: item1
24
25     Rectangle{
26         id: fullmonthREC
27         anchors.fill: parent; anchors.bottomMargin: 0
28         visible: true
29         opacity:0.9
30
31             Component {
32                 id: contactDelegate
33                 Item {
34                     width: grid.cellWidth; height: {
35                         if (header)
36                             return grid.cellHeight - 15;
37                         else return grid.cellHeight;
38                     }
39                     Rectangle {
40                         anchors.fill: parent;anchors.rightMargin: 2;anchors.topMargin: 2;
41                         Text { color: {
42                                 if (header)
43                                   return  "#000000";
44                                 else
45                                     return "#007070"
46                             }
47
48                             text: name; anchors.horizontalCenter: parent.horizontalCenter
49                             font.pixelSize: 21;font.bold: true;font.family: "Tahoma"
50                             anchors.topMargin: 0;
51                         }
52
53                         color: {
54                             if (header)
55                                 return "#FAFAFF";
56                             else{
57                                 if (inmonth){
58                                     if (day==initcurDay && month==initcurMonth && year==initcurYear)
59                                         return "#00EBEB";
60                                     else
61                                       return "lightsteelblue";
62                                 }
63                                 else
64                                     return "#AAAAAA";
65                             }
66                         }
67                          radius: 4
68                          MouseArea{
69                              id:fullmonthMouse
70                              anchors.fill: parent
71
72                              onClicked: {
73                                if (index >= 7){
74                                    LC.reset(day,month,year)
75                                    screen.calculateLunar(day,month,year)
76                                    screen.state="mainscreen"
77                                    screen.refresh()
78                                    maindatemodel.reset()
79                                    txtDATEpv.currentIndex = day-1;
80                                }
81                              }
82
83 onPressed:{
84     if (index >= 7)
85         parent.color="#F0F0F0"
86 }
87
88 onReleased:{
89       if (index >= 7){
90           if (inmonth){
91               if (day==initcurDay && month==initcurMonth && year==initcurYear)
92                   parent.color="#00EBEB";
93               else
94                   parent.color="lightsteelblue";
95           }else
96               parent.color="#AAAAAA";
97       }
98 }
99
100 onCanceled:{
101     if (index >= 7){
102         if (inmonth)
103         {if (day==initcurDay && month==initcurMonth && year==initcurYear) parent.color="#00EBEB"; else parent.color="lightsteelblue";}
104         else
105          parent.color="#AAAAAA";
106     }
107
108 }
109
110                          }
111                     }
112                 }
113             }
114
115             GridView {
116                 id: grid
117                 x: -335
118                 y: 41
119                 width: {
120                     800
121                 }
122
123                 height: {
124                     480
125                 }
126
127                 anchors.horizontalCenterOffset: 15
128                 anchors.bottomMargin: -52
129                 anchors.topMargin: 42
130                 anchors.horizontalCenter: parent.horizontalCenter
131                 anchors.bottom: parent.bottom
132                 anchors.top: parent.top
133                 cellWidth: 110; cellHeight: 50
134                 //Dung : 64 | Nam :110
135                 model:lmodel
136                 delegate: contactDelegate
137                 focus: false
138             }
139
140             ListModel {
141                 id:lmodel
142
143                 Component.onCompleted: {
144                     reset()
145                 }
146
147                 function reset(){
148                     for(var i=0;i<42;i++){
149                         append({header:false,name:"",inmonths:false,day:0,month:0,year:0})
150                     }
151                 }
152
153                 ListElement {
154                                         header:true;inmonth:false;day:0;month:0;year:0
155                     name: "CN"
156                 }
157
158                 ListElement {
159                     header:true;inmonth:false;day:0;month:0;year:0
160                     name: "Hai"
161                 }
162
163                 ListElement {
164                     header:true;inmonth:false;day:0;month:0;year:0
165                     name: "Ba"
166                 }
167                 ListElement {
168                                         header:true;inmonth:false;day:0;month:0;year:0
169                     name: "Tư"
170                 }
171                 ListElement {
172                                         header:true;inmonth:false;day:0;month:0;year:0
173                     name: "Năm"
174                 }
175                 ListElement {
176                                         header:true;inmonth:false;day:0;month:0;year:0
177                     name: "Sáu"
178                 }
179                 ListElement {
180                                         header:true;inmonth:false;day:0;month:0;year:0
181                     name: "Bảy"
182                 }
183             }
184
185             Component.onCompleted: {
186             }
187
188     }
189
190     ToolBarSingle { id: toolBar; height: 50;
191         y: screen.height-78
192         width: parent.width;
193         button1Label: "Quay Về"
194         onButton1Clicked:
195         {
196             screen.state="mainscreen"
197         }
198     }
199
200     transitions: [
201         Transition { NumberAnimation { properties: "x,y,opacity"; duration: 500; easing.type: Easing.InOutBack } }
202     ]
203
204     states: [
205         State {
206             name: "xemtheothang"
207             PropertyChanges {
208                 target: grid
209                 width : screen.width
210                 height: screen.height
211                 cellWidth: {
212                     if (screen.width>=800)
213                          return 110;
214                     else
215                         return 64;
216                 }
217             }
218         }
219     ]
220
221     function get_prevmonth(startfrom){
222         var cMonth=screen.curMonth;
223         var cYear=screen.curYear;
224         var pmonth = [];
225         if (cMonth == 1){
226             cMonth = 12
227             cYear--;
228         }else
229             cMonth--;
230          var daysofthemonthyear = LC.calDays(cMonth,cYear);
231         for (var i=daysofthemonthyear;i>daysofthemonthyear-startfrom;i--){
232             var lunarcl = AmLich.getLunarDate(i,cMonth,cYear)
233             pmonth.push({duong:i, am:lunarcl.day, month:cMonth, year:cYear})
234         }
235         return pmonth.reverse()
236     }
237
238     function get_nextmonth(startfrom){
239         var cMonth=screen.curMonth;
240         var cYear=screen.curYear;
241          var pmonth = [];
242         if (cMonth==12){
243             cMonth = 1;
244             cYear++;
245         }else
246             cMonth++;
247
248         for (var i=1;i<=startfrom;i++){
249           var lunarcl = AmLich.getLunarDate(i,cMonth,cYear)
250             pmonth.push({duong:i, am:lunarcl.day, month:cMonth, year:cYear});
251         }
252            return pmonth.reverse();
253     }
254
255     function reset(){
256         var firstdayofthemonthyear = AmLich.getLunarDate(1,screen.curMonth,screen.curYear).jd;
257         var startfrom = (firstdayofthemonthyear+1)%7;
258         var daysofthemonthyear = LC.calDays(screen.curMonth,screen.curYear);
259         var j=1;
260
261         var totalslot = 42;
262
263         var nextmonth = get_nextmonth(totalslot - (startfrom+daysofthemonthyear))
264         var prevmonth = get_prevmonth(startfrom)
265
266         var dayclick, monthclick, yearclick;
267         console.log(lmodel.count)
268
269         while(lmodel.count>7){
270             lmodel.remove(lmodel.count-1);
271         }
272
273         for (var i=7;i<49;i++){
274             var realnumber = i - 7;
275             if (realnumber >= startfrom && j<= daysofthemonthyear){
276             var lunarcl = AmLich.getLunarDate(j,screen.curMonth,screen.curYear)
277             if (lunarcl.day==1){
278                 var lunarclmonth = "/"+lunarcl.month
279             }else{
280                 var lunarclmonth = ""
281             }
282
283             var datas = j+"<br><span style='font-size:18px;float:right;color:#700070;'>&nbsp;&nbsp;"+lunarcl.day+lunarclmonth+"</span>";
284             dayclick = j;
285             monthclick = screen.curMonth;
286             yearclick = screen.curYear;
287             var inmonths = true;
288                 j++;
289             }else{
290                 if (realnumber<startfrom){
291                     var datas1= prevmonth[realnumber];
292                 }else
293                 {
294                     var datas1=nextmonth[(totalslot-realnumber)-1];
295                 }
296                 dayclick = datas1.duong;
297                 monthclick = datas1.month;
298                 yearclick = datas1.year;
299                 var datas = "<span style='color:grey;font-weight:normal;'>"+datas1.duong+"</span><br><span style='font-size:18px;float:right;color:#CCFFFF;'>&nbsp;&nbsp;"+datas1.am+"</span>";
300                 var inmonths=false;
301             }
302
303             lmodel.append({header:false,name:datas,inmonth:inmonths,day:dayclick,month:monthclick,year:yearclick})
304         }
305     }
306 }