13#include <QApplication>
17#include <QStandardPaths>
19#include <QStyleFactory>
34 : QObject(nullptr), currentThemeId_(
"auto")
36 registerBuiltinThemes();
39 if (
auto* theme =
getTheme(currentThemeId_))
41 effectiveColors_ = theme->colors;
44 connectSystemThemeSignals();
53 settingsController_ = settingsController;
61void ThemeManager::registerBuiltinThemes()
64 themes_[QStringLiteral(
"auto")] = createAutoTheme();
67 themes_[QStringLiteral(
"system")] = createSystemTheme();
70 themes_[QStringLiteral(
"standard-dark")] = createStandardDarkTheme();
71 themes_[QStringLiteral(
"standard-light")] = createStandardLightTheme();
74 themes_[QStringLiteral(
"cachyos-emerald")] = createCachyOSEmeraldTheme();
75 themes_[QStringLiteral(
"nord-dark")] = createNordDarkTheme();
76 themes_[QStringLiteral(
"dracula")] = createDraculaTheme();
77 themes_[QStringLiteral(
"catppuccin-mocha")] = createCatppuccinMochaTheme();
78 themes_[QStringLiteral(
"gruvbox-dark")] = createGruvboxDarkTheme();
79 themes_[QStringLiteral(
"tokyo-night")] = createTokyoNightTheme();
82 themes_[QStringLiteral(
"nord-light")] = createNordLightTheme();
83 themes_[QStringLiteral(
"catppuccin-latte")] = createCatppuccinLatteTheme();
84 themes_[QStringLiteral(
"gruvbox-light")] = createGruvboxLightTheme();
85 themes_[QStringLiteral(
"solarized-light")] = createSolarizedLightTheme();
96void ThemeManager::connectSystemThemeSignals()
98#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
100 if (QStyleHints* hints = QApplication::styleHints())
102 connect(hints, &QStyleHints::colorSchemeChanged,
this,
103 &ThemeManager::onSystemColorSchemeChanged);
108void ThemeManager::onSystemColorSchemeChanged()
114 themes_[QStringLiteral(
"auto")] = createAutoTheme();
115 updateEffectiveColors();
116 refreshAllWidgetStyles();
120bool ThemeManager::isAutoMode()
const
122 return currentThemeId_ == QStringLiteral(
"auto");
125QString ThemeManager::resolveAutoThemeId()
const
127#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
128 if (QStyleHints* hints = QApplication::styleHints())
130 Qt::ColorScheme scheme = hints->colorScheme();
131 if (scheme == Qt::ColorScheme::Dark)
132 return QStringLiteral(
"dark");
133 if (scheme == Qt::ColorScheme::Light)
134 return QStringLiteral(
"light");
138 return isSystemDarkMode() ? QStringLiteral(
"dark") : QStringLiteral(
"light");
141Theme ThemeManager::createAutoTheme()
145 theme.
id = QStringLiteral(
"auto");
146 theme.
displayName = QStringLiteral(
"Auto (System)");
150#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
151 if (QStyleHints* hints = QApplication::styleHints())
153 Qt::ColorScheme scheme = hints->colorScheme();
154 if (scheme == Qt::ColorScheme::Dark)
156 else if (scheme == Qt::ColorScheme::Light)
159 isDark = isSystemDarkMode();
163 isDark = isSystemDarkMode();
166 isDark = isSystemDarkMode();
171 QPalette systemPalette = QApplication::palette();
172 ThemeColors& c = theme.
colors;
179 QColor altBase = systemPalette.color(QPalette::AlternateBase);
190 QColor wt = systemPalette.color(QPalette::WindowText);
191 QColor tx = systemPalette.color(QPalette::Text);
192 if (tx.lightness() > wt.lightness())
213 QColor placeholder = systemPalette.color(QPalette::PlaceholderText);
214 c.
textMuted = (placeholder.lightness() < 80) ? QColor(128, 128, 128) : placeholder;
215 c.
textOnAccent = systemPalette.color(QPalette::HighlightedText);
217 theme.
defaultAccent = systemPalette.color(QPalette::Highlight);
223 c.
error = QColor(
"#ef5350");
225 c.
info = QColor(
"#4fc3f7");
228 QColor midColor = systemPalette.color(QPalette::Mid);
245 c.
hoverBackground = systemPalette.color(QPalette::Highlight).lighter(180);
247 c.
textPrimary = systemPalette.color(QPalette::WindowText);
249 c.
textMuted = systemPalette.color(QPalette::PlaceholderText);
250 c.
textOnAccent = systemPalette.color(QPalette::HighlightedText);
252 theme.
defaultAccent = systemPalette.color(QPalette::Highlight);
258 c.
error = QColor(
"#c62828");
260 c.
info = QColor(
"#1976d2");
263 c.
border = systemPalette.color(QPalette::Mid);
264 c.
borderLight = systemPalette.color(QPalette::Midlight);
274bool ThemeManager::isSystemDarkMode()
const
277 QPalette systemPalette = QApplication::palette();
278 QColor windowColor = systemPalette.color(QPalette::Window);
281 (windowColor.red() * 299 + windowColor.green() * 587 + windowColor.blue() * 114) / 1000;
282 return luminance < 128;
285Theme ThemeManager::createSystemTheme()
288 theme.
id = QStringLiteral(
"system");
289 theme.
displayName = QStringLiteral(
"System (Follow OS)");
292 QPalette systemPalette = QApplication::palette();
295 bool isDark = isSystemDarkMode();
297 ThemeColors& c = theme.
colors;
306 QColor altBase = systemPalette.color(QPalette::AlternateBase);
323 QColor wt = systemPalette.color(QPalette::WindowText);
324 QColor tx = systemPalette.color(QPalette::Text);
325 if (tx.lightness() > wt.lightness())
347 QColor placeholder = systemPalette.color(QPalette::PlaceholderText);
348 if (placeholder.lightness() < 80)
357 c.
textOnAccent = systemPalette.color(QPalette::HighlightedText);
359 theme.
defaultAccent = systemPalette.color(QPalette::Highlight);
366 c.
error = QColor(
"#ef5350");
368 c.
info = QColor(
"#4fc3f7");
372 QColor midColor = systemPalette.color(QPalette::Mid);
394 c.
hoverBackground = systemPalette.color(QPalette::Highlight).lighter(180);
396 c.
textPrimary = systemPalette.color(QPalette::WindowText);
398 c.
textMuted = systemPalette.color(QPalette::PlaceholderText);
399 c.
textOnAccent = systemPalette.color(QPalette::HighlightedText);
401 theme.
defaultAccent = systemPalette.color(QPalette::Highlight);
407 c.
error = QColor(
"#c62828");
409 c.
info = QColor(
"#1976d2");
412 c.
border = systemPalette.color(QPalette::Mid);
413 c.
borderLight = systemPalette.color(QPalette::Midlight);
423Theme ThemeManager::createStandardDarkTheme()
426 theme.
id = QStringLiteral(
"standard-dark");
427 theme.
displayName = QStringLiteral(
"Standard Dark");
430 ThemeColors& c = theme.
colors;
452 c.
error = QColor(
"#f14c4c");
454 c.
info = QColor(
"#3794ff");
458 c.
border = QColor(
"#454545");
469Theme ThemeManager::createCachyOSEmeraldTheme()
472 theme.
id = QStringLiteral(
"cachyos-emerald");
473 theme.
displayName = QStringLiteral(
"CachyOS Emerald");
477 ThemeColors& c = theme.
colors;
499 c.
error = QColor(
"#e05555");
501 c.
info = QColor(
"#55a8e0");
505 c.
border = QColor(
"#3a4042");
516Theme ThemeManager::createNordDarkTheme()
519 theme.
id = QStringLiteral(
"nord-dark");
523 ThemeColors& c = theme.
colors;
545 c.
error = QColor(
"#bf616a");
547 c.
info = QColor(
"#81a1c1");
551 c.
border = QColor(
"#4c566a");
562Theme ThemeManager::createDraculaTheme()
565 theme.
id = QStringLiteral(
"dracula");
569 ThemeColors& c = theme.
colors;
591 c.
error = QColor(
"#ff5555");
593 c.
info = QColor(
"#8be9fd");
597 c.
border = QColor(
"#6272a4");
608Theme ThemeManager::createCatppuccinMochaTheme()
611 theme.
id = QStringLiteral(
"catppuccin-mocha");
612 theme.
displayName = QStringLiteral(
"Catppuccin Mocha");
615 ThemeColors& c = theme.
colors;
637 c.
error = QColor(
"#f38ba8");
639 c.
info = QColor(
"#89b4fa");
643 c.
border = QColor(
"#45475a");
654Theme ThemeManager::createGruvboxDarkTheme()
657 theme.
id = QStringLiteral(
"gruvbox-dark");
658 theme.
displayName = QStringLiteral(
"Gruvbox Dark");
661 ThemeColors& c = theme.
colors;
683 c.
error = QColor(
"#fb4934");
685 c.
info = QColor(
"#83a598");
689 c.
border = QColor(
"#504945");
700Theme ThemeManager::createTokyoNightTheme()
703 theme.
id = QStringLiteral(
"tokyo-night");
707 ThemeColors& c = theme.
colors;
729 c.
error = QColor(
"#f7768e");
731 c.
info = QColor(
"#7dcfff");
735 c.
border = QColor(
"#414868");
750Theme ThemeManager::createStandardLightTheme()
753 theme.
id = QStringLiteral(
"standard-light");
754 theme.
displayName = QStringLiteral(
"Standard Light");
757 ThemeColors& c = theme.
colors;
779 c.
error = QColor(
"#d13438");
781 c.
info = QColor(
"#0078d4");
785 c.
border = QColor(
"#d1d1d1");
796Theme ThemeManager::createNordLightTheme()
799 theme.
id = QStringLiteral(
"nord-light");
803 ThemeColors& c = theme.
colors;
825 c.
error = QColor(
"#bf616a");
827 c.
info = QColor(
"#81a1c1");
831 c.
border = QColor(
"#d8dee9");
842Theme ThemeManager::createCatppuccinLatteTheme()
845 theme.
id = QStringLiteral(
"catppuccin-latte");
846 theme.
displayName = QStringLiteral(
"Catppuccin Latte");
849 ThemeColors& c = theme.
colors;
871 c.
error = QColor(
"#d20f39");
873 c.
info = QColor(
"#1e66f5");
877 c.
border = QColor(
"#bcc0cc");
888Theme ThemeManager::createGruvboxLightTheme()
891 theme.
id = QStringLiteral(
"gruvbox-light");
892 theme.
displayName = QStringLiteral(
"Gruvbox Light");
895 ThemeColors& c = theme.
colors;
917 c.
error = QColor(
"#9d0006");
919 c.
info = QColor(
"#076678");
923 c.
border = QColor(
"#bdae93");
934Theme ThemeManager::createSolarizedLightTheme()
937 theme.
id = QStringLiteral(
"solarized-light");
938 theme.
displayName = QStringLiteral(
"Solarized Light");
941 ThemeColors& c = theme.
colors;
963 c.
error = QColor(
"#dc322f");
965 c.
info = QColor(
"#268bd2");
969 c.
border = QColor(
"#93a1a1");
987 std::vector<QString> ids;
988 ids.reserve(themes_.size());
991 static const QString orderedIds[] = {
992 QStringLiteral(
"auto"),
993 QStringLiteral(
"system"),
994 QStringLiteral(
"standard-dark"),
995 QStringLiteral(
"standard-light"),
996 QStringLiteral(
"cachyos-emerald"),
997 QStringLiteral(
"nord-dark"),
998 QStringLiteral(
"dracula"),
999 QStringLiteral(
"catppuccin-mocha"),
1000 QStringLiteral(
"gruvbox-dark"),
1001 QStringLiteral(
"tokyo-night"),
1002 QStringLiteral(
"nord-light"),
1003 QStringLiteral(
"catppuccin-latte"),
1004 QStringLiteral(
"gruvbox-light"),
1005 QStringLiteral(
"solarized-light"),
1008 for (
const auto&
id : orderedIds)
1010 if (themes_.find(
id) != themes_.end())
1017 for (
const auto& [
id, theme] : themes_)
1019 if (std::find(ids.begin(), ids.end(),
id) == ids.end())
1030 auto it = themes_.find(
id);
1031 if (it != themes_.end())
1045 return currentThemeId_;
1050 if (themes_.find(themeId) == themes_.end())
1055 if (currentThemeId_ != themeId)
1057 currentThemeId_ = themeId;
1058 updateEffectiveColors();
1059 refreshAllWidgetStyles();
1070 if (color.isValid())
1072 customAccentColor_ = color;
1073 useCustomAccent_ =
true;
1074 updateEffectiveColors();
1075 refreshAllWidgetStyles();
1082 return effectiveColors_.accent;
1087 return useCustomAccent_;
1092 useCustomAccent_ =
false;
1093 customAccentColor_ = QColor();
1094 updateEffectiveColors();
1095 refreshAllWidgetStyles();
1105 return effectiveColors_;
1112void ThemeManager::updateEffectiveColors()
1121 effectiveColors_ = theme->
colors;
1124 if (useCustomAccent_ && customAccentColor_.isValid())
1126 effectiveColors_.accent = customAccentColor_;
1127 effectiveColors_.accentHover =
lightenColor(customAccentColor_, 15);
1128 effectiveColors_.accentPressed =
darkenColor(customAccentColor_, 15);
1132void ThemeManager::refreshAllWidgetStyles()
1137 for (QWidget* widget : QApplication::allWidgets())
1139 widget->style()->unpolish(widget);
1140 widget->style()->polish(widget);
1152 int fgL = fg.lightness();
1153 int bgL = bg.lightness();
1154 int diff = qAbs(fgL - bgL);
1155 if (diff >= minDiff)
1160 fg.getHsl(&h, &s, &l, &a);
1164 l = qMin(255, bgL + minDiff);
1169 l = qMax(0, bgL - minDiff);
1171 return QColor::fromHsl(h, s, l, a);
1177 color.getHsl(&h, &s, &l, &a);
1178 l = qMin(255, l + amount);
1179 return QColor::fromHsl(h, s, l, a);
1185 color.getHsl(&h, &s, &l, &a);
1186 l = qMax(0, l - amount);
1187 return QColor::fromHsl(h, s, l, a);
1197 generateIndicatorIcons();
1209void ThemeManager::generateIndicatorIcons()
1212 QString cacheDir = QStandardPaths::writableLocation(QStandardPaths::CacheLocation);
1213 QDir().mkpath(cacheDir);
1215 const QString color = effectiveColors_.
textOnAccent.name();
1218 checkmarkIconPath_ = cacheDir +
"/checkmark.svg";
1219 QFile checkFile(checkmarkIconPath_);
1220 if (checkFile.open(QIODevice::WriteOnly | QIODevice::Truncate))
1223 QString(
"<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'>"
1224 "<path d='M3.5 8.5L6.5 11.5L12.5 4.5' stroke='%1' stroke-width='2.5' "
1225 "stroke-linecap='round' stroke-linejoin='round' fill='none'/></svg>")
1232 radioDotIconPath_ = cacheDir +
"/radio_dot.svg";
1233 QFile radioFile(radioDotIconPath_);
1234 if (radioFile.open(QIODevice::WriteOnly | QIODevice::Truncate))
1236 radioFile.write(QString(
"<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'>"
1237 "<circle cx='8' cy='8' r='4' fill='%1'/></svg>")
1261 palette.setColor(QPalette::WindowText, textOnWin);
1262 palette.setColor(QPalette::Text, textOnBase);
1263 palette.setColor(QPalette::ButtonText, textOnBtn);
1264 palette.setColor(QPalette::BrightText, c.
textOnAccent);
1265 palette.setColor(QPalette::PlaceholderText, c.
textMuted);
1268 palette.setColor(QPalette::Highlight, c.
accent);
1269 palette.setColor(QPalette::HighlightedText, c.
textOnAccent);
1271#if QT_VERSION >= QT_VERSION_CHECK(6, 6, 0)
1276 palette.setColor(QPalette::Accent, c.
accent);
1280 palette.setColor(QPalette::Link, c.
info);
1281 palette.setColor(QPalette::LinkVisited, c.
accent);
1284 palette.setColor(QPalette::Disabled, QPalette::WindowText, c.
textMuted);
1285 palette.setColor(QPalette::Disabled, QPalette::Text, c.
textMuted);
1286 palette.setColor(QPalette::Disabled, QPalette::ButtonText, c.
textMuted);
1287 palette.setColor(QPalette::Disabled, QPalette::Button, c.
inputBackground);
1291 palette.setColor(QPalette::ToolTipText, c.
textPrimary);
1317 QColor accentFaded = c.
accent;
1318 accentFaded.setAlpha(180);
1319 QString accentFadedStr = accentFaded.name(QColor::HexArgb);
1330 "/* %1 %17 %18 %19 */"
1335 "QScrollBar:vertical {"
1336 " background: transparent;"
1340 "QScrollBar::handle:vertical {"
1342 " min-height: 24px;"
1343 " border-radius: 4px;"
1346 "QScrollBar::handle:vertical:hover {"
1349 "QScrollBar::add-line:vertical, QScrollBar::sub-line:vertical {"
1352 "QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical {"
1353 " background: none;"
1355 "QScrollBar:horizontal {"
1356 " background: transparent;"
1360 "QScrollBar::handle:horizontal {"
1363 " border-radius: 4px;"
1366 "QScrollBar::handle:horizontal:hover {"
1369 "QScrollBar::add-line:horizontal, QScrollBar::sub-line:horizontal {"
1372 "QScrollBar::add-page:horizontal, QScrollBar::sub-page:horizontal {"
1373 " background: none;"
1380 " background-color: %4;"
1382 " border: 1px solid %7;"
1383 " padding: 6px 10px;"
1384 " border-radius: 6px;"
1391 " background-color: %4;"
1392 " border: 1px solid %14;"
1393 " border-radius: 8px;"
1394 " padding: 6px 4px;"
1397 " padding: 8px 32px 8px 16px;"
1398 " border-radius: 4px;"
1402 "QMenu::item:selected {"
1403 " background-color: %20;"
1406 "QMenu::item:checked {"
1409 "QMenu::item:checked:selected {"
1412 "QMenu::item:disabled {"
1414 " background-color: transparent;"
1416 "QMenu::indicator {"
1419 " margin-left: 6px;"
1421 "QMenu::separator {"
1424 " margin: 4px 10px;"
1427 " padding-left: 8px;"
1434 " background-color: %8;"
1435 " border: 1px solid %6;"
1436 " border-radius: 6px;"
1437 " padding: 5px 10px;"
1439 " min-height: 20px;"
1442 " border-color: %7;"
1445 " border-color: %7;"
1447 "QComboBox::drop-down {"
1450 " subcontrol-position: right center;"
1452 "QComboBox QAbstractItemView {"
1453 " background-color: %4;"
1455 " border: 1px solid %14;"
1456 " border-radius: 6px;"
1459 " selection-background-color: %20;"
1460 " selection-color: %12;"
1462 "QComboBox QAbstractItemView::item {"
1463 " padding: 4px 8px;"
1466 "QComboBox QAbstractItemView::item:selected {"
1474 " background-color: %8;"
1475 " border: 1px solid %6;"
1476 " border-radius: 6px;"
1477 " padding: 5px 10px;"
1479 " selection-background-color: %7;"
1480 " selection-color: %12;"
1483 " border-color: %7;"
1485 "QLineEdit:disabled {"
1487 " background-color: %15;"
1493 "QSpinBox, QDoubleSpinBox {"
1494 " background-color: %8;"
1495 " border: 1px solid %6;"
1496 " border-radius: 6px;"
1497 " padding: 5px 10px;"
1500 "QSpinBox:focus, QDoubleSpinBox:focus {"
1501 " border-color: %7;"
1503 "QSpinBox::up-button, QDoubleSpinBox::up-button,"
1504 "QSpinBox::down-button, QDoubleSpinBox::down-button {"
1512 "QTextEdit, QPlainTextEdit {"
1513 " background-color: %8;"
1514 " border: 1px solid %6;"
1515 " border-radius: 6px;"
1518 " selection-background-color: %7;"
1519 " selection-color: %12;"
1521 "QTextEdit:focus, QPlainTextEdit:focus {"
1522 " border-color: %7;"
1528 "QTabWidget::pane {"
1529 " border: 1px solid %14;"
1530 " border-top: none;"
1531 " background-color: %9;"
1534 " background-color: transparent;"
1536 " border-bottom: 2px solid transparent;"
1537 " padding: 9px 18px;"
1538 " margin-right: 2px;"
1541 "QTabBar::tab:selected {"
1543 " border-bottom: 2px solid %7;"
1545 "QTabBar::tab:hover:!selected {"
1547 " border-bottom: 2px solid %14;"
1554 " border: 1px solid %14;"
1555 " border-left: 3px solid %7;"
1556 " border-radius: 6px;"
1557 " margin-top: 16px;"
1558 " padding: 12px 8px 8px 8px;"
1561 "QGroupBox::title {"
1562 " subcontrol-origin: margin;"
1566 " font-weight: bold;"
1577 "QCheckBox::indicator {"
1580 " border: 2px solid %6;"
1581 " border-radius: 4px;"
1582 " background-color: %8;"
1584 "QCheckBox::indicator:checked {"
1585 " background-color: %7;"
1586 " border-color: %7;"
1588 checkmarkIconPath_ +
1591 "QCheckBox::indicator:hover {"
1592 " border-color: %7;"
1594 "QCheckBox::indicator:disabled {"
1595 " background-color: %15;"
1596 " border-color: %14;"
1606 "QRadioButton::indicator {"
1609 " border: 2px solid %6;"
1610 " border-radius: 9px;"
1611 " background-color: %8;"
1613 "QRadioButton::indicator:checked {"
1614 " background-color: %7;"
1615 " border-color: %7;"
1620 "QRadioButton::indicator:hover {"
1621 " border-color: %7;"
1623 "QRadioButton::indicator:disabled {"
1624 " background-color: %15;"
1625 " border-color: %14;"
1632 " background-color: %8;"
1634 " border-radius: 4px;"
1635 " text-align: center;"
1639 "QProgressBar::chunk {"
1640 " background-color: %7;"
1641 " border-radius: 4px;"
1647 "QSlider::groove:horizontal {"
1650 " border-radius: 2px;"
1652 "QSlider::handle:horizontal {"
1657 " border-radius: 8px;"
1658 " border: 2px solid %7;"
1660 "QSlider::handle:horizontal:hover {"
1662 " border-color: %13;"
1664 "QSlider::sub-page:horizontal {"
1666 " border-radius: 2px;"
1673 " background-color: %4;"
1675 " border: 1px solid %6;"
1676 " border-radius: 6px;"
1677 " padding: 7px 16px;"
1678 " font-weight: 500;"
1680 "QPushButton:hover {"
1681 " background-color: %11;"
1682 " border-color: %7;"
1684 "QPushButton:pressed {"
1685 " background-color: %8;"
1686 " border-color: %7;"
1688 "QPushButton:disabled {"
1690 " background-color: %15;"
1691 " border-color: %14;"
1693 "QPushButton:focus {"
1695 " border-color: %7;"
1702 " border: 1px solid transparent;"
1703 " border-radius: 6px;"
1706 "QToolButton:hover {"
1707 " background-color: %11;"
1708 " border-color: %14;"
1710 "QToolButton:pressed {"
1711 " background-color: %8;"
1713 "QToolButton:focus {"
1715 " border-color: %7;"
1723 " background: transparent;"
1729 "QHeaderView::section {"
1730 " background-color: %9;"
1733 " border-bottom: 2px solid %14;"
1734 " padding: 8px 10px;"
1735 " font-weight: bold;"
1737 " text-transform: uppercase;"
1739 "QHeaderView::section:hover {"
1741 " background-color: %11;"
1747 "QTreeView, QTreeWidget {"
1748 " background-color: %4;"
1749 " alternate-background-color: %9;"
1750 " border: 1px solid %14;"
1751 " border-radius: 6px;"
1753 " selection-background-color: %20;"
1754 " selection-color: %5;"
1756 "QTreeView::item, QTreeWidget::item {"
1757 " padding: 4px 8px;"
1758 " border-radius: 4px;"
1761 "QTreeView::item:hover, QTreeWidget::item:hover {"
1762 " background-color: %11;"
1764 "QTreeView::item:selected, QTreeWidget::item:selected {"
1765 " background-color: %20;"
1772 "QTableView, QTableWidget {"
1773 " background-color: %4;"
1774 " alternate-background-color: %9;"
1775 " border: 1px solid %14;"
1776 " border-radius: 6px;"
1777 " gridline-color: %14;"
1779 " selection-background-color: %20;"
1780 " selection-color: %5;"
1786 "QListView, QListWidget {"
1787 " background-color: %4;"
1788 " border: 1px solid %14;"
1789 " border-radius: 6px;"
1792 "QListView::item, QListWidget::item {"
1793 " border-radius: 4px;"
1796 "QListView::item:hover, QListWidget::item:hover {"
1797 " background-color: %11;"
1799 "QListView::item:selected, QListWidget::item:selected {"
1800 " background-color: %20;"
1807 "QSplitter::handle {"
1808 " background-color: %14;"
1810 "QSplitter::handle:horizontal {"
1813 "QSplitter::handle:vertical {"
1816 "QSplitter::handle:hover {"
1817 " background-color: %7;"
1824 " background-color: %15;"
1830 "QDialog QGroupBox {"
1838 " background-color: %4;"
1841 "QMessageBox QLabel {"
1843 " background-color: transparent;"
1845 "QMessageBox QPushButton {"
1846 " background-color: %8;"
1848 " border: 1px solid %6;"
1849 " border-radius: 4px;"
1850 " padding: 6px 16px;"
1853 "QMessageBox QPushButton:hover {"
1854 " background-color: %11;"
1856 "QMessageBox QPushButton:pressed {"
1857 " background-color: %7;"
1865 " background-color: %9;"
1866 " border-top: 1px solid %14;"
1873 "QFrame[frameShape=\"4\"] {"
1877 "QFrame[frameShape=\"5\"] {"
1885 "QDialogButtonBox QPushButton {"
1887 " padding: 7px 20px;"
1900 "QLabel[link=\"true\"] {"
1907 "QLineEdit[placeholderText~=\"Search\"],"
1908 "QLineEdit[placeholderText~=\"search\"],"
1909 "QLineEdit[placeholderText~=\"Filter\"] {"
1910 " border-radius: 12px;"
1911 " padding: 5px 14px;"
1917 .arg(textOnCard.name())
1922 .arg(textSecOnCard.name())
1928 .arg(textSecOnCard.name())
1931 .arg(c.
error.name())
1932 .arg(accentFadedStr);
1943 QColor accentHighlight = c.
accent;
1944 accentHighlight.setAlpha(180);
1946 return QString(
"/* %2 */"
1948 " background-color: %1;"
1949 " border: 1px solid %6;"
1950 " border-radius: 8px;"
1951 " padding: 6px 4px;"
1954 " padding: 8px 32px 8px 16px;"
1955 " border-radius: 4px;"
1959 "QMenu::item:selected {"
1960 " background-color: %4;"
1963 "QMenu::item:checked {"
1966 "QMenu::item:checked:selected {"
1969 "QMenu::item:disabled {"
1971 " background-color: transparent;"
1973 "QMenu::indicator {"
1976 " margin-left: 6px;"
1978 "QMenu::separator {"
1981 " margin: 4px 10px;"
1984 " padding-left: 8px;"
1988 .arg(menuText.name())
1989 .arg(accentHighlight.name(QColor::HexArgb))
1990 .arg(menuDisabled.name())
2007 QPalette p = menu->palette();
2008 p.setColor(QPalette::Active, QPalette::WindowText, menuText);
2009 p.setColor(QPalette::Active, QPalette::Text, menuText);
2010 p.setColor(QPalette::Active, QPalette::ButtonText, menuText);
2011 p.setColor(QPalette::Active, QPalette::Window, c.
cardBackground);
2013 p.setColor(QPalette::Active, QPalette::Highlight, c.
accent);
2014 p.setColor(QPalette::Active, QPalette::HighlightedText, c.
textOnAccent);
2015 p.setColor(QPalette::Inactive, QPalette::WindowText, menuText);
2016 p.setColor(QPalette::Inactive, QPalette::Text, menuText);
2017 p.setColor(QPalette::Inactive, QPalette::ButtonText, menuText);
2018 p.setColor(QPalette::Inactive, QPalette::Window, c.
cardBackground);
2019 p.setColor(QPalette::Inactive, QPalette::Base, c.
cardBackground);
2020 p.setColor(QPalette::Inactive, QPalette::Highlight, c.
accent);
2021 p.setColor(QPalette::Inactive, QPalette::HighlightedText, c.
textOnAccent);
2022 p.setColor(QPalette::Disabled, QPalette::WindowText, c.
textMuted);
2023 p.setColor(QPalette::Disabled, QPalette::Text, c.
textMuted);
2024 p.setColor(QPalette::Disabled, QPalette::ButtonText, c.
textMuted);
2025 menu->setPalette(p);
2034 if (!settingsController_)
2039 auto settings = settingsController_->getAppSettings();
2040 settings.themeId = currentThemeId_.toStdString();
2041 settings.customAccentColor = useCustomAccent_ ? customAccentColor_.name().toStdString() :
"";
2042 settings.uiZoom = zoomLevel_;
2043 settings.fontFamily = fontFamily_.toStdString();
2044 settingsController_->setAppSettings(settings);
2049 if (!settingsController_)
2054 const auto& settings = settingsController_->getAppSettings();
2057 QString themeId = QString::fromStdString(settings.themeId);
2060 QSettings qSettings;
2061 QString wizardTheme = qSettings.value(
"app/wizardThemeId",
"").toString();
2062 if (!wizardTheme.isEmpty())
2065 if (themes_.find(wizardTheme) != themes_.end())
2067 themeId = wizardTheme;
2069 qSettings.remove(
"app/wizardThemeId");
2072 if (themes_.find(themeId) != themes_.end())
2074 currentThemeId_ = themeId;
2078 currentThemeId_ = QStringLiteral(
"auto");
2082 if (!settings.customAccentColor.empty())
2084 QColor color(QString::fromStdString(settings.customAccentColor));
2085 if (color.isValid())
2087 customAccentColor_ = color;
2088 useCustomAccent_ =
true;
2093 zoomLevel_ = std::clamp(settings.uiZoom, 75, 150);
2094 fontFamily_ = QString::fromStdString(settings.fontFamily);
2096 updateEffectiveColors();
2110 percent = std::clamp(percent, 75, 150);
2111 if (zoomLevel_ != percent)
2113 zoomLevel_ = percent;
2126 if (fontFamily_ != family)
2128 fontFamily_ = family;
2139 return static_cast<int>(std::lround(baseSize * zoomLevel_ / 100.0));
2144 return static_cast<int>(std::lround(baseSize * zoomLevel_ / 100.0));
2149 QFont font = baseFont;
2152 if (!fontFamily_.isEmpty())
2154 font.setFamily(fontFamily_);
2158 if (zoomLevel_ != 100)
2160 int scaledSize =
static_cast<int>(std::lround(font.pointSize() * zoomLevel_ / 100.0));
2169 QFont font = QApplication::font();
2172 if (baseFontSize_ == 0)
2174 baseFontSize_ = font.pointSize();
2175 if (baseFontSize_ <= 0)
2180 if (!fontFamily_.isEmpty())
2182 font.setFamily(fontFamily_);
2186 int scaledSize =
static_cast<int>(std::lround(baseFontSize_ * zoomLevel_ / 100.0));
static ThemeManager & instance()
void applyToApplication()
Apply current theme to the entire application.
QPalette buildPalette() const
Build QPalette from current theme.
static QColor ensureContrast(const QColor &fg, const QColor &bg, int minDiff=120)
Ensure foreground has sufficient contrast against background.
void resetAccentToDefault()
Reset accent to theme default.
static QColor darkenColor(const QColor &color, int amount)
Darken a color by decreasing its lightness.
QString currentThemeId() const
Get current theme ID.
QString buildStyleSheet() const
Build global stylesheet for widgets not covered by QPalette.
QString fontFamily() const
Get current font family (empty = system default).
bool hasCustomAccent() const
Check if using custom accent color.
void loadFromSettings()
Load theme settings from settings controller.
void styleMenu(QMenu *menu) const
Apply complete menu styling (stylesheet + palette) to a QMenu.
void setAccentColor(const QColor &color)
Set custom accent color (overrides theme default).
int scaledSize(int baseSize) const
Get scaled dimension for layouts/spacing.
void initialize(core::SettingsController *settingsController)
void setFontFamily(const QString &family)
Set font family.
void themeChanged()
Emitted when theme or accent color changes.
static QColor lightenColor(const QColor &color, int amount)
Lighten a color by increasing its lightness.
const Theme * getTheme(const QString &id) const
Get theme by ID (returns nullptr if not found).
void setZoomLevel(int percent)
Set zoom level (75-150).
int scaledFontSize(int baseSize) const
Get scaled font size for given base size.
QString menuStyleSheet() const
Get standalone menu stylesheet (for dynamically created menus).
int zoomLevel() const
Get current zoom level (75-150, default 100).
void setTheme(const QString &themeId)
Set active theme by ID.
void zoomChanged()
Emitted when zoom level or font changes.
const Theme * currentTheme() const
Get current theme.
const ThemeColors & colors() const
Get effective colors (with accent customization applied).
ThemeManager(const ThemeManager &)=delete
QFont scaledFont(const QFont &baseFont) const
Get scaled font (applies zoom + custom family if set).
std::vector< QString > getAvailableThemeIds() const
Get list of available theme IDs.
void saveToSettings()
Save theme settings to settings controller.
QColor accentColor() const
Get current accent color (custom or theme default).
QFont applicationFont() const
Get the base application font (with zoom and custom family applied).
QColor scrollbarThumbHover