You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
174 lines
5.3 KiB
QML
174 lines
5.3 KiB
QML
8 years ago
|
/*
|
||
8 years ago
|
|
||
8 years ago
|
* Copyright 2016 Smith AR <audoban@openmailbox.org>
|
||
|
* Michail Vourlakos <mvourlakos@gmail.com>
|
||
|
*
|
||
|
* This file is part of Latte-Dock
|
||
|
*
|
||
|
* Latte-Dock 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.
|
||
|
*
|
||
|
* Latte-Dock 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, see <http://www.gnu.org/licenses/>.
|
||
|
*/
|
||
8 years ago
|
|
||
|
import QtQuick 2.2
|
||
|
import QtGraphicalEffects 1.0
|
||
|
|
||
8 years ago
|
import org.kde.plasma.plasmoid 2.0
|
||
|
|
||
8 years ago
|
Rectangle {
|
||
8 years ago
|
property double proportion: 0
|
||
|
|
||
|
property double previousProportion: 0
|
||
8 years ago
|
|
||
8 years ago
|
property int numberValue
|
||
7 years ago
|
property string textValue
|
||
8 years ago
|
|
||
8 years ago
|
property bool fullCircle: true
|
||
|
property bool showNumber: true
|
||
7 years ago
|
property bool showText: false
|
||
7 years ago
|
property bool textWithBackgroundColor: false
|
||
8 years ago
|
|
||
8 years ago
|
property int radiusPerCentage: 100
|
||
7 years ago
|
property int minimumWidth: 0
|
||
6 years ago
|
property int maximumWidth: 9999
|
||
8 years ago
|
|
||
8 years ago
|
property double circleOpacity: 1
|
||
8 years ago
|
property double fontPixelSize: partSize // * 0.55
|
||
|
|
||
|
property double stdThickness: partSize < 0 ? 0 : partSize // "/2.1"
|
||
|
property double circleThicknessAttr: fullCircle ? 0 : stdThickness * 0.9
|
||
|
property double partSize: height / 2
|
||
|
property double pi2: Math.PI * 2
|
||
|
|
||
8 years ago
|
property color alphaBackColor: Qt.rgba(theme.backgroundColor.r, theme.backgroundColor.g, theme.backgroundColor.b, 0.45)
|
||
|
property color alphaBackColor2: Qt.rgba(theme.backgroundColor.r, theme.backgroundColor.g, theme.backgroundColor.b, 0.8)
|
||
7 years ago
|
|
||
|
width: Math.max(minimumWidth, valueText.width + 4*units.smallSpacing)
|
||
|
|
||
8 years ago
|
color: theme.backgroundColor //mainItemContainer.badgeIndicator > 0 ? alphaBackColor2 : alphaBackColor
|
||
7 years ago
|
radius: (radiusPerCentage / 100) * (height / 2)
|
||
8 years ago
|
border.width: Math.max(1,width/64)
|
||
|
|
||
8 years ago
|
onProportionChanged: {
|
||
7 years ago
|
// console.log(previousProportion + " - "+proportion);
|
||
8 years ago
|
if ((proportion - 0.03 >= previousProportion) || (proportion===1)) {
|
||
7 years ago
|
// console.log("request repaint...");
|
||
8 years ago
|
previousProportion = proportion;
|
||
|
repaint();
|
||
|
}
|
||
8 years ago
|
}
|
||
|
|
||
|
function repaint() {
|
||
|
canvas.requestPaint()
|
||
|
}
|
||
|
|
||
|
Canvas {
|
||
|
id: canvas
|
||
|
|
||
|
property int lineWidth: 1
|
||
|
property bool fill: true
|
||
|
property bool stroke: true
|
||
|
property real alpha: 1.0
|
||
|
|
||
|
// edge bleeding fix
|
||
|
readonly property double filler: 0.01
|
||
|
|
||
8 years ago
|
width: parent.width - 2 * parent.border.width
|
||
|
height: parent.height - 2 * parent.border.width
|
||
8 years ago
|
opacity: proportion > 0 ? 1 : 0
|
||
8 years ago
|
|
||
|
anchors.centerIn: parent
|
||
8 years ago
|
|
||
8 years ago
|
property color drawColor: theme.buttonFocusColor; //mainItemContainer.badgeIndicator > 0 ? theme.buttonFocusColor : theme.highlightColor;
|
||
8 years ago
|
|
||
|
onDrawColorChanged: requestPaint();
|
||
|
|
||
8 years ago
|
onPaint: {
|
||
8 years ago
|
var ctx = getContext('2d');
|
||
|
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
||
8 years ago
|
ctx.fillStyle = drawColor;
|
||
8 years ago
|
|
||
8 years ago
|
var startRadian = - Math.PI / 2;
|
||
8 years ago
|
|
||
8 years ago
|
var radians = pi2 * proportion;
|
||
8 years ago
|
|
||
|
ctx.beginPath();
|
||
8 years ago
|
ctx.arc(width/2, height/2, stdThickness, startRadian, startRadian + radians + filler, false);
|
||
|
ctx.arc(width/2, height/2, circleThicknessAttr, startRadian + radians + filler, startRadian, true);
|
||
8 years ago
|
|
||
8 years ago
|
ctx.closePath();
|
||
|
ctx.fill();
|
||
8 years ago
|
}
|
||
|
}
|
||
|
|
||
7 years ago
|
Rectangle {
|
||
|
id: badgerBackground
|
||
|
anchors.fill: canvas
|
||
|
color: canvas.drawColor
|
||
|
|
||
|
visible: proportion === 100 && showNumber
|
||
|
radius: parent.radius
|
||
|
}
|
||
|
|
||
8 years ago
|
Text {
|
||
|
id: valueText
|
||
6 years ago
|
anchors.centerIn: canvas
|
||
|
|
||
6 years ago
|
width: Math.min(maximumWidth - 4*units.smallSpacing, implicitWidth)
|
||
6 years ago
|
horizontalAlignment: Text.AlignHCenter
|
||
|
verticalAlignment: Text.AlignVCenter
|
||
|
|
||
6 years ago
|
elide: Text.ElideRight
|
||
|
|
||
7 years ago
|
text: {
|
||
|
if (showNumber) {
|
||
7 years ago
|
if (numberValue > 9999) {
|
||
|
return i18nc("Over 9999 new messages, overlay, keep short", "9,999+");
|
||
|
} else if (numberValue > 0) {
|
||
|
return numberValue.toLocaleString(Qt.locale(), 'f', 0);
|
||
|
}
|
||
7 years ago
|
}
|
||
|
|
||
|
if (showText) {
|
||
|
return textValue;
|
||
|
}
|
||
7 years ago
|
|
||
|
return "";
|
||
7 years ago
|
}
|
||
6 years ago
|
font.pixelSize: 0.62 * parent.height
|
||
8 years ago
|
font.bold: true
|
||
7 years ago
|
color: textWithBackgroundColor ? theme.backgroundColor : theme.textColor
|
||
7 years ago
|
visible: showNumber || showText
|
||
8 years ago
|
}
|
||
8 years ago
|
|
||
8 years ago
|
Rectangle{
|
||
7 years ago
|
anchors.fill: parent
|
||
|
anchors.topMargin: parent.border.width
|
||
|
anchors.bottomMargin: parent.border.width
|
||
|
anchors.leftMargin: parent.border.width
|
||
|
anchors.rightMargin: parent.border.width
|
||
|
color: "transparent"
|
||
|
border.width: parent.border.width
|
||
|
border.color: parent.alphaBackColor2
|
||
|
radius: parent.radius
|
||
8 years ago
|
}
|
||
|
|
||
8 years ago
|
Rectangle{
|
||
|
anchors.fill: parent
|
||
|
border.width: parent.border.width
|
||
|
border.color: parent.border.color
|
||
|
color: "transparent"
|
||
|
radius: parent.radius
|
||
|
}
|
||
8 years ago
|
}
|
||
|
|