nav: home/work shortcuts (#21276)
	
		
	
				
					
				
			* add home/work widgets
* remove todo
* set contents from response
* turn into buttons
* add navigate button
* fix includes
* close settings on nav press
* close sidebar when closing settings
* use live api endpoint
* larger fonts
* more text fits
* only place name
* remove static response
* properly clear
old-commit-hash: c21ea8b506
			
			
				vw-mqb-aeb
			
			
		
							parent
							
								
									1f8a63af7e
								
							
						
					
					
						commit
						dc19c670b6
					
				
				 14 changed files with 156 additions and 4 deletions
			
			
		@ -0,0 +1,3 @@ | 
				
			|||||||
 | 
					version https://git-lfs.github.com/spec/v1 | 
				
			||||||
 | 
					oid sha256:6e2fcc5b07c69bb71506257a37d0fd6abe3bd53892f34d6600a3a09795174da5 | 
				
			||||||
 | 
					size 6128 | 
				
			||||||
@ -0,0 +1,3 @@ | 
				
			|||||||
 | 
					version https://git-lfs.github.com/spec/v1 | 
				
			||||||
 | 
					oid sha256:62f1548c61503d8fdb03592413c38204834d52b30b6fb18d1a9982229616a97e | 
				
			||||||
 | 
					size 2713 | 
				
			||||||
@ -0,0 +1,3 @@ | 
				
			|||||||
 | 
					version https://git-lfs.github.com/spec/v1 | 
				
			||||||
 | 
					oid sha256:d5dc1f7709720d51911e1c2bd61a6bed9fe30c48807b9f26f542e280c54c1a74 | 
				
			||||||
 | 
					size 9165 | 
				
			||||||
@ -0,0 +1,3 @@ | 
				
			|||||||
 | 
					version https://git-lfs.github.com/spec/v1 | 
				
			||||||
 | 
					oid sha256:49aef21620a5d2666c87975b28c6eb1cc8e613c80e504d97f5278cde25872c9d | 
				
			||||||
 | 
					size 5570 | 
				
			||||||
@ -0,0 +1,3 @@ | 
				
			|||||||
 | 
					version https://git-lfs.github.com/spec/v1 | 
				
			||||||
 | 
					oid sha256:d2495943fec4ab00b1df5e4e6227bbec45ec57b19b25be561d616292316212f8 | 
				
			||||||
 | 
					size 2188 | 
				
			||||||
@ -0,0 +1,3 @@ | 
				
			|||||||
 | 
					version https://git-lfs.github.com/spec/v1 | 
				
			||||||
 | 
					oid sha256:93e6a2b405bbbdf48d54fc7c37612430f6688cf8541ee59b984d6add3b8f02a7 | 
				
			||||||
 | 
					size 8446 | 
				
			||||||
@ -1,19 +1,124 @@ | 
				
			|||||||
#include "map_settings.h" | 
					#include "map_settings.h" | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <QDebug> | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "selfdrive/ui/qt/request_repeater.h" | 
				
			||||||
#include "selfdrive/ui/qt/widgets/controls.h" | 
					#include "selfdrive/ui/qt/widgets/controls.h" | 
				
			||||||
 | 
					#include "selfdrive/common/util.h" | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static QString shorten(const QString &str, int max_len) { | 
				
			||||||
 | 
					  return str.size() > max_len ? str.left(max_len).trimmed() + "…" : str; | 
				
			||||||
 | 
					} | 
				
			||||||
 | 
					
 | 
				
			||||||
