diff --git a/tools/cabana/videowidget.cc b/tools/cabana/videowidget.cc index 84c2ff0498e156..d64eb0f343edfb 100644 --- a/tools/cabana/videowidget.cc +++ b/tools/cabana/videowidget.cc @@ -327,25 +327,12 @@ void StreamCameraView::paintGL() { CameraWidget::paintGL(); QPainter p(this); - double display_time = can->currentSec(); - + bool scrubbing = false; if (thumbnail_dispaly_time >= 0) { - if (can->isPaused()) { - display_time = thumbnail_dispaly_time; - p.fillRect(rect(), Qt::black); - auto it = big_thumbnails.lowerBound(can->toMonoTime(thumbnail_dispaly_time)); - if (it != big_thumbnails.end()) { - QPixmap scaled_thumb = it.value().scaled(rect().size(), Qt::KeepAspectRatio, Qt::SmoothTransformation); - int x = (rect().width() - scaled_thumb.width()) / 2; - int y = (rect().height() - scaled_thumb.height()) / 2; - p.drawPixmap(x, y, scaled_thumb); - } - } else { - drawThumbnail(p); - } + scrubbing = can->isPaused(); + scrubbing ? drawScrubThumbnail(p) : drawThumbnail(p); } - - if (auto alert = getReplay()->findAlertAtTime(display_time)) { + if (auto alert = getReplay()->findAlertAtTime(scrubbing ? thumbnail_dispaly_time : can->currentSec())) { drawAlert(p, rect(), *alert); } @@ -368,6 +355,18 @@ QPixmap StreamCameraView::generateThumbnail(QPixmap thumb, double seconds) { return scaled; } +void StreamCameraView::drawScrubThumbnail(QPainter &p) { + p.fillRect(rect(), Qt::black); + auto it = big_thumbnails.lowerBound(can->toMonoTime(thumbnail_dispaly_time)); + if (it != big_thumbnails.end()) { + QPixmap scaled_thumb = it.value().scaled(rect().size(), Qt::KeepAspectRatio, Qt::SmoothTransformation); + int x = (rect().width() - scaled_thumb.width()) / 2; + int y = (rect().height() - scaled_thumb.height()) / 2; + p.drawPixmap(x, y, scaled_thumb); + drawTime(p, QRect{x, y, scaled_thumb.width(), scaled_thumb.height()}, thumbnail_dispaly_time); + } +} + void StreamCameraView::drawThumbnail(QPainter &p) { if (thumbnail_dispaly_time < 0) return; @@ -380,13 +379,16 @@ void StreamCameraView::drawThumbnail(QPainter &p) { int y = height() - thumb.height() - THUMBNAIL_MARGIN; p.drawPixmap(x, y, thumb); - p.setPen(QPen(palette().color(QPalette::BrightText), 2)); - p.setFont(QFont(font().family(), 10)); - p.drawText(x, y, thumb.width(), thumb.height() - THUMBNAIL_MARGIN, - Qt::AlignHCenter | Qt::AlignBottom, QString::number(thumbnail_dispaly_time, 'f', 3)); + drawTime(p, QRect{x, y, thumb.width(), thumb.height()}, thumbnail_dispaly_time); } } +void StreamCameraView::drawTime(QPainter &p, const QRect &rect, double seconds) { + p.setPen(palette().color(QPalette::BrightText)); + p.setFont(QFont(font().family(), 10)); + p.drawText(rect.adjusted(0, 0, 0, -THUMBNAIL_MARGIN), Qt::AlignHCenter | Qt::AlignBottom, QString::number(seconds, 'f', 3)); +} + void StreamCameraView::drawAlert(QPainter &p, const QRect &rect, const Timeline::Entry &alert) { p.setPen(QPen(palette().color(QPalette::BrightText), 2)); QColor color = timeline_colors[int(alert.type)]; diff --git a/tools/cabana/videowidget.h b/tools/cabana/videowidget.h index b5d4740747e309..4636f9ea59386e 100644 --- a/tools/cabana/videowidget.h +++ b/tools/cabana/videowidget.h @@ -43,6 +43,8 @@ class StreamCameraView : public CameraWidget { QPixmap generateThumbnail(QPixmap thumbnail, double seconds); void drawAlert(QPainter &p, const QRect &rect, const Timeline::Entry &alert); void drawThumbnail(QPainter &p); + void drawScrubThumbnail(QPainter &p); + void drawTime(QPainter &p, const QRect &rect, double seconds); QPropertyAnimation *fade_animation; QMap big_thumbnails;