Skip to content

Commit

Permalink
gui: improve score colors
Browse files Browse the repository at this point in the history
Mix the base color with the score color in order to have a result that
matches the user's color theme. E.g. on a dark theme the background of
trained entries will appear dark as well, allowing us to use the default
font color to display entries details.
  • Loading branch information
Gnurou committed Oct 16, 2016
1 parent 664c33b commit c3db438
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
4 changes: 1 addition & 3 deletions src/gui/EntryDelegate.cc
Expand Up @@ -88,9 +88,7 @@ void EntryDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
else textColor = option.palette.color(QPalette::Active, QPalette::HighlightedText);
}
else {
// If the entry is trained, the background color is fixed because we know the background color
if (entry->trained()) textColor = Qt::black;
else textColor = option.palette.color(QPalette::Text);
textColor = option.palette.color(QPalette::Text);
}

// Draw the background
Expand Down
10 changes: 8 additions & 2 deletions src/gui/EntryFormatter.cc
Expand Up @@ -35,8 +35,14 @@ static QFont printFont = QFont("", 14);
QColor EntryFormatter::scoreColor(const Entry &entry)
{
int sc = entry.score() * 5;
return QColor(sc > 0xff ? sc < 0x1ff ? 0xff - (sc - 0x100) : 0x00 : 0xff,
sc < 0xff ? sc : 0xff, 0x00).lighter(165);
static const float r = 0.3;
QColor base(QPalette().color(QPalette::Base));
QColor score(QColor(sc > 0xff ? sc < 0x1ff ? 0xff - (sc - 0x100) : 0x00 : 0xff,
sc < 0xff ? sc : 0xff, 0x00).lighter(165));

return QColor(base.red() * (1 - r) + score.red() * r,
base.green() * (1 - r) + score.green() * r,
base.blue() * (1 - r) + score.blue() * r);
}


Expand Down

0 comments on commit c3db438

Please sign in to comment.