mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-08-24 02:13:46 +08:00
slc ui
This commit is contained in:
@@ -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")
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
@@ -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<QString> slc_engage_texts{
|
||||
SLCEngageTypeText[static_cast<int>(SLCEngageType::AUTO)],
|
||||
SLCEngageTypeText[static_cast<int>(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<QString> slc_offset_texts{
|
||||
SLCOffsetTypeText[static_cast<int>(SLCOffsetType::NONE)],
|
||||
SLCOffsetTypeText[static_cast<int>(SLCOffsetType::FIXED)],
|
||||
SLCOffsetTypeText[static_cast<int>(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<SLCEngageType>(std::stoi(params.get("SpeedLimitEngageType")))));
|
||||
slc_offset->setDescription(offsetDescription(static_cast<SLCOffsetType>(std::stoi(params.get("SpeedLimitOffsetType")))));
|
||||
|
||||
QString offsetLabel = QString::fromStdString(params.get("SpeedLimitValueOffset"));
|
||||
if (static_cast<SLCOffsetType>(std::stoi(params.get("SpeedLimitOffsetType"))) == SLCOffsetType::PERCENT) {
|
||||
offsetLabel += "%";
|
||||
}
|
||||
|
||||
if (static_cast<SLCOffsetType>(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();
|
||||
}
|
||||
@@ -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 = "<font color='white'><b>" + user_str + "</b></font>";
|
||||
} else {
|
||||
auto_str = "<font color='white'><b>" + auto_str + "</b></font>";
|
||||
}
|
||||
|
||||
return QString("%1<br>%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 = "<font color='white'><b>" + fixed_str + "</b></font>";
|
||||
} else if (type == SLCOffsetType::PERCENT) {
|
||||
percent_str = "<font color='white'><b>" + percent_str + "</b></font>";
|
||||
} else {
|
||||
none_str = "<font color='white'><b>" + none_str + "</b></font>";
|
||||
}
|
||||
|
||||
return QString("%1<br>%2<br>%3")
|
||||
.arg(none_str)
|
||||
.arg(fixed_str)
|
||||
.arg(percent_str);
|
||||
}
|
||||
};
|
||||
@@ -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<QString> slc_policy_texts{
|
||||
SLCSourcePolicyText[static_cast<int>(SLCSourcePolicy::CAR_ONLY)],
|
||||
SLCSourcePolicyText[static_cast<int>(SLCSourcePolicy::MAP_ONLY)],
|
||||
SLCSourcePolicyText[static_cast<int>(SLCSourcePolicy::CAR_FIRST)],
|
||||
SLCSourcePolicyText[static_cast<int>(SLCSourcePolicy::MAP_FIRST)],
|
||||
SLCSourcePolicyText[static_cast<int>(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<SLCSourcePolicy>(std::stoi(params.get("SpeedLimitControlPolicy")))));
|
||||
slc_policy->showDescription();
|
||||
}
|
||||
|
||||
void SpeedLimitControlSource::showEvent(QShowEvent *event) {
|
||||
refresh();
|
||||
}
|
||||
@@ -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 <qt5/QtWidgets/QWidget>
|
||||
|
||||
#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 = "<font color='white'><b>" + car_only + "</b></font>";
|
||||
} else if (type == SLCSourcePolicy::MAP_ONLY) {
|
||||
map_only = "<font color='white'><b>" + map_only + "</b></font>";
|
||||
} else if (type == SLCSourcePolicy::CAR_FIRST) {
|
||||
car_first = "<font color='white'><b>" + car_first + "</b></font>";
|
||||
} else if (type == SLCSourcePolicy::MAP_FIRST) {
|
||||
map_first = "<font color='white'><b>" + map_first + "</b></font>";
|
||||
} else {
|
||||
combined = "<font color='white'><b>" + combined + "</b></font>";
|
||||
}
|
||||
|
||||
return QString("%1<br>%2<br>%3<br>%4<br>%5")
|
||||
.arg(car_only)
|
||||
.arg(map_only)
|
||||
.arg(car_first)
|
||||
.arg(map_first)
|
||||
.arg(combined);
|
||||
}
|
||||
};
|
||||
@@ -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<QString> slc_warning_texts{
|
||||
SLCWarningTypeText[static_cast<int>(SLCWarningType::OFF)],
|
||||
SLCWarningTypeText[static_cast<int>(SLCWarningType::DISPLAY)],
|
||||
SLCWarningTypeText[static_cast<int>(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<QString> slc_warning_offset_texts{
|
||||
SLCOffsetTypeText[static_cast<int>(SLCOffsetType::NONE)],
|
||||
SLCOffsetTypeText[static_cast<int>(SLCOffsetType::FIXED)],
|
||||
SLCOffsetTypeText[static_cast<int>(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<SLCWarningType>(std::stoi(params.get("SpeedLimitWarningType")))));
|
||||
slc_warning_offset->setDescription(offsetDescription(static_cast<SLCOffsetType>(std::stoi(params.get("SpeedLimitWarningOffsetType")))));
|
||||
|
||||
QString offsetLabel = QString::fromStdString(params.get("SpeedLimitWarningValueOffset"));
|
||||
if (static_cast<SLCOffsetType>(std::stoi(params.get("SpeedLimitWarningOffsetType"))) == SLCOffsetType::PERCENT) {
|
||||
offsetLabel += "%";
|
||||
}
|
||||
|
||||
if (static_cast<SLCOffsetType>(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();
|
||||
}
|
||||
@@ -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 <qt5/QtWidgets/QWidget>
|
||||
|
||||
#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 = "<font color='white'><b>" + display_str + "</b></font>";
|
||||
} else if (type == SLCWarningType::CHIME) {
|
||||
chime_str = "<font color='white'><b>" + chime_str + "</b></font>";
|
||||
} else {
|
||||
off_str = "<font color='white'><b>" + off_str + "</b></font>";
|
||||
}
|
||||
|
||||
return QString("%1<br>%2<br>%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 = "<font color='white'><b>" + fixed_str + "</b></font>";
|
||||
} else if (type == SLCOffsetType::PERCENT) {
|
||||
percent_str = "<font color='white'><b>" + percent_str + "</b></font>";
|
||||
} else {
|
||||
none_str = "<font color='white'><b>" + none_str + "</b></font>";
|
||||
}
|
||||
|
||||
return QString("%1<br>%2<br>%3")
|
||||
.arg(none_str)
|
||||
.arg(fixed_str)
|
||||
.arg(percent_str);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user