diff options
| author | Mikaël Capelle <capelle.mikael@gmail.com> | 2021-01-08 17:41:10 +0100 |
|---|---|---|
| committer | Mikaël Capelle <capelle.mikael@gmail.com> | 2021-01-10 10:27:30 +0100 |
| commit | 7b684f4d15fa8f75fe802f9dd1534cf4ee2c25ea (patch) | |
| tree | 71a56125c5ccab03c34c6b95f0e208f8f56d95fc /src | |
| parent | d923730452e129260dc08a2a909c897eb9475ce7 (diff) | |
Tentative fix for automatic text color when markers or separator colors are used.
Diffstat (limited to 'src')
| -rw-r--r-- | src/modlistview.cpp | 21 | ||||
| -rw-r--r-- | src/settings.cpp | 8 |
2 files changed, 20 insertions, 9 deletions
diff --git a/src/modlistview.cpp b/src/modlistview.cpp index 53070d08..6b5ae66b 100644 --- a/src/modlistview.cpp +++ b/src/modlistview.cpp @@ -82,18 +82,29 @@ public: if (!color.isValid()) {
color = index.data(Qt::BackgroundRole).value<QColor>();
}
- else {
- // disable alternating row if the color is from the children
- opt.features &= ~QStyleOptionViewItem::Alternate;
- }
opt.backgroundBrush = color;
+ // we need to find the background color to compute the ideal text color
+ // but the mod list view uses alternate color so we need to find the
+ // right color
+ auto bg = opt.palette.base().color();
+ auto vrow = (opt.rect.y() - m_view->verticalOffset()) / opt.rect.height();
+ if (vrow % 2 == 1) {
+ bg = opt.palette.alternateBase().color();
+ }
+
// compute ideal foreground color for some rows
if (color.isValid()) {
if ((index.column() == ModList::COL_NAME
&& ModInfo::getByIndex(index.data(ModList::IndexRole).toInt())->isSeparator())
|| index.column() == ModList::COL_NOTES) {
- opt.palette.setBrush(QPalette::Text, ColorSettings::idealTextColor(color));
+
+ // combine the color with the background and then find the "ideal" text color
+ const auto a = color.alpha() / 255.;
+ int r = (1 - a) * bg.red() + a * color.red(),
+ g = (1 - a) * bg.green() + a * color.green(),
+ b = (1 - a) * bg.blue() + a * color.blue();
+ opt.palette.setBrush(QPalette::Text, ColorSettings::idealTextColor(QColor(r, g, b)));
}
}
diff --git a/src/settings.cpp b/src/settings.cpp index 251e2b15..488a9b01 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -1326,12 +1326,12 @@ void ColorSettings::setColorSeparatorScrollbar(bool b) QColor ColorSettings::idealTextColor(const QColor& rBackgroundColor) { - if (rBackgroundColor.alpha() == 0) + if (rBackgroundColor.alpha() < 50) return QColor(Qt::black); - const int THRESHOLD = 106 * 255.0f / rBackgroundColor.alpha(); - int BackgroundDelta = (rBackgroundColor.red() * 0.299) + (rBackgroundColor.green() * 0.587) + (rBackgroundColor.blue() * 0.114); - return QColor((255 - BackgroundDelta <= THRESHOLD) ? Qt::black : Qt::white); + // "inverse' of luminance of the background + int iLuminance = (rBackgroundColor.red() * 0.299) + (rBackgroundColor.green() * 0.587) + (rBackgroundColor.blue() * 0.114); + return QColor(iLuminance >= 128 ? Qt::black : Qt::white); } |
