summaryrefslogtreecommitdiff
path: root/contents/ui/ActivityView.qml
blob: b6996ba4e6fb6ee524517ced9f826383848d0313 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import QtQuick 2.15
import QtQuick.Layouts 1.15
import QtQuick.Controls 2.15

import org.kde.plasma.plasmoid 2.0
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 2.0 as PlasmaComponents
import org.kde.plasma.components 3.0 as PlasmaComponents3
import org.kde.plasma.extras 2.0 as PlasmaExtras

RowLayout {
    id: activityView
    width: parent.width
    Layout.fillWidth: true

    RowLayout {
        Layout.fillWidth: true
        PlasmaComponents3.CheckBox {
            id: activityCheckbox
            Layout.alignment: Qt.AlignTop
            onToggled: () => {
                activityLabel.font.strikeout = (checkState == Qt.Checked)
            }
        }

        ColumnLayout {
            PlasmaComponents3.Label {
                id: activityLabel
                text: `[${course}] ${title}`
                font.bold: important
                color: important ? PlasmaCore.Theme.negativeTextColor : PlasmaCore.Theme.textColor
                elide: Text.ElideRight
                Layout.fillWidth: true

            }

            PlasmaComponents3.Label {
                id: dueLabel
                visible: type == "assignment"
                text: "Due " + (due || "unknown")
                color: activityLabel.color
                Layout.fillWidth: true
            }

            MouseArea {
                anchors.fill: parent
                onClicked: () => {
                    activityCheckbox.toggle()  // toggle checkbox
                    activityCheckbox.toggled() // and trigger the onToggled effects
                }
            }
        }

    }

    RowLayout {
        Layout.alignment: Qt.AlignRight

        PlasmaComponents3.ToolButton {
            icon.name: "view-visible"
            onClicked: () => {
                Qt.openUrlExternally(url)
            }
        }

        PlasmaComponents3.ToolButton {
            icon.name: "emblem-important-symbolic"
            checked: important

            onClicked: () => {
                important = !important
                activityLabel.font.bold = important
                activityLabel.color = important ? PlasmaCore.Theme.negativeTextColor : PlasmaCore.Theme.textColor
                let importantActivities = plasmoid.configuration.importantActivities
                if (important) {
                    if (!importantActivities.includes(activityId)) {
                        importantActivities.push(activityId)
                    }
                } else {
                    // remove activityId from list
                    importantActivities.splice(importantActivities.indexOf(activityId), 1)
                }
                // save config
                plasmoid.configuration.importantActivities = importantActivities
            }
        }

        PlasmaComponents3.ToolButton {
            icon.name: "delete"
            onClicked: () => {
                // avoid non-fatal TypeError due to activityView.parent=null but .width=parent.width
                activityView.width = 0
                if (type == "announcement") {
                    announcementsModel.remove(index)
                } else {
                    assignmentsModel.remove(index)
                }
            }
        }
    }
}