Avoid unnecessary QColor -> QString conversions

This commit is contained in:
Joseph Donofry 2021-06-08 17:20:09 -04:00
parent ca91e9d0d1
commit 0a833b6e9b
No known key found for this signature in database
GPG key ID: E8A1D78EF044B0CB
3 changed files with 6 additions and 8 deletions

View file

@ -679,11 +679,10 @@ utils::hashQString(const QString &input)
return hash;
}
QString
utils::generateContrastingHexColor(const QString &input, const QString &background)
QColor
utils::generateContrastingHexColor(const QString &input, const QColor &backgroundCol)
{
const QColor backgroundCol(background);
const qreal backgroundLum = luminance(background);
const qreal backgroundLum = luminance(backgroundCol);
// Create a color for the input
auto hash = hashQString(input);

View file

@ -301,8 +301,8 @@ hashQString(const QString &input);
//! Generate a color (matching #RRGGBB) that has an acceptable contrast to background that is based
//! on the input string.
QString
generateContrastingHexColor(const QString &input, const QString &background);
QColor
generateContrastingHexColor(const QString &input, const QColor &background);
//! Given two luminance values, compute the contrast ratio between them.
qreal

View file

@ -122,8 +122,7 @@ QColor
TimelineViewManager::userColor(QString id, QColor background)
{
if (!userColors.contains(id))
userColors.insert(
id, QColor(utils::generateContrastingHexColor(id, background.name())));
userColors.insert(id, QColor(utils::generateContrastingHexColor(id, background)));
return userColors.value(id);
}