* changed options/fullmonth page to new UI
[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: fullmonth
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 "#000000"//"#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
128                 anchors.horizontalCenterOffset: 15
129                 anchors.bottomMargin: -52
130                 anchors.topMargin: 42
131                 anchors.horizontalCenter: parent.horizontalCenter
132                 anchors.bottom: parent.bottom
133                 anchors.top: parent.top
134                 cellWidth: 110; cellHeight: 50
135
136                 boundsBehavior:Flickable.DragAndOvershootBounds
137                 flickableDirection:Flickable.VerticalFlick
138
139                 model:lmodel
140                 delegate: contactDelegate
141                 focus: true
142
143                 onMovementStarted:{
144                    /* var newMonth = screen.curMonth+1;
145                     LC.reset(screen.curDay,newMonth,screen.curYear)
146                     screen.calculateLunar(screen.curDay,newMonth,screen.curYear)
147                     screen.refresh()
148                     reset()*/
149                 }
150
151             }
152
153             ListModel {
154                 id:lmodel
155
156                 Component.onCompleted: {
157                     reset()
158                 }
159
160                 function reset(){
161                     for(var i=0;i<42;i++){
162                         append({header:false,name:"",inmonths:false,day:0,month:0,year:0})
163                     }
164                 }
165
166                 ListElement {
167                                         header:true;inmonth:false;day:0;month:0;year:0
168                     name: "CN"
169                 }
170
171                 ListElement {
172                     header:true;inmonth:false;day:0;month:0;year:0
173                     name: "Hai"
174                 }
175
176                 ListElement {
177                     header:true;inmonth:false;day:0;month:0;year:0
178                     name: "Ba"
179                 }
180                 ListElement {
181                                         header:true;inmonth:false;day:0;month:0;year:0
182                     name: "Tư"
183                 }
184                 ListElement {
185                                         header:true;inmonth:false;day:0;month:0;year:0
186                     name: "Năm"
187                 }
188                 ListElement {
189                                         header:true;inmonth:false;day:0;month:0;year:0
190                     name: "Sáu"
191                 }
192                 ListElement {
193                                         header:true;inmonth:false;day:0;month:0;year:0
194                     name: "Bảy"
195                 }
196             }
197
198             Component.onCompleted: {
199             }
200
201     }
202
203     ToolBarSingle { id: toolBar; height: 50;
204         y: screen.height-78
205         width: parent.width;
206         button1Label: "Quay Về"
207         onButton1Clicked:
208         {
209             screen.state="mainscreen"
210         }
211     }
212
213     states: [
214         State {
215             name: "xemtheothang"
216             PropertyChanges {
217                 target: grid
218                 width : screen.width
219                 height: screen.height
220                 cellWidth: {
221                     if (screen.width>=800)
222                          return 110;
223                     else
224                         return 64;
225                 }
226             }
227         }
228     ]
229
230     function get_prevmonth(startfrom){
231         var cMonth=screen.curMonth;
232         var cYear=screen.curYear;
233         var pmonth = [];
234         if (cMonth == 1){
235             cMonth = 12
236             cYear--;
237         }else
238             cMonth--;
239          var daysofthemonthyear = LC.calDays(cMonth,cYear);
240         for (var i=daysofthemonthyear;i>daysofthemonthyear-startfrom;i--){
241             var lunarcl = AmLich.getLunarDate(i,cMonth,cYear)
242             pmonth.push({duong:i, am:lunarcl.day, month:cMonth, year:cYear})
243         }
244         return pmonth.reverse()
245     }
246
247     function get_nextmonth(startfrom){
248         var cMonth=screen.curMonth;
249         var cYear=screen.curYear;
250          var pmonth = [];
251         if (cMonth==12){
252             cMonth = 1;
253             cYear++;
254         }else
255             cMonth++;
256
257         for (var i=1;i<=startfrom;i++){
258           var lunarcl = AmLich.getLunarDate(i,cMonth,cYear)
259             pmonth.push({duong:i, am:lunarcl.day, month:cMonth, year:cYear});
260         }
261            return pmonth.reverse();
262     }
263
264     function reset(){
265         var firstdayofthemonthyear = AmLich.getLunarDate(1,screen.curMonth,screen.curYear).jd;
266         var startfrom = (firstdayofthemonthyear+1)%7;
267         var daysofthemonthyear = LC.calDays(screen.curMonth,screen.curYear);
268         var j=1;
269
270         var totalslot = 42;
271
272         var nextmonth = get_nextmonth(totalslot - (startfrom+daysofthemonthyear))
273         var prevmonth = get_prevmonth(startfrom)
274
275         var dayclick, monthclick, yearclick;
276
277         while(lmodel.count>7){
278             lmodel.remove(lmodel.count-1);
279         }
280
281         var datas1,datas,lunarclmonth,inmonths;
282
283         for (var i=7;i<49;i++){
284             var realnumber = i - 7;
285             if (realnumber >= startfrom && j<= daysofthemonthyear){
286             var lunarcl = AmLich.getLunarDate(j,screen.curMonth,screen.curYear)
287             if (lunarcl.day==1){
288                 lunarclmonth = "/"+lunarcl.month
289             }else{
290                 lunarclmonth = ""
291             }
292
293             datas = j+"<br><span style='font-size:18px;float:right;color:#700070;'>&nbsp;&nbsp;"+lunarcl.day+lunarclmonth+"</span>";
294             dayclick = j;
295             monthclick = screen.curMonth;
296             yearclick = screen.curYear;
297             inmonths = true;
298                 j++;
299             }else{
300                 if (realnumber<startfrom){
301                     datas1= prevmonth[realnumber];
302                 }else
303                 {
304                     datas1=nextmonth[(totalslot-realnumber)-1];
305                 }
306                 dayclick = datas1.duong;
307                 monthclick = datas1.month;
308                 yearclick = datas1.year;
309                 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>";
310                 inmonths=false;
311             }
312
313             lmodel.append({header:false,name:datas,inmonth:inmonths,day:dayclick,month:monthclick,year:yearclick})
314         }
315     }
316 }