MultiDayViewIncidenceDelegate.qml 4.32 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
// SPDX-FileCopyrightText: 2021 Claudio Cambra <claudio.cambra@gmail.com>
// SPDX-License-Identifier: GPL-2.0-or-later

import QtQuick 2.15
import QtQuick.Layouts 1.15
import QtQuick.Controls 2.15 as QQC2
import org.kde.kirigami 2.14 as Kirigami

import org.kde.kalendar 1.0 as Kalendar
import "dateutils.js" as DateUtils
import "labelutils.js" as LabelUtils

Rectangle {
    x: ((dayWidth + parentViewSpacing) * modelData.starts) + horizontalSpacing
15
    z: 10
16
17
18
19
    width: ((dayWidth + parentViewSpacing) * modelData.duration) - (horizontalSpacing * 2) - parentViewSpacing // Account for spacing added to x and for spacing at end of line
    height: parent.height
    opacity: isOpenOccurrence || isInCurrentMonth ?
        1.0 : 0.5
20
    Behavior on opacity { NumberAnimation { duration: Kirigami.Units.shortDuration; easing.type: Easing.OutCubic } }
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
    radius: Kirigami.Units.smallSpacing
    color: Qt.rgba(0,0,0,0)

    property real dayWidth: 0
    property real parentViewSpacing: 0
    property int horizontalSpacing: 0 // In between incidence spaces
    property string openOccurrenceId: ""
    property bool isOpenOccurrence: openOccurrenceId ?
        openOccurrenceId === modelData.incidenceId : false
    property bool reactToCurrentMonth: true
    readonly property bool isInCurrentMonth: reactToCurrentMonth && currentMonth ?
        modelData.endTime.getMonth() == root.month || modelData.startTime.getMonth() == root.month :
        true
    property bool isDark: false

36
    IncidenceBackground {
37
        id: incidenceBackground
38
39
40
41
        isOpenOccurrence: parent.isOpenOccurrence
        reactToCurrentMonth: parent.reactToCurrentMonth
        isInCurrentMonth: parent.isInCurrentMonth
        isDark: parent.isDark
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
    }

    RowLayout {
        id: incidenceContents
        clip: true
        property bool spaceRestricted: parent.width < Kirigami.Units.gridUnit * 5

        property color textColor: LabelUtils.getIncidenceLabelColor(modelData.color, root.isDark)

        function otherMonthTextColor(color) {
            if(isDark) {
                if(LabelUtils.getDarkness(color) >= 0.5) {
                    return Qt.lighter(color, 2);
                }
                return Qt.lighter(color, 1.5);
            }
            return Qt.darker(color, 3);
        }

        anchors {
            fill: parent
            leftMargin: spaceRestricted ? Kirigami.Units.smallSpacing / 2 : Kirigami.Units.smallSpacing
            rightMargin: spaceRestricted ? Kirigami.Units.smallSpacing / 2 : Kirigami.Units.smallSpacing
        }

        Kirigami.Icon {
            Layout.maximumHeight: parent.height
            Layout.maximumWidth: height

            source: modelData.incidenceTypeIcon
            isMask: true
            color: isOpenOccurrence ? (LabelUtils.isDarkColor(modelData.color) ? "white" : "black") :
                isInCurrentMonth ? incidenceContents.textColor :
                incidenceContents.otherMonthTextColor(modelData.color)
76
            Behavior on color { ColorAnimation { duration: Kirigami.Units.shortDuration; easing.type: Easing.OutCubic } }
77
78
79
80
81
82
83
84
85
            visible: !parent.spaceRestricted
        }

        QQC2.Label {
            Layout.fillWidth: true
            text: modelData.text
            elide: parent.spaceRestricted ? Text.ElideNone : Text.ElideRight // Eliding takes up space
            font.weight: Font.Medium
            font.pointSize: parent.spaceRestricted ? Kirigami.Theme.smallFont.pointSize :
86
                Kirigami.Theme.defaultFont.pointSize
87
            font.strikeout: modelData.todoCompleted
88
            renderType: Text.QtRendering
89
90
91
            color: isOpenOccurrence ? (LabelUtils.isDarkColor(modelData.color) ? "white" : "black") :
                isInCurrentMonth ? incidenceContents.textColor :
                incidenceContents.otherMonthTextColor(modelData.color)
92
            Behavior on color { ColorAnimation { duration: Kirigami.Units.shortDuration; easing.type: Easing.OutCubic } }
93
94
95
96
97
98
99
100
101
102
103
104
105
106
        }
    }

    IncidenceMouseArea {
        incidenceData: modelData
        collectionId: modelData.collectionId

        onViewClicked: viewIncidence(modelData, collectionData)
        onEditClicked: editIncidence(incidencePtr, collectionId)
        onDeleteClicked: deleteIncidence(incidencePtr, deleteDate)
        onTodoCompletedClicked: completeTodo(incidencePtr)
        onAddSubTodoClicked: root.addSubTodo(parentWrapper)
    }
}