1.0.2 Bumped version to 1.0.2-4
[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.1
19
20 import "Themes.js" as Themes
21 import "Settings.js" as Settings
22 import "main.js" as Script
23
24 Item {
25      id: screen
26      width: 480
27      height: 800
28
29      state:"mainscreen"
30
31      signal dialogClose
32
33      property int curMonth: Script.curMonth
34      property int curYear: Script.curYear
35
36      Loader {
37          id: theme_manager
38          property alias theme: theme_manager.item
39          source: Themes.default_theme()
40      }
41
42      Component.onCompleted: {
43         Settings.restore_nomodel();
44         Script.createDateTimeDialog(screen);
45         Script.datetimedlg.toolbar.connect(show_toolbar);
46         Script.datetimedlg.updatedate.connect(update_date);
47         Script.amdatetimedlg.toolbar.connect(show_toolbar);
48         Script.amdatetimedlg.updatedate.connect(update_date);
49         Script.fullmonth.toolbar.connect(show_toolbar);
50         Script.fullmonth.updatedate.connect(update_date);
51         maindatemodel.init();
52         Script.init();
53      }
54
55      function show_toolbar(){
56         screen.state="mainscreen";
57      }
58
59      function update_date(day, month, year){
60          txtDATEpv.currentIndex = day-1;
61          screen.curMonth = month;
62          screen.curYear = year;
63          Script.curMonth = month;
64          Script.curYear = year;
65          Script.changeDay(day, txtTHU, txtInfo, txtDAYAmLich);
66          Script.fullmonth.m_day=Script.curDay;
67          Script.fullmonth.m_month=Script.curMonth;
68          Script.fullmonth.m_year=Script.curYear;
69          Script.fullmonth.reset();
70      }
71
72      Rectangle {
73          id: mecal
74          anchors.fill: parent
75          color: "white"
76
77          state:"jumptodate"
78
79          Image {
80              source: theme_manager.theme.background_image; fillMode: Image.Stretch; anchors.fill: parent
81              opacity: theme_manager.theme.background_opacity
82          }
83
84
85          MouseArea {
86              id:mouseareaMM
87              property int  xfrom: 0
88              property int  yfrom: 0
89
90              property int fixed: 40
91              property int rise: 0
92
93              anchors.fill: parent;anchors.topMargin: 60;anchors.bottomMargin:60;
94
95              onPressAndHold:{
96                  if (Settings.pressandhold()==1){
97                      menu_item_Clicked(4);
98                  }
99              }
100
101              onDoubleClicked:{
102
103                  if (Settings.doubleclicked()==1){
104                      screen.state="switchX";
105                     Script.datetimedlg.state="show";
106                  }
107              }
108          }
109
110          //------------------------------------------------
111
112                   Rectangle {
113                       id:reelx
114                       width: 260
115                       height: 90
116                       y: 116
117                       anchors.horizontalCenter: parent.horizontalCenter
118                       property int index: 0
119                       onIndexChanged: txtDATEpv.currentIndex = reelx.index
120                       color: "transparent"
121
122                       Component {
123                           id: delegate
124                           Column {
125                               id: wrapper
126                               Text {
127                                   id: nameText
128                                   text: name
129                                   font.bold: true
130                                   font.pixelSize: wrapper.PathView.isCurrentItem ? 80 : 40
131                                   color: {
132                                       if (wrapper.PathView.isCurrentItem){
133                                           var stemp = Script.convertSolar2Lunar(txtDATEpv.currentIndex+1,curMonth,curYear,7);
134                                           if (Script.is_holiday(txtDATEpv.currentIndex+1,curMonth, stemp[0], stemp[1])){
135                                               return theme_manager.theme.markdate.holidays;
136                                           }else{
137                                           var mark_day = (Script.getLunarDate(txtDATEpv.currentIndex+1,curMonth,curYear).jd+1)%7;
138                                           if (mark_day === 0) //sunday
139                                               return theme_manager.theme.markdate.sunday;
140                                           if (mark_day == 6) //saturday
141                                               return theme_manager.theme.markdate.saturday;
142                                           else
143                                               return  theme_manager.theme.markdate.otherday_selected;
144                                           }
145                                       }
146                                       else
147                                           return "transparent";//theme_manager.theme.markdate.otherday;
148                                     }
149                               }
150                           }
151                       }
152
153                       PathView {
154                           id:txtDATEpv
155                           anchors.fill: parent
156                           model: maindatemodel
157                           delegate: delegate
158                           pathItemCount: 3
159                           clip: true
160                           Keys.onLeftPressed: decrementCurrentIndex()
161                           Keys.onRightPressed: incrementCurrentIndex()
162                           highlightMoveDuration:500
163                           preferredHighlightBegin: 0.5
164                           preferredHighlightEnd: 0.5
165                           highlightRangeMode: PathView.StrictlyEnforceRange
166                           focus: true
167                           interactive: true
168                           highlight: Rectangle{
169                               anchors.topMargin: 10;
170                               width:110;
171                               height:80;
172                               radius: 8;
173                               color:"#000000"
174                               opacity: 0.3
175                           }
176                           path: Path {
177                               startX: 0
178                               startY: 50
179                               PathLine {x: reelx.width; y: 50}
180                           }
181
182                           onMovementStarted:{
183
184                           }
185
186                           onMovementEnded: {
187                               Script.changeDay(txtDATEpv.currentIndex+1, txtTHU, txtInfo, txtDAYAmLich);
188                               Script.fullmonth.m_day=Script.curDay;
189                               Script.fullmonth.m_month=Script.curMonth;
190                               Script.fullmonth.m_year=Script.curYear;
191                               Script.fullmonth.reset();
192                           }
193                       }
194                   }
195                   ListModel {
196                       id:maindatemodel
197
198                       function reset(){
199                           var days_of_this_month = Script.calDays();
200                           var days_of_changes = days_of_this_month - maindatemodel.count;
201
202                           var ifs;
203
204                           if (days_of_changes<0){
205                               ifs=Math.abs(days_of_changes);
206                               while(ifs>0){
207                                   maindatemodel.remove(maindatemodel.count-1);
208                                   ifs-=1;
209                               }
210                           }else if(days_of_changes>0){
211                               ifs=maindatemodel.count;
212                               for (var i=1;i<=days_of_changes;i++)
213                                   append({name:i+ifs})
214                           }
215
216                          reelx.index = -1;
217                          reelx.index = Script.curDay - 1;
218
219                       }
220
221                       function init(){
222                           for(var i=1;i<=Script.calDays();i++)
223                               append({name:i});
224
225                           reelx.index = Script.curDay - 1;
226                       }
227                   }
228
229          //-------------------------------------------------
230
231          Text {
232              id: txtDMY
233                       x: 151
234                       y: 77
235                       height: 20
236                       color: "#29d999"
237                       text: "Tháng <b>"+screen.curMonth+"</b> Năm <b>"+screen.curYear+"</b>"
238                       horizontalAlignment: Text.AlignHCenter
239                       anchors.horizontalCenter: parent.horizontalCenter
240                       font.bold: false
241                       font.family: "Tahoma"
242                       smooth: true
243                       font.pixelSize: 28
244               }
245
246          Text {
247              id: txtTHU
248              x: 151
249              y: 210
250              height: 20
251              color: "#f0f0f5"
252              text: Script.__txtTHU_format()
253              horizontalAlignment: Text.AlignHCenter
254              anchors.horizontalCenter: parent.horizontalCenter
255              opacity: 0.6
256              font.bold: true
257              font.pixelSize: 30
258          }
259
260          Text {
261              id: txtInfo
262              x: 151
263              y: (screen.is_holiday ? 270 : 250)
264              height: 20
265              color: (Script.is_holiday ? theme_manager.theme.markdate.holidays : theme_manager.theme.markdate.not_holidays)
266              text: Script.__txtInfo_format()
267              horizontalAlignment: Text.AlignHCenter
268              anchors.horizontalCenter: parent.horizontalCenter
269              opacity: 0.6
270              font.bold: (screen.is_holiday ? true : false)
271              font.pixelSize: (screen.is_holiday ? 25 : 20)
272          }
273
274          Text {
275
276              id: txtDAYAmLich
277              x: 151
278              y: 330
279              height: 20
280              color: "#f0f0f5"
281              text: Script.__txtDAYAmLich_format()
282              horizontalAlignment: Text.AlignHCenter
283              anchors.horizontalCenter: parent.horizontalCenter
284              opacity: 0.6
285              font.bold: true
286              font.pixelSize: 25
287          }
288
289          ToolBar { id: toolBar; height: 42;
290              y: screen.height - 52
291              width: parent.width; opacity: 0.8
292              button1Label: "Menu"
293              button2Label: "Lựa Chọn"
294              onButton1Clicked:
295              {
296                  screen.state="switchX"
297                  var menuscreen = Script.createObject("MenuScreen.qml", screen);
298                  menuscreen.close.connect(closeDialogs);
299                  menuscreen.item_click.connect(menu_item_Clicked);
300                  menuscreen.state = "show";
301              }
302              onButton2Clicked: {
303                  screen.state="switchX"
304                  var optionsscreen = Script.createObject("OptionsScreen.qml", screen);
305                  optionsscreen.close.connect(closeDialogs);
306                  optionsscreen.state = "show";
307              }
308
309          }
310
311          MultiTitleBar { id: titleBar; width: parent.width }
312
313      }
314
315      function closeDialogs(){
316          dialogClose();
317          screen.state="mainscreen";
318      }
319
320      function menu_item_Clicked(id){
321          var qmlF = "";
322          if (id!=1)
323             screen.state="switchX";
324          switch(id){
325             case 1: Script.reset_to_default_day(txtTHU, txtInfo, txtDAYAmLich);
326                  txtDATEpv.currentIndex = Script.curDay-1;
327                 screen.curMonth = Script.curMonth;
328                 screen.curYear = Script.curYear;
329                 Script.fullmonth.m_day= Script.curDay-1;
330                 Script.fullmonth.m_month= Script.curMonth;
331                 Script.fullmonth.m_year= Script.curYear;
332                 break;
333             case 2: Script.amdatetimedlg.state="show";break;
334             case 3: Script.datetimedlg.state="show";break;
335             case 4: qmlF="XemNgayTotXauHoangDao";break;
336             case 5: Script.fullmonth.state="show";break;
337             case 6: qmlF = "About";break;
338             default:screen.state = "mainscreen";qmlF="";break;
339          }
340          if (qmlF){
341              var qmlobj = Script.createObject(qmlF+".qml", screen);
342              qmlobj.close.connect(closeDialogs);
343              qmlobj.state = "show";
344          }
345      }
346
347      states: [
348          State {
349              name:"mainscreen"
350              StateChangeScript {
351                  script:{
352                  }
353                 }
354          },
355          State {
356              name: "switchX";
357              PropertyChanges { target: toolBar; y: screen.height }
358              PropertyChanges { target: toolBar }
359              PropertyChanges { target: mouseareaMM;enabled:false }
360          }
361      ]
362
363      transitions: [
364          Transition { NumberAnimation { properties: "x,y,opacity"; duration: 300; easing.type: Easing.InOutBack } }
365      ]
366
367 }