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