99ca08817ede139cfe46aae6b651cbd0bd4619f0
[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
25 Item {
26      id: screen
27      width: 800
28      height: 480
29
30      property int curDay: LC.curDay()
31      property int curMonth: LC.curMonth()
32      property int curYear: LC.curYear()
33
34      property int initcurDay: LC.curDay()
35      property int initcurMonth: LC.curMonth()
36      property int initcurYear:LC.curYear()
37
38      property int lunarDay: AmLich.getLunarDate(curDay,curMonth,curYear).day
39      property int lunarMonth: AmLich.getLunarDate(curDay,curMonth,curYear).month
40      property string lunarYear: AmLich.getCanChi(AmLich.getLunarDate(curDay,curMonth,curYear))[2]
41
42      property int lunarYearInt : AmLich.getLunarDate(curDay,curMonth,curYear).year
43      property int jd : AmLich.getLunarDate(curDay,curMonth,curYear).jd
44      property string lunarGioHoangDao : AmLich.getGioHoangDao(jd)
45
46      property string lunarDayCanChi : AmLich.getCanChi(AmLich.getLunarDate(curDay,curMonth,curYear))[0]
47      property string lunarMonthCanChi : AmLich.getCanChi(AmLich.getLunarDate(curDay,curMonth,curYear))[1]
48
49      //property string lunarCanHour : AmLich.getCanHour0(LC.curHour())
50
51      state:"mainscreen"
52
53      Loader {
54          id: theme_manager
55          property alias theme: theme_manager.item
56          source: Themes.default_theme()
57      }
58
59      Rectangle {
60          id: background
61          anchors.fill: parent
62          color: "#343434"
63
64          state:"jumptodate"
65          Image {
66              source: theme_manager.theme.background_image; fillMode: Image.Tile; anchors.fill: parent; opacity: 0.3
67          }
68
69
70          MouseArea {
71              id:mouseareaMM
72              property int  xfrom: 0
73              property int  yfrom: 0
74
75              property int fixed: 40
76              property int rise: 0
77
78              anchors.fill: parent
79
80              onPressAndHold:{
81                  if (Settings.pressandhold()==1){
82                     screen.state="xemngaytotxauhoangdao"
83                  }
84              }
85
86              onDoubleClicked:{
87
88                  if (Settings.doubleclicked()==1){
89                      screen.state="datetimedialog"
90                  }
91              }
92
93  /*            onPressed: {
94                  xfrom=mouseX;
95                  yfrom=mouseY;
96              }
97
98              onReleased : {
99                  rise = mouseX - xfrom
100                  if (rise > fixed || rise <  -fixed){
101                  if (mouseX < xfrom){
102                      calculateLunar(LC.nextDay(), LC.curMonth(), LC.curYear())
103                  }else{
104                       calculateLunar(LC.prevDay(), LC.curMonth(), LC.curYear())
105                  }
106                  }
107
108              }*/
109          }
110
111          Text {
112              id: txtDMY
113              x: 140
114              y: 77
115              width: 80
116              height: 20
117              color: "#29d999"
118              text: "Tháng "+screen.curMonth+" Năm "+screen.curYear
119              anchors.horizontalCenter: parent.horizontalCenter
120              font.bold: true
121              font.family: "Tahoma"
122              smooth: true
123              horizontalAlignment: Text.AlignHCenter
124              font.pixelSize: 28
125          }
126
127          /*
128          Text {
129              id: txtDAY
130              x: 151
131              y: 126
132              width: 80
133              height: 20
134              color: "#f0f0f5"
135              text: screen.curDay
136              horizontalAlignment: Text.AlignHCenter
137              anchors.horizontalCenter: parent.horizontalCenter
138              opacity: 0.6
139              font.bold: true
140              font.pixelSize: 80
141          }
142 */
143
144          //------------------------------------------------
145
146                   Rectangle {
147                       id:reelx
148                               width: 300
149                               height: 100
150                                            y: 126
151                                            anchors.horizontalCenter: parent.horizontalCenter
152                                            property int index: 0
153          onIndexChanged: txtDATEpv.currentIndex = reelx.index
154          color: "transparent"
155                       Component {
156                           id: delegate
157                           Column {
158                               id: wrapper
159                               Text {
160                                   id: nameText
161                                   text: name
162                                   font.bold: true
163                                   font.pixelSize: wrapper.PathView.isCurrentItem ? 80 : 40
164                                   color: wrapper.PathView.isCurrentItem ? "#FFFFFF" : "grey"
165                               }
166                           }
167                       }
168
169                       PathView {
170                           id:txtDATEpv
171                           anchors.fill: parent
172                           model: maindatemodel
173                           delegate: delegate
174                           pathItemCount: 3
175                           clip: true
176                           preferredHighlightBegin: 0.5
177                           preferredHighlightEnd: 0.5
178                           highlightRangeMode: PathView.StrictlyEnforceRange
179                           focus: true
180                           path: Path {
181                               startX: 0
182                               startY: 50
183                               PathLine {x: reelx.width; y: 50}
184                           }
185                           onMovementEnded: {
186                               calculateLunar(txtDATEpv.currentIndex+1, LC.curMonth(), LC.curYear())
187                           }
188                       }
189                   }
190                   ListModel {
191                       id:maindatemodel
192
193                       function reset(){
194                           while(maindatemodel.count>0){
195                               try{maindatemodel.remove(maindatemodel.count-1)}catch(e){}
196                           }
197
198                           for(var i=1;i<=LC.calDays(screen.curMonth,screen.curYear);i++)
199                               append({name:i})
200                           reelx.index = screen.curDay -1
201                       }
202                   }
203
204          //-------------------------------------------------
205                   Component.onCompleted: {
206                      maindatemodel.reset()
207                   }
208
209          Text {
210              id: txtTHU
211              x: 151
212              y: 240
213              width: 80
214              height: 20
215              color: "#f0f0f5"
216              text: AmLich.getTHU(screen.jd)
217              horizontalAlignment: Text.AlignHCenter
218              anchors.horizontalCenter: parent.horizontalCenter
219              opacity: 0.6
220              font.bold: true
221              font.pixelSize: 30
222          }
223
224          Text {
225
226              id: txtDAYAmLich
227              x: 151
228              y: 300
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: 28
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          XemNgayTotXauHoangDao{
258              id: xntxhdScreen
259              state:"xemngaytotxauhoangdao"
260              anchors.verticalCenter: parent.verticalCenter
261              width: parent.width; height: parent.height-60;
262              x: -(screen.width * 1.5)
263          }
264
265          DateTimeDialog{
266              id: datetimeDialog
267              state:"datetimedialog"
268              anchors.verticalCenter: parent.verticalCenter
269              width: parent.width; height: parent.height-60;
270              x: -(screen.width * 1.5)
271          }
272
273          AmDateTimeDialog{
274              id: amdatetimeDialog
275              state:"amdatetimedialog"
276              anchors.verticalCenter: parent.verticalCenter
277              width: parent.width; height: parent.height-60;
278              x: -(screen.width * 1.5)
279          }
280
281          FullMonth{
282              id: fullmonthDialog
283              state:"xemtheothang"
284              anchors.verticalCenter: parent.verticalCenter
285              width: parent.width; height: parent.height-60;
286              x: -(screen.width * 1.5)
287          }
288
289          NoFeatureDialog{
290              id: nofeatureDialog
291              state:"nofeaturedialog"
292              anchors.verticalCenter: parent.verticalCenter
293              width: parent.width; height: parent.height-60;
294              x: -(screen.width * 1.5)
295          }
296
297
298          About{
299              id: aboutDialog
300              state:"aboutdialog"
301              anchors.verticalCenter: parent.verticalCenter
302              width: parent.width; height: parent.height-60;
303              x: -(screen.width * 1.5)
304          }
305
306
307          MultiTitleBar { id: titleBar; width: parent.width }
308          ToolBar { id: toolBar; height: 50;
309              y: screen.height - 48
310              width: parent.width; opacity: 0.9
311              button1Label: "Menu"
312              button2Label: "Lựa Chọn"
313              onButton1Clicked:
314              {
315                  screen.state="menuscreen"
316              }
317              onButton2Clicked: {
318                  screen.state="optionsscreen"
319              }
320          }
321      }
322
323      states: [
324          State {
325              name: "menuscreen";
326              PropertyChanges { target: menuScreen; x: 0; focus:true}
327              PropertyChanges { target: toolBar; y: screen.height }
328              PropertyChanges { target: toolBar }
329                           PropertyChanges { target: mouseareaMM;enabled:false }
330
331          },
332          State {
333              name: "optionsscreen";
334              PropertyChanges { target: optionsScreen; 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: "xemngaytotxauhoangdao";
342              PropertyChanges { target: xntxhdScreen; 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: "datetimedialog";
350              PropertyChanges { target: datetimeDialog; x: 0; focus:true}
351              PropertyChanges { target: toolBar; y: screen.height }
352              PropertyChanges { target: toolBar }
353              PropertyChanges { target: mouseareaMM;enabled:false }
354                                                                  PropertyChanges { target: reelx;enabled:false }
355              StateChangeScript {
356                  script:{
357                      datetimeDialog.reset()
358                  }
359                 }
360          },
361          State {
362              name: "amdatetimedialog";
363              PropertyChanges { target: amdatetimeDialog; x: 0; focus:true}
364              PropertyChanges { target: toolBar; y: screen.height }
365              PropertyChanges { target: toolBar }
366              PropertyChanges { target: mouseareaMM;enabled:false }
367                                                                  PropertyChanges { target: reelx;enabled:false }
368              StateChangeScript {
369                  script:{
370                      amdatetimeDialog.reset()
371                  }
372                 }
373          },
374          State {
375              name: "nofeaturedialog";
376              PropertyChanges { target: nofeatureDialog; x: 0; focus:true}
377              PropertyChanges { target: toolBar; y: screen.height }
378              PropertyChanges { target: toolBar }
379              PropertyChanges { target: mouseareaMM;enabled:false }
380                                                                  PropertyChanges { target: reelx;enabled:false }
381          },
382          State {
383              name: "aboutdialog";
384              PropertyChanges { target: aboutDialog; x: 0; focus:true}
385              PropertyChanges { target: toolBar; y: screen.height }
386              PropertyChanges { target: toolBar }
387              PropertyChanges { target: mouseareaMM;enabled:false }
388          },
389          State {
390              name: "xemtheothang";
391              PropertyChanges { target: fullmonthDialog; x: 0; focus:true}
392              PropertyChanges { target: toolBar; y: screen.height }
393              PropertyChanges { target: toolBar }
394              StateChangeScript {
395                  script:{
396                      fullmonthDialog.reset()
397                  }
398                 }
399              PropertyChanges { target: mouseareaMM;enabled:false }
400          }
401      ]
402
403      transitions: [
404          Transition { NumberAnimation { properties: "x,y,opacity"; duration: 500; easing.type: Easing.InOutBack } }
405      ]
406
407
408      function lunarTietKhi(){
409          return AmLich.TIETKHI[AmLich.getSunLongitude(screen.jd+1,7.0)];
410      }
411
412
413      function calculateLunar(D,M,Y){
414          screen.curDay =D
415          screen.curMonth = M
416          screen.curYear = Y
417          screen.lunarDay = AmLich.getLunarDate(screen.curDay,screen.curMonth,screen.curYear).day
418          screen.lunarMonth = AmLich.getLunarDate(screen.curDay,screen.curMonth,screen.curYear).month
419          screen.lunarYearInt = AmLich.getLunarDate(screen.curDay,screen.curMonth,screen.curYear).year
420          screen.lunarYear = AmLich.getCanChi(AmLich.getLunarDate(screen.curDay,screen.curMonth,screen.curYear))[2]//AmLich.getYearCanChi(screen.curYear)
421          screen.jd = AmLich.getLunarDate(screen.curDay,screen.curMonth,screen.curYear).jd
422          screen.lunarGioHoangDao = AmLich.getGioHoangDao(screen.jd)
423
424          screen.lunarDayCanChi = AmLich.getCanChi(AmLich.getLunarDate(screen.curDay,screen.curMonth,screen.curYear))[0]
425          screen.lunarMonthCanChi = AmLich.getCanChi(AmLich.getLunarDate(screen.curDay,screen.curMonth,screen.curYear))[1]
426
427          //console.log(screen.curDay+" "+screen.curMonth+" "+screen.curYear)
428          //console.log( AmLich.getCanChi(AmLich.getLunarDate(30,1,2007)))
429      }
430
431      function reset(){
432          calculateLunar(initcurDay, initcurMonth, initcurYear)
433          LC.reset(initcurDay, initcurMonth, initcurYear)
434          screen.state="mainscreen"
435          maindatemodel.reset()
436          txtDATEpv.currentIndex = initcurDay-1;
437      }
438
439      function refresh(){
440      }
441
442      Component.onCompleted: {
443
444      }
445 }