From 29f675451e872c46e45eb78bdf14a05ad3be0727 Mon Sep 17 00:00:00 2001 From: yan wang Date: Wed, 15 Feb 2023 18:11:19 +0800 Subject: [PATCH] =?UTF-8?q?Fix:=E4=BC=98=E5=8C=96=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E6=97=B6=E9=97=B4=E6=97=A5=E6=9C=9F=E6=98=BE=E7=A4=BA=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E7=9A=84=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- time/ukui-appwidget-time/data/time.qml | 83 +++++++++++++------------- 1 file changed, 43 insertions(+), 40 deletions(-) diff --git a/time/ukui-appwidget-time/data/time.qml b/time/ukui-appwidget-time/data/time.qml index 2fbc9da..1b840e0 100644 --- a/time/ukui-appwidget-time/data/time.qml +++ b/time/ukui-appwidget-time/data/time.qml @@ -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); + } }