aboutsummaryrefslogtreecommitdiffstats
path: root/desktop/NotificationRow.qml
blob: 7aff362443b94c6b5681d89f78b9076586e3c507 (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
// Copyright (C) 2026 Danilo M. <danix@danix.xyz>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2 as
// published by the Free Software Foundation.
//
// 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.

import QtQuick

// One notification in the drawer: app, summary and body. Live rows close with
// the X and click through to their actions; a history row is inert.
Item {
    id: row

    required property var notification
    // A history row has no live client: no X, and a click does nothing.
    property bool live: true

    readonly property bool inert: row.notification.expires !== 0 && Date.now() >= row.notification.expires

    implicitHeight: texts.implicitHeight + 16

    MouseArea {
        anchors.fill: parent
        acceptedButtons: Qt.LeftButton | Qt.RightButton
        cursorShape: Qt.PointingHandCursor
        onClicked: mouse => {
            if (mouse.button === Qt.RightButton) {
                Notify.closeAll();
                return;
            }
            if (!row.live) return;
            const acts = row.notification.actions || [];
            if (acts.length > 0 && !row.inert) Notify.actions(row.notification.id, acts);
            else Notify.close(row.notification.id);
        }
    }

    Column {
        id: texts
        anchors {
            left: parent.left
            right: closeBtn.visible ? closeBtn.left : parent.right
            rightMargin: 10
            verticalCenter: parent.verticalCenter
        }
        spacing: 2

        Text {
            width: parent.width
            text: (row.notification.app || "") + (row.notification.summary ? "  " + row.notification.summary : "")
            elide: Text.ElideRight
            font { family: Theme.fontFamily; pixelSize: Theme.fontSize - 3 }
            color: Theme.text
        }

        Text {
            width: parent.width
            visible: text !== ""
            text: row.notification.body || ""
            textFormat: Text.RichText
            wrapMode: Text.WordWrap
            maximumLineCount: 2
            elide: Text.ElideRight
            font { family: Theme.fontFamily; pixelSize: Theme.fontSize - 5 }
            color: Theme.subtext
        }
    }

    Text {
        id: closeBtn
        visible: row.live
        anchors { right: parent.right; verticalCenter: parent.verticalCenter }
        width: 20
        height: 20
        text: "\uf00d"
        horizontalAlignment: Text.AlignHCenter
        verticalAlignment: Text.AlignVCenter
        font { family: Theme.iconFamily; pixelSize: 11 }
        color: closeArea.containsMouse ? Theme.red : Theme.subtext

        MouseArea {
            id: closeArea
            anchors.fill: parent
            hoverEnabled: true
            cursorShape: Qt.PointingHandCursor
            onClicked: Notify.close(row.notification.id)
        }
    }
}