* Improved QML/JS.
[lichviet] / qml / LichViet / AmDateTimeDialog.qml
index 63890b7..83f05cd 100644 (file)
@@ -16,13 +16,26 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>
 */
 
 import QtQuick 1.0
-import "amlich-hnd.js" as AmLich
-import "amlich-aa98.js" as AmLich98
+
+import "Themes.js" as Themes
+import "main.js" as Script
 
 Item{
     id: amdatetime
     state: "switch_me"
 
+    anchors.verticalCenter: parent.verticalCenter
+    width: parent.width; height: parent.height;
+    x:(parent.width * 1.5)
+
+    Loader {
+        id: theme_manager
+        property alias theme: theme_manager.item
+        source: Themes.default_theme()
+    }
+
+    signal toolbar
+
     Rectangle {
         id: rectangle1
         x: 0
@@ -63,12 +76,12 @@ Item{
                  if (thangnhuan!=-1 && lunarmonth_pathview.currentIndex> thangnhuan)
                      lmonth-=1;
 
-                var finalSolarDay = AmLich98.convertLunar2Solar(lday,lmonth,lyear,lnhuan,7)
+                var finalSolarDay = Script.convertLunar2Solar(lday,lmonth,lyear,lnhuan,7)
 
                  LC.reset(finalSolarDay[0],finalSolarDay[1],finalSolarDay[2])
-                 screen.calculateLunar( finalSolarDay[0], finalSolarDay[1], finalSolarDay[2])
-                 screen.state="mainscreen"
-                 screen.refresh()
+                 Script.calculateLunar( finalSolarDay[0], finalSolarDay[1], finalSolarDay[2])
+                 Script.state="mainscreen"
+                 Script.refresh()
 
                  maindatemodel.reset()
                  txtDATEpv.currentIndex =  finalSolarDay[0]-1;
@@ -84,11 +97,14 @@ Item{
             height: 40
             text: "X"
             anchors.rightMargin: 56
-            onClicked: {screen.state="mainscreen"}
+            onClicked: {
+                amdatetime.state="close"
+                amdatetime.toolbar()
+            }
         }
 
         Rectangle {
-            id: rectangle2
+            id: rec22
             x: 23
             y: 89
             width: 415
@@ -135,6 +151,38 @@ Item{
                 }
             }
 
+            states: [
+                State {
+                    name: "switch_to_day";
+                    PropertyChanges { target:lmk;x:10;width:60;}
+                    PropertyChanges { target:lunaryear_pathview;pathItemCount:1;}
+                    PropertyChanges { target:lunarmonth_pathview;pathItemCount:1;}
+                    PropertyChanges { target:lunarday_pathview;pathItemCount:3;}
+                    PropertyChanges { target:lunarday_mousearea;visible:false;}
+                    PropertyChanges { target:lunaryear_mousearea;visible:true;}
+                    PropertyChanges { target:lunarmonth_mousearea;visible:true;}
+                },
+                State {
+                    name: "switch_to_year";
+                    PropertyChanges { target:lmk;x:207;width:198;}
+                    PropertyChanges { target:lunarday_pathview;pathItemCount:1;}
+                    PropertyChanges { target:lunarmonth_pathview;pathItemCount:1;}
+                    PropertyChanges { target:lunaryear_pathview;pathItemCount:3;}
+                    PropertyChanges { target:lunarday_mousearea;visible:true;}
+                    PropertyChanges { target:lunaryear_mousearea;visible:false;}
+                    PropertyChanges { target:lunarmonth_mousearea;visible:true;}
+                },
+                State {
+                    name: "switch_to_month";
+                    PropertyChanges { target:lmk;x:60;width:150;}
+                    PropertyChanges { target:lunarday_pathview;pathItemCount:1;}
+                    PropertyChanges { target:lunaryear_pathview;pathItemCount:1;}
+                    PropertyChanges { target:lunarmonth_pathview;pathItemCount:3;}
+                    PropertyChanges { target:lunarday_mousearea;visible:true;}
+                    PropertyChanges { target:lunaryear_mousearea;visible:true;}
+                    PropertyChanges { target:lunarmonth_mousearea;visible:false;}
+                }]
+
             /**LUNAR YEAR**/
             Rectangle {
                 id:lunaryear_rec
@@ -182,7 +230,7 @@ Item{
 
                      onMovementEnded: {
                          //console.log(lunaryear_pathview.currentIndex)
-                         AmLich.getYearInfo(lunaryear_pathview.currentIndex+1900);
+                         Script.getYearInfo(lunaryear_pathview.currentIndex+1900);
                          lunarmonth_model.change(lunaryear_pathview.currentIndex+1900, lunarmonth_pathview.currentIndex+1);
                      }
                 }
@@ -190,7 +238,7 @@ Item{
                     id:lunaryear_mousearea
                     anchors.fill: parent
                     onClicked: {
-                        amdatetime.state="switch_to_year"
+                        rec22.state="switch_to_year"
                     }
                 }
             }
@@ -198,17 +246,18 @@ Item{
             ListModel {
                 id:lunaryear_model
                 Component.onCompleted: {
-                    init()
+                    //init()
                  }
 
                 function init(){
                     for(var i=1900;i<2099;i++){
-                        var lunarYear = AmLich.getYearCanChi(i)
+                        var lunarYear = Script.getYearCanChi(i)
                         append({name:i+" ("+lunarYear+")"})
                     }
                 }
 
                 function change(YYYY){
+                    lunaryear_pathview.currentIndex=-1;
                     lunaryear_pathview.currentIndex = YYYY - 1900
                 }
             }
@@ -266,7 +315,7 @@ Item{
                         id:lunarday_mousearea
                         anchors.fill: parent
                         onClicked: {
-                            amdatetime.state="switch_to_day"
+                            rec22.state="switch_to_day"
                         }
                     }
 
@@ -275,8 +324,12 @@ Item{
                 ListModel {
                     id:lunarday_model
                     Component.onCompleted: {
+
+                    }
+
+                    function init(){
                         for(var i=1;i<=30;i++)
-                            append({name:i})
+                            lunarday_model.append({name:i})
                     }
 
                     function change(MM,DD){
@@ -286,11 +339,11 @@ Item{
                         }
 
 
-                        var daystotal = AmLich.RMM[MM-1];
+                        var daystotal = Script.RMM[MM-1];
 
                         if(lunarmonth_model.get(MM-1).nhuan){
 
-                                for (var i=1;i<=AmLich.LML;i++)
+                                for (var i=1;i<=Script.LML;i++)
                                      lunarday_model.append({name:i})
 
                         }else{
@@ -337,7 +390,7 @@ Item{
                             lunarday_model.append({name:i})
                         }*/
 
-                        lunarday_rec.index = DD-1;
+                        lunarday_pathview.currentIndex=-1;
                         lunarday_pathview.currentIndex= DD-1;
 
                     }
@@ -404,7 +457,7 @@ Item{
                             id:lunarmonth_mousearea
                             anchors.fill: parent
                             onClicked: {
-                                amdatetime.state="switch_to_month"
+                                rec22.state="switch_to_month"
                             }
                         }
 
@@ -429,11 +482,11 @@ Item{
                         function readd(YYYY, MM){
                             var yTest = YYYY;
                             var preFix = "Tháng ";
-                            var a=AmLich.leapMonth(yTest)
+                            var a=Script.leapMonth(yTest)
                             var t=0;
                             if(a){ // nam nhuan
                                  for(var i=0;i<=12;i++){
-                                    var l=AmLich.getYearInfo(yTest)[i].month
+                                    var l=Script.getYearInfo(yTest)[i].month
                                      if (t==l)
                                          lunarmonth_model.append({name:preFix+l+" (N)", nhuan:true})
                                      else
@@ -447,7 +500,8 @@ Item{
                                     lunarmonth_model.append({name:preFix+i, nhuan:false})
                             }
 
-                            lunarmonth_rec.index = MM -1;
+                            //lunarmonth_rec.index = MM -1;
+                            lunarmonth_pathview.currentIndex=-1;
                             lunarmonth_pathview.currentIndex = MM-1;
 
                         }
@@ -459,50 +513,28 @@ Item{
     }
 
     Component.onCompleted: {
-
+        reset();
     }
 
     states: [
         State {
-            name: "switch_to_day";
-            PropertyChanges { target:lmk;x:10;width:60;}
-            PropertyChanges { target:lunaryear_pathview;pathItemCount:1;}
-                                    PropertyChanges { target:lunarmonth_pathview;pathItemCount:1;}
-            PropertyChanges { target:lunarday_pathview;pathItemCount:3;}
-            PropertyChanges { target:lunarday_mousearea;visible:false;}
-            PropertyChanges { target:lunaryear_mousearea;visible:true;}
-            PropertyChanges { target:lunarmonth_mousearea;visible:true;}
+            name: "show"
+            AnchorChanges { target: amdatetime; anchors.right: parent.right }
         },
         State {
-            name: "switch_to_year";
-            PropertyChanges { target:lmk;x:207;width:198;}
-            PropertyChanges { target:lunarday_pathview;pathItemCount:1;}
-                                    PropertyChanges { target:lunarmonth_pathview;pathItemCount:1;}
-            PropertyChanges { target:lunaryear_pathview;pathItemCount:3;}
-            PropertyChanges { target:lunarday_mousearea;visible:true;}
-            PropertyChanges { target:lunaryear_mousearea;visible:false;}
-                        PropertyChanges { target:lunarmonth_mousearea;visible:true;}
-        },
-        State {
-            name: "switch_to_month";
-            PropertyChanges { target:lmk;x:60;width:150;}
-            PropertyChanges { target:lunarday_pathview;pathItemCount:1;}
-            PropertyChanges { target:lunaryear_pathview;pathItemCount:1;}
-                        PropertyChanges { target:lunarmonth_pathview;pathItemCount:3;}
-            PropertyChanges { target:lunarday_mousearea;visible:true;}
-            PropertyChanges { target:lunaryear_mousearea;visible:true;}
-                        PropertyChanges { target:lunarmonth_mousearea;visible:false;}
+            name: "close"
+            AnchorChanges { target: amdatetime; anchors.right: parent.left }
         }
     ]
 
     function reset(){
-        var acs = AmLich.getYearInfo(screen.curYear)
-        var a=AmLich.getLunarDate(screen.curDay,screen.curMonth,screen.curYear)
+        var acs = Script.getYearInfo(Script.curYear)
+        var a=Script.getLunarDate(Script.curDay,Script.curMonth,Script.curYear)
                 var finalmonth=a.month;
         if (a.leap)
             finalmonth+=1;
         else{
-        var aaa=AmLich.leapMonth(screen.curYear)
+        var aaa=Script.leapMonth(Script.curYear)
         var t=-1;
 
         if (aaa){
@@ -520,9 +552,15 @@ Item{
         }
         }
 
+        lunaryear_model.init()
+        lunarday_model.init()
         lunaryear_model.change(a.year)
         lunarmonth_model.change(a.year, finalmonth)
         lunarday_model.change(finalmonth,a.day)
 
     }
+
+    transitions: Transition {
+        AnchorAnimation { easing.type: Easing.OutQuart; duration: 300 }
+    }
 }