From 9e66d05fae0b4f88f2662754c0f0747f83e49ffa Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Thu, 20 Jul 2023 14:28:47 +0200 Subject: [PATCH] Make it possible to seek using the 4th and 5th mouse buttons. This makes it a bit more comfortable to seek around when using a mouse, without having to move the left hand over to the right side of the keyboard. --- main.cpp | 3 ++- video_widget.cpp | 6 +++++- video_widget.h | 4 +++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/main.cpp b/main.cpp index 65a64e1..4caeac3 100644 --- a/main.cpp +++ b/main.cpp @@ -86,7 +86,6 @@ MainWindow::MainWindow(EventsModel *events, PlayersModel *players, position_changed(pos); }); - // It's not really clear whether PgUp should be forwards or backwards, // but mpv does at least up = forwards, so that's probably standard. QShortcut *pgdown = new QShortcut(QKeySequence(Qt::Key_PageDown), this); @@ -99,6 +98,8 @@ MainWindow::MainWindow(EventsModel *events, PlayersModel *players, connect(ui->minus2s, &QPushButton::clicked, [this]() { ui->video->seek(-2000); }); connect(ui->plus2s, &QPushButton::clicked, [this]() { ui->video->seek(2000); }); + connect(ui->video, &VideoWidget::mouse_back_clicked, [this]() { ui->video->seek(-2000); }); + connect(ui->video, &VideoWidget::mouse_forward_clicked, [this]() { ui->video->seek(2000); }); connect(ui->minus1f, &QPushButton::clicked, [this]() { ui->video->seek_frames(-1); }); connect(ui->plus1f, &QPushButton::clicked, [this]() { ui->video->seek_frames(1); }); diff --git a/video_widget.cpp b/video_widget.cpp index 0a7ff43..a5b4513 100644 --- a/video_widget.cpp +++ b/video_widget.cpp @@ -497,7 +497,11 @@ void VideoWidget::wheelEvent(QWheelEvent *event) void VideoWidget::mousePressEvent(QMouseEvent *e) { - if (e->button() == Qt::LeftButton) { + if (e->button() == Qt::BackButton) { + emit mouse_back_clicked(); + } else if (e->button() == Qt::ForwardButton) { + emit mouse_forward_clicked(); + } else if (e->button() == Qt::LeftButton) { dragging = true; last_drag_x = e->position().x(); last_drag_y = e->position().y(); diff --git a/video_widget.h b/video_widget.h index 56cf928..1f1ffe2 100644 --- a/video_widget.h +++ b/video_widget.h @@ -39,13 +39,15 @@ public: void paintGL() override; void wheelEvent(QWheelEvent *event) override; - // For dragging. + // For dragging, and for back/forward button presses. void mousePressEvent(QMouseEvent *e); void mouseReleaseEvent(QMouseEvent *e); void mouseMoveEvent(QMouseEvent *e); signals: void position_changed(uint64_t pos); + void mouse_back_clicked(); + void mouse_forward_clicked(); private: // Should really have been persistent and a PBO, but this is OK for now. -- 2.39.2