Files
dragonpilot/selfdrive/ui/qt/maps/map.h
Willem Melching 86aefbe766 Mapbox widget (#20751)
* squash mapbox stuff

* only hacks for pc

* no hack there

* only update when needed

* get destination from param

* no need for user agent

* add athena method

* change nav path color

* layout cleanups

* margin top

* add build scripts

* rename header file

* set pitch

* fix icon blinking

* keep both options

* draw on top to fix last blinking

* only recomput with gps

* fix include

* put map in onroadwidget

* update mapbox plugin to allow specifying directions url

* cycle through views

* dynamic resize

* only when present

* add map_helpers

* whitespace

* small fixes

* let scons decide

* update setup files

* implicit dependency

* fix alerts

* Update selfdrive/ui/SConscript

* move clearLayout to util.h

* only build when map.cc present

* move maps to own folder

Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com>
2021-05-17 14:57:07 +02:00

100 lines
2.2 KiB
C++

#pragma once
#include <QGeoCoordinate>
#include <QGeoManeuver>
#include <QGeoRouteRequest>
#include <QGeoRouteSegment>
#include <QGeoRoutingManager>
#include <QGeoServiceProvider>
#include <QGestureEvent>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QLabel>
#include <QMapboxGL>
#include <QMouseEvent>
#include <QOpenGLWidget>
#include <QScopedPointer>
#include <QString>
#include <QtGlobal>
#include <QTimer>
#include <QWheelEvent>
#include <QMap>
#include <QPixmap>
#include "cereal/messaging/messaging.h"
class MapWindow : public QOpenGLWidget {
Q_OBJECT
public:
MapWindow(const QMapboxGLSettings &);
~MapWindow();
private:
void initializeGL() final;
void paintGL() final;
void resizeGL(int w, int h) override;
QMapboxGLSettings m_settings;
QScopedPointer<QMapboxGL> m_map;
void initLayers();
void mousePressEvent(QMouseEvent *ev) final;
void mouseMoveEvent(QMouseEvent *ev) final;
void wheelEvent(QWheelEvent *ev) final;
bool event(QEvent *event) final;
bool gestureEvent(QGestureEvent *event);
void pinchTriggered(QPinchGesture *gesture);
bool m_sourceAdded = false;
SubMaster *sm;
QTimer* timer;
// Panning
QPointF m_lastPos;
int pan_counter = 0;
int zoom_counter = 0;
// Route
bool gps_ok = false;
bool has_route = false;
QGeoServiceProvider *geoservice_provider;
QGeoRoutingManager *routing_manager;
QGeoRoute route;
QGeoRouteSegment segment;
QWidget* map_instructions;
QMapbox::Coordinate last_position = QMapbox::Coordinate(37.7393118509158, -122.46471285025565);
QMapbox::Coordinate nav_destination;
double last_maneuver_distance = 1000;
void calculateRoute(QMapbox::Coordinate destination);
bool shouldRecompute();
private slots:
void timerUpdate();
void routeCalculated(QGeoRouteReply *reply);
signals:
void distanceChanged(float distance);
void instructionsChanged(QMap<QString, QVariant> banner);
};
class MapInstructions : public QWidget {
Q_OBJECT
private:
QLabel *distance;
QLabel *primary;
QLabel *secondary;
QLabel *icon_01;
QHBoxLayout *lane_layout;
QMap<QString, QVariant> last_banner;
public:
MapInstructions(QWidget * parent=nullptr);
public slots:
void updateDistance(float d);
void updateInstructions(QMap<QString, QVariant> banner);
};