text selection consistency

Leo Savernik l.savernik at aon.at
Sun Sep 28 16:04:51 BST 2003


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Am Samstag, 27. September 2003 01:39 schrieb David Faure:
> On Saturday 27 September 2003 01:34, Max Howell wrote:
[...]
>
> A generic method that detects if two colors are too close to be
> distinguishable would be useful in many contexts - e.g. when determining
> the selection color in KWord (it defaults to the KDE selection color, but
> if the frame's background color has that color too, then it'll be hard to
> see).

Before I wrote my own I looked into kdefx, but found nothing useful. So my own 
solution determines low contrast by all rgb components of two colors having a 
delta below an arbitrary threshold. See here:

inline bool hasSufficientContrast(const QColor &c1, const QColor &c2)
{
// ### arbitrary value, to be adapted if necessary (LS)
#define CONTRAST_DISTANCE 5

  if (QABS(c1.red() - c2.red()) > CONTRAST_DISTANCE) return true;
  if (QABS(c1.green() - c2.green()) > CONTRAST_DISTANCE) return true;
  if (QABS(c1.blue() - c2.blue()) > CONTRAST_DISTANCE) return true;

  return false;

#undef CONTRAST_DISTANCE
}

It's very primitive, and I don't know if it's "right", but I needed a very 
fast solution, and it works for all the cases I tested.

mfg
	Leo
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE/dviUj5jssenUYTsRAvbJAJ99Y1AIem4MxY2Ju2n79l9k1MWJ5gCgk2pQ
jChqproYqU7oGIxGuHpXv5E=
=UmyI
-----END PGP SIGNATURE-----





More information about the kfm-devel mailing list