cabana: scrub by shift dragging on graph (#27545)

* cabana: scrub by shift dragging on graph

* not while live streaming
This commit is contained in:
Willem Melching
2023-03-09 22:14:06 +01:00
committed by GitHub
parent b5d29b550c
commit b79f4594c4
2 changed files with 28 additions and 0 deletions
+26
View File
@@ -668,6 +668,16 @@ void ChartView::mousePressEvent(QMouseEvent *event) {
if (dropAction == Qt::MoveAction) {
return;
}
} else if (event->button() == Qt::LeftButton && QApplication::keyboardModifiers().testFlag(Qt::ShiftModifier)) {
if (!can->liveStreaming()) {
// Save current playback state when scrubbing
resume_after_scrub = !can->isPaused();
if (resume_after_scrub) {
can->pause(true);
}
is_scrubbing = true;
}
} else {
QChartView::mousePressEvent(event);
}
@@ -701,9 +711,25 @@ void ChartView::mouseReleaseEvent(QMouseEvent *event) {
} else {
QGraphicsView::mouseReleaseEvent(event);
}
// Resume playback if we were scrubbing
is_scrubbing = false;
if (resume_after_scrub) {
can->pause(false);
resume_after_scrub = false;
}
}
void ChartView::mouseMoveEvent(QMouseEvent *ev) {
// Scrubbing
if (is_scrubbing && QApplication::keyboardModifiers().testFlag(Qt::ShiftModifier)) {
double t = chart()->mapToValue({(double)ev->x(), (double)ev->y()}).x();
// Prevent seeking past the end of the route
t = std::clamp(t, 0., can->totalSeconds());
can->seekTo(t);
return;
}
auto rubber = findChild<QRubberBand *>();
bool is_zooming = rubber && rubber->isVisible();
const auto plot_area = chart()->plotArea();
+2
View File
@@ -97,6 +97,8 @@ private:
double cur_sec = 0;
const QString mime_type = "application/x-cabanachartview";
SeriesType series_type = SeriesType::Line;
bool is_scrubbing = false;
bool resume_after_scrub = false;
friend class ChartsWidget;
};