/*SPDX-FileCopyrightText: 2016 Kai Uwe Broulik <kde@privat.broulik.de>SPDX-License-Identifier: GPL-2.0-or-later*/import QtQuickimport org.kde.kirigami as Kirigamiimport org.kde.graphicaleffects as KGraphicalEffectsimport org.kde.plasma.plasmoidItem {id: rootreadonly property bool verySmallIcon:icon.width < Kirigami.Units.iconSizes.smallMedium ||icon.height < Kirigami.Units.iconSizes.smallMediumreadonly property bool shiftBadgeDown: (Plasmoid.pluginName === "org.kde.plasma.icontasks") && task.audioStreamIcon !== nullreadonly property int badgeMaskY: shiftBadgeDown ? root.height - badgeRect.height : 0readonly property int offset: Math.round(Math.max(Kirigami.Units.smallSpacing / 2, badgeMask.width / 32))readonly property int extraHorizontalOffset: verySmallIcon && badgeRect.text.length > 2 ? -2 : 0// The small font is likely to not be small enough here for very space-constrained// panels; allow going this much under it.readonly property real smallestFractionOfSmallFontSize: 0.75// If the actual height is less, scale the font down. If it's greater, scale it up.readonly property int iconSizeForDefaultFontSize: Kirigami.Units.iconSizes.largereadonly property real badgeScaleFactor: Math.max(smallestFractionOfSmallFontSize, icon.height / iconSizeForDefaultFontSize)Item {id: badgeMaskanchors.fill: parentRectangle {anchors.right: parent.rightanchors.rightMargin: -root.offset + root.extraHorizontalOffsety: root.badgeMaskYBehavior on y {NumberAnimation { duration: Kirigami.Units.longDuration }}visible: task.smartLauncherItem.countVisiblewidth: badgeRect.width + root.offset * 2height: badgeRect.height + root.offset * 2radius: height// Badge changes width based on number.onWidthChanged: maskShaderSource.scheduleUpdate()onVisibleChanged: maskShaderSource.scheduleUpdate()onYChanged: maskShaderSource.scheduleUpdate()}}ShaderEffectSource {id: iconShaderSourcesourceItem: iconhideSource: GraphicsInfo.api !== GraphicsInfo.Software}ShaderEffectSource {id: maskShaderSourcesourceItem: badgeMaskhideSource: truelive: false}KGraphicalEffects.BadgeEffect {id: shaderanchors.fill: parentsource: iconShaderSourcemask: maskShaderSourceonWidthChanged: maskShaderSource.scheduleUpdate()onHeightChanged: maskShaderSource.scheduleUpdate()}Kirigami.Badge {id: badgeRectanchors.right: parent.rightanchors.rightMargin: root.extraHorizontalOffsety: root.badgeMaskY + root.offsetBehavior on y {NumberAnimation { duration: Kirigami.Units.longDuration }}visible: task.smartLauncherItem.countVisiblepadding: Math.floor(root.badgeScaleFactor * 2)font.pointSize: Math.floor((Kirigami.Theme.smallFont.pointSize * root.badgeScaleFactor))text: {let unreadCount = task.smartLauncherItem.count;if (unreadCount > 9999) {return i18nc("'k' is a suffix for 'thousand'; keep to one character or else the badge could overflow!", "9k+");} else if (unreadCount > 999) {let rounded = Math.floor(unreadCount / 1000);return i18nc("'k' is a suffix for 'thousand'; keep to one character or else the badge could overflow!", "%1k", rounded);} else {return unreadCount.toLocaleString(Qt.locale(), 'f', 0);}}}}