| 3479 | } |
| 3480 | |
| 3481 | QColor contrastingColor(const QColor &col, const QColor &defaultCol) |
| 3482 | { |
| 3483 | float backLum = getLuminance(col); |
| 3484 | float textLum = getLuminance(defaultCol); |
| 3485 | |
| 3486 | bool backDark = backLum < 0.2f; |
| 3487 | bool textDark = textLum < 0.2f; |
| 3488 | |
| 3489 | // if they're contrasting, use the text colour desired |
| 3490 | if(backDark != textDark) |
| 3491 | return defaultCol; |
| 3492 | |
| 3493 | // otherwise pick a contrasting colour |
| 3494 | if(backDark) |
| 3495 | return QColor(Qt::white); |
| 3496 | else |
| 3497 | return QColor(Qt::black); |
| 3498 | } |
| 3499 | |
| 3500 | // we declare this partial class to get the accessors. THIS IS DANGEROUS as the ABI is unstable and |
| 3501 | // this is a private class. The first few functions have been stable for a while so we hope that it |