From ae5c6aeae69f94630e29f672afc59ccbc0217df3 Mon Sep 17 00:00:00 2001 From: Dean Lee Date: Thu, 2 Sep 2021 04:30:33 +0800 Subject: [PATCH] HomeWindow: cleanup mousePressEvent (#21683) * cleanup mousePressEvent * show/hide map in onroad * merge master old-commit-hash: 579fb8072a002dc0794fe8584ca0f0edc6682a35 --- selfdrive/ui/qt/home.cc | 15 ++------------- selfdrive/ui/qt/onroad.cc | 9 +++++++++ selfdrive/ui/qt/onroad.h | 5 +++-- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/selfdrive/ui/qt/home.cc b/selfdrive/ui/qt/home.cc index a6f02bc005..bf4a76386b 100644 --- a/selfdrive/ui/qt/home.cc +++ b/selfdrive/ui/qt/home.cc @@ -68,19 +68,8 @@ void HomeWindow::showDriverView(bool show) { void HomeWindow::mousePressEvent(QMouseEvent* e) { // Handle sidebar collapsing - if (onroad->isVisible() && (!sidebar->isVisible() || e->x() > sidebar->width())) { - - // TODO: Handle this without exposing pointer to map widget - // Hide map first if visible, then hide sidebar - if (onroad->map != nullptr && onroad->map->isVisible()) { - onroad->map->setVisible(false); - } else if (!sidebar->isVisible()) { - sidebar->setVisible(true); - } else { - sidebar->setVisible(false); - - if (onroad->map != nullptr) onroad->map->setVisible(true); - } + if (onroad->isVisible()) { + sidebar->setVisible(!sidebar->isVisible() && !onroad->isMapVisible()); } } diff --git a/selfdrive/ui/qt/onroad.cc b/selfdrive/ui/qt/onroad.cc index ad07220585..75593cda2a 100644 --- a/selfdrive/ui/qt/onroad.cc +++ b/selfdrive/ui/qt/onroad.cc @@ -69,6 +69,15 @@ void OnroadWindow::updateState(const UIState &s) { } } +void OnroadWindow::mousePressEvent(QMouseEvent* e) { + if (map != nullptr) { + bool sidebarVisible = geometry().x() > 0; + map->setVisible(!sidebarVisible && !map->isVisible()); + } + // propagation event to parent(HomeWindow) + QWidget::mousePressEvent(e); +} + void OnroadWindow::offroadTransition(bool offroad) { #ifdef ENABLE_MAPS if (!offroad) { diff --git a/selfdrive/ui/qt/onroad.h b/selfdrive/ui/qt/onroad.h index 4d9881fd4c..7ef9dfcbe0 100644 --- a/selfdrive/ui/qt/onroad.h +++ b/selfdrive/ui/qt/onroad.h @@ -54,14 +54,15 @@ class OnroadWindow : public QWidget { public: OnroadWindow(QWidget* parent = 0); - QWidget *map = nullptr; + bool isMapVisible() const { return map && map->isVisible(); } private: void paintEvent(QPaintEvent *event); - + void mousePressEvent(QMouseEvent* e) override; OnroadAlerts *alerts; NvgWindow *nvg; QColor bg = bg_colors[STATUS_DISENGAGED]; + QWidget *map = nullptr; QHBoxLayout* split; signals: