* Theme now is simple and very fast
[lichviet] / qml / LichViet / AmDateTimeDialog.qml
index d7d9a09..2cafdd2 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
 
 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,
 (at your option) any later version.
 
 This program is distributed in the hope that it will be useful,
@@ -16,13 +16,27 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>
 */
 
 import QtQuick 1.0
 */
 
 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"
 
 
 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
+    signal updatedate(int day, int month, int year)
+
     Rectangle {
         id: rectangle1
         x: 0
     Rectangle {
         id: rectangle1
         x: 0
@@ -38,8 +52,9 @@ Item{
 
         Button {
             id: button2
 
         Button {
             id: button2
-            x: 313
-            anchors.right: parent.right; anchors.rightMargin: 8; y: 185; width: 140; height: 40
+            anchors.right: parent.right; anchors.rightMargin: 145; y: 185; width: 100; height: 40
+            anchors.horizontalCenter: parent.horizontalCenter
+
             text: "OK"
             onClicked: {
                  var lday = lunarday_pathview.currentIndex+1;
             text: "OK"
             onClicked: {
                  var lday = lunarday_pathview.currentIndex+1;
@@ -63,15 +78,11 @@ Item{
                  if (thangnhuan!=-1 && lunarmonth_pathview.currentIndex> thangnhuan)
                      lmonth-=1;
 
                  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()
-
-                 maindatemodel.reset()
-                 txtDATEpv.currentIndex =  finalSolarDay[0]-1;
+                 amdatetime.state="close";
+                 amdatetime.toolbar();
+                 amdatetime.updatedate(finalSolarDay[0], finalSolarDay[1], finalSolarDay[2])
 
             }
         }
 
             }
         }
@@ -84,11 +95,14 @@ Item{
             height: 40
             text: "X"
             anchors.rightMargin: 56
             height: 40
             text: "X"
             anchors.rightMargin: 56
-            onClicked: {screen.state="mainscreen"}
+            onClicked: {
+                amdatetime.state="close"
+                amdatetime.toolbar()
+            }
         }
 
         Rectangle {
         }
 
         Rectangle {
-            id: rectangle2
+            id: rec22
             x: 23
             y: 89
             width: 415
             x: 23
             y: 89
             width: 415
@@ -135,6 +149,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
             /**LUNAR YEAR**/
             Rectangle {
                 id:lunaryear_rec
@@ -182,7 +228,7 @@ Item{
 
                      onMovementEnded: {
                          //console.log(lunaryear_pathview.currentIndex)
 
                      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);
                      }
                 }
                          lunarmonth_model.change(lunaryear_pathview.currentIndex+1900, lunarmonth_pathview.currentIndex+1);
                      }
                 }
@@ -190,7 +236,7 @@ Item{
                     id:lunaryear_mousearea
                     anchors.fill: parent
                     onClicked: {
                     id:lunaryear_mousearea
                     anchors.fill: parent
                     onClicked: {
-                        amdatetime.state="switch_to_year"
+                        rec22.state="switch_to_year"
                     }
                 }
             }
                     }
                 }
             }
@@ -198,17 +244,18 @@ Item{
             ListModel {
                 id:lunaryear_model
                 Component.onCompleted: {
             ListModel {
                 id:lunaryear_model
                 Component.onCompleted: {
-                    init()
+                    //init()
                  }
 
                 function init(){
                     for(var i=1900;i<2099;i++){
                  }
 
                 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){
                         append({name:i+" ("+lunarYear+")"})
                     }
                 }
 
                 function change(YYYY){
+                    lunaryear_pathview.currentIndex=-1;
                     lunaryear_pathview.currentIndex = YYYY - 1900
                 }
             }
                     lunaryear_pathview.currentIndex = YYYY - 1900
                 }
             }
@@ -266,7 +313,7 @@ Item{
                         id:lunarday_mousearea
                         anchors.fill: parent
                         onClicked: {
                         id:lunarday_mousearea
                         anchors.fill: parent
                         onClicked: {
-                            amdatetime.state="switch_to_day"
+                            rec22.state="switch_to_day"
                         }
                     }
 
                         }
                     }
 
@@ -275,8 +322,12 @@ Item{
                 ListModel {
                     id:lunarday_model
                     Component.onCompleted: {
                 ListModel {
                     id:lunarday_model
                     Component.onCompleted: {
+
+                    }
+
+                    function init(){
                         for(var i=1;i<=30;i++)
                         for(var i=1;i<=30;i++)
-                            append({name:i})
+                            lunarday_model.append({name:i})
                     }
 
                     function change(MM,DD){
                     }
 
                     function change(MM,DD){
@@ -286,11 +337,11 @@ Item{
                         }
 
 
                         }
 
 
-                        var daystotal = AmLich.RMM[MM-1];
+                        var daystotal = Script.RMM[MM-1];
 
                         if(lunarmonth_model.get(MM-1).nhuan){
 
 
                         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{
                                      lunarday_model.append({name:i})
 
                         }else{
@@ -337,7 +388,7 @@ Item{
                             lunarday_model.append({name:i})
                         }*/
 
                             lunarday_model.append({name:i})
                         }*/
 
-                        lunarday_rec.index = DD-1;
+                        lunarday_pathview.currentIndex=-1;
                         lunarday_pathview.currentIndex= DD-1;
 
                     }
                         lunarday_pathview.currentIndex= DD-1;
 
                     }
@@ -404,7 +455,7 @@ Item{
                             id:lunarmonth_mousearea
                             anchors.fill: parent
                             onClicked: {
                             id:lunarmonth_mousearea
                             anchors.fill: parent
                             onClicked: {
-                                amdatetime.state="switch_to_month"
+                                rec22.state="switch_to_month"
                             }
                         }
 
                             }
                         }
 
@@ -429,11 +480,11 @@ Item{
                         function readd(YYYY, MM){
                             var yTest = YYYY;
                             var preFix = "Tháng ";
                         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 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
                                      if (t==l)
                                          lunarmonth_model.append({name:preFix+l+" (N)", nhuan:true})
                                      else
@@ -447,7 +498,8 @@ Item{
                                     lunarmonth_model.append({name:preFix+i, nhuan:false})
                             }
 
                                     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;
 
                         }
                             lunarmonth_pathview.currentIndex = MM-1;
 
                         }
@@ -459,60 +511,34 @@ Item{
     }
 
     Component.onCompleted: {
     }
 
     Component.onCompleted: {
-
+        reset();
     }
 
     states: [
         State {
     }
 
     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;}
+            name: "show"
+            AnchorChanges { target: amdatetime; anchors.right: parent.right }
         },
         State {
         },
         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 }
         }
     ]
 
         }
     ]
 
-    transitions: [
-        Transition { NumberAnimation { properties: "x,y,opacity"; duration: 100; easing.type: Easing.InOutBack } }
-    ]
-
     function reset(){
     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 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){
            for (var i=0;i<=12;i++){
                var l=acs[i].month
         var t=-1;
 
         if (aaa){
            for (var i=0;i<=12;i++){
                var l=acs[i].month
-                if (t==l && a.leap==0){
+                if (t==l && a.leap===0){
                     if (a.month>i){
                     finalmonth = finalmonth+1;
                     break;
                     if (a.month>i){
                     finalmonth = finalmonth+1;
                     break;
@@ -524,9 +550,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)
 
     }
         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 }
+    }
 }
 }