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
old-commit-hash: 64fb5cb922
beeps
Dean Lee 2 years ago committed by GitHub
parent a729ed4216
commit 14443527cc
  1. 5
      tools/cabana/videowidget.cc

@ -262,7 +262,8 @@ void Slider::mousePressEvent(QMouseEvent *e) {
void Slider::mouseMoveEvent(QMouseEvent *e) { void Slider::mouseMoveEvent(QMouseEvent *e) {
QPixmap thumb; QPixmap thumb;
AlertInfo alert; 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); std::lock_guard lk(thumbnail_lock);
uint64_t mono_time = (seconds + can->routeStartTime()) * 1e9; uint64_t mono_time = (seconds + can->routeStartTime()) * 1e9;
@ -273,7 +274,7 @@ void Slider::mouseMoveEvent(QMouseEvent *e) {
alert = alert_it->second; 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(); int y = -thumb.height();
thumbnail_label.showPixmap(mapToParent({x, y}), utils::formatSeconds(seconds), thumb, alert); thumbnail_label.showPixmap(mapToParent({x, y}), utils::formatSeconds(seconds), thumb, alert);
QSlider::mouseMoveEvent(e); QSlider::mouseMoveEvent(e);

Loading…
Cancel
Save