From 928fbecec0d88fff684f3eecf1306393ef21be05 Mon Sep 17 00:00:00 2001 From: iejMac <61431446+iejMac@users.noreply.github.com> Date: Tue, 13 Apr 2021 13:42:13 -0700 Subject: [PATCH] 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 --- selfdrive/ui/qt/offroad/settings.cc | 142 +++++++++++++------------ selfdrive/ui/qt/offroad/settings.hpp | 7 ++ selfdrive/ui/qt/widgets/controls.cc | 6 ++ selfdrive/ui/qt/widgets/controls.hpp | 1 + selfdrive/ui/qt/widgets/scrollview.cc | 4 + selfdrive/ui/qt/widgets/scrollview.hpp | 2 + 6 files changed, 94 insertions(+), 68 deletions(-) diff --git a/selfdrive/ui/qt/offroad/settings.cc b/selfdrive/ui/qt/offroad/settings.cc index 456576494..1af85a83d 100644 --- a/selfdrive/ui/qt/offroad/settings.cc +++ b/selfdrive/ui/qt/offroad/settings.cc @@ -19,70 +19,72 @@ #include "home.hpp" -QWidget * toggles_panel() { +TogglesPanel::TogglesPanel(QWidget *parent) : QWidget(parent) { QVBoxLayout *toggles_list = new QVBoxLayout(); - toggles_list->addWidget(new ParamControl("OpenpilotEnabledToggle", - "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.", - "../assets/offroad/icon_openpilot.png" - )); - toggles_list->addWidget(horizontal_line()); - toggles_list->addWidget(new ParamControl("IsLdwEnabled", - "Enable Lane Departure Warnings", - "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()); - toggles_list->addWidget(new ParamControl("IsRHD", - "Enable Right-Hand Drive", - "Allow openpilot to obey left-hand traffic conventions and perform driver monitoring on right driver seat.", - "../assets/offroad/icon_openpilot_mirrored.png" - )); - toggles_list->addWidget(horizontal_line()); - toggles_list->addWidget(new ParamControl("IsMetric", - "Use Metric System", - "Display speed in km/h instead of mp/h.", - "../assets/offroad/icon_metric.png" - )); - toggles_list->addWidget(horizontal_line()); - toggles_list->addWidget(new ParamControl("CommunityFeaturesToggle", - "Enable Community Features", - "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", - "../assets/offroad/icon_shell.png" - )); - toggles_list->addWidget(horizontal_line()); - toggles_list->addWidget(new ParamControl("IsUploadRawEnabled", - "Upload Raw Logs", - "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()); + QList toggles; + + toggles.append(new ParamControl("OpenpilotEnabledToggle", + "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.", + "../assets/offroad/icon_openpilot.png", + this)); + toggles.append(new ParamControl("IsLdwEnabled", + "Enable Lane Departure Warnings", + "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", + this)); + toggles.append(new ParamControl("IsRHD", + "Enable Right-Hand Drive", + "Allow openpilot to obey left-hand traffic conventions and perform driver monitoring on right driver seat.", + "../assets/offroad/icon_openpilot_mirrored.png", + this)); + toggles.append(new ParamControl("IsMetric", + "Use Metric System", + "Display speed in km/h instead of mp/h.", + "../assets/offroad/icon_metric.png", + this)); + toggles.append(new ParamControl("CommunityFeaturesToggle", + "Enable Community Features", + "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", + "../assets/offroad/icon_shell.png", + this)); + toggles.append(new ParamControl("IsUploadRawEnabled", + "Upload Raw Logs", + "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", + this)); ParamControl *record_toggle = new ParamControl("RecordFront", - "Record and Upload Driver Camera", - "Upload data from the driver facing camera and help improve the driver monitoring algorithm.", - "../assets/offroad/icon_monitoring.png"); - toggles_list->addWidget(record_toggle); - toggles_list->addWidget(horizontal_line()); - toggles_list->addWidget(new ParamControl("EndToEndToggle", - "\U0001f96c Disable use of lanelines (Alpha) \U0001f96c", - "In this mode openpilot will ignore lanelines and just drive how it thinks a human would.", - "../assets/offroad/icon_road.png")); + "Record and Upload Driver Camera", + "Upload data from the driver facing camera and help improve the driver monitoring algorithm.", + "../assets/offroad/icon_monitoring.png", + this); + toggles.append(record_toggle); + toggles.append(new ParamControl("EndToEndToggle", + "\U0001f96c Disable use of lanelines (Alpha) \U0001f96c", + "In this mode openpilot will ignore lanelines and just drive how it thinks a human would.", + "../assets/offroad/icon_road.png", + this)); #ifdef QCOM2 - toggles_list->addWidget(horizontal_line()); - toggles_list->addWidget(new ParamControl("EnableWideCamera", - "Enable use of Wide Angle Camera", - "Use wide angle camera for driving and ui. Only takes effect after reboot.", - "../assets/offroad/icon_openpilot.png")); + toggles.append(new ParamControl("EnableWideCamera", + "Enable use of Wide Angle Camera", + "Use wide angle camera for driving and ui. Only takes effect after reboot.", + "../assets/offroad/icon_openpilot.png", + this)); #endif bool record_lock = Params().getBool("RecordFrontLock"); record_toggle->setEnabled(!record_lock); - QWidget *widget = new QWidget; - widget->setLayout(toggles_list); - return widget; + for(ParamControl *toggle : toggles){ + if(toggles_list->count() != 0){ + toggles_list->addWidget(horizontal_line()); + } + toggles_list->addWidget(toggle); + } + + setLayout(toggles_list); } DevicePanel::DevicePanel(QWidget* parent) : QWidget(parent) { @@ -101,18 +103,18 @@ DevicePanel::DevicePanel(QWidget* parent) : QWidget(parent) { QList offroad_btns; 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)", - [=]() { - Params().putBool("IsDriverViewEnabled", true); - GLWindow::ui_state.scene.driver_view = true; } - )); + "Preview the driver facing camera to help optimize device mounting position for best driver monitoring experience. (vehicle must be off)", + [=]() { + Params().putBool("IsDriverViewEnabled", 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."; ButtonControl *resetCalibBtn = new ButtonControl("Reset Calibration", "RESET", resetCalibDesc, [=]() { if (ConfirmationDialog::confirm("Are you sure you want to reset calibration?")) { Params().remove("CalibrationParams"); } - }); + }, "", this); connect(resetCalibBtn, &ButtonControl::showDescription, [=]() { QString desc = resetCalibDesc; 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", "Review the rules, features, and limitations of openpilot", [=]() { - if (ConfirmationDialog::confirm("Are you sure you want to review the training guide?")) { - Params().remove("CompletedTrainingVersion"); - emit reviewTrainingGuide(); - } - })); + if (ConfirmationDialog::confirm("Are you sure you want to review the training guide?")) { + Params().remove("CompletedTrainingVersion"); + emit reviewTrainingGuide(); + } + }, "", this)); QString brand = params.getBool("Passive") ? "dashcam" : "openpilot"; offroad_btns.append(new ButtonControl("Uninstall " + brand, "UNINSTALL", "", [=]() { if (ConfirmationDialog::confirm("Are you sure you want to uninstall?")) { Params().putBool("DoUninstall", true); } - })); + }, "", this)); for(auto &btn : offroad_btns){ device_layout->addWidget(horizontal_line()); @@ -283,7 +285,7 @@ SettingsWindow::SettingsWindow(QWidget *parent) : QFrame(parent) { QPair panels[] = { {"Device", device}, {"Network", network_panel(this)}, - {"Toggles", toggles_panel()}, + {"Toggles", new TogglesPanel(this)}, {"Developer", new DeveloperPanel()}, }; @@ -319,7 +321,6 @@ SettingsWindow::SettingsWindow(QWidget *parent) : QFrame(parent) { panel_widget->setCurrentWidget(w); }); } - qobject_cast(nav_btns->buttons()[0])->setChecked(true); sidebar_layout->setContentsMargins(50, 50, 100, 50); // main settings layout, sidebar + main panel @@ -349,3 +350,8 @@ void SettingsWindow::hideEvent(QHideEvent *event){ #endif } +void SettingsWindow::showEvent(QShowEvent *event){ + panel_widget->setCurrentIndex(0); + nav_btns->buttons()[0]->setChecked(true); +} + diff --git a/selfdrive/ui/qt/offroad/settings.hpp b/selfdrive/ui/qt/offroad/settings.hpp index 58bdc2be8..bb8428f34 100644 --- a/selfdrive/ui/qt/offroad/settings.hpp +++ b/selfdrive/ui/qt/offroad/settings.hpp @@ -21,6 +21,12 @@ signals: void reviewTrainingGuide(); }; +class TogglesPanel : public QWidget { + Q_OBJECT +public: + explicit TogglesPanel(QWidget *parent = nullptr); +}; + class DeveloperPanel : public QFrame { Q_OBJECT public: @@ -39,6 +45,7 @@ public: protected: void hideEvent(QHideEvent *event); + void showEvent(QShowEvent *event); signals: void closeSettings(); diff --git a/selfdrive/ui/qt/widgets/controls.cc b/selfdrive/ui/qt/widgets/controls.cc index 37fa13e61..882e8cd71 100644 --- a/selfdrive/ui/qt/widgets/controls.cc +++ b/selfdrive/ui/qt/widgets/controls.cc @@ -58,3 +58,9 @@ AbstractControl::AbstractControl(const QString &title, const QString &desc, cons setLayout(vlayout); setStyleSheet("background-color: transparent;"); } + +void AbstractControl::hideEvent(QHideEvent *e){ + if(description != nullptr){ + description->hide(); + } +} diff --git a/selfdrive/ui/qt/widgets/controls.hpp b/selfdrive/ui/qt/widgets/controls.hpp index 652749e9f..c5814ebd2 100644 --- a/selfdrive/ui/qt/widgets/controls.hpp +++ b/selfdrive/ui/qt/widgets/controls.hpp @@ -24,6 +24,7 @@ signals: protected: AbstractControl(const QString &title, const QString &desc = "", const QString &icon = "", QWidget *parent = nullptr); + void hideEvent(QHideEvent *e); QSize minimumSizeHint() const override { QSize size = QFrame::minimumSizeHint(); diff --git a/selfdrive/ui/qt/widgets/scrollview.cc b/selfdrive/ui/qt/widgets/scrollview.cc index b58e4bb53..9aab2b72a 100644 --- a/selfdrive/ui/qt/widgets/scrollview.cc +++ b/selfdrive/ui/qt/widgets/scrollview.cc @@ -40,3 +40,7 @@ ScrollView::ScrollView(QWidget *w, QWidget *parent) : QScrollArea(parent){ scroller->grabGesture(this->viewport(), QScroller::LeftMouseButtonGesture); scroller->setScrollerProperties(sp); } + +void ScrollView::hideEvent(QHideEvent *e){ + verticalScrollBar()->setValue(0); +} diff --git a/selfdrive/ui/qt/widgets/scrollview.hpp b/selfdrive/ui/qt/widgets/scrollview.hpp index 54a0e670d..54887aefb 100644 --- a/selfdrive/ui/qt/widgets/scrollview.hpp +++ b/selfdrive/ui/qt/widgets/scrollview.hpp @@ -8,4 +8,6 @@ class ScrollView : public QScrollArea { public: explicit ScrollView(QWidget *w = nullptr, QWidget *parent = nullptr); +protected: + void hideEvent(QHideEvent *e); };