mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-07-02 03:52:11 +08:00
cabana: custom slider to indicate the status of engaged/disengaged/alerts (#26003)
* timeline * remove todo * cleanup old-commit-hash: beb0f8ac234d28b72c6267d0b4c55fdf81c817b9
This commit is contained in:
@@ -4,7 +4,9 @@
|
||||
#include <QDateTime>
|
||||
#include <QHBoxLayout>
|
||||
#include <QMouseEvent>
|
||||
#include <QPainter>
|
||||
#include <QPushButton>
|
||||
#include <QTimer>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#include "tools/cabana/parser.h"
|
||||
@@ -98,8 +100,50 @@ void VideoWidget::updateState() {
|
||||
}
|
||||
|
||||
// Slider
|
||||
// TODO: show timeline bar like what replay did.
|
||||
Slider::Slider(QWidget *parent) : QSlider(Qt::Horizontal, parent) {
|
||||
QTimer *timer = new QTimer(this);
|
||||
timer->setInterval(2000);
|
||||
timer->callOnTimeout([this]() { timeline = parser->replay->getTimeline(); });
|
||||
timer->start();
|
||||
}
|
||||
|
||||
void Slider::paintEvent(QPaintEvent *ev) {
|
||||
auto getPaintRange = [this](double begin, double end) -> std::pair<double, double> {
|
||||
double total_sec = maximum() - minimum();
|
||||
int start_pos = ((std::max((double)minimum(), (double)begin) - minimum()) / total_sec) * width();
|
||||
int end_pos = ((std::min((double)maximum(), (double)end) - minimum()) / total_sec) * width();
|
||||
return {start_pos, end_pos};
|
||||
};
|
||||
|
||||
QPainter p(this);
|
||||
const int v_margin = 2;
|
||||
p.fillRect(rect().adjusted(0, v_margin, 0, -v_margin), QColor(0, 0, 128));
|
||||
|
||||
for (auto [begin, end, type] : timeline) {
|
||||
if (begin > maximum() || end < minimum()) continue;
|
||||
|
||||
if (type == TimelineType::Engaged) {
|
||||
auto [start_pos, end_pos] = getPaintRange(begin, end);
|
||||
p.fillRect(QRect(start_pos, v_margin, end_pos - start_pos, height() - v_margin * 2), QColor(0, 135, 0));
|
||||
}
|
||||
}
|
||||
for (auto [begin, end, type] : timeline) {
|
||||
if (type == TimelineType::Engaged || begin > maximum() || end < minimum()) continue;
|
||||
|
||||
auto [start_pos, end_pos] = getPaintRange(begin, end);
|
||||
if (type == TimelineType::UserFlag) {
|
||||
p.fillRect(QRect(start_pos, height() - v_margin - 3, end_pos - start_pos, 3), Qt::white);
|
||||
} else {
|
||||
QColor color(Qt::green);
|
||||
if (type != TimelineType::AlertInfo)
|
||||
color = type == TimelineType::AlertWarning ? Qt::yellow : Qt::red;
|
||||
|
||||
p.fillRect(QRect(start_pos, height() - v_margin - 3, end_pos - start_pos, 3), color);
|
||||
}
|
||||
}
|
||||
p.setPen(QPen(Qt::black, 2));
|
||||
qreal x = width() * ((value() - minimum()) / double(maximum() - minimum()));
|
||||
p.drawLine(QPointF{x, 0.}, QPointF{x, (qreal)height()});
|
||||
}
|
||||
|
||||
void Slider::mousePressEvent(QMouseEvent *e) {
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <QWidget>
|
||||
|
||||
#include "selfdrive/ui/qt/widgets/cameraview.h"
|
||||
#include "tools/replay/replay.h"
|
||||
|
||||
class Slider : public QSlider {
|
||||
Q_OBJECT
|
||||
@@ -15,6 +16,10 @@ public:
|
||||
|
||||
signals:
|
||||
void setPosition(int value);
|
||||
|
||||
private:
|
||||
void paintEvent(QPaintEvent *ev) override;
|
||||
std::vector<std::tuple<int, int, TimelineType>> timeline;
|
||||
};
|
||||
|
||||
class VideoWidget : public QWidget {
|
||||
|
||||
Reference in New Issue
Block a user