From 05e91c074d0fbabfd3475d4f34b975819159519b Mon Sep 17 00:00:00 2001 From: Cameron Clough Date: Thu, 24 Aug 2023 12:47:22 +0100 Subject: [PATCH] ui: hasPrime/primeChanged helper (#29590) --- selfdrive/ui/qt/home.cc | 6 +++--- selfdrive/ui/ui.cc | 7 +++++++ selfdrive/ui/ui.h | 2 ++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/selfdrive/ui/qt/home.cc b/selfdrive/ui/qt/home.cc index f5eab4664e..f93b590007 100644 --- a/selfdrive/ui/qt/home.cc +++ b/selfdrive/ui/qt/home.cc @@ -157,9 +157,9 @@ OffroadHome::OffroadHome(QWidget* parent) : QFrame(parent) { left_widget->addWidget(new PrimeAdWidget); left_widget->setStyleSheet("border-radius: 10px;"); - left_widget->setCurrentIndex(uiState()->primeType() ? 0 : 1); - connect(uiState(), &UIState::primeTypeChanged, [=](PrimeType prime_type) { - left_widget->setCurrentIndex((prime_type != PrimeType::NONE) ? 0 : 1); + left_widget->setCurrentIndex(uiState()->hasPrime() ? 0 : 1); + connect(uiState(), &UIState::primeChanged, [=](bool prime) { + left_widget->setCurrentIndex(prime ? 0 : 1); }); home_layout->addWidget(left_widget, 1); diff --git a/selfdrive/ui/ui.cc b/selfdrive/ui/ui.cc index 7b12d54888..fa857c769b 100644 --- a/selfdrive/ui/ui.cc +++ b/selfdrive/ui/ui.cc @@ -270,9 +270,16 @@ void UIState::update() { void UIState::setPrimeType(PrimeType type) { if (type != prime_type) { + bool prev_prime = hasPrime(); + prime_type = type; Params().put("PrimeType", std::to_string(prime_type)); emit primeTypeChanged(prime_type); + + bool prime = hasPrime(); + if (prev_prime != prime) { + emit primeChanged(prime); + } } } diff --git a/selfdrive/ui/ui.h b/selfdrive/ui/ui.h index cac8995278..bd9d059422 100644 --- a/selfdrive/ui/ui.h +++ b/selfdrive/ui/ui.h @@ -164,6 +164,7 @@ public: void setPrimeType(PrimeType type); inline PrimeType primeType() const { return prime_type; } + inline bool hasPrime() const { return prime_type != PrimeType::UNKNOWN && prime_type != PrimeType::NONE; } int fb_w = 0, fb_h = 0; @@ -179,6 +180,7 @@ public: signals: void uiUpdate(const UIState &s); void offroadTransition(bool offroad); + void primeChanged(bool prime); void primeTypeChanged(PrimeType prime_type); private slots: