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