Improve Calendar

This commit is contained in:
Vyn 2024-04-20 09:02:25 +02:00
parent eb284afecd
commit fb0f21f119
4 changed files with 97 additions and 58 deletions

View file

@ -1 +1 @@
cmake -S . -B ./build -G Ninja && cd build && ninja && ./mirai cmake -DCMAKE_BUILD_TYPE=Debug -S . -B ./build -G Ninja && cd build && ninja && ./mirai

View file

@ -17,6 +17,8 @@ Window {
visible: true visible: true
title: qsTr("Hello World") title: qsTr("Hello World")
property string selectedView: "list" property string selectedView: "list"
Backend { Backend {
@ -28,6 +30,10 @@ Window {
property QtObject selected: MiraiColorPalette property QtObject selected: MiraiColorPalette
} }
function capitalize(str) {
return str.charAt(0).toUpperCase() + str.slice(1)
}
function openSettings() { function openSettings() {
filesForm.reset() filesForm.reset()
filesFormPopup.open() filesFormPopup.open()

View file

@ -11,7 +11,7 @@ import Mirai
ColumnLayout { ColumnLayout {
id: control id: control
spacing: 32
QtObject { QtObject {
id: internal id: internal
property date weekStartDate: { property date weekStartDate: {
@ -22,14 +22,25 @@ ColumnLayout {
} }
RowLayout { RowLayout {
spacing: 12
Layout.fillWidth: true
Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
AppButton { AppButton {
text: "<-" text: "<"
onClicked: { onClicked: {
internal.weekStartDate.setDate(internal.weekStartDate.getDate() - 7) internal.weekStartDate.setDate(internal.weekStartDate.getDate() - 7)
} }
} }
AppText {
text: capitalize(internal.weekStartDate.toLocaleDateString(Qt.locale(), "MMMM"))
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter
font.pointSize: 24
}
AppButton { AppButton {
text: "->" text: ">"
onClicked: { onClicked: {
internal.weekStartDate.setDate(internal.weekStartDate.getDate() + 7) internal.weekStartDate.setDate(internal.weekStartDate.getDate() + 7)
} }
@ -65,16 +76,28 @@ ColumnLayout {
Repeater { Repeater {
model: 7 model: 7
ColumnLayout { Rectangle {
spacing: 0
property date day: new Date(new Date(internal.weekStartDate).setDate(internal.weekStartDate.getDate() + index))
Layout.fillWidth: true Layout.fillWidth: true
Layout.fillHeight: true Layout.fillHeight: true
property date day: new Date(new Date(internal.weekStartDate).setDate(internal.weekStartDate.getDate() + index))
color: "transparent"
Rectangle {
color: colorPalette.selected.calendarLines
height: parent.height
width: 1
anchors.left: parent.left
}
ColumnLayout {
anchors.fill: parent
spacing: 0
AppText { AppText {
Layout.fillWidth: true Layout.fillWidth: true
text: parent.day.toLocaleDateString(Qt.locale(), "yyyy-MM-dd") text: capitalize(day.toLocaleDateString(Qt.locale(), "dddd dd"))
verticalAlignment: Text.AlignVCenter verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter horizontalAlignment: Text.AlignHCenter
} }
@ -126,6 +149,15 @@ ColumnLayout {
} }
} }
} }
Rectangle {
color: day.getFullYear() === new Date().getFullYear() &&
day.getMonth() === new Date().getMonth() &&
day.getDate() === new Date().getDate() ? colorPalette.selected.calendarCurrentTime : "transparent"
height: 2
width: parent.width
y: daysSurface.hourHeight * (new Date().getHours() + (new Date().getMinutes() / 60))
}
}
} }
} }
} }

View file

@ -22,5 +22,6 @@ QtObject {
property string filterSelected: CatppuccinFrappe.surface1 property string filterSelected: CatppuccinFrappe.surface1
property string modalBorder: CatppuccinFrappe.lavender property string modalBorder: CatppuccinFrappe.lavender
property string calendarLines: CatppuccinFrappe.surface0 property string calendarLines: CatppuccinFrappe.surface0
property string calendarCurrentTime: CatppuccinFrappe.red
property string calendarEvent: CatppuccinFrappe.overlay0 property string calendarEvent: CatppuccinFrappe.overlay0
} }