From 8a0385e13e8a6641d7c199fe4d8e06b06173c413 Mon Sep 17 00:00:00 2001 From: Jason Wen Date: Tue, 31 Oct 2023 04:45:26 +0000 Subject: [PATCH] ui: Fix Speed Limit Control interaction with speed limit sign --- selfdrive/ui/qt/onroad.cc | 42 +++++++++++++++++++++++++++------------ selfdrive/ui/qt/onroad.h | 4 ++-- selfdrive/ui/ui.h | 4 ++-- 3 files changed, 33 insertions(+), 17 deletions(-) diff --git a/selfdrive/ui/qt/onroad.cc b/selfdrive/ui/qt/onroad.cc index ab1acbec22..f58386b82e 100644 --- a/selfdrive/ui/qt/onroad.cc +++ b/selfdrive/ui/qt/onroad.cc @@ -193,20 +193,11 @@ void OnroadWindow::mousePressEvent(QMouseEvent* e) { UIState *s = uiState(); UIScene &scene = s->scene; - SubMaster &sm = *(uiState()->sm); - auto longitudinal_plan_sp = sm["longitudinalPlanSP"].getLongitudinalPlanSP(); + SubMaster &sm = *(s->sm); QRect debug_tap_rect = QRect(rect().center().x() - 200, rect().center().y() - 200, 400, 400); - QRect speed_limit_touch_rect = speed_sgn_rc.adjusted(-50, -50, 50, 50); - if (longitudinal_plan_sp.getSpeedLimit() > 0.0 && speed_limit_touch_rect.contains(e->x(), e->y())) { - // If touching the speed limit sign area when visible - scene.last_speed_limit_sign_tap = seconds_since_boot(); - params.putBool("LastSpeedLimitSignTap", true); - scene.speed_limit_control_enabled = !scene.speed_limit_control_enabled; - params.putBool("SpeedLimitControl", scene.speed_limit_control_enabled); - propagate_event = false; - } else if (scene.debug_snapshot_enabled && debug_tap_rect.contains(e->x(), e->y())) { + if (scene.debug_snapshot_enabled && debug_tap_rect.contains(e->x(), e->y())) { issue_debug_snapshot(sm); propagate_event = false; } @@ -479,6 +470,30 @@ AnnotatedCameraWidget::AnnotatedCameraWidget(VisionStreamType type, QWidget* par updateButtonsLayout(); } +void AnnotatedCameraWidget::mousePressEvent(QMouseEvent* e) { + bool propagate_event = true; + + UIState *s = uiState(); + UIScene &scene = s->scene; + const SubMaster &sm = *(s->sm); + auto longitudinal_plan_sp = sm["longitudinalPlanSP"].getLongitudinalPlanSP(); + + QRect speed_limit_touch_rect = scene.sl_sign_rect; + + if (longitudinal_plan_sp.getSpeedLimit() > 0.0 && speed_limit_touch_rect.contains(e->x(), e->y())) { + // If touching the speed limit sign area when visible + scene.last_speed_limit_sign_tap = seconds_since_boot(); + params.putBool("LastSpeedLimitSignTap", true); + scene.speed_limit_control_enabled = !scene.speed_limit_control_enabled; + params.putBool("SpeedLimitControl", scene.speed_limit_control_enabled); + propagate_event = false; + } + + if (propagate_event) { + QWidget::mousePressEvent(e); + } +} + #ifdef ENABLE_DASHCAM void AnnotatedCameraWidget::offroadTransition(bool offroad) { if (offroad) { @@ -851,6 +866,7 @@ void AnnotatedCameraWidget::drawHud(QPainter &p) { p.drawText(set_speed_rect.adjusted(0, 77, 0, 0), Qt::AlignTop | Qt::AlignHCenter, setSpeedStr); const QRect sign_rect = set_speed_rect.adjusted(sign_margin, default_size.height(), -sign_margin, -sign_margin); + uiState()->scene.sl_sign_rect = sign_rect; // US/Canada (MUTCD style) sign if ((mapSourcedSpeedLimit && !is_metric && !isNavSpeedLimit) || has_us_speed_limit) { p.setPen(Qt::NoPen); @@ -943,8 +959,8 @@ void AnnotatedCameraWidget::drawHud(QPainter &p) { // Turn Speed Sign if (showTurnSpeedLimit) { - QRect rc = speed_sgn_rc; - rc.moveTop(speed_sgn_rc.bottom() + UI_BORDER_SIZE); + QRect rc = uiState()->scene.sl_sign_rect; + rc.moveTop(uiState()->scene.sl_sign_rect.bottom() + UI_BORDER_SIZE); drawTrunSpeedSign(p, rc, turnSpeedLimit, tscSubText, curveSign, tscActive); } } diff --git a/selfdrive/ui/qt/onroad.h b/selfdrive/ui/qt/onroad.h index 35cad672da..e883d786c8 100644 --- a/selfdrive/ui/qt/onroad.h +++ b/selfdrive/ui/qt/onroad.h @@ -124,6 +124,8 @@ private: void updateButtonsLayout(); void drawFeatureStatusText(QPainter &p, int x, int y); + void mousePressEvent(QMouseEvent* e) override; + Params params; QVBoxLayout *main_layout; QHBoxLayout *buttons_layout; @@ -296,8 +298,6 @@ private: QWidget *map = nullptr; QHBoxLayout* split; - Params params; - QWidget *onroad_settings = nullptr; private slots: diff --git a/selfdrive/ui/ui.h b/selfdrive/ui/ui.h index 50c7b55e55..ab8c474120 100644 --- a/selfdrive/ui/ui.h +++ b/selfdrive/ui/ui.h @@ -20,8 +20,6 @@ const int UI_BORDER_SIZE = 30; const int UI_HEADER_HEIGHT = 420; -const QRect speed_sgn_rc(UI_BORDER_SIZE * 2, UI_BORDER_SIZE * 2.5 + 202, 184, 184); - struct FeatureStatusText { const QStringList dlp_list_text = { "Laneful", "Laneless", "Auto" }; const QStringList gac_list_text = { "Maniac", "Aggressive", "Standard", "Relaxed" }; @@ -240,6 +238,8 @@ typedef struct UIScene { bool torqued_override; bool dynamic_experimental_control_toggle, dynamic_experimental_control; + + QRect sl_sign_rect; } UIScene; class UIState : public QObject {