253 lines
7.8 KiB
QML
253 lines
7.8 KiB
QML
pragma ComponentBehavior: Bound
|
|
|
|
import QtQuick
|
|
import QtQuick.Controls
|
|
import QtQuick.Layouts
|
|
import qs.Components
|
|
import qs.Helpers
|
|
import qs.Config
|
|
import qs.Modules
|
|
|
|
CustomMouseArea {
|
|
id: root
|
|
|
|
required property var state
|
|
|
|
readonly property int currMonth: state.currentDate.getMonth()
|
|
readonly property int currYear: state.currentDate.getFullYear()
|
|
|
|
anchors.left: parent.left
|
|
anchors.right: parent.right
|
|
implicitHeight: inner.implicitHeight + inner.anchors.margins * 2
|
|
|
|
acceptedButtons: Qt.MiddleButton
|
|
onClicked: root.state.currentDate = new Date()
|
|
|
|
function onWheel(event: WheelEvent): void {
|
|
if (event.angleDelta.y > 0)
|
|
root.state.currentDate = new Date(root.currYear, root.currMonth - 1, 1);
|
|
else if (event.angleDelta.y < 0)
|
|
root.state.currentDate = new Date(root.currYear, root.currMonth + 1, 1);
|
|
}
|
|
|
|
ColumnLayout {
|
|
id: inner
|
|
|
|
anchors.fill: parent
|
|
anchors.margins: Appearance.padding.large
|
|
spacing: Appearance.spacing.small
|
|
|
|
RowLayout {
|
|
id: monthNavigationRow
|
|
|
|
Layout.fillWidth: true
|
|
spacing: Appearance.spacing.small
|
|
|
|
Item {
|
|
implicitWidth: implicitHeight
|
|
implicitHeight: prevMonthText.implicitHeight + Appearance.padding.small * 2
|
|
|
|
StateLayer {
|
|
id: prevMonthStateLayer
|
|
|
|
radius: Appearance.rounding.full
|
|
|
|
function onClicked(): void {
|
|
root.state.currentDate = new Date(root.currYear, root.currMonth - 1, 1);
|
|
}
|
|
}
|
|
|
|
MaterialIcon {
|
|
id: prevMonthText
|
|
|
|
anchors.centerIn: parent
|
|
text: "chevron_left"
|
|
color: DynamicColors.palette.m3tertiary
|
|
font.pointSize: Appearance.font.size.normal
|
|
font.weight: 700
|
|
}
|
|
}
|
|
|
|
Item {
|
|
Layout.fillWidth: true
|
|
|
|
implicitWidth: monthYearDisplay.implicitWidth + Appearance.padding.small * 2
|
|
implicitHeight: monthYearDisplay.implicitHeight + Appearance.padding.small * 2
|
|
|
|
StateLayer {
|
|
anchors.fill: monthYearDisplay
|
|
anchors.margins: -Appearance.padding.small
|
|
anchors.leftMargin: -Appearance.padding.normal
|
|
anchors.rightMargin: -Appearance.padding.normal
|
|
|
|
radius: Appearance.rounding.full
|
|
disabled: {
|
|
const now = new Date();
|
|
return root.currMonth === now.getMonth() && root.currYear === now.getFullYear();
|
|
}
|
|
|
|
function onClicked(): void {
|
|
root.state.currentDate = new Date();
|
|
}
|
|
}
|
|
|
|
CustomText {
|
|
id: monthYearDisplay
|
|
|
|
anchors.centerIn: parent
|
|
text: grid.title
|
|
color: DynamicColors.palette.m3primary
|
|
font.pointSize: Appearance.font.size.normal
|
|
font.weight: 500
|
|
font.capitalization: Font.Capitalize
|
|
}
|
|
}
|
|
|
|
Item {
|
|
implicitWidth: implicitHeight
|
|
implicitHeight: nextMonthText.implicitHeight + Appearance.padding.small * 2
|
|
|
|
StateLayer {
|
|
id: nextMonthStateLayer
|
|
|
|
radius: Appearance.rounding.full
|
|
|
|
function onClicked(): void {
|
|
root.state.currentDate = new Date(root.currYear, root.currMonth + 1, 1);
|
|
}
|
|
}
|
|
|
|
MaterialIcon {
|
|
id: nextMonthText
|
|
|
|
anchors.centerIn: parent
|
|
text: "chevron_right"
|
|
color: DynamicColors.palette.m3tertiary
|
|
font.pointSize: Appearance.font.size.normal
|
|
font.weight: 700
|
|
}
|
|
}
|
|
}
|
|
|
|
DayOfWeekRow {
|
|
id: daysRow
|
|
|
|
Layout.fillWidth: true
|
|
locale: grid.locale
|
|
|
|
delegate: CustomText {
|
|
required property var model
|
|
|
|
horizontalAlignment: Text.AlignHCenter
|
|
text: model.shortName
|
|
font.weight: 500
|
|
color: (model.day === 0) ? DynamicColors.palette.m3secondary : DynamicColors.palette.m3onSurfaceVariant
|
|
}
|
|
}
|
|
|
|
Item {
|
|
Layout.fillWidth: true
|
|
implicitHeight: grid.implicitHeight
|
|
|
|
MonthGrid {
|
|
id: grid
|
|
|
|
month: root.currMonth
|
|
year: root.currYear
|
|
|
|
anchors.fill: parent
|
|
|
|
spacing: 3
|
|
locale: Qt.locale("en_SE")
|
|
|
|
delegate: Item {
|
|
id: dayItem
|
|
|
|
required property var model
|
|
|
|
implicitWidth: implicitHeight
|
|
implicitHeight: text.implicitHeight + Appearance.padding.small * 2
|
|
|
|
CustomText {
|
|
id: text
|
|
|
|
anchors.centerIn: parent
|
|
|
|
horizontalAlignment: Text.AlignHCenter
|
|
text: grid.locale.toString(dayItem.model.day)
|
|
color: {
|
|
const dayOfWeek = dayItem.model.date.getUTCDay();
|
|
if (dayOfWeek === 6)
|
|
return DynamicColors.palette.m3secondary;
|
|
|
|
return DynamicColors.palette.m3onSurfaceVariant;
|
|
}
|
|
opacity: dayItem.model.today || dayItem.model.month === grid.month ? 1 : 0.4
|
|
font.pointSize: Appearance.font.size.normal
|
|
font.weight: 500
|
|
}
|
|
}
|
|
}
|
|
|
|
CustomRect {
|
|
id: todayIndicator
|
|
|
|
readonly property Item todayItem: grid.contentItem.children.find(c => c.model.today) ?? null
|
|
property Item today
|
|
|
|
onTodayItemChanged: {
|
|
if (todayItem)
|
|
today = todayItem;
|
|
}
|
|
|
|
x: today ? today.x + (today.width - implicitWidth) / 2 : 0
|
|
y: today?.y ?? 0
|
|
|
|
implicitWidth: today?.implicitWidth ?? 0
|
|
implicitHeight: today?.implicitHeight ?? 0
|
|
|
|
clip: true
|
|
radius: Appearance.rounding.full
|
|
color: DynamicColors.palette.m3primary
|
|
|
|
opacity: todayItem ? 1 : 0
|
|
scale: todayItem ? 1 : 0.7
|
|
|
|
Coloriser {
|
|
x: -todayIndicator.x
|
|
y: -todayIndicator.y
|
|
|
|
implicitWidth: grid.width
|
|
implicitHeight: grid.height
|
|
|
|
source: grid
|
|
sourceColor: DynamicColors.palette.m3onSurface
|
|
colorizationColor: DynamicColors.palette.m3onPrimary
|
|
}
|
|
|
|
Behavior on opacity {
|
|
Anim {}
|
|
}
|
|
|
|
Behavior on scale {
|
|
Anim {}
|
|
}
|
|
|
|
Behavior on x {
|
|
Anim {
|
|
duration: Appearance.anim.durations.expressiveDefaultSpatial
|
|
easing.bezierCurve: Appearance.anim.curves.expressiveDefaultSpatial
|
|
}
|
|
}
|
|
|
|
Behavior on y {
|
|
Anim {
|
|
duration: Appearance.anim.durations.expressiveDefaultSpatial
|
|
easing.bezierCurve: Appearance.anim.curves.expressiveDefaultSpatial
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|