navigator view ready

This commit is contained in:
Gary Wang 2019-10-04 20:41:27 +08:00
parent 820ad4e419
commit e11ca3bba5
2 changed files with 32 additions and 1 deletions

View File

@ -25,10 +25,36 @@ void NavigatorView::updateMainViewportRegion()
{ {
if (m_mainView != nullptr) { if (m_mainView != nullptr) {
m_viewportRegion = mapFromScene(m_mainView->mapToScene(m_mainView->rect())); 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) void NavigatorView::wheelEvent(QWheelEvent *event)
{ {
event->ignore(); event->ignore();

View File

@ -16,9 +16,14 @@ public slots:
void updateMainViewportRegion(); void updateMainViewportRegion();
private: private:
void mousePressEvent(QMouseEvent * event) override;
void mouseMoveEvent(QMouseEvent * event) override;
void mouseReleaseEvent(QMouseEvent * event) override;
void wheelEvent(QWheelEvent *event) override; void wheelEvent(QWheelEvent *event) override;
void paintEvent(QPaintEvent *event) override; void paintEvent(QPaintEvent *event) override;
bool m_mouseDown = false;
QPolygon m_viewportRegion; QPolygon m_viewportRegion;
QGraphicsView *m_mainView = nullptr; QGraphicsView *m_mainView = nullptr;
}; };