nav: show recents (#21405)

* add recent buttons

* remove static request

* layout

* recent doesn't have to be a favorite

* work

* spacing

* spacing

* no recents

* query next

* not null

* this needs to live here

* less spacing between items
old-commit-hash: 9f98a3e44f
commatwo_master
Willem Melching 4 years ago committed by GitHub
parent dd3d2f6949
commit fba42aab80
  1. 3
      selfdrive/ui/SConscript
  2. 2
      selfdrive/ui/qt/maps/map.cc
  3. 115
      selfdrive/ui/qt/maps/map_settings.cc
  4. 10
      selfdrive/ui/qt/maps/map_settings.h
  5. 18
      selfdrive/ui/qt/util.cc
  6. 17
      selfdrive/ui/qt/util.h

@ -19,7 +19,8 @@ if arch == "Darwin":
del base_libs[base_libs.index('OpenCL')] del base_libs[base_libs.index('OpenCL')]
qt_env['FRAMEWORKS'] += ['OpenCL'] qt_env['FRAMEWORKS'] += ['OpenCL']
widgets_src = ["qt/widgets/input.cc", "qt/widgets/drive_stats.cc", widgets_src = ["qt/util.cc",
"qt/widgets/input.cc", "qt/widgets/drive_stats.cc",
"qt/widgets/ssh_keys.cc", "qt/widgets/toggle.cc", "qt/widgets/controls.cc", "qt/widgets/ssh_keys.cc", "qt/widgets/toggle.cc", "qt/widgets/controls.cc",
"qt/widgets/offroad_alerts.cc", "qt/widgets/setup.cc", "qt/widgets/keyboard.cc", "qt/widgets/offroad_alerts.cc", "qt/widgets/setup.cc", "qt/widgets/keyboard.cc",
"qt/widgets/scrollview.cc", "qt/widgets/cameraview.cc", "#phonelibs/qrcode/QrCode.cc", "qt/api.cc", "qt/widgets/scrollview.cc", "qt/widgets/cameraview.cc", "#phonelibs/qrcode/QrCode.cc", "qt/api.cc",

@ -9,6 +9,7 @@
#include "selfdrive/ui/ui.h" #include "selfdrive/ui/ui.h"
#include "selfdrive/ui/qt/util.h" #include "selfdrive/ui/qt/util.h"
#include "selfdrive/ui/qt/maps/map_helpers.h" #include "selfdrive/ui/qt/maps/map_helpers.h"
#include "selfdrive/ui/qt/request_repeater.h"
const int PAN_TIMEOUT = 100; const int PAN_TIMEOUT = 100;
@ -69,7 +70,6 @@ MapWindow::MapWindow(const QMapboxGLSettings &settings) : m_settings(settings) {
last_position = *last_gps_position; last_position = *last_gps_position;
} }
grabGesture(Qt::GestureType::PinchGesture); grabGesture(Qt::GestureType::PinchGesture);
} }

