Added global controller andalso filebrowser qml
[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                           highlightMoveDuration:500
164                           Keys.onDownPressed: if (!moving && interactive) incrementCurrentIndex()
165                           Keys.onUpPressed: if (!moving && interactive) decrementCurrentIndex()
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                           onFlickEnded : {
185                           }
186
187                           onMovementEnded: {
188                               calculateLunar(txtDATEpv.currentIndex+1, LC.curMonth(), LC.curYear())
189                           }
190                       }
191                   }
192                   ListModel {
193                       id:maindatemodel
194
195                       function reset(){
196                           var days_of_this_month = LC.calDays(screen.curMonth,screen.curYear);
197                           var days_of_changes = days_of_this_month - maindatemodel.count;
198
199                           var ifs;
200
201                           if (days_of_changes<0){
202                               ifs=Math.abs(days_of_changes);
203                               while(ifs>0){
204                                   maindatemodel.remove(maindatemodel.count-1);
205                                   ifs-=1;
206                               }
207                           }else if(days_of_changes>0){
208                               ifs=maindatemodel.count;
209                               for (var i=1;i<=days_of_changes;i++)
210                                   append({name:i+ifs})
211                           }
212
213                          reelx.index = -1; // I dont now why must be added -1 before screen.curDay-1
214                          reelx.index = screen.curDay-1;
215
216                       }
217
218                       function init(){
219                           for(var i=1;i<=LC.calDays(screen.curMonth,screen.curYear);i++)
220                               append({name:i})
221
222                           reelx.index = screen.curDay -1
223                       }
224                   }
225
226          //-------------------------------------------------
227
228          Text {
229              id: txtTHU
230              x: 151
231              y: 210
232              width: 80
233              height: 20
234              color: "#f0f0f5"
235              text: AmLich.getTHU(screen.jd)
236              horizontalAlignment: Text.AlignHCenter
237              anchors.horizontalCenter: parent.horizontalCenter
238              opacity: 0.6
239              font.bold: true
240              font.pixelSize: 30
241          }
242
243          Text {
244              id: txtInfo
245              x: 151
246              y: (screen.is_holiday ? 270 : 250)
247              width: 80
248              height: 20
249              color: (screen.is_holiday ? theme_manager.theme.markdate.holidays : theme_manager.theme.markdate.not_holidays)
250              text: screen.day_info
251              horizontalAlignment: Text.AlignHCenter
252              anchors.horizontalCenter: parent.horizontalCenter
253              opacity: 0.6
254              font.bold: (screen.is_holiday ? true : false)
255              font.pixelSize: (screen.is_holiday ? 25 : 20)
256          }
257
258          Text {
259
260              id: txtDAYAmLich
261              x: 151
262              y: 330
263              width: 80
264              height: 20
265              color: "#f0f0f5"
266              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>"
267              horizontalAlignment: Text.AlignHCenter
268              anchors.horizontalCenter: parent.horizontalCenter
269              opacity: 0.6
270              font.bold: true
271              font.pixelSize: 25
272          }
273
274
275          MenuScreen{
276              id: menuScreen
277              state:"menuscreen"
278              anchors.verticalCenter: parent.verticalCenter
279              width: parent.width; height: parent.height-60;
280              x: -(screen.width * 1.5)
281          }
282
283          OptionsScreen{
284              id: optionsScreen
285              state:"optionsscreen"
286              anchors.verticalCenter: parent.verticalCenter
287              width: parent.width; height: parent.height-60;
288              x: -(screen.width * 1.5)
289          }
290
291          ChangeTheme{
292              id: changeTheme
293              state:"changetheme"
294              anchors.verticalCenter: parent.verticalCenter
295              width: parent.width; height: parent.height-60;
296              x: -(screen.width * 1.5)
297          }
298
299          XemNgayTotXauHoangDao{
300              id: xntxhdScreen
301              state:"xemngaytotxauhoangdao"
302              anchors.verticalCenter: parent.verticalCenter
303              width: parent.width; height: parent.height-60;
304              x: -(screen.width * 1.5)
305          }
306
307          DateTimeDialog{
308              id: datetimeDialog
309              state:"datetimedialog"
310              anchors.verticalCenter: parent.verticalCenter
311              width: parent.width; height: parent.height-60;
312              x: -(screen.width * 1.5)
313          }
314
315          AmDateTimeDialog{
316              id: amdatetimeDialog
317              state:"amdatetimedialog"
318              anchors.verticalCenter: parent.verticalCenter
319              width: parent.width; height: parent.height-60;
320              x: -(screen.width * 1.5)
321          }
322
323          FullMonth{
324              id: fullmonthDialog
325              state:"xemtheothang"
326              anchors.verticalCenter: parent.verticalCenter
327              width: parent.width; height: parent.height-60;
328              x: -(screen.width * 1.5)
329          }
330
331          About{
332              id: aboutDialog
333              state:"aboutdialog"
334              anchors.verticalCenter: parent.verticalCenter
335              width: parent.width; height: parent.height-60;
336              x: -(screen.width * 1.5)
337          }
338
339          FileBrowser{
340              id: fileBrowser
341              state:"filebrowser"
342              anchors.verticalCenter: parent.verticalCenter
343              width: parent.width; height: parent.height-60;
344              x: -(screen.width * 1.5)
345          }
346
347
348          MultiTitleBar { id: titleBar; width: parent.width }
349          ToolBar { id: toolBar; height: 50;
350              y: screen.height - 48
351              width: parent.width; opacity: 0.9
352              button1Label: "Menu"
353              button2Label: "Lựa Chọn"
354              onButton1Clicked:
355              {
356                  screen.state="menuscreen"
357              }
358              onButton2Clicked: {
359                  screen.state="optionsscreen"
360              }
361          }
362      }
363
364      states: [
365          State {
366              name:"mainscreen"
367              StateChangeScript {
368                  script:{
369                  }
370                 }
371          },
372          State {
373              name: "menuscreen";
374              PropertyChanges { target: menuScreen; x: 0; focus:true}
375              PropertyChanges { target: toolBar; y: screen.height }
376              PropertyChanges { target: toolBar }
377                           PropertyChanges { target: mouseareaMM;enabled:false }
378
379          },
380              State{
381                  name:"filebrowser"
382                  PropertyChanges { target: fileBrowser; x: 0; focus:true; visible:true;}
383                  PropertyChanges { target: toolBar; y: screen.height }
384                  PropertyChanges { target: toolBar }
385              },
386          State {
387              name: "optionsscreen";
388              PropertyChanges { target: optionsScreen; x: 0; focus:true}
389              PropertyChanges { target: toolBar; y: screen.height }
390              PropertyChanges { target: toolBar }
391                           PropertyChanges { target: mouseareaMM;enabled:false }
392
393          },
394          State {
395              name: "changetheme";
396              PropertyChanges { target: changeTheme; x: 0; focus:true}
397              PropertyChanges { target: toolBar; y: screen.height }
398              PropertyChanges { target: toolBar }
399              PropertyChanges { target: reelx;enabled:false }
400              PropertyChanges { target: mouseareaMM;enabled:false }
401
402          },
403          State {
404              name: "xemngaytotxauhoangdao";
405              PropertyChanges { target: xntxhdScreen; x: 0; focus:true;visible:true;}
406              PropertyChanges { target: toolBar; y: screen.height }
407              PropertyChanges { target: toolBar }
408              PropertyChanges { target: mouseareaMM;enabled:false }
409
410              StateChangeScript {
411                  script:{
412                      xntxhdScreen.reset()
413                  }
414                 }
415
416          },
417          State {
418              name: "datetimedialog";
419              PropertyChanges { target: datetimeDialog; x: 0; focus:true}
420              PropertyChanges { target: toolBar; y: screen.height }
421              PropertyChanges { target: toolBar }
422              PropertyChanges { target: mouseareaMM;enabled:false }
423                                                                  PropertyChanges { target: reelx;enabled:false }
424              StateChangeScript {
425                  script:{
426                      datetimeDialog.reset()
427                  }
428                 }
429          },
430          State {
431              name: "amdatetimedialog";
432              PropertyChanges { target: amdatetimeDialog; x: 0; focus:true}
433              PropertyChanges { target: toolBar; y: screen.height }
434              PropertyChanges { target: toolBar }
435              PropertyChanges { target: mouseareaMM;enabled:false }
436                                                                  PropertyChanges { target: reelx;enabled:false }
437              StateChangeScript {
438                  script:{
439                      amdatetimeDialog.reset()
440                  }
441                 }
442          },
443          State {
444              name: "aboutdialog";
445              PropertyChanges { target: aboutDialog; x: 0; focus:true; visible:true;}
446              PropertyChanges { target: toolBar; y: screen.height }
447              PropertyChanges { target: toolBar }
448              PropertyChanges { target: mouseareaMM;enabled:false }
449          },
450          State {
451              name: "xemtheothang";
452              PropertyChanges { target: fullmonthDialog; x: 0; focus:true; visible:true;}
453              PropertyChanges { target: toolBar; y: screen.height }
454              PropertyChanges { target: toolBar }
455              StateChangeScript {
456                  script:{
457                      fullmonthDialog.reset()
458                  }
459                 }
460              PropertyChanges { target: mouseareaMM;enabled:false }
461          }
462      ]
463
464      transitions: [
465          //normally i used InOutBack
466          Transition { NumberAnimation { properties: "x,y,opacity"; duration: 300; easing.type: Easing.InOutBack } }
467      ]
468
469
470      function lunarTietKhi(){
471          return AmLich.TIETKHI[AmLich.getSunLongitude(screen.jd+1,7.0)];
472      }
473
474
475      function calculateLunar(D,M,Y){
476          screen.curDay =D
477          screen.curMonth = M
478          screen.curYear = Y
479          screen.lunarDay = AmLich.getLunarDate(screen.curDay,screen.curMonth,screen.curYear).day
480          screen.lunarMonth = AmLich.getLunarDate(screen.curDay,screen.curMonth,screen.curYear).month
481          screen.lunarYearInt = AmLich.getLunarDate(screen.curDay,screen.curMonth,screen.curYear).year
482          screen.lunarYear = AmLich.getCanChi(AmLich.getLunarDate(screen.curDay,screen.curMonth,screen.curYear))[2]//AmLich.getYearCanChi(screen.curYear)
483          screen.jd = AmLich.getLunarDate(screen.curDay,screen.curMonth,screen.curYear).jd
484          screen.lunarGioHoangDao = AmLich.getGioHoangDao(screen.jd)
485
486          screen.lunarDayCanChi = AmLich.getCanChi(AmLich.getLunarDate(screen.curDay,screen.curMonth,screen.curYear))[0]
487          screen.lunarMonthCanChi = AmLich.getCanChi(AmLich.getLunarDate(screen.curDay,screen.curMonth,screen.curYear))[1]
488
489      }
490
491      function reset(){
492          calculateLunar(initcurDay, initcurMonth, initcurYear)
493          LC.reset(initcurDay, initcurMonth, initcurYear)
494          screen.state="mainscreen"
495          maindatemodel.reset()
496          txtDATEpv.currentIndex = initcurDay-1;
497      }
498
499      function refresh(){
500
501      }
502
503      Component.onCompleted: {
504         amdatetimeDialog.reset()
505         maindatemodel.init()
506      }
507
508 }