/* Copyright (C) 2011 by Cuong Le 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 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see */ import QtQuick 1.0 import "../DatePicker/component" as Comp import "amlich-hnd.js" as AmLich import "amlich-aa98.js" as AmLich98 import "CacNgayLeTrongNam.js" as CNLTN Item{ id: fullmonth property int m_day: screen.curDay property int m_month: screen.curMonth property int m_year: screen.curYear property Component headerRenderer:Component { id: defaultHeaderRenderer Item { width: cellWidth height: cellHeight Rectangle { width: parent.width - 4 height: parent.height - 4 anchors.centerIn: parent radius: 4 color: "#FAFAFF" } Text { width: cellWidth height: cellHeight verticalAlignment: Text.AlignVCenter horizontalAlignment: Text.AlignHCenter text: model.modelData font.bold: true font.pointSize: width ? width / 6 : 1 } } } property Component daysRenderer: Component { Item { width: cellWidth height: cellHeight Rectangle { id:recms width: parent.width - 4 height: parent.height - 4 anchors.centerIn: parent radius: 4 color: model ? model.inmonth ? (model.current ? "blue" : "lightsteelblue") : "#AAAAAA" : "black" } Text { id:txt_solar_day anchors.fill: parent anchors.leftMargin: 10 verticalAlignment: Text.AlignVCenter horizontalAlignment: Text.AlignLeft text: model ? model.day : "" color: model ? model.inmonth ? (model.current ? "red" : model.inholiday ? theme_manager.theme.markdate.holidays : "black") : "grey" : "red" font.pointSize: parent.width ? parent.width / 6 : 1 font.bold: true } Text { anchors.fill: parent anchors.leftMargin: txt_solar_day.anchors.leftMargin+40 anchors.topMargin: 20 verticalAlignment: Text.AlignVCenter horizontalAlignment: Text.AlignBottom text: model ? model.lunar_day : "" color: model ? model.inmonth ? (model.current ? "red" : "#700070") : "grey" : "red" font.pointSize: parent.width ? parent.width / 8 : 1 } MouseArea { anchors.fill: parent property real mX property real mY property bool hold: false onClicked: { LC.reset(model.day,m_month,m_year) screen.calculateLunar(model.day,m_month,m_year) screen.state="mainscreen" screen.refresh() maindatemodel.reset() txtDATEpv.currentIndex = model.day-1; } onPositionChanged: { mX = mouseX; mY = mouseY; hold=true; } onPressed: { recms.color="#F0F0F0" } onReleased: { if (hold){ if (mouseY+mY<0){ if (Math.abs(mouseY) >= 30){ m_month+=1; if (m_month >=13){ m_month=1; m_year++; } } } else { if (mouseY >= 50){ m_month-=1; if(m_month<=0){ m_month=12; m_year--; } } } reset(); hold=false; } } } } } Rectangle{ id: fullmonthREC anchors.fill: parent; anchors.bottomMargin: 0 opacity:0.9 ListModel { id: monthModel } Grid { id: grid anchors.bottomMargin: -52 anchors.topMargin: 78 anchors.horizontalCenter: parent.horizontalCenter anchors.bottom: parent.bottom anchors.top: parent.top columns: 7 rows: 7 Repeater { model: ["CN", "Hai", "Ba", "Tư", "Năm", "Sáu", "Bảy"] delegate: Item { id: headerDelegate width: fullmonthREC.width / grid.columns height: (fullmonthREC.height-92) / grid.rows property int theIndex: index property variant theModel: model Loader { property alias model: headerDelegate.theModel property alias index: headerDelegate.theIndex property alias cellWidth: headerDelegate.width property alias cellHeight: headerDelegate.height anchors.fill: parent sourceComponent: headerRenderer } } } Repeater { model: monthModel delegate: Item { id: daysDelegate property int theIndex: index property variant theModel: model width: fullmonthREC.width / grid.columns height: (fullmonthREC.height-92) / grid.rows Loader { property alias model: daysDelegate.theModel property alias index: daysDelegate.theIndex property alias cellWidth: daysDelegate.width property alias cellHeight: daysDelegate.height anchors.fill: parent sourceComponent: daysRenderer } } } } Text { id: txt_caption y: 40 width:parent.width text: "Tháng "+m_month+", "+m_year horizontalAlignment: Text.AlignHCenter font.pixelSize: 24 font.bold: true } } ToolBarSingle { id: toolBar; height: 50; y: screen.height-78 width: parent.width; button1Label: "Quay Về" onButton1Clicked: { screen.state="mainscreen" } } function reset() { monthModel.clear() var firstdayofthemonthyear = AmLich.getLunarDate(1,m_month,m_year).jd; var startfrom = (firstdayofthemonthyear+1)%7; var daysofthemonthyear = LC.calDays(m_month,m_year); var j=1; var totalslot = 42; var nextmonth = get_nextmonth(totalslot - (startfrom+daysofthemonthyear)) var prevmonth = get_prevmonth(startfrom) var dayclick, monthclick, yearclick; var datas1,datas,lunarclmonth,inmonth; for (var i=0;i<42;i++){ if (i >= startfrom && j<= daysofthemonthyear){ dayclick = j; monthclick = m_month; yearclick = m_year; inmonth = true; j++; }else{ if (idaysofthemonthyear-startfrom;i--){ var lunarcl = AmLich.getLunarDate(i,cMonth,cYear) pmonth.push({duong:i, am:lunarcl.day, month:cMonth, year:cYear}) } return pmonth.reverse() } function get_nextmonth(startfrom){ var cMonth=m_month; var cYear=m_year; var pmonth = []; if (cMonth==12){ cMonth = 1; cYear++; }else cMonth++; for (var i=1;i<=startfrom;i++){ var lunarcl = AmLich.getLunarDate(i,cMonth,cYear) pmonth.push({duong:i, am:lunarcl.day, month:cMonth, year:cYear}); } return pmonth.reverse(); } }