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/modlistview.cpp | |
| parent | d923730452e129260dc08a2a909c897eb9475ce7 (diff) | |
Tentative fix for automatic text color when markers or separator colors are used.
Diffstat (limited to 'src/modlistview.cpp')
| -rw-r--r-- | src/modlistview.cpp | 21 |
1 files changed, 16 insertions, 5 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)));
}
}
|
