forked from openkylin/ukui-system-appwidget
Fix:优化更新时间日期显示代码的逻辑
This commit is contained in:
parent
cb6f507159
commit
29f675451e
|
@ -23,6 +23,9 @@ AppWidget {
|
|||
property string themename;
|
||||
property bool qmleffect: false
|
||||
property bool qmlenable: true
|
||||
property var timeStr: ""
|
||||
property var dateInfo: ""
|
||||
property var timeInfo: ""
|
||||
|
||||
Timer {
|
||||
id: gettime;
|
||||
|
@ -31,48 +34,12 @@ AppWidget {
|
|||
repeat: true;
|
||||
triggeredOnStart: true
|
||||
onTriggered: {
|
||||
appwidget.hour = Qt.formatTime(new Date(),"hh");
|
||||
appwidget.minute = Qt.formatTime(new Date(),"mm");
|
||||
if(appwidget.timeformat === "12") {
|
||||
appwidget.hournumber = Number(appwidget.hour);
|
||||
ampm.text = Qt.formatTime(new Date(), "AP")
|
||||
if(appwidget.hournumber > 12) {
|
||||
appwidget.hournumber -= 12;
|
||||
}
|
||||
|
||||
if(appwidget.hournumber < 10) {
|
||||
time1rec.width = 244*appwidget.scalefactor
|
||||
time1.width = 244*appwidget.scalefactor
|
||||
// console.log("=12制 宽度=",time1rec.width);
|
||||
}else {
|
||||
time1rec.width = 294*appwidget.scalefactor
|
||||
time1.width = 294*appwidget.scalefactor
|
||||
// console.log("=12制 宽度=",time1rec.width);
|
||||
}
|
||||
|
||||
appwidget.hour = appwidget.hournumber.toString();
|
||||
time1.text = appwidget.hour + ":" + appwidget.minute
|
||||
// console.log("=12制=",time1.text);
|
||||
}
|
||||
else {
|
||||
time2.text = appwidget.hour + ":" + appwidget.minute
|
||||
// console.log("=24制=",time2.text);
|
||||
}
|
||||
week1.text = Qt.formatDate(new Date(),"ddd")
|
||||
week2.text = Qt.formatDate(new Date(),"ddd")
|
||||
|
||||
if(dateformat == "cn") {
|
||||
date1.text = Qt.formatDate(new Date(),"MM/dd");
|
||||
date2.text = Qt.formatDate(new Date(),"MM/dd");
|
||||
}
|
||||
if(dateformat == "en") {
|
||||
date1.text = Qt.formatDate(new Date(),"MM-dd");
|
||||
date2.text = Qt.formatDate(new Date(),"MM-dd");
|
||||
}
|
||||
updateTimeInfo();
|
||||
updateWeakInfo();
|
||||
updateDateInfo();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Rectangle {
|
||||
id :twelverec
|
||||
color: "transparent"
|
||||
|
@ -84,7 +51,6 @@ AppWidget {
|
|||
Rectangle {
|
||||
id :time1rec
|
||||
color: "transparent"
|
||||
// border.color: "green"
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
width: 244*appwidget.scalefactor
|
||||
height: 112*appwidget.scalefactor
|
||||
|
@ -339,6 +305,43 @@ AppWidget {
|
|||
appwidget.qmlenable = false;
|
||||
}
|
||||
}
|
||||
function updateTimeInfo()
|
||||
{
|
||||
appwidget.timeInfo = (appwidget.timeformat === "12") ? "hh mm AP" : "hh mm";
|
||||
appwidget.timeStr = Qt.formatTime(new Date(), appwidget.timeInfo).trim().split(/\s+/);
|
||||
appwidget.hour = appwidget.timeStr[0];
|
||||
appwidget.minute = appwidget.timeStr[1];
|
||||
if (appwidget.timeInfo === "hh mm AP") {
|
||||
appwidget.hournumber = Number(appwidget.hour);
|
||||
if(appwidget.hournumber < 10) {
|
||||
time1rec.width = 244*appwidget.scalefactor
|
||||
}
|
||||
else {
|
||||
time1rec.width = 294*appwidget.scalefactor;
|
||||
}
|
||||
appwidget.hour = appwidget.hournumber.toString();
|
||||
ampm.text = Qt.formatTime(new Date(), "AP");
|
||||
}
|
||||
|
||||
time1.text = appwidget.hour + ":" + appwidget.minute;
|
||||
time2.text = appwidget.hour + ":" + appwidget.minute
|
||||
}
|
||||
function updateWeakInfo()
|
||||
{
|
||||
week1.text = Qt.formatDate(new Date(),"ddd")
|
||||
week2.text = Qt.formatDate(new Date(),"ddd")
|
||||
}
|
||||
function updateDateInfo()
|
||||
{
|
||||
if(dateformat == "cn") {
|
||||
appwidget.dateInfo = "MM/dd";
|
||||
}
|
||||
if(dateformat == "en") {
|
||||
appwidget.dateInfo = "MM-dd";
|
||||
}
|
||||
date1.text = Qt.formatDate(new Date(),appwidget.dateInfo);
|
||||
date2.text = Qt.formatDate(new Date(),appwidget.dateInfo);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue