MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / getDeviceColor

Method getDeviceColor

app/src/SerialStudio.cpp:754–773  ·  view source on GitHub ↗

* @brief Returns a saturated accent color for a given device index. */

Source from the content-addressed store, hash-verified

752 * @brief Returns a saturated accent color for a given device index.
753 */
754QColor SerialStudio::getDeviceColor(const int sourceId)
755{
756 if (sourceId <= 0)
757 return QColor(Qt::transparent);
758
759 static const auto* theme = &Misc::ThemeManager::instance();
760 const auto& colors = theme->deviceColors();
761 if (colors.isEmpty())
762 return QColor(Qt::transparent);
763
764 const auto& base = colors.at((sourceId - 1) % colors.count()).first;
765 const auto bg = theme->getColor(QStringLiteral("base"));
766 const bool dark = bg.isValid() && bg.lightnessF() < 0.5;
767
768 float h, s, l, a;
769 base.getHslF(&h, &s, &l, &a);
770 s = qBound(0.45f, s * 2.5f, 0.85f);
771 l = dark ? 0.65f : 0.38f;
772 return QColor::fromHslF(h, s, l, 1.0f);
773}
774
775//--------------------------------------------------------------------------------------------------
776// String processing

Callers

nothing calls this directly

Calls 4

isEmptyMethod · 0.80
getColorMethod · 0.80
countMethod · 0.45
isValidMethod · 0.45

Tested by

no test coverage detected