diff --git a/applets/taskmanager/package/contents/ui/Badge.qml b/applets/taskmanager/package/contents/ui/Badge.qml new file mode 100644 --- /dev/null +++ b/applets/taskmanager/package/contents/ui/Badge.qml @@ -0,0 +1,49 @@ +/*************************************************************************** + * Copyright (C) 2018 Kai Uwe Broulik * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * 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. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * + ***************************************************************************/ + +import QtQuick 2.4 + +import org.kde.plasma.components 2.0 as PlasmaComponents + +Rectangle { + id: badgeRect + + property alias text: label.text + property alias textColor: label.color + property int number: 0 + + implicitWidth: Math.max(height, Math.round(label.contentWidth + radius / 2)) // Add some padding around. + color: theme.highlightColor + radius: height / 2 + + PlasmaComponents.Label { + id: label + anchors.centerIn: parent + width: height + height: Math.round(parent.height) + horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignVCenter + fontSizeMode: Text.VerticalFit + font.pointSize: 1024 + minimumPointSize: 5 + color: theme.backgroundColor + text: badgeRect.number > 9999 ? i18nc("Over 9999 new messages, overlay, keep short", "9,999+") + : badgeRect.number.toLocaleString(Qt.locale(), 'f', 0) + } +} diff --git a/applets/taskmanager/package/contents/ui/TaskBadgeOverlay.qml b/applets/taskmanager/package/contents/ui/TaskBadgeOverlay.qml --- a/applets/taskmanager/package/contents/ui/TaskBadgeOverlay.qml +++ b/applets/taskmanager/package/contents/ui/TaskBadgeOverlay.qml @@ -34,11 +34,16 @@ y: -offset width: badgeRect.width + offset * 2 height: badgeRect.height + offset * 2 - radius: width + radius: badgeRect.radius + offset * 2 + + // Badge changes width based on number. + onWidthChanged: shader.mask.scheduleUpdate() } } ShaderEffect { + id: shader + anchors.fill: parent property var source: ShaderEffectSource { sourceItem: icon @@ -66,25 +71,11 @@ " } - Rectangle { + Badge { id: badgeRect x: Qt.application.layoutDirection === Qt.RightToLeft ? iconWidthDelta : parent.width - width - iconWidthDelta - width: height height: Math.round(parent.height * 0.4) - color: theme.highlightColor - radius: width - PlasmaComponents.Label { - anchors.centerIn: parent - width: height - height: Math.round(parent.height) - horizontalAlignment: Text.AlignHCenter - verticalAlignment: Text.AlignVCenter - fontSizeMode: Text.Fit - font.pointSize: 1024 - minimumPointSize: 5 - color: theme.backgroundColor - text: task.smartLauncherItem.count - } + number: task.smartLauncherItem.count } }