MapPanel::MapPanel(QWidget* parent) : QWidget(parent) { | 
					MapPanel::MapPanel(QWidget* parent) : QWidget(parent) { | 
				
			||||||
  QVBoxLayout *main_layout = new QVBoxLayout(this); | 
					  QVBoxLayout *main_layout = new QVBoxLayout(this); | 
				
			||||||
  Params params = Params(); | 
					  Params params = Params(); | 
				
			||||||
 | 
					
 | 
				
			||||||
  QString dongle = QString::fromStdString(params.get("DongleId", false)); | 
					  // Home
 | 
				
			||||||
  // TODO: Add buttons for home/work shortcuts
 | 
					  QHBoxLayout *home_layout = new QHBoxLayout; | 
				
			||||||
 | 
					  home_button = new QPushButton; | 
				
			||||||
 | 
					  home_button->setIconSize(QSize(200, 200)); | 
				
			||||||
 | 
					  home_layout->addWidget(home_button); | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  home_address = new QLabel; | 
				
			||||||
 | 
					  home_address->setWordWrap(true); | 
				
			||||||
 | 
					  home_layout->addSpacing(30); | 
				
			||||||
 | 
					  home_layout->addWidget(home_address); | 
				
			||||||
 | 
					  home_layout->addStretch(); | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // Work
 | 
				
			||||||
 | 
					  QHBoxLayout *work_layout = new QHBoxLayout; | 
				
			||||||
 | 
					  work_button = new QPushButton; | 
				
			||||||
 | 
					  work_button->setIconSize(QSize(200, 200)); | 
				
			||||||
 | 
					  work_layout->addWidget(work_button); | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  work_address = new QLabel; | 
				
			||||||
 | 
					  work_address->setWordWrap(true); | 
				
			||||||
 | 
					  work_layout->addSpacing(30); | 
				
			||||||
 | 
					  work_layout->addWidget(work_address); | 
				
			||||||
 | 
					  work_layout->addStretch(); | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // Home & Work layout
 | 
				
			||||||
 | 
					  QHBoxLayout *home_work_layout = new QHBoxLayout; | 
				
			||||||
 | 
					  home_work_layout->addLayout(home_layout, 1); | 
				
			||||||
 | 
					  home_work_layout->addSpacing(50); | 
				
			||||||
 | 
					  home_work_layout->addLayout(work_layout, 1); | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  main_layout->addLayout(home_work_layout); | 
				
			||||||
 | 
					  main_layout->addSpacing(50); | 
				
			||||||
 | 
					  main_layout->addWidget(horizontal_line()); | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // Settings
 | 
				
			||||||
  main_layout->addWidget(new ParamControl("NavSettingTime24h", | 
					  main_layout->addWidget(new ParamControl("NavSettingTime24h", | 
				
			||||||
                                    "Show ETA in 24h format", | 
					                                    "Show ETA in 24h format", | 
				
			||||||
                                    "Use 24h format instead of am/pm", | 
					                                    "Use 24h format instead of am/pm", | 
				
			||||||
                                    "", | 
					                                    "", | 
				
			||||||
                                    this)); | 
					                                    this)); | 
				
			||||||
  main_layout->addStretch(); | 
					  main_layout->addStretch(); | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  clear(); | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  std::string dongle_id = Params().get("DongleId"); | 
				
			||||||
 | 
					  if (util::is_valid_dongle_id(dongle_id)) { | 
				
			||||||
 | 
					    std::string url = "https://api.commadotai.com/v1/navigation/" + dongle_id + "/locations"; | 
				
			||||||
 | 
					    RequestRepeater* repeater = new RequestRepeater(this, QString::fromStdString(url), "ApiCache_NavDestinations", 30); | 
				
			||||||
 | 
					    QObject::connect(repeater, &RequestRepeater::receivedResponse, this, &MapPanel::parseResponse); | 
				
			||||||
 | 
					  } | 
				
			||||||
 | 
					} | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void MapPanel::clear() { | 
				
			||||||
 | 
					  home_button->setIcon(QPixmap("../assets/navigation/home_inactive.png")); | 
				
			||||||
 | 
					  home_address->setStyleSheet(R"(font-size: 50px; color: grey;)"); | 
				
			||||||
 | 
					  home_address->setText("No home\nlocation set"); | 
				
			||||||
 | 
					  home_button->disconnect(); | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  work_button->setIcon(QPixmap("../assets/navigation/work_inactive.png")); | 
				
			||||||
 | 
					  work_address->setStyleSheet(R"(font-size: 50px; color: grey;)"); | 
				
			||||||
 | 
					  work_address->setText("No work\nlocation set"); | 
				
			||||||
 | 
					  work_button->disconnect(); | 
				
			||||||
 | 
					} | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void MapPanel::parseResponse(const QString &response) { | 
				
			||||||
 | 
					  QJsonDocument doc = QJsonDocument::fromJson(response.trimmed().toUtf8()); | 
				
			||||||
 | 
					  if (doc.isNull()) { | 
				
			||||||
 | 
					    qDebug() << "JSON Parse failed on navigation locations"; | 
				
			||||||
 | 
					    return; | 
				
			||||||
 | 
					  } | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  clear(); | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  for (auto location : doc.array()) { | 
				
			||||||
 | 
					    auto obj = location.toObject(); | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    auto type = obj["save_type"].toString(); | 
				
			||||||
 | 
					    auto label = obj["label"].toString(); | 
				
			||||||
 | 
					    auto name = obj["place_name"].toString(); | 
				
			||||||
 | 
					    auto details = shorten(obj["place_details"].toString(), 30); | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (type == "favorite") { | 
				
			||||||
 | 
					      if (label == "home") { | 
				
			||||||
 | 
					        home_address->setText(name); | 
				
			||||||
 | 
					        home_address->setStyleSheet(R"(font-size: 50px; color: white;)"); | 
				
			||||||
 | 
					        home_button->setIcon(QPixmap("../assets/navigation/home.png")); | 
				
			||||||
 | 
					        QObject::connect(home_button, &QPushButton::clicked, [=]() { | 
				
			||||||
 | 
					          navigateTo(obj); | 
				
			||||||
 | 
					          emit closeSettings(); | 
				
			||||||
 | 
					        }); | 
				
			||||||
 | 
					      } else if (label == "work") { | 
				
			||||||
 | 
					        work_address->setText(name); | 
				
			||||||
 | 
					        work_address->setStyleSheet(R"(font-size: 50px; color: white;)"); | 
				
			||||||
 | 
					        work_button->setIcon(QPixmap("../assets/navigation/work.png")); | 
				
			||||||
 | 
					        QObject::connect(work_button, &QPushButton::clicked, [=]() { | 
				
			||||||
 | 
					          navigateTo(obj); | 
				
			||||||
 | 
					          emit closeSettings(); | 
				
			||||||
 | 
					        }); | 
				
			||||||
 | 
					      } | 
				
			||||||
 | 
					    } | 
				
			||||||
 | 
					  } | 
				
			||||||
 | 
					} | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void MapPanel::navigateTo(const QJsonObject &place) { | 
				
			||||||
 | 
					  QJsonDocument doc(place); | 
				
			||||||
 | 
					  Params().put("NavDestination", doc.toJson().toStdString()); | 
				
			||||||
} | 
					} | 
				
			||||||
 | 
				
			|||||||
