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