Warning, /plasma/latte-dock/containment/package/contents/ui/abilities/privates/MetricsPrivate.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 import org.kde.plasma.plasmoid 2.0
0008 
0009 import org.kde.latte.core 0.2 as LatteCore
0010 import org.kde.latte.abilities.host 0.1 as AbilityHost
0011 
0012 import "./metrics" as MetricsPrivateTypes
0013 
0014 AbilityHost.Metrics {
0015     id: mets
0016     property Item animations: null
0017     property Item autosize: null
0018     property Item background: null
0019     property Item indicators: null
0020     property Item parabolic: null
0021 
0022     //! private properties to avoid too many not needed animation calculations
0023     readonly property int _iconSize: autosizeEnabled && autosize.iconSize > 0 ? Math.min(autosize.iconSize, maxIconSize) : maxIconSize
0024     readonly property int _maxIconSize: {
0025         //! round to nearest odd number
0026         var storedIconSize = 2 * Math.round(plasmoid.configuration.iconSize / 2)
0027 
0028         return portionIconSize!==-1 ? portionIconSize : storedIconSize;
0029     }
0030 
0031     //! Private Properties
0032     readonly property int portionIconSize: { //icon size based on screen height
0033         if ((plasmoid.configuration.proportionIconSize===-1) || !latteView)
0034             return -1;
0035 
0036         var basedOnScreenHeight = Math.max(16,Math.round(latteView.screenGeometry.height * plasmoid.configuration.proportionIconSize/100))
0037 
0038         //! round to nearest odd number
0039         return 2 * Math.round(basedOnScreenHeight/2);
0040     }
0041 
0042     readonly property bool autosizeEnabled: autosize !== undefined && autosize.isActive
0043 
0044     readonly property MetricsPrivateTypes.Fraction fraction: MetricsPrivateTypes.Fraction{
0045         thicknessMargin: Math.max(indicators.info.minThicknessPadding, plasmoid.configuration.thickMargin / 100)
0046         lengthMargin: plasmoid.configuration.lengthExtMargin / 100
0047         lengthPadding: indicators.isEnabled ? indicators.padding : 0
0048         lengthAppletPadding: indicators.isEnabled ? indicators.info.appletLengthPadding : -1
0049     }
0050 
0051     //! based on background / plasma theme minimum thickness requirements; behaveAsPlasmaPanel and floating is a good scenario for this
0052     readonly property int marginMinThickness: Math.max(0, (background.totals.minThickness - _maxIconSize) / 2)
0053 
0054     readonly property int maxThicknessForView: Math.max(mask.maxScreenEdge + ((maxIconSize+2*margin.maxTailThickness)*2) + extraThicknessForZoomed,
0055                                                         384)
0056 
0057     //! Thickness Private Calculations
0058 
0059     readonly property int marginBetweenContentsAndEditRuler: 10
0060     readonly property int extraThicknessForNormal: Math.max(extraThicknessFromIndicators, extraThicknessFromShadows)
0061     readonly property int extraThicknessForZoomed: marginBetweenContentsAndEditRuler + extraThicknessForNormal
0062 
0063     readonly property int extraThicknessFromShadows: {
0064         if (LatteCore.WindowSystem.isPlatformWayland) {
0065             return 0;
0066         }
0067 
0068         //! 45% of max shadow size in px.
0069         var shadowMaxNeededMargin = 0.45 * root.myView.itemShadow.maxSize;
0070         var shadowOpacity = (plasmoid.configuration.shadowOpacity) / 100;
0071         //! +40% of shadow opacity in percentage
0072         shadowOpacity = shadowOpacity + shadowOpacity*0.4;
0073 
0074         //! This way we are trying to calculate how many pixels are needed in order for the shadow
0075         //! to be drawn correctly without being cut of from View::mask() under X11
0076         shadowMaxNeededMargin = (shadowMaxNeededMargin * shadowOpacity);
0077 
0078         //! give some more space when items shadows are enabled and extremely big
0079         if (root.myView.itemShadow.isEnabled && metrics.margin.maxHeadThickness < shadowMaxNeededMargin) {
0080             return shadowMaxNeededMargin - metrics.margin.maxHeadThickness;
0081         }
0082 
0083         return 0;
0084     }
0085 
0086     readonly property int extraThicknessFromIndicators: indicators.info.extraMaskThickness
0087 
0088     readonly property real mediumFactor: (1 + (0.65 * (parabolic.factor.maxZoom-1)))
0089     readonly property real mediumMarginsFactor: 1 + ((mediumFactor-1) * parabolic.factor.marginThicknessZoomInPercentage)
0090     readonly property real maxMarginsFactor: 1 + ((parabolic.factor.maxZoom-1) * parabolic.factor.marginThicknessZoomInPercentage)
0091 
0092     //! BEHAVIORS
0093     Behavior on iconSize {
0094         NumberAnimation {
0095             duration: 0.8 * animations.duration.proposed
0096 
0097             onRunningChanged: {
0098                 if (!running) {
0099                     mets.iconSizeAnimationEnded();
0100                 }
0101             }
0102         }
0103     }
0104 
0105     margin {
0106         Behavior on length {
0107             NumberAnimation {
0108                 duration: 0.8 * animations.duration.proposed
0109                 easing.type: Easing.OutCubic
0110             }
0111         }
0112 
0113         Behavior on screenEdge {
0114             enabled: !root.behaveAsPlasmaPanel
0115             NumberAnimation {
0116                 duration: 0.8 * animations.duration.proposed
0117                 easing.type: Easing.OutCubic
0118             }
0119         }
0120 
0121         Behavior on tailThickness {
0122             NumberAnimation {
0123                 duration: 0.8 * animations.duration.proposed
0124                 easing.type: Easing.OutCubic
0125             }
0126         }
0127 
0128         Behavior on headThickness {
0129             NumberAnimation {
0130                 duration: 0.8 * animations.duration.proposed
0131                 easing.type: Easing.OutCubic
0132             }
0133         }
0134     }
0135 
0136     padding {
0137         Behavior on length {
0138             NumberAnimation {
0139                 duration: 0.8 * animations.duration.proposed
0140                 easing.type: Easing.OutCubic
0141             }
0142         }
0143     }
0144 }