From 7b684f4d15fa8f75fe802f9dd1534cf4ee2c25ea Mon Sep 17 00:00:00 2001 From: Mikaƫl Capelle Date: Fri, 8 Jan 2021 17:41:10 +0100 Subject: Tentative fix for automatic text color when markers or separator colors are used. --- src/modlistview.cpp | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'src/modlistview.cpp') 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(); } - 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))); } } -- cgit v1.3.1