UI: Reset settings state when hiding panels (#20670)

* git stat

* first panel and button reset

* progress

* toggles parent + list

* check if label nullptr

* style

* fixes

* fixes

* remove line

* white space

* tabs and spaces
pull/20000/head
iejMac 4 years ago committed by GitHub
parent fe2f63849a
commit 928fbecec0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 142
      selfdrive/ui/qt/offroad/settings.cc
  2. 7
      selfdrive/ui/qt/offroad/settings.hpp
  3. 6
      selfdrive/ui/qt/widgets/controls.cc
  4. 1
      selfdrive/ui/qt/widgets/controls.hpp
  5. 4
      selfdrive/ui/qt/widgets/scrollview.cc
  6. 2
      selfdrive/ui/qt/widgets/scrollview.hpp

@ -19,70 +19,72 @@
#include "home.hpp" #include "home.hpp"
QWidget * toggles_panel() { TogglesPanel::TogglesPanel(QWidget *parent) : QWidget(parent) {
QVBoxLayout *toggles_list = new QVBoxLayout(); QVBoxLayout *toggles_list = new QVBoxLayout();
toggles_list->addWidget(new ParamControl("OpenpilotEnabledToggle", QList<ParamControl*> toggles;
"Enable openpilot",
"Use the openpilot system for adaptive cruise control and lane keep driver assistance. Your attention is required at all times to use this feature. Changing this setting takes effect when the car is powered off.", toggles.append(new ParamControl("OpenpilotEnabledToggle",
"../assets/offroad/icon_openpilot.png" "Enable openpilot",
)); "Use the openpilot system for adaptive cruise control and lane keep driver assistance. Your attention is required at all times to use this feature. Changing this setting takes effect when the car is powered off.",
toggles_list->addWidget(horizontal_line()); "../assets/offroad/icon_openpilot.png",
toggles_list->addWidget(new ParamControl("IsLdwEnabled", this));
"Enable Lane Departure Warnings", toggles.append(new ParamControl("IsLdwEnabled",
"Receive alerts to steer back into the lane when your vehicle drifts over a detected lane line without a turn signal activated while driving over 31mph (50kph).", "Enable Lane Departure Warnings",
"../assets/offroad/icon_warning.png" "Receive alerts to steer back into the lane when your vehicle drifts over a detected lane line without a turn signal activated while driving over 31mph (50kph).",
)); "../assets/offroad/icon_warning.png",
toggles_list->addWidget(horizontal_line()); this));
toggles_list->addWidget(new ParamControl("IsRHD", toggles.append(new ParamControl("IsRHD",
"Enable Right-Hand Drive", "Enable Right-Hand Drive",
"Allow openpilot to obey left-hand traffic conventions and perform driver monitoring on right driver seat.", "Allow openpilot to obey left-hand traffic conventions and perform driver monitoring on right driver seat.",
"../assets/offroad/icon_openpilot_mirrored.png" "../assets/offroad/icon_openpilot_mirrored.png",
)); this));
toggles_list->addWidget(horizontal_line()); toggles.append(new ParamControl("IsMetric",
toggles_list->addWidget(new ParamControl("IsMetric", "Use Metric System",
"Use Metric System", "Display speed in km/h instead of mp/h.",
"Display speed in km/h instead of mp/h.", "../assets/offroad/icon_metric.png",
"../assets/offroad/icon_metric.png" this));
)); toggles.append(new ParamControl("CommunityFeaturesToggle",
toggles_list->addWidget(horizontal_line()); "Enable Community Features",
toggles_list->addWidget(new ParamControl("CommunityFeaturesToggle", "Use features from the open source community that are not maintained or supported by comma.ai and have not been confirmed to meet the standard safety model. These features include community supported cars and community supported hardware. Be extra cautious when using these features",
"Enable Community Features", "../assets/offroad/icon_shell.png",
"Use features from the open source community that are not maintained or supported by comma.ai and have not been confirmed to meet the standard safety model. These features include community supported cars and community supported hardware. Be extra cautious when using these features", this));
"../assets/offroad/icon_shell.png" toggles.append(new ParamControl("IsUploadRawEnabled",
)); "Upload Raw Logs",
toggles_list->addWidget(horizontal_line()); "Upload full logs and full resolution video by default while on WiFi. If not enabled, individual logs can be marked for upload at my.comma.ai/useradmin.",
toggles_list->addWidget(new ParamControl("IsUploadRawEnabled", "../assets/offroad/icon_network.png",
"Upload Raw Logs", this));
"Upload full logs and full resolution video by default while on WiFi. If not enabled, individual logs can be marked for upload at my.comma.ai/useradmin.",
"../assets/offroad/icon_network.png"
));
toggles_list->addWidget(horizontal_line());
ParamControl *record_toggle = new ParamControl("RecordFront", ParamControl *record_toggle = new ParamControl("RecordFront",
"Record and Upload Driver Camera", "Record and Upload Driver Camera",
"Upload data from the driver facing camera and help improve the driver monitoring algorithm.", "Upload data from the driver facing camera and help improve the driver monitoring algorithm.",
"../assets/offroad/icon_monitoring.png"); "../assets/offroad/icon_monitoring.png",
toggles_list->addWidget(record_toggle); this);
toggles_list->addWidget(horizontal_line()); toggles.append(record_toggle);
toggles_list->addWidget(new ParamControl("EndToEndToggle", toggles.append(new ParamControl("EndToEndToggle",
"\U0001f96c Disable use of lanelines (Alpha) \U0001f96c", "\U0001f96c Disable use of lanelines (Alpha) \U0001f96c",
"In this mode openpilot will ignore lanelines and just drive how it thinks a human would.", "In this mode openpilot will ignore lanelines and just drive how it thinks a human would.",
"../assets/offroad/icon_road.png")); "../assets/offroad/icon_road.png",
this));
#ifdef QCOM2 #ifdef QCOM2
toggles_list->addWidget(horizontal_line()); toggles.append(new ParamControl("EnableWideCamera",
toggles_list->addWidget(new ParamControl("EnableWideCamera", "Enable use of Wide Angle Camera",
"Enable use of Wide Angle Camera", "Use wide angle camera for driving and ui. Only takes effect after reboot.",
"Use wide angle camera for driving and ui. Only takes effect after reboot.", "../assets/offroad/icon_openpilot.png",
"../assets/offroad/icon_openpilot.png")); this));
#endif #endif
bool record_lock = Params().getBool("RecordFrontLock"); bool record_lock = Params().getBool("RecordFrontLock");
record_toggle->setEnabled(!record_lock); record_toggle->setEnabled(!record_lock);
QWidget *widget = new QWidget; for(ParamControl *toggle : toggles){
widget->setLayout(toggles_list); if(toggles_list->count() != 0){
return widget; toggles_list->addWidget(horizontal_line());
}
toggles_list->addWidget(toggle);
}
setLayout(toggles_list);
} }
DevicePanel::DevicePanel(QWidget* parent) : QWidget(parent) { DevicePanel::DevicePanel(QWidget* parent) : QWidget(parent) {
@ -101,18 +103,18 @@ DevicePanel::DevicePanel(QWidget* parent) : QWidget(parent) {
QList<ButtonControl*> offroad_btns; QList<ButtonControl*> offroad_btns;
offroad_btns.append(new ButtonControl("Driver Camera", "PREVIEW", offroad_btns.append(new ButtonControl("Driver Camera", "PREVIEW",
"Preview the driver facing camera to help optimize device mounting position for best driver monitoring experience. (vehicle must be off)", "Preview the driver facing camera to help optimize device mounting position for best driver monitoring experience. (vehicle must be off)",
[=]() { [=]() {
Params().putBool("IsDriverViewEnabled", true); Params().putBool("IsDriverViewEnabled", true);
GLWindow::ui_state.scene.driver_view = true; } GLWindow::ui_state.scene.driver_view = true;
)); }, "", this));
QString resetCalibDesc = "openpilot requires the device to be mounted within 4° left or right and within 5° up or down. openpilot is continuously calibrating, resetting is rarely required."; QString resetCalibDesc = "openpilot requires the device to be mounted within 4° left or right and within 5° up or down. openpilot is continuously calibrating, resetting is rarely required.";
ButtonControl *resetCalibBtn = new ButtonControl("Reset Calibration", "RESET", resetCalibDesc, [=]() { ButtonControl *resetCalibBtn = new ButtonControl("Reset Calibration", "RESET", resetCalibDesc, [=]() {
if (ConfirmationDialog::confirm("Are you sure you want to reset calibration?")) { if (ConfirmationDialog::confirm("Are you sure you want to reset calibration?")) {
Params().remove("CalibrationParams"); Params().remove("CalibrationParams");
} }
}); }, "", this);
connect(resetCalibBtn, &ButtonControl::showDescription, [=]() { connect(resetCalibBtn, &ButtonControl::showDescription, [=]() {
QString desc = resetCalibDesc; QString desc = resetCalibDesc;
std::string calib_bytes = Params().get("CalibrationParams"); std::string calib_bytes = Params().get("CalibrationParams");
@ -138,18 +140,18 @@ DevicePanel::DevicePanel(QWidget* parent) : QWidget(parent) {
offroad_btns.append(new ButtonControl("Review Training Guide", "REVIEW", offroad_btns.append(new ButtonControl("Review Training Guide", "REVIEW",
"Review the rules, features, and limitations of openpilot", [=]() { "Review the rules, features, and limitations of openpilot", [=]() {
if (ConfirmationDialog::confirm("Are you sure you want to review the training guide?")) { if (ConfirmationDialog::confirm("Are you sure you want to review the training guide?")) {
Params().remove("CompletedTrainingVersion"); Params().remove("CompletedTrainingVersion");
emit reviewTrainingGuide(); emit reviewTrainingGuide();
} }
})); }, "", this));
QString brand = params.getBool("Passive") ? "dashcam" : "openpilot"; QString brand = params.getBool("Passive") ? "dashcam" : "openpilot";
offroad_btns.append(new ButtonControl("Uninstall " + brand, "UNINSTALL", "", [=]() { offroad_btns.append(new ButtonControl("Uninstall " + brand, "UNINSTALL", "", [=]() {
if (ConfirmationDialog::confirm("Are you sure you want to uninstall?")) { if (ConfirmationDialog::confirm("Are you sure you want to uninstall?")) {
Params().putBool("DoUninstall", true); Params().putBool("DoUninstall", true);
} }
})); }, "", this));
for(auto &btn : offroad_btns){ for(auto &btn : offroad_btns){
device_layout->addWidget(horizontal_line()); device_layout->addWidget(horizontal_line());
@ -283,7 +285,7 @@ SettingsWindow::SettingsWindow(QWidget *parent) : QFrame(parent) {
QPair<QString, QWidget *> panels[] = { QPair<QString, QWidget *> panels[] = {
{"Device", device}, {"Device", device},
{"Network", network_panel(this)}, {"Network", network_panel(this)},
{"Toggles", toggles_panel()}, {"Toggles", new TogglesPanel(this)},
{"Developer", new DeveloperPanel()}, {"Developer", new DeveloperPanel()},
}; };
@ -319,7 +321,6 @@ SettingsWindow::SettingsWindow(QWidget *parent) : QFrame(parent) {
panel_widget->setCurrentWidget(w); panel_widget->setCurrentWidget(w);
}); });
} }
qobject_cast<QPushButton *>(nav_btns->buttons()[0])->setChecked(true);
sidebar_layout->setContentsMargins(50, 50, 100, 50); sidebar_layout->setContentsMargins(50, 50, 100, 50);
// main settings layout, sidebar + main panel // main settings layout, sidebar + main panel
@ -349,3 +350,8 @@ void SettingsWindow::hideEvent(QHideEvent *event){
#endif #endif
} }
void SettingsWindow::showEvent(QShowEvent *event){
panel_widget->setCurrentIndex(0);
nav_btns->buttons()[0]->setChecked(true);
}

@ -21,6 +21,12 @@ signals:
void reviewTrainingGuide(); void reviewTrainingGuide();
}; };
class TogglesPanel : public QWidget {
Q_OBJECT
public:
explicit TogglesPanel(QWidget *parent = nullptr);
};
class DeveloperPanel : public QFrame { class DeveloperPanel : public QFrame {
Q_OBJECT Q_OBJECT
public: public:
@ -39,6 +45,7 @@ public:
protected: protected:
void hideEvent(QHideEvent *event); void hideEvent(QHideEvent *event);
void showEvent(QShowEvent *event);
signals: signals:
void closeSettings(); void closeSettings();

@ -58,3 +58,9 @@ AbstractControl::AbstractControl(const QString &title, const QString &desc, cons
setLayout(vlayout); setLayout(vlayout);
setStyleSheet("background-color: transparent;"); setStyleSheet("background-color: transparent;");
} }
void AbstractControl::hideEvent(QHideEvent *e){
if(description != nullptr){
description->hide();
}
}

@ -24,6 +24,7 @@ signals:
protected: protected:
AbstractControl(const QString &title, const QString &desc = "", const QString &icon = "", QWidget *parent = nullptr); AbstractControl(const QString &title, const QString &desc = "", const QString &icon = "", QWidget *parent = nullptr);
void hideEvent(QHideEvent *e);
QSize minimumSizeHint() const override { QSize minimumSizeHint() const override {
QSize size = QFrame::minimumSizeHint(); QSize size = QFrame::minimumSizeHint();

@ -40,3 +40,7 @@ ScrollView::ScrollView(QWidget *w, QWidget *parent) : QScrollArea(parent){
scroller->grabGesture(this->viewport(), QScroller::LeftMouseButtonGesture); scroller->grabGesture(this->viewport(), QScroller::LeftMouseButtonGesture);
scroller->setScrollerProperties(sp); scroller->setScrollerProperties(sp);
} }
void ScrollView::hideEvent(QHideEvent *e){
verticalScrollBar()->setValue(0);
}

@ -8,4 +8,6 @@ class ScrollView : public QScrollArea {
public: public:
explicit ScrollView(QWidget *w = nullptr, QWidget *parent = nullptr); explicit ScrollView(QWidget *w = nullptr, QWidget *parent = nullptr);
protected:
void hideEvent(QHideEvent *e);
}; };

Loading…
Cancel
Save