[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: kdelibs/kdecore
From: Stephan Binner <binner () kde ! org>
Date: 2005-01-17 10:53:11
Message-ID: 20050117105311.0AE481CF99 () office ! kde ! org
[Download RAW message or body]
CVS commit by binner:
+ static bool hasSufficientContrast(const QColor &c1, const QColor &c2);
M +28 -0 kapplication.cpp 1.698
M +8 -2 kapplication.h 1.323
--- kdelibs/kdecore/kapplication.cpp #1.697:1.698
@@ -2857,4 +2857,32 @@ QString KApplication::randomString(int l
}
+bool KApplication::hasSufficientContrast(const QColor &c1, const QColor &c2)
+{
+ // Taken from khtml/misc/helper.cc
+#define HUE_DISTANCE 40
+#define CONTRAST_DISTANCE 10
+
+ int h1, s1, v1, h2, s2, v2;
+ int hdist = -CONTRAST_DISTANCE;
+ c1.hsv(&h1,&s1,&v1);
+ c2.hsv(&h2,&s2,&v2);
+ if(h1!=-1 && h2!=-1) { // grey values have no hue
+ hdist = kAbs(h1-h2);
+ if (hdist > 180) hdist = 360-hdist;
+ if (hdist < HUE_DISTANCE) {
+ hdist -= HUE_DISTANCE;
+ // see if they are high key or low key colours
+ bool hk1 = h1>=45 && h1<=225;
+ bool hk2 = h2>=45 && h2<=225;
+ if (hk1 && hk2)
+ hdist = (5*hdist)/3;
+ else if (!hk1 && !hk2)
+ hdist = (7*hdist)/4;
+ }
+ hdist = kMin(hdist, HUE_DISTANCE*2);
+ }
+ return hdist + (kAbs(s1-s2)*128)/(160+kMin(s1,s2)) + kAbs(v1-v2) > CONTRAST_DISTANCE;
+}
+
bool KApplication::authorize(const QString &genericAction)
{
--- kdelibs/kdecore/kapplication.h #1.322:1.323
@@ -1073,4 +1073,10 @@ public:
static uint mouseState() KDE_DEPRECATED;
+ /**
+ * Checks whether the given colors have enough contrast
+ * @returns true if contrast is ok
+ * @since 3.4
+ */
+ static bool hasSufficientContrast(const QColor &c1, const QColor &c2);
public slots:
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic