* @brief Returns a saturated accent color for a given device index. */
| 752 | * @brief Returns a saturated accent color for a given device index. |
| 753 | */ |
| 754 | QColor 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 |