cabana: fix time is displayed incorrectly when mouse dragged outside of the slider (#28048)

fix time is displayed incorrectly when the mouse is dragged outside of the slider
pull/28053/head
Dean Lee 2 years ago committed by GitHub
parent 5940802b5f
commit 64fb5cb922
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      tools/cabana/videowidget.cc

@ -262,7 +262,8 @@ void Slider::mousePressEvent(QMouseEvent *e) {
void Slider::mouseMoveEvent(QMouseEvent *e) {
QPixmap thumb;
AlertInfo alert;
double seconds = (minimum() + e->pos().x() * ((maximum() - minimum()) / (double)width())) / 1000.0;
int pos = std::clamp(e->pos().x(), 0, width());
double seconds = (minimum() + pos * ((maximum() - minimum()) / (double)width())) / 1000.0;
{
std::lock_guard lk(thumbnail_lock);
uint64_t mono_time = (seconds + can->routeStartTime()) * 1e9;
@ -273,7 +274,7 @@ void Slider::mouseMoveEvent(QMouseEvent *e) {
alert = alert_it->second;
}
}
int x = std::clamp(e->pos().x() - thumb.width() / 2, THUMBNAIL_MARGIN, rect().right() - thumb.width() - THUMBNAIL_MARGIN);
int x = std::clamp(pos - thumb.width() / 2, THUMBNAIL_MARGIN, rect().right() - thumb.width() - THUMBNAIL_MARGIN);
int y = -thumb.height();
thumbnail_label.showPixmap(mapToParent({x, y}), utils::formatSeconds(seconds), thumb, alert);
QSlider::mouseMoveEvent(e);

Loading…
Cancel
Save