summary refs log tree commit diff
path: root/resources/qml/components/NotificationBubble.qml
blob: d4838e9259390aba2e58e1c763e74b64d53bde27 (plain) (blame)
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
// SPDX-FileCopyrightText: Nheko Contributors
//
// SPDX-License-Identifier: GPL-3.0-or-later

import QtQuick 2.15
import QtQuick.Controls 2.15
import im.nheko 1.0

Rectangle {
    id: bubbleRoot

    required property int notificationCount
    required property bool hasLoudNotification
    required property color bubbleBackgroundColor
    required property color bubbleTextColor
    property bool mayBeVisible: true
    property alias font: notificationBubbleText.font
    baselineOffset: notificationBubbleText.baseline - bubbleRoot.top

    visible: mayBeVisible && notificationCount > 0
    implicitHeight: notificationBubbleText.height + Nheko.paddingMedium
    implicitWidth: Math.max(notificationBubbleText.width, height)
    radius: height / 2
    color: hasLoudNotification ? Nheko.theme.red : bubbleBackgroundColor
    ToolTip.text: notificationCount
    ToolTip.delay: Nheko.tooltipDelay
    ToolTip.visible: notificationBubbleHover.hovered && (notificationCount > 9999)

    Label {
        id: notificationBubbleText

        anchors.centerIn: bubbleRoot
        horizontalAlignment: Text.AlignHCenter
        verticalAlignment: Text.AlignVCenter
        width: Math.max(implicitWidth + Nheko.paddingMedium, bubbleRoot.height)
        font.bold: true
        font.pixelSize: fontMetrics.font.pixelSize * 0.8
        color: bubbleRoot.hasLoudNotification ? "white" : bubbleRoot.bubbleTextColor
        text: bubbleRoot.notificationCount > 9999 ? "9999+" : bubbleRoot.notificationCount

        HoverHandler {
            id: notificationBubbleHover
        }

    }

}