diff options
| author | Danilo M. <danix@danix.xyz> | 2026-08-26 15:33:00 +0200 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-08-26 15:33:00 +0200 |
| commit | 39a0cce152dda3b3d828c6145f02c3db9bbd7449 (patch) | |
| tree | 695a862a9c01fad66cbe9bff542fedf810459415 /src | |
| parent | 656d70aef7cacff69d2616d2df0cbe8d6e4188f9 (diff) | |
| download | qtmaildir-39a0cce152dda3b3d828c6145f02c3db9bbd7449.tar.gz qtmaildir-39a0cce152dda3b3d828c6145f02c3db9bbd7449.zip | |
feat: choose an avatar fill and derive its colour
Diffstat (limited to 'src')
| -rw-r--r-- | src/avatar.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/avatar.cpp b/src/avatar.cpp index 4cedae2..0e2b25f 100644 --- a/src/avatar.cpp +++ b/src/avatar.cpp @@ -75,4 +75,26 @@ QString initialsFor(const QString &displayName, const QString &address, return QStringLiteral("??"); } +Fill fillFor(const QString &displayName, bool isBusinessSender) +{ + // The list first: it is the user's explicit override and must beat the + // heuristic, or a listed sender could never be pinned. + if (isBusinessSender) + return Fill::TwoTone; + return displayName.trimmed().isEmpty() ? Fill::TwoTone : Fill::Identicon; +} + +QColor colourFor(const QString &address) +{ + // The same construction TagColors::colourFor() uses for a tag with nothing + // configured: hashed so it is stable, at a fixed saturation and lightness + // so it cannot come out neon and cannot lose its contrast with the + // initials. The lightness differs from that function's deliberately: a + // chip carries dark text, a squircle carries white. + const QByteArray digest = + QCryptographicHash::hash(address.toUtf8(), QCryptographicHash::Md5); + const int hue = static_cast<quint8>(digest.at(0)) * 360 / 256; + return QColor::fromHsl(hue, 110, 95); +} + } // namespace Avatar |