@ -4,6 +4,7 @@
#include "selfdrive/ui/qt/request_repeater.h" #include "selfdrive/ui/qt/request_repeater.h"
#include "selfdrive/ui/qt/widgets/controls.h" #include "selfdrive/ui/qt/widgets/controls.h"
#include "selfdrive/ui/qt/util.h"
#include "selfdrive/common/util.h" #include "selfdrive/common/util.h"
static QString shorten(const QString &str, int max_len) { static QString shorten(const QString &str, int max_len) {
@ -47,8 +48,21 @@ MapPanel::MapPanel(QWidget* parent) : QWidget(parent) {
main_layout->addLayout(home_work_layout); main_layout->addLayout(home_work_layout);
main_layout->addSpacing(50); main_layout->addSpacing(50);
main_layout->addWidget(horizontal_line()); main_layout->addWidget(horizontal_line());
main_layout->addSpacing(50);
// Recents
QLabel *recent = new QLabel("Recent");
recent->setStyleSheet(R"(font-size: 55px;)");
main_layout->addWidget(recent);
main_layout->addSpacing(20);
recent_layout = new QVBoxLayout;
main_layout->addLayout(recent_layout);
// Settings // Settings
main_layout->addSpacing(50);
main_layout->addWidget(horizontal_line());
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",
@ -60,10 +74,27 @@ MapPanel::MapPanel(QWidget* parent) : QWidget(parent) {
std::string dongle_id = Params().get("DongleId"); std::string dongle_id = Params().get("DongleId");
if (util::is_valid_dongle_id(dongle_id)) { if (util::is_valid_dongle_id(dongle_id)) {
std::string url = "https://api.commadotai.com/v1/navigation/" + dongle_id + "/locations"; // Fetch favorite and recent locations
RequestRepeater* repeater = new RequestRepeater(this, QString::fromStdString(url), "ApiCache_NavDestinations", 30); {
QObject::connect(repeater, &RequestRepeater::receivedResponse, this, &MapPanel::parseResponse); 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);
}
// Destination set while offline
{
std::string url = "https://api.commadotai.com/v1/navigation/" + dongle_id + "/next";
RequestRepeater* repeater = new RequestRepeater(this, QString::fromStdString(url), "", 10);
QObject::connect(repeater, &RequestRepeater::receivedResponse, [](QString resp) {
auto params = Params();
if (resp != "null" && params.get("NavDestination").empty()) {
params.put("NavDestination", resp.toStdString());
}
});
}
} }
} }
void MapPanel::clear() { void MapPanel::clear() {
@ -76,6 +107,8 @@ void MapPanel::clear() {
work_address->setStyleSheet(R"(font-size: 50px; color: grey;)"); work_address->setStyleSheet(R"(font-size: 50px; color: grey;)");
work_address->setText("No work\nlocation set"); work_address->setText("No work\nlocation set");
work_button->disconnect(); work_button->disconnect();
clearLayout(recent_layout);
} }
@ -88,6 +121,7 @@ void MapPanel::parseResponse(const QString &response) {
clear(); clear();
bool has_recents = false;
for (auto location : doc.array()) { for (auto location : doc.array()) {
auto obj = location.toObject(); auto obj = location.toObject();
@ -96,26 +130,65 @@ void MapPanel::parseResponse(const QString &response) {
auto name = obj["place_name"].toString(); auto name = obj["place_name"].toString();
auto details = shorten(obj["place_details"].toString(), 30); auto details = shorten(obj["place_details"].toString(), 30);
if (type == "favorite") { if (type == "favorite" && label == "home") {
if (label == "home") { home_address->setText(name);
home_address->setText(name); home_address->setStyleSheet(R"(font-size: 50px; color: white;)");
home_address->setStyleSheet(R"(font-size: 50px; color: white;)"); home_button->setIcon(QPixmap("../assets/navigation/home.png"));
home_button->setIcon(QPixmap("../assets/navigation/home.png")); QObject::connect(home_button, &QPushButton::clicked, [=]() {
QObject::connect(home_button, &QPushButton::clicked, [=]() { navigateTo(obj);
navigateTo(obj); emit closeSettings();
emit closeSettings(); });
}); } else if (type == "favorite" && label == "work") {
} else if (label == "work") { work_address->setText(name);
work_address->setText(name); work_address->setStyleSheet(R"(font-size: 50px; color: white;)");
work_address->setStyleSheet(R"(font-size: 50px; color: white;)"); work_button->setIcon(QPixmap("../assets/navigation/work.png"));
work_button->setIcon(QPixmap("../assets/navigation/work.png")); QObject::connect(work_button, &QPushButton::clicked, [=]() {
QObject::connect(work_button, &QPushButton::clicked, [=]() { navigateTo(obj);
navigateTo(obj); emit closeSettings();
emit closeSettings(); });
}); } else {
} ClickableWidget *widget = new ClickableWidget;
QHBoxLayout *layout = new QHBoxLayout(widget);
layout->setContentsMargins(40, 10, 40, 10);
QLabel *recent_label = new QLabel(name + " " + details);
recent_label->setStyleSheet(R"(font-size: 50px; color: #9c9c9c)");
layout->addWidget(recent_label);
layout->addStretch();
QLabel *arrow = new QLabel("");
arrow->setStyleSheet(R"(font-size: 60px;)");
layout->addWidget(arrow);
widget->setStyleSheet(R"(
.ClickableWidget {
border-radius: 10px;
border-width: 1px;
border-style: solid;
border-color: gray;
}
QWidget {
background-color: #393939;
}
)");
QObject::connect(widget, &ClickableWidget::clicked, [=]() {
navigateTo(obj);
emit closeSettings();
});
recent_layout->addWidget(widget);
recent_layout->addSpacing(10);
has_recents = true;
} }
} }
if (!has_recents) {
QLabel *no_recents = new QLabel(" no recent destinations");
no_recents->setStyleSheet(R"(font-size: 50px; color: #9c9c9c)");
recent_layout->addWidget(no_recents);
}
} }
void MapPanel::navigateTo(const QJsonObject &place) { void MapPanel::navigateTo(const QJsonObject &place) {

@ -1,10 +1,11 @@
#pragma once #pragma once
#include <QWidget> #include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
#include <QLabel> #include <QLabel>
#include <QPushButton> #include <QPushButton>
#include <QJsonObject> #include <QVBoxLayout>
#include <QJsonDocument> #include <QWidget>
#include <QJsonArray>
class MapPanel : public QWidget { class MapPanel : public QWidget {
Q_OBJECT Q_OBJECT
@ -18,6 +19,7 @@ public:
private: private:
QPushButton *home_button, *work_button; QPushButton *home_button, *work_button;
QLabel *home_address, *work_address; QLabel *home_address, *work_address;
QVBoxLayout *recent_layout;
signals: signals:
void closeSettings(); void closeSettings();

@ -0,0 +1,18 @@
#include "selfdrive/ui/qt/util.h"
#include <QStyleOption>
#include <QDebug>
ClickableWidget::ClickableWidget(QWidget *parent) : QWidget(parent) { }
void ClickableWidget::mouseReleaseEvent(QMouseEvent *event) {
emit clicked();
}
// Fix stylesheets
void ClickableWidget::paintEvent(QPaintEvent *) {
QStyleOption opt;
opt.init(this);
QPainter p(this);
style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
}

@ -3,8 +3,10 @@
#include <QDateTime> #include <QDateTime>
#include <QLayout> #include <QLayout>
#include <QLayoutItem> #include <QLayoutItem>
#include <QMouseEvent>
#include <QPainter> #include <QPainter>
#include <QSurfaceFormat> #include <QSurfaceFormat>
#include <QWidget>
#include "selfdrive/common/params.h" #include "selfdrive/common/params.h"
@ -69,3 +71,18 @@ inline void setQtSurfaceFormat() {
#endif #endif
QSurfaceFormat::setDefaultFormat(fmt); QSurfaceFormat::setDefaultFormat(fmt);
} }
class ClickableWidget : public QWidget
{
Q_OBJECT
public:
ClickableWidget(QWidget *parent = nullptr);
protected:
void mouseReleaseEvent(QMouseEvent *event) override;
void paintEvent(QPaintEvent *) override;
signals:
void clicked();
};

Loading…
Cancel
Save