cabana: click time label to seek to a specified time (#27006)

pull/26946/head
Dean Lee 2 years ago committed by GitHub
parent b7ce77b3aa
commit cebee69f30
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      tools/cabana/canmessages.h
  2. 28
      tools/cabana/videowidget.cc
  3. 5
      tools/cabana/videowidget.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(); }

@ -3,11 +3,11 @@
#include <QBuffer>
#include <QButtonGroup>
#include <QDateTime>
#include <QHBoxLayout>
#include <QMouseEvent>
#include <QPainter>
#include <QPixmap>
#include <QStyleOptionSlider>
#include <QTimeEdit>
#include <QTimer>
#include <QToolTip>
#include <QVBoxLayout>
@ -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;

@ -3,12 +3,14 @@
#include <atomic>
#include <mutex>
#include <QHBoxLayout>
#include <QFuture>
#include <QLabel>
#include <QPushButton>
#include <QSlider>
#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;
};

Loading…
Cancel
Save