mirror of
https://github.com/MoreTore/openpilot.git
synced 2026-08-05 16:26:14 +08:00
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
This commit is contained in:
@@ -82,7 +82,7 @@ void Networking::connectToNetwork(const Network &n) {
|
||||
} else if (n.security_type == SecurityType::OPEN) {
|
||||
wifi->connect(n);
|
||||
} 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()) {
|
||||
wifi->connect(n, pass);
|
||||
}
|
||||
@@ -92,7 +92,7 @@ void Networking::connectToNetwork(const Network &n) {
|
||||
void Networking::wrongPassword(const QString &ssid) {
|
||||
for (Network n : wifi->seen_networks) {
|
||||
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()) {
|
||||
wifi->connect(n, pass);
|
||||
}
|
||||
@@ -125,7 +125,7 @@ AdvancedNetworking::AdvancedNetworking(QWidget* parent, WifiManager* wifi): QWid
|
||||
// Change tethering password
|
||||
ButtonControl *editPasswordButton = new ButtonControl("Tethering Password", "EDIT");
|
||||
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()) {
|
||||
wifi->changeTetheringPassword(pass);
|
||||
}
|
||||
|
||||
@@ -394,12 +394,4 @@ void SettingsWindow::hideEvent(QHideEvent *event) {
|
||||
#ifdef QCOM
|
||||
HardwareEon::close_activities();
|
||||
#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");
|
||||
main_layout->addWidget(custom_btn);
|
||||
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()) {
|
||||
this->download(input_url);
|
||||
}
|
||||
|
||||
@@ -5,7 +5,19 @@
|
||||
#include "selfdrive/ui/qt/qt_window.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->setContentsMargins(50, 50, 50, 50);
|
||||
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) {
|
||||
InputDialog d = InputDialog(prompt);
|
||||
QString InputDialog::getText(const QString &prompt, QWidget *parent, int minLength, const QString &defaultText) {
|
||||
InputDialog d = InputDialog(prompt, parent);
|
||||
d.line->setText(defaultText);
|
||||
d.setMinLength(minLength);
|
||||
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,
|
||||
QWidget *parent):QDialog(parent) {
|
||||
QWidget *parent) : QDialogBase(parent) {
|
||||
setWindowFlags(Qt::Popup);
|
||||
main_layout = new QVBoxLayout(this);
|
||||
main_layout->setMargin(25);
|
||||
|
||||
@@ -9,12 +9,20 @@
|
||||
|
||||
#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
|
||||
|
||||
public:
|
||||
explicit InputDialog(const QString &prompt_text, QWidget* parent = 0);
|
||||
static QString getText(const QString &prompt, int minLength = -1, const QString &defaultText = "");
|
||||
explicit InputDialog(const QString &prompt_text, QWidget *parent);
|
||||
static QString getText(const QString &prompt, QWidget *parent, int minLength = -1, const QString &defaultText = "");
|
||||
QString text();
|
||||
void setMessage(const QString &message, bool clearInputField = true);
|
||||
void setMinLength(int length);
|
||||
@@ -38,14 +46,14 @@ signals:
|
||||
void emitText(const QString &text);
|
||||
};
|
||||
|
||||
class ConfirmationDialog : public QDialog {
|
||||
class ConfirmationDialog : public QDialogBase {
|
||||
Q_OBJECT
|
||||
|
||||
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, QWidget *parent = 0);
|
||||
static bool confirm(const QString &prompt_text, QWidget *parent = 0);
|
||||
explicit ConfirmationDialog(const QString &prompt_text, const QString &confirm_text,
|
||||
const QString &cancel_text, QWidget* parent);
|
||||
static bool alert(const QString &prompt_text, QWidget *parent);
|
||||
static bool confirm(const QString &prompt_text, QWidget *parent);
|
||||
|
||||
private:
|
||||
QLabel *prompt;
|
||||
|
||||
@@ -11,7 +11,7 @@ SshControl::SshControl() : ButtonControl("SSH Keys", "", "Warning: This grants S
|
||||
|
||||
QObject::connect(this, &ButtonControl::released, [=]() {
|
||||
if (text() == "ADD") {
|
||||
QString username = InputDialog::getText("Enter your GitHub username");
|
||||
QString username = InputDialog::getText("Enter your GitHub username", this);
|
||||
if (username.length() > 0) {
|
||||
setText("LOADING");
|
||||
setEnabled(false);
|
||||
@@ -46,18 +46,18 @@ void SshControl::getUserKeys(const QString &username) {
|
||||
params.put("GithubUsername", username.toStdString());
|
||||
params.put("GithubSshKeys", resp.toStdString());
|
||||
} else {
|
||||
ConfirmationDialog::alert("Username '" + username + "' has no keys on GitHub");
|
||||
ConfirmationDialog::alert("Username '" + username + "' has no keys on GitHub", this);
|
||||
}
|
||||
refresh();
|
||||
request->deleteLater();
|
||||
});
|
||||
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();
|
||||
request->deleteLater();
|
||||
});
|
||||
QObject::connect(request, &HttpRequest::timeoutResponse, [=] {
|
||||
ConfirmationDialog::alert("Request timed out");
|
||||
ConfirmationDialog::alert("Request timed out", this);
|
||||
refresh();
|
||||
request->deleteLater();
|
||||
});
|
||||
|
||||
@@ -27,7 +27,6 @@ public:
|
||||
private:
|
||||
Params params;
|
||||
|
||||
QPushButton btn;
|
||||
QLabel username_label;
|
||||
|
||||
void refresh();
|
||||
|
||||
Reference in New Issue
Block a user