| 1479 | } |
| 1480 | |
| 1481 | QString ThemeManager::cssFragment(const QString& token) const |
| 1482 | { |
| 1483 | // Alias-aware: lookupRaw expands `{primitive.key}` references before |
| 1484 | // returning, so QSS templates referencing semantic tokens that |
| 1485 | // alias-resolve through the primitives palette emit the right |
| 1486 | // literal value. |
| 1487 | const QVariant v = lookupRaw(QString(), token); |
| 1488 | if (v.isValid()) { |
| 1489 | if (v.userType() == qMetaTypeId<ThemeGradient>()) { |
| 1490 | return gradientCssFragment(v.value<ThemeGradient>()); |
| 1491 | } |
| 1492 | if (v.userType() == qMetaTypeId<ThemeFont>()) { |
| 1493 | return v.value<ThemeFont>().family; |
| 1494 | } |
| 1495 | return colorHexToCssFragment(v.toString()); |
| 1496 | } |
| 1497 | // Virtual lookup: `font.size.<role>` falls through to the embedded |
| 1498 | // size field on `font.family.<role>` when no direct token exists. |
| 1499 | // Lets QSS templates write `font-size: {{font.size.freq}}px` and have |
| 1500 | // edits to the freq compound's size take effect without needing a |
| 1501 | // separate scalar token namespace. |
| 1502 | if (token.startsWith(QStringLiteral("font.size."))) { |
| 1503 | const QString role = token.mid(QStringLiteral("font.size.").size()); |
| 1504 | const QVariant compound = lookupRaw(QString(), |
| 1505 | QStringLiteral("font.family.") + role); |
| 1506 | if (compound.userType() == qMetaTypeId<ThemeFont>()) { |
| 1507 | const int sz = compound.value<ThemeFont>().size; |
| 1508 | if (sz > 0) return QString::number(sz); |
| 1509 | } |
| 1510 | } |
| 1511 | return QString(); |
| 1512 | } |
| 1513 | |
| 1514 | QFont ThemeManager::font(const QString& token) const |
| 1515 | { |