1
0
mirror of https://github.com/KDE/latte-dock.git synced 2024-12-26 23:21:37 +03:00

move qml luminance calculations to js files

This commit is contained in:
Michail Vourlakos 2018-10-26 18:13:23 +03:00
parent 9374ff3cc4
commit 37b89f2830
4 changed files with 72 additions and 90 deletions

View File

@ -0,0 +1,33 @@
/*
* Copyright 2018 Michail Vourlakos <mvourlakos@gmail.com>
*
* This file is part of Latte-Dock
*
* Latte-Dock is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* Latte-Dock is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
function colorLuminas(color) {
return colorLuminasFromRGB(color.r, color.g, color.b)
}
// formula for luminance according to:
// https://www.w3.org/TR/2008/REC-WCAG20-20081211/#relativeluminancedef
function colorLuminasFromRGB(r, g, b) {
var rS = (r <= 0.03928) ? ( r / 12.92) : Math.pow( ((r + 0.055) / 1.055), 2.4 );
var gS = (g <= 0.03928) ? ( g / 12.92) : Math.pow( ((g + 0.055) / 1.055), 2.4 );
var bS = (b <= 0.03928) ? ( b / 12.92) : Math.pow( ((b + 0.055) / 1.055), 2.4 );
return 0.2126*rS + 0.7152*gS + 0.0722*bS;
}

View File

@ -24,6 +24,8 @@ import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.latte 0.1 as Latte
import "../../code/ColorizerTools.js" as ColorizerTools
Loader{
id: manager
@ -33,65 +35,8 @@ Loader{
|| !Latte.WindowSystem.compositingActive
readonly property bool forceSolidnessAndColorize: forceSolidness && forceColorizeFromActiveWindowScheme
// formula for luminance according to:
// https://www.w3.org/TR/2008/REC-WCAG20-20081211/#relativeluminancedef
property real textColorRs: {
var color = theme.textColor.r;
if (color <= 0.03928) {
return color / 12.92;
} else {
return Math.pow( ((color + 0.055) / 1.055), 2.4 );
}
}
property real textColorGs: {
var color = theme.textColor.g;
if (color <= 0.03928) {
return color / 12.92;
} else {
return Math.pow( ((color + 0.055) / 1.055), 2.4 );
}
}
property real textColorBs: {
var color = theme.textColor.b;
if (color <= 0.03928) {
return color / 12.92;
} else {
return Math.pow( ((color + 0.055) / 1.055), 2.4 );
}
}
//! -------
property real backColorRs: {
var color = theme.backgroundColor.r;
if (color <= 0.03928) {
return color / 12.92;
} else {
return Math.pow( ((color + 0.055) / 1.055), 2.4 );
}
}
property real backColorGs: {
var color = theme.backgroundColor.g;
if (color <= 0.03928) {
return color / 12.92;
} else {
return Math.pow( ((color + 0.055) / 1.055), 2.4 );
}
}
property real backColorBs: {
var color = theme.backgroundColor.b;
if (color <= 0.03928) {
return color / 12.92;
} else {
return Math.pow( ((color + 0.055) / 1.055), 2.4 );
}
}
readonly property real themeBackgroundColorLuma: 0.2126*backColorRs + 0.7152*backColorGs + 0.0722*backColorBs
readonly property real themeTextColorLuma: 0.2126*textColorRs + 0.7152*textColorGs + 0.0722*textColorBs
readonly property real themeBackgroundColorLuma: ColorizerTools.colorLuminas(theme.backgroundColor)
readonly property real themeTextColorLuma: ColorizerTools.colorLuminas(theme.textColor)
readonly property color minimizedDotColor: themeTextColorLuma > 0.6 ? Qt.darker(theme.textColor, 1.7) : Qt.lighter(theme.textColor, 7)
property bool mustBeShown: active && (!forceSolidPanel || forceSolidnessAndColorize)

View File

@ -0,0 +1,33 @@
/*
* Copyright 2018 Michail Vourlakos <mvourlakos@gmail.com>
*
* This file is part of Latte-Dock
*
* Latte-Dock is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* Latte-Dock is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
function colorLuminas(color) {
return colorLuminasFromRGB(color.r, color.g, color.b)
}
// formula for luminance according to:
// https://www.w3.org/TR/2008/REC-WCAG20-20081211/#relativeluminancedef
function colorLuminasFromRGB(r, g, b) {
var rS = (r <= 0.03928) ? ( r / 12.92) : Math.pow( ((r + 0.055) / 1.055), 2.4 );
var gS = (g <= 0.03928) ? ( g / 12.92) : Math.pow( ((g + 0.055) / 1.055), 2.4 );
var bS = (b <= 0.03928) ? ( b / 12.92) : Math.pow( ((b + 0.055) / 1.055), 2.4 );
return 0.2126*rS + 0.7152*gS + 0.0722*bS;
}

View File

@ -36,6 +36,7 @@ import org.kde.latte 0.1 as Latte
import "task" as Task
import "../code/tools.js" as TaskTools
import "../code/activitiesTools.js" as ActivitiesTools
import "../code/ColorizerTools.js" as ColorizerTools
Item {
id:root
@ -93,37 +94,7 @@ Item {
property int widthMargins: root.vertical ? thickMargin : iconMargin
property int heightMargins: !root.vertical ? thickMargin : iconMargin
// formula for luminance according to:
// https://www.w3.org/TR/2008/REC-WCAG20-20081211/#relativeluminancedef
property real textColorRs: {
var color = theme.textColor.r;
if (color <= 0.03928) {
return color / 12.92;
} else {
return Math.pow( ((color + 0.055) / 1.055), 2.4 );
}
}
property real textColorGs: {
var color = theme.textColor.g;
if (color <= 0.03928) {
return color / 12.92;
} else {
return Math.pow( ((color + 0.055) / 1.055), 2.4 );
}
}
property real textColorBs: {
var color = theme.textColor.b;
if (color <= 0.03928) {
return color / 12.92;
} else {
return Math.pow( ((color + 0.055) / 1.055), 2.4 );
}
}
property real textColorLuma: 0.2126*textColorRs + 0.7152*textColorGs + 0.0722*textColorBs
property real textColorLuma: ColorizerTools.colorLuminas(theme.textColor)
property color minimizedDotColor: {
if (latteDock) {
return latteDock.minimizedDotColor;