2016-12-25 09:25:27 +02:00
/ *
2019-03-18 20:06:52 +02:00
* Copyright 2019 Michail Vourlakos < mvourlakos @ gmail . com >
2017-01-02 17:05:30 -05:00
*
* 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/>.
* /
2016-12-25 09:25:27 +02:00
import QtQuick 2.2
import QtGraphicalEffects 1.0
2017-04-11 20:23:43 +03:00
import org . kde . plasma . plasmoid 2.0
2017-02-08 19:02:03 +02:00
Rectangle {
2017-02-07 20:53:44 +02:00
property double proportion: 0
property double previousProportion: 0
2016-12-25 09:25:27 +02:00
2019-07-10 17:31:49 +03:00
property bool style3d: true
2017-06-05 19:33:58 +03:00
property int numberValue
2018-01-02 19:38:46 +02:00
property string textValue
2016-12-25 09:25:27 +02:00
2017-06-05 19:33:58 +03:00
property bool fullCircle: true
property bool showNumber: true
2018-01-02 19:38:46 +02:00
property bool showText: false
2018-02-25 17:31:10 +02:00
property bool textWithBackgroundColor: false
2016-12-25 09:25:27 +02:00
2017-06-04 11:15:32 +03:00
property int radiusPerCentage: 100
2018-03-31 10:29:15 +03:00
property int minimumWidth: 0
2019-01-24 15:29:41 +02:00
property int maximumWidth: 9999
2016-12-25 09:25:27 +02:00
2017-06-04 11:15:32 +03:00
property double circleOpacity: 1
2016-12-25 09:25:27 +02:00
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
2018-03-31 10:29:15 +03:00
width: Math . max ( minimumWidth , valueText . width + 4 * units . smallSpacing )
2019-04-23 17:22:30 +03:00
color: theme . backgroundColor
2018-03-31 10:29:15 +03:00
radius: ( radiusPerCentage / 100 ) * ( height / 2 )
2019-04-23 19:00:53 +03:00
border.width: 0 //Math.max(1,width/64)
2019-04-23 17:22:30 +03:00
2019-04-23 19:00:53 +03:00
property int borderWidth: 1
property real borderOpacity: 1
property color borderColor: theme . textColor
2019-04-23 17:22:30 +03:00
property color textColor: theme . textColor
property color highlightedColor: theme . buttonFocusColor
2017-02-08 19:02:03 +02:00
2019-07-10 17:31:49 +03:00
readonly property bool singleCharacter: ( showNumber && numberValue <= 9 && numberValue >= 0 ) || ( showText && textValue . length === 1 )
2016-12-25 09:25:27 +02:00
onProportionChanged: {
2019-07-28 23:26:48 +03:00
if ( proportion < 0.03 ) {
previousProportion = 0 ;
}
//console.log(previousProportion + " - "+proportion);
var currentStep = ( proportion - previousProportion ) ;
if ( ( currentStep >= 0.01 ) || ( proportion >= 1 && previousProportion !== 1 ) ) {
2017-10-21 15:58:34 +03:00
// console.log("request repaint...");
2017-02-07 20:53:44 +02:00
previousProportion = proportion ;
repaint ( ) ;
}
2016-12-25 09:25:27 +02:00
}
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
2019-04-23 19:00:53 +03:00
width: parent . width - 2 * parent . borderWidth
height: parent . height - 2 * parent . borderWidth
2017-04-11 20:23:43 +03:00
opacity: proportion > 0 ? 1 : 0
2017-02-08 19:02:03 +02:00
anchors.centerIn: parent
2016-12-25 09:25:27 +02:00
2019-04-23 17:22:30 +03:00
property color drawColor: highlightedColor
2017-04-11 20:23:43 +03:00
onDrawColorChanged: requestPaint ( ) ;
2016-12-25 09:25:27 +02:00
onPaint: {
2017-02-08 19:02:03 +02:00
var ctx = getContext ( '2d' ) ;
ctx . clearRect ( 0 , 0 , canvas . width , canvas . height ) ;
2017-04-11 20:23:43 +03:00
ctx . fillStyle = drawColor ;
2016-12-25 09:25:27 +02:00
2017-02-08 19:02:03 +02:00
var startRadian = - Math . PI / 2 ;
2016-12-25 09:25:27 +02:00
2017-02-08 19:02:03 +02:00
var radians = pi2 * proportion ;
2016-12-25 09:25:27 +02:00
ctx . beginPath ( ) ;
2017-02-08 19:02:03 +02:00
ctx . arc ( width / 2 , height / 2 , stdThickness , startRadian , startRadian + radians + filler , false ) ;
ctx . arc ( width / 2 , height / 2 , circleThicknessAttr , startRadian + radians + filler , startRadian , true ) ;
2016-12-25 09:25:27 +02:00
2017-02-08 19:02:03 +02:00
ctx . closePath ( ) ;
ctx . fill ( ) ;
2016-12-25 09:25:27 +02:00
}
}
2018-03-31 10:29:15 +03:00
Rectangle {
id: badgerBackground
anchors.fill: canvas
color: canvas . drawColor
2019-07-28 23:26:48 +03:00
visible: proportion === 1 && showNumber
2018-03-31 10:29:15 +03:00
radius: parent . radius
}
2016-12-25 09:25:27 +02:00
Text {
id: valueText
2019-01-26 15:27:57 +02:00
anchors.centerIn: canvas
2019-01-24 15:29:41 +02:00
width: Math . min ( maximumWidth - 4 * units . smallSpacing , implicitWidth )
2019-01-26 15:27:57 +02:00
horizontalAlignment: Text . AlignHCenter
verticalAlignment: Text . AlignVCenter
2019-01-24 15:29:41 +02:00
elide: Text . ElideRight
2018-01-02 19:38:46 +02:00
text: {
if ( showNumber ) {
2018-03-31 10:29:15 +03:00
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 ) ;
}
2018-01-02 19:38:46 +02:00
}
if ( showText ) {
return textValue ;
}
2018-07-23 19:35:09 +03:00
return "" ;
2018-01-02 19:38:46 +02:00
}
2019-01-27 10:29:16 +02:00
font.pixelSize: 0.62 * parent . height
2017-04-11 20:23:43 +03:00
font.bold: true
2019-04-23 17:22:30 +03:00
color: textWithBackgroundColor ? parent.color : parent . textColor
2018-01-02 19:38:46 +02:00
visible: showNumber || showText
2016-12-25 09:25:27 +02:00
}
2017-03-08 18:50:52 +02:00
2017-05-01 10:01:24 +03:00
Rectangle {
2017-10-21 15:58:34 +03:00
anchors.fill: parent
2019-04-23 19:00:53 +03:00
anchors.topMargin: parent . borderWidth
anchors.bottomMargin: parent . borderWidth
anchors.leftMargin: parent . borderWidth
anchors.rightMargin: parent . borderWidth
2017-10-21 15:58:34 +03:00
color: "transparent"
2019-04-23 19:00:53 +03:00
border.width: parent . borderWidth > 0 ? parent . borderWidth + 1 : 0
2019-04-23 17:22:30 +03:00
border.color: "black"
2017-10-21 15:58:34 +03:00
radius: parent . radius
2019-04-23 17:22:30 +03:00
opacity: 0.4
2019-07-10 17:31:49 +03:00
visible: style3d
2017-05-01 10:01:24 +03:00
}
2017-03-08 18:50:52 +02:00
Rectangle {
anchors.fill: parent
2019-04-23 19:00:53 +03:00
border.width: parent . borderWidth
2019-07-10 18:34:26 +03:00
border.color: {
if ( style3d ) {
return parent . borderColor
}
2019-07-28 23:26:48 +03:00
return proportion === 1 ? parent.highlightedColor : parent . color
2019-07-10 18:34:26 +03:00
}
2017-03-08 18:50:52 +02:00
color: "transparent"
radius: parent . radius
2019-04-23 19:00:53 +03:00
opacity: parent . borderOpacity
2017-03-08 18:50:52 +02:00
}
2016-12-25 09:25:27 +02:00
}