Warning, /plasma/latte-dock/containment/package/contents/ui/colorizer/Manager.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 import org.kde.latte.core 0.2 as LatteCore
0012 import org.kde.latte.private.app 0.1 as LatteApp
0013 import org.kde.latte.private.containment 0.1 as LatteContainment
0014 
0015 import "../../code/ColorizerTools.js" as ColorizerTools
0016 
0017 Loader{
0018     id: manager
0019 
0020     //! the loader loads the backgroundTracker component
0021     active: root.themeColors === LatteContainment.Types.SmartThemeColors
0022 
0023     readonly property bool backgroundIsBusy: item ? item.isBusy : false
0024 
0025     readonly property real originalThemeTextColorBrightness: ColorizerTools.colorBrightness(theme.textColor)
0026     readonly property color originalLightTextColor: originalThemeTextColorBrightness > 127.5 ? theme.textColor : theme.backgroundColor
0027 
0028     readonly property real themeTextColorBrightness: ColorizerTools.colorBrightness(textColor)
0029     readonly property real backgroundColorBrightness: ColorizerTools.colorBrightness(backgroundColor)
0030 
0031     readonly property color focusGlowColor: Qt.hsva(buttonFocusColor.h, buttonFocusColor.s, 1.0, 1.0)
0032 
0033     readonly property color outlineColorBase: backgroundColor
0034     readonly property real outlineColorBaseBrightness: ColorizerTools.colorBrightness(outlineColorBase)
0035     readonly property color outlineColor: {
0036         if (!root.panelOutline) {
0037             return backgroundColor;
0038         }
0039 
0040         if (outlineColorBaseBrightness > 127.5) {
0041             return Qt.darker(outlineColorBase, 1.5);
0042         } else {
0043             return Qt.lighter(outlineColorBase, 2.2);
0044         }
0045     }
0046 
0047     readonly property bool editModeTextColorIsBright: ColorizerTools.colorBrightness(editModeTextColor) > 127.5
0048     readonly property color editModeTextColor: latteView && latteView.layout ? latteView.layout.textColor : "white"
0049 
0050     readonly property bool mustBeShown: (applyTheme && applyTheme !== theme)
0051                                         || (root.inConfigureAppletsMode && (root.themeColors === LatteContainment.Types.SmartThemeColors))
0052 
0053     readonly property real currentBackgroundBrightness: item ? item.currentBrightness : -1000
0054 
0055     readonly property bool applyingWindowColors: (root.windowColors === LatteContainment.Types.ActiveWindowColors && latteView && latteView.windowsTracker
0056                                                   && selectedWindowsTracker.activeWindowScheme)
0057                                                  || (root.windowColors === LatteContainment.Types.TouchingWindowColors && latteView && latteView.windowsTracker
0058                                                      && latteView.windowsTracker.currentScreen.touchingWindowScheme)
0059 
0060     property QtObject applyTheme: {
0061         if (!root.environment.isGraphicsSystemAccelerated) {
0062             return theme;
0063         }
0064 
0065         if (latteView && latteView.windowsTracker && !(root.plasmaBackgroundForPopups && root.hasExpandedApplet)) {
0066             if (root.windowColors === LatteContainment.Types.ActiveWindowColors && selectedWindowsTracker.activeWindowScheme) {
0067                 return selectedWindowsTracker.activeWindowScheme;
0068             }
0069 
0070             if (root.windowColors === LatteContainment.Types.TouchingWindowColors && latteView.windowsTracker.currentScreen.touchingWindowScheme) {
0071                 //! we must track touching windows and when they are not ative
0072                 //! the active window scheme is used for convenience
0073                 if (latteView.windowsTracker.currentScreen.existsWindowTouching || latteView.windowsTracker.currentScreen.existsWindowTouchingEdge
0074                         && !(latteView.windowsTracker.currentScreen.activeWindowTouching || latteView.windowsTracker.currentScreen.activeWindowTouchingEdge)
0075                         && latteView.windowsTracker.currentScreen.activeWindowScheme) {
0076                     return latteView.windowsTracker.currentScreen.activeWindowScheme;
0077                 }
0078 
0079                 return latteView.windowsTracker.currentScreen.touchingWindowScheme;
0080             }
0081         }
0082 
0083         if (themeExtended) {
0084             if (root.userShowPanelBackground && root.plasmaBackgroundForPopups && root.hasExpandedApplet /*for expanded popups when it is enabled*/
0085                     || root.plasmaStyleBusyForTouchingBusyVerticalView
0086                     || (root.themeColors === LatteContainment.Types.SmartThemeColors /*for Smart theming that Windows colors are not used and the user wants solidness at some cases*/
0087                         && root.windowColors === LatteContainment.Types.NoneWindowColors
0088                         && root.forceSolidPanel) ) {
0089                 /* plasma style*/
0090                 return theme;
0091             }
0092 
0093             if (root.themeColors === LatteContainment.Types.DarkThemeColors) {
0094                 return themeExtended.darkTheme;
0095             } else if (root.themeColors === LatteContainment.Types.LightThemeColors) {
0096                 return themeExtended.lightTheme;
0097             } else if (root.themeColors === LatteContainment.Types.ReverseThemeColors) {
0098                 return themeExtended.isLightTheme ? themeExtended.darkTheme : themeExtended.lightTheme;
0099             } else if (root.themeColors === LatteContainment.Types.LayoutThemeColors && latteView && latteView.layout) {
0100                 return latteView.layout.scheme;
0101             }
0102 
0103             if (root.themeColors === LatteContainment.Types.SmartThemeColors) {
0104                 //! Smart Colors Case
0105                 if (!root.forcePanelForBusyBackground) {
0106                     //! simple case that not a busy background is applied
0107                     return currentBackgroundBrightness > 127.5 ? themeExtended.lightTheme : themeExtended.darkTheme;
0108                 } else {
0109                     //! Smart + Busy background case
0110                     var themeContrastedTextColor = currentBackgroundBrightness > 127.5 ? themeExtended.lightTheme : themeExtended.darkTheme;
0111                     var themeContrastedBackground = currentBackgroundBrightness > 127.5 ? themeExtended.darkTheme : themeExtended.lightTheme;
0112 
0113                     if (root.myView.backgroundStoredOpacity < 0.35) {
0114                         //! textColor should be better to provide the needed contrast
0115                         return themeContrastedTextColor;
0116                     } else if (root.myView.backgroundStoredOpacity >= 0.35 && root.myView.backgroundStoredOpacity <= 0.70) {
0117                         //! provide a dark case scenario at all cases
0118                         return themeExtended.darkTheme;
0119                     } else {
0120                         //! default plasma theme should be better for panel transparency > 70
0121                         return theme;
0122                     }
0123                 }
0124             }
0125         }
0126 
0127         return theme;
0128     }
0129 
0130     property color applyColor: textColor
0131 
0132     readonly property color backgroundColor:applyTheme.backgroundColor
0133     readonly property color textColor: {
0134         if (latteView && latteView.layout
0135                 && root.inConfigureAppletsMode
0136                 && LatteCore.WindowSystem.compositingActive
0137                 && root.myView.backgroundStoredOpacity<0.40
0138                 && (root.themeColors === LatteContainment.Types.SmartThemeColors)) {
0139             return latteView.layout.textColor;
0140         }
0141 
0142         return applyTheme.textColor;
0143     }
0144 
0145     readonly property color inactiveBackgroundColor: applyTheme === theme ? theme.backgroundColor : applyTheme.inactiveBackgroundColor
0146     readonly property color inactiveTextColor: applyTheme === theme ? theme.textColor : applyTheme.inactiveTextColor
0147 
0148     readonly property color highlightColor: applyTheme.highlightColor
0149     readonly property color highlightedTextColor: applyTheme.highlightedTextColor
0150     readonly property color positiveTextColor: applyTheme.positiveTextColor
0151     readonly property color neutralTextColor: applyTheme.neutralTextColor
0152     readonly property color negativeTextColor: applyTheme.negativeTextColor
0153 
0154     readonly property color buttonTextColor: applyTheme.buttonTextColor
0155     readonly property color buttonBackgroundColor: applyTheme.buttonBackgroundColor
0156     readonly property color buttonHoverColor: applyTheme.buttonHoverColor
0157     readonly property color buttonFocusColor: applyTheme.buttonFocusColor
0158 
0159     readonly property string scheme: {
0160         if (root.inConfigureAppletsMode && (root.themeColors === LatteContainment.Types.SmartThemeColors)) {
0161             if (!LatteCore.WindowSystem.compositingActive && applyTheme !== theme) {
0162                 return applyTheme.schemeFile;
0163             }
0164 
0165             //! in edit mode (that is shown the edit visual without opacity)
0166             //! take care the applets that need a proper color scheme to paint themselves
0167             if ((editModeTextColorIsBright && themeExtended.isLightTheme)
0168                     || (!editModeTextColorIsBright && !themeExtended.isLightTheme)) {
0169                 if (themeExtended.darkTheme === themeExtended.defaultTheme) {
0170                     console.log("light theme... : " + themeExtended.isLightTheme);
0171                     return themeExtended.lightTheme.schemeFile;
0172                 } else {
0173                     console.log("dark theme... : " + themeExtended.isDarkTheme);
0174                     return themeExtended.darkTheme.schemeFile;
0175                 }
0176             } else {
0177                 console.log("default theme... : " + themeExtended.isLightTheme);
0178                 return themeExtended.defaultTheme.schemeFile;
0179             }
0180         }
0181 
0182         if (applyTheme===theme || !mustBeShown) {
0183             if (themeExtended) {
0184                 return themeExtended.defaultTheme.schemeFile;
0185             } else {
0186                 return "kdeglobals";
0187             }
0188         }
0189 
0190         return applyTheme.schemeFile;
0191     }
0192 
0193     sourceComponent: LatteApp.BackgroundTracker {
0194         activity: root.myView.isReady ? root.myView.lastUsedActivity : ""
0195         location: plasmoid.location
0196         screenName: latteView && latteView.positioner ? latteView.positioner.currentScreenName : ""
0197     }
0198 }