* Improved QML/JS.
[lichviet] / qml / LichViet / XemNgayTotXauHoangDao.qml
index 718efcf..f5f4c3b 100644 (file)
@@ -17,11 +17,32 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>
 
 import QtQuick 1.0
 
-import "amlich-hnd.js" as AmLich
-import "xemngaytotxau.js" as NTX
+import "main.js" as Script
+import "Themes.js" as Themes
 
 Item{
-    id:main_item
+    id:xntxhd
+
+    anchors.verticalCenter: parent.verticalCenter
+    width: parent.width; height: parent.height;
+    x:(parent.width * 1.5)
+
+    signal close
+
+    Loader {
+        id: theme_manager
+        property alias theme: theme_manager.item
+        source: Themes.default_theme()
+    }
+
+    Connections {
+        target: xntxhd.parent
+
+        onDialogClose: {
+            xntxhd.state = "close";
+            xntxhd.destroy(600);
+        }
+    }
 
     property string day_month_year_LN_CN:  ""
     property string nhi_thap_bat_tu:  ""
@@ -35,12 +56,8 @@ Item{
 
     Rectangle {
         id: rectangle1
-        x: 0
-        y: -5
-        anchors.rightMargin: 0
-        anchors.leftMargin: 0
-        anchors.topMargin:30
-        anchors.fill: parent; anchors.bottomMargin: 16
+
+        anchors.fill: parent; anchors.bottomMargin: 0;
         visible: true
         opacity:0.9
 
@@ -51,7 +68,7 @@ Item{
                 Column {
 
                     Rectangle {
-                                        width:rectangle1.width;
+                                        width:rectangle1.width-10;
                                         y:30;
                                         x:0
                                         height:1
@@ -66,7 +83,7 @@ Item{
                     }
 
                     Text { x:5;y:50;text:getHD(name,idm) ;textFormat: Text.RichText;wrapMode: Text.WordWrap; font.pixelSize: 20
-                        font.family: "Tahoma";width:parent.width;}
+                        font.family: "Tahoma";width:parent.width-10;}
 
                     Rectangle{
                         width:rectangle1.width;
@@ -117,7 +134,7 @@ Item{
 
         ListView {
               id: listView
-              anchors.fill: parent;anchors.topMargin: 0;anchors.leftMargin: 0; anchors.bottomMargin: 16
+              anchors.fill: parent;anchors.topMargin: 45;anchors.leftMargin: 5;anchors.rightMargin: 5;anchors.bottomMargin: 55
               model: listModel
               delegate: listDelegate
               focus: true
@@ -127,14 +144,12 @@ Item{
 
     }
 
-    ToolBarSingle { id: toolBar; height: 50;
-        y: screen.height-78
+    ToolBarSingle {
+        id: toolBar; height: 42;
+        y: parent.height-52
         width: parent.width;
         button1Label: "Quay Về"
-        onButton1Clicked:
-        {
-            screen.state="mainscreen"
-        }
+        onButton1Clicked:xntxhd.close()
     }
 
     function getHD(name,idm){
@@ -142,28 +157,63 @@ Item{
             name="<span style='color:blue;'>"+name+"</span><br>";
         }
 
+        reset();
+
         switch(idm){
-        case 0 : return name+ main_item.day_month_year_LN_CN;break;
-        case 1 : return name+screen.lunarGioHoangDao;break;
-        case 2 : return name+screen.lunarTietKhi();break;
-        case 3 : return name+main_item.nhi_thap_bat_tu; break;
-        case 5 :  return name+main_item.luan_giai;break;
-        case -1: return name+main_item.truc;break;
-        case 6: return name+main_item.cac_sao_tot;break;
-        case 7: return name+main_item.cac_sao_xau;break;
-        case -2: return name+main_item.huong_xuat_hanh;break;
-        case 8: return main_item.warnning;break;
+        case 0 : return name+ xntxhd.day_month_year_LN_CN;break;
+        case 1 : return name+Script.lunarGioHoangDao;break;
+        case 2 : return name+Script.lunarTietKhi();break;
+        case 3 : return name+xntxhd.nhi_thap_bat_tu; break;
+        case 5 :  return name+xntxhd.luan_giai;break;
+        case -1: return name+xntxhd.truc;break;
+        case 6: return name+xntxhd.cac_sao_tot;break;
+        case 7: return name+xntxhd.cac_sao_xau;break;
+        case -2: return name+xntxhd.huong_xuat_hanh;break;
+        case 8: return xntxhd.warnning;break;
         }
     }
 
     function reset(){
-        main_item.day_month_year_LN_CN = AmLich.getTHU(screen.jd)+",ngày <b>"+screen.curDay+"</b> tháng <b>"+screen.curMonth+"</b> năm <b>"+screen.curYear+"</b><br>Ngày <b>"+screen.lunarDay+"</b> tháng <b>"+screen.lunarMonth+"</b> năm <b>"+screen.lunarYear+"</b> (<b>"+screen.lunarYearInt+"</b>)";
-        main_item.nhi_thap_bat_tu = NTX.sao(screen.curYear,AmLich.getLunarDate(screen.curDay,screen.curMonth,screen.curYear).jd - AmLich.getLunarDate(1,1,screen.curYear).jd);
-        main_item.truc = NTX.truc(screen.lunarMonth, screen.lunarDayCanChi, screen.lunarMonthCanChi);
-        main_item.cac_sao_tot = NTX.cacsaotot(screen.lunarMonth, screen.lunarDayCanChi);
-        main_item.cac_sao_xau = NTX.cacsaoxau(screen.lunarMonth, screen.lunarDayCanChi);
-        main_item.luan_giai = NTX.luangiai(screen.curDay);
-        main_item.huong_xuat_hanh = NTX.huong_xuat_hanh(screen.lunarDayCanChi);
+        xntxhd.day_month_year_LN_CN = Script.thu()+",ngày <b>"+Script.curDay+"</b> tháng <b>"+Script.curMonth+"</b> năm <b>"+Script.curYear+"</b><br>Ngày <b>"+Script.lunarDay+"</b> tháng <b>"+Script.lunarMonth+"</b> năm <b>"+Script.lunarYear+"</b> (<b>"+Script.lunarYearInt+"</b>)";
+        xntxhd.nhi_thap_bat_tu = Script.sao(Script.curYear,Script.getLunarDate(Script.curDay,Script.curMonth,Script.curYear).jd - Script.getLunarDate(1,1,Script.curYear).jd);
+        xntxhd.truc = Script.truc(Script.lunarMonth, Script.lunarDayCanChi, Script.lunarMonthCanChi);
+        xntxhd.cac_sao_tot = Script.cacsaotot(Script.lunarMonth, Script.lunarDayCanChi);
+        xntxhd.cac_sao_xau = Script.cacsaoxau(Script.lunarMonth, Script.lunarDayCanChi);
+        xntxhd.luan_giai = Script.luangiai(Script.curDay);
+        xntxhd.huong_xuat_hanh = Script.huong_xuat_hanh(Script.lunarDayCanChi);
+    }
+
+    Rectangle {
+        width : xntxhd.width
+        height: 45
+        color:"white"
+        opacity: 0.5
+    }
+
+    Text {
+        id: title
+
+        anchors { horizontalCenter: xntxhd.horizontalCenter; top: xntxhd.top; topMargin: 10 }
+        font.pixelSize: 22
+        color: "black"
+        text: "Xem Ngày Tốt/Xấu"
+        smooth: true
+        font.bold: true
+    }
+
+    states: [
+        State {
+            name: "show"
+            AnchorChanges { target: xntxhd; anchors.right: parent.right }
+        },
+        State {
+            name: "close"
+            AnchorChanges { target: xntxhd; anchors.right: parent.left }
+        }
+    ]
+
+    transitions: Transition {
+        AnchorAnimation { easing.type: Easing.OutQuart; duration: 300 }
     }
 
 }