Files
pay/guis/mobile/MiniCalendarWidget.qml
T

110 lines
3.5 KiB
QML
Raw Permalink Normal View History

/*
* 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-07-03 22:51:45 +02:00
// when the user clicks on a date.
property int selected: 0
// an array of ints.
property var highlights: []
2025-07-03 22:51:45 +02:00
property string monthFormat: "MMM yy"
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
onVisibleChanged: if (visible) selected = 0;
2025-06-27 21:03:06 +02:00
QQC2.Label {
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-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
color: "red"
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: {
var last = new Date(root.month.getFullYear(), root.month.getMonth() + 1, 0).getDay();
return last === 6 ? 0 : 13;
}
anchors.right: days.right
width: 10
color: "red"
opacity: 0.13
radius: 3
}
Flow {
id: days
anchors.top: monthLabel.bottom
width: parent.width
spacing: 3
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)
return hack.getDate();
}
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 {
id: theLabel
text: (modelData + 1)
2025-06-27 21:03:06 +02:00
width: parent.width
horizontalAlignment: Text.AlignHCenter
font.pixelSize: 7
2025-06-27 21:03:06 +02:00
color: parent.highlighted ? "black" : palette.dark
}
2025-07-03 22:51:45 +02:00
MouseArea {
anchors.fill: parent
onClicked: root.selected = modelData + 1;
}
}
}
}
}