Added global controller andalso filebrowser qml
[lichviet] / qml / LichViet / main.qml
index aa948ae..338f9a1 100644 (file)
@@ -3,7 +3,7 @@ Copyright (C) 2011  by Cuong Le <metacuong@gmail.com>
 
 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
+the Free Software Foundation, either version 2 of the License, or
 (at your option) any later version.
 
 This program is distributed in the hope that it will be useful,
@@ -21,6 +21,7 @@ import "amlich-aa98.js" as AmLich98
 
 import "Settings.js" as Settings
 import "Themes.js" as Themes
+import "CacNgayLeTrongNam.js" as CNLTN
 
 Item {
      id: screen
@@ -46,7 +47,8 @@ Item {
      property string lunarDayCanChi : AmLich.getCanChi(AmLich.getLunarDate(curDay,curMonth,curYear))[0]
      property string lunarMonthCanChi : AmLich.getCanChi(AmLich.getLunarDate(curDay,curMonth,curYear))[1]
 
-     //property string lunarCanHour : AmLich.getCanHour0(LC.curHour())
+     property string day_info : CNLTN.get(screen)
+     property bool is_holiday : CNLTN.is_holiday(screen.curDay,screen.curMonth, screen.curYear, screen.lunarDay, screen.lunarMonth)
 
      state:"mainscreen"
 
@@ -63,7 +65,7 @@ Item {
 
          state:"jumptodate"
          Image {
-             source: theme_manager.theme.background_image; fillMode: Image.Tile; anchors.fill: parent; opacity: 0.3
+             source: theme_manager.theme.background_image; fillMode: Image.Stretch; anchors.fill: parent; opacity: 0.3
          }
 
 
@@ -98,9 +100,10 @@ Item {
              width: 80
              height: 20
              color: "#29d999"
-             text: "Tháng "+screen.curMonth+" Năm "+screen.curYear
+             textFormat: Text.RichText
+             text: "Tháng <b>"+screen.curMonth+"</b> Năm <b>"+screen.curYear+"</b>"
              anchors.horizontalCenter: parent.horizontalCenter
-             font.bold: true
+             font.bold: false
              font.family: "Tahoma"
              smooth: true
              horizontalAlignment: Text.AlignHCenter
@@ -111,13 +114,14 @@ Item {
 
                   Rectangle {
                       id:reelx
-                              width: 300
-                              height: 100
-                                           y: 126
-                                           anchors.horizontalCenter: parent.horizontalCenter
-                                           property int index: 0
-         onIndexChanged: txtDATEpv.currentIndex = reelx.index
-         color: "transparent"
+                      width: 260
+                      height: 90
+                      y: 116
+                      anchors.horizontalCenter: parent.horizontalCenter
+                      property int index: 0
+                      onIndexChanged: txtDATEpv.currentIndex = reelx.index
+                      color: "transparent"
+
                       Component {
                           id: delegate
                           Column {
@@ -127,7 +131,24 @@ Item {
                                   text: name
                                   font.bold: true
                                   font.pixelSize: wrapper.PathView.isCurrentItem ? 80 : 40
-                                  color: wrapper.PathView.isCurrentItem ? "#FFFFFF" : "grey"
+                                  color: {
+                                      if (wrapper.PathView.isCurrentItem){
+                                          var stemp = AmLich98.convertSolar2Lunar(txtDATEpv.currentIndex+1,curMonth,curYear,7);
+                                          if (CNLTN.is_holiday(txtDATEpv.currentIndex+1,curMonth, stemp[0], stemp[1])){
+                                              return theme_manager.theme.markdate.holidays;
+                                          }else{
+                                          var mark_day = (AmLich.getLunarDate(txtDATEpv.currentIndex+1,curMonth,curYear).jd+1)%7;
+                                          if (mark_day === 0) //sunday
+                                              return theme_manager.theme.markdate.sunday;
+                                          if (mark_day == 6) //saturday
+                                              return theme_manager.theme.markdate.saturday;
+                                          else
+                                              return  theme_manager.theme.markdate.otherday_selected;
+                                          }
+                                      }
+                                      else
+                                          return "transparent";//theme_manager.theme.markdate.otherday;
+                                    }
                               }
                           }
                       }
@@ -139,15 +160,30 @@ Item {
                           delegate: delegate
                           pathItemCount: 3
                           clip: true
+                          highlightMoveDuration:500
+                          Keys.onDownPressed: if (!moving && interactive) incrementCurrentIndex()
+                          Keys.onUpPressed: if (!moving && interactive) decrementCurrentIndex()
                           preferredHighlightBegin: 0.5
                           preferredHighlightEnd: 0.5
                           highlightRangeMode: PathView.StrictlyEnforceRange
                           focus: true
+                          interactive: true
+                          highlight: Rectangle{
+                              anchors.topMargin: 10;
+                              width:110;
+                              height:80;
+                              radius: 8;
+                              color:"#000000"
+                              opacity: 0.3
+                          }
                           path: Path {
                               startX: 0
                               startY: 50
                               PathLine {x: reelx.width; y: 50}
                           }
+                          onFlickEnded : {
+                          }
+
                           onMovementEnded: {
                               calculateLunar(txtDATEpv.currentIndex+1, LC.curMonth(), LC.curYear())
                           }
@@ -157,25 +193,42 @@ Item {
                       id:maindatemodel
 
                       function reset(){
-                          while(maindatemodel.count>0){
-                              try{maindatemodel.remove(maindatemodel.count-1)}catch(e){}
+                          var days_of_this_month = LC.calDays(screen.curMonth,screen.curYear);
+                          var days_of_changes = days_of_this_month - maindatemodel.count;
+
+                          var ifs;
+
+                          if (days_of_changes<0){
+                              ifs=Math.abs(days_of_changes);
+                              while(ifs>0){
+                                  maindatemodel.remove(maindatemodel.count-1);
+                                  ifs-=1;
+                              }
+                          }else if(days_of_changes>0){
+                              ifs=maindatemodel.count;
+                              for (var i=1;i<=days_of_changes;i++)
+                                  append({name:i+ifs})
                           }
 
+                         reelx.index = -1; // I dont now why must be added -1 before screen.curDay-1
+                         reelx.index = screen.curDay-1;
+
+                      }
+
+                      function init(){
                           for(var i=1;i<=LC.calDays(screen.curMonth,screen.curYear);i++)
                               append({name:i})
+
                           reelx.index = screen.curDay -1
                       }
                   }
 
          //-------------------------------------------------
-                  Component.onCompleted: {
-                     maindatemodel.reset()
-                  }
 
          Text {
              id: txtTHU
              x: 151
-             y: 240
+             y: 210
              width: 80
              height: 20
              color: "#f0f0f5"
@@ -188,10 +241,25 @@ Item {
          }
 
          Text {
+             id: txtInfo
+             x: 151
+             y: (screen.is_holiday ? 270 : 250)
+             width: 80
+             height: 20
+             color: (screen.is_holiday ? theme_manager.theme.markdate.holidays : theme_manager.theme.markdate.not_holidays)
+             text: screen.day_info
+             horizontalAlignment: Text.AlignHCenter
+             anchors.horizontalCenter: parent.horizontalCenter
+             opacity: 0.6
+             font.bold: (screen.is_holiday ? true : false)
+             font.pixelSize: (screen.is_holiday ? 25 : 20)
+         }
+
+         Text {
 
              id: txtDAYAmLich
              x: 151
-             y: 300
+             y: 330
              width: 80
              height: 20
              color: "#f0f0f5"
@@ -200,7 +268,7 @@ Item {
              anchors.horizontalCenter: parent.horizontalCenter
              opacity: 0.6
              font.bold: true
-             font.pixelSize: 28
+             font.pixelSize: 25
          }
 
 
@@ -220,6 +288,14 @@ Item {
              x: -(screen.width * 1.5)
          }
 
+         ChangeTheme{
+             id: changeTheme
+             state:"changetheme"
+             anchors.verticalCenter: parent.verticalCenter
+             width: parent.width; height: parent.height-60;
+             x: -(screen.width * 1.5)
+         }
+
          XemNgayTotXauHoangDao{
              id: xntxhdScreen
              state:"xemngaytotxauhoangdao"
@@ -252,18 +328,17 @@ Item {
              x: -(screen.width * 1.5)
          }
 
-         NoFeatureDialog{
-             id: nofeatureDialog
-             state:"nofeaturedialog"
+         About{
+             id: aboutDialog
+             state:"aboutdialog"
              anchors.verticalCenter: parent.verticalCenter
              width: parent.width; height: parent.height-60;
              x: -(screen.width * 1.5)
          }
 
-
-         About{
-             id: aboutDialog
-             state:"aboutdialog"
+         FileBrowser{
+             id: fileBrowser
+             state:"filebrowser"
              anchors.verticalCenter: parent.verticalCenter
              width: parent.width; height: parent.height-60;
              x: -(screen.width * 1.5)
@@ -288,6 +363,13 @@ Item {
 
      states: [
          State {
+             name:"mainscreen"
+             StateChangeScript {
+                 script:{
+                 }
+                }
+         },
+         State {
              name: "menuscreen";
              PropertyChanges { target: menuScreen; x: 0; focus:true}
              PropertyChanges { target: toolBar; y: screen.height }
@@ -295,6 +377,12 @@ Item {
                           PropertyChanges { target: mouseareaMM;enabled:false }
 
          },
+             State{
+                 name:"filebrowser"
+                 PropertyChanges { target: fileBrowser; x: 0; focus:true; visible:true;}
+                 PropertyChanges { target: toolBar; y: screen.height }
+                 PropertyChanges { target: toolBar }
+             },
          State {
              name: "optionsscreen";
              PropertyChanges { target: optionsScreen; x: 0; focus:true}
@@ -304,8 +392,17 @@ Item {
 
          },
          State {
+             name: "changetheme";
+             PropertyChanges { target: changeTheme; x: 0; focus:true}
+             PropertyChanges { target: toolBar; y: screen.height }
+             PropertyChanges { target: toolBar }
+             PropertyChanges { target: reelx;enabled:false }
+             PropertyChanges { target: mouseareaMM;enabled:false }
+
+         },
+         State {
              name: "xemngaytotxauhoangdao";
-             PropertyChanges { target: xntxhdScreen; x: 0; focus:true}
+             PropertyChanges { target: xntxhdScreen; x: 0; focus:true;visible:true;}
              PropertyChanges { target: toolBar; y: screen.height }
              PropertyChanges { target: toolBar }
              PropertyChanges { target: mouseareaMM;enabled:false }
@@ -344,23 +441,15 @@ Item {
                 }
          },
          State {
-             name: "nofeaturedialog";
-             PropertyChanges { target: nofeatureDialog; x: 0; focus:true}
-             PropertyChanges { target: toolBar; y: screen.height }
-             PropertyChanges { target: toolBar }
-             PropertyChanges { target: mouseareaMM;enabled:false }
-                                                                 PropertyChanges { target: reelx;enabled:false }
-         },
-         State {
              name: "aboutdialog";
-             PropertyChanges { target: aboutDialog; x: 0; focus:true}
+             PropertyChanges { target: aboutDialog; x: 0; focus:true; visible:true;}
              PropertyChanges { target: toolBar; y: screen.height }
              PropertyChanges { target: toolBar }
              PropertyChanges { target: mouseareaMM;enabled:false }
          },
          State {
              name: "xemtheothang";
-             PropertyChanges { target: fullmonthDialog; x: 0; focus:true}
+             PropertyChanges { target: fullmonthDialog; x: 0; focus:true; visible:true;}
              PropertyChanges { target: toolBar; y: screen.height }
              PropertyChanges { target: toolBar }
              StateChangeScript {
@@ -373,7 +462,8 @@ Item {
      ]
 
      transitions: [
-         Transition { NumberAnimation { properties: "x,y,opacity"; duration: 500; easing.type: Easing.InOutBack } }
+         //normally i used InOutBack
+         Transition { NumberAnimation { properties: "x,y,opacity"; duration: 300; easing.type: Easing.InOutBack } }
      ]
 
 
@@ -407,9 +497,12 @@ Item {
      }
 
      function refresh(){
+
      }
 
      Component.onCompleted: {
-
+        amdatetimeDialog.reset()
+        maindatemodel.init()
      }
+
 }