]> git.sesse.net Git - pkanalytics/commitdiff
Support dragging the picture around when we are zoomed.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Thu, 13 Jul 2023 15:16:20 +0000 (17:16 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Thu, 13 Jul 2023 15:16:20 +0000 (17:16 +0200)
video_widget.cpp
video_widget.h

index 3cb5fa1faa38d8a33cd615d014e8ba1a6ebf96e4..1d899d2507182f8f7c6d98cc206632101d97b85f 100644 (file)
@@ -32,6 +32,7 @@ extern "C" {
 
 #include <QOpenGLFunctions>
 #include <QWheelEvent>
+#include <QMouseEvent>
 
 using namespace std;
 using namespace std::chrono;
@@ -493,6 +494,40 @@ void VideoWidget::wheelEvent(QWheelEvent *event)
        fixup_zoom_matrix();
 }
 
+void VideoWidget::mousePressEvent(QMouseEvent *e)
+{
+       if (e->button() == Qt::LeftButton) {
+               dragging = true;
+               last_drag_x = e->position().x();
+               last_drag_y = e->position().y();
+       }
+}
+
+void VideoWidget::mouseReleaseEvent(QMouseEvent *e)
+{
+       if (e->button() == Qt::LeftButton) {
+               dragging = false;
+       }
+}
+
+void VideoWidget::mouseMoveEvent(QMouseEvent *e)
+{
+       if (!dragging) {
+               return;
+       }
+       float dx = (e->position().x() - last_drag_x) / width();
+       float dy = (e->position().y() - last_drag_y) / height();
+
+       //zoom_matrix[6] += dx * zoom_matrix[0];
+       //zoom_matrix[7] += dy * zoom_matrix[4];
+       zoom_matrix[6] += dx;
+       zoom_matrix[7] -= dy;
+       fixup_zoom_matrix();
+
+       last_drag_x = e->position().x();
+       last_drag_y = e->position().y();
+}
+
 // Normalize the matrix so that we never get skew or similar,
 // and also never can zoom or pan too far out.
 void VideoWidget::fixup_zoom_matrix()
index 801d5cdb6844565e1c7de2853a06de28bc6e99ee..56cf92862605d41b82e56caf90f9d834c4ec64e7 100644 (file)
@@ -39,6 +39,11 @@ public:
        void paintGL() override;
        void wheelEvent(QWheelEvent *event) override;
 
+       // For dragging.
+       void mousePressEvent(QMouseEvent *e);
+       void mouseReleaseEvent(QMouseEvent *e);
+       void mouseMoveEvent(QMouseEvent *e);
+
 signals:
        void position_changed(uint64_t pos);
 
@@ -92,6 +97,9 @@ private:
 
        std::string pathname;
 
+       bool dragging = false;
+       float last_drag_x, last_drag_y;
+
        void producer_thread_func();
        bool play_video(const std::string &pathname);
        void internal_rewind();