nav: add button to clear current route (#22167)

* nav: add button to clear current route

* fix scroll

* retab

Co-authored-by: Comma Device <device@comma.ai>
pull/22168/head
Adeeb Shihadeh 4 years ago committed by GitHub
parent bcb8a11d7f
commit d5475ba946
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      selfdrive/common/params.h
  2. 50
      selfdrive/ui/qt/maps/map_settings.cc
  3. 6
      selfdrive/ui/qt/maps/map_settings.h
  4. 5
      selfdrive/ui/qt/offroad/settings.cc
  5. 2
      selfdrive/ui/qt/widgets/controls.cc
  6. 6
      selfdrive/ui/qt/widgets/controls.h

@ -43,6 +43,10 @@ public:
return params_path;
}
inline std::string getParamPath(std::string key) {
return params_path + "/d/" + key;
}
template <class T>
std::optional<T> get(const char *key, bool block = false) {
std::istringstream iss(get(key, block));

@ -55,13 +55,43 @@ MapPanel::MapPanel(QWidget* parent) : QWidget(parent) {
main_layout->addWidget(horizontal_line());
main_layout->addSpacing(20);
// Current route
{
current_widget = new QWidget(this);
QVBoxLayout *current_layout = new QVBoxLayout(current_widget);
QLabel *title = new QLabel("Current Destination");
title->setStyleSheet("font-size: 55px");
current_layout->addWidget(title);
current_route = new ButtonControl("", "CLEAR");
current_route->setStyleSheet("padding-left: 40px;");
current_layout->addWidget(current_route);
QObject::connect(current_route, &ButtonControl::clicked, [=]() {
params.remove("NavDestination");
updateCurrentRoute();
});
current_layout->addSpacing(10);
current_layout->addWidget(horizontal_line());
current_layout->addSpacing(20);
}
main_layout->addWidget(current_widget);
// Recents
QLabel *recents_title = new QLabel("Recent Destinations");
recents_title->setStyleSheet("font-size: 55px");
main_layout->addWidget(recents_title);
main_layout->addSpacing(20);
recent_layout = new QVBoxLayout;
QWidget *recent_widget = new LayoutWidget(recent_layout, this);
ScrollView *recent_scroller = new ScrollView(recent_widget, this);
main_layout->addWidget(recent_scroller, 1);
main_layout->addWidget(recent_scroller);
// No prime upsell
QWidget * no_prime_widget = new QWidget;
{
QVBoxLayout *no_prime_layout = new QVBoxLayout(no_prime_widget);
QLabel *signup_header = new QLabel("Try the Navigation Beta");
signup_header->setStyleSheet(R"(font-size: 75px; color: white; font-weight:600;)");
@ -79,10 +109,10 @@ MapPanel::MapPanel(QWidget* parent) : QWidget(parent) {
signup->setStyleSheet(R"(font-size: 45px; color: white; font-weight:300;)");
signup->setAlignment(Qt::AlignCenter);
no_prime_layout->addSpacing(50);
no_prime_layout->addSpacing(20);
no_prime_layout->addWidget(signup);
no_prime_layout->addStretch();
}
stack->addWidget(main_widget);
stack->addWidget(no_prime_widget);
@ -126,6 +156,10 @@ MapPanel::MapPanel(QWidget* parent) : QWidget(parent) {
}
}
void MapPanel::showEvent(QShowEvent *event) {
updateCurrentRoute();
}
void MapPanel::clear() {
home_button->setIcon(QPixmap("../assets/navigation/home_inactive.png"));
home_address->setStyleSheet(R"(font-size: 50px; color: grey;)");
@ -140,6 +174,16 @@ void MapPanel::clear() {
clearLayout(recent_layout);
}
void MapPanel::updateCurrentRoute() {
auto dest = QString::fromStdString(params.get("NavDestination"));
QJsonDocument doc = QJsonDocument::fromJson(dest.trimmed().toUtf8());
if (dest.size() && !doc.isNull()) {
auto name = doc["place_name"].toString();
auto details = doc["place_details"].toString();
current_route->setTitle(shorten(name + " " + details, 42));
}
current_widget->setVisible(dest.size() && !doc.isNull());
}
void MapPanel::parseResponse(const QString &response) {
QJsonDocument doc = QJsonDocument::fromJson(response.trimmed().toUtf8());

@ -9,6 +9,7 @@
#include <QStackedWidget>
#include "selfdrive/common/params.h"
#include "selfdrive/ui/qt/widgets/controls.h"
class MapPanel : public QWidget {
Q_OBJECT
@ -18,14 +19,19 @@ public:
void navigateTo(const QJsonObject &place);
void parseResponse(const QString &response);
void failedResponse(const QString &response);
void updateCurrentRoute();
void clear();
private:
void showEvent(QShowEvent *event) override;
Params params;
QStackedWidget *stack;
QPushButton *home_button, *work_button;
QLabel *home_address, *work_address;
QVBoxLayout *recent_layout;
QWidget *current_widget;
ButtonControl *current_route;
signals:
void closeSettings();

@ -209,9 +209,8 @@ SoftwarePanel::SoftwarePanel(QWidget* parent) : QWidget(parent) {
updateBtn = new ButtonControl("Check for Update", "");
connect(updateBtn, &ButtonControl::clicked, [=]() {
if (params.getBool("IsOffroad")) {
const QString paramsPath = QString::fromStdString(params.getParamsPath());
fs_watch->addPath(paramsPath + "/d/LastUpdateTime");
fs_watch->addPath(paramsPath + "/d/UpdateFailedCount");
fs_watch->addPath(QString::fromStdString(params.getParamPath("LastUpdateTime")));
fs_watch->addPath(QString::fromStdString(params.getParamPath("UpdateFailedCount")));
updateBtn->setText("CHECKING");
updateBtn->setEnabled(false);
}

@ -45,7 +45,7 @@ AbstractControl::AbstractControl(const QString &title, const QString &desc, cons
if (!desc.isEmpty()) {
description = new QLabel(desc);
description->setContentsMargins(40, 20, 40, 20);
description->setStyleSheet("font-size: 40px; color:grey");
description->setStyleSheet("font-size: 40px; color: grey");
description->setWordWrap(true);
description->setVisible(false);
main_layout->addWidget(description);

@ -33,7 +33,11 @@ class AbstractControl : public QFrame {
public:
void setDescription(const QString &desc) {
if(description) description->setText(desc);
if (description) description->setText(desc);
}
void setTitle(const QString &title) {
title_label->setText(title);
}
signals:

Loading…
Cancel
Save