mirror of
https://github.com/dragonpilot/dragonpilot.git
synced 2026-06-27 00:42:05 +08:00
qt confirmation dialogs (#20202)
* confirmation dialog widget * looks pretty good * fix qcom2 Co-authored-by: Comma Device <device@comma.ai>
This commit is contained in:
@@ -24,7 +24,7 @@ else:
|
||||
del qt_base_libs[qt_base_libs.index('OpenCL')]
|
||||
qt_env['FRAMEWORKS'] += ['OpenCL']
|
||||
|
||||
widgets_src = ["qt/widgets/input_field.cc", "qt/widgets/drive_stats.cc",
|
||||
widgets_src = ["qt/widgets/input.cc", "qt/widgets/drive_stats.cc",
|
||||
"qt/widgets/ssh_keys.cc", "qt/widgets/toggle.cc", "qt/qt_sound.cc",
|
||||
"qt/widgets/offroad_alerts.cc", "qt/widgets/setup.cc", "qt/widgets/keyboard.cc",
|
||||
"#phonelibs/qrcode/QrCode.cc"]
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#include <QTimer>
|
||||
|
||||
#include "wifiManager.hpp"
|
||||
#include "widgets/input_field.hpp"
|
||||
#include "widgets/input.hpp"
|
||||
#include "widgets/ssh_keys.hpp"
|
||||
#include "widgets/toggle.hpp"
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#endif
|
||||
|
||||
#include "settings.hpp"
|
||||
#include "widgets/input.hpp"
|
||||
#include "widgets/toggle.hpp"
|
||||
#include "widgets/offroad_alerts.hpp"
|
||||
|
||||
@@ -159,13 +160,14 @@ QWidget * device_panel() {
|
||||
Params().write_db_value("IsDriverViewEnabled", "1", 1);
|
||||
});
|
||||
|
||||
|
||||
// TODO: show current calibration values
|
||||
QPushButton *clear_cal_btn = new QPushButton("Reset Calibration");
|
||||
device_layout->addWidget(clear_cal_btn, 0, Qt::AlignBottom);
|
||||
device_layout->addWidget(horizontal_line(), Qt::AlignBottom);
|
||||
QObject::connect(clear_cal_btn, &QPushButton::released, [=]() {
|
||||
Params().delete_db_value("CalibrationParams");
|
||||
if (ConfirmationDialog::confirm("Are you sure you want to reset calibration?")) {
|
||||
Params().delete_db_value("CalibrationParams");
|
||||
}
|
||||
});
|
||||
|
||||
QPushButton *poweroff_btn = new QPushButton("Power Off");
|
||||
@@ -178,10 +180,13 @@ QWidget * device_panel() {
|
||||
QObject::connect(reboot_btn, &QPushButton::released, [=]() { std::system("sudo reboot"); });
|
||||
#endif
|
||||
|
||||
// TODO: add confirmation dialog
|
||||
QPushButton *uninstall_btn = new QPushButton("Uninstall openpilot");
|
||||
device_layout->addWidget(uninstall_btn);
|
||||
QObject::connect(uninstall_btn, &QPushButton::released, [=]() { Params().write_db_value("DoUninstall", "1"); });
|
||||
QObject::connect(uninstall_btn, &QPushButton::released, [=]() {
|
||||
if (ConfirmationDialog::confirm("Are you sure you want to uninstall?")) {
|
||||
Params().write_db_value("DoUninstall", "1");
|
||||
}
|
||||
});
|
||||
|
||||
QWidget *widget = new QWidget;
|
||||
widget->setLayout(device_layout);
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
#include "setup.hpp"
|
||||
#include "offroad/networking.hpp"
|
||||
#include "widgets/input_field.hpp"
|
||||
#include "widgets/input.hpp"
|
||||
#include "qt_window.hpp"
|
||||
|
||||
#define USER_AGENT "AGNOSSetup-0.1"
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
#include "wifi.hpp"
|
||||
#include "offroad/networking.hpp"
|
||||
#include "widgets/input_field.hpp"
|
||||
#include "widgets/input.hpp"
|
||||
#include "qt_window.hpp"
|
||||
|
||||
void WifiSetup::finish() {
|
||||
@@ -25,8 +25,8 @@ WifiSetup::WifiSetup(QWidget *parent) {
|
||||
QObject::connect(finish_btn, SIGNAL(released()), this, SLOT(finish()));
|
||||
|
||||
QWidget* n = new Networking(this, true);
|
||||
|
||||
//Next 5 lines to keep the same stylesheet on the networking widget
|
||||
|
||||
// Next 5 lines to keep the same stylesheet on the networking widget
|
||||
QLayout* backgroundLayout = new QVBoxLayout();
|
||||
backgroundLayout->addWidget(n);
|
||||
QWidget* q = new QWidget();
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include <QPushButton>
|
||||
|
||||
#include "input_field.hpp"
|
||||
#include "input.hpp"
|
||||
#include "qt_window.hpp"
|
||||
|
||||
InputDialog::InputDialog(QString prompt_text, QWidget *parent):QDialog(parent) {
|
||||
@@ -60,11 +60,7 @@ QString InputDialog::getText(const QString prompt, int minLength) {
|
||||
InputDialog d = InputDialog(prompt);
|
||||
d.setMinLength(minLength);
|
||||
const int ret = d.exec();
|
||||
if (ret) {
|
||||
return d.text();
|
||||
} else {
|
||||
return QString();
|
||||
}
|
||||
return ret ? d.text() : QString();
|
||||
}
|
||||
|
||||
QString InputDialog::text() {
|
||||
@@ -100,10 +96,6 @@ void InputDialog::handleInput(QString s) {
|
||||
line->insert(s.left(1));
|
||||
}
|
||||
|
||||
void InputDialog::show(){
|
||||
setMainWindow(this);
|
||||
}
|
||||
|
||||
void InputDialog::setMessage(QString message, bool clearInputField){
|
||||
label->setText(message);
|
||||
if (clearInputField){
|
||||
@@ -113,4 +105,63 @@ void InputDialog::setMessage(QString message, bool clearInputField){
|
||||
|
||||
void InputDialog::setMinLength(int length){
|
||||
minLength = length;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
ConfirmationDialog::ConfirmationDialog(QString prompt_text, QString confirm_text, QString cancel_text,
|
||||
QWidget *parent):QDialog(parent) {
|
||||
layout = new QVBoxLayout();
|
||||
layout->setMargin(25);
|
||||
|
||||
prompt = new QLabel(prompt_text, this);
|
||||
prompt->setWordWrap(true);
|
||||
prompt->setAlignment(Qt::AlignHCenter);
|
||||
prompt->setStyleSheet(R"(font-size: 55px; font-weight: 400;)");
|
||||
layout->addWidget(prompt, 1, Qt::AlignTop | Qt::AlignHCenter);
|
||||
|
||||
// cancel + confirm buttons
|
||||
QHBoxLayout *btn_layout = new QHBoxLayout();
|
||||
btn_layout->setSpacing(20);
|
||||
btn_layout->addStretch(1);
|
||||
layout->addLayout(btn_layout);
|
||||
|
||||
QPushButton* cancel_btn = new QPushButton(cancel_text);
|
||||
btn_layout->addWidget(cancel_btn, 0, Qt::AlignRight);
|
||||
QObject::connect(cancel_btn, SIGNAL(released()), this, SLOT(reject()));
|
||||
|
||||
QPushButton* confirm_btn = new QPushButton(confirm_text);
|
||||
btn_layout->addWidget(confirm_btn, 0, Qt::AlignRight);
|
||||
QObject::connect(confirm_btn, SIGNAL(released()), this, SLOT(accept()));
|
||||
|
||||
setFixedSize(900, 350);
|
||||
setStyleSheet(R"(
|
||||
* {
|
||||
color: black;
|
||||
background-color: white;
|
||||
}
|
||||
QPushButton {
|
||||
font-size: 40px;
|
||||
padding: 30px;
|
||||
padding-right: 45px;
|
||||
padding-left: 45px;
|
||||
border-radius: 7px;
|
||||
background-color: #44444400;
|
||||
}
|
||||
)");
|
||||
|
||||
setLayout(layout);
|
||||
}
|
||||
|
||||
bool ConfirmationDialog::confirm(const QString prompt_text) {
|
||||
ConfirmationDialog d = ConfirmationDialog(prompt_text);
|
||||
return d.exec();
|
||||
}
|
||||
|
||||
int ConfirmationDialog::exec() {
|
||||
// TODO: make this work without fullscreen
|
||||
#ifdef QCOM2
|
||||
setMainWindow(this);
|
||||
#endif
|
||||
return QDialog::exec();
|
||||
}
|
||||
@@ -16,7 +16,6 @@ public:
|
||||
explicit InputDialog(QString prompt_text, QWidget* parent = 0);
|
||||
static QString getText(QString prompt, int minLength = -1);
|
||||
QString text();
|
||||
void show();
|
||||
void setMessage(QString message, bool clearInputField=true);
|
||||
void setMinLength(int length);
|
||||
|
||||
@@ -37,3 +36,20 @@ signals:
|
||||
void cancel();
|
||||
void emitText(QString text);
|
||||
};
|
||||
|
||||
|
||||
class ConfirmationDialog : public QDialog {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ConfirmationDialog(QString prompt_text, QString confirm_text = "Ok",
|
||||
QString cancel_text = "Cancel", QWidget* parent = 0);
|
||||
static bool confirm(QString prompt_text);
|
||||
|
||||
private:
|
||||
QLabel *prompt;
|
||||
QVBoxLayout *layout;
|
||||
|
||||
public slots:
|
||||
int exec() override;
|
||||
};
|
||||
@@ -6,7 +6,7 @@
|
||||
#include <QNetworkReply>
|
||||
|
||||
#include "widgets/ssh_keys.hpp"
|
||||
#include "widgets/input_field.hpp"
|
||||
#include "widgets/input.hpp"
|
||||
#include "common/params.h"
|
||||
|
||||
QWidget* layout_to_widget(QLayout* l){
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#include <QTimer>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QStackedLayout>
|
||||
#include "input_field.hpp"
|
||||
#include "widgets/input.hpp"
|
||||
|
||||
class SSH : public QWidget {
|
||||
Q_OBJECT
|
||||
|
||||
Reference in New Issue
Block a user