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