mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-09-29 04:13:43 +08:00
ui: Fix Speed Limit Control interaction with speed limit sign
This commit is contained in:
+29
-13
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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:
|
||||
|
||||
+2
-2
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user