2022-08-28 21:48:51 +00:00
|
|
|
/*
|
|
|
|
SPDX-FileCopyrightText: 2013 Heena Mahour <heena393@gmail.com>
|
|
|
|
SPDX-FileCopyrightText: 2013 Sebastian Kügler <sebas@kde.org>
|
|
|
|
SPDX-FileCopyrightText: 2015 Kai Uwe Broulik <kde@privat.broulik.de>
|
|
|
|
SPDX-FileCopyrightText: 2021 Jan Blackquill <uhhadd@gmail.com>
|
|
|
|
SPDX-FileCopyrightText: 2021 Carl Schwan <carlschwan@kde.org>
|
|
|
|
|
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2024-08-09 01:20:25 +00:00
|
|
|
import QtQuick 2.2
|
|
|
|
|
|
|
|
import org.kde.plasma.plasmoid 2.0
|
2022-08-28 21:48:51 +00:00
|
|
|
import org.kde.plasma.core 2.0 as PlasmaCore
|
|
|
|
import org.kde.plasma.components 3.0 as PlasmaComponents3
|
|
|
|
import org.kde.plasma.extras 2.0 as PlasmaExtras
|
|
|
|
import QtQml.Models 2.15
|
|
|
|
|
2024-08-09 01:20:25 +00:00
|
|
|
import Qt5Compat.GraphicalEffects
|
|
|
|
|
|
|
|
import org.kde.kirigami as Kirigami
|
|
|
|
import org.kde.ksvg as KSvg
|
|
|
|
import org.kde.plasma.workspace.calendar 2.0
|
2022-08-28 21:48:51 +00:00
|
|
|
|
|
|
|
PlasmaComponents3.AbstractButton {
|
|
|
|
id: dayStyle
|
|
|
|
|
|
|
|
hoverEnabled: true
|
|
|
|
property var dayModel: null
|
|
|
|
|
|
|
|
signal activated
|
|
|
|
|
2024-08-09 01:20:25 +00:00
|
|
|
|
2022-08-28 21:48:51 +00:00
|
|
|
readonly property date thisDate: new Date(yearNumber, typeof monthNumber !== "undefined" ? monthNumber - 1 : 0, typeof dayNumber !== "undefined" ? dayNumber : 1)
|
|
|
|
readonly property bool today: {
|
|
|
|
const today = root.today;
|
|
|
|
let result = true;
|
|
|
|
if (dateMatchingPrecision >= Calendar.MatchYear) {
|
|
|
|
result = result && today.getFullYear() === thisDate.getFullYear()
|
|
|
|
}
|
|
|
|
if (dateMatchingPrecision >= Calendar.MatchYearAndMonth) {
|
|
|
|
result = result && today.getMonth() === thisDate.getMonth()
|
|
|
|
}
|
|
|
|
if (dateMatchingPrecision >= Calendar.MatchYearMonthAndDay) {
|
|
|
|
result = result && today.getDate() === thisDate.getDate()
|
|
|
|
}
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
readonly property bool selected: {
|
|
|
|
const current = root.currentDate;
|
|
|
|
let result = true;
|
|
|
|
if (dateMatchingPrecision >= Calendar.MatchYear) {
|
|
|
|
result = result && current.getFullYear() === thisDate.getFullYear()
|
|
|
|
}
|
|
|
|
if (dateMatchingPrecision >= Calendar.MatchYearAndMonth) {
|
|
|
|
result = result && current.getMonth() === thisDate.getMonth()
|
|
|
|
}
|
|
|
|
if (dateMatchingPrecision >= Calendar.MatchYearMonthAndDay) {
|
|
|
|
result = result && current.getDate() === thisDate.getDate()
|
|
|
|
}
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
|
|
|
PlasmaExtras.Highlight {
|
|
|
|
id: todayRect
|
|
|
|
anchors.fill: parent
|
|
|
|
hovered: true
|
|
|
|
opacity: {
|
2024-08-09 01:20:25 +00:00
|
|
|
if (today && !dayStyle.hovered && !selected) {
|
|
|
|
return 0;
|
2022-08-28 21:48:51 +00:00
|
|
|
} else if (selected) {
|
2024-08-09 01:20:25 +00:00
|
|
|
return 0.8;
|
|
|
|
} else if (dayStyle.pressed) {
|
2022-08-28 21:48:51 +00:00
|
|
|
return 0.3;
|
2024-08-09 01:20:25 +00:00
|
|
|
} else if (dayStyle.hovered) {
|
|
|
|
return 0.6;
|
2022-08-28 21:48:51 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
z: -1;
|
|
|
|
}
|
|
|
|
|
2024-08-09 01:20:25 +00:00
|
|
|
Rectangle {
|
|
|
|
id: currentDayRect
|
|
|
|
anchors.fill: parent
|
|
|
|
visible: today
|
|
|
|
radius: 2
|
|
|
|
border.color: "#0066cc"
|
|
|
|
color: "transparent"
|
|
|
|
}
|
2022-08-28 21:48:51 +00:00
|
|
|
contentItem: PlasmaExtras.Heading {
|
|
|
|
id: label
|
2024-08-09 01:20:25 +00:00
|
|
|
horizontalAlignment: dateMatchingPrecision != Calendar.MatchYearMonthAndDay ? Text.AlignHCenter: Text.AlignRight
|
2022-08-28 21:48:51 +00:00
|
|
|
verticalAlignment: Text.AlignVCenter
|
2024-08-09 01:20:25 +00:00
|
|
|
bottomPadding: dateMatchingPrecision != Calendar.MatchYearMonthAndDay ? 0 : 1
|
|
|
|
rightPadding: dateMatchingPrecision != Calendar.MatchYearMonthAndDay ? 0 : Kirigami.Units.smallSpacing+1
|
2022-08-28 21:48:51 +00:00
|
|
|
wrapMode: Text.NoWrap
|
|
|
|
elide: Text.ElideRight
|
2024-08-09 01:20:25 +00:00
|
|
|
font.bold: calendar.showAgenda && model.eventCount !== undefined && model.eventCount > 0
|
2022-08-28 21:48:51 +00:00
|
|
|
fontSizeMode: Text.Fit
|
2023-08-24 22:32:11 +00:00
|
|
|
|
2024-08-09 01:20:25 +00:00
|
|
|
color: today || (!dayStyle.pressed && dayStyle.hovered) ? "#0066cc" : Kirigami.Theme.textColor
|
|
|
|
|
|
|
|
text: {
|
|
|
|
if(model.label) {
|
|
|
|
if(dateMatchingPrecision == Calendar.MatchYearAndMonth) return model.label.substring(0, 3);
|
|
|
|
return model.label;
|
|
|
|
}
|
|
|
|
return dayNumber;
|
|
|
|
}
|
2023-08-24 22:32:11 +00:00
|
|
|
opacity: isCurrent ? 1.0 : 0.5
|
2022-08-28 21:48:51 +00:00
|
|
|
level: 5
|
|
|
|
}
|
|
|
|
}
|