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