diff --git a/selfdrive/common/params.cc b/selfdrive/common/params.cc index f8fb480a8d..cb3cac825a 100644 --- a/selfdrive/common/params.cc +++ b/selfdrive/common/params.cc @@ -186,6 +186,7 @@ std::unordered_map keys = { {"LiveParameters", PERSISTENT}, {"MapboxToken", PERSISTENT}, {"NavDestination", CLEAR_ON_MANAGER_START | CLEAR_ON_IGNITION_OFF}, + {"NavSettingTime24h", PERSISTENT}, {"OpenpilotEnabledToggle", PERSISTENT}, {"PandaFirmware", CLEAR_ON_MANAGER_START | CLEAR_ON_PANDA_DISCONNECT}, {"PandaFirmwareHex", CLEAR_ON_MANAGER_START | CLEAR_ON_PANDA_DISCONNECT}, diff --git a/selfdrive/ui/SConscript b/selfdrive/ui/SConscript index d7625cf1ca..7a38c66215 100644 --- a/selfdrive/ui/SConscript +++ b/selfdrive/ui/SConscript @@ -30,7 +30,7 @@ if arch != 'aarch64': if maps: base_libs += ['qmapboxgl'] - widgets_src += ["qt/maps/map_helpers.cc", "qt/maps/map.cc"] + widgets_src += ["qt/maps/map_helpers.cc", "qt/maps/map_settings.cc", "qt/maps/map.cc"] qt_env['CPPDEFINES'] = ["ENABLE_MAPS"] widgets = qt_env.Library("qt_widgets", widgets_src, LIBS=base_libs) diff --git a/selfdrive/ui/qt/maps/map.cc b/selfdrive/ui/qt/maps/map.cc index e8c92ba53c..0e4d54a35a 100644 --- a/selfdrive/ui/qt/maps/map.cc +++ b/selfdrive/ui/qt/maps/map.cc @@ -6,7 +6,6 @@ #include "selfdrive/common/util.h" #include "selfdrive/common/swaglog.h" -#include "selfdrive/common/params.h" #include "selfdrive/ui/ui.h" #include "selfdrive/ui/qt/util.h" #include "selfdrive/ui/qt/maps/map_helpers.h" @@ -46,8 +45,8 @@ MapWindow::MapWindow(const QMapboxGLSettings &settings) : m_settings(settings) { connect(this, &MapWindow::ETAChanged, map_eta, &MapETA::updateETA); const int h = 180; - const int w = 500; - map_eta->setGeometry(0, 1080 - h, w, h); + map_eta->setFixedHeight(h); + map_eta->move(0, 1080 - h); map_eta->setVisible(false); // Routing @@ -608,10 +607,11 @@ void MapInstructions::updateInstructions(QMap banner){ MapETA::MapETA(QWidget * parent) : QWidget(parent){ QHBoxLayout *layout_outer = new QHBoxLayout; layout_outer->setContentsMargins(20, 25, 20, 25); + layout_outer->setSpacing(20); { QVBoxLayout *layout = new QVBoxLayout; - eta = new QLabel("12:26"); + eta = new QLabel; eta->setAlignment(Qt::AlignCenter); auto eta_unit = new QLabel("eta"); @@ -672,7 +672,11 @@ void MapETA::updateETA(float s, float s_typical, float d) { // ETA auto eta_time = QDateTime::currentDateTime().addSecs(s).time(); - eta->setText(eta_time.toString("HH:mm")); + if (params.getBool("NavSettingTime24h")) { + eta->setText(eta_time.toString("HH:mm")); + } else { + eta->setText(eta_time.toString("h:mm a")); + } // Remaining time if (s < 3600) { @@ -680,7 +684,7 @@ void MapETA::updateETA(float s, float s_typical, float d) { time_unit->setText("min"); } else { int hours = int(s) / 3600; - time->setText(QString::number(hours) + ":" + QString::number(int((s - hours * 3600) / 60))); + time->setText(QString::number(hours) + ":" + QString::number(int((s - hours * 3600) / 60)).rightJustified(2, '0')); time_unit->setText("hr"); } @@ -708,4 +712,6 @@ void MapETA::updateETA(float s, float s_typical, float d) { distance_str.setNum(num, 'f', num < 100 ? 1 : 0); distance->setText(distance_str); + + adjustSize(); } diff --git a/selfdrive/ui/qt/maps/map.h b/selfdrive/ui/qt/maps/map.h index c7bfb9786c..88db3333c9 100644 --- a/selfdrive/ui/qt/maps/map.h +++ b/selfdrive/ui/qt/maps/map.h @@ -23,7 +23,9 @@ #include #include +#include "selfdrive/common/params.h" #include "cereal/messaging/messaging.h" + class MapInstructions : public QWidget { Q_OBJECT @@ -52,6 +54,7 @@ private: QLabel *time_unit; QLabel *distance; QLabel *distance_unit; + Params params; public: MapETA(QWidget * parent=nullptr); diff --git a/selfdrive/ui/qt/maps/map_settings.cc b/selfdrive/ui/qt/maps/map_settings.cc new file mode 100644 index 0000000000..d15dfa0588 --- /dev/null +++ b/selfdrive/ui/qt/maps/map_settings.cc @@ -0,0 +1,20 @@ +#include "map_settings.h" + +#include "selfdrive/ui/qt/widgets/controls.h" + + +MapPanel::MapPanel(QWidget* parent) : QWidget(parent) { + QVBoxLayout *layout = new QVBoxLayout; + Params params = Params(); + + QString dongle = QString::fromStdString(params.get("DongleId", false)); + // TODO: Add buttons for home/work shortcuts + + layout->addWidget(new ParamControl("NavSettingTime24h", + "Show ETA in 24h format", + "Use 24h format instead of am/pm", + "", + this)); + layout->addStretch(); + setLayout(layout); +} \ No newline at end of file diff --git a/selfdrive/ui/qt/maps/map_settings.h b/selfdrive/ui/qt/maps/map_settings.h new file mode 100644 index 0000000000..b2deec696f --- /dev/null +++ b/selfdrive/ui/qt/maps/map_settings.h @@ -0,0 +1,8 @@ +#pragma once +#include + +class MapPanel : public QWidget { + Q_OBJECT +public: + explicit MapPanel(QWidget* parent = nullptr); +}; \ No newline at end of file diff --git a/selfdrive/ui/qt/offroad/settings.cc b/selfdrive/ui/qt/offroad/settings.cc index f449f20515..addccf3890 100644 --- a/selfdrive/ui/qt/offroad/settings.cc +++ b/selfdrive/ui/qt/offroad/settings.cc @@ -6,6 +6,11 @@ #ifndef QCOM #include "selfdrive/ui/qt/offroad/networking.h" #endif + +#ifdef ENABLE_MAPS +#include "selfdrive/ui/qt/maps/map_settings.h" +#endif + #include "selfdrive/common/params.h" #include "selfdrive/common/util.h" #include "selfdrive/hardware/hw.h" @@ -350,33 +355,39 @@ SettingsWindow::SettingsWindow(QWidget *parent) : QFrame(parent) { QObject::connect(device, &DevicePanel::reviewTrainingGuide, this, &SettingsWindow::reviewTrainingGuide); QObject::connect(device, &DevicePanel::showDriverView, this, &SettingsWindow::showDriverView); - QPair panels[] = { + QList> panels = { {"Device", device}, {"Network", network_panel(this)}, {"Toggles", new TogglesPanel(this)}, {"Software", new SoftwarePanel(this)}, }; - sidebar_layout->addSpacing(45); +#ifdef ENABLE_MAPS + if (!Params().get("MapboxToken").empty()){ + panels.push_back({"Navigation", new MapPanel(this)}); + } +#endif + const int padding = panels.size() > 3 ? 25 : 35; + nav_btns = new QButtonGroup(); for (auto &[name, panel] : panels) { QPushButton *btn = new QPushButton(name); btn->setCheckable(true); btn->setChecked(nav_btns->buttons().size() == 0); - btn->setStyleSheet(R"( + btn->setStyleSheet(QString(R"( QPushButton { color: grey; border: none; background: none; font-size: 65px; font-weight: 500; - padding-top: 35px; - padding-bottom: 35px; + padding-top: %1px; + padding-bottom: %1px; } QPushButton:checked { color: white; } - )"); + )").arg(padding)); nav_btns->addButton(btn); sidebar_layout->addWidget(btn, 0, Qt::AlignRight);