Warning, /plasma/latte-dock/containment/package/contents/ui/colorizer/CustomBackground.qml is written in an unsupported language. File is not indexed.

0001 /*
0002     SPDX-FileCopyrightText: 2018 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.plasmoid 2.0
0009 import org.kde.plasma.core 2.0 as PlasmaCore
0010 
0011 Item{
0012     id: main
0013     clip: !kirigamiRect.active
0014 
0015     property int borderWidth: 0
0016     property int roundness: 0
0017     property int shadowSize: 0
0018 
0019     property real backgroundOpacity: 1.0
0020 
0021     property color backgroundColor: "black"
0022     property color borderColor: "transparent"
0023     property color shadowColor: "black"
0024 
0025     property bool topBorder: false
0026     property bool leftBorder: false
0027     property bool bottomBorder: false
0028     property bool rightBorder: false
0029 
0030     property bool onlyHorizontalBorders: !leftBorder && !rightBorder
0031     property bool onlyVerticalBorders: !topBorder && !bottomBorder
0032 
0033     property int noOfBorders: {
0034         if (allBorders) {
0035             return 4;
0036         }
0037 
0038         var i = 0;
0039 
0040         if (topBorder) {
0041             i = i + 1;
0042         }
0043         if (leftBorder) {
0044             i = i + 1;
0045         }
0046         if (rightBorder) {
0047             i = i + 1;
0048         }
0049         if (bottomBorder) {
0050             i = i + 1;
0051         }
0052 
0053         return i;
0054     }
0055 
0056     readonly property bool allBorders: (latteView && latteView.effects && (latteView.effects.enabledBorders === PlasmaCore.FrameSvg.AllBorders))
0057 
0058     readonly property bool bothVerticals: (leftBorder && rightBorder)
0059     readonly property bool bothHorizontals: (bottomBorder && topBorder)
0060 
0061     readonly property bool drawWithoutRoundness: onlyHorizontalBorders || onlyVerticalBorders
0062 
0063     readonly property Item painterRectangle: painter
0064 
0065     Binding{
0066         target: main
0067         property: "topBorder"
0068         when: latteView
0069         value: {
0070             return (latteView && latteView.effects && ((latteView.effects.enabledBorders & PlasmaCore.FrameSvg.TopBorder)) > 0) || allBorders;
0071         }
0072     }
0073 
0074     Binding{
0075         target: main
0076         property: "leftBorder"
0077         when: latteView
0078         value: {
0079             return (latteView && latteView.effects && ((latteView.effects.enabledBorders & PlasmaCore.FrameSvg.LeftBorder)) > 0) || allBorders;
0080         }
0081     }
0082 
0083     Binding{
0084         target: main
0085         property: "bottomBorder"
0086         when: latteView
0087         value: {
0088             return (latteView && latteView.effects && ((latteView.effects.enabledBorders & PlasmaCore.FrameSvg.BottomBorder)) > 0) || allBorders;
0089         }
0090     }
0091 
0092     Binding{
0093         target: main
0094         property: "rightBorder"
0095         when: latteView
0096         value: {
0097             return (latteView && latteView.effects && ((latteView.effects.enabledBorders & PlasmaCore.FrameSvg.RightBorder)) > 0) || allBorders;
0098         }
0099     }
0100 
0101     Loader {
0102         id: kirigamiRect
0103         anchors.fill: painter
0104         active: root.kirigamiLibraryIsFound && main.shadowSize>0
0105         //! this "source" approach is needed in order for KF5<=5.68 to load Latte correctly with no
0106         //! qml breakage because Kirigami2.ShadowedRectangle is not present
0107         source: root.kirigamiLibraryIsFound ? "KirigamiShadowedRectangle.qml" : "NormalRectangle.qml"
0108     }
0109 
0110     Rectangle{
0111         id: painter
0112         anchors.verticalCenter: parent.verticalCenter
0113         anchors.horizontalCenter: parent.horizontalCenter
0114         opacity: backgroundOpacity
0115 
0116         width: {
0117             if (plasmoid.formFactor === PlasmaCore.Types.Horizontal) {
0118                 if (drawWithoutRoundness) {
0119                     return parent.width + 2*borderWidth;
0120                 } else if (noOfBorders === 2 || (noOfBorders === 3 && bothHorizontals)) {
0121                     return parent.width + Math.max(roundness, 2*borderWidth);
0122                 } else if (noOfBorders === 3 && bothVerticals) {
0123                     return parent.width;
0124                 }
0125             } else if (plasmoid.formFactor === PlasmaCore.Types.Vertical) {
0126                 if (drawWithoutRoundness) {
0127                     return parent.width + 2 * borderWidth;
0128                 } else if ((noOfBorders === 2 && !bothVerticals) || (noOfBorders === 3 && bothHorizontals)) {
0129                     return parent.width + Math.max(roundness, 2 * borderWidth);
0130                 }
0131             }
0132 
0133             return parent.width;
0134         }
0135 
0136 
0137         height: {
0138             if (plasmoid.formFactor === PlasmaCore.Types.Horizontal) {
0139                 if (drawWithoutRoundness) {
0140                     return parent.height + 2 * borderWidth;
0141                 } else if ((noOfBorders === 2 && !bothHorizontals) || (noOfBorders === 3 && bothVerticals)) {
0142                     return parent.height + Math.max(roundness,2 * borderWidth);
0143                 }
0144             } else if (plasmoid.formFactor === PlasmaCore.Types.Vertical) {
0145                 if (drawWithoutRoundness) {
0146                     return parent.height + 2*borderWidth;
0147                 } else if (noOfBorders === 2 || (noOfBorders === 3 && bothVerticals)) {
0148                     return parent.height + Math.max(roundness, 2*borderWidth);
0149                 } else if (noOfBorders === 3 && bothHorizontals) {
0150                     return parent.height;
0151                 }
0152             }
0153 
0154             return parent.height;
0155         }
0156 
0157         radius: drawWithoutRoundness ? 0 : roundness
0158         color: main.backgroundColor
0159         border.width: main.borderWidth
0160         border.color: main.borderColor
0161 
0162         readonly property int centerStep: {
0163             if (allBorders) {
0164                 return 0;
0165             }
0166 
0167             return Math.max(Math.ceil((drawWithoutRoundness ? 0 : roundness) / 2) , borderWidth)
0168         }
0169 
0170         states: [
0171             State {
0172                 name: "horizontal"
0173                 when: (plasmoid.formFactor === PlasmaCore.Types.Horizontal)
0174 
0175                 PropertyChanges{
0176                     target: painter
0177                     anchors.horizontalCenterOffset: {
0178                         if (drawWithoutRoundness || (noOfBorders === 3 && bothVerticals)) {
0179                             return 0;
0180                         } else if (noOfBorders === 2 || (noOfBorders === 3 && bothHorizontals)) {
0181                             if (leftBorder) {
0182                                 return centerStep;
0183                             } else if (rightBorder) {
0184                                 return -centerStep;
0185                             }
0186                         }
0187 
0188                         return 0;
0189                     }
0190                     anchors.verticalCenterOffset: {
0191                         if (allBorders || (noOfBorders>=2 && bothHorizontals)) {
0192                             return 0;
0193                         }
0194 
0195                         //bottom edge and top edge
0196                         return plasmoid.location === PlasmaCore.Types.TopEdge ? -centerStep : centerStep;
0197                     }
0198                 }
0199             },
0200             State {
0201                 name: "vertical"
0202                 when: (plasmoid.formFactor === PlasmaCore.Types.Vertical)
0203 
0204                 PropertyChanges{
0205                     target: painter
0206                     anchors.verticalCenterOffset: {
0207                         if (drawWithoutRoundness || (noOfBorders === 3 && bothHorizontals)) {
0208                             return 0;
0209                         } else if (noOfBorders === 2 || (noOfBorders === 3 && bothVerticals)) {
0210                             if (bottomBorder) {
0211                                 return -centerStep;
0212                             } else if (topBorder) {
0213                                 return centerStep;
0214                             }
0215                         }
0216 
0217                         return 0;
0218                     }
0219                     anchors.horizontalCenterOffset: {
0220                         if (allBorders || (noOfBorders>=2 && bothVerticals)) {
0221                             return 0;
0222                         }
0223 
0224                         //left edge and right edge
0225                         return plasmoid.location === PlasmaCore.Types.LeftEdge ? -centerStep : centerStep;
0226                     }
0227                 }
0228             }
0229         ]
0230     }
0231 
0232 }