2025-06-27 01:02:10 +02:00
|
|
|
/*
|
|
|
|
|
* This file is part of the Flowee project
|
|
|
|
|
* Copyright (C) 2025 Tom Zander <tom@flowee.org>
|
|
|
|
|
*
|
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
import QtQuick
|
|
|
|
|
import QtQuick.Controls.Basic as QQC2
|
|
|
|
|
import "../Flowee" as Flowee
|
|
|
|
|
|
|
|
|
|
Item {
|
|
|
|
|
id: root
|
|
|
|
|
// please only set it ever to be the first of the month!
|
|
|
|
|
required property date month
|
2025-08-03 20:35:31 +02:00
|
|
|
// the date before which all items have lower visibility
|
|
|
|
|
property date oldCutoff: new Date(1978, 0, 1)
|
2025-07-03 22:51:45 +02:00
|
|
|
// when the user clicks on a date.
|
|
|
|
|
property int selected: 0
|
2025-06-27 01:02:10 +02:00
|
|
|
|
|
|
|
|
// an array of ints.
|
|
|
|
|
property var highlights: []
|
2025-07-03 22:51:45 +02:00
|
|
|
property string monthFormat: "MMM yy"
|
2025-06-27 01:02:10 +02:00
|
|
|
|
2025-07-03 22:51:45 +02:00
|
|
|
width: implicitWidth
|
|
|
|
|
height: implicitHeight
|
2025-07-07 16:17:28 +02:00
|
|
|
implicitWidth: 88
|
2025-07-03 22:51:45 +02:00
|
|
|
implicitHeight: days.y + 6 * 13
|
2026-03-14 21:14:42 +01:00
|
|
|
onVisibleChanged: if (visible) selected = 0
|
2025-06-27 21:03:06 +02:00
|
|
|
QQC2.Label {
|
2025-06-27 01:02:10 +02:00
|
|
|
id: monthLabel
|
2025-07-03 22:51:45 +02:00
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
|
text: Qt.locale().toString(root.month, root.monthFormat)
|
|
|
|
|
font.pixelSize: 9
|
2025-06-27 21:03:06 +02:00
|
|
|
color: palette.dark
|
2025-06-27 01:02:10 +02:00
|
|
|
}
|
|
|
|
|
|
2025-07-07 16:17:28 +02:00
|
|
|
Rectangle { // sundays
|
2025-07-03 22:51:45 +02:00
|
|
|
anchors.top: days.top
|
|
|
|
|
anchors.topMargin: root.month.getDay() === 0 ? 0 : 10
|
|
|
|
|
anchors.bottom: days.bottom
|
|
|
|
|
width: 10
|
2025-08-03 20:35:31 +02:00
|
|
|
color: palette.highlight
|
2025-07-03 22:51:45 +02:00
|
|
|
opacity: 0.2
|
|
|
|
|
radius: 3
|
|
|
|
|
}
|
2025-07-07 16:17:28 +02:00
|
|
|
Rectangle { // saturdays
|
|
|
|
|
anchors.top: days.top
|
|
|
|
|
anchors.bottom: days.bottom
|
|
|
|
|
anchors.bottomMargin: {
|
2026-03-14 21:14:42 +01:00
|
|
|
var last = new Date(root.month.getFullYear(), root.month.getMonth() + 1, 0).getDay()
|
|
|
|
|
return last === 6 ? 0 : 13
|
2025-07-07 16:17:28 +02:00
|
|
|
}
|
|
|
|
|
anchors.right: days.right
|
|
|
|
|
width: 10
|
2025-08-03 20:35:31 +02:00
|
|
|
color: palette.highlight
|
|
|
|
|
opacity: 0.27
|
2025-07-07 16:17:28 +02:00
|
|
|
radius: 3
|
|
|
|
|
}
|
2025-06-27 01:02:10 +02:00
|
|
|
Flow {
|
|
|
|
|
id: days
|
|
|
|
|
anchors.top: monthLabel.bottom
|
|
|
|
|
width: parent.width
|
|
|
|
|
spacing: 3
|
2025-08-03 20:35:31 +02:00
|
|
|
|
|
|
|
|
property int lowBrightnessDay: {
|
|
|
|
|
if (isNaN(root.oldCutoff))
|
2026-03-14 21:14:42 +01:00
|
|
|
return -1
|
|
|
|
|
let cutOff = root.oldCutoff
|
|
|
|
|
let current = root.month // remember, this one is always the first of the month
|
|
|
|
|
let copy = new Date(cutOff.getFullYear(), cutOff.getMonth(), 1)
|
2025-08-03 20:35:31 +02:00
|
|
|
if (current < copy) // the entire month is before cutoff.
|
2026-03-14 21:14:42 +01:00
|
|
|
return 40
|
2025-08-03 20:35:31 +02:00
|
|
|
if (current.getFullYear() !== cutOff.getFullYear()
|
|
|
|
|
|| current.getMonth() !== cutOff.getMonth())
|
2026-03-14 21:14:42 +01:00
|
|
|
return -1
|
|
|
|
|
return cutOff.getDate() - 1
|
2025-08-03 20:35:31 +02:00
|
|
|
}
|
|
|
|
|
|
2025-06-27 01:02:10 +02:00
|
|
|
Repeater {
|
|
|
|
|
model: root.month.getDay()
|
|
|
|
|
Item { width: 10; height: 10 }
|
|
|
|
|
}
|
|
|
|
|
Repeater {
|
|
|
|
|
model: {
|
|
|
|
|
// a dirty JavaScript hack. Day zero is actually the last day in the previous month.
|
|
|
|
|
var hack = new Date(root.month.getFullYear(), root.month.getMonth() + 1, 0)
|
2026-03-14 21:14:42 +01:00
|
|
|
return hack.getDate()
|
2025-06-27 01:02:10 +02:00
|
|
|
}
|
2025-06-27 21:03:06 +02:00
|
|
|
Item {
|
|
|
|
|
width: 10
|
|
|
|
|
height: theLabel.contentHeight
|
|
|
|
|
property bool highlighted: root.highlights.includes(modelData + 1)
|
|
|
|
|
Rectangle {
|
|
|
|
|
color: parent.highlighted ? mainWindow.floweeGreen : "#00000000"
|
|
|
|
|
width: parent.width
|
|
|
|
|
height: width
|
|
|
|
|
anchors.centerIn: parent
|
|
|
|
|
radius: 6
|
|
|
|
|
}
|
|
|
|
|
QQC2.Label {
|
2025-06-27 01:02:10 +02:00
|
|
|
id: theLabel
|
|
|
|
|
text: (modelData + 1)
|
2025-06-27 21:03:06 +02:00
|
|
|
width: parent.width
|
2025-06-27 01:02:10 +02:00
|
|
|
horizontalAlignment: Text.AlignHCenter
|
|
|
|
|
font.pixelSize: 7
|
2025-06-27 21:03:06 +02:00
|
|
|
color: parent.highlighted ? "black" : palette.dark
|
2025-08-03 20:35:31 +02:00
|
|
|
opacity: modelData < days.lowBrightnessDay ? 0.3 : 1
|
2025-06-27 01:02:10 +02:00
|
|
|
}
|
2025-07-03 22:51:45 +02:00
|
|
|
MouseArea {
|
|
|
|
|
anchors.fill: parent
|
2025-08-03 20:35:31 +02:00
|
|
|
enabled: modelData >= days.lowBrightnessDay
|
2026-03-14 21:14:42 +01:00
|
|
|
onClicked: root.selected = modelData + 1
|
2025-07-03 22:51:45 +02:00
|
|
|
}
|
2025-06-27 01:02:10 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|