@ -1,8 +1,24 @@ | 
				
			|||||||
#pragma once | 
					#pragma once | 
				
			||||||
#include <QWidget> | 
					#include <QWidget> | 
				
			||||||
 | 
					#include <QLabel> | 
				
			||||||
 | 
					#include <QPushButton> | 
				
			||||||
 | 
					#include <QJsonObject> | 
				
			||||||
 | 
					#include <QJsonDocument> | 
				
			||||||
 | 
					#include <QJsonArray> | 
				
			||||||
 | 
					
 | 
				
			||||||
class MapPanel : public QWidget { | 
					class MapPanel : public QWidget { | 
				
			||||||
  Q_OBJECT | 
					  Q_OBJECT | 
				
			||||||
public: | 
					public: | 
				
			||||||
  explicit MapPanel(QWidget* parent = nullptr); | 
					  explicit MapPanel(QWidget* parent = nullptr); | 
				
			||||||
}; | 
					
 | 
				
			||||||
 | 
					  void navigateTo(const QJsonObject &place); | 
				
			||||||
 | 
					  void parseResponse(const QString &response); | 
				
			||||||
 | 
					  void clear(); | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					private: | 
				
			||||||
 | 
					  QPushButton *home_button, *work_button; | 
				
			||||||
 | 
					  QLabel *home_address, *work_address; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					signals: | 
				
			||||||
 | 
					  void closeSettings(); | 
				
			||||||
 | 
					}; | 
				
			||||||
 | 
				
			|||||||
					Loading…
					
					
				
		Reference in new issue