offroad alert improvements (#20443)

* alert niceties

* cleanup

* move the button

Co-authored-by: Comma Device <device@comma.ai>
pull/20444/head
Adeeb Shihadeh 4 years ago committed by GitHub
parent 43ce7165c4
commit 0ccaec495c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 17
      selfdrive/ui/qt/home.cc
  2. 28
      selfdrive/ui/qt/widgets/offroad_alerts.cc

@ -79,19 +79,20 @@ OffroadHome::OffroadHome(QWidget* parent) : QWidget(parent) {
date = new QLabel(); date = new QLabel();
date->setStyleSheet(R"(font-size: 55px;)"); 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"; std::string brand = Params().read_db_bool("Passive") ? "dashcam" : "openpilot";
QLabel* version = new QLabel(QString::fromStdString(brand + " v" + Params().get("Version"))); QLabel* version = new QLabel(QString::fromStdString(brand + " v" + Params().get("Version")));
version->setStyleSheet(R"(font-size: 55px;)"); 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); 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 content
main_layout->addSpacing(25); main_layout->addSpacing(25);
center_layout = new QStackedLayout(); center_layout = new QStackedLayout();
@ -152,6 +153,7 @@ void OffroadHome::refresh() {
alerts_widget->refresh(); alerts_widget->refresh();
if (!alerts_widget->alerts.size() && !alerts_widget->updateAvailable) { if (!alerts_widget->alerts.size() && !alerts_widget->updateAvailable) {
emit closeAlerts();
alert_notification->setVisible(false); alert_notification->setVisible(false);
return; return;
} }
@ -163,6 +165,9 @@ void OffroadHome::refresh() {
alert_notification->setText(QString::number(alerts) + " ALERT" + (alerts == 1 ? "" : "S")); alert_notification->setText(QString::number(alerts) + " ALERT" + (alerts == 1 ? "" : "S"));
} }
if (!alert_notification->isVisible() && !first_refresh) {
emit openAlerts();
}
alert_notification->setVisible(true); alert_notification->setVisible(true);
// Red background for alerts, blue for update available // Red background for alerts, blue for update available

@ -44,6 +44,7 @@ OffroadAlert::OffroadAlert(QWidget* parent) : QFrame(parent) {
setLayout(main_layout); setLayout(main_layout);
setStyleSheet(R"( setStyleSheet(R"(
* { * {
font-size: 48px;
color: white; color: white;
} }
QFrame { QFrame {
@ -52,7 +53,6 @@ OffroadAlert::OffroadAlert(QWidget* parent) : QFrame(parent) {
} }
QPushButton { QPushButton {
color: black; color: black;
font-size: 50px;
font-weight: 500; font-weight: 500;
border-radius: 30px; border-radius: 30px;
background-color: white; background-color: white;
@ -72,37 +72,26 @@ void OffroadAlert::refresh() {
parse_alerts(); parse_alerts();
cleanStackedWidget(alerts_stack); cleanStackedWidget(alerts_stack);
std::vector<char> bytes = Params().read_db_bytes("UpdateAvailable"); updateAvailable = Params().read_db_bool("UpdateAvailable");
updateAvailable = bytes.size() && bytes[0] == '1';
reboot_btn->setVisible(updateAvailable); reboot_btn->setVisible(updateAvailable);
QVBoxLayout *layout = new QVBoxLayout; QVBoxLayout *layout = new QVBoxLayout;
layout->setSpacing(20);
if (updateAvailable) { if (updateAvailable) {
QString release_notes = QString::fromStdString(Params().get("ReleaseNotes")); QLabel *body = new QLabel(QString::fromStdString(Params().get("ReleaseNotes")));
QLabel *body = new QLabel(release_notes); body->setStyleSheet(R"(font-size: 48px;)");
body->setStyleSheet(R"(
font-size: 48px;
)");
layout->addWidget(body, 0, Qt::AlignLeft | Qt::AlignTop); layout->addWidget(body, 0, Qt::AlignLeft | Qt::AlignTop);
} else { } else {
// TODO: paginate the alerts
for (const auto &alert : alerts) { for (const auto &alert : alerts) {
QLabel *l = new QLabel(alert.text); QLabel *l = new QLabel(alert.text);
l->setWordWrap(true);
l->setMargin(60); l->setMargin(60);
l->setWordWrap(true);
QString style = R"( l->setStyleSheet("background-color: " + QString(alert.severity ? "#E22C2C" : "#292929"));
font-size: 48px;
)";
style.append("background-color: " + QString(alert.severity ? "#E22C2C" : "#292929"));
l->setStyleSheet(style);
layout->addWidget(l, 0, Qt::AlignTop); layout->addWidget(l, 0, Qt::AlignTop);
} }
layout->setSpacing(20);
} }
QWidget *w = new QWidget(); QWidget *w = new QWidget();
w->setLayout(layout); w->setLayout(layout);
alerts_stack->addWidget(w); alerts_stack->addWidget(w);
@ -112,7 +101,6 @@ void OffroadAlert::parse_alerts() {
alerts.clear(); alerts.clear();
for (const QString &key : alert_keys) { for (const QString &key : alert_keys) {
std::vector<char> bytes = Params().read_db_bytes(key.toStdString().c_str()); std::vector<char> bytes = Params().read_db_bytes(key.toStdString().c_str());
if (bytes.size()) { if (bytes.size()) {
QJsonDocument doc_par = QJsonDocument::fromJson(QByteArray(bytes.data(), bytes.size())); QJsonDocument doc_par = QJsonDocument::fromJson(QByteArray(bytes.data(), bytes.size()));
QJsonObject obj = doc_par.object(); QJsonObject obj = doc_par.object();

Loading…
Cancel
Save