From b5084ab97de6a059512f16d6d00dfae5dc73c15e Mon Sep 17 00:00:00 2001 From: nayan8teen Date: Sun, 1 Jun 2025 15:58:50 -0400 Subject: [PATCH] slc ui --- selfdrive/ui/sunnypilot/SConscript | 8 +- .../qt/offroad/settings/longitudinal_panel.cc | 68 ++++++++++ .../qt/offroad/settings/longitudinal_panel.h | 22 ++++ .../settings/slc/speed_limit_control.cc | 109 ++++++++++++++++ .../settings/slc/speed_limit_control.h | 118 ++++++++++++++++++ .../slc/speed_limit_control_source.cc | 49 ++++++++ .../settings/slc/speed_limit_control_source.h | 58 +++++++++ .../slc/speed_limit_control_warning.cc | 95 ++++++++++++++ .../slc/speed_limit_control_warning.h | 73 +++++++++++ 9 files changed, 599 insertions(+), 1 deletion(-) create mode 100644 selfdrive/ui/sunnypilot/qt/offroad/settings/slc/speed_limit_control.cc create mode 100644 selfdrive/ui/sunnypilot/qt/offroad/settings/slc/speed_limit_control.h create mode 100644 selfdrive/ui/sunnypilot/qt/offroad/settings/slc/speed_limit_control_source.cc create mode 100644 selfdrive/ui/sunnypilot/qt/offroad/settings/slc/speed_limit_control_source.h create mode 100644 selfdrive/ui/sunnypilot/qt/offroad/settings/slc/speed_limit_control_warning.cc create mode 100644 selfdrive/ui/sunnypilot/qt/offroad/settings/slc/speed_limit_control_warning.h diff --git a/selfdrive/ui/sunnypilot/SConscript b/selfdrive/ui/sunnypilot/SConscript index 4a6a44640b..358c211de6 100644 --- a/selfdrive/ui/sunnypilot/SConscript +++ b/selfdrive/ui/sunnypilot/SConscript @@ -56,6 +56,12 @@ osm_panel_qt_src = [ "sunnypilot/qt/offroad/settings/osm/models_fetcher.cc", ] +slc_panel_qt_src = [ + "sunnypilot/qt/offroad/settings/slc/speed_limit_control.cc", + "sunnypilot/qt/offroad/settings/slc/speed_limit_control_source.cc", + "sunnypilot/qt/offroad/settings/slc/speed_limit_control_warning.cc", +] + vehicle_panel_qt_src = [ "sunnypilot/qt/offroad/settings/vehicle/brand_settings_factory.cc", "sunnypilot/qt/offroad/settings/vehicle/brand_settings_interface.cc", @@ -78,7 +84,7 @@ brand_settings_qt_src = [ ] sp_widgets_src = widgets_src + network_src -sp_qt_src = qt_src + lateral_panel_qt_src + vehicle_panel_qt_src + brand_settings_qt_src + osm_panel_qt_src +sp_qt_src = qt_src + lateral_panel_qt_src + vehicle_panel_qt_src + brand_settings_qt_src + osm_panel_qt_src + slc_panel_qt_src sp_qt_util = qt_util Export('sp_widgets_src', 'sp_qt_src', "sp_qt_util") diff --git a/selfdrive/ui/sunnypilot/qt/offroad/settings/longitudinal_panel.cc b/selfdrive/ui/sunnypilot/qt/offroad/settings/longitudinal_panel.cc index 9d8a4d9c19..11006150be 100644 --- a/selfdrive/ui/sunnypilot/qt/offroad/settings/longitudinal_panel.cc +++ b/selfdrive/ui/sunnypilot/qt/offroad/settings/longitudinal_panel.cc @@ -8,4 +8,72 @@ #include "selfdrive/ui/sunnypilot/qt/offroad/settings/longitudinal_panel.h" LongitudinalPanel::LongitudinalPanel(QWidget *parent) : QWidget(parent) { + setStyleSheet(R"( + #back_btn { + font-size: 50px; + margin: 0px; + padding: 15px; + border-width: 0; + border-radius: 30px; + color: #dddddd; + background-color: #393939; + } + #back_btn:pressed { + background-color: #4a4a4a; + } + )"); + + main_layout = new QStackedLayout(this); + ListWidget *list = new ListWidget(this, false); + + cruisePanelScreen = new QWidget(this); + QVBoxLayout* vlayout = new QVBoxLayout(cruisePanelScreen); + vlayout->setContentsMargins(50, 20, 50, 20); + + cruisePanelScroller = new ScrollViewSP(list, this); + vlayout->addWidget(cruisePanelScroller); + + slcControl = new SpeedLimitControl( + "SpeedLimitControl", + tr("Speed Limit Control (SLC)"), + tr("When you engage ACC, you will be prompted to set the cruising speed to the speed limit of the road adjusted by the Offset and Source Policy specified, or the current driving speed. " + "The maximum cruising speed will always be the MAX set speed."), + "", + this); + list->addItem(slcControl); + connect(slcControl, &SpeedLimitControl::toggleFlipped, this, &LongitudinalPanel::refresh); + connect(slcControl, &SpeedLimitControl::slcWarningButtonClicked, this, &LongitudinalPanel::handleSlcWarningButtonClick); + connect(slcControl, &SpeedLimitControl::slcSourceButtonClicked, this, &LongitudinalPanel::handleSLCSourceButtonClick); + + slcWarningScreen = new SpeedLimitControlWarning(this); + connect(slcWarningScreen, &SpeedLimitControlWarning::backPress, this, &LongitudinalPanel::handleSLCBackButtonClick); + slcSourceScreen = new SpeedLimitControlSource(this); + connect(slcSourceScreen, &SpeedLimitControlSource::backPress, this, &LongitudinalPanel::handleSLCBackButtonClick); + + + main_layout->addWidget(cruisePanelScreen); + main_layout->addWidget(slcWarningScreen); + main_layout->addWidget(slcSourceScreen); + main_layout->setCurrentWidget(cruisePanelScreen); +} + +void LongitudinalPanel::handleSlcWarningButtonClick() { + main_layout->setCurrentWidget(slcWarningScreen); +} + +void LongitudinalPanel::handleSLCSourceButtonClick() { + main_layout->setCurrentWidget(slcSourceScreen); +} + +void LongitudinalPanel::handleSLCBackButtonClick() { + main_layout->setCurrentWidget(cruisePanelScreen); +} + +void LongitudinalPanel::showEvent(QShowEvent *event) { + main_layout->setCurrentWidget(cruisePanelScreen); + refresh(); +} + +void LongitudinalPanel::refresh() { + slcControl->refresh(); } diff --git a/selfdrive/ui/sunnypilot/qt/offroad/settings/longitudinal_panel.h b/selfdrive/ui/sunnypilot/qt/offroad/settings/longitudinal_panel.h index cd68e3ec2f..2a6c98458c 100644 --- a/selfdrive/ui/sunnypilot/qt/offroad/settings/longitudinal_panel.h +++ b/selfdrive/ui/sunnypilot/qt/offroad/settings/longitudinal_panel.h @@ -7,11 +7,33 @@ #pragma once +#include "selfdrive/ui/sunnypilot/ui.h" #include "selfdrive/ui/sunnypilot/qt/offroad/settings/settings.h" +#include "selfdrive/ui/sunnypilot/qt/offroad/settings/slc/speed_limit_control.h" +#include "selfdrive/ui/sunnypilot/qt/offroad/settings/slc/speed_limit_control_warning.h" +#include "selfdrive/ui/sunnypilot/qt/offroad/settings/slc/speed_limit_control_source.h" +#include "selfdrive/ui/sunnypilot/qt/widgets/scrollview.h" class LongitudinalPanel : public QWidget { Q_OBJECT public: explicit LongitudinalPanel(QWidget *parent = nullptr); + void showEvent(QShowEvent *event) override; + void refresh(); + +private slots: + void handleSlcWarningButtonClick(); + void handleSLCSourceButtonClick(); + void handleSLCBackButtonClick(); + +private: + Params params; + QStackedLayout *main_layout = nullptr; + ScrollViewSP *cruisePanelScroller = nullptr; + QWidget *cruisePanelScreen = nullptr; + + SpeedLimitControl *slcControl; + SpeedLimitControlWarning *slcWarningScreen; + SpeedLimitControlSource *slcSourceScreen; }; diff --git a/selfdrive/ui/sunnypilot/qt/offroad/settings/slc/speed_limit_control.cc b/selfdrive/ui/sunnypilot/qt/offroad/settings/slc/speed_limit_control.cc new file mode 100644 index 0000000000..72edda3216 --- /dev/null +++ b/selfdrive/ui/sunnypilot/qt/offroad/settings/slc/speed_limit_control.cc @@ -0,0 +1,109 @@ +/** + * Copyright (c) 2021-, Haibin Wen, sunnypilot, and a number of other contributors. + * + * This file is part of sunnypilot and is licensed under the MIT License. + * See the LICENSE.md file in the root directory for more details. + */ + +#include "selfdrive/ui/sunnypilot/qt/offroad/settings/slc/speed_limit_control.h" + +SpeedLimitControl::SpeedLimitControl(const QString ¶m, const QString &title, const QString &desc, const QString &icon, QWidget *parent) + : ExpandableToggleRow(param, title, desc, icon, parent) { + + auto *slcFrame = new QFrame(this); + auto *slcFrameLayout = new QVBoxLayout(); + slcFrame->setLayout(slcFrameLayout); + slcFrameLayout->setSpacing(0); + + auto *slcBtnFrame = new QFrame(this); + auto *slcBtnFrameLayout = new QGridLayout(); + slcBtnFrame->setLayout(slcBtnFrameLayout); + slcBtnFrameLayout->setSpacing(0); + + slcWarningControl = new PushButtonSP(tr("Customize Warning")); + connect(slcWarningControl, &QPushButton::clicked, this, &SpeedLimitControl::slcWarningButtonClicked); + + slcSourceControl = new PushButtonSP(tr("Customize Source")); + connect(slcSourceControl, &QPushButton::clicked, this, &SpeedLimitControl::slcSourceButtonClicked); + + slcWarningControl->setFixedWidth(650); + slcSourceControl->setFixedWidth(650); + slcBtnFrameLayout->addWidget(slcWarningControl, 0, 0, Qt::AlignLeft); + slcBtnFrameLayout->addWidget(slcSourceControl, 0, 1, Qt::AlignRight); + slcFrameLayout->addWidget(slcBtnFrame); + + + std::vector slc_engage_texts{ + SLCEngageTypeText[static_cast(SLCEngageType::AUTO)], + SLCEngageTypeText[static_cast(SLCEngageType::USER_CONFIRM)]}; + slc_engage_setting = new ButtonParamControlSP( + "SpeedLimitEngageType", + tr("Engage Mode"), + "", + "", + slc_engage_texts, + 300); + slcFrameLayout->addWidget(slc_engage_setting); + + QFrame *offsetFrame = new QFrame(this); + QVBoxLayout *offsetLayout = new QVBoxLayout(offsetFrame); + + std::vector slc_offset_texts{ + SLCOffsetTypeText[static_cast(SLCOffsetType::NONE)], + SLCOffsetTypeText[static_cast(SLCOffsetType::FIXED)], + SLCOffsetTypeText[static_cast(SLCOffsetType::PERCENT)]}; + slc_offset_setting = new ButtonParamControlSP( + "SpeedLimitOffsetType", + tr("Speed Limit Offset"), + "", + "", + slc_offset_texts, + 300); + + offsetLayout->addWidget(slc_offset_setting); + + slc_offset = new OptionControlSP( + "SpeedLimitValueOffset", + "", + "", + "", + {-30, 30} + ); + slc_offset->setFixedWidth(100); + offsetLayout->addWidget(slc_offset); + + slcFrameLayout->addWidget(offsetFrame); + + connect(slc_offset, &OptionControlSP::updateLabels, this, &SpeedLimitControl::refresh); + connect(slc_offset_setting, &ButtonParamControlSP::showDescriptionEvent, slc_offset, &OptionControlSP::showDescription); + connect(slc_engage_setting, &ButtonParamControlSP::buttonClicked, this, &SpeedLimitControl::refresh); + connect(slc_offset_setting, &ButtonParamControlSP::buttonClicked, this, &SpeedLimitControl::refresh); + + refresh(); + addItem(slcFrame); +} + +void SpeedLimitControl::refresh() { + slc_engage_setting->setDescription(engageModeDescription(static_cast(std::stoi(params.get("SpeedLimitEngageType"))))); + slc_offset->setDescription(offsetDescription(static_cast(std::stoi(params.get("SpeedLimitOffsetType"))))); + + QString offsetLabel = QString::fromStdString(params.get("SpeedLimitValueOffset")); + if (static_cast(std::stoi(params.get("SpeedLimitOffsetType"))) == SLCOffsetType::PERCENT) { + offsetLabel += "%"; + } + + if (static_cast(std::stoi(params.get("SpeedLimitOffsetType"))) == SLCOffsetType::NONE) { + slc_offset->setDisabled(true); + slc_offset->setLabel(tr("N/A")); + } else { + slc_offset->setDisabled(false); + slc_offset->setLabel(offsetLabel); + } + + slc_engage_setting->showDescription(); + slc_offset->showDescription(); +} + +void SpeedLimitControl::showEvent(QShowEvent *event) { + refresh(); +} diff --git a/selfdrive/ui/sunnypilot/qt/offroad/settings/slc/speed_limit_control.h b/selfdrive/ui/sunnypilot/qt/offroad/settings/slc/speed_limit_control.h new file mode 100644 index 0000000000..0d6a22ff7c --- /dev/null +++ b/selfdrive/ui/sunnypilot/qt/offroad/settings/slc/speed_limit_control.h @@ -0,0 +1,118 @@ +/* + * Copyright (c) 2021-, Haibin Wen, sunnypilot, and a number of other contributors. + * + * This file is part of sunnypilot and is licensed under the MIT License. + * See the LICENSE.md file in the root directory for more details. + */ + +#pragma once + +#include "selfdrive/ui/sunnypilot/ui.h" +#include "selfdrive/ui/sunnypilot/qt/offroad/settings/settings.h" +#include "selfdrive/ui/sunnypilot/qt/widgets/controls.h" +#include "selfdrive/ui/sunnypilot/qt/widgets/expandable_row.h" + +enum class SLCEngageType { + AUTO, + USER_CONFIRM, +}; + +inline const char *SLCEngageTypeText[] { + QT_TR_NOOP("Auto"), + QT_TR_NOOP("User Confirm") +}; + +enum class SLCOffsetType { + NONE, + FIXED, + PERCENT, +}; + +inline const char *SLCOffsetTypeText[] { + QT_TR_NOOP("None"), + QT_TR_NOOP("Fixed"), + QT_TR_NOOP("Percent"), +}; + +enum class SLCWarningType { + OFF, + DISPLAY, + CHIME, +}; + +inline const char *SLCWarningTypeText[] { + QT_TR_NOOP("Off"), + QT_TR_NOOP("Display"), + QT_TR_NOOP("Chime") +}; + +enum class SLCSourcePolicy { + CAR_ONLY, + MAP_ONLY, + CAR_FIRST, + MAP_FIRST, + COMBINED +}; + +inline const char *SLCSourcePolicyText[] { + QT_TR_NOOP("Car\nOnly"), + QT_TR_NOOP("Map\nOnly"), + QT_TR_NOOP("Car\nFirst"), + QT_TR_NOOP("Map\nFirst"), + QT_TR_NOOP("Combined") +}; + +class SpeedLimitControl : public ExpandableToggleRow { + Q_OBJECT + +public: + SpeedLimitControl(const QString ¶m, const QString &title, const QString &desc, const QString &icon, QWidget *parent = nullptr); + void refresh(); + void showEvent(QShowEvent *event) override; + +signals: + void slcWarningButtonClicked(); + void slcSourceButtonClicked(); + +private: + Params params; + PushButtonSP *slcWarningControl; + PushButtonSP *slcSourceControl; + ButtonParamControlSP *slc_offset_setting; + OptionControlSP *slc_offset; + ButtonParamControlSP *slc_engage_setting; + + static QString engageModeDescription(SLCEngageType type = SLCEngageType::AUTO) { + QString auto_str = tr("⦿ Auto: Automatic speed adjustment based on speed limit data"); + QString user_str = tr("⦿ User Confirm: Asks driver to confirm speed adjustment based on speed limit data"); + + if (type == SLCEngageType::USER_CONFIRM) { + user_str = "" + user_str + ""; + } else { + auto_str = "" + auto_str + ""; + } + + return QString("%1
%2") + .arg(auto_str) + .arg(user_str); + } + + static QString offsetDescription(SLCOffsetType type = SLCOffsetType::NONE) { + QString none_str = tr("⦿ None: No Offset"); + QString fixed_str = tr("⦿ Fixed: Adds a fixed offset [Speed Limit + Offset]"); + QString percent_str = tr("⦿ Percent: Adds a percent offset [Speed Limit + (Offset % Speed Limit)]"); + + if (type == SLCOffsetType::FIXED) { + fixed_str = "" + fixed_str + ""; + } else if (type == SLCOffsetType::PERCENT) { + percent_str = "" + percent_str + ""; + } else { + none_str = "" + none_str + ""; + } + + return QString("%1
%2
%3") + .arg(none_str) + .arg(fixed_str) + .arg(percent_str); + } +}; diff --git a/selfdrive/ui/sunnypilot/qt/offroad/settings/slc/speed_limit_control_source.cc b/selfdrive/ui/sunnypilot/qt/offroad/settings/slc/speed_limit_control_source.cc new file mode 100644 index 0000000000..d9e3583e56 --- /dev/null +++ b/selfdrive/ui/sunnypilot/qt/offroad/settings/slc/speed_limit_control_source.cc @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2021-, Haibin Wen, sunnypilot, and a number of other contributors. + * + * This file is part of sunnypilot and is licensed under the MIT License. + * See the LICENSE.md file in the root directory for more details. + */ + +#include "selfdrive/ui/sunnypilot/qt/offroad/settings/slc/speed_limit_control_source.h" + +SpeedLimitControlSource::SpeedLimitControlSource(QWidget *parent) : QWidget(parent) { + QVBoxLayout* main_layout = new QVBoxLayout(this); + main_layout->setContentsMargins(50, 20, 50, 20); + main_layout->setSpacing(20); + + // Back button + PanelBackButton* back = new PanelBackButton(tr("Back")); + connect(back, &QPushButton::clicked, [=]() { emit backPress(); }); + main_layout->addWidget(back, 0, Qt::AlignLeft); + + ListWidgetSP *list = new ListWidgetSP(this, true); + + std::vector slc_policy_texts{ + SLCSourcePolicyText[static_cast(SLCSourcePolicy::CAR_ONLY)], + SLCSourcePolicyText[static_cast(SLCSourcePolicy::MAP_ONLY)], + SLCSourcePolicyText[static_cast(SLCSourcePolicy::CAR_FIRST)], + SLCSourcePolicyText[static_cast(SLCSourcePolicy::MAP_FIRST)], + SLCSourcePolicyText[static_cast(SLCSourcePolicy::COMBINED)]}; + slc_policy = new ButtonParamControlSP( + "SpeedLimitControlPolicy", + tr("Speed Limit Source"), + "", + "", + slc_policy_texts, + 250); + list->addItem(slc_policy); + connect(slc_policy, &ButtonParamControlSP::buttonClicked, this, &SpeedLimitControlSource::refresh); + + refresh(); + main_layout->addWidget(list); +}; + +void SpeedLimitControlSource::refresh() { + slc_policy->setDescription(sourceDescription(static_cast(std::stoi(params.get("SpeedLimitControlPolicy"))))); + slc_policy->showDescription(); +} + +void SpeedLimitControlSource::showEvent(QShowEvent *event) { + refresh(); +} diff --git a/selfdrive/ui/sunnypilot/qt/offroad/settings/slc/speed_limit_control_source.h b/selfdrive/ui/sunnypilot/qt/offroad/settings/slc/speed_limit_control_source.h new file mode 100644 index 0000000000..884c23146e --- /dev/null +++ b/selfdrive/ui/sunnypilot/qt/offroad/settings/slc/speed_limit_control_source.h @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2021-, Haibin Wen, sunnypilot, and a number of other contributors. + * + * This file is part of sunnypilot and is licensed under the MIT License. + * See the LICENSE.md file in the root directory for more details. + */ + +#pragma once + +#include + +#include "selfdrive/ui/sunnypilot/ui.h" +#include "selfdrive/ui/sunnypilot/qt/offroad/settings/settings.h" +#include "selfdrive/ui/sunnypilot/qt/offroad/settings/slc/speed_limit_control.h" +#include "selfdrive/ui/sunnypilot/qt/widgets/controls.h" + +class SpeedLimitControlSource : public QWidget { + Q_OBJECT + +public: + explicit SpeedLimitControlSource(QWidget *parent = nullptr); + void refresh(); + void showEvent(QShowEvent *event) override; + +signals: + void backPress(); + +private: + Params params; + ButtonParamControlSP *slc_policy; + + static QString sourceDescription(SLCSourcePolicy type = SLCSourcePolicy::CAR_ONLY) { + QString car_only = tr("⦿ Car Only: "); + QString map_only = tr("⦿ Map Only: "); + QString car_first = tr("⦿ Car First: "); + QString map_first = tr("⦿ Map First: "); + QString combined = tr("⦿ Combined: "); + + if (type == SLCSourcePolicy::CAR_ONLY) { + car_only = "" + car_only + ""; + } else if (type == SLCSourcePolicy::MAP_ONLY) { + map_only = "" + map_only + ""; + } else if (type == SLCSourcePolicy::CAR_FIRST) { + car_first = "" + car_first + ""; + } else if (type == SLCSourcePolicy::MAP_FIRST) { + map_first = "" + map_first + ""; + } else { + combined = "" + combined + ""; + } + + return QString("%1
%2
%3
%4
%5") + .arg(car_only) + .arg(map_only) + .arg(car_first) + .arg(map_first) + .arg(combined); + } +}; diff --git a/selfdrive/ui/sunnypilot/qt/offroad/settings/slc/speed_limit_control_warning.cc b/selfdrive/ui/sunnypilot/qt/offroad/settings/slc/speed_limit_control_warning.cc new file mode 100644 index 0000000000..5b0722f08c --- /dev/null +++ b/selfdrive/ui/sunnypilot/qt/offroad/settings/slc/speed_limit_control_warning.cc @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2021-, Haibin Wen, sunnypilot, and a number of other contributors. + * + * This file is part of sunnypilot and is licensed under the MIT License. + * See the LICENSE.md file in the root directory for more details. + */ + +#include "selfdrive/ui/sunnypilot/qt/offroad/settings/slc/speed_limit_control_warning.h" + +SpeedLimitControlWarning::SpeedLimitControlWarning(QWidget *parent) : QWidget(parent) { + QVBoxLayout* main_layout = new QVBoxLayout(this); + main_layout->setContentsMargins(50, 20, 50, 20); + main_layout->setSpacing(20); + + // Back button + PanelBackButton* back = new PanelBackButton(tr("Back")); + connect(back, &QPushButton::clicked, [=]() { emit backPress(); }); + main_layout->addWidget(back, 0, Qt::AlignLeft); + + ListWidgetSP *list = new ListWidgetSP(this, true); + + std::vector slc_warning_texts{ + SLCWarningTypeText[static_cast(SLCWarningType::OFF)], + SLCWarningTypeText[static_cast(SLCWarningType::DISPLAY)], + SLCWarningTypeText[static_cast(SLCWarningType::CHIME)]}; + slc_warning_settings = new ButtonParamControlSP( + "SpeedLimitWarningType", tr("Speed Limit Warning"), + "", + "", + slc_warning_texts, + 300); + list->addItem(slc_warning_settings); + + QFrame *offsetFrame = new QFrame(this); + QVBoxLayout *offsetLayout = new QVBoxLayout(offsetFrame); + + std::vector slc_warning_offset_texts{ + SLCOffsetTypeText[static_cast(SLCOffsetType::NONE)], + SLCOffsetTypeText[static_cast(SLCOffsetType::FIXED)], + SLCOffsetTypeText[static_cast(SLCOffsetType::PERCENT)]}; + slc_warning_offset_settings = new ButtonParamControlSP( + "SpeedLimitWarningOffsetType", + tr("Warning Offset"), + tr(""), + "", + slc_warning_offset_texts, + 300); + offsetLayout->addWidget(slc_warning_offset_settings); + + slc_warning_offset = new OptionControlSP( + "SpeedLimitWarningValueOffset", + "", + "", + "", + {-30, 30} + ); + slc_warning_offset->setFixedWidth(100); + offsetLayout->addWidget(slc_warning_offset); + + list->addItem(offsetFrame); + + connect(slc_warning_offset, &OptionControlSP::updateLabels, this, &SpeedLimitControlWarning::refresh); + connect(slc_warning_offset_settings, &ButtonParamControlSP::showDescriptionEvent, slc_warning_offset, &OptionControlSP::showDescription); + connect(slc_warning_settings, &ButtonParamControlSP::buttonClicked, this, &SpeedLimitControlWarning::refresh); + connect(slc_warning_offset_settings, &ButtonParamControlSP::buttonClicked, this, &SpeedLimitControlWarning::refresh); + + refresh(); + main_layout->addWidget(list); + +}; + +void SpeedLimitControlWarning::refresh() { + slc_warning_settings->setDescription(warningDescription(static_cast(std::stoi(params.get("SpeedLimitWarningType"))))); + slc_warning_offset->setDescription(offsetDescription(static_cast(std::stoi(params.get("SpeedLimitWarningOffsetType"))))); + + QString offsetLabel = QString::fromStdString(params.get("SpeedLimitWarningValueOffset")); + if (static_cast(std::stoi(params.get("SpeedLimitWarningOffsetType"))) == SLCOffsetType::PERCENT) { + offsetLabel += "%"; + } + + if (static_cast(std::stoi(params.get("SpeedLimitWarningOffsetType"))) == SLCOffsetType::NONE) { + slc_warning_offset->setDisabled(true); + slc_warning_offset->setLabel(tr("N/A")); + } else { + slc_warning_offset->setDisabled(false); + slc_warning_offset->setLabel(offsetLabel); + } + + slc_warning_settings->showDescription(); + slc_warning_offset->showDescription(); +} + +void SpeedLimitControlWarning::showEvent(QShowEvent *event) { + refresh(); +} diff --git a/selfdrive/ui/sunnypilot/qt/offroad/settings/slc/speed_limit_control_warning.h b/selfdrive/ui/sunnypilot/qt/offroad/settings/slc/speed_limit_control_warning.h new file mode 100644 index 0000000000..a375130fa2 --- /dev/null +++ b/selfdrive/ui/sunnypilot/qt/offroad/settings/slc/speed_limit_control_warning.h @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2021-, Haibin Wen, sunnypilot, and a number of other contributors. + * + * This file is part of sunnypilot and is licensed under the MIT License. + * See the LICENSE.md file in the root directory for more details. + */ + +#pragma once + +#include + +#include "selfdrive/ui/sunnypilot/ui.h" +#include "selfdrive/ui/sunnypilot/qt/offroad/settings/settings.h" +#include "selfdrive/ui/sunnypilot/qt/offroad/settings/slc/speed_limit_control.h" +#include "selfdrive/ui/sunnypilot/qt/widgets/controls.h" + +class SpeedLimitControlWarning : public QWidget { + Q_OBJECT + +public: + SpeedLimitControlWarning(QWidget *parent = nullptr); + + void refresh(); + void showEvent(QShowEvent *event) override; + +signals: + void backPress(); + +private: + Params params; + + ButtonParamControlSP *slc_warning_settings; + ButtonParamControlSP *slc_warning_offset_settings; + OptionControlSP *slc_warning_offset; + + static QString warningDescription(SLCWarningType type = SLCWarningType::OFF) { + QString off_str = tr("⦿ Off: No Warning"); + QString display_str = tr("⦿ Display: Speed Limit Sign will visually alert"); + QString chime_str = tr("⦿ Chime: Speed Limit Sign will visually alert along with an audible chime"); + + if (type == SLCWarningType::DISPLAY) { + display_str = "" + display_str + ""; + } else if (type == SLCWarningType::CHIME) { + chime_str = "" + chime_str + ""; + } else { + off_str = "" + off_str + ""; + } + + return QString("%1
%2
%3") + .arg(off_str) + .arg(display_str) + .arg(chime_str); + } + + static QString offsetDescription(SLCOffsetType type = SLCOffsetType::NONE) { + QString none_str = tr("⦿ None: No Offset"); + QString fixed_str = tr("⦿ Fixed: Adds a fixed offset [Speed Limit + Offset]"); + QString percent_str = tr("⦿ Percent: Adds a percent offset [Speed Limit + (Offset % Speed Limit)]"); + + if (type == SLCOffsetType::FIXED) { + fixed_str = "" + fixed_str + ""; + } else if (type == SLCOffsetType::PERCENT) { + percent_str = "" + percent_str + ""; + } else { + none_str = "" + none_str + ""; + } + + return QString("%1
%2
%3") + .arg(none_str) + .arg(fixed_str) + .arg(percent_str); + } +};