diff --git a/selfdrive/ui/sunnypilot/qt/offroad/settings/sunnypilot_panel.cc b/selfdrive/ui/sunnypilot/qt/offroad/settings/sunnypilot_panel.cc index 38b62a229f..57b38c8f91 100644 --- a/selfdrive/ui/sunnypilot/qt/offroad/settings/sunnypilot_panel.cc +++ b/selfdrive/ui/sunnypilot/qt/offroad/settings/sunnypilot_panel.cc @@ -34,6 +34,7 @@ SunnypilotPanel::SunnypilotPanel(SettingsWindowSP *parent) : QFrame(parent) { main_layout->setCurrentWidget(madsWidget); }); madsSettingsButton->setEnabled(madsToggle->isToggled()); + QObject::connect(madsToggle, &ToggleControl::toggleFlipped, madsSettingsButton, &SubPanelButton::setEnabled); madsWidget = new MadsSettings(this); connect(madsWidget, &MadsSettings::backPress, [=]() { @@ -42,9 +43,9 @@ SunnypilotPanel::SunnypilotPanel(SettingsWindowSP *parent) : QFrame(parent) { }); list->addItem(madsSettingsButton); - QObject::connect(madsToggle, &ToggleControl::toggleFlipped, [=](bool state) { - madsSettingsButton->setEnabled(state); - }); + toggleOffroadOnly = { + madsToggle, + }; QObject::connect(uiState(), &UIState::offroadTransition, this, &SunnypilotPanel::updateToggles); sunnypilotScroller = new ScrollViewSP(list, this); @@ -81,5 +82,9 @@ void SunnypilotPanel::hideEvent(QHideEvent *event) { } void SunnypilotPanel::updateToggles(bool _offroad) { + for (auto *toggle : toggleOffroadOnly) { + toggle->setEnabled(_offroad); + } + offroad = _offroad; } diff --git a/selfdrive/ui/sunnypilot/qt/offroad/settings/sunnypilot_panel.h b/selfdrive/ui/sunnypilot/qt/offroad/settings/sunnypilot_panel.h index d6f1ea81fd..231eddf1ee 100644 --- a/selfdrive/ui/sunnypilot/qt/offroad/settings/sunnypilot_panel.h +++ b/selfdrive/ui/sunnypilot/qt/offroad/settings/sunnypilot_panel.h @@ -31,6 +31,7 @@ private: QStackedLayout* main_layout = nullptr; QWidget* sunnypilotScreen = nullptr; ScrollViewSP *sunnypilotScroller = nullptr; + std::vector toggleOffroadOnly; bool offroad; ParamControl *madsToggle;