bf570b4bd0f2c65b09c5216673a422d50154e493
[lichviet] / qml / LichViet / main.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 "amlich-hnd.js" as AmLich
20 import "amlich-aa98.js" as AmLich98
21
22 import "Settings.js" as Settings
23 import "Themes.js" as Themes
24 import "CacNgayLeTrongNam.js" as CNLTN
25
26 Item {
27      id: screen
28      width: 800
29      height: 480
30
31      property int curDay: LC.curDay()
32      property int curMonth: LC.curMonth()
33      property int curYear: LC.curYear()
34
35      property int initcurDay: LC.curDay()
36      property int initcurMonth: LC.curMonth()
37      property int initcurYear:LC.curYear()
38
39      property int lunarDay: AmLich.getLunarDate(curDay,curMonth,curYear).day
40      property int lunarMonth: AmLich.getLunarDate(curDay,curMonth,curYear).month
41      property string lunarYear: AmLich.getCanChi(AmLich.getLunarDate(curDay,curMonth,curYear))[2]
42
43      property int lunarYearInt : AmLich.getLunarDate(curDay,curMonth,curYear).year
44      property int jd : AmLich.getLunarDate(curDay,curMonth,curYear).jd
45      property string lunarGioHoangDao : AmLich.getGioHoangDao(jd)
46
47      property string lunarDayCanChi : AmLich.getCanChi(AmLich.getLunarDate(curDay,curMonth,curYear))[0]
48      property string lunarMonthCanChi : AmLich.getCanChi(AmLich.getLunarDate(curDay,curMonth,curYear))[1]
49
50      property string day_info : CNLTN.get(screen)
51      property bool is_holiday : CNLTN.is_holiday(screen.curDay,screen.curMonth, screen.curYear, screen.lunarDay, screen.lunarMonth)
52
53      state:"mainscreen"
54
55      Loader {
56          id: theme_manager
57          property alias theme: theme_manager.item
58          source: Themes.default_theme()
59      }
60
61      Rectangle {
62          id: background
63          anchors.fill: parent
64          color: "#343434"
65
66          state:"jumptodate"
67          Image {
68              source: theme_manager.theme.background_image; fillMode: Image.Stretch; anchors.fill: parent
69              opacity: theme_manager.theme.background_opacity
70          }
71
72
73          MouseArea {
74              id:mouseareaMM
75              property int  xfrom: 0
76              property int  yfrom: 0
77
78              property int fixed: 40
79              property int rise: 0
80
81              anchors.fill: parent;anchors.topMargin: 60;anchors.bottomMargin:60;
82
83              onPressAndHold:{
84                  if (Settings.pressandhold()==1){
85                     screen.state="xemngaytotxauhoangdao"
86                  }
87              }
88
89              onDoubleClicked:{
90
91                  if (Settings.doubleclicked()==1){
92                      screen.state="datetimedialog"
93                  }
94              }
95          }
96
97          Text {
98              id: txtDMY
99              x: 140
100              y: 77
101              width: 80
102              height: 20
103              color: "#29d999"
104              textFormat: Text.RichText
105              text: "Tháng <b>"+screen.curMonth+"</b> Năm <b>"+screen.curYear+"</b>"
106              anchors.horizontalCenter: parent.horizontalCenter
107              font.bold: false
108              font.family: "Tahoma"
109              smooth: true
110              horizontalAlignment: Text.AlignHCenter
111              font.pixelSize: 28
112          }
113
114          //------------------------------------------------
115
116                   Rectangle {
117                       id:reelx
118                       width: 260
119                       height: 90
120                       y: 116
121                       anchors.horizontalCenter: parent.horizontalCenter
122                       property int index: 0
123                       onIndexChanged: txtDATEpv.currentIndex = reelx.index
124                       color: "transparent"
125
126                       Component {
127                           id: delegate
128                           Column {
129                               id: wrapper
130                               Text {
131                                   id: nameText
132                                   text: name
133                                   font.bold: true
134                                   font.pixelSize: wrapper.PathView.isCurrentItem ? 80 : 40
135                                   color: {
136                                       if (wrapper.PathView.isCurrentItem){
137                                           var stemp = AmLich98.convertSolar2Lunar(txtDATEpv.currentIndex+1,curMonth,curYear,7);
138                                           if (CNLTN.is_holiday(txtDATEpv.currentIndex+1,curMonth, stemp[0], stemp[1])){
139                                               return theme_manager.theme.markdate.holidays;
140                                           }else{
141                                           var mark_day = (AmLich.getLunarDate(txtDATEpv.currentIndex+1,curMonth,curYear).jd+1)%7;
142                                           if (mark_day === 0) //sunday
143                                               return theme_manager.theme.markdate.sunday;
144                                           if (mark_day == 6) //saturday
145                                               return theme_manager.theme.markdate.saturday;
146                                           else
147                                               return  theme_manager.theme.markdate.otherday_selected;
148                                           }
149                                       }
150                                       else
151                                           return "transparent";//theme_manager.theme.markdate.otherday;
152                                     }
153                               }
154                           }
155                       }
156
157                       PathView {
158                           id:txtDATEpv
159                           anchors.fill: parent
160                           model: maindatemodel
161                           delegate: delegate
162                           pathItemCount: 3
163                           clip: true
164                           Keys.onLeftPressed: decrementCurrentIndex()
165                           Keys.onRightPressed: incrementCurrentIndex()
166                           highlightMoveDuration:500
167                           preferredHighlightBegin: 0.5
168                           preferredHighlightEnd: 0.5
169                           highlightRangeMode: PathView.StrictlyEnforceRange
170                           focus: true
171                           interactive: true
172                           highlight: Rectangle{
173                               anchors.topMargin: 10;
174                               width:110;
175                               height:80;
176                               radius: 8;
177                               color:"#000000"
178                               opacity: 0.3
179                           }
180                           path: Path {
181                               startX: 0
182                               startY: 50
183                               PathLine {x: reelx.width; y: 50}
184                           }
185
186                           onMovementStarted:{
187
188                           }
189
190                           onMovementEnded: {
191                               calculateLunar(txtDATEpv.currentIndex+1, LC.curMonth(), LC.curYear())
192                           }
193                       }
194                   }
195                   ListModel {
196                       id:maindatemodel
197
198                       function reset(){
199                           var days_of_this_month = LC.calDays(screen.curMonth,screen.curYear);
200                           var days_of_changes = days_of_this_month - maindatemodel.count;
201
202                           var ifs;
203
204                           if (days_of_changes<0){
205                               ifs=Math.abs(days_of_changes);
206                               while(ifs>0){
207                                   maindatemodel.remove(maindatemodel.count-1);
208                                   ifs-=1;
209                               }
210                           }else if(days_of_changes>0){
211                               ifs=maindatemodel.count;
212                               for (var i=1;i<=days_of_changes;i++)
213                                   append({name:i+ifs})
214                           }
215
216                          reelx.index = -1; // I dont now why must be added -1 before screen.curDay-1
217                          reelx.index = screen.curDay-1;
218
219                       }
220
221                       function init(){
222                           for(var i=1;i<=LC.calDays(screen.curMonth,screen.curYear);i++)
223                               append({name:i})
224
225                           reelx.index = screen.curDay -1
226                       }
227                   }
228
229          //-------------------------------------------------
230
231          Text {
232              id: txtTHU
233              x: 151
234              y: 210
235              width: 80
236              height: 20
237              color: "#f0f0f5"
238              text: AmLich.getTHU(screen.jd)
239              horizontalAlignment: Text.AlignHCenter
240              anchors.horizontalCenter: parent.horizontalCenter
241              opacity: 0.6
242              font.bold: true
243              font.pixelSize: 30
244          }
245
246          Text {
247              id: txtInfo
248              x: 151
249              y: (screen.is_holiday ? 270 : 250)
250              width: 80
251              height: 20
252              color: (screen.is_holiday ? theme_manager.theme.markdate.holidays : theme_manager.theme.markdate.not_holidays)
253              text: screen.day_info
254              horizontalAlignment: Text.AlignHCenter
255              anchors.horizontalCenter: parent.horizontalCenter
256              opacity: 0.6
257              font.bold: (screen.is_holiday ? true : false)
258              font.pixelSize: (screen.is_holiday ? 25 : 20)
259          }
260
261          Text {
262
263              id: txtDAYAmLich
264              x: 151
265              y: 330
266              width: 80
267              height: 20
268              color: "#f0f0f5"
269              text: "Ngày <span style='color:#C0C0C0;'>"+screen.lunarDay+" ("+screen.lunarDayCanChi+")</span><br>Tháng <span style='color:#C0C0C0;'>"+screen.lunarMonth+" ("+screen.lunarMonthCanChi+")</span><br>Năm <span style='color:#C0C0C0;'>"+screen.lunarYearInt+" ("+screen.lunarYear+")</span>"
270              horizontalAlignment: Text.AlignHCenter
271              anchors.horizontalCenter: parent.horizontalCenter
272              opacity: 0.6
273              font.bold: true
274              font.pixelSize: 25
275          }
276
277
278          MenuScreen{
279              id: menuScreen
280              state:"menuscreen"
281              anchors.verticalCenter: parent.verticalCenter
282              width: parent.width; height: parent.height-60;
283              x: -(screen.width * 1.5)
284          }
285
286          OptionsScreen{
287              id: optionsScreen
288              state:"optionsscreen"
289              anchors.verticalCenter: parent.verticalCenter
290              width: parent.width; height: parent.height-60;
291              x: -(screen.width * 1.5)
292          }
293
294          ChangeTheme{
295              id: changeTheme
296              state:"changetheme"
297              anchors.verticalCenter: parent.verticalCenter
298              width: parent.width; height: parent.height-60;
299              x: -(screen.width * 1.5)
300          }
301
302          XemNgayTotXauHoangDao{
303              id: xntxhdScreen
304              state:"xemngaytotxauhoangdao"
305              anchors.verticalCenter: parent.verticalCenter
306              width: parent.width; height: parent.height-60;
307              x: -(screen.width * 1.5)
308          }
309
310          DateTimeDialog{
311              id: datetimeDialog
312              state:"datetimedialog"
313              anchors.verticalCenter: parent.verticalCenter
314              width: parent.width; height: parent.height-60;
315              x: -(screen.width * 1.5)
316          }
317
318          AmDateTimeDialog{
319              id: amdatetimeDialog
320              state:"amdatetimedialog"
321              anchors.verticalCenter: parent.verticalCenter
322              width: parent.width; height: parent.height-60;
323              x: -(screen.width * 1.5)
324          }
325
326          FullMonth{
327              id: fullmonthDialog
328              state:"xemtheothang"
329              anchors.verticalCenter: parent.verticalCenter
330              width: parent.width; height: parent.height-60;
331              x: -(screen.width * 1.5)
332          }
333
334          About{
335              id: aboutDialog
336              state:"aboutdialog"
337              anchors.verticalCenter: parent.verticalCenter
338              width: parent.width; height: parent.height-60;
339              x: -(screen.width * 1.5)
340          }
341
342          FileBrowser{
343              id: fileBrowser
344              state:"filebrowser"
345              anchors.verticalCenter: parent.verticalCenter
346              width: parent.width; height: parent.height-60;
347              x: -(screen.width * 1.5)
348          }
349
350
351          MultiTitleBar { id: titleBar; width: parent.width }
352          ToolBar { id: toolBar; height: 50;
353              y: screen.height - 48
354              width: parent.width; opacity: 0.9
355              button1Label: "Menu"
356              button2Label: "Lựa Chọn"
357              onButton1Clicked:
358              {
359                  screen.state="menuscreen"
360              }
361              onButton2Clicked: {
362                  screen.state="optionsscreen"
363              }
364          }
365      }
366
367      states: [
368          State {
369              name:"mainscreen"
370              StateChangeScript {
371                  script:{
372                  }
373                 }
374          },
375          State {
376              name: "menuscreen";
377              PropertyChanges { target: menuScreen; x: 0; focus:true}
378              PropertyChanges { target: toolBar; y: screen.height }
379              PropertyChanges { target: toolBar }
380                           PropertyChanges { target: mouseareaMM;enabled:false }
381
382          },
383              State{
384                  name:"filebrowser"
385                  PropertyChanges { target: fileBrowser; x: 0; focus:true; visible:true;}
386                  PropertyChanges { target: toolBar; y: screen.height }
387                  PropertyChanges { target: toolBar }
388                  StateChangeScript {
389                      script:{
390                          fileBrowser.refresh();
391                      }
392                     }
393              },
394          State {
395              name: "optionsscreen";
396              PropertyChanges { target: optionsScreen; x: 0; focus:true}
397              PropertyChanges { target: toolBar; y: screen.height }
398              PropertyChanges { target: toolBar }
399                           PropertyChanges { target: mouseareaMM;enabled:false }
400
401          },
402          State {
403              name: "changetheme";
404              PropertyChanges { target: changeTheme; x: 0; focus:true}
405              PropertyChanges { target: toolBar; y: screen.height }
406              PropertyChanges { target: toolBar }
407              PropertyChanges { target: reelx;enabled:false }
408              PropertyChanges { target: mouseareaMM;enabled:false }
409
410          },
411          State {
412              name: "xemngaytotxauhoangdao";
413              PropertyChanges { target: xntxhdScreen; x: 0; focus:true;visible:true;}
414              PropertyChanges { target: toolBar; y: screen.height }
415              PropertyChanges { target: toolBar }
416              PropertyChanges { target: mouseareaMM;enabled:false }
417
418              StateChangeScript {
419                  script:{
420                      xntxhdScreen.reset()
421                  }
422                 }
423
424          },
425          State {
426              name: "datetimedialog";
427              PropertyChanges { target: datetimeDialog; x: 0; focus:true}
428              PropertyChanges { target: toolBar; y: screen.height }
429              PropertyChanges { target: toolBar }
430              PropertyChanges { target: mouseareaMM;enabled:false }
431                                                                  PropertyChanges { target: reelx;enabled:false }
432              StateChangeScript {
433                  script:{
434                      datetimeDialog.reset()
435                  }
436                 }
437          },
438          State {
439              name: "amdatetimedialog";
440              PropertyChanges { target: amdatetimeDialog; x: 0; focus:true}
441              PropertyChanges { target: toolBar; y: screen.height }
442              PropertyChanges { target: toolBar }
443              PropertyChanges { target: mouseareaMM;enabled:false }
444                                                                  PropertyChanges { target: reelx;enabled:false }
445              StateChangeScript {
446                  script:{
447                      amdatetimeDialog.reset()
448                  }
449                 }
450          },
451          State {
452              name: "aboutdialog";
453              PropertyChanges { target: aboutDialog; x: 0; focus:true; visible:true;}
454              PropertyChanges { target: toolBar; y: screen.height }
455              PropertyChanges { target: toolBar }
456              PropertyChanges { target: mouseareaMM;enabled:false }
457          },
458          State {
459              name: "xemtheothang";
460              PropertyChanges { target: fullmonthDialog; x: 0; focus:true; visible:true;}
461              PropertyChanges { target: toolBar; y: screen.height }
462              PropertyChanges { target: toolBar }
463              StateChangeScript {
464                  script:{
465                      fullmonthDialog.reset()
466                  }
467                 }
468              PropertyChanges { target: mouseareaMM;enabled:false }
469          }
470      ]
471
472      transitions: [
473          //normally i used InOutBack
474          Transition { NumberAnimation { properties: "x,y,opacity"; duration: 300; easing.type: Easing.InOutBack } }
475      ]
476
477
478      function lunarTietKhi(){
479          return AmLich.TIETKHI[AmLich.getSunLongitude(screen.jd+1,7.0)];
480      }
481
482
483      function calculateLunar(D,M,Y){
484          screen.curDay =D
485          screen.curMonth = M
486          screen.curYear = Y
487          screen.lunarDay = AmLich.getLunarDate(screen.curDay,screen.curMonth,screen.curYear).day
488          screen.lunarMonth = AmLich.getLunarDate(screen.curDay,screen.curMonth,screen.curYear).month
489          screen.lunarYearInt = AmLich.getLunarDate(screen.curDay,screen.curMonth,screen.curYear).year
490          screen.lunarYear = AmLich.getCanChi(AmLich.getLunarDate(screen.curDay,screen.curMonth,screen.curYear))[2]//AmLich.getYearCanChi(screen.curYear)
491          screen.jd = AmLich.getLunarDate(screen.curDay,screen.curMonth,screen.curYear).jd
492          screen.lunarGioHoangDao = AmLich.getGioHoangDao(screen.jd)
493
494          screen.lunarDayCanChi = AmLich.getCanChi(AmLich.getLunarDate(screen.curDay,screen.curMonth,screen.curYear))[0]
495          screen.lunarMonthCanChi = AmLich.getCanChi(AmLich.getLunarDate(screen.curDay,screen.curMonth,screen.curYear))[1]
496
497      }
498
499      function reset(){
500          calculateLunar(initcurDay, initcurMonth, initcurYear)
501          LC.reset(initcurDay, initcurMonth, initcurYear)
502          screen.state="mainscreen"
503          maindatemodel.reset()
504          txtDATEpv.currentIndex = initcurDay-1;
505      }
506
507      function refresh(){
508
509      }
510
511      Component.onCompleted: {
512         amdatetimeDialog.reset()
513         maindatemodel.init()
514      }
515
516 }