input.cc: close dialog when parent is hidden (#21318)

* close dialog when parent is hidden

* Q_OBJECT

* apply reviews

* rebase master

* rebase master

* fix wroing minLength

* merge master
old-commit-hash: 5be75f5354
commatwo_master
Dean Lee 4 years ago committed by GitHub
parent b4e26fa46b
commit 0c59f626c7
  1. 6
      selfdrive/ui/qt/offroad/networking.cc
  2. 8
      selfdrive/ui/qt/offroad/settings.cc
  3. 2
      selfdrive/ui/qt/setup/setup.cc
  4. 20
      selfdrive/ui/qt/widgets/input.cc
  5. 24
      selfdrive/ui/qt/widgets/input.h
  6. 8
      selfdrive/ui/qt/widgets/ssh_keys.cc
  7. 1
      selfdrive/ui/qt/widgets/ssh_keys.h

@ -82,7 +82,7 @@ void Networking::connectToNetwork(const Network &n) {
} else if (n.security_type == SecurityType::OPEN) { } else if (n.security_type == SecurityType::OPEN) {
wifi->connect(n); wifi->connect(n);
} else if (n.security_type == SecurityType::WPA) { } else if (n.security_type == SecurityType::WPA) {
QString pass = InputDialog::getText("Enter password for \"" + n.ssid + "\"", 8); QString pass = InputDialog::getText("Enter password for \"" + n.ssid + "\"", this, 8);
if (!pass.isEmpty()) { if (!pass.isEmpty()) {
wifi->connect(n, pass); wifi->connect(n, pass);
} }
@ -92,7 +92,7 @@ void Networking::connectToNetwork(const Network &n) {
void Networking::wrongPassword(const QString &ssid) { void Networking::wrongPassword(const QString &ssid) {
for (Network n : wifi->seen_networks) { for (Network n : wifi->seen_networks) {
if (n.ssid == ssid) { if (n.ssid == ssid) {
QString pass = InputDialog::getText("Wrong password for \"" + n.ssid +"\"", 8); QString pass = InputDialog::getText("Wrong password for \"" + n.ssid +"\"", this, 8);
if (!pass.isEmpty()) { if (!pass.isEmpty()) {
wifi->connect(n, pass); wifi->connect(n, pass);
} }
@ -125,7 +125,7 @@ AdvancedNetworking::AdvancedNetworking(QWidget* parent, WifiManager* wifi): QWid
// Change tethering password // Change tethering password
ButtonControl *editPasswordButton = new ButtonControl("Tethering Password", "EDIT"); ButtonControl *editPasswordButton = new ButtonControl("Tethering Password", "EDIT");
connect(editPasswordButton, &ButtonControl::released, [=]() { connect(editPasswordButton, &ButtonControl::released, [=]() {
QString pass = InputDialog::getText("Enter new tethering password", 8, wifi->getTetheringPassword()); QString pass = InputDialog::getText("Enter new tethering password", this, 8, wifi->getTetheringPassword());
if (!pass.isEmpty()) { if (!pass.isEmpty()) {
wifi->changeTetheringPassword(pass); wifi->changeTetheringPassword(pass);
} }

@ -394,12 +394,4 @@ void SettingsWindow::hideEvent(QHideEvent *event) {
#ifdef QCOM #ifdef QCOM
HardwareEon::close_activities(); HardwareEon::close_activities();
#endif #endif
// TODO: this should be handled by the Dialog classes
QList<QWidget*> children = findChildren<QWidget *>();
for(auto &w : children) {
if(w->metaObject()->superClass()->className() == QString("QDialog")) {
w->close();
}
}
} }

@ -109,7 +109,7 @@ QWidget * Setup::software_selection() {
QPushButton *custom_btn = new QPushButton("Custom"); QPushButton *custom_btn = new QPushButton("Custom");
main_layout->addWidget(custom_btn); main_layout->addWidget(custom_btn);
QObject::connect(custom_btn, &QPushButton::released, this, [=]() { QObject::connect(custom_btn, &QPushButton::released, this, [=]() {
QString input_url = InputDialog::getText("Enter URL"); QString input_url = InputDialog::getText("Enter URL", this);
if (input_url.size()) { if (input_url.size()) {
this->download(input_url); this->download(input_url);
} }

@ -5,7 +5,19 @@
#include "selfdrive/ui/qt/qt_window.h" #include "selfdrive/ui/qt/qt_window.h"
#include "selfdrive/hardware/hw.h" #include "selfdrive/hardware/hw.h"
InputDialog::InputDialog(const QString &prompt_text, QWidget *parent) : QDialog(parent) { QDialogBase::QDialogBase(QWidget *parent) : QDialog(parent) {
Q_ASSERT(parent != nullptr);
parent->installEventFilter(this);
}
bool QDialogBase::eventFilter(QObject *o, QEvent *e) {
if (o == parent() && e->type() == QEvent::Hide) {
reject();
}
return QDialog::eventFilter(o, e);
}
InputDialog::InputDialog(const QString &prompt_text, QWidget *parent) : QDialogBase(parent) {
main_layout = new QVBoxLayout(this); main_layout = new QVBoxLayout(this);
main_layout->setContentsMargins(50, 50, 50, 50); main_layout->setContentsMargins(50, 50, 50, 50);
main_layout->setSpacing(20); main_layout->setSpacing(20);
@ -57,8 +69,8 @@ InputDialog::InputDialog(const QString &prompt_text, QWidget *parent) : QDialog(
} }
QString InputDialog::getText(const QString &prompt, int minLength, const QString &defaultText) { QString InputDialog::getText(const QString &prompt, QWidget *parent, int minLength, const QString &defaultText) {
InputDialog d = InputDialog(prompt); InputDialog d = InputDialog(prompt, parent);
d.line->setText(defaultText); d.line->setText(defaultText);
d.setMinLength(minLength); d.setMinLength(minLength);
const int ret = d.exec(); const int ret = d.exec();
@ -114,7 +126,7 @@ void InputDialog::setMinLength(int length) {
} }
ConfirmationDialog::ConfirmationDialog(const QString &prompt_text, const QString &confirm_text, const QString &cancel_text, ConfirmationDialog::ConfirmationDialog(const QString &prompt_text, const QString &confirm_text, const QString &cancel_text,
QWidget *parent):QDialog(parent) { QWidget *parent) : QDialogBase(parent) {
setWindowFlags(Qt::Popup); setWindowFlags(Qt::Popup);
main_layout = new QVBoxLayout(this); main_layout = new QVBoxLayout(this);
main_layout->setMargin(25); main_layout->setMargin(25);

@ -9,12 +9,20 @@
#include "selfdrive/ui/qt/widgets/keyboard.h" #include "selfdrive/ui/qt/widgets/keyboard.h"
class InputDialog : public QDialog { class QDialogBase : public QDialog {
Q_OBJECT
protected:
QDialogBase(QWidget *parent);
bool eventFilter(QObject *o, QEvent *e) override;
};
class InputDialog : public QDialogBase {
Q_OBJECT Q_OBJECT
public: public:
explicit InputDialog(const QString &prompt_text, QWidget* parent = 0); explicit InputDialog(const QString &prompt_text, QWidget *parent);
static QString getText(const QString &prompt, int minLength = -1, const QString &defaultText = ""); static QString getText(const QString &prompt, QWidget *parent, int minLength = -1, const QString &defaultText = "");
QString text(); QString text();
void setMessage(const QString &message, bool clearInputField = true); void setMessage(const QString &message, bool clearInputField = true);
void setMinLength(int length); void setMinLength(int length);
@ -38,14 +46,14 @@ signals:
void emitText(const QString &text); void emitText(const QString &text);
}; };
class ConfirmationDialog : public QDialog { class ConfirmationDialog : public QDialogBase {
Q_OBJECT Q_OBJECT
public: public:
explicit ConfirmationDialog(const QString &prompt_text, const QString &confirm_text = "Ok", explicit ConfirmationDialog(const QString &prompt_text, const QString &confirm_text,
const QString &cancel_text = "Cancel", QWidget* parent = 0); const QString &cancel_text, QWidget* parent);
static bool alert(const QString &prompt_text, QWidget *parent = 0); static bool alert(const QString &prompt_text, QWidget *parent);
static bool confirm(const QString &prompt_text, QWidget *parent = 0); static bool confirm(const QString &prompt_text, QWidget *parent);
private: private:
QLabel *prompt; QLabel *prompt;

@ -11,7 +11,7 @@ SshControl::SshControl() : ButtonControl("SSH Keys", "", "Warning: This grants S
QObject::connect(this, &ButtonControl::released, [=]() { QObject::connect(this, &ButtonControl::released, [=]() {
if (text() == "ADD") { if (text() == "ADD") {
QString username = InputDialog::getText("Enter your GitHub username"); QString username = InputDialog::getText("Enter your GitHub username", this);
if (username.length() > 0) { if (username.length() > 0) {
setText("LOADING"); setText("LOADING");
setEnabled(false); setEnabled(false);
@ -46,18 +46,18 @@ void SshControl::getUserKeys(const QString &username) {
params.put("GithubUsername", username.toStdString()); params.put("GithubUsername", username.toStdString());
params.put("GithubSshKeys", resp.toStdString()); params.put("GithubSshKeys", resp.toStdString());
} else { } else {
ConfirmationDialog::alert("Username '" + username + "' has no keys on GitHub"); ConfirmationDialog::alert("Username '" + username + "' has no keys on GitHub", this);
} }
refresh(); refresh();
request->deleteLater(); request->deleteLater();
}); });
QObject::connect(request, &HttpRequest::failedResponse, [=] { QObject::connect(request, &HttpRequest::failedResponse, [=] {
ConfirmationDialog::alert("Username '" + username + "' doesn't exist on GitHub"); ConfirmationDialog::alert("Username '" + username + "' doesn't exist on GitHub", this);
refresh(); refresh();
request->deleteLater(); request->deleteLater();
}); });
QObject::connect(request, &HttpRequest::timeoutResponse, [=] { QObject::connect(request, &HttpRequest::timeoutResponse, [=] {
ConfirmationDialog::alert("Request timed out"); ConfirmationDialog::alert("Request timed out", this);
refresh(); refresh();
request->deleteLater(); request->deleteLater();
}); });

@ -27,7 +27,6 @@ public:
private: private:
Params params; Params params;
QPushButton btn;
QLabel username_label; QLabel username_label;
void refresh(); void refresh();

Loading…
Cancel
Save