X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=video_widget.cpp;h=1d899d2507182f8f7c6d98cc206632101d97b85f;hb=d86834b0c2ecc2df21d70a7db8a2a9d949dccc74;hp=3cb5fa1faa38d8a33cd615d014e8ba1a6ebf96e4;hpb=3ea646d51ad82169f61354700d729c703d31c9d3;p=pkanalytics diff --git a/video_widget.cpp b/video_widget.cpp index 3cb5fa1..1d899d2 100644 --- a/video_widget.cpp +++ b/video_widget.cpp @@ -32,6 +32,7 @@ extern "C" { #include #include +#include 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()