improved code by removing redundancies and done some optimizations
This commit is contained in:
@@ -169,6 +169,55 @@ Rectangle {
|
||||
|
||||
MouseArea { anchors.fill: parent; propagateComposedEvents: false }
|
||||
|
||||
component MonthNavButton: Rectangle {
|
||||
id: navBtn
|
||||
required property int direction
|
||||
|
||||
width: 26; height: 26; radius: 6
|
||||
|
||||
color: btnMouse.containsMouse
|
||||
? (btnMouse.pressed ? root.t.calArrowBgPress : root.t.calArrowBgHover)
|
||||
: root.t.calArrowBg
|
||||
scale: btnMouse.pressed ? 0.88 : 1.0
|
||||
|
||||
Behavior on color { ColorAnimation { duration: 120 } }
|
||||
Behavior on scale { NumberAnimation { duration: 100; easing.type: Easing.OutCubic } }
|
||||
|
||||
MouseArea {
|
||||
id: btnMouse
|
||||
anchors.fill: parent
|
||||
hoverEnabled: true
|
||||
cursorShape: Qt.PointingHandCursor
|
||||
|
||||
function navigate() {
|
||||
if (slideAnim.running) return
|
||||
cal.slideDir = navBtn.direction
|
||||
let m = cal.displayMonth + navBtn.direction
|
||||
let y = cal.displayYear
|
||||
if (m > 11) { m = 0; y += 1 }
|
||||
if (m < 0) { m = 11; y -= 1 }
|
||||
cal.pendingMonth = m
|
||||
cal.pendingYear = y
|
||||
slideAnim.restart()
|
||||
}
|
||||
|
||||
onPressed: { navigate(); holdDelay.restart() }
|
||||
onReleased: { holdDelay.stop(); holdRepeat.stop() }
|
||||
onCanceled: { holdDelay.stop(); holdRepeat.stop() }
|
||||
|
||||
Timer { id: holdDelay; interval: 400; repeat: false; onTriggered: holdRepeat.restart() }
|
||||
Timer { id: holdRepeat; interval: 200; repeat: true; onTriggered: btnMouse.navigate() }
|
||||
}
|
||||
|
||||
Text {
|
||||
anchors.centerIn: parent
|
||||
text: navBtn.direction < 0 ? "‹" : "›"
|
||||
color: btnMouse.containsMouse ? root.t.calArrowIconHover : root.t.calArrowIcon
|
||||
font.pixelSize: 18; font.bold: true
|
||||
Behavior on color { ColorAnimation { duration: 120 } }
|
||||
}
|
||||
}
|
||||
|
||||
ColumnLayout {
|
||||
id: cardCol
|
||||
anchors { left: parent.left; right: parent.right; top: parent.top }
|
||||
@@ -188,6 +237,7 @@ Rectangle {
|
||||
Layout.fillWidth: true
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
}
|
||||
|
||||
Text {
|
||||
text: timeManager.now.toLocaleDateString(Qt.locale(), "d MMMM yyyy")
|
||||
color: root.t.clockPopupHeader
|
||||
@@ -203,58 +253,7 @@ Rectangle {
|
||||
RowLayout {
|
||||
Layout.fillWidth: true
|
||||
|
||||
Rectangle {
|
||||
id: prevMonthBtn
|
||||
width: 26; height: 26; radius: 6
|
||||
color: prevBtnMouse.containsMouse
|
||||
? (prevBtnMouse.pressed ? root.t.calArrowBgPress : root.t.calArrowBgHover)
|
||||
: root.t.calArrowBg
|
||||
scale: prevBtnMouse.pressed ? 0.88 : 1.0
|
||||
|
||||
Behavior on color { ColorAnimation { duration: 120 } }
|
||||
Behavior on scale { NumberAnimation { duration: 100; easing.type: Easing.OutCubic } }
|
||||
|
||||
MouseArea {
|
||||
id: prevBtnMouse
|
||||
anchors.fill: parent
|
||||
hoverEnabled: true
|
||||
cursorShape: Qt.PointingHandCursor
|
||||
|
||||
function goToPrev() {
|
||||
if (slideAnim.running) return
|
||||
cal.slideDir = -1
|
||||
let m = cal.displayMonth - 1
|
||||
let y = cal.displayYear
|
||||
if (m < 0) { m = 11; y -= 1 }
|
||||
cal.pendingMonth = m
|
||||
cal.pendingYear = y
|
||||
slideAnim.restart()
|
||||
}
|
||||
|
||||
onPressed: { goToPrev(); prevHoldDelay.restart() }
|
||||
onReleased: { prevHoldDelay.stop(); prevHoldRepeat.stop() }
|
||||
onCanceled: { prevHoldDelay.stop(); prevHoldRepeat.stop() }
|
||||
|
||||
Timer {
|
||||
id: prevHoldDelay
|
||||
interval: 400; repeat: false
|
||||
onTriggered: prevHoldRepeat.restart()
|
||||
}
|
||||
Timer {
|
||||
id: prevHoldRepeat
|
||||
interval: 200; repeat: true
|
||||
onTriggered: prevBtnMouse.goToPrev()
|
||||
}
|
||||
}
|
||||
|
||||
Text {
|
||||
anchors.centerIn: parent
|
||||
text: "‹"
|
||||
color: prevBtnMouse.containsMouse ? root.t.calArrowIconHover : root.t.calArrowIcon
|
||||
font.pixelSize: 18; font.bold: true
|
||||
Behavior on color { ColorAnimation { duration: 120 } }
|
||||
}
|
||||
}
|
||||
MonthNavButton { direction: -1 }
|
||||
|
||||
Text {
|
||||
text: new Date(cal.displayYear, cal.displayMonth, 1).toLocaleDateString(Qt.locale(), "MMMM yyyy")
|
||||
@@ -263,58 +262,7 @@ Rectangle {
|
||||
Layout.fillWidth: true; horizontalAlignment: Text.AlignHCenter
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
id: nextMonthBtn
|
||||
width: 26; height: 26; radius: 6
|
||||
color: nextBtnMouse.containsMouse
|
||||
? (nextBtnMouse.pressed ? root.t.calArrowBgPress : root.t.calArrowBgHover)
|
||||
: root.t.calArrowBg
|
||||
scale: nextBtnMouse.pressed ? 0.88 : 1.0
|
||||
|
||||
Behavior on color { ColorAnimation { duration: 120 } }
|
||||
Behavior on scale { NumberAnimation { duration: 100; easing.type: Easing.OutCubic } }
|
||||
|
||||
MouseArea {
|
||||
id: nextBtnMouse
|
||||
anchors.fill: parent
|
||||
hoverEnabled: true
|
||||
cursorShape: Qt.PointingHandCursor
|
||||
|
||||
function goToNext() {
|
||||
if (slideAnim.running) return
|
||||
cal.slideDir = 1
|
||||
let m = cal.displayMonth + 1
|
||||
let y = cal.displayYear
|
||||
if (m > 11) { m = 0; y += 1 }
|
||||
cal.pendingMonth = m
|
||||
cal.pendingYear = y
|
||||
slideAnim.restart()
|
||||
}
|
||||
|
||||
onPressed: { goToNext(); nextHoldDelay.restart() }
|
||||
onReleased: { nextHoldDelay.stop(); nextHoldRepeat.stop() }
|
||||
onCanceled: { nextHoldDelay.stop(); nextHoldRepeat.stop() }
|
||||
|
||||
Timer {
|
||||
id: nextHoldDelay
|
||||
interval: 400; repeat: false
|
||||
onTriggered: nextHoldRepeat.restart()
|
||||
}
|
||||
Timer {
|
||||
id: nextHoldRepeat
|
||||
interval: 200; repeat: true
|
||||
onTriggered: nextBtnMouse.goToNext()
|
||||
}
|
||||
}
|
||||
|
||||
Text {
|
||||
anchors.centerIn: parent
|
||||
text: "›"
|
||||
color: nextBtnMouse.containsMouse ? root.t.calArrowIconHover : root.t.calArrowIcon
|
||||
font.pixelSize: 18; font.bold: true
|
||||
Behavior on color { ColorAnimation { duration: 120 } }
|
||||
}
|
||||
}
|
||||
MonthNavButton { direction: 1 }
|
||||
}
|
||||
|
||||
Item {
|
||||
@@ -363,57 +311,57 @@ Rectangle {
|
||||
anchors.fill: parent
|
||||
clip: true
|
||||
|
||||
ColumnLayout {
|
||||
id: gridCol
|
||||
width: parent.width
|
||||
spacing: 2
|
||||
ColumnLayout {
|
||||
id: gridCol
|
||||
width: parent.width
|
||||
spacing: 2
|
||||
|
||||
Row {
|
||||
spacing: 0
|
||||
Repeater {
|
||||
model: ["Mo","Tu","We","Th","Fr","Sa","Su"]
|
||||
Text {
|
||||
width: (card.width - 32) / 7
|
||||
text: modelData; color: root.t.clockPopupDim
|
||||
font.pixelSize: 11; horizontalAlignment: Text.AlignHCenter
|
||||
Row {
|
||||
spacing: 0
|
||||
Repeater {
|
||||
model: ["Mo","Tu","We","Th","Fr","Sa","Su"]
|
||||
Text {
|
||||
width: (card.width - 32) / 7
|
||||
text: modelData; color: root.t.clockPopupDim
|
||||
font.pixelSize: 11; horizontalAlignment: Text.AlignHCenter
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Repeater {
|
||||
model: 6
|
||||
Row {
|
||||
id: weekRow
|
||||
property int weekIndex: index
|
||||
Repeater {
|
||||
model: 7
|
||||
delegate: Item {
|
||||
width: (card.width - 32) / 7; height: 26
|
||||
readonly property int dayNum: (weekRow.weekIndex * 7 + index) - ((new Date(cal.displayYear, cal.displayMonth, 1).getDay() + 6) % 7) + 1
|
||||
readonly property bool inMonth: dayNum >= 1 && dayNum <= new Date(cal.displayYear, cal.displayMonth + 1, 0).getDate()
|
||||
readonly property bool isToday: inMonth && dayNum === timeManager.now.getDate() && cal.displayYear === timeManager.now.getFullYear() && cal.displayMonth === timeManager.now.getMonth()
|
||||
Repeater {
|
||||
model: 6
|
||||
Row {
|
||||
id: weekRow
|
||||
property int weekIndex: index
|
||||
Repeater {
|
||||
model: 7
|
||||
delegate: Item {
|
||||
width: (card.width - 32) / 7; height: 26
|
||||
readonly property int dayNum: (weekRow.weekIndex * 7 + index) - ((new Date(cal.displayYear, cal.displayMonth, 1).getDay() + 6) % 7) + 1
|
||||
readonly property bool inMonth: dayNum >= 1 && dayNum <= new Date(cal.displayYear, cal.displayMonth + 1, 0).getDate()
|
||||
readonly property bool isToday: inMonth && dayNum === timeManager.now.getDate() && cal.displayYear === timeManager.now.getFullYear() && cal.displayMonth === timeManager.now.getMonth()
|
||||
|
||||
Rectangle {
|
||||
anchors.centerIn: parent; width: 22; height: 22; radius: 11
|
||||
color: isToday ? root.t.accent : "transparent"
|
||||
visible: inMonth
|
||||
}
|
||||
Rectangle {
|
||||
anchors.centerIn: parent; width: 22; height: 22; radius: 11
|
||||
color: isToday ? root.t.accent : "transparent"
|
||||
visible: inMonth
|
||||
}
|
||||
|
||||
Text {
|
||||
anchors.fill: parent
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
text: inMonth ? dayNum : ""
|
||||
color: isToday ? root.t.todayText : (index >= 5 ? root.t.clockPopupDim : root.t.clockPopupText)
|
||||
font.pixelSize: 12; font.bold: isToday
|
||||
Text {
|
||||
anchors.fill: parent
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
text: inMonth ? dayNum : ""
|
||||
color: isToday ? root.t.todayText : (index >= 5 ? root.t.clockPopupDim : root.t.clockPopupText)
|
||||
font.pixelSize: 12; font.bold: isToday
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Rectangle { Layout.fillWidth: true; height: 1; color: root.t.calSeparator }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user