Warning, /plasma/latte-dock/declarativeimports/components/BadgeText.qml is written in an unsupported language. File is not indexed.
0001 /* 0002 * Copyright 2019 Michail Vourlakos <mvourlakos@gmail.com> 0003 * 0004 * This file is part of Latte-Dock 0005 * 0006 * Latte-Dock is free software; you can redistribute it and/or 0007 * modify it under the terms of the GNU General Public License as 0008 * published by the Free Software Foundation; either version 2 of 0009 * the License, or (at your option) any later version. 0010 * 0011 * Latte-Dock is distributed in the hope that it will be useful, 0012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0014 * GNU General Public License for more details. 0015 * 0016 * You should have received a copy of the GNU General Public License 0017 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0018 */ 0019 0020 import QtQuick 2.2 0021 import QtGraphicalEffects 1.0 0022 0023 import org.kde.plasma.plasmoid 2.0 0024 0025 Rectangle { 0026 property double proportion: 0 0027 0028 property double previousProportion: 0 0029 0030 property bool style3d: true 0031 0032 property int numberValue 0033 property string textValue 0034 0035 property bool fullCircle: true 0036 property bool showNumber: true 0037 property bool showText: false 0038 property bool textWithBackgroundColor: false 0039 0040 property int radiusPerCentage: 100 0041 property int minimumWidth: 0 0042 property int maximumWidth: 9999 0043 0044 property double circleOpacity: 1 0045 property double fontPixelSize: partSize // * 0.55 0046 0047 property double stdThickness: partSize < 0 ? 0 : partSize // "/2.1" 0048 property double circleThicknessAttr: fullCircle ? 0 : stdThickness * 0.9 0049 property double partSize: height / 2 0050 property double pi2: Math.PI * 2 0051 0052 width: Math.max(minimumWidth, valueText.width + 4*units.smallSpacing) 0053 0054 color: theme.backgroundColor 0055 radius: (radiusPerCentage / 100) * (height / 2) 0056 border.width: 0 //Math.max(1,width/64) 0057 0058 property int borderWidth: 1 0059 property real borderOpacity: 1 0060 property color borderColor: theme.textColor 0061 property color textColor: theme.textColor 0062 property color highlightedColor: theme.buttonFocusColor 0063 0064 readonly property bool singleCharacter: (showNumber && numberValue<=9 && numberValue>=0)|| (showText && textValue.length===1) 0065 0066 onProportionChanged: { 0067 if (proportion<0.03) { 0068 previousProportion = 0; 0069 } 0070 0071 //console.log(previousProportion + " - "+proportion); 0072 var currentStep = (proportion - previousProportion); 0073 if ((currentStep >= 0.01) || (proportion>=1 && previousProportion !==1)) { 0074 // console.log("request repaint..."); 0075 previousProportion = proportion; 0076 repaint(); 0077 } 0078 } 0079 0080 function repaint() { 0081 canvas.requestPaint() 0082 } 0083 0084 Canvas { 0085 id: canvas 0086 0087 property int lineWidth: 1 0088 property bool fill: true 0089 property bool stroke: true 0090 property real alpha: 1.0 0091 0092 // edge bleeding fix 0093 readonly property double filler: 0.01 0094 0095 width: parent.width - 2 * parent.borderWidth 0096 height: parent.height - 2 * parent.borderWidth 0097 opacity: proportion > 0 ? 1 : 0 0098 0099 anchors.centerIn: parent 0100 0101 property color drawColor: highlightedColor 0102 0103 onDrawColorChanged: requestPaint(); 0104 0105 onPaint: { 0106 var ctx = getContext('2d'); 0107 ctx.clearRect(0, 0, canvas.width, canvas.height); 0108 ctx.fillStyle = drawColor; 0109 0110 var startRadian = - Math.PI / 2; 0111 0112 var radians = pi2 * proportion; 0113 0114 ctx.beginPath(); 0115 ctx.arc(width/2, height/2, stdThickness, startRadian, startRadian + radians + filler, false); 0116 ctx.arc(width/2, height/2, circleThicknessAttr, startRadian + radians + filler, startRadian, true); 0117 0118 ctx.closePath(); 0119 ctx.fill(); 0120 } 0121 } 0122 0123 Rectangle { 0124 id: badgerBackground 0125 anchors.fill: canvas 0126 color: canvas.drawColor 0127 0128 visible: proportion === 1 && showNumber 0129 radius: parent.radius 0130 } 0131 0132 Text { 0133 id: valueText 0134 anchors.centerIn: canvas 0135 0136 width: Math.min(maximumWidth - 4*units.smallSpacing, implicitWidth) 0137 horizontalAlignment: Text.AlignHCenter 0138 verticalAlignment: Text.AlignVCenter 0139 0140 elide: Text.ElideRight 0141 0142 text: { 0143 if (showNumber) { 0144 if (numberValue > 9999) { 0145 return i18nc("Over 9999 new messages, overlay, keep short", "9,999+"); 0146 } else if (numberValue > 0) { 0147 return numberValue.toLocaleString(Qt.locale(), 'f', 0); 0148 } 0149 } 0150 0151 if (showText) { 0152 return textValue; 0153 } 0154 0155 return ""; 0156 } 0157 font.pixelSize: 0.62 * parent.height 0158 font.bold: true 0159 color: textWithBackgroundColor ? parent.color : parent.textColor 0160 visible: showNumber || showText 0161 } 0162 0163 Rectangle{ 0164 anchors.fill: parent 0165 anchors.topMargin: parent.borderWidth 0166 anchors.bottomMargin: parent.borderWidth 0167 anchors.leftMargin: parent.borderWidth 0168 anchors.rightMargin: parent.borderWidth 0169 color: "transparent" 0170 border.width: parent.borderWidth > 0 ? parent.borderWidth+1 : 0 0171 border.color: "black" 0172 radius: parent.radius 0173 opacity: 0.4 0174 0175 visible: style3d 0176 } 0177 0178 Rectangle{ 0179 anchors.fill: parent 0180 border.width: parent.borderWidth 0181 border.color: { 0182 if (style3d) { 0183 return parent.borderColor 0184 } 0185 0186 return proportion === 1 ? parent.highlightedColor : parent.color 0187 } 0188 color: "transparent" 0189 radius: parent.radius 0190 opacity: parent.borderOpacity 0191 } 0192 } 0193