| 1 |
// SPDX-FileCopyrightText: Nheko Contributors |
| 2 |
// |
| 3 |
// SPDX-License-Identifier: GPL-3.0-or-later |
| 4 |
|
| 5 |
import QtQuick 2.15 |
| 6 |
import QtQuick.Controls 2.15 |
| 7 |
import im.nheko 1.0 |
| 8 |
|
| 9 |
Rectangle { |
| 10 |
id: bubbleRoot |
| 11 |
|
| 12 |
required property int notificationCount |
| 13 |
required property bool hasLoudNotification |
| 14 |
required property color bubbleBackgroundColor |
| 15 |
required property color bubbleTextColor |
| 16 |
property bool mayBeVisible: true |
| 17 |
property alias font: notificationBubbleText.font |
| 18 |
baselineOffset: notificationBubbleText.baseline - bubbleRoot.top |
| 19 |
|
| 20 |
visible: mayBeVisible && notificationCount > 0 |
| 21 |
implicitHeight: notificationBubbleText.height + Nheko.paddingMedium |
| 22 |
implicitWidth: Math.max(notificationBubbleText.width, height) |
| 23 |
radius: height / 2 |
| 24 |
color: hasLoudNotification ? Nheko.theme.red : bubbleBackgroundColor |
| 25 |
ToolTip.text: notificationCount |
| 26 |
ToolTip.delay: Nheko.tooltipDelay |
| 27 |
ToolTip.visible: notificationBubbleHover.hovered && (notificationCount > 9999) |
| 28 |
|
| 29 |
Label { |
| 30 |
id: notificationBubbleText |
| 31 |
|
| 32 |
anchors.centerIn: bubbleRoot |
| 33 |
horizontalAlignment: Text.AlignHCenter |
| 34 |
verticalAlignment: Text.AlignVCenter |
| 35 |
width: Math.max(implicitWidth + Nheko.paddingMedium, bubbleRoot.height) |
| 36 |
font.bold: true |
| 37 |
font.pixelSize: fontMetrics.font.pixelSize * 0.8 |
| 38 |
color: bubbleRoot.hasLoudNotification ? "white" : bubbleRoot.bubbleTextColor |
| 39 |
text: bubbleRoot.notificationCount > 9999 ? "9999+" : bubbleRoot.notificationCount |
| 40 |
|
| 41 |
HoverHandler { |
| 42 |
id: notificationBubbleHover |
| 43 |
} |
| 44 |
|
| 45 |
} |
| 46 |
|
| 47 |
} |