plasma5-addons/0001-Color-Picker-Add-border-around-color-if-contrast-to-.patch
Fabian Vogt 1b80c461d7 - Add upstream patches from master to improve appearance of color picker:
* 0001-Color-Picker-Add-border-around-color-if-contrast-to-.patch
  * 0002-Color-Picker-Add-contrast-frame-around-colors-in-pop.patch

OBS-URL: https://build.opensuse.org/package/show/KDE:Frameworks5/plasma5-addons?expand=0&rev=127
2017-01-28 10:47:37 +00:00

58 lines
2.4 KiB
Diff

From ef3fd95a32572c20b8e8e407b45726be4a95bcfd Mon Sep 17 00:00:00 2001
From: Kai Uwe Broulik <kde@privat.broulik.de>
Date: Thu, 26 Jan 2017 16:21:09 +0100
Subject: [PATCH 1/2] [Color Picker] Add border around color if contrast to
surrounding view is too little
When picking a light color on a light panel, it might not be obvious that the color is shown there.
Add a border around the picked color if contrast is too little.
Differential Revision: https://phabricator.kde.org/D4224
---
applets/colorpicker/package/contents/ui/main.qml | 29 ++++++++++++++++++++++++
1 file changed, 29 insertions(+)
diff --git a/applets/colorpicker/package/contents/ui/main.qml b/applets/colorpicker/package/contents/ui/main.qml
index b45d00486..845391cd8 100644
--- a/applets/colorpicker/package/contents/ui/main.qml
+++ b/applets/colorpicker/package/contents/ui/main.qml
@@ -189,6 +189,35 @@ Item {
height: units.roundToIconSize(pickerIcon.height) * 0.75
radius: width / 2
color: root.recentColor
+
+ function luminance(color) {
+ if (!color) {
+ return 0;
+ }
+
+ // formula for luminance according to https://www.w3.org/TR/2008/REC-WCAG20-20081211/#relativeluminancedef
+
+ var a = [color.r, color.g, color.b].map(function (v) {
+ return (v <= 0.03928) ? v / 12.92 :
+ Math.pow( ((v + 0.055) / 1.055), 2.4 );
+ });
+
+ return a[0] * 0.2126 + a[1] * 0.7152 + a[2] * 0.0722;
+ }
+
+ border {
+ color: theme.textColor
+ width: {
+ var contrast = luminance(theme.viewBackgroundColor) / luminance(colorCircle.color) + 0.05;
+
+ // show border only if there's too little contrast to the surrounding view
+ if (contrast > 3) {
+ return 0;
+ } else {
+ return Math.round(Math.max(units.devicePixelRatio, width / 20));
+ }
+ }
+ }
}
}
}
--
2.11.0