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
albatross
iejMac 2021-04-13 13:42:13 -07:00 committed by GitHub
parent fe2f63849a
commit 928fbecec0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 94 additions and 68 deletions

View File

@ -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<ParamControl*> 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<ButtonControl*> 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<QString, QWidget *> 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<QPushButton *>(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);
}

View File

@ -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();

View File

@ -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();
}
}

View File

@ -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();

View File

@ -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);
}

View File

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