Warning, /plasma/latte-dock/containment/package/contents/ui/colorizer/CustomBackground.qml is written in an unsupported language. File is not indexed.
0001 /*
0002 * Copyright 2018 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.7
0021
0022 import org.kde.plasma.plasmoid 2.0
0023 import org.kde.plasma.core 2.0 as PlasmaCore
0024
0025 import org.kde.latte 0.2 as Latte
0026
0027 Item{
0028 id: main
0029 anchors.fill: parent
0030 clip: true
0031
0032 property int roundness: 0
0033 property color backgroundColor
0034 property color borderColor: "transparent"
0035 property int borderWidth: 0
0036
0037 property bool topBorder: false
0038 property bool leftBorder: false
0039 property bool bottomBorder: false
0040 property bool rightBorder: false
0041
0042 property int noOfBorders: {
0043 var i = 0;
0044
0045 if (topBorder) {
0046 i = i + 1;
0047 }
0048 if (leftBorder) {
0049 i = i + 1;
0050 }
0051 if (rightBorder) {
0052 i = i + 1;
0053 }
0054 if (bottomBorder) {
0055 i = i + 1;
0056 }
0057
0058 return i;
0059 }
0060
0061 readonly property bool drawWithoutRoundness: noOfBorders === 1
0062
0063 Binding{
0064 target: main
0065 property: "topBorder"
0066 when: latteView
0067 value: {
0068 return ((latteView && latteView.effects && (latteView.effects.enabledBorders & PlasmaCore.FrameSvg.TopBorder)) > 0);
0069 }
0070 }
0071
0072 Binding{
0073 target: main
0074 property: "leftBorder"
0075 when: latteView
0076 value: {
0077 return ((latteView && latteView.effects && (latteView.effects.enabledBorders & PlasmaCore.FrameSvg.LeftBorder)) > 0);
0078 }
0079 }
0080
0081 Binding{
0082 target: main
0083 property: "bottomBorder"
0084 when: latteView
0085 value: {
0086 return ((latteView && latteView.effects && (latteView.effects.enabledBorders & PlasmaCore.FrameSvg.BottomBorder)) > 0);
0087 }
0088 }
0089
0090 Binding{
0091 target: main
0092 property: "rightBorder"
0093 when: latteView
0094 value: {
0095 return ((latteView && latteView.effects && (latteView.effects.enabledBorders & PlasmaCore.FrameSvg.RightBorder)) > 0);
0096 }
0097 }
0098
0099 Rectangle{
0100 id: painter
0101 anchors.verticalCenter: parent.verticalCenter
0102 anchors.horizontalCenter: parent.horizontalCenter
0103
0104 width: {
0105 if (plasmoid.formFactor === PlasmaCore.Types.Horizontal) {
0106 if (drawWithoutRoundness) {
0107 return parent.width + 2*borderWidth;
0108 } else if (noOfBorders === 2) {
0109 return parent.width + Math.max(roundness, 2*borderWidth);
0110 } else if (noOfBorders === 3) {
0111 return parent.width;
0112 }
0113 } else if (plasmoid.formFactor === PlasmaCore.Types.Vertical) {
0114 if (drawWithoutRoundness) {
0115 return parent.width + 2 * borderWidth;
0116 } else if (noOfBorders === 2 || noOfBorders === 3) {
0117 return parent.width + Math.max(roundness, 2 * borderWidth);
0118 }
0119 }
0120 }
0121
0122
0123 height: {
0124 if (plasmoid.formFactor === PlasmaCore.Types.Horizontal) {
0125 if (drawWithoutRoundness) {
0126 return parent.height + 2 * borderWidth;
0127 } else if (noOfBorders === 2 || noOfBorders === 3) {
0128 return parent.height + Math.max(roundness,2 * borderWidth);
0129 }
0130 } else if (plasmoid.formFactor === PlasmaCore.Types.Vertical) {
0131 if (drawWithoutRoundness) {
0132 return parent.height + 2*borderWidth;
0133 } else if (noOfBorders === 2) {
0134 return parent.height + Math.max(roundness, 2*borderWidth);
0135 } else if (noOfBorders === 3) {
0136 return parent.height;
0137 }
0138 }
0139 }
0140
0141 radius: drawWithoutRoundness ? 0 : roundness
0142 color: parent.backgroundColor
0143 border.width: main.borderWidth
0144 border.color: main.borderColor
0145
0146 readonly property int centerStep: Math.max(Math.ceil((drawWithoutRoundness ? 0 : roundness) / 2) , borderWidth)
0147
0148 states: [
0149 State {
0150 name: "horizontal"
0151 when: (plasmoid.formFactor === PlasmaCore.Types.Horizontal)
0152
0153 PropertyChanges{
0154 target: painter
0155 anchors.horizontalCenterOffset: {
0156 if (drawWithoutRoundness || noOfBorders === 3) {
0157 return 0;
0158 } else if (noOfBorders === 2) {
0159 if (leftBorder) {
0160 return centerStep;
0161 } else if (rightBorder) {
0162 return -centerStep;
0163 }
0164 }
0165
0166 return 0;
0167 }
0168 anchors.verticalCenterOffset: {
0169 //bottom edge and top edge
0170 return plasmoid.location === PlasmaCore.Types.TopEdge ? -centerStep : centerStep;
0171 }
0172 }
0173 },
0174 State {
0175 name: "vertical"
0176 when: (plasmoid.formFactor === PlasmaCore.Types.Vertical)
0177
0178 PropertyChanges{
0179 target: painter
0180 anchors.verticalCenterOffset: {
0181 if (drawWithoutRoundness || noOfBorders === 3) {
0182 return 0;
0183 } else if (noOfBorders === 2) {
0184 if (bottomBorder) {
0185 return -centerStep;
0186 } else if (topBorder) {
0187 return centerStep;
0188 }
0189 }
0190
0191 return 0;
0192 }
0193 anchors.horizontalCenterOffset: {
0194 //left edge and right edge
0195 return plasmoid.location === PlasmaCore.Types.LeftEdge ? -centerStep : centerStep;
0196 }
0197 }
0198 }
0199 ]
0200 }
0201
0202 }