* Fixes for pathview date component (slowly in date switching)
[lichviet] / qml / LichViet / main.qml
index aa948ae..1c7eb47 100644 (file)
@@ -21,11 +21,12 @@ import "amlich-aa98.js" as AmLich98
 
 import "Settings.js" as Settings
 import "Themes.js" as Themes
+import "CacNgayLeTrongNam.js" as CNLTN
 
 Item {
      id: screen
-     width: 800
-     height: 480
+     width: 480
+     height: 800
 
      property int curDay: LC.curDay()
      property int curMonth: LC.curMonth()
@@ -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
          }
 
 
@@ -111,13 +113,13 @@ 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 +129,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 theme_manager.theme.markdate.otherday;
+                                    }
                               }
                           }
                       }
@@ -139,15 +158,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 +191,49 @@ Item {
                       id:maindatemodel
 
                       function reset(){
+                          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(){
                           while(maindatemodel.count>0){
                               try{maindatemodel.remove(maindatemodel.count-1)}catch(e){}
                           }
 
                           for(var i=1;i<=LC.calDays(screen.curMonth,screen.curYear);i++)
                               append({name:i})
+
                           reelx.index = screen.curDay -1
                       }
                   }
 
          //-------------------------------------------------
                   Component.onCompleted: {
-                     maindatemodel.reset()
+                     maindatemodel.init()
                   }
 
          Text {
              id: txtTHU
              x: 151
-             y: 240
+             y: 210
              width: 80
              height: 20
              color: "#f0f0f5"
@@ -188,10 +246,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 +273,7 @@ Item {
              anchors.horizontalCenter: parent.horizontalCenter
              opacity: 0.6
              font.bold: true
-             font.pixelSize: 28
+             font.pixelSize: 25
          }
 
 
@@ -220,6 +293,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"
@@ -288,6 +369,13 @@ Item {
 
      states: [
          State {
+             name:"mainscreen"
+             StateChangeScript {
+                 script:{
+                 }
+                }
+         },
+         State {
              name: "menuscreen";
              PropertyChanges { target: menuScreen; x: 0; focus:true}
              PropertyChanges { target: toolBar; y: screen.height }
@@ -304,6 +392,14 @@ Item {
 
          },
          State {
+             name: "changetheme";
+             PropertyChanges { target: changeTheme; x: 0; focus:true}
+             PropertyChanges { target: toolBar; y: screen.height }
+             PropertyChanges { target: toolBar }
+                          PropertyChanges { target: mouseareaMM;enabled:false }
+
+         },
+         State {
              name: "xemngaytotxauhoangdao";
              PropertyChanges { target: xntxhdScreen; x: 0; focus:true}
              PropertyChanges { target: toolBar; y: screen.height }
@@ -407,6 +503,7 @@ Item {
      }
 
      function refresh(){
+
      }
 
      Component.onCompleted: {