improved code by removing redundancies and done some optimizations
This commit is contained in:
@@ -19,25 +19,21 @@ PanelWindow {
|
||||
property string secondsString: ""
|
||||
|
||||
function startTyping() {
|
||||
typedChars = 0;
|
||||
secondsText.opacity = 0;
|
||||
typingTimer.start();
|
||||
typedChars = 0
|
||||
secondsText.opacity = 0
|
||||
typingTimer.start()
|
||||
}
|
||||
|
||||
function updateDate() {
|
||||
let d = new Date();
|
||||
fullDateString = d.toLocaleDateString(Qt.locale(), "dddd, d MMMM yyyy");
|
||||
startTyping();
|
||||
}
|
||||
|
||||
function updateSeconds() {
|
||||
let d = new Date();
|
||||
secondsString = Qt.formatTime(d, "hh:mm:ss");
|
||||
function updateDate(d) {
|
||||
let now = d || new Date()
|
||||
fullDateString = now.toLocaleDateString(Qt.locale(), "dddd, d MMMM yyyy")
|
||||
startTyping()
|
||||
}
|
||||
|
||||
Component.onCompleted: {
|
||||
updateSeconds();
|
||||
updateDate();
|
||||
let d = new Date()
|
||||
secondsString = Qt.formatTime(d, "hh:mm:ss")
|
||||
updateDate(d)
|
||||
}
|
||||
|
||||
Column {
|
||||
@@ -53,7 +49,7 @@ PanelWindow {
|
||||
font.weight: Font.ExtraLight
|
||||
font.letterSpacing: 4
|
||||
opacity: 0.55
|
||||
style: Text.DropShadow
|
||||
style: Text.Raised
|
||||
text: fullDateString.substring(0, typedChars)
|
||||
}
|
||||
|
||||
@@ -66,7 +62,7 @@ PanelWindow {
|
||||
font.weight: Font.ExtraLight
|
||||
font.letterSpacing: 6
|
||||
opacity: 0
|
||||
style: Text.DropShadow
|
||||
style: Text.Raised
|
||||
text: secondsString
|
||||
|
||||
Behavior on opacity {
|
||||
@@ -84,10 +80,10 @@ PanelWindow {
|
||||
repeat: true
|
||||
onTriggered: {
|
||||
if (typedChars < fullDateString.length) {
|
||||
typedChars++;
|
||||
typedChars++
|
||||
} else {
|
||||
stop();
|
||||
secondsText.opacity = 0.55;
|
||||
stop()
|
||||
secondsText.opacity = 0.55
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -97,10 +93,10 @@ PanelWindow {
|
||||
running: true
|
||||
repeat: true
|
||||
onTriggered: {
|
||||
updateSeconds();
|
||||
let d = new Date();
|
||||
let d = new Date()
|
||||
secondsString = Qt.formatTime(d, "hh:mm:ss")
|
||||
if (d.getSeconds() === 0 && d.getMinutes() === 0 && d.getHours() === 0)
|
||||
updateDate();
|
||||
updateDate(d)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user