From 0fe155b7c30e9db4bd08b61d8e7e325ec58ac24a Mon Sep 17 00:00:00 2001 From: iejMac <61431446+iejMac@users.noreply.github.com> Date: Fri, 23 Apr 2021 21:24:53 -0700 Subject: [PATCH] UI: close dialogs on settings close (#20541) * this works * fix * fix * fix * blacklist * style * tabs * tabs * temporary * hideEvent * fix * changes * dont need this * works * no signal * Merge branch 'master' of github.com:commaai/openpilot into ui_close_after_timeout * works * cleanup * little more cleanup Co-authored-by: Adeeb Shihadeh --- selfdrive/ui/qt/offroad/settings.cc | 26 +++++++++++++++++--------- selfdrive/ui/qt/widgets/input.cc | 9 ++++----- selfdrive/ui/qt/widgets/input.hpp | 4 ++-- 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/selfdrive/ui/qt/offroad/settings.cc b/selfdrive/ui/qt/offroad/settings.cc index 890539b7f..0e36d2770 100644 --- a/selfdrive/ui/qt/offroad/settings.cc +++ b/selfdrive/ui/qt/offroad/settings.cc @@ -121,7 +121,7 @@ DevicePanel::DevicePanel(QWidget* parent) : QWidget(parent) { 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?")) { + if (ConfirmationDialog::confirm("Are you sure you want to reset calibration?", this)) { Params().remove("CalibrationParams"); } }, "", this); @@ -150,15 +150,15 @@ 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(); - } - }, "", this)); + if (ConfirmationDialog::confirm("Are you sure you want to review the training guide?", this)) { + 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?")) { + if (ConfirmationDialog::confirm("Are you sure you want to uninstall?", this)) { Params().putBool("DoUninstall", true); } }, "", this)); @@ -176,7 +176,7 @@ DevicePanel::DevicePanel(QWidget* parent) : QWidget(parent) { QPushButton *reboot_btn = new QPushButton("Reboot"); power_layout->addWidget(reboot_btn); QObject::connect(reboot_btn, &QPushButton::released, [=]() { - if (ConfirmationDialog::confirm("Are you sure you want to reboot?")) { + if (ConfirmationDialog::confirm("Are you sure you want to reboot?", this)) { Hardware::reboot(); } }); @@ -185,7 +185,7 @@ DevicePanel::DevicePanel(QWidget* parent) : QWidget(parent) { poweroff_btn->setStyleSheet("background-color: #E22C2C;"); power_layout->addWidget(poweroff_btn); QObject::connect(poweroff_btn, &QPushButton::released, [=]() { - if (ConfirmationDialog::confirm("Are you sure you want to power off?")) { + if (ConfirmationDialog::confirm("Are you sure you want to power off?", this)) { Hardware::poweroff(); } }); @@ -358,6 +358,14 @@ void SettingsWindow::hideEvent(QHideEvent *event){ #ifdef QCOM HardwareEon::close_activities(); #endif + + // TODO: this should be handled by the Dialog classes + QList children = findChildren(); + for(auto &w : children){ + if(w->metaObject()->superClass()->className() == QString("QDialog")){ + w->close(); + } + } } void SettingsWindow::showEvent(QShowEvent *event){ diff --git a/selfdrive/ui/qt/widgets/input.cc b/selfdrive/ui/qt/widgets/input.cc index cc0dada7d..3b6303347 100644 --- a/selfdrive/ui/qt/widgets/input.cc +++ b/selfdrive/ui/qt/widgets/input.cc @@ -111,7 +111,6 @@ void InputDialog::setMinLength(int length){ minLength = length; } - ConfirmationDialog::ConfirmationDialog(const QString &prompt_text, const QString &confirm_text, const QString &cancel_text, QWidget *parent):QDialog(parent) { setWindowFlags(Qt::Popup); @@ -161,13 +160,13 @@ ConfirmationDialog::ConfirmationDialog(const QString &prompt_text, const QString setLayout(layout); } -bool ConfirmationDialog::alert(const QString &prompt_text) { - ConfirmationDialog d = ConfirmationDialog(prompt_text, "Ok", ""); +bool ConfirmationDialog::alert(const QString &prompt_text, QWidget *parent) { + ConfirmationDialog d = ConfirmationDialog(prompt_text, "Ok", "", parent); return d.exec(); } -bool ConfirmationDialog::confirm(const QString &prompt_text) { - ConfirmationDialog d = ConfirmationDialog(prompt_text); +bool ConfirmationDialog::confirm(const QString &prompt_text, QWidget *parent) { + ConfirmationDialog d = ConfirmationDialog(prompt_text, "Ok", "Cancel", parent); return d.exec(); } diff --git a/selfdrive/ui/qt/widgets/input.hpp b/selfdrive/ui/qt/widgets/input.hpp index f52ad4416..1004469ab 100644 --- a/selfdrive/ui/qt/widgets/input.hpp +++ b/selfdrive/ui/qt/widgets/input.hpp @@ -44,8 +44,8 @@ class ConfirmationDialog : public QDialog { public: explicit ConfirmationDialog(const QString &prompt_text, const QString &confirm_text = "Ok", const QString &cancel_text = "Cancel", QWidget* parent = 0); - static bool alert(const QString &prompt_text); - static bool confirm(const QString &prompt_text); + static bool alert(const QString &prompt_text, QWidget *parent = 0); + static bool confirm(const QString &prompt_text, QWidget *parent = 0); private: QLabel *prompt;