From e11ca3bba5059e56a52905f9086e0d5f152cca6a Mon Sep 17 00:00:00 2001 From: Gary Wang Date: Fri, 4 Oct 2019 20:41:27 +0800 Subject: [PATCH] navigator view ready --- navigatorview.cpp | 28 +++++++++++++++++++++++++++- navigatorview.h | 5 +++++ 2 files changed, 32 insertions(+), 1 deletion(-) 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; };