diff --git a/navigatorview.cpp b/navigatorview.cpp index 9d01edf..fa8e51f 100644 --- a/navigatorview.cpp +++ b/navigatorview.cpp @@ -25,10 +25,36 @@ void NavigatorView::updateMainViewportRegion() { if (m_mainView != nullptr) { m_viewportRegion = mapFromScene(m_mainView->mapToScene(m_mainView->rect())); - qDebug() << m_mainView->rect() << m_mainView->mapToScene(m_mainView->rect()) << m_viewportRegion; } } +void NavigatorView::mousePressEvent(QMouseEvent *event) +{ + m_mouseDown = true; + + if (m_mainView) { + m_mainView->centerOn(mapToScene(event->pos())); + } + + return QGraphicsView::mousePressEvent(event); +} + +void NavigatorView::mouseMoveEvent(QMouseEvent *event) +{ + if (m_mouseDown && m_mainView) { + m_mainView->centerOn(mapToScene(event->pos())); + } + + return QGraphicsView::mouseMoveEvent(event); +} + +void NavigatorView::mouseReleaseEvent(QMouseEvent *event) +{ + m_mouseDown = false; + + return QGraphicsView::mouseReleaseEvent(event); +} + void NavigatorView::wheelEvent(QWheelEvent *event) { event->ignore(); diff --git a/navigatorview.h b/navigatorview.h index e082a06..163e1ab 100644 --- a/navigatorview.h +++ b/navigatorview.h @@ -16,9 +16,14 @@ public slots: void updateMainViewportRegion(); private: + void mousePressEvent(QMouseEvent * event) override; + void mouseMoveEvent(QMouseEvent * event) override; + void mouseReleaseEvent(QMouseEvent * event) override; + void wheelEvent(QWheelEvent *event) override; void paintEvent(QPaintEvent *event) override; + bool m_mouseDown = false; QPolygon m_viewportRegion; QGraphicsView *m_mainView = nullptr; };