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. 88
      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; return params_path;
} }
inline std::string getParamPath(std::string key) {
return params_path + "/d/" + key;
}
template <class T> template <class T>
std::optional<T> get(const char *key, bool block = false) { std::optional<T> get(const char *key, bool block = false) {
std::istringstream iss(get(key, block)); std::istringstream iss(get(key, block));

@ -55,34 +55,64 @@ MapPanel::MapPanel(QWidget* parent) : QWidget(parent) {
main_layout->addWidget(horizontal_line()); main_layout->addWidget(horizontal_line());
main_layout->addSpacing(20); 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 // 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; recent_layout = new QVBoxLayout;
QWidget *recent_widget = new LayoutWidget(recent_layout, this); QWidget *recent_widget = new LayoutWidget(recent_layout, this);
ScrollView *recent_scroller = new ScrollView(recent_widget, 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; QWidget * no_prime_widget = new QWidget;
QVBoxLayout *no_prime_layout = new QVBoxLayout(no_prime_widget); {
QLabel *signup_header = new QLabel("Try the Navigation Beta"); QVBoxLayout *no_prime_layout = new QVBoxLayout(no_prime_widget);
signup_header->setStyleSheet(R"(font-size: 75px; color: white; font-weight:600;)"); QLabel *signup_header = new QLabel("Try the Navigation Beta");
signup_header->setAlignment(Qt::AlignCenter); signup_header->setStyleSheet(R"(font-size: 75px; color: white; font-weight:600;)");
signup_header->setAlignment(Qt::AlignCenter);
no_prime_layout->addWidget(signup_header);
no_prime_layout->addSpacing(50); no_prime_layout->addWidget(signup_header);
no_prime_layout->addSpacing(50);
QLabel *screenshot = new QLabel;
QPixmap pm = QPixmap("../assets/navigation/screenshot.png"); QLabel *screenshot = new QLabel;
screenshot->setPixmap(pm.scaledToWidth(vwp_w * 0.5, Qt::SmoothTransformation)); QPixmap pm = QPixmap("../assets/navigation/screenshot.png");
no_prime_layout->addWidget(screenshot, 0, Qt::AlignHCenter); screenshot->setPixmap(pm.scaledToWidth(vwp_w * 0.5, Qt::SmoothTransformation));
no_prime_layout->addWidget(screenshot, 0, Qt::AlignHCenter);
QLabel *signup = new QLabel("Get turn-by-turn directions displayed and more with a comma \nprime subscription. Sign up now: https://connect.comma.ai");
signup->setStyleSheet(R"(font-size: 45px; color: white; font-weight:300;)"); QLabel *signup = new QLabel("Get turn-by-turn directions displayed and more with a comma \nprime subscription. Sign up now: https://connect.comma.ai");
signup->setAlignment(Qt::AlignCenter); signup->setStyleSheet(R"(font-size: 45px; color: white; font-weight:300;)");
signup->setAlignment(Qt::AlignCenter);
no_prime_layout->addSpacing(50);
no_prime_layout->addWidget(signup); no_prime_layout->addSpacing(20);
no_prime_layout->addWidget(signup);
no_prime_layout->addStretch(); no_prime_layout->addStretch();
}
stack->addWidget(main_widget); stack->addWidget(main_widget);
stack->addWidget(no_prime_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() { void MapPanel::clear() {
home_button->setIcon(QPixmap("../assets/navigation/home_inactive.png")); home_button->setIcon(QPixmap("../assets/navigation/home_inactive.png"));
home_address->setStyleSheet(R"(font-size: 50px; color: grey;)"); home_address->setStyleSheet(R"(font-size: 50px; color: grey;)");
@ -140,6 +174,16 @@ void MapPanel::clear() {
clearLayout(recent_layout); 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) { void MapPanel::parseResponse(const QString &response) {
QJsonDocument doc = QJsonDocument::fromJson(response.trimmed().toUtf8()); QJsonDocument doc = QJsonDocument::fromJson(response.trimmed().toUtf8());

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

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

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

@ -33,7 +33,11 @@ class AbstractControl : public QFrame {
public: public:
void setDescription(const QString &desc) { 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: signals:

Loading…
Cancel
Save