]> git.sesse.net Git - pkanalytics/blobdiff - video_widget.cpp
Support dragging the picture around when we are zoomed.
[pkanalytics] / video_widget.cpp
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()