mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-07-14 22:02:09 +08:00
UI: refactor ButtonControl (#21315)
old-commit-hash: 8675c970d49499d541c38172b1c5516dec7df480
This commit is contained in:
@@ -145,7 +145,8 @@ AdvancedNetworking::AdvancedNetworking(QWidget* parent, WifiManager* wifi): QWid
|
||||
main_layout->addWidget(horizontal_line(), 0);
|
||||
|
||||
// Change tethering password
|
||||
editPasswordButton = new ButtonControl("Tethering Password", "EDIT", "", [=]() {
|
||||
editPasswordButton = new ButtonControl("Tethering Password", "EDIT");
|
||||
connect(editPasswordButton, &ButtonControl::released, [=]() {
|
||||
QString pass = InputDialog::getText("Enter new tethering password", 8);
|
||||
if (pass.size()) {
|
||||
wifi->changeTetheringPassword(pass);
|
||||
|
||||
@@ -113,18 +113,18 @@ DevicePanel::DevicePanel(QWidget* parent) : QWidget(parent) {
|
||||
main_layout->addWidget(new LabelControl("Serial", serial));
|
||||
|
||||
// offroad-only buttons
|
||||
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)",
|
||||
[=]() { emit showDriverView(); }, "", this));
|
||||
auto dcamBtn = 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)");
|
||||
connect(dcamBtn, &ButtonControl::released, [=]() { emit showDriverView(); });
|
||||
|
||||
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, [=]() {
|
||||
auto resetCalibBtn = new ButtonControl("Reset Calibration", "RESET", resetCalibDesc);
|
||||
connect(resetCalibBtn, &ButtonControl::released, [=]() {
|
||||
if (ConfirmationDialog::confirm("Are you sure you want to reset calibration?", this)) {
|
||||
Params().remove("CalibrationParams");
|
||||
}
|
||||
}, "", this);
|
||||
});
|
||||
connect(resetCalibBtn, &ButtonControl::showDescription, [=]() {
|
||||
QString desc = resetCalibDesc;
|
||||
std::string calib_bytes = Params().get("CalibrationParams");
|
||||
@@ -146,25 +146,25 @@ DevicePanel::DevicePanel(QWidget* parent) : QWidget(parent) {
|
||||
}
|
||||
resetCalibBtn->setDescription(desc);
|
||||
});
|
||||
offroad_btns.append(resetCalibBtn);
|
||||
|
||||
offroad_btns.append(new ButtonControl("Review Training Guide", "REVIEW",
|
||||
"Review the rules, features, and limitations of openpilot", [=]() {
|
||||
auto retrainingBtn = new ButtonControl("Review Training Guide", "REVIEW", "Review the rules, features, and limitations of openpilot");
|
||||
connect(retrainingBtn, &ButtonControl::released, [=]() {
|
||||
if (ConfirmationDialog::confirm("Are you sure you want to review the training guide?", this)) {
|
||||
Params().remove("CompletedTrainingVersion");
|
||||
emit reviewTrainingGuide();
|
||||
}
|
||||
}, "", this));
|
||||
});
|
||||
|
||||
offroad_btns.append(new ButtonControl("Uninstall " + getBrand(), "UNINSTALL", "", [=]() {
|
||||
auto uninstallBtn = new ButtonControl("Uninstall " + getBrand(), "UNINSTALL");
|
||||
connect(uninstallBtn, &ButtonControl::released, [=]() {
|
||||
if (ConfirmationDialog::confirm("Are you sure you want to uninstall?", this)) {
|
||||
Params().putBool("DoUninstall", true);
|
||||
}
|
||||
}, "", this));
|
||||
});
|
||||
|
||||
for(auto &btn : offroad_btns) {
|
||||
for (auto btn : {dcamBtn, resetCalibBtn, retrainingBtn, uninstallBtn}) {
|
||||
main_layout->addWidget(horizontal_line());
|
||||
QObject::connect(parent, SIGNAL(offroadTransition(bool)), btn, SLOT(setEnabled(bool)));
|
||||
connect(parent, SIGNAL(offroadTransition(bool)), btn, SLOT(setEnabled(bool)));
|
||||
main_layout->addWidget(btn);
|
||||
}
|
||||
|
||||
@@ -207,7 +207,8 @@ SoftwarePanel::SoftwarePanel(QWidget* parent) : QWidget(parent) {
|
||||
osVersionLbl = new LabelControl("OS Version");
|
||||
versionLbl = new LabelControl("Version", "", QString::fromStdString(params.get("ReleaseNotes")).trimmed());
|
||||
lastUpdateLbl = new LabelControl("Last Update Check", "", "The last time openpilot successfully checked for an update. The updater only runs while the car is off.");
|
||||
updateBtn = new ButtonControl("Check for Update", "", "", [=]() {
|
||||
updateBtn = new ButtonControl("Check for Update", "");
|
||||
connect(updateBtn, &ButtonControl::released, [=]() {
|
||||
if (params.getBool("IsOffroad")) {
|
||||
const QString paramsPath = QString::fromStdString(params.getParamsPath());
|
||||
fs_watch->addPath(paramsPath + "/d/LastUpdateTime");
|
||||
@@ -216,7 +217,7 @@ SoftwarePanel::SoftwarePanel(QWidget* parent) : QWidget(parent) {
|
||||
updateBtn->setEnabled(false);
|
||||
}
|
||||
std::system("pkill -1 -f selfdrive.updated");
|
||||
}, "", this);
|
||||
});
|
||||
|
||||
QVBoxLayout *main_layout = new QVBoxLayout(this);
|
||||
QWidget *widgets[] = {versionLbl, lastUpdateLbl, updateBtn, gitBranchLbl, gitCommitLbl, osVersionLbl};
|
||||
|
||||
@@ -63,3 +63,25 @@ void AbstractControl::hideEvent(QHideEvent *e) {
|
||||
description->hide();
|
||||
}
|
||||
}
|
||||
|
||||
// controls
|
||||
|
||||
ButtonControl::ButtonControl(const QString &title, const QString &text, const QString &desc, QWidget *parent) : AbstractControl(title, desc, "", parent) {
|
||||
btn.setText(text);
|
||||
btn.setStyleSheet(R"(
|
||||
QPushButton {
|
||||
padding: 0;
|
||||
border-radius: 50px;
|
||||
font-size: 35px;
|
||||
font-weight: 500;
|
||||
color: #E4E4E4;
|
||||
background-color: #393939;
|
||||
}
|
||||
QPushButton:disabled {
|
||||
color: #33E4E4E4;
|
||||
}
|
||||
)");
|
||||
btn.setFixedSize(250, 100);
|
||||
QObject::connect(&btn, &QPushButton::released, this, &ButtonControl::released);
|
||||
hlayout->addWidget(&btn);
|
||||
}
|
||||
|
||||
@@ -56,32 +56,15 @@ class ButtonControl : public AbstractControl {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
template <typename Functor>
|
||||
ButtonControl(const QString &title, const QString &text, const QString &desc, Functor functor, const QString &icon = "", QWidget *parent = nullptr) : AbstractControl(title, desc, icon, parent) {
|
||||
btn.setText(text);
|
||||
btn.setStyleSheet(R"(
|
||||
QPushButton {
|
||||
padding: 0;
|
||||
border-radius: 50px;
|
||||
font-size: 35px;
|
||||
font-weight: 500;
|
||||
color: #E4E4E4;
|
||||
background-color: #393939;
|
||||
}
|
||||
QPushButton:disabled {
|
||||
color: #33E4E4E4;
|
||||
}
|
||||
)");
|
||||
btn.setFixedSize(250, 100);
|
||||
QObject::connect(&btn, &QPushButton::released, functor);
|
||||
hlayout->addWidget(&btn);
|
||||
}
|
||||
void setText(const QString &text) { btn.setText(text); }
|
||||
ButtonControl(const QString &title, const QString &text, const QString &desc = "", QWidget *parent = nullptr);
|
||||
inline void setText(const QString &text) { btn.setText(text); }
|
||||
inline QString text() const { return btn.text(); }
|
||||
|
||||
signals:
|
||||
void released();
|
||||
|
||||
public slots:
|
||||
void setEnabled(bool enabled) {
|
||||
btn.setEnabled(enabled);
|
||||
};
|
||||
void setEnabled(bool enabled) { btn.setEnabled(enabled); };
|
||||
|
||||
private:
|
||||
QPushButton btn;
|
||||
|
||||
@@ -4,32 +4,17 @@
|
||||
#include "selfdrive/ui/qt/api.h"
|
||||
#include "selfdrive/ui/qt/widgets/input.h"
|
||||
|
||||
SshControl::SshControl() : AbstractControl("SSH Keys", "Warning: This grants SSH access to all public keys in your GitHub settings. Never enter a GitHub username other than your own. A comma employee will NEVER ask you to add their GitHub username.", "") {
|
||||
|
||||
// setup widget
|
||||
hlayout->addStretch(1);
|
||||
|
||||
username_label.setAlignment(Qt::AlignVCenter);
|
||||
SshControl::SshControl() : ButtonControl("SSH Keys", "", "Warning: This grants SSH access to all public keys in your GitHub settings. Never enter a GitHub username other than your own. A comma employee will NEVER ask you to add their GitHub username.") {
|
||||
username_label.setAlignment(Qt::AlignRight | Qt::AlignVCenter);
|
||||
username_label.setStyleSheet("color: #aaaaaa");
|
||||
hlayout->addWidget(&username_label);
|
||||
hlayout->insertWidget(1, &username_label);
|
||||
|
||||
btn.setStyleSheet(R"(
|
||||
padding: 0;
|
||||
border-radius: 50px;
|
||||
font-size: 35px;
|
||||
font-weight: 500;
|
||||
color: #E4E4E4;
|
||||
background-color: #393939;
|
||||
)");
|
||||
btn.setFixedSize(250, 100);
|
||||
hlayout->addWidget(&btn);
|
||||
|
||||
QObject::connect(&btn, &QPushButton::released, [=]() {
|
||||
if (btn.text() == "ADD") {
|
||||
QObject::connect(this, &ButtonControl::released, [=]() {
|
||||
if (text() == "ADD") {
|
||||
QString username = InputDialog::getText("Enter your GitHub username");
|
||||
if (username.length() > 0) {
|
||||
btn.setText("LOADING");
|
||||
btn.setEnabled(false);
|
||||
setText("LOADING");
|
||||
setEnabled(false);
|
||||
getUserKeys(username);
|
||||
}
|
||||
} else {
|
||||
@@ -46,12 +31,12 @@ void SshControl::refresh() {
|
||||
QString param = QString::fromStdString(params.get("GithubSshKeys"));
|
||||
if (param.length()) {
|
||||
username_label.setText(QString::fromStdString(params.get("GithubUsername")));
|
||||
btn.setText("REMOVE");
|
||||
setText("REMOVE");
|
||||
} else {
|
||||
username_label.setText("");
|
||||
btn.setText("ADD");
|
||||
setText("ADD");
|
||||
}
|
||||
btn.setEnabled(true);
|
||||
setEnabled(true);
|
||||
}
|
||||
|
||||
void SshControl::getUserKeys(const QString &username) {
|
||||
|
||||
@@ -18,7 +18,7 @@ public:
|
||||
};
|
||||
|
||||
// SSH key management widget
|
||||
class SshControl : public AbstractControl {
|
||||
class SshControl : public ButtonControl {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
||||
Reference in New Issue
Block a user