Warning, /plasma/latte-dock/declarativeimports/components/SpriteRectangle.qml is written in an unsupported language. File is not indexed.

0001 /*
0002     SPDX-FileCopyrightText: 2020 Michail Vourlakos <mvourlakos@gmail.com>
0003     SPDX-License-Identifier: GPL-2.0-or-later
0004 */
0005 
0006 import QtQuick 2.7
0007 
0008 import org.kde.plasma.core 2.0 as PlasmaCore
0009 
0010 Canvas {
0011     property color color: "lightblue"
0012     property bool isHorizontal: true
0013     property int spriteMargin: 1
0014     property int spritePosition: PlasmaCore.Types.CenterPositioned
0015     property int spriteSize: 5
0016 
0017     readonly property int length: isHorizontal ? width : height
0018     readonly property int currentSprite: Math.min(spriteSize, maxSpriteSize)
0019 
0020     readonly property int maxSpriteSize: (length - 2*spriteMargin)/7
0021 
0022     readonly property int centeredrectstart: {
0023         if (spritePosition === PlasmaCore.Types.LeftPositioned
0024                 || spritePosition === PlasmaCore.Types.TopPositioned) {
0025             return spriteMargin;
0026         } else if (spritePosition === PlasmaCore.Types.RightPositioned
0027                    || spritePosition === PlasmaCore.Types.BottomPositioned) {
0028             return isHorizontal ? (width - (7*currentSprite) - spriteMargin) : (height - (7*currentSprite) - spriteMargin)
0029         }
0030 
0031         return isHorizontal ? (width - 7*currentSprite) / 2 : (height - 7*currentSprite)/2
0032     }
0033 
0034     readonly property int a1: 0
0035     readonly property int b1: centeredrectstart + 4*currentSprite
0036     readonly property int c1: centeredrectstart
0037     readonly property int d1: 0
0038 
0039     readonly property int a2: b1 + currentSprite
0040     readonly property int b2: a2 + currentSprite
0041     readonly property int c2: c1 + 2 * currentSprite
0042     readonly property int d2: c1 + currentSprite
0043 
0044     readonly property int a3: b2 + currentSprite
0045     readonly property int b3: isHorizontal ? width : height
0046     readonly property int c3: isHorizontal ? width : height
0047     readonly property int d3: c2 + currentSprite
0048 
0049     onColorChanged: requestPaint()
0050     onSpriteMarginChanged: requestPaint()
0051     onSpritePositionChanged: requestPaint()
0052     onSpriteSizeChanged: requestPaint()
0053     onWidthChanged: requestPaint()
0054     onHeightChanged: requestPaint()
0055 
0056     onPaint:{
0057         var ctx = getContext("2d");
0058 
0059         ctx.beginPath();
0060         ctx.clearRect(0,0,width,height);
0061         ctx.fill();
0062 
0063         ctx.fillStyle = color;
0064         ctx.lineWidth=1;
0065 
0066         var start = isHorizontal ? 0 : width;
0067         var end = isHorizontal ? height : 0;
0068 
0069         if (isHorizontal) {
0070             ctx.beginPath();
0071             ctx.moveTo(a1,start);
0072             ctx.lineTo(b1,start);
0073             ctx.lineTo(c1,end);
0074             ctx.lineTo(d1,end);
0075             ctx.fill();
0076 
0077             ctx.beginPath ();
0078             ctx.moveTo(a2,start);
0079             ctx.lineTo(b2,start);
0080             ctx.lineTo(c2,end);
0081             ctx.lineTo(d2,end);
0082             ctx.fill();
0083 
0084             ctx.beginPath ();
0085             ctx.moveTo(a3,start);
0086             ctx.lineTo(b3,start);
0087             ctx.lineTo(c3,end);
0088             ctx.lineTo(d3,end);
0089             ctx.fill();
0090         } else {
0091             ctx.beginPath ();
0092             ctx.moveTo(start,a1);
0093             ctx.lineTo(start,b1);
0094             ctx.lineTo(end, c1);
0095             ctx.lineTo(end, d1);
0096             ctx.fill();
0097 
0098             ctx.beginPath ();
0099             ctx.moveTo(start,a2);
0100             ctx.lineTo(start,b2);
0101             ctx.lineTo(end,c2);
0102             ctx.lineTo(end,d2);
0103             ctx.fill();
0104 
0105             ctx.beginPath ();
0106             ctx.moveTo(start,a3);
0107             ctx.lineTo(start,b3);
0108             ctx.lineTo(end,c3);
0109             ctx.lineTo(end,d3);
0110             ctx.fill();
0111         }
0112     }
0113 }