Warning, /plasma/latte-dock/indicators/default/package/ui/main.qml is written in an unsupported language. File is not indexed.

0001 /*
0002     SPDX-FileCopyrightText: 2019 Michail Vourlakos <mvourlakos@gmail.com>
0003     SPDX-License-Identifier: GPL-2.0-or-later
0004 */
0005 
0006 import QtQuick 2.0
0007 import QtQuick.Layouts 1.1
0008 import QtGraphicalEffects 1.0
0009 
0010 import org.kde.plasma.plasmoid 2.0
0011 import org.kde.plasma.core 2.0 as PlasmaCore
0012 import org.kde.plasma.components 2.0 as PlasmaComponents
0013 
0014 import org.kde.latte.core 0.2 as LatteCore
0015 import org.kde.latte.components 1.0 as LatteComponents
0016 
0017 LatteComponents.IndicatorItem{
0018     id: root
0019     extraMaskThickness: reversedEnabled && glowEnabled ? 1.7 * (factor * indicator.maxIconSize) : 0
0020 
0021     enabledForApplets: indicator && indicator.configuration ? indicator.configuration.enabledForApplets : true
0022     lengthPadding: indicator && indicator.configuration ? indicator.configuration.lengthPadding : 0.08
0023     backgroundCornerMargin: indicator && indicator.configuration ? indicator.configuration.backgroundCornerMargin : 1.00
0024 
0025     readonly property real factor: indicator.configuration.size
0026     readonly property int size: factor * indicator.currentIconSize
0027     readonly property int thickLocalMargin: indicator.configuration.thickMargin * indicator.currentIconSize
0028 
0029     readonly property int screenEdgeMargin: plasmoid.location === PlasmaCore.Types.Floating || reversedEnabled ? 0 : indicator.screenEdgeMargin
0030 
0031     readonly property int thicknessMargin: screenEdgeMargin + thickLocalMargin + (glowEnabled ? 1 : 0)
0032 
0033     property real textColorBrightness: colorBrightness(indicator.palette.textColor)
0034 
0035     property color isActiveColor: indicator.palette.buttonFocusColor
0036     property color minimizedColor: {
0037         if (minimizedTaskColoredDifferently) {
0038             return (textColorBrightness > 127.5 ? Qt.darker(indicator.palette.textColor, 1.7) : Qt.lighter(indicator.palette.textColor, 7));
0039         }
0040 
0041         return isActiveColor;
0042     }
0043 
0044     property color notActiveColor: indicator.isMinimized ? minimizedColor : isActiveColor
0045 
0046     //! Common Options
0047     readonly property bool reversedEnabled: indicator.configuration.reversed
0048 
0049     //! Configuration Options
0050     readonly property bool extraDotOnActive: indicator.configuration.extraDotOnActive
0051     readonly property bool minimizedTaskColoredDifferently: indicator.configuration.minimizedTaskColoredDifferently
0052     readonly property int activeStyle: indicator.configuration.activeStyle
0053     //!glow options
0054     readonly property bool glowEnabled: indicator.configuration.glowEnabled
0055     readonly property bool glow3D: indicator.configuration.glow3D
0056     readonly property int glowApplyTo: indicator.configuration.glowApplyTo
0057     readonly property real glowOpacity: indicator.configuration.glowOpacity
0058     readonly property int glowMargins: glowEnabled ? 12 : 0
0059 
0060     /*Rectangle{
0061         anchors.fill: parent
0062         border.width: 1
0063         border.color: "blue"
0064         color: "transparent"
0065     }*/
0066 
0067     function colorBrightness(color) {
0068         return colorBrightnessFromRGB(color.r * 255, color.g * 255, color.b * 255);
0069     }
0070 
0071     // formula for brightness according to:
0072     // https://www.w3.org/TR/AERT/#color-contrast
0073     function colorBrightnessFromRGB(r, g, b) {
0074         return (r * 299 + g * 587 + b * 114) / 1000
0075     }
0076 
0077     Grid{
0078         id: grid
0079         columns: plasmoid.formFactor === PlasmaCore.Types.Vertical ? 1 : 0
0080         rows: plasmoid.formFactor !== PlasmaCore.Types.Vertical ? 1 : 0
0081         columnSpacing: 0
0082         rowSpacing: 0
0083 
0084         LatteComponents.GlowPoint{
0085             id:firstPoint
0086             width: stateWidth
0087             height: stateHeight
0088             opacity: {
0089                 if (indicator.isEmptySpace) {
0090                     return 0;
0091                 }
0092 
0093                 if (indicator.isTask) {
0094                     return indicator.isLauncher || (indicator.inRemoving && !isAnimating) ? 0 : 1
0095                 }
0096 
0097                 if (indicator.isApplet) {
0098                     return (indicator.isActive || isAnimating) ? 1 : 0
0099                 }
0100             }
0101 
0102             basicColor: indicator.isActive || (indicator.isGroup && indicator.hasShown) ? root.isActiveColor : root.notActiveColor
0103 
0104             size: root.size
0105             glow3D: glow3D
0106             animation: Math.max(1.65*3*LatteCore.Environment.longDuration,indicator.durationTime*3*LatteCore.Environment.longDuration)
0107             location: plasmoid.location
0108             glowOpacity: root.glowOpacity
0109             contrastColor: indicator.shadowColor
0110             attentionColor: indicator.palette.negativeTextColor
0111 
0112             roundCorners: true
0113             showAttention: indicator.inAttention
0114             showGlow: {
0115                 if (glowEnabled && (glowApplyTo === 2 /*All*/ || showAttention ))
0116                     return true;
0117                 else if (glowEnabled && glowApplyTo === 1 /*OnActive*/ && indicator.hasActive)
0118                     return true;
0119                 else
0120                     return false;
0121             }
0122             showBorder: glow3D
0123 
0124             property int stateWidth: {
0125                 if (!vertical && isActive && activeStyle === 0 /*Line*/) {
0126                     return (indicator.isGroup ? root.width - secondPoint.width : root.width - spacer.width) - glowMargins;
0127                 }
0128 
0129                 return root.size;
0130             }
0131 
0132             property int stateHeight: {
0133                 if (vertical && isActive && activeStyle === 0 /*Line*/) {
0134                     return (indicator.isGroup ? root.height - secondPoint.height : root.height - spacer.height) - glowMargins;
0135                 }
0136 
0137                 return root.size;
0138             }
0139 
0140             property int animationTime: indicator.durationTime* (0.75*LatteCore.Environment.longDuration)
0141 
0142             property bool isActive: indicator.hasActive || indicator.isActive
0143 
0144             property bool vertical: plasmoid.formFactor === PlasmaCore.Types.Vertical
0145 
0146             property real scaleFactor: indicator.scaleFactor
0147 
0148             readonly property bool isAnimating: inGrowAnimation || inShrinkAnimation
0149             property bool inGrowAnimation: false
0150             property bool inShrinkAnimation: false
0151 
0152             property bool isBindingBlocked: isAnimating
0153 
0154             readonly property bool isActiveStateForAnimation: indicator.isActive && root.activeStyle === 0 /*Line*/
0155 
0156             onIsActiveStateForAnimationChanged: {
0157                 if (root.activeStyle === 0 /*Line*/) {
0158                     if (isActiveStateForAnimation) {
0159                         inGrowAnimation = true;
0160                         inShrinkAnimation = false;
0161                     } else {
0162                         inGrowAnimation = false;
0163                         inShrinkAnimation = true;
0164                     }
0165                 } else {
0166                     inGrowAnimation = false;
0167                     inShrinkAnimation = false;
0168                 }
0169             }
0170 
0171             onWidthChanged: {
0172                 if (!vertical) {
0173                     if (inGrowAnimation && width >= stateWidth) {
0174                         inGrowAnimation = false;
0175                     } else if (inShrinkAnimation && width <= stateWidth) {
0176                         inShrinkAnimation = false;
0177                     }
0178                 }
0179             }
0180 
0181             onHeightChanged: {
0182                 if (vertical) {
0183                     if (inGrowAnimation && height >= stateHeight) {
0184                         inGrowAnimation = false;
0185                     } else if (inShrinkAnimation && height <= stateHeight) {
0186                         inShrinkAnimation = false;
0187                     }
0188                 }
0189             }
0190 
0191             Behavior on width {
0192                 enabled: (!firstPoint.vertical && (firstPoint.isAnimating || firstPoint.opacity === 0/*first showing requirement*/))
0193                 NumberAnimation {
0194                     duration: firstPoint.animationTime
0195                     easing.type: Easing.Linear
0196                 }
0197             }
0198 
0199             Behavior on height {
0200                 enabled: (firstPoint.vertical && (firstPoint.isAnimating || firstPoint.opacity === 0/*first showing requirement*/))
0201                 NumberAnimation {
0202                     duration: firstPoint.animationTime
0203                     easing.type: Easing.Linear
0204                 }
0205             }
0206         }
0207 
0208         Item{
0209             id:spacer
0210             width: secondPoint.visible ? 0.5*root.size : 0
0211             height: secondPoint.visible ? 0.5*root.size : 0
0212         }
0213 
0214         LatteComponents.GlowPoint{
0215             id:secondPoint
0216             width: visible ? root.size : 0
0217             height: width
0218 
0219             size: root.size
0220             glow3D: glow3D
0221             animation: Math.max(1.65*3*LatteCore.Environment.longDuration,indicator.durationTime*3*LatteCore.Environment.longDuration)
0222             location: plasmoid.location
0223             glowOpacity: root.glowOpacity
0224             contrastColor: indicator.shadowColor
0225             showBorder: glow3D
0226 
0227             basicColor: state2Color
0228             roundCorners: true
0229             showGlow: glowEnabled  && glowApplyTo === 2 /*All*/
0230             visible:  ( indicator.isGroup && ((extraDotOnActive && activeStyle === 0) /*Line*/
0231                                               || activeStyle === 1 /*Dot*/
0232                                               || !indicator.hasActive) ) ? true: false
0233 
0234             //when there is no active window
0235             property color state1Color: indicator.hasShown ? root.isActiveColor : root.minimizedColor
0236             //when there is active window
0237             property color state2Color: indicator.hasMinimized ? root.minimizedColor : root.isActiveColor
0238         }
0239     }
0240 
0241     states: [
0242         State {
0243             name: "left"
0244             when: ((plasmoid.location === PlasmaCore.Types.LeftEdge && !reversedEnabled) ||
0245                    (plasmoid.location === PlasmaCore.Types.RightEdge && reversedEnabled))
0246 
0247             AnchorChanges {
0248                 target: grid
0249                 anchors{ verticalCenter:parent.verticalCenter; horizontalCenter:undefined;
0250                     top:undefined; bottom:undefined; left:parent.left; right:undefined;}
0251             }
0252             PropertyChanges{
0253                 target: grid
0254                 anchors.leftMargin: root.thicknessMargin;    anchors.rightMargin: 0;     anchors.topMargin:0;    anchors.bottomMargin:0;
0255                 anchors.horizontalCenterOffset: 0; anchors.verticalCenterOffset: 0;
0256             }
0257         },
0258         State {
0259             name: "bottom"
0260             when: (plasmoid.location === PlasmaCore.Types.Floating ||
0261                    (plasmoid.location === PlasmaCore.Types.BottomEdge && !reversedEnabled) ||
0262                    (plasmoid.location === PlasmaCore.Types.TopEdge && reversedEnabled))
0263 
0264             AnchorChanges {
0265                 target: grid
0266                 anchors{ verticalCenter:undefined; horizontalCenter:parent.horizontalCenter;
0267                     top:undefined; bottom:parent.bottom; left:undefined; right:undefined;}
0268             }
0269             PropertyChanges{
0270                 target: grid
0271                 anchors.leftMargin: 0;    anchors.rightMargin: 0;     anchors.topMargin:0;    anchors.bottomMargin: root.thicknessMargin;
0272                 anchors.horizontalCenterOffset: 0; anchors.verticalCenterOffset: 0;
0273             }
0274         },
0275         State {
0276             name: "top"
0277             when: ((plasmoid.location === PlasmaCore.Types.TopEdge && !reversedEnabled) ||
0278                    (plasmoid.location === PlasmaCore.Types.BottomEdge && reversedEnabled))
0279 
0280             AnchorChanges {
0281                 target: grid
0282                 anchors{ verticalCenter:undefined; horizontalCenter:parent.horizontalCenter;
0283                     top:parent.top; bottom:undefined; left:undefined; right:undefined;}
0284             }
0285             PropertyChanges{
0286                 target: grid
0287                 anchors.leftMargin: 0;    anchors.rightMargin: 0;     anchors.topMargin: root.thicknessMargin;    anchors.bottomMargin:0;
0288                 anchors.horizontalCenterOffset: 0; anchors.verticalCenterOffset: 0;
0289             }
0290         },
0291         State {
0292             name: "right"
0293             when: ((plasmoid.location === PlasmaCore.Types.RightEdge && !reversedEnabled) ||
0294                    (plasmoid.location === PlasmaCore.Types.LeftEdge && reversedEnabled))
0295 
0296             AnchorChanges {
0297                 target: grid
0298                 anchors{ verticalCenter:parent.verticalCenter; horizontalCenter:undefined;
0299                     top:undefined; bottom:undefined; left:undefined; right:parent.right;}
0300             }
0301             PropertyChanges{
0302                 target: grid
0303                 anchors.leftMargin: 0;    anchors.rightMargin: root.thicknessMargin;     anchors.topMargin:0;    anchors.bottomMargin:0;
0304                 anchors.horizontalCenterOffset: 0; anchors.verticalCenterOffset: 0;
0305             }
0306         }
0307     ]
0308 }// number of windows indicator
0309