Custom themes

Added toggles for the "Custom Themes" configuration. Colors, icons, sounds, and turn signal animations are all individually toggleable.
This commit is contained in:
FrogAi
2024-01-12 22:39:30 -07:00
parent 142e5e0975
commit 7e0e9f2643
67 changed files with 281 additions and 28 deletions

View File

@@ -48,6 +48,23 @@ Sidebar::Sidebar(QWidget *parent) : QFrame(parent), onroad(false), flag_pressed(
isStorageLeft = params.getBool("ShowStorageLeft");
isStorageUsed = params.getBool("ShowStorageUsed");
themeConfiguration = {
{0, {"stock", {QColor(255, 255, 255)}}},
{1, {"frog_theme", {QColor(23, 134, 68)}}},
{2, {"tesla_theme", {QColor(0, 72, 255)}}},
{3, {"stalin_theme", {QColor(255, 0, 0)}}}
};
for (auto &[key, themeData] : themeConfiguration) {
QString &themeName = themeData.first;
QString base = themeName == "stock" ? "../assets/images" : QString("../frogpilot/assets/custom_themes/%1/images").arg(themeName);
std::vector<QString> paths = {base + "/button_home.png", base + "/button_flag.png", base + "/button_settings.png"};
home_imgs[key] = loadPixmap(paths[0], home_btn.size());
flag_imgs[key] = loadPixmap(paths[1], home_btn.size());
settings_imgs[key] = loadPixmap(paths[2], settings_btn.size(), Qt::IgnoreAspectRatio);
}
updateFrogPilotParams();
}
@@ -117,6 +134,8 @@ void Sidebar::updateState(const UIState &s) {
// FrogPilot properties
auto frogpilotDeviceState = sm["frogpilotDeviceState"].getFrogpilotDeviceState();
QColor theme_color = currentColors[0];
// FrogPilot metrics
if (isCPU || isGPU) {
auto cpu_loads = deviceState.getCpuUsagePercent();
@@ -129,7 +148,7 @@ void Sidebar::updateState(const UIState &s) {
QString metric = isGPU ? gpu : cpu;
int usage = isGPU ? gpu_usage : cpu_usage;
ItemStatus cpuStatus = {{tr(isGPU ? "GPU" : "CPU"), metric}, good_color};
ItemStatus cpuStatus = {{tr(isGPU ? "GPU" : "CPU"), metric}, theme_color};
if (usage >= 85) {
cpuStatus = {{tr(isGPU ? "GPU" : "CPU"), metric}, danger_color};
} else if (usage >= 70) {
@@ -147,7 +166,7 @@ void Sidebar::updateState(const UIState &s) {
QString storage = QString::number(isStorageLeft ? storage_left : storage_used) + " GB";
if (isMemoryUsage) {
ItemStatus memoryStatus = {{tr("MEMORY"), memory}, good_color};
ItemStatus memoryStatus = {{tr("MEMORY"), memory}, theme_color};
if (memory_usage >= 85) {
memoryStatus = {{tr("MEMORY"), memory}, danger_color};
} else if (memory_usage >= 70) {
@@ -155,7 +174,7 @@ void Sidebar::updateState(const UIState &s) {
}
setProperty("memoryStatus", QVariant::fromValue(memoryStatus));
} else {
ItemStatus storageStatus = {{tr(isStorageLeft ? "LEFT" : "USED"), storage}, good_color};
ItemStatus storageStatus = {{tr(isStorageLeft ? "LEFT" : "USED"), storage}, theme_color};
if (10 <= storage_left && storage_left < 25) {
storageStatus = {{tr(isStorageLeft ? "LEFT" : "USED"), storage}, warning_color};
} else if (storage_left < 10) {
@@ -171,7 +190,7 @@ void Sidebar::updateState(const UIState &s) {
connectStatus = ItemStatus{{tr("CONNECT"), tr("OFFLINE")}, warning_color};
} else {
connectStatus = nanos_since_boot() - last_ping < 80e9
? ItemStatus{{tr("CONNECT"), tr("ONLINE")}, good_color}
? ItemStatus{{tr("CONNECT"), tr("ONLINE")}, theme_color}
: ItemStatus{{tr("CONNECT"), tr("ERROR")}, danger_color};
}
setProperty("connectStatus", QVariant::fromValue(connectStatus));
@@ -179,13 +198,13 @@ void Sidebar::updateState(const UIState &s) {
ItemStatus tempStatus = {{tr("TEMP"), tr("HIGH")}, danger_color};
auto ts = deviceState.getThermalStatus();
if (ts == cereal::DeviceState::ThermalStatus::GREEN) {
tempStatus = {{tr("TEMP"), tr("GOOD")}, good_color};
tempStatus = {{tr("TEMP"), tr("GOOD")}, theme_color};
} else if (ts == cereal::DeviceState::ThermalStatus::YELLOW) {
tempStatus = {{tr("TEMP"), tr("OK")}, warning_color};
}
setProperty("tempStatus", QVariant::fromValue(tempStatus));
ItemStatus pandaStatus = {{tr("VEHICLE"), tr("ONLINE")}, good_color};
ItemStatus pandaStatus = {{tr("VEHICLE"), tr("ONLINE")}, theme_color};
if (s.scene.pandaType == cereal::PandaState::PandaType::UNKNOWN) {
pandaStatus = {{tr("NO"), tr("PANDA")}, danger_color};
} else if (s.scene.started && !sm["liveLocationKalman"].getLiveLocationKalman().getGpsOK()) {
@@ -196,6 +215,15 @@ void Sidebar::updateState(const UIState &s) {
void Sidebar::updateFrogPilotParams() {
// Update FrogPilot parameters upon toggle change
isCustomTheme = params.getBool("CustomTheme");
customColors = isCustomTheme ? params.getInt("CustomColors") : 0;
customIcons = isCustomTheme ? params.getInt("CustomIcons") : 0;
home_img = home_imgs[customIcons];
flag_img = flag_imgs[customIcons];
settings_img = settings_imgs[customIcons];
currentColors = themeConfiguration[customColors].second;
}
void Sidebar::paintEvent(QPaintEvent *event) {