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