From 3303e07056f258322982feac20ede3cd2f46e8b6 Mon Sep 17 00:00:00 2001 From: Tats Date: Mon, 13 Jul 2015 16:45:03 -0600 Subject: [PATCH] Added support for scrolling in source+destination canvases by mid-button clicking. --- MapperGLCanvas.cpp | 18 ++++++++++++++++++ MapperGLCanvas.h | 1 + 2 files changed, 19 insertions(+) diff --git a/MapperGLCanvas.cpp b/MapperGLCanvas.cpp index c198e11..5b6fdd3 100644 --- a/MapperGLCanvas.cpp +++ b/MapperGLCanvas.cpp @@ -391,6 +391,24 @@ void MapperGLCanvas::wheelEvent(QWheelEvent *event) event->accept(); } +void MapperGLCanvas::mouseMoveEvent(QMouseEvent *event) +{ + static QPoint lastPos; + + // Click-and-drag translate view. + if (event->buttons() & Qt::MiddleButton) + { + QPoint pos = event->pos(); + QPointF diff = mapToScene(pos) - mapToScene(lastPos); + QGraphicsView* view = scene()->views().first(); + view->translate(diff.x(), diff.y()); + view->update(); + lastPos = pos; + } + + QGraphicsView::mouseMoveEvent(event); +} + bool MapperGLCanvas::eventFilter(QObject *target, QEvent *event) { if (event->type() == QEvent::KeyPress) diff --git a/MapperGLCanvas.h b/MapperGLCanvas.h index 7b537eb..ed6e16e 100644 --- a/MapperGLCanvas.h +++ b/MapperGLCanvas.h @@ -142,6 +142,7 @@ public slots: void deselectAll(); void wheelEvent(QWheelEvent *event); + void mouseMoveEvent(QMouseEvent *event); // Event Filter bool eventFilter(QObject *target, QEvent *event);