mirror of
https://github.com/dragonpilot/dragonpilot.git
synced 2026-06-22 22:42:05 +08:00
offroad alert improvements (#20443)
* alert niceties * cleanup * move the button Co-authored-by: Comma Device <device@comma.ai>
This commit is contained in:
+11
-6
@@ -79,19 +79,20 @@ OffroadHome::OffroadHome(QWidget* parent) : QWidget(parent) {
|
||||
|
||||
date = new QLabel();
|
||||
date->setStyleSheet(R"(font-size: 55px;)");
|
||||
header_layout->addWidget(date, 0, Qt::AlignTop | Qt::AlignLeft);
|
||||
header_layout->addWidget(date, 0, Qt::AlignHCenter | Qt::AlignLeft);
|
||||
|
||||
alert_notification = new QPushButton();
|
||||
alert_notification->setVisible(false);
|
||||
QObject::connect(alert_notification, SIGNAL(released()), this, SLOT(openAlerts()));
|
||||
header_layout->addWidget(alert_notification, 0, Qt::AlignHCenter | Qt::AlignRight);
|
||||
|
||||
std::string brand = Params().read_db_bool("Passive") ? "dashcam" : "openpilot";
|
||||
QLabel* version = new QLabel(QString::fromStdString(brand + " v" + Params().get("Version")));
|
||||
version->setStyleSheet(R"(font-size: 55px;)");
|
||||
header_layout->addWidget(version, 0, Qt::AlignTop | Qt::AlignRight);
|
||||
header_layout->addWidget(version, 0, Qt::AlignHCenter | Qt::AlignRight);
|
||||
|
||||
main_layout->addLayout(header_layout);
|
||||
|
||||
alert_notification = new QPushButton();
|
||||
QObject::connect(alert_notification, SIGNAL(released()), this, SLOT(openAlerts()));
|
||||
main_layout->addWidget(alert_notification, 0, Qt::AlignTop | Qt::AlignRight);
|
||||
|
||||
// main content
|
||||
main_layout->addSpacing(25);
|
||||
center_layout = new QStackedLayout();
|
||||
@@ -152,6 +153,7 @@ void OffroadHome::refresh() {
|
||||
|
||||
alerts_widget->refresh();
|
||||
if (!alerts_widget->alerts.size() && !alerts_widget->updateAvailable) {
|
||||
emit closeAlerts();
|
||||
alert_notification->setVisible(false);
|
||||
return;
|
||||
}
|
||||
@@ -163,6 +165,9 @@ void OffroadHome::refresh() {
|
||||
alert_notification->setText(QString::number(alerts) + " ALERT" + (alerts == 1 ? "" : "S"));
|
||||
}
|
||||
|
||||
if (!alert_notification->isVisible() && !first_refresh) {
|
||||
emit openAlerts();
|
||||
}
|
||||
alert_notification->setVisible(true);
|
||||
|
||||
// Red background for alerts, blue for update available
|
||||
|
||||
@@ -44,6 +44,7 @@ OffroadAlert::OffroadAlert(QWidget* parent) : QFrame(parent) {
|
||||
setLayout(main_layout);
|
||||
setStyleSheet(R"(
|
||||
* {
|
||||
font-size: 48px;
|
||||
color: white;
|
||||
}
|
||||
QFrame {
|
||||
@@ -52,7 +53,6 @@ OffroadAlert::OffroadAlert(QWidget* parent) : QFrame(parent) {
|
||||
}
|
||||
QPushButton {
|
||||
color: black;
|
||||
font-size: 50px;
|
||||
font-weight: 500;
|
||||
border-radius: 30px;
|
||||
background-color: white;
|
||||
@@ -72,37 +72,26 @@ void OffroadAlert::refresh() {
|
||||
parse_alerts();
|
||||
cleanStackedWidget(alerts_stack);
|
||||
|
||||
std::vector<char> bytes = Params().read_db_bytes("UpdateAvailable");
|
||||
updateAvailable = bytes.size() && bytes[0] == '1';
|
||||
|
||||
updateAvailable = Params().read_db_bool("UpdateAvailable");
|
||||
reboot_btn->setVisible(updateAvailable);
|
||||
|
||||
QVBoxLayout *layout = new QVBoxLayout;
|
||||
layout->setSpacing(20);
|
||||
|
||||
if (updateAvailable) {
|
||||
QString release_notes = QString::fromStdString(Params().get("ReleaseNotes"));
|
||||
QLabel *body = new QLabel(release_notes);
|
||||
body->setStyleSheet(R"(
|
||||
font-size: 48px;
|
||||
)");
|
||||
QLabel *body = new QLabel(QString::fromStdString(Params().get("ReleaseNotes")));
|
||||
body->setStyleSheet(R"(font-size: 48px;)");
|
||||
layout->addWidget(body, 0, Qt::AlignLeft | Qt::AlignTop);
|
||||
} else {
|
||||
// TODO: paginate the alerts
|
||||
for (const auto &alert : alerts) {
|
||||
QLabel *l = new QLabel(alert.text);
|
||||
l->setWordWrap(true);
|
||||
l->setMargin(60);
|
||||
|
||||
QString style = R"(
|
||||
font-size: 48px;
|
||||
)";
|
||||
style.append("background-color: " + QString(alert.severity ? "#E22C2C" : "#292929"));
|
||||
l->setStyleSheet(style);
|
||||
|
||||
l->setWordWrap(true);
|
||||
l->setStyleSheet("background-color: " + QString(alert.severity ? "#E22C2C" : "#292929"));
|
||||
layout->addWidget(l, 0, Qt::AlignTop);
|
||||
}
|
||||
layout->setSpacing(20);
|
||||
}
|
||||
|
||||
QWidget *w = new QWidget();
|
||||
w->setLayout(layout);
|
||||
alerts_stack->addWidget(w);
|
||||
@@ -112,7 +101,6 @@ void OffroadAlert::parse_alerts() {
|
||||
alerts.clear();
|
||||
for (const QString &key : alert_keys) {
|
||||
std::vector<char> bytes = Params().read_db_bytes(key.toStdString().c_str());
|
||||
|
||||
if (bytes.size()) {
|
||||
QJsonDocument doc_par = QJsonDocument::fromJson(QByteArray(bytes.data(), bytes.size()));
|
||||
QJsonObject obj = doc_par.object();
|
||||
|
||||
Reference in New Issue
Block a user