From cebee69f304357c5966dec9b316a4d15e68c571b Mon Sep 17 00:00:00 2001 From: Dean Lee Date: Fri, 20 Jan 2023 02:32:48 +0800 Subject: [PATCH] cabana: click time label to seek to a specified time (#27006) --- tools/cabana/canmessages.h | 1 + tools/cabana/videowidget.cc | 28 +++++++++++++++++++++++++--- tools/cabana/videowidget.h | 5 +++++ 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/tools/cabana/canmessages.h b/tools/cabana/canmessages.h index 2451793742..2cdc010d8c 100644 --- a/tools/cabana/canmessages.h +++ b/tools/cabana/canmessages.h @@ -34,6 +34,7 @@ public: inline double totalSeconds() const { return replay->totalSeconds(); } inline double routeStartTime() const { return replay->routeStartTime() / (double)1e9; } inline double currentSec() const { return replay->currentSeconds(); } + inline QDateTime currentDateTime() const { return replay->currentDateTime(); } inline const CanData &lastMessage(const QString &id) { return can_msgs[id]; } inline const Route* route() const { return replay->route(); } diff --git a/tools/cabana/videowidget.cc b/tools/cabana/videowidget.cc index 400cc5108a..2f6aab249a 100644 --- a/tools/cabana/videowidget.cc +++ b/tools/cabana/videowidget.cc @@ -3,11 +3,11 @@ #include #include #include -#include #include #include #include #include +#include #include #include #include @@ -31,8 +31,9 @@ VideoWidget::VideoWidget(QWidget *parent) : QWidget(parent) { frame_layout->addWidget(cam_widget); // slider controls - QHBoxLayout *slider_layout = new QHBoxLayout(); - QLabel *time_label = new QLabel("00:00"); + slider_layout = new QHBoxLayout(); + time_label = new ElidedLabel("00:00"); + time_label->setToolTip(tr("Click to set current time")); slider_layout->addWidget(time_label); slider = new Slider(this); @@ -64,6 +65,7 @@ VideoWidget::VideoWidget(QWidget *parent) : QWidget(parent) { cam_widget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding); setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum); + QObject::connect(time_label, &ElidedLabel::clicked, this, &VideoWidget::timeLabelClicked); QObject::connect(slider, &QSlider::sliderReleased, [this]() { can->seekTo(slider->value() / 1000.0); }); QObject::connect(slider, &QSlider::valueChanged, [=](int value) { time_label->setText(formatTime(value / 1000)); }); QObject::connect(cam_widget, &CameraWidget::clicked, []() { can->pause(!can->isPaused()); }); @@ -78,6 +80,26 @@ VideoWidget::VideoWidget(QWidget *parent) : QWidget(parent) { updatePlayBtnState(); } +void VideoWidget::timeLabelClicked() { + auto time_edit = new QTimeEdit(this); + auto init_date_time = can->currentDateTime(); + time_edit->setDateTime(init_date_time); + time_edit->setDisplayFormat("hh:mm:ss"); + time_label->setVisible(false); + slider_layout->insertWidget(0, time_edit); + QTimer::singleShot(0, [=]() { time_edit->setFocus(); }); + + QObject::connect(time_edit, &QTimeEdit::editingFinished, [=]() { + if (time_edit->dateTime() != init_date_time) { + int seconds = can->route()->datetime().secsTo(time_edit->dateTime()); + can->seekTo(seconds); + } + time_edit->setVisible(false); + time_label->setVisible(true); + time_edit->deleteLater(); + }); +} + void VideoWidget::rangeChanged(double min, double max, bool is_zoomed) { if (!is_zoomed) { min = 0; diff --git a/tools/cabana/videowidget.h b/tools/cabana/videowidget.h index 424a5b08fe..e9899abbbf 100644 --- a/tools/cabana/videowidget.h +++ b/tools/cabana/videowidget.h @@ -3,12 +3,14 @@ #include #include +#include #include #include #include #include #include "selfdrive/ui/qt/widgets/cameraview.h" +#include "selfdrive/ui/qt/widgets/controls.h" #include "tools/cabana/canmessages.h" class Slider : public QSlider { @@ -45,9 +47,12 @@ public: protected: void updateState(); void updatePlayBtnState(); + void timeLabelClicked(); CameraWidget *cam_widget; QLabel *end_time_label; + ElidedLabel *time_label; + QHBoxLayout *slider_layout; QPushButton *play_btn; Slider *slider; };